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