]> Git Repo - binutils.git/blob - gdb/os9kread.c
* TODO: Add suggestions about structure passing tests.
[binutils.git] / gdb / os9kread.c
1 /* Read os9/os9k symbol tables and convert to internal format, for GDB.
2    Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993
3    Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
20
21 /* This module provides three functions: os9k_symfile_init,
22    which initializes to read a symbol file; os9k_new_init, which 
23    discards existing cached information when all symbols are being
24    discarded; and os9k_symfile_read, which reads a symbol table
25    from a file.
26
27    os9k_symfile_read only does the minimum work necessary for letting the
28    user "name" things symbolically; it does not read the entire symtab.
29    Instead, it reads the external and static symbols and puts them in partial
30    symbol tables.  When more extensive information is requested of a
31    file, the corresponding partial symbol table is mutated into a full
32    fledged symbol table by going back and reading the symbols
33    for real.  os9k_psymtab_to_symtab() is the function that does this */
34
35 #include "defs.h"
36 #include <string.h>
37 #include <stdio.h>
38
39 #if defined(USG) || defined(__CYGNUSCLIB__)
40 #include <sys/types.h>
41 #include <fcntl.h>
42 #endif
43
44 #include <obstack.h>
45 #include <sys/param.h>
46 #ifndef NO_SYS_FILE
47 #include <sys/file.h>
48 #endif
49 #include <sys/stat.h>
50 #include <ctype.h>
51 #include "symtab.h"
52 #include "breakpoint.h"
53 #include "command.h"
54 #include "target.h"
55 #include "gdbcore.h"            /* for bfd stuff */
56 #include "libbfd.h"             /* FIXME Secret internal BFD stuff (bfd_read) */
57 #include "libaout.h"            /* FIXME Secret internal BFD stuff for a.out */
58 #include "symfile.h"
59 #include "objfiles.h"
60 #include "buildsym.h"
61 #include "gdb-stabs.h"
62 #include "demangle.h"
63 #include "language.h"           /* Needed inside partial-stab.h */
64 #include "complaints.h"
65 #include "os9k.h"
66 #include "stabsread.h"
67
68 #if !defined (SEEK_SET)
69 #define SEEK_SET 0
70 #define SEEK_CUR 1
71 #endif
72
73 /* Each partial symbol table entry contains a pointer to private data for the
74    read_symtab() function to use when expanding a partial symbol table entry
75    to a full symbol table entry.
76
77    For dbxread this structure contains the offset within the file symbol table
78    of first local symbol for this file, and count of the section
79    of the symbol table devoted to this file's symbols (actually, the section
80    bracketed may contain more than just this file's symbols).  It also contains
81    further information needed to locate the symbols if they are in an ELF file.
82
83    If ldsymcnt is 0, the only reason for this thing's existence is the
84    dependency list.  Nothing else will happen when it is read in.  */
85
86 #define LDSYMOFF(p) (((struct symloc *)((p)->read_symtab_private))->ldsymoff)
87 #define LDSYMCNT(p) (((struct symloc *)((p)->read_symtab_private))->ldsymnum)
88
89 struct symloc {
90   int ldsymoff;
91   int ldsymnum;
92 };
93
94 /* Remember what we deduced to be the source language of this psymtab. */
95 static enum language psymtab_language = language_unknown;
96
97 /* keep partial symbol table file nested depth */
98 static int psymfile_depth = 0;
99
100 /* keep symbol table file nested depth */
101 static int symfile_depth = 0;
102
103 /* Nonzero means give verbose info on gdb action.  From main.c.  */
104 extern int info_verbose;
105
106 extern int previous_stab_code;
107
108 /* The BFD for this file -- implicit parameter to next_symbol_text.  */
109 static bfd *symfile_bfd;
110
111 /* Name of last function encountered.  Used in Solaris to approximate
112    object file boundaries.  */
113 static char *last_function_name;
114
115 /* Complaints about the symbols we have encountered.  */
116 extern struct complaint lbrac_complaint;
117
118 extern struct complaint unknown_symtype_complaint;
119
120 extern struct complaint unknown_symchar_complaint;
121
122 extern struct complaint lbrac_rbrac_complaint;
123
124 extern struct complaint repeated_header_complaint;
125
126 extern struct complaint repeated_header_name_complaint;
127
128 static struct complaint lbrac_unmatched_complaint =
129   {"unmatched Increment Block Entry before symtab pos %d", 0, 0};
130
131 static struct complaint lbrac_mismatch_complaint =
132   {"IBE/IDE symbol mismatch at symtab pos %d", 0, 0};
133
134 \f
135 /* Local function prototypes */
136 static void
137 os9k_read_ofile_symtab PARAMS ((struct partial_symtab *));
138
139 static void
140 os9k_psymtab_to_symtab PARAMS ((struct partial_symtab *));
141
142 static void
143 os9k_psymtab_to_symtab_1 PARAMS ((struct partial_symtab *));
144
145 static void
146 read_os9k_psymtab PARAMS ((struct section_offsets *, struct objfile *,
147                          CORE_ADDR, int));
148
149 static void
150 init_psymbol_list PARAMS ((struct objfile *));
151
152 static char *
153 os9k_next_symbol_text PARAMS ((void));
154
155 static int
156 fill_sym PARAMS ((FILE *, bfd *));
157
158 static void
159 os9k_symfile_init PARAMS ((struct objfile *));
160
161 static void
162 os9k_new_init PARAMS ((struct objfile *));
163
164 static void
165 os9k_symfile_read PARAMS ((struct objfile *, struct section_offsets *, int));
166
167 static void
168 os9k_symfile_finish PARAMS ((struct objfile *));
169
170 static void
171 os9k_process_one_symbol PARAMS ((int, int, CORE_ADDR, char *, 
172      struct section_offsets *, struct objfile *));
173
174 static struct partial_symtab *
175 os9k_start_psymtab PARAMS ((struct objfile *, struct section_offsets *, char *,
176                        CORE_ADDR, int, int, struct partial_symbol *,
177                        struct partial_symbol *));
178
179 static struct partial_symtab *
180 os9k_end_psymtab PARAMS ((struct partial_symtab *, char **, int, int, CORE_ADDR,
181                      struct partial_symtab **, int));
182
183 static void
184 record_minimal_symbol PARAMS ((char *, CORE_ADDR, int, struct objfile *));
185 \f
186 #define HANDLE_RBRAC(val) \
187   if ((val) > pst->texthigh) pst->texthigh = (val);
188
189 #define SWAP_STBHDR(hdrp, abfd) \
190   { \
191     (hdrp)->fmtno = bfd_get_16(abfd, (unsigned char *)&(hdrp)->fmtno); \
192     (hdrp)->crc = bfd_get_32(abfd, (unsigned char *)&(hdrp)->crc); \
193     (hdrp)->offset = bfd_get_32(abfd, (unsigned char *)&(hdrp)->offset); \
194     (hdrp)->nsym = bfd_get_32(abfd, (unsigned char *)&(hdrp)->nsym); \
195   }
196 #define SWAP_STBSYM(symp, abfd) \
197   { \
198     (symp)->value = bfd_get_32(abfd, (unsigned char *)&(symp)->value); \
199     (symp)->type = bfd_get_16(abfd, (unsigned char *)&(symp)->type); \
200     (symp)->stroff = bfd_get_32(abfd, (unsigned char *)&(symp)->stroff); \
201   }
202 #define N_DATA 0
203 #define N_BSS 1
204 #define N_RDATA 2
205 #define N_IDATA 3
206 #define N_TEXT 4
207 #define N_ABS 6
208
209 static void
210 record_minimal_symbol (name, address, type, objfile)
211      char *name;
212      CORE_ADDR address;
213      int type;
214      struct objfile *objfile;
215 {
216   enum minimal_symbol_type ms_type;
217
218   switch (type)
219     {
220     case N_TEXT:  ms_type = mst_text; break;
221     case N_DATA:  ms_type = mst_data; break;
222     case N_BSS:   ms_type = mst_bss;  break;
223     case N_RDATA: ms_type = mst_bss; break;
224     case N_IDATA: ms_type = mst_data; break;
225     case N_ABS:   ms_type = mst_abs;  break;
226     default:      ms_type = mst_unknown; break;
227   }
228
229   prim_record_minimal_symbol
230     (obsavestring (name, strlen(name), &objfile->symbol_obstack),
231      address, ms_type, objfile);
232 }
233
234 /* read and process .stb file and store in minimal symbol table */
235 typedef char mhhdr[80];
236 struct stbhdr {
237         mhhdr comhdr;
238         char * name;
239         short fmtno;
240         int crc;
241         int offset;
242         int nsym;
243         char *pad;
244 };
245 struct stbsymbol {
246         int value;
247         short type;
248         int stroff;
249 };
250 #define STBSYMSIZE 10
251
252 static int 
253 read_minimal_symbols(objfile)
254      struct objfile *objfile;
255 {
256 FILE *fp;
257 bfd *abfd;
258 struct stbhdr hdr;
259 struct stbsymbol sym;
260 int ch, i, j, off;
261 char buf[64], buf1[128];
262                 
263   fp = objfile->auxf1;
264   if (fp == NULL) return;
265   abfd = objfile->obfd;
266   fread(&hdr.comhdr[0], sizeof(mhhdr), 1, fp);
267   i = 0;
268   ch = getc(fp);
269   while (ch != -1) {
270     buf[i] = (char)ch;
271     i++;
272     if (ch == 0) break;
273     ch = getc(fp);
274   };
275   if (i%2) ch=getc(fp);
276   hdr.name = &buf[0];
277
278   fread(&hdr.fmtno, sizeof(hdr.fmtno), 1, fp);
279   fread(&hdr.crc, sizeof(hdr.crc), 1, fp);
280   fread(&hdr.offset, sizeof(hdr.offset), 1, fp);
281   fread(&hdr.nsym, sizeof(hdr.nsym), 1, fp);
282   SWAP_STBHDR(&hdr, abfd);      
283         
284   /* read symbols */
285   init_minimal_symbol_collection();
286   off = hdr.offset;
287   for (i = hdr.nsym; i > 0; i--) {
288     fseek(fp, (long)off, 0);
289     fread(&sym.value, sizeof(sym.value), 1, fp);
290     fread(&sym.type, sizeof(sym.type), 1, fp);
291     fread(&sym.stroff, sizeof(sym.stroff), 1, fp);
292     SWAP_STBSYM (&sym, abfd);
293     fseek(fp, (long)sym.stroff, 0);
294     j = 0;
295     ch = getc(fp);
296     while (ch != -1) {
297         buf1[j] = (char)ch;
298         j++;
299         if (ch == 0) break;
300         ch = getc(fp);
301     };
302     record_minimal_symbol(buf1, sym.value, sym.type&7, objfile);
303     off += STBSYMSIZE;
304   };
305   install_minimal_symbols (objfile);
306   return 1;
307 }
308 \f
309 /* Scan and build partial symbols for a symbol file.
310    We have been initialized by a call to os9k_symfile_init, which 
311    put all the relevant info into a "struct os9k_symfile_info",
312    hung off the objfile structure.
313
314    SECTION_OFFSETS contains offsets relative to which the symbols in the
315    various sections are (depending where the sections were actually loaded).
316    MAINLINE is true if we are reading the main symbol
317    table (as opposed to a shared lib or dynamically loaded file).  */
318
319 static void
320 os9k_symfile_read (objfile, section_offsets, mainline)
321      struct objfile *objfile;
322      struct section_offsets *section_offsets;
323      int mainline;      /* FIXME comments above */
324 {
325   bfd *sym_bfd;
326   int val;
327   int stb_exist;
328   struct cleanup *back_to;
329
330   sym_bfd = objfile->obfd;
331   /* If we are reinitializing, or if we have never loaded syms yet, init */
332   if (mainline || objfile->global_psymbols.size == 0 || 
333     objfile->static_psymbols.size == 0)
334     init_psymbol_list (objfile);
335
336   pending_blocks = 0;
337   back_to = make_cleanup (really_free_pendings, 0);
338
339   make_cleanup (discard_minimal_symbols, 0);
340   read_minimal_symbols (objfile);
341
342   /* Now that the symbol table data of the executable file are all in core,
343      process them and define symbols accordingly.  */
344   read_os9k_psymtab (section_offsets, objfile,
345                    bfd_section_vma  (sym_bfd, DBX_TEXT_SECT (objfile)),
346                    bfd_section_size (sym_bfd, DBX_TEXT_SECT (objfile)));
347
348   if (!have_partial_symbols ()) {
349     wrap_here ("");
350     printf_filtered ("(no debugging symbols found)...");
351     wrap_here ("");
352   }
353
354   do_cleanups (back_to);
355 }
356
357 /* Initialize anything that needs initializing when a completely new
358    symbol file is specified (not just adding some symbols from another
359    file, e.g. a shared library).  */
360
361 static void
362 os9k_new_init (ignore)
363      struct objfile *ignore;
364 {
365   stabsread_new_init ();
366   buildsym_new_init ();
367   psymfile_depth = 0;
368 /*
369   init_header_files ();
370 */
371 }
372
373 /* os9k_symfile_init ()
374    It is passed a struct objfile which contains, among other things,
375    the BFD for the file whose symbols are being read, and a slot for a pointer
376    to "private data" which we fill with goodies.
377
378    Since BFD doesn't know how to read debug symbols in a format-independent
379    way (and may never do so...), we have to do it ourselves.  We will never
380    be called unless this is an a.out (or very similar) file. 
381    FIXME, there should be a cleaner peephole into the BFD environment here.  */
382
383 static void
384 os9k_symfile_init (objfile)
385      struct objfile *objfile;
386 {
387   int val;
388   bfd *sym_bfd = objfile->obfd;
389   char *name = bfd_get_filename (sym_bfd);
390   char dbgname[64], stbname[64];
391   FILE *symfile = 0;
392   FILE *minfile = 0;
393
394
395   strcpy(dbgname, name);
396   strcat(dbgname, ".dbg");
397   strcpy(stbname, name);
398   strcat(stbname, ".stb");
399
400   if ((symfile = fopen(dbgname, "r")) == NULL) {
401     warning("Symbol file %s not found", dbgname);
402   }
403   objfile->auxf2 = symfile;
404
405   if ((minfile = fopen(stbname, "r")) == NULL) {
406     warning("Symbol file %s not found", stbname);
407   }
408   objfile->auxf1 = minfile;
409
410   /* Allocate struct to keep track of the symfile */
411   objfile->sym_stab_info = (PTR)
412     xmmalloc (objfile -> md, sizeof (struct dbx_symfile_info));
413   DBX_SYMFILE_INFO (objfile)->stab_section_info = NULL;
414
415   DBX_TEXT_SECT (objfile) = bfd_get_section_by_name (sym_bfd, ".text");
416   if (!DBX_TEXT_SECT (objfile))
417     error ("Can't find .text section in file");
418
419   DBX_SYMBOL_SIZE (objfile) = 0;     /* variable size symbol */
420   DBX_SYMCOUNT (objfile) =  0;  /* used to be bfd_get_symcount(sym_bfd) */
421   DBX_SYMTAB_OFFSET (objfile) = 0;  /* used to be SYMBOL_TABLE_OFFSET */
422 }
423
424 /* Perform any local cleanups required when we are done with a particular
425    objfile.  I.E, we are in the process of discarding all symbol information
426    for an objfile, freeing up all memory held for it, and unlinking the
427    objfile struct from the global list of known objfiles. */
428
429 static void
430 os9k_symfile_finish (objfile)
431      struct objfile *objfile;
432 {
433   if (objfile->sym_stab_info != NULL)
434     {
435       mfree (objfile -> md, objfile->sym_stab_info);
436     }
437 /*
438   free_header_files ();
439 */
440 }
441
442 \f
443 struct st_dbghdr {
444   int sync;
445   short rev;
446   int crc;
447   short os;
448   short cpu;
449 };
450 #define SYNC            (int)0xefbefeca
451
452 #define SWAP_DBGHDR(hdrp, abfd) \
453   { \
454     (hdrp)->sync = bfd_get_32(abfd, (unsigned char *)&(hdrp)->sync); \
455     (hdrp)->rev = bfd_get_16(abfd, (unsigned char *)&(hdrp)->rev); \
456     (hdrp)->crc = bfd_get_32(abfd, (unsigned char *)&(hdrp)->crc); \
457     (hdrp)->os = bfd_get_16(abfd, (unsigned char *)&(hdrp)->os); \
458     (hdrp)->cpu = bfd_get_16(abfd, (unsigned char *)&(hdrp)->cpu); \
459   }
460
461 #define N_SYM_CMPLR     0
462 #define N_SYM_SLINE     1
463 #define N_SYM_SYM       2
464 #define N_SYM_LBRAC     3
465 #define N_SYM_RBRAC     4
466 #define N_SYM_SE        5
467
468 struct internal_symstruct {
469   short n_type;
470   short n_desc;
471   long n_value;
472   char * n_strx;
473 };
474 static struct internal_symstruct symbol;
475 static struct internal_symstruct *symbuf = &symbol;
476 static char strbuf[4096];
477 static struct st_dbghdr dbghdr;
478 static short cmplrid;
479
480 #define VER_PRE_ULTRAC  ((short)4)
481 #define VER_ULTRAC      ((short)5)
482
483 static int
484 fill_sym (dbg_file, abfd)
485      FILE *dbg_file;
486      bfd *abfd;
487 {
488 short id;
489 short si, nmask;
490 long li;
491 int ii;
492 char *p;
493
494   int nbytes = fread(&si, sizeof(si), 1, dbg_file);
495   if (nbytes == 0)
496     return 0;
497   if (nbytes < 0)
498     perror_with_name ("reading .dbg file.");
499   symbuf->n_desc = 0;
500   symbuf->n_value = 0;
501   symbuf->n_strx = NULL;
502   symbuf->n_type = bfd_get_16 (abfd, (unsigned char *)&si);
503   symbuf->n_type = 0xf & symbuf->n_type;
504   switch (symbuf->n_type)
505     {
506     case N_SYM_CMPLR:
507       fread(&si, sizeof(si), 1, dbg_file);
508       symbuf->n_desc = bfd_get_16(abfd, (unsigned char *)&si);
509       cmplrid = symbuf->n_desc & 0xff;
510       break;
511     case N_SYM_SLINE:
512       fread(&li, sizeof(li), 1, dbg_file);
513       symbuf->n_value = bfd_get_32(abfd, (unsigned char *)&li);
514       fread(&li, sizeof(li), 1, dbg_file);
515       li = bfd_get_32(abfd, (unsigned char *)&li);
516       symbuf->n_strx = (char *)(li >> 12);
517       symbuf->n_desc = li & 0xfff;
518       break;
519     case N_SYM_SYM:
520       fread(&li, sizeof(li), 1, dbg_file);
521       symbuf->n_value = bfd_get_32(abfd, (unsigned char *)&li);
522       si = 0;
523       do {
524         ii = getc(dbg_file);
525         strbuf[si++] = (char) ii;
526       } while (ii != 0 || si % 2 != 0);
527       symbuf->n_strx = strbuf;
528       p = (char *) strchr (strbuf, ':');
529       if (!p) break;
530       if ((p[1] == 'F' || p[1] == 'f') && cmplrid == VER_PRE_ULTRAC)
531         {
532           fread(&si, sizeof(si), 1, dbg_file);
533           nmask = bfd_get_16(abfd, (unsigned char *)&si);
534           for (ii=0; ii<nmask; ii++)
535             fread(&si, sizeof(si), 1, dbg_file);
536         }
537       break;
538     case N_SYM_LBRAC:
539       fread(&li, sizeof(li), 1, dbg_file);
540       symbuf->n_value = bfd_get_32(abfd, (unsigned char *)&li);
541       break;
542     case N_SYM_RBRAC:
543       fread(&li, sizeof(li), 1, dbg_file);
544       symbuf->n_value = bfd_get_32(abfd, (unsigned char *)&li);
545       break;
546     case N_SYM_SE:
547       break;
548     }
549     return 1;
550 }
551 \f
552 /* Initializes storage for all of the partial symbols that will be
553    created by read_dbx_symtab and subsidiaries.  */
554
555 static void
556 init_psymbol_list (objfile)
557      struct objfile *objfile;
558 {
559   /* Free any previously allocated psymbol lists.  */
560   if (objfile -> global_psymbols.list)
561     mfree (objfile -> md, (PTR)objfile -> global_psymbols.list);
562   if (objfile -> static_psymbols.list)
563     mfree (objfile -> md, (PTR)objfile -> static_psymbols.list);
564
565   /* Current best guess is that there are approximately a twentieth
566      of the total symbols (in a debugging file) are global or static
567      oriented symbols */
568   objfile -> global_psymbols.size = DBX_SYMCOUNT (objfile) / 10;
569   objfile -> static_psymbols.size = DBX_SYMCOUNT (objfile) / 10;
570   objfile -> global_psymbols.next = objfile -> global_psymbols.list = (struct partial_symbol *)
571     xmmalloc (objfile -> md, objfile -> global_psymbols.size * sizeof (struct partial_symbol));
572   objfile -> static_psymbols.next = objfile -> static_psymbols.list = (struct partial_symbol *)
573     xmmalloc (objfile -> md, objfile -> static_psymbols.size * sizeof (struct partial_symbol));
574 }
575
576 /* Given pointers to an a.out symbol table in core containing dbx
577    style data, setup partial_symtab's describing each source file for
578    which debugging information is available.
579    SYMFILE_NAME is the name of the file we are reading from
580    and SECTION_OFFSETS is the set of offsets for the various sections
581    of the file (a set of zeros if the mainline program).  */
582
583 static void
584 read_os9k_psymtab (section_offsets, objfile, text_addr, text_size)
585      struct section_offsets *section_offsets;
586      struct objfile *objfile;
587      CORE_ADDR text_addr;
588      int text_size;
589 {
590   register struct internal_symstruct *bufp = 0; /* =0 avoids gcc -Wall glitch*/
591   register char *namestring;
592   int nsl;
593   int past_first_source_file = 0;
594   CORE_ADDR last_o_file_start = 0;
595   struct cleanup *back_to;
596   bfd *abfd;
597   FILE *fp;
598
599   /* End of the text segment of the executable file.  */
600   static CORE_ADDR end_of_text_addr;
601
602   /* Current partial symtab */
603   static struct partial_symtab *pst = 0;
604
605   /* List of current psymtab's include files */
606   char **psymtab_include_list;
607   int includes_allocated;
608   int includes_used;
609
610   /* Index within current psymtab dependency list */
611   struct partial_symtab **dependency_list;
612   int dependencies_used, dependencies_allocated;
613
614   includes_allocated = 30;
615   includes_used = 0;
616   psymtab_include_list = (char **) alloca (includes_allocated *
617                                            sizeof (char *));
618
619   dependencies_allocated = 30;
620   dependencies_used = 0;
621   dependency_list =
622     (struct partial_symtab **) alloca (dependencies_allocated *
623                                        sizeof (struct partial_symtab *));
624
625   last_source_file = NULL;
626
627 #ifdef END_OF_TEXT_DEFAULT
628   end_of_text_addr = END_OF_TEXT_DEFAULT;
629 #else
630   end_of_text_addr = text_addr + section_offsets->offsets[SECT_OFF_TEXT]
631                                + text_size;     /* Relocate */
632 #endif
633
634   abfd = objfile->obfd;
635   fp = objfile->auxf2; 
636                 
637   fread(&dbghdr.sync, sizeof(dbghdr.sync), 1, fp);
638   fread(&dbghdr.rev, sizeof(dbghdr.rev), 1, fp);
639   fread(&dbghdr.crc, sizeof(dbghdr.crc), 1, fp);
640   fread(&dbghdr.os, sizeof(dbghdr.os), 1, fp);
641   fread(&dbghdr.cpu, sizeof(dbghdr.cpu), 1, fp);
642   SWAP_DBGHDR(&dbghdr, abfd);      
643
644   symnum = 0;
645   while(1)
646     {
647     int ret;
648     long cursymoffset;
649
650       /* Get the symbol for this run and pull out some info */
651       QUIT;     /* allow this to be interruptable */
652       cursymoffset = ftell(objfile->auxf2);
653       ret = fill_sym(objfile->auxf2, abfd);
654       if (ret <= 0) break;
655       else symnum++;
656       bufp = symbuf;
657
658       /* Special case to speed up readin. */
659       if (bufp->n_type == (short)N_SYM_SLINE) continue;
660
661 #define CUR_SYMBOL_VALUE bufp->n_value
662       /* partial-stab.h */
663
664       switch (bufp->n_type)
665         {
666         char *p;
667
668         case N_SYM_CMPLR:
669           continue;
670
671         case N_SYM_SE:
672           CUR_SYMBOL_VALUE += ANOFFSET(section_offsets, SECT_OFF_TEXT);
673           if (psymfile_depth == 1 && pst)
674             {
675               os9k_end_psymtab (pst, psymtab_include_list, includes_used,
676                        symnum, CUR_SYMBOL_VALUE,
677                        dependency_list, dependencies_used);
678               pst = (struct partial_symtab *) 0;
679               includes_used = 0;
680               dependencies_used = 0;
681             }
682           psymfile_depth--;
683           continue;
684
685         case N_SYM_SYM:         /* Typedef or automatic variable. */
686           namestring = bufp->n_strx;
687           p = (char *) strchr (namestring, ':');
688           if (!p)
689             continue;           /* Not a debugging symbol.   */
690
691           /* Main processing section for debugging symbols which
692              the initial read through the symbol tables needs to worry
693              about.  If we reach this point, the symbol which we are
694              considering is definitely one we are interested in.
695              p must also contain the (valid) index into the namestring
696              which indicates the debugging type symbol.  */
697
698           switch (p[1])
699             {
700             case 'S' :
701               {
702                 unsigned long valu;
703                 enum language tmp_language;
704                 
705                 valu = CUR_SYMBOL_VALUE + 
706                   ANOFFSET (section_offsets, SECT_OFF_TEXT);
707                 past_first_source_file = 1;
708
709                 if (psymfile_depth == 0) {
710                   if (!pst)
711                     pst = os9k_start_psymtab (objfile, section_offsets,
712                                  namestring, valu,
713                                  cursymoffset,
714                                  symnum-1,
715                                  objfile -> global_psymbols.next,
716                                  objfile -> static_psymbols.next);
717                 } else { /* this is a include file */
718                   tmp_language = deduce_language_from_filename (namestring);
719                   if (tmp_language != language_unknown
720                         && (tmp_language != language_c
721                         || psymtab_language != language_cplus))
722                         psymtab_language = tmp_language;
723
724 /*
725                   if (pst && STREQ (namestring, pst->filename))
726                     continue;
727                   {
728                     register int i;
729                     for (i = 0; i < includes_used; i++)
730                       if (STREQ (namestring, psymtab_include_list[i]))
731                         {
732                           i = -1; 
733                           break;
734                         }
735                     if (i == -1)
736                       continue;
737                   }
738 */
739
740                   psymtab_include_list[includes_used++] = namestring;
741                   if (includes_used >= includes_allocated)
742                     {
743                       char **orig = psymtab_include_list;
744
745                       psymtab_include_list = (char **)
746                           alloca ((includes_allocated *= 2) * sizeof (char *));
747                       memcpy ((PTR)psymtab_include_list, (PTR)orig,
748                           includes_used * sizeof (char *));
749                     }
750
751                 }
752                 psymfile_depth++;
753                 continue;
754               }
755
756             case 'v':
757               ADD_PSYMBOL_ADDR_TO_LIST (namestring, p - namestring,
758                                         VAR_NAMESPACE, LOC_STATIC,
759                                         objfile->static_psymbols,
760                                         CUR_SYMBOL_VALUE,
761                                         psymtab_language, objfile);
762               continue;
763             case 'V':
764               ADD_PSYMBOL_ADDR_TO_LIST (namestring, p - namestring,
765                                         VAR_NAMESPACE, LOC_STATIC,
766                                         objfile->global_psymbols,
767                                         CUR_SYMBOL_VALUE,
768                                         psymtab_language, objfile);
769               continue;
770
771             case 'T':
772               if (p != namestring)      /* a name is there, not just :T... */
773                 {
774                   ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
775                                        STRUCT_NAMESPACE, LOC_TYPEDEF,
776                                        objfile->static_psymbols,
777                                        CUR_SYMBOL_VALUE,
778                                        psymtab_language, objfile);
779                   if (p[2] == 't')
780                     {
781                       /* Also a typedef with the same name.  */
782                       ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
783                                            VAR_NAMESPACE, LOC_TYPEDEF,
784                                            objfile->static_psymbols,
785                                            CUR_SYMBOL_VALUE, psymtab_language,
786                                            objfile);
787                       p += 1;
788                     }
789                   /* The semantics of C++ state that "struct foo { ... }"
790                      also defines a typedef for "foo".  Unfortuantely, cfront
791                      never makes the typedef when translating from C++ to C.
792                      We make the typedef here so that "ptype foo" works as
793                      expected for cfront translated code.  */
794                   else if (psymtab_language == language_cplus)
795                    {
796                       /* Also a typedef with the same name.  */
797                       ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
798                                            VAR_NAMESPACE, LOC_TYPEDEF,
799                                            objfile->static_psymbols,
800                                            CUR_SYMBOL_VALUE, psymtab_language,
801                                            objfile);
802                    }
803                 }
804               goto check_enum;
805             case 't':
806               if (p != namestring)      /* a name is there, not just :T... */
807                 {
808                   ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
809                                        VAR_NAMESPACE, LOC_TYPEDEF,
810                                        objfile->static_psymbols,
811                                        CUR_SYMBOL_VALUE,
812                                        psymtab_language, objfile);
813                 }
814             check_enum:
815               /* If this is an enumerated type, we need to
816                  add all the enum constants to the partial symbol
817                  table.  This does not cover enums without names, e.g.
818                  "enum {a, b} c;" in C, but fortunately those are
819                  rare.  There is no way for GDB to find those from the
820                  enum type without spending too much time on it.  Thus
821                  to solve this problem, the compiler needs to put out the
822                  enum in a nameless type.  GCC2 does this.  */
823
824               /* We are looking for something of the form
825                  <name> ":" ("t" | "T") [<number> "="] "e" <size>
826                  {<constant> ":" <value> ","} ";".  */
827
828               /* Skip over the colon and the 't' or 'T'.  */
829               p += 2;
830               /* This type may be given a number.  Also, numbers can come
831                  in pairs like (0,26).  Skip over it.  */
832               while ((*p >= '0' && *p <= '9')
833                      || *p == '(' || *p == ',' || *p == ')'
834                      || *p == '=')
835                 p++;
836
837               if (*p++ == 'e')
838                 {
839                   /* We have found an enumerated type. skip size */
840                   while (*p >= '0' && *p <= '9') p++;
841                   /* According to comments in read_enum_type
842                      a comma could end it instead of a semicolon.
843                      I don't know where that happens.
844                      Accept either.  */
845                   while (*p && *p != ';' && *p != ',')
846                     {
847                       char *q;
848
849                       /* Check for and handle cretinous dbx symbol name
850                          continuation! 
851                       if (*p == '\\')
852                         p = next_symbol_text ();
853                       */
854
855                       /* Point to the character after the name
856                          of the enum constant.  */
857                       for (q = p; *q && *q != ':'; q++)
858                         ;
859                       /* Note that the value doesn't matter for
860                          enum constants in psymtabs, just in symtabs.  */
861                       ADD_PSYMBOL_TO_LIST (p, q - p,
862                                            VAR_NAMESPACE, LOC_CONST,
863                                            objfile->static_psymbols, 0,
864                                            psymtab_language, objfile);
865                       /* Point past the name.  */
866                       p = q;
867                       /* Skip over the value.  */
868                       while (*p && *p != ',')
869                         p++;
870                       /* Advance past the comma.  */
871                       if (*p)
872                         p++;
873                     }
874                 }
875               continue;
876             case 'c':
877               /* Constant, e.g. from "const" in Pascal.  */
878               ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
879                                    VAR_NAMESPACE, LOC_CONST,
880                                    objfile->static_psymbols, CUR_SYMBOL_VALUE,
881                                    psymtab_language, objfile);
882               continue;
883
884             case 'f':
885               CUR_SYMBOL_VALUE += ANOFFSET(section_offsets, SECT_OFF_TEXT);
886               if (pst && pst->textlow == 0)
887                 pst->textlow = CUR_SYMBOL_VALUE;
888
889               ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
890                                    VAR_NAMESPACE, LOC_BLOCK,
891                                    objfile->static_psymbols, CUR_SYMBOL_VALUE,
892                                    psymtab_language, objfile);
893               continue;
894
895             case 'F':
896               CUR_SYMBOL_VALUE += ANOFFSET(section_offsets, SECT_OFF_TEXT);
897               if (pst && pst->textlow == 0)
898                 pst->textlow = CUR_SYMBOL_VALUE;
899
900               ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
901                                    VAR_NAMESPACE, LOC_BLOCK,
902                                    objfile->global_psymbols, CUR_SYMBOL_VALUE,
903                                    psymtab_language, objfile);
904               continue;
905
906             case 'p':
907             case 'l':
908             case 's':
909               continue;
910
911             case ':':
912               /* It is a C++ nested symbol.  We don't need to record it
913                  (I don't think); if we try to look up foo::bar::baz,
914                  then symbols for the symtab containing foo should get
915                  read in, I think.  */
916               /* Someone says sun cc puts out symbols like
917                  /foo/baz/maclib::/usr/local/bin/maclib,
918                  which would get here with a symbol type of ':'.  */
919               continue;
920
921             default:
922               /* Unexpected symbol descriptor.  The second and subsequent stabs
923                  of a continued stab can show up here.  The question is
924                  whether they ever can mimic a normal stab--it would be
925                  nice if not, since we certainly don't want to spend the
926                  time searching to the end of every string looking for
927                  a backslash.  */
928
929               complain (&unknown_symchar_complaint, p[1]);
930               continue;
931             }
932
933         case N_SYM_RBRAC:
934           CUR_SYMBOL_VALUE += ANOFFSET(section_offsets, SECT_OFF_TEXT);
935 #ifdef HANDLE_RBRAC
936           HANDLE_RBRAC(CUR_SYMBOL_VALUE);
937           continue;
938 #endif
939         case N_SYM_LBRAC:
940           continue;
941
942         default:
943           /* If we haven't found it yet, ignore it.  It's probably some
944              new type we don't know about yet.  */
945           complain (&unknown_symtype_complaint,
946                     local_hex_string ((unsigned long) bufp->n_type));
947           continue;
948         }
949     }
950
951   DBX_SYMCOUNT (objfile) = symnum;
952
953   /* If there's stuff to be cleaned up, clean it up.  */
954   if (DBX_SYMCOUNT (objfile) > 0
955 /*FIXME, does this have a bug at start address 0? */
956       && last_o_file_start
957       && objfile -> ei.entry_point < bufp->n_value
958       && objfile -> ei.entry_point >= last_o_file_start)
959     {
960       objfile -> ei.entry_file_lowpc = last_o_file_start;
961       objfile -> ei.entry_file_highpc = bufp->n_value;
962     }
963
964   if (pst)
965     {
966       os9k_end_psymtab (pst, psymtab_include_list, includes_used,
967                    symnum, end_of_text_addr,
968                    dependency_list, dependencies_used);
969     }
970 /*
971   do_cleanups (back_to);
972 */
973 }
974
975 /* Allocate and partially fill a partial symtab.  It will be
976    completely filled at the end of the symbol list.
977
978    SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
979    is the address relative to which its symbols are (incremental) or 0
980    (normal). */
981
982
983 static struct partial_symtab *
984 os9k_start_psymtab (objfile, section_offsets,
985                filename, textlow, ldsymoff,ldsymcnt,  global_syms, static_syms)
986      struct objfile *objfile;
987      struct section_offsets *section_offsets;
988      char *filename;
989      CORE_ADDR textlow;
990      int ldsymoff;
991      int ldsymcnt;
992      struct partial_symbol *global_syms;
993      struct partial_symbol *static_syms;
994 {
995   struct partial_symtab *result =
996       start_psymtab_common(objfile, section_offsets,
997                            filename, textlow, global_syms, static_syms);
998
999   result->read_symtab_private = (char *)
1000     obstack_alloc (&objfile -> psymbol_obstack, sizeof (struct symloc));
1001
1002   LDSYMOFF(result) = ldsymoff;
1003   LDSYMCNT(result) = ldsymcnt;
1004   result->read_symtab = os9k_psymtab_to_symtab;
1005
1006   /* Deduce the source language from the filename for this psymtab. */
1007   psymtab_language = deduce_language_from_filename (filename);
1008   return result;
1009 }
1010
1011 /* Close off the current usage of PST.  
1012    Returns PST or NULL if the partial symtab was empty and thrown away.
1013    FIXME:  List variables and peculiarities of same.  */
1014
1015 static struct partial_symtab *
1016 os9k_end_psymtab (pst, include_list, num_includes, capping_symbol_cnt,
1017              capping_text, dependency_list, number_dependencies)
1018      struct partial_symtab *pst;
1019      char **include_list;
1020      int num_includes;
1021      int capping_symbol_cnt;
1022      CORE_ADDR capping_text;
1023      struct partial_symtab **dependency_list;
1024      int number_dependencies;
1025 /*     struct partial_symbol *capping_global, *capping_static;*/
1026 {
1027   int i;
1028   struct partial_symtab *p1;
1029   struct objfile *objfile = pst -> objfile;
1030
1031   if (capping_symbol_cnt != -1)
1032       LDSYMCNT(pst) = capping_symbol_cnt - LDSYMCNT(pst);
1033
1034   /* Under Solaris, the N_SO symbols always have a value of 0,
1035      instead of the usual address of the .o file.  Therefore,
1036      we have to do some tricks to fill in texthigh and textlow.
1037      The first trick is in partial-stab.h: if we see a static
1038      or global function, and the textlow for the current pst
1039      is still 0, then we use that function's address for 
1040      the textlow of the pst.
1041
1042      Now, to fill in texthigh, we remember the last function seen
1043      in the .o file (also in partial-stab.h).  Also, there's a hack in
1044      bfd/elf.c and gdb/elfread.c to pass the ELF st_size field
1045      to here via the misc_info field.  Therefore, we can fill in
1046      a reliable texthigh by taking the address plus size of the
1047      last function in the file.
1048
1049      Unfortunately, that does not cover the case where the last function
1050      in the file is static.  See the paragraph below for more comments
1051      on this situation.
1052
1053      Finally, if we have a valid textlow for the current file, we run
1054      down the partial_symtab_list filling in previous texthighs that
1055      are still unknown.  */
1056
1057   if (pst->texthigh == 0 && last_function_name) {
1058     char *p;
1059     int n;
1060     struct minimal_symbol *minsym;
1061
1062     p = strchr (last_function_name, ':');
1063     if (p == NULL)
1064       p = last_function_name;
1065     n = p - last_function_name;
1066     p = alloca (n + 1);
1067     strncpy (p, last_function_name, n);
1068     p[n] = 0;
1069     
1070     minsym = lookup_minimal_symbol (p, objfile);
1071
1072     if (minsym) {
1073       pst->texthigh = SYMBOL_VALUE_ADDRESS(minsym)+(long)MSYMBOL_INFO(minsym);
1074     } else {
1075       /* This file ends with a static function, and it's
1076          difficult to imagine how hard it would be to track down
1077          the elf symbol.  Luckily, most of the time no one will notice,
1078          since the next file will likely be compiled with -g, so
1079          the code below will copy the first fuction's start address 
1080          back to our texthigh variable.  (Also, if this file is the
1081          last one in a dynamically linked program, texthigh already
1082          has the right value.)  If the next file isn't compiled
1083          with -g, then the last function in this file winds up owning
1084          all of the text space up to the next -g file, or the end (minus
1085          shared libraries).  This only matters for single stepping,
1086          and even then it will still work, except that it will single
1087          step through all of the covered functions, instead of setting
1088          breakpoints around them as it usualy does.  This makes it
1089          pretty slow, but at least it doesn't fail.
1090
1091          We can fix this with a fairly big change to bfd, but we need
1092          to coordinate better with Cygnus if we want to do that.  FIXME.  */
1093     }
1094     last_function_name = NULL;
1095   }
1096
1097   /* this test will be true if the last .o file is only data */
1098   if (pst->textlow == 0)
1099     pst->textlow = pst->texthigh;
1100
1101   /* If we know our own starting text address, then walk through all other
1102      psymtabs for this objfile, and if any didn't know their ending text
1103      address, set it to our starting address.  Take care to not set our
1104      own ending address to our starting address, nor to set addresses on
1105      `dependency' files that have both textlow and texthigh zero.  */
1106   if (pst->textlow) {
1107     ALL_OBJFILE_PSYMTABS (objfile, p1) {
1108       if (p1->texthigh == 0  && p1->textlow != 0 && p1 != pst) {
1109         p1->texthigh = pst->textlow;
1110         /* if this file has only data, then make textlow match texthigh */
1111         if (p1->textlow == 0)
1112           p1->textlow = p1->texthigh;
1113       }
1114     }
1115   }
1116
1117   /* End of kludge for patching Solaris textlow and texthigh.  */
1118
1119   pst->n_global_syms =
1120     objfile->global_psymbols.next - (objfile->global_psymbols.list + pst->globals_offset);
1121   pst->n_static_syms =
1122     objfile->static_psymbols.next - (objfile->static_psymbols.list + pst->statics_offset);
1123
1124   pst->number_of_dependencies = number_dependencies;
1125   if (number_dependencies)
1126     {
1127       pst->dependencies = (struct partial_symtab **)
1128         obstack_alloc (&objfile->psymbol_obstack,
1129                        number_dependencies * sizeof (struct partial_symtab *));
1130       memcpy (pst->dependencies, dependency_list,
1131              number_dependencies * sizeof (struct partial_symtab *));
1132     }
1133   else
1134     pst->dependencies = 0;
1135
1136   for (i = 0; i < num_includes; i++)
1137     {
1138       struct partial_symtab *subpst =
1139         allocate_psymtab (include_list[i], objfile);
1140
1141       subpst->section_offsets = pst->section_offsets;
1142       subpst->read_symtab_private =
1143           (char *) obstack_alloc (&objfile->psymbol_obstack,
1144                                   sizeof (struct symloc));
1145       LDSYMOFF(subpst) =
1146         LDSYMCNT(subpst) =
1147           subpst->textlow =
1148             subpst->texthigh = 0;
1149
1150       /* We could save slight bits of space by only making one of these,
1151          shared by the entire set of include files.  FIXME-someday.  */
1152       subpst->dependencies = (struct partial_symtab **)
1153         obstack_alloc (&objfile->psymbol_obstack,
1154                        sizeof (struct partial_symtab *));
1155       subpst->dependencies[0] = pst;
1156       subpst->number_of_dependencies = 1;
1157
1158       subpst->globals_offset =
1159         subpst->n_global_syms =
1160           subpst->statics_offset =
1161             subpst->n_static_syms = 0;
1162
1163       subpst->readin = 0;
1164       subpst->symtab = 0;
1165       subpst->read_symtab = pst->read_symtab;
1166     }
1167
1168   sort_pst_symbols (pst);
1169
1170   /* If there is already a psymtab or symtab for a file of this name, 
1171      remove it.
1172      (If there is a symtab, more drastic things also happen.)
1173      This happens in VxWorks.  */
1174   free_named_symtabs (pst->filename);
1175
1176   if (num_includes == 0
1177    && number_dependencies == 0
1178    && pst->n_global_syms == 0
1179    && pst->n_static_syms == 0) {
1180     /* Throw away this psymtab, it's empty.  We can't deallocate it, since
1181        it is on the obstack, but we can forget to chain it on the list.  */
1182     struct partial_symtab *prev_pst;
1183
1184     /* First, snip it out of the psymtab chain */
1185
1186     if (pst->objfile->psymtabs == pst)
1187       pst->objfile->psymtabs = pst->next;
1188     else
1189       for (prev_pst = pst->objfile->psymtabs; prev_pst; prev_pst = pst->next)
1190         if (prev_pst->next == pst)
1191           prev_pst->next = pst->next;
1192
1193     /* Next, put it on a free list for recycling */
1194     pst->next = pst->objfile->free_psymtabs;
1195     pst->objfile->free_psymtabs = pst;
1196
1197     /* Indicate that psymtab was thrown away.  */
1198     pst = (struct partial_symtab *)NULL;
1199   }
1200   return pst;
1201 }
1202 \f
1203 static void
1204 os9k_psymtab_to_symtab_1 (pst)
1205      struct partial_symtab *pst;
1206 {
1207   struct cleanup *old_chain;
1208   int i;
1209   
1210   if (!pst)
1211     return;
1212
1213   if (pst->readin)
1214     {
1215       fprintf_unfiltered (gdb_stderr, "Psymtab for %s already read in.  Shouldn't happen.\n",
1216                pst->filename);
1217       return;
1218     }
1219
1220   /* Read in all partial symtabs on which this one is dependent */
1221   for (i = 0; i < pst->number_of_dependencies; i++)
1222     if (!pst->dependencies[i]->readin)
1223       {
1224         /* Inform about additional files that need to be read in.  */
1225         if (info_verbose)
1226           {
1227             fputs_filtered (" ", gdb_stdout);
1228             wrap_here ("");
1229             fputs_filtered ("and ", gdb_stdout);
1230             wrap_here ("");
1231             printf_filtered ("%s...", pst->dependencies[i]->filename);
1232             wrap_here ("");             /* Flush output */
1233             gdb_flush (gdb_stdout);
1234           }
1235         os9k_psymtab_to_symtab_1 (pst->dependencies[i]);
1236       }
1237
1238   if (LDSYMCNT(pst))            /* Otherwise it's a dummy */
1239     {
1240       /* Init stuff necessary for reading in symbols */
1241       stabsread_init ();
1242       buildsym_init ();
1243       old_chain = make_cleanup (really_free_pendings, 0);
1244
1245       /* Read in this file's symbols */
1246       os9k_read_ofile_symtab (pst);
1247       sort_symtab_syms (pst->symtab);
1248       do_cleanups (old_chain);
1249     }
1250
1251   pst->readin = 1;
1252 }
1253
1254 /* Read in all of the symbols for a given psymtab for real.
1255    Be verbose about it if the user wants that.  */
1256
1257 static void
1258 os9k_psymtab_to_symtab (pst)
1259      struct partial_symtab *pst;
1260 {
1261   bfd *sym_bfd;
1262
1263   if (!pst)
1264     return;
1265
1266   if (pst->readin)
1267     {
1268       fprintf_unfiltered (gdb_stderr, "Psymtab for %s already read in.  Shouldn't happen.\n",
1269                pst->filename);
1270       return;
1271     }
1272
1273   if (LDSYMCNT(pst) || pst->number_of_dependencies)
1274     {
1275       /* Print the message now, before reading the string table,
1276          to avoid disconcerting pauses.  */
1277       if (info_verbose)
1278         {
1279           printf_filtered ("Reading in symbols for %s...", pst->filename);
1280           gdb_flush (gdb_stdout);
1281         }
1282
1283       sym_bfd = pst->objfile->obfd;
1284       os9k_psymtab_to_symtab_1 (pst);
1285
1286       /* Match with global symbols.  This only needs to be done once,
1287          after all of the symtabs and dependencies have been read in.   */
1288       scan_file_globals (pst->objfile);
1289
1290       /* Finish up the debug error message.  */
1291       if (info_verbose)
1292         printf_filtered ("done.\n");
1293     }
1294 }
1295
1296 /* Read in a defined section of a specific object file's symbols. */
1297 static void
1298 os9k_read_ofile_symtab (pst)
1299      struct partial_symtab *pst;
1300 {
1301   register struct internal_symstruct *bufp;
1302   unsigned char type;
1303   unsigned max_symnum;
1304   register bfd *abfd;
1305   struct objfile *objfile;
1306   int sym_offset;               /* Offset to start of symbols to read */
1307   CORE_ADDR text_offset;        /* Start of text segment for symbols */
1308   int text_size;                /* Size of text segment for symbols */
1309   struct section_offsets *section_offsets;
1310   FILE *dbg_file;
1311
1312   objfile = pst->objfile;
1313   sym_offset = LDSYMOFF(pst);
1314   max_symnum = LDSYMCNT(pst);
1315   text_offset = pst->textlow;
1316   text_size = pst->texthigh - pst->textlow;
1317   section_offsets = pst->section_offsets;
1318
1319   current_objfile = objfile;
1320   subfile_stack = NULL;
1321   last_source_file = NULL;
1322
1323   abfd = objfile->obfd;
1324   dbg_file = objfile->auxf2;
1325
1326 #if 0
1327   /* It is necessary to actually read one symbol *before* the start
1328      of this symtab's symbols, because the GCC_COMPILED_FLAG_SYMBOL
1329      occurs before the N_SO symbol.
1330      Detecting this in read_dbx_symtab
1331      would slow down initial readin, so we look for it here instead. */
1332   if (!processing_acc_compilation && sym_offset >= (int)symbol_size)
1333     {
1334       fseek (objefile->auxf2, sym_offset, SEEK_CUR);
1335       fill_sym(objfile->auxf2, abfd);
1336       bufp = symbuf;
1337
1338       processing_gcc_compilation = 0;
1339       if (bufp->n_type == N_TEXT)
1340         {
1341           if (STREQ (namestring, GCC_COMPILED_FLAG_SYMBOL))
1342             processing_gcc_compilation = 1;
1343           else if (STREQ (namestring, GCC2_COMPILED_FLAG_SYMBOL))
1344             processing_gcc_compilation = 2;
1345         }
1346
1347       /* Try to select a C++ demangling based on the compilation unit
1348          producer. */
1349
1350       if (processing_gcc_compilation)
1351         {
1352           if (AUTO_DEMANGLING)
1353             {
1354               set_demangling_style (GNU_DEMANGLING_STYLE_STRING);
1355             }
1356         }
1357     }
1358   else
1359     {
1360       /* The N_SO starting this symtab is the first symbol, so we
1361          better not check the symbol before it.  I'm not this can
1362          happen, but it doesn't hurt to check for it.  */
1363       bfd_seek (symfile_bfd, sym_offset, SEEK_CUR);
1364       processing_gcc_compilation = 0;
1365     }
1366 #endif /* 0 */
1367
1368   fseek(dbg_file, (long)sym_offset, 0);
1369 /*
1370   if (bufp->n_type != (unsigned char)N_SYM_SYM)
1371     error("First symbol in segment of executable not a source symbol");
1372 */
1373
1374   for (symnum = 0; symnum < max_symnum; symnum++)
1375     {
1376       QUIT;                     /* Allow this to be interruptable */
1377       fill_sym(dbg_file, abfd);
1378       bufp = symbuf;
1379       type = bufp->n_type;
1380
1381       os9k_process_one_symbol (type, bufp->n_desc, bufp->n_value,
1382               bufp->n_strx, section_offsets, objfile);
1383
1384       /* We skip checking for a new .o or -l file; that should never
1385          happen in this routine. */
1386 #if 0
1387       else if (type == N_TEXT)
1388         {
1389           /* I don't think this code will ever be executed, because
1390              the GCC_COMPILED_FLAG_SYMBOL usually is right before
1391              the N_SO symbol which starts this source file.
1392              However, there is no reason not to accept
1393              the GCC_COMPILED_FLAG_SYMBOL anywhere.  */
1394
1395           if (STREQ (namestring, GCC_COMPILED_FLAG_SYMBOL))
1396             processing_gcc_compilation = 1;
1397           else if (STREQ (namestring, GCC2_COMPILED_FLAG_SYMBOL))
1398             processing_gcc_compilation = 2;
1399
1400           if (AUTO_DEMANGLING)
1401             {
1402               set_demangling_style (GNU_DEMANGLING_STYLE_STRING);
1403             }
1404         }
1405       else if (type & N_EXT || type == (unsigned char)N_TEXT
1406                || type == (unsigned char)N_NBTEXT
1407                ) {
1408           /* Global symbol: see if we came across a dbx defintion for
1409              a corresponding symbol.  If so, store the value.  Remove
1410              syms from the chain when their values are stored, but
1411              search the whole chain, as there may be several syms from
1412              different files with the same name. */
1413           /* This is probably not true.  Since the files will be read
1414              in one at a time, each reference to a global symbol will
1415              be satisfied in each file as it appears. So we skip this
1416              section. */
1417           ;
1418         }
1419 #endif /* 0 */
1420     }
1421
1422   current_objfile = NULL;
1423
1424   /* In a Solaris elf file, this variable, which comes from the
1425      value of the N_SO symbol, will still be 0.  Luckily, text_offset,
1426      which comes from pst->textlow is correct. */
1427   if (last_source_start_addr == 0)
1428     last_source_start_addr = text_offset;
1429   pst->symtab = end_symtab (text_offset + text_size, 0, 0, objfile,
1430                             SECT_OFF_TEXT);
1431   end_stabs ();
1432 }
1433
1434 \f
1435 /* This handles a single symbol from the symbol-file, building symbols
1436    into a GDB symtab.  It takes these arguments and an implicit argument.
1437
1438    TYPE is the type field of the ".stab" symbol entry.
1439    DESC is the desc field of the ".stab" entry.
1440    VALU is the value field of the ".stab" entry.
1441    NAME is the symbol name, in our address space.
1442    SECTION_OFFSETS is a set of amounts by which the sections of this object
1443           file were relocated when it was loaded into memory.
1444           All symbols that refer
1445           to memory locations need to be offset by these amounts.
1446    OBJFILE is the object file from which we are reading symbols.
1447                It is used in end_symtab.  */
1448
1449 static void
1450 os9k_process_one_symbol (type, desc, valu, name, section_offsets, objfile)
1451      int type, desc;
1452      CORE_ADDR valu;
1453      char *name;
1454      struct section_offsets *section_offsets;
1455      struct objfile *objfile;
1456 {
1457   register struct context_stack *new;
1458   /* The stab type used for the definition of the last function.
1459      N_STSYM or N_GSYM for SunOS4 acc; N_FUN for other compilers.  */
1460   static int function_stab_type = 0;
1461
1462 #if 0
1463   /* Something is wrong if we see real data before
1464      seeing a source file name.  */
1465   if (last_source_file == NULL && type != (unsigned char)N_SO)
1466     {
1467       /* Ignore any symbols which appear before an N_SO symbol.  Currently
1468          no one puts symbols there, but we should deal gracefully with the
1469          case.  A complain()t might be in order (if !IGNORE_SYMBOL (type)),
1470          but this should not be an error ().  */
1471       return;
1472     }
1473 #endif /* 0 */
1474
1475   switch (type)
1476     {
1477     case N_SYM_LBRAC:
1478       /* On most machines, the block addresses are relative to the
1479          N_SO, the linker did not relocate them (sigh).  */
1480       valu += ANOFFSET (section_offsets, SECT_OFF_TEXT); 
1481       new = push_context (desc, valu);
1482       break;
1483
1484     case N_SYM_RBRAC:
1485       valu += ANOFFSET (section_offsets, SECT_OFF_TEXT); 
1486       new = pop_context();
1487
1488 #if !defined (OS9K_VARIABLES_INSIDE_BLOCK)
1489 #define OS9K_VARIABLES_INSIDE_BLOCK(desc, gcc_p) 1
1490 #endif
1491
1492       if (!OS9K_VARIABLES_INSIDE_BLOCK(desc, processing_gcc_compilation))
1493         local_symbols = new->locals;
1494
1495       if (context_stack_depth > 1)
1496         {
1497           /* This is not the outermost LBRAC...RBRAC pair in the function,
1498              its local symbols preceded it, and are the ones just recovered
1499              from the context stack.  Define the block for them (but don't
1500              bother if the block contains no symbols.  Should we complain
1501              on blocks without symbols?  I can't think of any useful purpose
1502              for them).  */
1503           if (local_symbols != NULL)
1504             {
1505               /* Muzzle a compiler bug that makes end < start.  (which
1506                  compilers?  Is this ever harmful?).  */
1507               if (new->start_addr > valu)
1508                 {
1509                   complain (&lbrac_rbrac_complaint);
1510                   new->start_addr = valu;
1511                 }
1512               /* Make a block for the local symbols within.  */
1513               finish_block (0, &local_symbols, new->old_blocks,
1514                             new->start_addr, valu, objfile);
1515             }
1516         }
1517       else
1518         {
1519           if (context_stack_depth == 0)
1520             {
1521               within_function = 0;
1522               /* Make a block for the local symbols within.  */
1523               finish_block (new->name, &local_symbols, new->old_blocks,
1524                         new->start_addr, valu, objfile);
1525             }
1526           else
1527             {
1528               /* attach local_symbols to the end of new->locals */
1529               if (!new->locals) new->locals = local_symbols;
1530               else {
1531                 struct pending *p;
1532
1533                 p = new->locals;
1534                 while (p->next) p = p->next; 
1535                 p->next = local_symbols;
1536               }
1537             }
1538         }
1539
1540       if (OS9K_VARIABLES_INSIDE_BLOCK(desc, processing_gcc_compilation))
1541         /* Now pop locals of block just finished.  */
1542         local_symbols = new->locals;
1543       break;
1544
1545
1546     case N_SYM_SLINE:
1547       /* This type of "symbol" really just records
1548          one line-number -- core-address correspondence.
1549          Enter it in the line list for this symbol table.  */
1550       /* Relocate for dynamic loading and for ELF acc fn-relative syms.  */
1551       valu += ANOFFSET (section_offsets, SECT_OFF_TEXT); 
1552       record_line (current_subfile, (int)name, valu);
1553       break;
1554
1555     /* The following symbol types need to have the appropriate offset added
1556        to their value; then we process symbol definitions in the name.  */
1557     case N_SYM_SYM:
1558
1559       if (name)
1560         {
1561           char deftype;
1562           char *dirn, *n;
1563           char *p = strchr (name, ':');
1564           if (p == NULL)
1565             deftype = '\0';
1566           else
1567             deftype = p[1];
1568
1569
1570           switch (deftype)
1571             {
1572             case 'S':
1573               valu += ANOFFSET (section_offsets, SECT_OFF_TEXT);
1574               n = strrchr(name, '/');
1575               if (n != NULL) {
1576                 *n = '\0';
1577                 n++;
1578                 dirn = name;
1579               } else {
1580                 n = name;
1581                 dirn = NULL;
1582               }
1583               *p = '\0';
1584               if (symfile_depth++ == 0) {
1585                 if (last_source_file) {
1586                   end_symtab (valu, 0, 0, objfile, SECT_OFF_TEXT);
1587                   end_stabs ();
1588                 }
1589                 start_stabs ();
1590                 os9k_stabs = 1;
1591                 start_symtab (n, dirn, valu);
1592               } else {
1593                 push_subfile();
1594                 start_subfile (n, dirn!=NULL ? dirn : current_subfile->dirname);
1595               }
1596               break;
1597
1598             case 'f':
1599             case 'F':
1600               valu += ANOFFSET (section_offsets, SECT_OFF_TEXT);
1601               function_stab_type = type;
1602
1603               within_function = 1;
1604               new = push_context (0, valu);
1605               new->name = define_symbol (valu, name, desc, type, objfile);
1606               break;
1607
1608             case 'V':
1609             case 'v':
1610               valu += ANOFFSET (section_offsets, SECT_OFF_DATA);
1611               define_symbol (valu, name, desc, type, objfile);
1612               break;
1613
1614             default:
1615               define_symbol (valu, name, desc, type, objfile);
1616               break;
1617             }
1618         }
1619       break;
1620
1621     case N_SYM_SE:
1622         if (--symfile_depth != 0)
1623           start_subfile(pop_subfile(), current_subfile->dirname);
1624       break;
1625
1626     default:
1627       complain (&unknown_symtype_complaint,
1628                 local_hex_string((unsigned long) type));
1629       /* FALLTHROUGH */
1630       break;
1631
1632     case N_SYM_CMPLR:
1633       break;
1634     }
1635   previous_stab_code = type;
1636 }
1637 \f
1638 /* Parse the user's idea of an offset for dynamic linking, into our idea
1639    of how to represent it for fast symbol reading.  */
1640
1641 static struct section_offsets *
1642 os9k_symfile_offsets (objfile, addr)
1643      struct objfile *objfile;
1644      CORE_ADDR addr;
1645 {
1646   struct section_offsets *section_offsets;
1647   int i;
1648
1649   objfile->num_sections = SECT_OFF_MAX;
1650   section_offsets = (struct section_offsets *)
1651     obstack_alloc (&objfile -> psymbol_obstack,
1652                    sizeof (struct section_offsets)
1653                    + sizeof (section_offsets->offsets) * (SECT_OFF_MAX-1));
1654
1655   for (i = 0; i < SECT_OFF_MAX; i++)
1656     ANOFFSET (section_offsets, i) = addr;
1657   
1658   return section_offsets;
1659 }
1660 \f
1661 static struct sym_fns os9k_sym_fns =
1662 {
1663   bfd_target_os9k_flavour,
1664   os9k_new_init,        /* sym_new_init: init anything gbl to entire symtab */
1665   os9k_symfile_init,    /* sym_init: read initial info, setup for sym_read() */
1666   os9k_symfile_read,    /* sym_read: read a symbol file into symtab */
1667   os9k_symfile_finish,  /* sym_finish: finished with file, cleanup */
1668   os9k_symfile_offsets, /* sym_offsets: parse user's offsets to internal form*/
1669   NULL                  /* next: pointer to next struct sym_fns */
1670 };
1671
1672 void
1673 _initialize_os9kread ()
1674 {
1675   add_symtab_fns(&os9k_sym_fns);
1676 }
This page took 0.116691 seconds and 4 git commands to generate.