Home | History | Annotate | Line # | Download | only in gdb
dbxread.c revision 1.6
      1 /* Read dbx symbol tables and convert to internal format, for GDB.
      2    Copyright (C) 1986-2016 Free Software Foundation, Inc.
      3 
      4    This file is part of GDB.
      5 
      6    This program is free software; you can redistribute it and/or modify
      7    it under the terms of the GNU General Public License as published by
      8    the Free Software Foundation; either version 3 of the License, or
      9    (at your option) any later version.
     10 
     11    This program is distributed in the hope that it will be useful,
     12    but WITHOUT ANY WARRANTY; without even the implied warranty of
     13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     14    GNU General Public License for more details.
     15 
     16    You should have received a copy of the GNU General Public License
     17    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
     18 
     19 /* This module provides three functions: dbx_symfile_init,
     20    which initializes to read a symbol file; dbx_new_init, which
     21    discards existing cached information when all symbols are being
     22    discarded; and dbx_symfile_read, which reads a symbol table
     23    from a file.
     24 
     25    dbx_symfile_read only does the minimum work necessary for letting the
     26    user "name" things symbolically; it does not read the entire symtab.
     27    Instead, it reads the external and static symbols and puts them in partial
     28    symbol tables.  When more extensive information is requested of a
     29    file, the corresponding partial symbol table is mutated into a full
     30    fledged symbol table by going back and reading the symbols
     31    for real.  dbx_psymtab_to_symtab() is the function that does this */
     32 
     33 #include "defs.h"
     34 #if defined(__CYGNUSCLIB__)
     35 #include <sys/types.h>
     36 #include <fcntl.h>
     37 #endif
     38 
     39 #include "gdb_obstack.h"
     40 #include <sys/stat.h>
     41 #include "symtab.h"
     42 #include "breakpoint.h"
     43 #include "target.h"
     44 #include "gdbcore.h"		/* for bfd stuff */
     45 #include "libaout.h"		/* FIXME Secret internal BFD stuff for a.out */
     46 #include "filenames.h"
     47 #include "objfiles.h"
     48 #include "buildsym.h"
     49 #include "stabsread.h"
     50 #include "gdb-stabs.h"
     51 #include "demangle.h"
     52 #include "complaints.h"
     53 #include "cp-abi.h"
     54 #include "cp-support.h"
     55 #include "psympriv.h"
     56 #include "block.h"
     57 
     58 #include "aout/aout64.h"
     59 #include "aout/stab_gnu.h"	/* We always use GNU stabs, not
     60 				   native, now.  */
     61 
     62 
     64 /* Key for dbx-associated data.  */
     65 
     66 const struct objfile_data *dbx_objfile_data_key;
     67 
     68 /* We put a pointer to this structure in the read_symtab_private field
     69    of the psymtab.  */
     70 
     71 struct symloc
     72   {
     73     /* Offset within the file symbol table of first local symbol for this
     74        file.  */
     75 
     76     int ldsymoff;
     77 
     78     /* Length (in bytes) of the section of the symbol table devoted to
     79        this file's symbols (actually, the section bracketed may contain
     80        more than just this file's symbols).  If ldsymlen is 0, the only
     81        reason for this thing's existence is the dependency list.  Nothing
     82        else will happen when it is read in.  */
     83 
     84     int ldsymlen;
     85 
     86     /* The size of each symbol in the symbol file (in external form).  */
     87 
     88     int symbol_size;
     89 
     90     /* Further information needed to locate the symbols if they are in
     91        an ELF file.  */
     92 
     93     int symbol_offset;
     94     int string_offset;
     95     int file_string_offset;
     96   };
     97 
     98 #define LDSYMOFF(p) (((struct symloc *)((p)->read_symtab_private))->ldsymoff)
     99 #define LDSYMLEN(p) (((struct symloc *)((p)->read_symtab_private))->ldsymlen)
    100 #define SYMLOC(p) ((struct symloc *)((p)->read_symtab_private))
    101 #define SYMBOL_SIZE(p) (SYMLOC(p)->symbol_size)
    102 #define SYMBOL_OFFSET(p) (SYMLOC(p)->symbol_offset)
    103 #define STRING_OFFSET(p) (SYMLOC(p)->string_offset)
    104 #define FILE_STRING_OFFSET(p) (SYMLOC(p)->file_string_offset)
    105 
    106 
    108 /* The objfile we are currently reading.  */
    109 
    110 static struct objfile *dbxread_objfile;
    111 
    112 /* Remember what we deduced to be the source language of this psymtab.  */
    113 
    114 static enum language psymtab_language = language_unknown;
    115 
    116 /* The BFD for this file -- implicit parameter to next_symbol_text.  */
    117 
    118 static bfd *symfile_bfd;
    119 
    120 /* The size of each symbol in the symbol file (in external form).
    121    This is set by dbx_symfile_read when building psymtabs, and by
    122    dbx_psymtab_to_symtab when building symtabs.  */
    123 
    124 static unsigned symbol_size;
    125 
    126 /* This is the offset of the symbol table in the executable file.  */
    127 
    128 static unsigned symbol_table_offset;
    129 
    130 /* This is the offset of the string table in the executable file.  */
    131 
    132 static unsigned string_table_offset;
    133 
    134 /* For elf+stab executables, the n_strx field is not a simple index
    135    into the string table.  Instead, each .o file has a base offset in
    136    the string table, and the associated symbols contain offsets from
    137    this base.  The following two variables contain the base offset for
    138    the current and next .o files.  */
    139 
    140 static unsigned int file_string_table_offset;
    141 static unsigned int next_file_string_table_offset;
    142 
    143 /* .o and NLM files contain unrelocated addresses which are based at
    144    0.  When non-zero, this flag disables some of the special cases for
    145    Solaris elf+stab text addresses at location 0.  */
    146 
    147 static int symfile_relocatable = 0;
    148 
    149 /* If this is nonzero, N_LBRAC, N_RBRAC, and N_SLINE entries are
    150    relative to the function start address.  */
    151 
    152 static int block_address_function_relative = 0;
    153 
    154 /* The lowest text address we have yet encountered.  This is needed
    156    because in an a.out file, there is no header field which tells us
    157    what address the program is actually going to be loaded at, so we
    158    need to make guesses based on the symbols (which *are* relocated to
    159    reflect the address it will be loaded at).  */
    160 
    161 static CORE_ADDR lowest_text_address;
    162 
    163 /* Non-zero if there is any line number info in the objfile.  Prevents
    164    dbx_end_psymtab from discarding an otherwise empty psymtab.  */
    165 
    166 static int has_line_numbers;
    167 
    168 /* Complaints about the symbols we have encountered.  */
    169 
    170 static void
    171 unknown_symtype_complaint (const char *arg1)
    172 {
    173   complaint (&symfile_complaints, _("unknown symbol type %s"), arg1);
    174 }
    175 
    176 static void
    177 lbrac_mismatch_complaint (int arg1)
    178 {
    179   complaint (&symfile_complaints,
    180 	     _("N_LBRAC/N_RBRAC symbol mismatch at symtab pos %d"), arg1);
    181 }
    182 
    183 static void
    184 repeated_header_complaint (const char *arg1, int arg2)
    185 {
    186   complaint (&symfile_complaints,
    187 	     _("\"repeated\" header file %s not "
    188 	       "previously seen, at symtab pos %d"),
    189 	     arg1, arg2);
    190 }
    191 
    192 /* find_text_range --- find start and end of loadable code sections
    193 
    194    The find_text_range function finds the shortest address range that
    195    encloses all sections containing executable code, and stores it in
    196    objfile's text_addr and text_size members.
    197 
    198    dbx_symfile_read will use this to finish off the partial symbol
    199    table, in some cases.  */
    200 
    201 static void
    202 find_text_range (bfd * sym_bfd, struct objfile *objfile)
    203 {
    204   asection *sec;
    205   int found_any = 0;
    206   CORE_ADDR start = 0;
    207   CORE_ADDR end = 0;
    208 
    209   for (sec = sym_bfd->sections; sec; sec = sec->next)
    210     if (bfd_get_section_flags (sym_bfd, sec) & SEC_CODE)
    211       {
    212 	CORE_ADDR sec_start = bfd_section_vma (sym_bfd, sec);
    213 	CORE_ADDR sec_end = sec_start + bfd_section_size (sym_bfd, sec);
    214 
    215 	if (found_any)
    216 	  {
    217 	    if (sec_start < start)
    218 	      start = sec_start;
    219 	    if (sec_end > end)
    220 	      end = sec_end;
    221 	  }
    222 	else
    223 	  {
    224 	    start = sec_start;
    225 	    end = sec_end;
    226 	  }
    227 
    228 	found_any = 1;
    229       }
    230 
    231   if (!found_any)
    232     error (_("Can't find any code sections in symbol file"));
    233 
    234   DBX_TEXT_ADDR (objfile) = start;
    235   DBX_TEXT_SIZE (objfile) = end - start;
    236 }
    237 
    238 
    240 
    241 /* During initial symbol readin, we need to have a structure to keep
    242    track of which psymtabs have which bincls in them.  This structure
    243    is used during readin to setup the list of dependencies within each
    244    partial symbol table.  */
    245 
    246 struct header_file_location
    247 {
    248   char *name;			/* Name of header file */
    249   int instance;			/* See above */
    250   struct partial_symtab *pst;	/* Partial symtab that has the
    251 				   BINCL/EINCL defs for this file.  */
    252 };
    253 
    254 /* The actual list and controling variables.  */
    255 static struct header_file_location *bincl_list, *next_bincl;
    256 static int bincls_allocated;
    257 
    258 /* Local function prototypes.  */
    259 
    260 extern void _initialize_dbxread (void);
    261 
    262 static void read_ofile_symtab (struct objfile *, struct partial_symtab *);
    263 
    264 static void dbx_read_symtab (struct partial_symtab *self,
    265 			     struct objfile *objfile);
    266 
    267 static void dbx_psymtab_to_symtab_1 (struct objfile *, struct partial_symtab *);
    268 
    269 static void read_dbx_dynamic_symtab (struct objfile *objfile);
    270 
    271 static void read_dbx_symtab (struct objfile *);
    272 
    273 static void free_bincl_list (struct objfile *);
    274 
    275 static struct partial_symtab *find_corresponding_bincl_psymtab (char *, int);
    276 
    277 static void add_bincl_to_list (struct partial_symtab *, char *, int);
    278 
    279 static void init_bincl_list (int, struct objfile *);
    280 
    281 static char *dbx_next_symbol_text (struct objfile *);
    282 
    283 static void fill_symbuf (bfd *);
    284 
    285 static void dbx_symfile_init (struct objfile *);
    286 
    287 static void dbx_new_init (struct objfile *);
    288 
    289 static void dbx_symfile_read (struct objfile *, int);
    290 
    291 static void dbx_symfile_finish (struct objfile *);
    292 
    293 static void record_minimal_symbol (const char *, CORE_ADDR, int,
    294 				   struct objfile *);
    295 
    296 static void add_new_header_file (char *, int);
    297 
    298 static void add_old_header_file (char *, int);
    299 
    300 static void add_this_object_header_file (int);
    301 
    302 static struct partial_symtab *start_psymtab (struct objfile *, char *,
    303 					     CORE_ADDR, int,
    304 					     struct partial_symbol **,
    305 					     struct partial_symbol **);
    306 
    307 /* Free up old header file tables.  */
    308 
    309 void
    310 free_header_files (void)
    311 {
    312   if (this_object_header_files)
    313     {
    314       xfree (this_object_header_files);
    315       this_object_header_files = NULL;
    316     }
    317   n_allocated_this_object_header_files = 0;
    318 }
    319 
    320 /* Allocate new header file tables.  */
    321 
    322 void
    323 init_header_files (void)
    324 {
    325   n_allocated_this_object_header_files = 10;
    326   this_object_header_files = XNEWVEC (int, 10);
    327 }
    328 
    329 /* Add header file number I for this object file
    330    at the next successive FILENUM.  */
    331 
    332 static void
    333 add_this_object_header_file (int i)
    334 {
    335   if (n_this_object_header_files == n_allocated_this_object_header_files)
    336     {
    337       n_allocated_this_object_header_files *= 2;
    338       this_object_header_files
    339 	= (int *) xrealloc ((char *) this_object_header_files,
    340 		       n_allocated_this_object_header_files * sizeof (int));
    341     }
    342 
    343   this_object_header_files[n_this_object_header_files++] = i;
    344 }
    345 
    346 /* Add to this file an "old" header file, one already seen in
    347    a previous object file.  NAME is the header file's name.
    348    INSTANCE is its instance code, to select among multiple
    349    symbol tables for the same header file.  */
    350 
    351 static void
    352 add_old_header_file (char *name, int instance)
    353 {
    354   struct header_file *p = HEADER_FILES (dbxread_objfile);
    355   int i;
    356 
    357   for (i = 0; i < N_HEADER_FILES (dbxread_objfile); i++)
    358     if (filename_cmp (p[i].name, name) == 0 && instance == p[i].instance)
    359       {
    360 	add_this_object_header_file (i);
    361 	return;
    362       }
    363   repeated_header_complaint (name, symnum);
    364 }
    365 
    366 /* Add to this file a "new" header file: definitions for its types follow.
    367    NAME is the header file's name.
    368    Most often this happens only once for each distinct header file,
    369    but not necessarily.  If it happens more than once, INSTANCE has
    370    a different value each time, and references to the header file
    371    use INSTANCE values to select among them.
    372 
    373    dbx output contains "begin" and "end" markers for each new header file,
    374    but at this level we just need to know which files there have been;
    375    so we record the file when its "begin" is seen and ignore the "end".  */
    376 
    377 static void
    378 add_new_header_file (char *name, int instance)
    379 {
    380   int i;
    381   struct header_file *hfile;
    382 
    383   /* Make sure there is room for one more header file.  */
    384 
    385   i = N_ALLOCATED_HEADER_FILES (dbxread_objfile);
    386 
    387   if (N_HEADER_FILES (dbxread_objfile) == i)
    388     {
    389       if (i == 0)
    390 	{
    391 	  N_ALLOCATED_HEADER_FILES (dbxread_objfile) = 10;
    392 	  HEADER_FILES (dbxread_objfile) = (struct header_file *)
    393 	    xmalloc (10 * sizeof (struct header_file));
    394 	}
    395       else
    396 	{
    397 	  i *= 2;
    398 	  N_ALLOCATED_HEADER_FILES (dbxread_objfile) = i;
    399 	  HEADER_FILES (dbxread_objfile) = (struct header_file *)
    400 	    xrealloc ((char *) HEADER_FILES (dbxread_objfile),
    401 		      (i * sizeof (struct header_file)));
    402 	}
    403     }
    404 
    405   /* Create an entry for this header file.  */
    406 
    407   i = N_HEADER_FILES (dbxread_objfile)++;
    408   hfile = HEADER_FILES (dbxread_objfile) + i;
    409   hfile->name = xstrdup (name);
    410   hfile->instance = instance;
    411   hfile->length = 10;
    412   hfile->vector = XCNEWVEC (struct type *, 10);
    413 
    414   add_this_object_header_file (i);
    415 }
    416 
    417 #if 0
    418 static struct type **
    419 explicit_lookup_type (int real_filenum, int index)
    420 {
    421   struct header_file *f = &HEADER_FILES (dbxread_objfile)[real_filenum];
    422 
    423   if (index >= f->length)
    424     {
    425       f->length *= 2;
    426       f->vector = (struct type **)
    427 	xrealloc (f->vector, f->length * sizeof (struct type *));
    428       memset (&f->vector[f->length / 2],
    429 	      '\0', f->length * sizeof (struct type *) / 2);
    430     }
    431   return &f->vector[index];
    432 }
    433 #endif
    434 
    435 static void
    437 record_minimal_symbol (const char *name, CORE_ADDR address, int type,
    438 		       struct objfile *objfile)
    439 {
    440   enum minimal_symbol_type ms_type;
    441   int section;
    442 
    443   switch (type)
    444     {
    445     case N_TEXT | N_EXT:
    446       ms_type = mst_text;
    447       section = SECT_OFF_TEXT (objfile);
    448       break;
    449     case N_DATA | N_EXT:
    450       ms_type = mst_data;
    451       section = SECT_OFF_DATA (objfile);
    452       break;
    453     case N_BSS | N_EXT:
    454       ms_type = mst_bss;
    455       section = SECT_OFF_BSS (objfile);
    456       break;
    457     case N_ABS | N_EXT:
    458       ms_type = mst_abs;
    459       section = -1;
    460       break;
    461 #ifdef N_SETV
    462     case N_SETV | N_EXT:
    463       ms_type = mst_data;
    464       section = SECT_OFF_DATA (objfile);
    465       break;
    466     case N_SETV:
    467       /* I don't think this type actually exists; since a N_SETV is the result
    468          of going over many .o files, it doesn't make sense to have one
    469          file local.  */
    470       ms_type = mst_file_data;
    471       section = SECT_OFF_DATA (objfile);
    472       break;
    473 #endif
    474     case N_TEXT:
    475     case N_NBTEXT:
    476     case N_FN:
    477     case N_FN_SEQ:
    478       ms_type = mst_file_text;
    479       section = SECT_OFF_TEXT (objfile);
    480       break;
    481     case N_DATA:
    482       ms_type = mst_file_data;
    483 
    484       /* Check for __DYNAMIC, which is used by Sun shared libraries.
    485          Record it as global even if it's local, not global, so
    486          lookup_minimal_symbol can find it.  We don't check symbol_leading_char
    487          because for SunOS4 it always is '_'.  */
    488       if (name[8] == 'C' && strcmp ("__DYNAMIC", name) == 0)
    489 	ms_type = mst_data;
    490 
    491       /* Same with virtual function tables, both global and static.  */
    492       {
    493 	const char *tempstring = name;
    494 
    495 	if (tempstring[0] == bfd_get_symbol_leading_char (objfile->obfd))
    496 	  ++tempstring;
    497 	if (is_vtable_name (tempstring))
    498 	  ms_type = mst_data;
    499       }
    500       section = SECT_OFF_DATA (objfile);
    501       break;
    502     case N_BSS:
    503       ms_type = mst_file_bss;
    504       section = SECT_OFF_BSS (objfile);
    505       break;
    506     default:
    507       ms_type = mst_unknown;
    508       section = -1;
    509       break;
    510     }
    511 
    512   if ((ms_type == mst_file_text || ms_type == mst_text)
    513       && address < lowest_text_address)
    514     lowest_text_address = address;
    515 
    516   prim_record_minimal_symbol_and_info
    517     (name, address, ms_type, section, objfile);
    518 }
    519 
    520 /* Scan and build partial symbols for a symbol file.
    522    We have been initialized by a call to dbx_symfile_init, which
    523    put all the relevant info into a "struct dbx_symfile_info",
    524    hung off the objfile structure.  */
    525 
    526 static void
    527 dbx_symfile_read (struct objfile *objfile, int symfile_flags)
    528 {
    529   bfd *sym_bfd;
    530   int val;
    531   struct cleanup *back_to;
    532 
    533   sym_bfd = objfile->obfd;
    534 
    535   /* .o and .nlm files are relocatables with text, data and bss segs based at
    536      0.  This flag disables special (Solaris stabs-in-elf only) fixups for
    537      symbols with a value of 0.  */
    538 
    539   symfile_relocatable = bfd_get_file_flags (sym_bfd) & HAS_RELOC;
    540 
    541   /* This is true for Solaris (and all other systems which put stabs
    542      in sections, hopefully, since it would be silly to do things
    543      differently from Solaris), and false for SunOS4 and other a.out
    544      file formats.  */
    545   block_address_function_relative =
    546     ((startswith (bfd_get_target (sym_bfd), "elf"))
    547      || (startswith (bfd_get_target (sym_bfd), "som"))
    548      || (startswith (bfd_get_target (sym_bfd), "coff"))
    549      || (startswith (bfd_get_target (sym_bfd), "pe"))
    550      || (startswith (bfd_get_target (sym_bfd), "epoc-pe"))
    551      || (startswith (bfd_get_target (sym_bfd), "nlm")));
    552 
    553   val = bfd_seek (sym_bfd, DBX_SYMTAB_OFFSET (objfile), SEEK_SET);
    554   if (val < 0)
    555     perror_with_name (objfile_name (objfile));
    556 
    557   /* Size the symbol table.  */
    558   if (objfile->global_psymbols.size == 0 && objfile->static_psymbols.size == 0)
    559     init_psymbol_list (objfile, DBX_SYMCOUNT (objfile));
    560 
    561   symbol_size = DBX_SYMBOL_SIZE (objfile);
    562   symbol_table_offset = DBX_SYMTAB_OFFSET (objfile);
    563 
    564   free_pending_blocks ();
    565   back_to = make_cleanup (really_free_pendings, 0);
    566 
    567   init_minimal_symbol_collection ();
    568   make_cleanup_discard_minimal_symbols ();
    569 
    570   /* Read stabs data from executable file and define symbols.  */
    571 
    572   read_dbx_symtab (objfile);
    573 
    574   /* Add the dynamic symbols.  */
    575 
    576   read_dbx_dynamic_symtab (objfile);
    577 
    578   /* Install any minimal symbols that have been collected as the current
    579      minimal symbols for this objfile.  */
    580 
    581   install_minimal_symbols (objfile);
    582 
    583   do_cleanups (back_to);
    584 }
    585 
    586 /* Initialize anything that needs initializing when a completely new
    587    symbol file is specified (not just adding some symbols from another
    588    file, e.g. a shared library).  */
    589 
    590 static void
    591 dbx_new_init (struct objfile *ignore)
    592 {
    593   stabsread_new_init ();
    594   buildsym_new_init ();
    595   init_header_files ();
    596 }
    597 
    598 
    599 /* dbx_symfile_init ()
    600    is the dbx-specific initialization routine for reading symbols.
    601    It is passed a struct objfile which contains, among other things,
    602    the BFD for the file whose symbols are being read, and a slot for a pointer
    603    to "private data" which we fill with goodies.
    604 
    605    We read the string table into malloc'd space and stash a pointer to it.
    606 
    607    Since BFD doesn't know how to read debug symbols in a format-independent
    608    way (and may never do so...), we have to do it ourselves.  We will never
    609    be called unless this is an a.out (or very similar) file.
    610    FIXME, there should be a cleaner peephole into the BFD environment here.  */
    611 
    612 #define DBX_STRINGTAB_SIZE_SIZE sizeof(long)	/* FIXME */
    613 
    614 static void
    615 dbx_symfile_init (struct objfile *objfile)
    616 {
    617   int val;
    618   bfd *sym_bfd = objfile->obfd;
    619   char *name = bfd_get_filename (sym_bfd);
    620   asection *text_sect;
    621   unsigned char size_temp[DBX_STRINGTAB_SIZE_SIZE];
    622   struct dbx_symfile_info *dbx;
    623 
    624   /* Allocate struct to keep track of the symfile.  */
    625   dbx = XCNEW (struct dbx_symfile_info);
    626   set_objfile_data (objfile, dbx_objfile_data_key, dbx);
    627 
    628   DBX_TEXT_SECTION (objfile) = bfd_get_section_by_name (sym_bfd, ".text");
    629   DBX_DATA_SECTION (objfile) = bfd_get_section_by_name (sym_bfd, ".data");
    630   DBX_BSS_SECTION (objfile) = bfd_get_section_by_name (sym_bfd, ".bss");
    631 
    632   /* FIXME POKING INSIDE BFD DATA STRUCTURES.  */
    633 #define	STRING_TABLE_OFFSET	(sym_bfd->origin + obj_str_filepos (sym_bfd))
    634 #define	SYMBOL_TABLE_OFFSET	(sym_bfd->origin + obj_sym_filepos (sym_bfd))
    635 
    636   /* FIXME POKING INSIDE BFD DATA STRUCTURES.  */
    637 
    638   text_sect = bfd_get_section_by_name (sym_bfd, ".text");
    639   if (!text_sect)
    640     error (_("Can't find .text section in symbol file"));
    641   DBX_TEXT_ADDR (objfile) = bfd_section_vma (sym_bfd, text_sect);
    642   DBX_TEXT_SIZE (objfile) = bfd_section_size (sym_bfd, text_sect);
    643 
    644   DBX_SYMBOL_SIZE (objfile) = obj_symbol_entry_size (sym_bfd);
    645   DBX_SYMCOUNT (objfile) = bfd_get_symcount (sym_bfd);
    646   DBX_SYMTAB_OFFSET (objfile) = SYMBOL_TABLE_OFFSET;
    647 
    648   /* Read the string table and stash it away in the objfile_obstack.
    649      When we blow away the objfile the string table goes away as well.
    650      Note that gdb used to use the results of attempting to malloc the
    651      string table, based on the size it read, as a form of sanity check
    652      for botched byte swapping, on the theory that a byte swapped string
    653      table size would be so totally bogus that the malloc would fail.  Now
    654      that we put in on the objfile_obstack, we can't do this since gdb gets
    655      a fatal error (out of virtual memory) if the size is bogus.  We can
    656      however at least check to see if the size is less than the size of
    657      the size field itself, or larger than the size of the entire file.
    658      Note that all valid string tables have a size greater than zero, since
    659      the bytes used to hold the size are included in the count.  */
    660 
    661   if (STRING_TABLE_OFFSET == 0)
    662     {
    663       /* It appears that with the existing bfd code, STRING_TABLE_OFFSET
    664          will never be zero, even when there is no string table.  This
    665          would appear to be a bug in bfd.  */
    666       DBX_STRINGTAB_SIZE (objfile) = 0;
    667       DBX_STRINGTAB (objfile) = NULL;
    668     }
    669   else
    670     {
    671       val = bfd_seek (sym_bfd, STRING_TABLE_OFFSET, SEEK_SET);
    672       if (val < 0)
    673 	perror_with_name (name);
    674 
    675       memset (size_temp, 0, sizeof (size_temp));
    676       val = bfd_bread (size_temp, sizeof (size_temp), sym_bfd);
    677       if (val < 0)
    678 	{
    679 	  perror_with_name (name);
    680 	}
    681       else if (val == 0)
    682 	{
    683 	  /* With the existing bfd code, STRING_TABLE_OFFSET will be set to
    684 	     EOF if there is no string table, and attempting to read the size
    685 	     from EOF will read zero bytes.  */
    686 	  DBX_STRINGTAB_SIZE (objfile) = 0;
    687 	  DBX_STRINGTAB (objfile) = NULL;
    688 	}
    689       else
    690 	{
    691 	  /* Read some data that would appear to be the string table size.
    692 	     If there really is a string table, then it is probably the right
    693 	     size.  Byteswap if necessary and validate the size.  Note that
    694 	     the minimum is DBX_STRINGTAB_SIZE_SIZE.  If we just read some
    695 	     random data that happened to be at STRING_TABLE_OFFSET, because
    696 	     bfd can't tell us there is no string table, the sanity checks may
    697 	     or may not catch this.  */
    698 	  DBX_STRINGTAB_SIZE (objfile) = bfd_h_get_32 (sym_bfd, size_temp);
    699 
    700 	  if (DBX_STRINGTAB_SIZE (objfile) < sizeof (size_temp)
    701 	      || DBX_STRINGTAB_SIZE (objfile) > bfd_get_size (sym_bfd))
    702 	    error (_("ridiculous string table size (%d bytes)."),
    703 		   DBX_STRINGTAB_SIZE (objfile));
    704 
    705 	  DBX_STRINGTAB (objfile) =
    706 	    (char *) obstack_alloc (&objfile->objfile_obstack,
    707 				    DBX_STRINGTAB_SIZE (objfile));
    708 	  OBJSTAT (objfile, sz_strtab += DBX_STRINGTAB_SIZE (objfile));
    709 
    710 	  /* Now read in the string table in one big gulp.  */
    711 
    712 	  val = bfd_seek (sym_bfd, STRING_TABLE_OFFSET, SEEK_SET);
    713 	  if (val < 0)
    714 	    perror_with_name (name);
    715 	  val = bfd_bread (DBX_STRINGTAB (objfile),
    716 			   DBX_STRINGTAB_SIZE (objfile),
    717 			   sym_bfd);
    718 	  if (val != DBX_STRINGTAB_SIZE (objfile))
    719 	    perror_with_name (name);
    720 	}
    721     }
    722 }
    723 
    724 /* Perform any local cleanups required when we are done with a particular
    725    objfile.  I.E, we are in the process of discarding all symbol information
    726    for an objfile, freeing up all memory held for it, and unlinking the
    727    objfile struct from the global list of known objfiles.  */
    728 
    729 static void
    730 dbx_symfile_finish (struct objfile *objfile)
    731 {
    732   free_header_files ();
    733 }
    734 
    735 static void
    736 dbx_free_symfile_info (struct objfile *objfile, void *arg)
    737 {
    738   struct dbx_symfile_info *dbx = (struct dbx_symfile_info *) arg;
    739 
    740   if (dbx->header_files != NULL)
    741     {
    742       int i = dbx->n_header_files;
    743       struct header_file *hfiles = dbx->header_files;
    744 
    745       while (--i >= 0)
    746 	{
    747 	  xfree (hfiles[i].name);
    748 	  xfree (hfiles[i].vector);
    749 	}
    750       xfree (hfiles);
    751     }
    752 
    753   xfree (dbx);
    754 }
    755 
    756 
    757 
    759 /* Buffer for reading the symbol table entries.  */
    760 static struct external_nlist symbuf[4096];
    761 static int symbuf_idx;
    762 static int symbuf_end;
    763 
    764 /* Name of last function encountered.  Used in Solaris to approximate
    765    object file boundaries.  */
    766 static char *last_function_name;
    767 
    768 /* The address in memory of the string table of the object file we are
    769    reading (which might not be the "main" object file, but might be a
    770    shared library or some other dynamically loaded thing).  This is
    771    set by read_dbx_symtab when building psymtabs, and by
    772    read_ofile_symtab when building symtabs, and is used only by
    773    next_symbol_text.  FIXME: If that is true, we don't need it when
    774    building psymtabs, right?  */
    775 static char *stringtab_global;
    776 
    777 /* These variables are used to control fill_symbuf when the stabs
    778    symbols are not contiguous (as may be the case when a COFF file is
    779    linked using --split-by-reloc).  */
    780 static struct stab_section_list *symbuf_sections;
    781 static unsigned int symbuf_left;
    782 static unsigned int symbuf_read;
    783 
    784 /* This variable stores a global stabs buffer, if we read stabs into
    785    memory in one chunk in order to process relocations.  */
    786 static bfd_byte *stabs_data;
    787 
    788 /* Refill the symbol table input buffer
    789    and set the variables that control fetching entries from it.
    790    Reports an error if no data available.
    791    This function can read past the end of the symbol table
    792    (into the string table) but this does no harm.  */
    793 
    794 static void
    795 fill_symbuf (bfd *sym_bfd)
    796 {
    797   unsigned int count;
    798   int nbytes;
    799 
    800   if (stabs_data)
    801     {
    802       nbytes = sizeof (symbuf);
    803       if (nbytes > symbuf_left)
    804         nbytes = symbuf_left;
    805       memcpy (symbuf, stabs_data + symbuf_read, nbytes);
    806     }
    807   else if (symbuf_sections == NULL)
    808     {
    809       count = sizeof (symbuf);
    810       nbytes = bfd_bread (symbuf, count, sym_bfd);
    811     }
    812   else
    813     {
    814       if (symbuf_left <= 0)
    815 	{
    816 	  file_ptr filepos = symbuf_sections->section->filepos;
    817 
    818 	  if (bfd_seek (sym_bfd, filepos, SEEK_SET) != 0)
    819 	    perror_with_name (bfd_get_filename (sym_bfd));
    820 	  symbuf_left = bfd_section_size (sym_bfd, symbuf_sections->section);
    821 	  symbol_table_offset = filepos - symbuf_read;
    822 	  symbuf_sections = symbuf_sections->next;
    823 	}
    824 
    825       count = symbuf_left;
    826       if (count > sizeof (symbuf))
    827 	count = sizeof (symbuf);
    828       nbytes = bfd_bread (symbuf, count, sym_bfd);
    829     }
    830 
    831   if (nbytes < 0)
    832     perror_with_name (bfd_get_filename (sym_bfd));
    833   else if (nbytes == 0)
    834     error (_("Premature end of file reading symbol table"));
    835   symbuf_end = nbytes / symbol_size;
    836   symbuf_idx = 0;
    837   symbuf_left -= nbytes;
    838   symbuf_read += nbytes;
    839 }
    840 
    841 static void
    842 stabs_seek (int sym_offset)
    843 {
    844   if (stabs_data)
    845     {
    846       symbuf_read += sym_offset;
    847       symbuf_left -= sym_offset;
    848     }
    849   else
    850     bfd_seek (symfile_bfd, sym_offset, SEEK_CUR);
    851 }
    852 
    853 #define INTERNALIZE_SYMBOL(intern, extern, abfd)			\
    854   {									\
    855     (intern).n_strx = bfd_h_get_32 (abfd, (extern)->e_strx);		\
    856     (intern).n_type = bfd_h_get_8 (abfd, (extern)->e_type);		\
    857     (intern).n_other = 0;						\
    858     (intern).n_desc = bfd_h_get_16 (abfd, (extern)->e_desc);  		\
    859     if (bfd_get_sign_extend_vma (abfd))					\
    860       (intern).n_value = bfd_h_get_signed_32 (abfd, (extern)->e_value);	\
    861     else								\
    862       (intern).n_value = bfd_h_get_32 (abfd, (extern)->e_value);	\
    863   }
    864 
    865 /* Invariant: The symbol pointed to by symbuf_idx is the first one
    866    that hasn't been swapped.  Swap the symbol at the same time
    867    that symbuf_idx is incremented.  */
    868 
    869 /* dbx allows the text of a symbol name to be continued into the
    870    next symbol name!  When such a continuation is encountered
    871    (a \ at the end of the text of a name)
    872    call this function to get the continuation.  */
    873 
    874 static char *
    875 dbx_next_symbol_text (struct objfile *objfile)
    876 {
    877   struct internal_nlist nlist;
    878 
    879   if (symbuf_idx == symbuf_end)
    880     fill_symbuf (symfile_bfd);
    881 
    882   symnum++;
    883   INTERNALIZE_SYMBOL (nlist, &symbuf[symbuf_idx], symfile_bfd);
    884   OBJSTAT (objfile, n_stabs++);
    885 
    886   symbuf_idx++;
    887 
    888   return nlist.n_strx + stringtab_global + file_string_table_offset;
    889 }
    890 
    891 /* Initialize the list of bincls to contain none and have some
    893    allocated.  */
    894 
    895 static void
    896 init_bincl_list (int number, struct objfile *objfile)
    897 {
    898   bincls_allocated = number;
    899   next_bincl = bincl_list = XNEWVEC (struct header_file_location,
    900 				     bincls_allocated);
    901 }
    902 
    903 /* Add a bincl to the list.  */
    904 
    905 static void
    906 add_bincl_to_list (struct partial_symtab *pst, char *name, int instance)
    907 {
    908   if (next_bincl >= bincl_list + bincls_allocated)
    909     {
    910       int offset = next_bincl - bincl_list;
    911 
    912       bincls_allocated *= 2;
    913       bincl_list = (struct header_file_location *)
    914 	xrealloc ((char *) bincl_list,
    915 		  bincls_allocated * sizeof (struct header_file_location));
    916       next_bincl = bincl_list + offset;
    917     }
    918   next_bincl->pst = pst;
    919   next_bincl->instance = instance;
    920   next_bincl++->name = name;
    921 }
    922 
    923 /* Given a name, value pair, find the corresponding
    924    bincl in the list.  Return the partial symtab associated
    925    with that header_file_location.  */
    926 
    927 static struct partial_symtab *
    928 find_corresponding_bincl_psymtab (char *name, int instance)
    929 {
    930   struct header_file_location *bincl;
    931 
    932   for (bincl = bincl_list; bincl < next_bincl; bincl++)
    933     if (bincl->instance == instance
    934 	&& strcmp (name, bincl->name) == 0)
    935       return bincl->pst;
    936 
    937   repeated_header_complaint (name, symnum);
    938   return (struct partial_symtab *) 0;
    939 }
    940 
    941 /* Free the storage allocated for the bincl list.  */
    942 
    943 static void
    944 free_bincl_list (struct objfile *objfile)
    945 {
    946   xfree (bincl_list);
    947   bincls_allocated = 0;
    948 }
    949 
    950 static void
    951 do_free_bincl_list_cleanup (void *objfile)
    952 {
    953   free_bincl_list ((struct objfile *) objfile);
    954 }
    955 
    956 static struct cleanup *
    957 make_cleanup_free_bincl_list (struct objfile *objfile)
    958 {
    959   return make_cleanup (do_free_bincl_list_cleanup, objfile);
    960 }
    961 
    962 /* Set namestring based on nlist.  If the string table index is invalid,
    963    give a fake name, and print a single error message per symbol file read,
    964    rather than abort the symbol reading or flood the user with messages.  */
    965 
    966 static char *
    967 set_namestring (struct objfile *objfile, const struct internal_nlist *nlist)
    968 {
    969   char *namestring;
    970 
    971   if (nlist->n_strx + file_string_table_offset
    972       >= DBX_STRINGTAB_SIZE (objfile)
    973       || nlist->n_strx + file_string_table_offset < nlist->n_strx)
    974     {
    975       complaint (&symfile_complaints,
    976 		 _("bad string table offset in symbol %d"),
    977 		 symnum);
    978       namestring = "<bad string table offset>";
    979     }
    980   else
    981     namestring = (nlist->n_strx + file_string_table_offset
    982 		  + DBX_STRINGTAB (objfile));
    983   return namestring;
    984 }
    985 
    986 /* Scan a SunOs dynamic symbol table for symbols of interest and
    987    add them to the minimal symbol table.  */
    988 
    989 static void
    990 read_dbx_dynamic_symtab (struct objfile *objfile)
    991 {
    992   bfd *abfd = objfile->obfd;
    993   struct cleanup *back_to;
    994   int counter;
    995   long dynsym_size;
    996   long dynsym_count;
    997   asymbol **dynsyms;
    998   asymbol **symptr;
    999   arelent **relptr;
   1000   long dynrel_size;
   1001   long dynrel_count;
   1002   arelent **dynrels;
   1003   CORE_ADDR sym_value;
   1004   const char *name;
   1005 
   1006   /* Check that the symbol file has dynamic symbols that we know about.
   1007      bfd_arch_unknown can happen if we are reading a sun3 symbol file
   1008      on a sun4 host (and vice versa) and bfd is not configured
   1009      --with-target=all.  This would trigger an assertion in bfd/sunos.c,
   1010      so we ignore the dynamic symbols in this case.  */
   1011   if (bfd_get_flavour (abfd) != bfd_target_aout_flavour
   1012       || (bfd_get_file_flags (abfd) & DYNAMIC) == 0
   1013       || bfd_get_arch (abfd) == bfd_arch_unknown)
   1014     return;
   1015 
   1016   dynsym_size = bfd_get_dynamic_symtab_upper_bound (abfd);
   1017   if (dynsym_size < 0)
   1018     return;
   1019 
   1020   dynsyms = (asymbol **) xmalloc (dynsym_size);
   1021   back_to = make_cleanup (xfree, dynsyms);
   1022 
   1023   dynsym_count = bfd_canonicalize_dynamic_symtab (abfd, dynsyms);
   1024   if (dynsym_count < 0)
   1025     {
   1026       do_cleanups (back_to);
   1027       return;
   1028     }
   1029 
   1030   /* Enter dynamic symbols into the minimal symbol table
   1031      if this is a stripped executable.  */
   1032   if (bfd_get_symcount (abfd) <= 0)
   1033     {
   1034       symptr = dynsyms;
   1035       for (counter = 0; counter < dynsym_count; counter++, symptr++)
   1036 	{
   1037 	  asymbol *sym = *symptr;
   1038 	  asection *sec;
   1039 	  int type;
   1040 
   1041 	  sec = bfd_get_section (sym);
   1042 
   1043 	  /* BFD symbols are section relative.  */
   1044 	  sym_value = sym->value + sec->vma;
   1045 
   1046 	  if (bfd_get_section_flags (abfd, sec) & SEC_CODE)
   1047 	    {
   1048 	      type = N_TEXT;
   1049 	    }
   1050 	  else if (bfd_get_section_flags (abfd, sec) & SEC_DATA)
   1051 	    {
   1052 	      type = N_DATA;
   1053 	    }
   1054 	  else if (bfd_get_section_flags (abfd, sec) & SEC_ALLOC)
   1055 	    {
   1056 	      type = N_BSS;
   1057 	    }
   1058 	  else
   1059 	    continue;
   1060 
   1061 	  if (sym->flags & BSF_GLOBAL)
   1062 	    type |= N_EXT;
   1063 
   1064 	  record_minimal_symbol (bfd_asymbol_name (sym), sym_value,
   1065 				 type, objfile);
   1066 	}
   1067     }
   1068 
   1069   /* Symbols from shared libraries have a dynamic relocation entry
   1070      that points to the associated slot in the procedure linkage table.
   1071      We make a mininal symbol table entry with type mst_solib_trampoline
   1072      at the address in the procedure linkage table.  */
   1073   dynrel_size = bfd_get_dynamic_reloc_upper_bound (abfd);
   1074   if (dynrel_size < 0)
   1075     {
   1076       do_cleanups (back_to);
   1077       return;
   1078     }
   1079 
   1080   dynrels = (arelent **) xmalloc (dynrel_size);
   1081   make_cleanup (xfree, dynrels);
   1082 
   1083   dynrel_count = bfd_canonicalize_dynamic_reloc (abfd, dynrels, dynsyms);
   1084   if (dynrel_count < 0)
   1085     {
   1086       do_cleanups (back_to);
   1087       return;
   1088     }
   1089 
   1090   for (counter = 0, relptr = dynrels;
   1091        counter < dynrel_count;
   1092        counter++, relptr++)
   1093     {
   1094       arelent *rel = *relptr;
   1095       CORE_ADDR address = rel->address;
   1096 
   1097       switch (bfd_get_arch (abfd))
   1098 	{
   1099 	case bfd_arch_sparc:
   1100 	  if (rel->howto->type != RELOC_JMP_SLOT)
   1101 	    continue;
   1102 	  break;
   1103 	case bfd_arch_m68k:
   1104 	  /* `16' is the type BFD produces for a jump table relocation.  */
   1105 	  if (rel->howto->type != 16)
   1106 	    continue;
   1107 
   1108 	  /* Adjust address in the jump table to point to
   1109 	     the start of the bsr instruction.  */
   1110 	  address -= 2;
   1111 	  break;
   1112 	default:
   1113 	  continue;
   1114 	}
   1115 
   1116       name = bfd_asymbol_name (*rel->sym_ptr_ptr);
   1117       prim_record_minimal_symbol (name, address, mst_solib_trampoline,
   1118 				  objfile);
   1119     }
   1120 
   1121   do_cleanups (back_to);
   1122 }
   1123 
   1124 static CORE_ADDR
   1125 find_stab_function_addr (char *namestring, const char *filename,
   1126 			 struct objfile *objfile)
   1127 {
   1128   struct bound_minimal_symbol msym;
   1129   char *p;
   1130   int n;
   1131 
   1132   p = strchr (namestring, ':');
   1133   if (p == NULL)
   1134     p = namestring;
   1135   n = p - namestring;
   1136   p = (char *) alloca (n + 2);
   1137   strncpy (p, namestring, n);
   1138   p[n] = 0;
   1139 
   1140   msym = lookup_minimal_symbol (p, filename, objfile);
   1141   if (msym.minsym == NULL)
   1142     {
   1143       /* Sun Fortran appends an underscore to the minimal symbol name,
   1144          try again with an appended underscore if the minimal symbol
   1145          was not found.  */
   1146       p[n] = '_';
   1147       p[n + 1] = 0;
   1148       msym = lookup_minimal_symbol (p, filename, objfile);
   1149     }
   1150 
   1151   if (msym.minsym == NULL && filename != NULL)
   1152     {
   1153       /* Try again without the filename.  */
   1154       p[n] = 0;
   1155       msym = lookup_minimal_symbol (p, NULL, objfile);
   1156     }
   1157   if (msym.minsym == NULL && filename != NULL)
   1158     {
   1159       /* And try again for Sun Fortran, but without the filename.  */
   1160       p[n] = '_';
   1161       p[n + 1] = 0;
   1162       msym = lookup_minimal_symbol (p, NULL, objfile);
   1163     }
   1164 
   1165   return msym.minsym == NULL ? 0 : BMSYMBOL_VALUE_ADDRESS (msym);
   1166 }
   1167 
   1168 static void
   1169 function_outside_compilation_unit_complaint (const char *arg1)
   1170 {
   1171   complaint (&symfile_complaints,
   1172 	     _("function `%s' appears to be defined "
   1173 	       "outside of all compilation units"),
   1174 	     arg1);
   1175 }
   1176 
   1177 /* Setup partial_symtab's describing each source file for which
   1178    debugging information is available.  */
   1179 
   1180 static void
   1181 read_dbx_symtab (struct objfile *objfile)
   1182 {
   1183   struct gdbarch *gdbarch = get_objfile_arch (objfile);
   1184   struct external_nlist *bufp = 0;	/* =0 avoids gcc -Wall glitch.  */
   1185   struct internal_nlist nlist;
   1186   CORE_ADDR text_addr;
   1187   int text_size;
   1188   char *sym_name;
   1189   int sym_len;
   1190 
   1191   char *namestring;
   1192   int nsl;
   1193   int past_first_source_file = 0;
   1194   CORE_ADDR last_function_start = 0;
   1195   struct cleanup *back_to;
   1196   bfd *abfd;
   1197   int textlow_not_set;
   1198   int data_sect_index;
   1199 
   1200   /* Current partial symtab.  */
   1201   struct partial_symtab *pst;
   1202 
   1203   /* List of current psymtab's include files.  */
   1204   const char **psymtab_include_list;
   1205   int includes_allocated;
   1206   int includes_used;
   1207 
   1208   /* Index within current psymtab dependency list.  */
   1209   struct partial_symtab **dependency_list;
   1210   int dependencies_used, dependencies_allocated;
   1211 
   1212   text_addr = DBX_TEXT_ADDR (objfile);
   1213   text_size = DBX_TEXT_SIZE (objfile);
   1214 
   1215   /* FIXME.  We probably want to change stringtab_global rather than add this
   1216      while processing every symbol entry.  FIXME.  */
   1217   file_string_table_offset = 0;
   1218   next_file_string_table_offset = 0;
   1219 
   1220   stringtab_global = DBX_STRINGTAB (objfile);
   1221 
   1222   pst = (struct partial_symtab *) 0;
   1223 
   1224   includes_allocated = 30;
   1225   includes_used = 0;
   1226   psymtab_include_list = (const char **) alloca (includes_allocated *
   1227 						 sizeof (const char *));
   1228 
   1229   dependencies_allocated = 30;
   1230   dependencies_used = 0;
   1231   dependency_list =
   1232     (struct partial_symtab **) alloca (dependencies_allocated *
   1233 				       sizeof (struct partial_symtab *));
   1234 
   1235   /* Init bincl list */
   1236   init_bincl_list (20, objfile);
   1237   back_to = make_cleanup_free_bincl_list (objfile);
   1238 
   1239   set_last_source_file (NULL);
   1240 
   1241   lowest_text_address = (CORE_ADDR) -1;
   1242 
   1243   symfile_bfd = objfile->obfd;	/* For next_text_symbol.  */
   1244   abfd = objfile->obfd;
   1245   symbuf_end = symbuf_idx = 0;
   1246   next_symbol_text_func = dbx_next_symbol_text;
   1247   textlow_not_set = 1;
   1248   has_line_numbers = 0;
   1249 
   1250   /* FIXME: jimb/2003-09-12: We don't apply the right section's offset
   1251      to global and static variables.  The stab for a global or static
   1252      variable doesn't give us any indication of which section it's in,
   1253      so we can't tell immediately which offset in
   1254      objfile->section_offsets we should apply to the variable's
   1255      address.
   1256 
   1257      We could certainly find out which section contains the variable
   1258      by looking up the variable's unrelocated address with
   1259      find_pc_section, but that would be expensive; this is the
   1260      function that constructs the partial symbol tables by examining
   1261      every symbol in the entire executable, and it's
   1262      performance-critical.  So that expense would not be welcome.  I'm
   1263      not sure what to do about this at the moment.
   1264 
   1265      What we have done for years is to simply assume that the .data
   1266      section's offset is appropriate for all global and static
   1267      variables.  Recently, this was expanded to fall back to the .bss
   1268      section's offset if there is no .data section, and then to the
   1269      .rodata section's offset.  */
   1270   data_sect_index = objfile->sect_index_data;
   1271   if (data_sect_index == -1)
   1272     data_sect_index = SECT_OFF_BSS (objfile);
   1273   if (data_sect_index == -1)
   1274     data_sect_index = SECT_OFF_RODATA (objfile);
   1275 
   1276   /* If data_sect_index is still -1, that's okay.  It's perfectly fine
   1277      for the file to have no .data, no .bss, and no .text at all, if
   1278      it also has no global or static variables.  If it does, we will
   1279      get an internal error from an ANOFFSET macro below when we try to
   1280      use data_sect_index.  */
   1281 
   1282   for (symnum = 0; symnum < DBX_SYMCOUNT (objfile); symnum++)
   1283     {
   1284       /* Get the symbol for this run and pull out some info.  */
   1285       QUIT;			/* Allow this to be interruptable.  */
   1286       if (symbuf_idx == symbuf_end)
   1287 	fill_symbuf (abfd);
   1288       bufp = &symbuf[symbuf_idx++];
   1289 
   1290       /*
   1291        * Special case to speed up readin.
   1292        */
   1293       if (bfd_h_get_8 (abfd, bufp->e_type) == N_SLINE)
   1294 	{
   1295 	  has_line_numbers = 1;
   1296 	  continue;
   1297 	}
   1298 
   1299       INTERNALIZE_SYMBOL (nlist, bufp, abfd);
   1300       OBJSTAT (objfile, n_stabs++);
   1301 
   1302       /* Ok.  There is a lot of code duplicated in the rest of this
   1303          switch statement (for efficiency reasons).  Since I don't
   1304          like duplicating code, I will do my penance here, and
   1305          describe the code which is duplicated:
   1306 
   1307          *) The assignment to namestring.
   1308          *) The call to strchr.
   1309          *) The addition of a partial symbol the two partial
   1310          symbol lists.  This last is a large section of code, so
   1311          I've imbedded it in the following macro.  */
   1312 
   1313       switch (nlist.n_type)
   1314 	{
   1315 	  /*
   1316 	   * Standard, external, non-debugger, symbols
   1317 	   */
   1318 
   1319 	case N_TEXT | N_EXT:
   1320 	case N_NBTEXT | N_EXT:
   1321 	  goto record_it;
   1322 
   1323 	case N_DATA | N_EXT:
   1324 	case N_NBDATA | N_EXT:
   1325 	  goto record_it;
   1326 
   1327 	case N_BSS:
   1328 	case N_BSS | N_EXT:
   1329 	case N_NBBSS | N_EXT:
   1330 	case N_SETV | N_EXT:		/* FIXME, is this in BSS? */
   1331 	  goto record_it;
   1332 
   1333 	case N_ABS | N_EXT:
   1334 	  record_it:
   1335 	  namestring = set_namestring (objfile, &nlist);
   1336 
   1337 	  record_minimal_symbol (namestring, nlist.n_value,
   1338 				 nlist.n_type, objfile);	/* Always */
   1339 	  continue;
   1340 
   1341 	  /* Standard, local, non-debugger, symbols.  */
   1342 
   1343 	case N_NBTEXT:
   1344 
   1345 	  /* We need to be able to deal with both N_FN or N_TEXT,
   1346 	     because we have no way of knowing whether the sys-supplied ld
   1347 	     or GNU ld was used to make the executable.  Sequents throw
   1348 	     in another wrinkle -- they renumbered N_FN.  */
   1349 
   1350 	case N_FN:
   1351 	case N_FN_SEQ:
   1352 	case N_TEXT:
   1353 	  namestring = set_namestring (objfile, &nlist);
   1354 
   1355 	  if ((namestring[0] == '-' && namestring[1] == 'l')
   1356 	      || (namestring[(nsl = strlen (namestring)) - 1] == 'o'
   1357 		  && namestring[nsl - 2] == '.'))
   1358 	    {
   1359 	      nlist.n_value += ANOFFSET (objfile->section_offsets,
   1360 					 SECT_OFF_TEXT (objfile));
   1361 
   1362 	      if (past_first_source_file && pst
   1363 		  /* The gould NP1 uses low values for .o and -l symbols
   1364 		     which are not the address.  */
   1365 		  && nlist.n_value >= pst->textlow)
   1366 		{
   1367 		  dbx_end_psymtab (objfile, pst, psymtab_include_list,
   1368 				   includes_used, symnum * symbol_size,
   1369 				   nlist.n_value > pst->texthigh
   1370 				   ? nlist.n_value : pst->texthigh,
   1371 				   dependency_list, dependencies_used,
   1372 				   textlow_not_set);
   1373 		  pst = (struct partial_symtab *) 0;
   1374 		  includes_used = 0;
   1375 		  dependencies_used = 0;
   1376 		  has_line_numbers = 0;
   1377 		}
   1378 	      else
   1379 		past_first_source_file = 1;
   1380 	    }
   1381 	  else
   1382 	    goto record_it;
   1383 	  continue;
   1384 
   1385 	case N_DATA:
   1386 	  goto record_it;
   1387 
   1388 	case N_UNDF | N_EXT:
   1389 	  /* The case (nlist.n_value != 0) is a "Fortran COMMON" symbol.
   1390 	     We used to rely on the target to tell us whether it knows
   1391 	     where the symbol has been relocated to, but none of the
   1392 	     target implementations actually provided that operation.
   1393 	     So we just ignore the symbol, the same way we would do if
   1394 	     we had a target-side symbol lookup which returned no match.
   1395 
   1396 	     All other symbols (with nlist.n_value == 0), are really
   1397 	     undefined, and so we ignore them too.  */
   1398 	  continue;
   1399 
   1400 	case N_UNDF:
   1401 	  if (processing_acc_compilation && nlist.n_strx == 1)
   1402 	    {
   1403 	      /* Deal with relative offsets in the string table
   1404 		 used in ELF+STAB under Solaris.  If we want to use the
   1405 		 n_strx field, which contains the name of the file,
   1406 		 we must adjust file_string_table_offset *before* calling
   1407 		 set_namestring().  */
   1408 	      past_first_source_file = 1;
   1409 	      file_string_table_offset = next_file_string_table_offset;
   1410 	      next_file_string_table_offset =
   1411 		file_string_table_offset + nlist.n_value;
   1412 	      if (next_file_string_table_offset < file_string_table_offset)
   1413 		error (_("string table offset backs up at %d"), symnum);
   1414 	      /* FIXME -- replace error() with complaint.  */
   1415 	      continue;
   1416 	    }
   1417 	  continue;
   1418 
   1419 	  /* Lots of symbol types we can just ignore.  */
   1420 
   1421 	case N_ABS:
   1422 	case N_NBDATA:
   1423 	case N_NBBSS:
   1424 	  continue;
   1425 
   1426 	  /* Keep going . . .  */
   1427 
   1428 	  /*
   1429 	   * Special symbol types for GNU
   1430 	   */
   1431 	case N_INDR:
   1432 	case N_INDR | N_EXT:
   1433 	case N_SETA:
   1434 	case N_SETA | N_EXT:
   1435 	case N_SETT:
   1436 	case N_SETT | N_EXT:
   1437 	case N_SETD:
   1438 	case N_SETD | N_EXT:
   1439 	case N_SETB:
   1440 	case N_SETB | N_EXT:
   1441 	case N_SETV:
   1442 	  continue;
   1443 
   1444 	  /*
   1445 	   * Debugger symbols
   1446 	   */
   1447 
   1448 	case N_SO:
   1449 	  {
   1450 	    CORE_ADDR valu;
   1451 	    static int prev_so_symnum = -10;
   1452 	    static int first_so_symnum;
   1453 	    const char *p;
   1454 	    static char *dirname_nso;
   1455 	    int prev_textlow_not_set;
   1456 
   1457 	    valu = nlist.n_value + ANOFFSET (objfile->section_offsets,
   1458 					     SECT_OFF_TEXT (objfile));
   1459 
   1460 	    prev_textlow_not_set = textlow_not_set;
   1461 
   1462 	    /* A zero value is probably an indication for the SunPRO 3.0
   1463 	       compiler.  dbx_end_psymtab explicitly tests for zero, so
   1464 	       don't relocate it.  */
   1465 
   1466 	    if (nlist.n_value == 0
   1467 		&& gdbarch_sofun_address_maybe_missing (gdbarch))
   1468 	      {
   1469 		textlow_not_set = 1;
   1470 		valu = 0;
   1471 	      }
   1472 	    else
   1473 	      textlow_not_set = 0;
   1474 
   1475 	    past_first_source_file = 1;
   1476 
   1477 	    if (prev_so_symnum != symnum - 1)
   1478 	      {			/* Here if prev stab wasn't N_SO.  */
   1479 		first_so_symnum = symnum;
   1480 
   1481 		if (pst)
   1482 		  {
   1483 		    dbx_end_psymtab (objfile, pst, psymtab_include_list,
   1484 				     includes_used, symnum * symbol_size,
   1485 				     valu > pst->texthigh
   1486 				     ? valu : pst->texthigh,
   1487 				     dependency_list, dependencies_used,
   1488 				     prev_textlow_not_set);
   1489 		    pst = (struct partial_symtab *) 0;
   1490 		    includes_used = 0;
   1491 		    dependencies_used = 0;
   1492 		    has_line_numbers = 0;
   1493 		  }
   1494 	      }
   1495 
   1496 	    prev_so_symnum = symnum;
   1497 
   1498 	    /* End the current partial symtab and start a new one.  */
   1499 
   1500 	    namestring = set_namestring (objfile, &nlist);
   1501 
   1502 	    /* Null name means end of .o file.  Don't start a new one.  */
   1503 	    if (*namestring == '\000')
   1504 	      continue;
   1505 
   1506 	    /* Some compilers (including gcc) emit a pair of initial N_SOs.
   1507 	       The first one is a directory name; the second the file name.
   1508 	       If pst exists, is empty, and has a filename ending in '/',
   1509 	       we assume the previous N_SO was a directory name.  */
   1510 
   1511 	    p = lbasename (namestring);
   1512 	    if (p != namestring && *p == '\000')
   1513 	      {
   1514 		/* Save the directory name SOs locally, then save it into
   1515 		   the psymtab when it's created below.  */
   1516 	        dirname_nso = namestring;
   1517 	        continue;
   1518 	      }
   1519 
   1520 	    /* Some other compilers (C++ ones in particular) emit useless
   1521 	       SOs for non-existant .c files.  We ignore all subsequent SOs
   1522 	       that immediately follow the first.  */
   1523 
   1524 	    if (!pst)
   1525 	      {
   1526 		pst = start_psymtab (objfile,
   1527 				     namestring, valu,
   1528 				     first_so_symnum * symbol_size,
   1529 				     objfile->global_psymbols.next,
   1530 				     objfile->static_psymbols.next);
   1531 		pst->dirname = dirname_nso;
   1532 		dirname_nso = NULL;
   1533 	      }
   1534 	    continue;
   1535 	  }
   1536 
   1537 	case N_BINCL:
   1538 	  {
   1539 	    enum language tmp_language;
   1540 
   1541 	    /* Add this bincl to the bincl_list for future EXCLs.  No
   1542 	       need to save the string; it'll be around until
   1543 	       read_dbx_symtab function returns.  */
   1544 
   1545 	    namestring = set_namestring (objfile, &nlist);
   1546 	    tmp_language = deduce_language_from_filename (namestring);
   1547 
   1548 	    /* Only change the psymtab's language if we've learned
   1549 	       something useful (eg. tmp_language is not language_unknown).
   1550 	       In addition, to match what start_subfile does, never change
   1551 	       from C++ to C.  */
   1552 	    if (tmp_language != language_unknown
   1553 		&& (tmp_language != language_c
   1554 		    || psymtab_language != language_cplus))
   1555 	      psymtab_language = tmp_language;
   1556 
   1557 	    if (pst == NULL)
   1558 	      {
   1559 		/* FIXME: we should not get here without a PST to work on.
   1560 		   Attempt to recover.  */
   1561 		complaint (&symfile_complaints,
   1562 			   _("N_BINCL %s not in entries for "
   1563 			     "any file, at symtab pos %d"),
   1564 			   namestring, symnum);
   1565 		continue;
   1566 	      }
   1567 	    add_bincl_to_list (pst, namestring, nlist.n_value);
   1568 
   1569 	    /* Mark down an include file in the current psymtab.  */
   1570 
   1571 	    goto record_include_file;
   1572 	  }
   1573 
   1574 	case N_SOL:
   1575 	  {
   1576 	    enum language tmp_language;
   1577 
   1578 	    /* Mark down an include file in the current psymtab.  */
   1579 	    namestring = set_namestring (objfile, &nlist);
   1580 	    tmp_language = deduce_language_from_filename (namestring);
   1581 
   1582 	    /* Only change the psymtab's language if we've learned
   1583 	       something useful (eg. tmp_language is not language_unknown).
   1584 	       In addition, to match what start_subfile does, never change
   1585 	       from C++ to C.  */
   1586 	    if (tmp_language != language_unknown
   1587 		&& (tmp_language != language_c
   1588 		    || psymtab_language != language_cplus))
   1589 	      psymtab_language = tmp_language;
   1590 
   1591 	    /* In C++, one may expect the same filename to come round many
   1592 	       times, when code is coming alternately from the main file
   1593 	       and from inline functions in other files.  So I check to see
   1594 	       if this is a file we've seen before -- either the main
   1595 	       source file, or a previously included file.
   1596 
   1597 	       This seems to be a lot of time to be spending on N_SOL, but
   1598 	       things like "break c-exp.y:435" need to work (I
   1599 	       suppose the psymtab_include_list could be hashed or put
   1600 	       in a binary tree, if profiling shows this is a major hog).  */
   1601 	    if (pst && filename_cmp (namestring, pst->filename) == 0)
   1602 	      continue;
   1603 	    {
   1604 	      int i;
   1605 
   1606 	      for (i = 0; i < includes_used; i++)
   1607 		if (filename_cmp (namestring, psymtab_include_list[i]) == 0)
   1608 		  {
   1609 		    i = -1;
   1610 		    break;
   1611 		  }
   1612 	      if (i == -1)
   1613 		continue;
   1614 	    }
   1615 
   1616 	  record_include_file:
   1617 
   1618 	    psymtab_include_list[includes_used++] = namestring;
   1619 	    if (includes_used >= includes_allocated)
   1620 	      {
   1621 		const char **orig = psymtab_include_list;
   1622 
   1623 		psymtab_include_list = (const char **)
   1624 		  alloca ((includes_allocated *= 2) * sizeof (const char *));
   1625 		memcpy (psymtab_include_list, orig,
   1626 			includes_used * sizeof (const char *));
   1627 	      }
   1628 	    continue;
   1629 	  }
   1630 	case N_LSYM:		/* Typedef or automatic variable.  */
   1631 	case N_STSYM:		/* Data seg var -- static.  */
   1632 	case N_LCSYM:		/* BSS      "  */
   1633 	case N_ROSYM:		/* Read-only data seg var -- static.  */
   1634 	case N_NBSTS:		/* Gould nobase.  */
   1635 	case N_NBLCS:		/* symbols.  */
   1636 	case N_FUN:
   1637 	case N_GSYM:		/* Global (extern) variable; can be
   1638 				   data or bss (sigh FIXME).  */
   1639 
   1640 	  /* Following may probably be ignored; I'll leave them here
   1641 	     for now (until I do Pascal and Modula 2 extensions).  */
   1642 
   1643 	case N_PC:		/* I may or may not need this; I
   1644 				   suspect not.  */
   1645 	case N_M2C:		/* I suspect that I can ignore this here.  */
   1646 	case N_SCOPE:		/* Same.   */
   1647 	{
   1648 	  char *p;
   1649 
   1650 	  namestring = set_namestring (objfile, &nlist);
   1651 
   1652 	  /* See if this is an end of function stab.  */
   1653 	  if (pst && nlist.n_type == N_FUN && *namestring == '\000')
   1654 	    {
   1655 	      CORE_ADDR valu;
   1656 
   1657 	      /* It's value is the size (in bytes) of the function for
   1658 		 function relative stabs, or the address of the function's
   1659 		 end for old style stabs.  */
   1660 	      valu = nlist.n_value + last_function_start;
   1661 	      if (pst->texthigh == 0 || valu > pst->texthigh)
   1662 		pst->texthigh = valu;
   1663 	      break;
   1664 	    }
   1665 
   1666 	  p = (char *) strchr (namestring, ':');
   1667 	  if (!p)
   1668 	    continue;		/* Not a debugging symbol.   */
   1669 
   1670  	  sym_len = 0;
   1671 	  sym_name = NULL;	/* pacify "gcc -Werror" */
   1672  	  if (psymtab_language == language_cplus)
   1673  	    {
   1674 	      char *new_name, *name = (char *) xmalloc (p - namestring + 1);
   1675  	      memcpy (name, namestring, p - namestring);
   1676 
   1677  	      name[p - namestring] = '\0';
   1678  	      new_name = cp_canonicalize_string (name);
   1679  	      if (new_name != NULL)
   1680  		{
   1681  		  sym_len = strlen (new_name);
   1682 		  sym_name = (char *) obstack_copy0 (&objfile->objfile_obstack,
   1683 						     new_name, sym_len);
   1684  		  xfree (new_name);
   1685  		}
   1686               xfree (name);
   1687  	    }
   1688 
   1689  	  if (sym_len == 0)
   1690  	    {
   1691  	      sym_name = namestring;
   1692  	      sym_len = p - namestring;
   1693  	    }
   1694 
   1695 	  /* Main processing section for debugging symbols which
   1696 	     the initial read through the symbol tables needs to worry
   1697 	     about.  If we reach this point, the symbol which we are
   1698 	     considering is definitely one we are interested in.
   1699 	     p must also contain the (valid) index into the namestring
   1700 	     which indicates the debugging type symbol.  */
   1701 
   1702 	  switch (p[1])
   1703 	    {
   1704 	    case 'S':
   1705 	      nlist.n_value += ANOFFSET (objfile->section_offsets,
   1706 					 data_sect_index);
   1707 
   1708 	      if (gdbarch_static_transform_name_p (gdbarch))
   1709 		gdbarch_static_transform_name (gdbarch, namestring);
   1710 
   1711 	      add_psymbol_to_list (sym_name, sym_len, 1,
   1712 				   VAR_DOMAIN, LOC_STATIC,
   1713 				   &objfile->static_psymbols,
   1714 				   nlist.n_value, psymtab_language, objfile);
   1715 	      continue;
   1716 
   1717 	    case 'G':
   1718 	      nlist.n_value += ANOFFSET (objfile->section_offsets,
   1719 					 data_sect_index);
   1720 	      /* The addresses in these entries are reported to be
   1721 		 wrong.  See the code that reads 'G's for symtabs.  */
   1722 	      add_psymbol_to_list (sym_name, sym_len, 1,
   1723 				   VAR_DOMAIN, LOC_STATIC,
   1724 				   &objfile->global_psymbols,
   1725 				   nlist.n_value, psymtab_language, objfile);
   1726 	      continue;
   1727 
   1728 	    case 'T':
   1729 	      /* When a 'T' entry is defining an anonymous enum, it
   1730 		 may have a name which is the empty string, or a
   1731 		 single space.  Since they're not really defining a
   1732 		 symbol, those shouldn't go in the partial symbol
   1733 		 table.  We do pick up the elements of such enums at
   1734 		 'check_enum:', below.  */
   1735 	      if (p >= namestring + 2
   1736 		  || (p == namestring + 1
   1737 		      && namestring[0] != ' '))
   1738 		{
   1739 		  add_psymbol_to_list (sym_name, sym_len, 1,
   1740 				       STRUCT_DOMAIN, LOC_TYPEDEF,
   1741 				       &objfile->static_psymbols,
   1742 				       0, psymtab_language, objfile);
   1743 		  if (p[2] == 't')
   1744 		    {
   1745 		      /* Also a typedef with the same name.  */
   1746 		      add_psymbol_to_list (sym_name, sym_len, 1,
   1747 					   VAR_DOMAIN, LOC_TYPEDEF,
   1748 					   &objfile->static_psymbols,
   1749 					   0, psymtab_language, objfile);
   1750 		      p += 1;
   1751 		    }
   1752 		}
   1753 	      goto check_enum;
   1754 
   1755 	    case 't':
   1756 	      if (p != namestring)	/* a name is there, not just :T...  */
   1757 		{
   1758 		  add_psymbol_to_list (sym_name, sym_len, 1,
   1759 				       VAR_DOMAIN, LOC_TYPEDEF,
   1760 				       &objfile->static_psymbols,
   1761 				       0, psymtab_language, objfile);
   1762 		}
   1763 	    check_enum:
   1764 	      /* If this is an enumerated type, we need to
   1765 		 add all the enum constants to the partial symbol
   1766 		 table.  This does not cover enums without names, e.g.
   1767 		 "enum {a, b} c;" in C, but fortunately those are
   1768 		 rare.  There is no way for GDB to find those from the
   1769 		 enum type without spending too much time on it.  Thus
   1770 		 to solve this problem, the compiler needs to put out the
   1771 		 enum in a nameless type.  GCC2 does this.  */
   1772 
   1773 	      /* We are looking for something of the form
   1774 		 <name> ":" ("t" | "T") [<number> "="] "e"
   1775 		 {<constant> ":" <value> ","} ";".  */
   1776 
   1777 	      /* Skip over the colon and the 't' or 'T'.  */
   1778 	      p += 2;
   1779 	      /* This type may be given a number.  Also, numbers can come
   1780 		 in pairs like (0,26).  Skip over it.  */
   1781 	      while ((*p >= '0' && *p <= '9')
   1782 		     || *p == '(' || *p == ',' || *p == ')'
   1783 		     || *p == '=')
   1784 		p++;
   1785 
   1786 	      if (*p++ == 'e')
   1787 		{
   1788 		  /* The aix4 compiler emits extra crud before the members.  */
   1789 		  if (*p == '-')
   1790 		    {
   1791 		      /* Skip over the type (?).  */
   1792 		      while (*p != ':')
   1793 			p++;
   1794 
   1795 		      /* Skip over the colon.  */
   1796 		      p++;
   1797 		    }
   1798 
   1799 		  /* We have found an enumerated type.  */
   1800 		  /* According to comments in read_enum_type
   1801 		     a comma could end it instead of a semicolon.
   1802 		     I don't know where that happens.
   1803 		     Accept either.  */
   1804 		  while (*p && *p != ';' && *p != ',')
   1805 		    {
   1806 		      char *q;
   1807 
   1808 		      /* Check for and handle cretinous dbx symbol name
   1809 			 continuation!  */
   1810 		      if (*p == '\\' || (*p == '?' && p[1] == '\0'))
   1811 			p = next_symbol_text (objfile);
   1812 
   1813 		      /* Point to the character after the name
   1814 			 of the enum constant.  */
   1815 		      for (q = p; *q && *q != ':'; q++)
   1816 			;
   1817 		      /* Note that the value doesn't matter for
   1818 			 enum constants in psymtabs, just in symtabs.  */
   1819 		      add_psymbol_to_list (p, q - p, 1,
   1820 					   VAR_DOMAIN, LOC_CONST,
   1821 					   &objfile->static_psymbols, 0,
   1822 					   psymtab_language, objfile);
   1823 		      /* Point past the name.  */
   1824 		      p = q;
   1825 		      /* Skip over the value.  */
   1826 		      while (*p && *p != ',')
   1827 			p++;
   1828 		      /* Advance past the comma.  */
   1829 		      if (*p)
   1830 			p++;
   1831 		    }
   1832 		}
   1833 	      continue;
   1834 
   1835 	    case 'c':
   1836 	      /* Constant, e.g. from "const" in Pascal.  */
   1837 	      add_psymbol_to_list (sym_name, sym_len, 1,
   1838 				   VAR_DOMAIN, LOC_CONST,
   1839 				   &objfile->static_psymbols, 0,
   1840 				   psymtab_language, objfile);
   1841 	      continue;
   1842 
   1843 	    case 'f':
   1844 	      if (! pst)
   1845 		{
   1846 		  int name_len = p - namestring;
   1847 		  char *name = (char *) xmalloc (name_len + 1);
   1848 
   1849 		  memcpy (name, namestring, name_len);
   1850 		  name[name_len] = '\0';
   1851 		  function_outside_compilation_unit_complaint (name);
   1852 		  xfree (name);
   1853 		}
   1854 	      nlist.n_value += ANOFFSET (objfile->section_offsets,
   1855 					 SECT_OFF_TEXT (objfile));
   1856 	      /* Kludges for ELF/STABS with Sun ACC.  */
   1857 	      last_function_name = namestring;
   1858 	      /* Do not fix textlow==0 for .o or NLM files, as 0 is a legit
   1859 		 value for the bottom of the text seg in those cases.  */
   1860 	      if (nlist.n_value == ANOFFSET (objfile->section_offsets,
   1861 					     SECT_OFF_TEXT (objfile))
   1862 		  && gdbarch_sofun_address_maybe_missing (gdbarch))
   1863 		{
   1864 		  CORE_ADDR minsym_valu =
   1865 		    find_stab_function_addr (namestring,
   1866 					     pst ? pst->filename : NULL,
   1867 					     objfile);
   1868 
   1869 		  /* find_stab_function_addr will return 0 if the minimal
   1870 		     symbol wasn't found.  (Unfortunately, this might also
   1871 		     be a valid address.)  Anyway, if it *does* return 0,
   1872 		     it is likely that the value was set correctly to begin
   1873 		     with...  */
   1874 		  if (minsym_valu != 0)
   1875 		    nlist.n_value = minsym_valu;
   1876 		}
   1877 	      if (pst && textlow_not_set
   1878 		  && gdbarch_sofun_address_maybe_missing (gdbarch))
   1879 		{
   1880 		  pst->textlow = nlist.n_value;
   1881 		  textlow_not_set = 0;
   1882 		}
   1883 	      /* End kludge.  */
   1884 
   1885 	      /* Keep track of the start of the last function so we
   1886 		 can handle end of function symbols.  */
   1887 	      last_function_start = nlist.n_value;
   1888 
   1889 	      /* In reordered executables this function may lie outside
   1890 		 the bounds created by N_SO symbols.  If that's the case
   1891 		 use the address of this function as the low bound for
   1892 		 the partial symbol table.  */
   1893 	      if (pst
   1894 		  && (textlow_not_set
   1895 		      || (nlist.n_value < pst->textlow
   1896 			  && (nlist.n_value
   1897 			      != ANOFFSET (objfile->section_offsets,
   1898 					   SECT_OFF_TEXT (objfile))))))
   1899 		{
   1900 		  pst->textlow = nlist.n_value;
   1901 		  textlow_not_set = 0;
   1902 		}
   1903 	      add_psymbol_to_list (sym_name, sym_len, 1,
   1904 				   VAR_DOMAIN, LOC_BLOCK,
   1905 				   &objfile->static_psymbols,
   1906 				   nlist.n_value, psymtab_language, objfile);
   1907 	      continue;
   1908 
   1909 	      /* Global functions were ignored here, but now they
   1910 		 are put into the global psymtab like one would expect.
   1911 		 They're also in the minimal symbol table.  */
   1912 	    case 'F':
   1913 	      if (! pst)
   1914 		{
   1915 		  int name_len = p - namestring;
   1916 		  char *name = (char *) xmalloc (name_len + 1);
   1917 
   1918 		  memcpy (name, namestring, name_len);
   1919 		  name[name_len] = '\0';
   1920 		  function_outside_compilation_unit_complaint (name);
   1921 		  xfree (name);
   1922 		}
   1923 	      nlist.n_value += ANOFFSET (objfile->section_offsets,
   1924 					 SECT_OFF_TEXT (objfile));
   1925 	      /* Kludges for ELF/STABS with Sun ACC.  */
   1926 	      last_function_name = namestring;
   1927 	      /* Do not fix textlow==0 for .o or NLM files, as 0 is a legit
   1928 		 value for the bottom of the text seg in those cases.  */
   1929 	      if (nlist.n_value == ANOFFSET (objfile->section_offsets,
   1930 					     SECT_OFF_TEXT (objfile))
   1931 		  && gdbarch_sofun_address_maybe_missing (gdbarch))
   1932 		{
   1933 		  CORE_ADDR minsym_valu =
   1934 		    find_stab_function_addr (namestring,
   1935 					     pst ? pst->filename : NULL,
   1936 					     objfile);
   1937 
   1938 		  /* find_stab_function_addr will return 0 if the minimal
   1939 		     symbol wasn't found.  (Unfortunately, this might also
   1940 		     be a valid address.)  Anyway, if it *does* return 0,
   1941 		     it is likely that the value was set correctly to begin
   1942 		     with...  */
   1943 		  if (minsym_valu != 0)
   1944 		    nlist.n_value = minsym_valu;
   1945 		}
   1946 	      if (pst && textlow_not_set
   1947 		  && gdbarch_sofun_address_maybe_missing (gdbarch))
   1948 		{
   1949 		  pst->textlow = nlist.n_value;
   1950 		  textlow_not_set = 0;
   1951 		}
   1952 	      /* End kludge.  */
   1953 
   1954 	      /* Keep track of the start of the last function so we
   1955 		 can handle end of function symbols.  */
   1956 	      last_function_start = nlist.n_value;
   1957 
   1958 	      /* In reordered executables this function may lie outside
   1959 		 the bounds created by N_SO symbols.  If that's the case
   1960 		 use the address of this function as the low bound for
   1961 		 the partial symbol table.  */
   1962 	      if (pst
   1963 		  && (textlow_not_set
   1964 		      || (nlist.n_value < pst->textlow
   1965 			  && (nlist.n_value
   1966 			      != ANOFFSET (objfile->section_offsets,
   1967 					   SECT_OFF_TEXT (objfile))))))
   1968 		{
   1969 		  pst->textlow = nlist.n_value;
   1970 		  textlow_not_set = 0;
   1971 		}
   1972 	      add_psymbol_to_list (sym_name, sym_len, 1,
   1973 				   VAR_DOMAIN, LOC_BLOCK,
   1974 				   &objfile->global_psymbols,
   1975 				   nlist.n_value, psymtab_language, objfile);
   1976 	      continue;
   1977 
   1978 	      /* Two things show up here (hopefully); static symbols of
   1979 		 local scope (static used inside braces) or extensions
   1980 		 of structure symbols.  We can ignore both.  */
   1981 	    case 'V':
   1982 	    case '(':
   1983 	    case '0':
   1984 	    case '1':
   1985 	    case '2':
   1986 	    case '3':
   1987 	    case '4':
   1988 	    case '5':
   1989 	    case '6':
   1990 	    case '7':
   1991 	    case '8':
   1992 	    case '9':
   1993 	    case '-':
   1994 	    case '#':	/* For symbol identification (used in live ranges).  */
   1995 	      continue;
   1996 
   1997 	    case ':':
   1998 	      /* It is a C++ nested symbol.  We don't need to record it
   1999 		 (I don't think); if we try to look up foo::bar::baz,
   2000 		 then symbols for the symtab containing foo should get
   2001 		 read in, I think.  */
   2002 	      /* Someone says sun cc puts out symbols like
   2003 		 /foo/baz/maclib::/usr/local/bin/maclib,
   2004 		 which would get here with a symbol type of ':'.  */
   2005 	      continue;
   2006 
   2007 	    default:
   2008 	      /* Unexpected symbol descriptor.  The second and subsequent stabs
   2009 		 of a continued stab can show up here.  The question is
   2010 		 whether they ever can mimic a normal stab--it would be
   2011 		 nice if not, since we certainly don't want to spend the
   2012 		 time searching to the end of every string looking for
   2013 		 a backslash.  */
   2014 
   2015 	      complaint (&symfile_complaints,
   2016 			 _("unknown symbol descriptor `%c'"),
   2017 			 p[1]);
   2018 
   2019 	      /* Ignore it; perhaps it is an extension that we don't
   2020 		 know about.  */
   2021 	      continue;
   2022 	    }
   2023 	}
   2024 
   2025 	case N_EXCL:
   2026 
   2027 	  namestring = set_namestring (objfile, &nlist);
   2028 
   2029 	  /* Find the corresponding bincl and mark that psymtab on the
   2030 	     psymtab dependency list.  */
   2031 	  {
   2032 	    struct partial_symtab *needed_pst =
   2033 	      find_corresponding_bincl_psymtab (namestring, nlist.n_value);
   2034 
   2035 	    /* If this include file was defined earlier in this file,
   2036 	       leave it alone.  */
   2037 	    if (needed_pst == pst)
   2038 	      continue;
   2039 
   2040 	    if (needed_pst)
   2041 	      {
   2042 		int i;
   2043 		int found = 0;
   2044 
   2045 		for (i = 0; i < dependencies_used; i++)
   2046 		  if (dependency_list[i] == needed_pst)
   2047 		    {
   2048 		      found = 1;
   2049 		      break;
   2050 		    }
   2051 
   2052 		/* If it's already in the list, skip the rest.  */
   2053 		if (found)
   2054 		  continue;
   2055 
   2056 		dependency_list[dependencies_used++] = needed_pst;
   2057 		if (dependencies_used >= dependencies_allocated)
   2058 		  {
   2059 		    struct partial_symtab **orig = dependency_list;
   2060 
   2061 		    dependency_list =
   2062 		      (struct partial_symtab **)
   2063 		      alloca ((dependencies_allocated *= 2)
   2064 			      * sizeof (struct partial_symtab *));
   2065 		    memcpy (dependency_list, orig,
   2066 			    (dependencies_used
   2067 			     * sizeof (struct partial_symtab *)));
   2068 #ifdef DEBUG_INFO
   2069 		    fprintf_unfiltered (gdb_stderr,
   2070 					"Had to reallocate "
   2071 					"dependency list.\n");
   2072 		    fprintf_unfiltered (gdb_stderr,
   2073 					"New dependencies allocated: %d\n",
   2074 					dependencies_allocated);
   2075 #endif
   2076 		  }
   2077 	      }
   2078 	  }
   2079 	  continue;
   2080 
   2081 	case N_ENDM:
   2082 	  /* Solaris 2 end of module, finish current partial symbol table.
   2083 	     dbx_end_psymtab will set pst->texthigh to the proper value, which
   2084 	     is necessary if a module compiled without debugging info
   2085 	     follows this module.  */
   2086 	  if (pst && gdbarch_sofun_address_maybe_missing (gdbarch))
   2087 	    {
   2088 	      dbx_end_psymtab (objfile, pst,
   2089 			       psymtab_include_list, includes_used,
   2090 			       symnum * symbol_size,
   2091 			       (CORE_ADDR) 0, dependency_list,
   2092 			       dependencies_used, textlow_not_set);
   2093 	      pst = (struct partial_symtab *) 0;
   2094 	      includes_used = 0;
   2095 	      dependencies_used = 0;
   2096 	      has_line_numbers = 0;
   2097 	    }
   2098 	  continue;
   2099 
   2100 	case N_RBRAC:
   2101 #ifdef HANDLE_RBRAC
   2102 	  HANDLE_RBRAC (nlist.n_value);
   2103 	  continue;
   2104 #endif
   2105 	case N_EINCL:
   2106 	case N_DSLINE:
   2107 	case N_BSLINE:
   2108 	case N_SSYM:		/* Claim: Structure or union element.
   2109 				   Hopefully, I can ignore this.  */
   2110 	case N_ENTRY:		/* Alternate entry point; can ignore.  */
   2111 	case N_MAIN:		/* Can definitely ignore this.   */
   2112 	case N_CATCH:		/* These are GNU C++ extensions */
   2113 	case N_EHDECL:		/* that can safely be ignored here.  */
   2114 	case N_LENG:
   2115 	case N_BCOMM:
   2116 	case N_ECOMM:
   2117 	case N_ECOML:
   2118 	case N_FNAME:
   2119 	case N_SLINE:
   2120 	case N_RSYM:
   2121 	case N_PSYM:
   2122 	case N_BNSYM:
   2123 	case N_ENSYM:
   2124 	case N_LBRAC:
   2125 	case N_NSYMS:		/* Ultrix 4.0: symbol count */
   2126 	case N_DEFD:		/* GNU Modula-2 */
   2127 	case N_ALIAS:		/* SunPro F77: alias name, ignore for now.  */
   2128 
   2129 	case N_OBJ:		/* Useless types from Solaris.  */
   2130 	case N_OPT:
   2131 	case N_PATCH:
   2132 	  /* These symbols aren't interesting; don't worry about them.  */
   2133 	  continue;
   2134 
   2135 	default:
   2136 	  /* If we haven't found it yet, ignore it.  It's probably some
   2137 	     new type we don't know about yet.  */
   2138 	  unknown_symtype_complaint (hex_string (nlist.n_type));
   2139 	  continue;
   2140 	}
   2141     }
   2142 
   2143   /* If there's stuff to be cleaned up, clean it up.  */
   2144   if (pst)
   2145     {
   2146       /* Don't set pst->texthigh lower than it already is.  */
   2147       CORE_ADDR text_end =
   2148 	(lowest_text_address == (CORE_ADDR) -1
   2149 	 ? (text_addr + ANOFFSET (objfile->section_offsets,
   2150 				  SECT_OFF_TEXT (objfile)))
   2151 	 : lowest_text_address)
   2152 	+ text_size;
   2153 
   2154       dbx_end_psymtab (objfile, pst, psymtab_include_list, includes_used,
   2155 		       symnum * symbol_size,
   2156 		       text_end > pst->texthigh ? text_end : pst->texthigh,
   2157 		       dependency_list, dependencies_used, textlow_not_set);
   2158     }
   2159 
   2160   do_cleanups (back_to);
   2161 }
   2162 
   2163 /* Allocate and partially fill a partial symtab.  It will be
   2164    completely filled at the end of the symbol list.
   2165 
   2166    SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
   2167    is the address relative to which its symbols are (incremental) or 0
   2168    (normal).  */
   2169 
   2170 static struct partial_symtab *
   2171 start_psymtab (struct objfile *objfile, char *filename, CORE_ADDR textlow,
   2172 	       int ldsymoff, struct partial_symbol **global_syms,
   2173 	       struct partial_symbol **static_syms)
   2174 {
   2175   struct partial_symtab *result =
   2176     start_psymtab_common (objfile, filename, textlow,
   2177 			  global_syms, static_syms);
   2178 
   2179   result->read_symtab_private =
   2180     XOBNEW (&objfile->objfile_obstack, struct symloc);
   2181   LDSYMOFF (result) = ldsymoff;
   2182   result->read_symtab = dbx_read_symtab;
   2183   SYMBOL_SIZE (result) = symbol_size;
   2184   SYMBOL_OFFSET (result) = symbol_table_offset;
   2185   STRING_OFFSET (result) = string_table_offset;
   2186   FILE_STRING_OFFSET (result) = file_string_table_offset;
   2187 
   2188   /* Deduce the source language from the filename for this psymtab.  */
   2189   psymtab_language = deduce_language_from_filename (filename);
   2190 
   2191   return result;
   2192 }
   2193 
   2194 /* Close off the current usage of PST.
   2195    Returns PST or NULL if the partial symtab was empty and thrown away.
   2196 
   2197    FIXME:  List variables and peculiarities of same.  */
   2198 
   2199 struct partial_symtab *
   2200 dbx_end_psymtab (struct objfile *objfile, struct partial_symtab *pst,
   2201 		 const char **include_list, int num_includes,
   2202 		 int capping_symbol_offset, CORE_ADDR capping_text,
   2203 		 struct partial_symtab **dependency_list,
   2204 		 int number_dependencies,
   2205 		 int textlow_not_set)
   2206 {
   2207   int i;
   2208   struct gdbarch *gdbarch = get_objfile_arch (objfile);
   2209 
   2210   if (capping_symbol_offset != -1)
   2211     LDSYMLEN (pst) = capping_symbol_offset - LDSYMOFF (pst);
   2212   pst->texthigh = capping_text;
   2213 
   2214   /* Under Solaris, the N_SO symbols always have a value of 0,
   2215      instead of the usual address of the .o file.  Therefore,
   2216      we have to do some tricks to fill in texthigh and textlow.
   2217      The first trick is: if we see a static
   2218      or global function, and the textlow for the current pst
   2219      is not set (ie: textlow_not_set), then we use that function's
   2220      address for the textlow of the pst.  */
   2221 
   2222   /* Now, to fill in texthigh, we remember the last function seen
   2223      in the .o file.  Also, there's a hack in
   2224      bfd/elf.c and gdb/elfread.c to pass the ELF st_size field
   2225      to here via the misc_info field.  Therefore, we can fill in
   2226      a reliable texthigh by taking the address plus size of the
   2227      last function in the file.  */
   2228 
   2229   if (pst->texthigh == 0 && last_function_name
   2230       && gdbarch_sofun_address_maybe_missing (gdbarch))
   2231     {
   2232       char *p;
   2233       int n;
   2234       struct bound_minimal_symbol minsym;
   2235 
   2236       p = strchr (last_function_name, ':');
   2237       if (p == NULL)
   2238 	p = last_function_name;
   2239       n = p - last_function_name;
   2240       p = (char *) alloca (n + 2);
   2241       strncpy (p, last_function_name, n);
   2242       p[n] = 0;
   2243 
   2244       minsym = lookup_minimal_symbol (p, pst->filename, objfile);
   2245       if (minsym.minsym == NULL)
   2246 	{
   2247 	  /* Sun Fortran appends an underscore to the minimal symbol name,
   2248 	     try again with an appended underscore if the minimal symbol
   2249 	     was not found.  */
   2250 	  p[n] = '_';
   2251 	  p[n + 1] = 0;
   2252 	  minsym = lookup_minimal_symbol (p, pst->filename, objfile);
   2253 	}
   2254 
   2255       if (minsym.minsym)
   2256 	pst->texthigh = (BMSYMBOL_VALUE_ADDRESS (minsym)
   2257 			 + MSYMBOL_SIZE (minsym.minsym));
   2258 
   2259       last_function_name = NULL;
   2260     }
   2261 
   2262   if (!gdbarch_sofun_address_maybe_missing (gdbarch))
   2263     ;
   2264   /* This test will be true if the last .o file is only data.  */
   2265   else if (textlow_not_set)
   2266     pst->textlow = pst->texthigh;
   2267   else
   2268     {
   2269       struct partial_symtab *p1;
   2270 
   2271       /* If we know our own starting text address, then walk through all other
   2272          psymtabs for this objfile, and if any didn't know their ending text
   2273          address, set it to our starting address.  Take care to not set our
   2274          own ending address to our starting address, nor to set addresses on
   2275          `dependency' files that have both textlow and texthigh zero.  */
   2276 
   2277       ALL_OBJFILE_PSYMTABS (objfile, p1)
   2278       {
   2279 	if (p1->texthigh == 0 && p1->textlow != 0 && p1 != pst)
   2280 	  {
   2281 	    p1->texthigh = pst->textlow;
   2282 	    /* If this file has only data, then make textlow match
   2283 	       texthigh.  */
   2284 	    if (p1->textlow == 0)
   2285 	      p1->textlow = p1->texthigh;
   2286 	  }
   2287       }
   2288     }
   2289 
   2290   /* End of kludge for patching Solaris textlow and texthigh.  */
   2291 
   2292   end_psymtab_common (objfile, pst);
   2293 
   2294   pst->number_of_dependencies = number_dependencies;
   2295   if (number_dependencies)
   2296     {
   2297       pst->dependencies = XOBNEWVEC (&objfile->objfile_obstack,
   2298 				     struct partial_symtab *,
   2299 				     number_dependencies);
   2300       memcpy (pst->dependencies, dependency_list,
   2301 	      number_dependencies * sizeof (struct partial_symtab *));
   2302     }
   2303   else
   2304     pst->dependencies = 0;
   2305 
   2306   for (i = 0; i < num_includes; i++)
   2307     {
   2308       struct partial_symtab *subpst =
   2309 	allocate_psymtab (include_list[i], objfile);
   2310 
   2311       subpst->read_symtab_private =
   2312 	XOBNEW (&objfile->objfile_obstack, struct symloc);
   2313       LDSYMOFF (subpst) =
   2314 	LDSYMLEN (subpst) =
   2315 	subpst->textlow =
   2316 	subpst->texthigh = 0;
   2317 
   2318       /* We could save slight bits of space by only making one of these,
   2319          shared by the entire set of include files.  FIXME-someday.  */
   2320       subpst->dependencies =
   2321 	XOBNEW (&objfile->objfile_obstack, struct partial_symtab *);
   2322       subpst->dependencies[0] = pst;
   2323       subpst->number_of_dependencies = 1;
   2324 
   2325       subpst->globals_offset =
   2326 	subpst->n_global_syms =
   2327 	subpst->statics_offset =
   2328 	subpst->n_static_syms = 0;
   2329 
   2330       subpst->readin = 0;
   2331       subpst->compunit_symtab = 0;
   2332       subpst->read_symtab = pst->read_symtab;
   2333     }
   2334 
   2335   if (num_includes == 0
   2336       && number_dependencies == 0
   2337       && pst->n_global_syms == 0
   2338       && pst->n_static_syms == 0
   2339       && has_line_numbers == 0)
   2340     {
   2341       /* Throw away this psymtab, it's empty.  We can't deallocate it, since
   2342          it is on the obstack, but we can forget to chain it on the list.  */
   2343       /* Empty psymtabs happen as a result of header files which don't have
   2344          any symbols in them.  There can be a lot of them.  But this check
   2345          is wrong, in that a psymtab with N_SLINE entries but nothing else
   2346          is not empty, but we don't realize that.  Fixing that without slowing
   2347          things down might be tricky.  */
   2348 
   2349       discard_psymtab (objfile, pst);
   2350 
   2351       /* Indicate that psymtab was thrown away.  */
   2352       pst = NULL;
   2353     }
   2354   return pst;
   2355 }
   2356 
   2357 static void
   2359 dbx_psymtab_to_symtab_1 (struct objfile *objfile, struct partial_symtab *pst)
   2360 {
   2361   struct cleanup *old_chain;
   2362   int i;
   2363 
   2364   if (pst->readin)
   2365     {
   2366       fprintf_unfiltered (gdb_stderr, "Psymtab for %s already read in.  "
   2367 			  "Shouldn't happen.\n",
   2368 			  pst->filename);
   2369       return;
   2370     }
   2371 
   2372   /* Read in all partial symtabs on which this one is dependent.  */
   2373   for (i = 0; i < pst->number_of_dependencies; i++)
   2374     if (!pst->dependencies[i]->readin)
   2375       {
   2376 	/* Inform about additional files that need to be read in.  */
   2377 	if (info_verbose)
   2378 	  {
   2379 	    fputs_filtered (" ", gdb_stdout);
   2380 	    wrap_here ("");
   2381 	    fputs_filtered ("and ", gdb_stdout);
   2382 	    wrap_here ("");
   2383 	    printf_filtered ("%s...", pst->dependencies[i]->filename);
   2384 	    wrap_here ("");	/* Flush output.  */
   2385 	    gdb_flush (gdb_stdout);
   2386 	  }
   2387 	dbx_psymtab_to_symtab_1 (objfile, pst->dependencies[i]);
   2388       }
   2389 
   2390   if (LDSYMLEN (pst))		/* Otherwise it's a dummy.  */
   2391     {
   2392       /* Init stuff necessary for reading in symbols */
   2393       stabsread_init ();
   2394       buildsym_init ();
   2395       old_chain = make_cleanup (really_free_pendings, 0);
   2396       file_string_table_offset = FILE_STRING_OFFSET (pst);
   2397       symbol_size = SYMBOL_SIZE (pst);
   2398 
   2399       /* Read in this file's symbols.  */
   2400       bfd_seek (objfile->obfd, SYMBOL_OFFSET (pst), SEEK_SET);
   2401       read_ofile_symtab (objfile, pst);
   2402 
   2403       do_cleanups (old_chain);
   2404     }
   2405 
   2406   pst->readin = 1;
   2407 }
   2408 
   2409 /* Read in all of the symbols for a given psymtab for real.
   2410    Be verbose about it if the user wants that.  SELF is not NULL.  */
   2411 
   2412 static void
   2413 dbx_read_symtab (struct partial_symtab *self, struct objfile *objfile)
   2414 {
   2415   if (self->readin)
   2416     {
   2417       fprintf_unfiltered (gdb_stderr, "Psymtab for %s already read in.  "
   2418 			  "Shouldn't happen.\n",
   2419 			  self->filename);
   2420       return;
   2421     }
   2422 
   2423   if (LDSYMLEN (self) || self->number_of_dependencies)
   2424     {
   2425       struct cleanup *back_to;
   2426 
   2427       /* Print the message now, before reading the string table,
   2428          to avoid disconcerting pauses.  */
   2429       if (info_verbose)
   2430 	{
   2431 	  printf_filtered ("Reading in symbols for %s...", self->filename);
   2432 	  gdb_flush (gdb_stdout);
   2433 	}
   2434 
   2435       next_symbol_text_func = dbx_next_symbol_text;
   2436 
   2437       back_to = make_cleanup (null_cleanup, NULL);
   2438 
   2439       if (DBX_STAB_SECTION (objfile))
   2440 	{
   2441 	  stabs_data
   2442 	    = symfile_relocate_debug_section (objfile,
   2443 					      DBX_STAB_SECTION (objfile),
   2444 					      NULL);
   2445 
   2446 	  if (stabs_data)
   2447 	    make_cleanup (free_current_contents, (void *) &stabs_data);
   2448 	}
   2449 
   2450       dbx_psymtab_to_symtab_1 (objfile, self);
   2451 
   2452       do_cleanups (back_to);
   2453 
   2454       /* Match with global symbols.  This only needs to be done once,
   2455          after all of the symtabs and dependencies have been read in.   */
   2456       scan_file_globals (objfile);
   2457 
   2458       /* Finish up the debug error message.  */
   2459       if (info_verbose)
   2460 	printf_filtered ("done.\n");
   2461     }
   2462 }
   2463 
   2464 /* Read in a defined section of a specific object file's symbols.  */
   2465 
   2466 static void
   2467 read_ofile_symtab (struct objfile *objfile, struct partial_symtab *pst)
   2468 {
   2469   char *namestring;
   2470   struct external_nlist *bufp;
   2471   struct internal_nlist nlist;
   2472   unsigned char type;
   2473   unsigned max_symnum;
   2474   bfd *abfd;
   2475   int sym_offset;		/* Offset to start of symbols to read */
   2476   int sym_size;			/* Size of symbols to read */
   2477   CORE_ADDR text_offset;	/* Start of text segment for symbols */
   2478   int text_size;		/* Size of text segment for symbols */
   2479   struct section_offsets *section_offsets;
   2480 
   2481   sym_offset = LDSYMOFF (pst);
   2482   sym_size = LDSYMLEN (pst);
   2483   text_offset = pst->textlow;
   2484   text_size = pst->texthigh - pst->textlow;
   2485   section_offsets = objfile->section_offsets;
   2486 
   2487   dbxread_objfile = objfile;
   2488 
   2489   stringtab_global = DBX_STRINGTAB (objfile);
   2490   set_last_source_file (NULL);
   2491 
   2492   abfd = objfile->obfd;
   2493   symfile_bfd = objfile->obfd;	/* Implicit param to next_text_symbol.  */
   2494   symbuf_end = symbuf_idx = 0;
   2495   symbuf_read = 0;
   2496   symbuf_left = sym_offset + sym_size;
   2497 
   2498   /* It is necessary to actually read one symbol *before* the start
   2499      of this symtab's symbols, because the GCC_COMPILED_FLAG_SYMBOL
   2500      occurs before the N_SO symbol.
   2501 
   2502      Detecting this in read_dbx_symtab
   2503      would slow down initial readin, so we look for it here instead.  */
   2504   if (!processing_acc_compilation && sym_offset >= (int) symbol_size)
   2505     {
   2506       stabs_seek (sym_offset - symbol_size);
   2507       fill_symbuf (abfd);
   2508       bufp = &symbuf[symbuf_idx++];
   2509       INTERNALIZE_SYMBOL (nlist, bufp, abfd);
   2510       OBJSTAT (objfile, n_stabs++);
   2511 
   2512       namestring = set_namestring (objfile, &nlist);
   2513 
   2514       processing_gcc_compilation = 0;
   2515       if (nlist.n_type == N_TEXT)
   2516 	{
   2517 	  const char *tempstring = namestring;
   2518 
   2519 	  if (strcmp (namestring, GCC_COMPILED_FLAG_SYMBOL) == 0)
   2520 	    processing_gcc_compilation = 1;
   2521 	  else if (strcmp (namestring, GCC2_COMPILED_FLAG_SYMBOL) == 0)
   2522 	    processing_gcc_compilation = 2;
   2523 	  if (tempstring[0] == bfd_get_symbol_leading_char (symfile_bfd))
   2524 	    ++tempstring;
   2525 	  if (startswith (tempstring, "__gnu_compiled"))
   2526 	    processing_gcc_compilation = 2;
   2527 	}
   2528     }
   2529   else
   2530     {
   2531       /* The N_SO starting this symtab is the first symbol, so we
   2532          better not check the symbol before it.  I'm not this can
   2533          happen, but it doesn't hurt to check for it.  */
   2534       stabs_seek (sym_offset);
   2535       processing_gcc_compilation = 0;
   2536     }
   2537 
   2538   if (symbuf_idx == symbuf_end)
   2539     fill_symbuf (abfd);
   2540   bufp = &symbuf[symbuf_idx];
   2541   if (bfd_h_get_8 (abfd, bufp->e_type) != N_SO)
   2542     error (_("First symbol in segment of executable not a source symbol"));
   2543 
   2544   max_symnum = sym_size / symbol_size;
   2545 
   2546   for (symnum = 0;
   2547        symnum < max_symnum;
   2548        symnum++)
   2549     {
   2550       QUIT;			/* Allow this to be interruptable.  */
   2551       if (symbuf_idx == symbuf_end)
   2552 	fill_symbuf (abfd);
   2553       bufp = &symbuf[symbuf_idx++];
   2554       INTERNALIZE_SYMBOL (nlist, bufp, abfd);
   2555       OBJSTAT (objfile, n_stabs++);
   2556 
   2557       type = bfd_h_get_8 (abfd, bufp->e_type);
   2558 
   2559       namestring = set_namestring (objfile, &nlist);
   2560 
   2561       if (type & N_STAB)
   2562 	{
   2563 	  if (sizeof (nlist.n_value) > 4
   2564 	      /* We are a 64-bit debugger debugging a 32-bit program.  */
   2565 	      && (type == N_LSYM || type == N_PSYM))
   2566 	      /* We have to be careful with the n_value in the case of N_LSYM
   2567 		 and N_PSYM entries, because they are signed offsets from frame
   2568 		 pointer, but we actually read them as unsigned 32-bit values.
   2569 		 This is not a problem for 32-bit debuggers, for which negative
   2570 		 values end up being interpreted correctly (as negative
   2571 		 offsets) due to integer overflow.
   2572 		 But we need to sign-extend the value for 64-bit debuggers,
   2573 		 or we'll end up interpreting negative values as very large
   2574 		 positive offsets.  */
   2575 	    nlist.n_value = (nlist.n_value ^ 0x80000000) - 0x80000000;
   2576 	  process_one_symbol (type, nlist.n_desc, nlist.n_value,
   2577 			      namestring, section_offsets, objfile);
   2578 	}
   2579       /* We skip checking for a new .o or -l file; that should never
   2580          happen in this routine.  */
   2581       else if (type == N_TEXT)
   2582 	{
   2583 	  /* I don't think this code will ever be executed, because
   2584 	     the GCC_COMPILED_FLAG_SYMBOL usually is right before
   2585 	     the N_SO symbol which starts this source file.
   2586 	     However, there is no reason not to accept
   2587 	     the GCC_COMPILED_FLAG_SYMBOL anywhere.  */
   2588 
   2589 	  if (strcmp (namestring, GCC_COMPILED_FLAG_SYMBOL) == 0)
   2590 	    processing_gcc_compilation = 1;
   2591 	  else if (strcmp (namestring, GCC2_COMPILED_FLAG_SYMBOL) == 0)
   2592 	    processing_gcc_compilation = 2;
   2593 	}
   2594       else if (type & N_EXT || type == (unsigned char) N_TEXT
   2595 	       || type == (unsigned char) N_NBTEXT)
   2596 	{
   2597 	  /* Global symbol: see if we came across a dbx defintion for
   2598 	     a corresponding symbol.  If so, store the value.  Remove
   2599 	     syms from the chain when their values are stored, but
   2600 	     search the whole chain, as there may be several syms from
   2601 	     different files with the same name.  */
   2602 	  /* This is probably not true.  Since the files will be read
   2603 	     in one at a time, each reference to a global symbol will
   2604 	     be satisfied in each file as it appears.  So we skip this
   2605 	     section.  */
   2606 	  ;
   2607 	}
   2608     }
   2609 
   2610   /* In a Solaris elf file, this variable, which comes from the
   2611      value of the N_SO symbol, will still be 0.  Luckily, text_offset,
   2612      which comes from pst->textlow is correct.  */
   2613   if (last_source_start_addr == 0)
   2614     last_source_start_addr = text_offset;
   2615 
   2616   /* In reordered executables last_source_start_addr may not be the
   2617      lower bound for this symtab, instead use text_offset which comes
   2618      from pst->textlow which is correct.  */
   2619   if (last_source_start_addr > text_offset)
   2620     last_source_start_addr = text_offset;
   2621 
   2622   pst->compunit_symtab = end_symtab (text_offset + text_size,
   2623 				     SECT_OFF_TEXT (objfile));
   2624 
   2625   end_stabs ();
   2626 
   2627   dbxread_objfile = NULL;
   2628 }
   2629 
   2630 
   2632 /* Record the namespace that the function defined by SYMBOL was
   2633    defined in, if necessary.  BLOCK is the associated block; use
   2634    OBSTACK for allocation.  */
   2635 
   2636 static void
   2637 cp_set_block_scope (const struct symbol *symbol,
   2638 		    struct block *block,
   2639 		    struct obstack *obstack)
   2640 {
   2641   if (SYMBOL_DEMANGLED_NAME (symbol) != NULL)
   2642     {
   2643       /* Try to figure out the appropriate namespace from the
   2644 	 demangled name.  */
   2645 
   2646       /* FIXME: carlton/2003-04-15: If the function in question is
   2647 	 a method of a class, the name will actually include the
   2648 	 name of the class as well.  This should be harmless, but
   2649 	 is a little unfortunate.  */
   2650 
   2651       const char *name = SYMBOL_DEMANGLED_NAME (symbol);
   2652       unsigned int prefix_len = cp_entire_prefix_len (name);
   2653 
   2654       block_set_scope (block,
   2655 		       (const char *) obstack_copy0 (obstack, name, prefix_len),
   2656 		       obstack);
   2657     }
   2658 }
   2659 
   2660 /* This handles a single symbol from the symbol-file, building symbols
   2661    into a GDB symtab.  It takes these arguments and an implicit argument.
   2662 
   2663    TYPE is the type field of the ".stab" symbol entry.
   2664    DESC is the desc field of the ".stab" entry.
   2665    VALU is the value field of the ".stab" entry.
   2666    NAME is the symbol name, in our address space.
   2667    SECTION_OFFSETS is a set of amounts by which the sections of this
   2668    object file were relocated when it was loaded into memory.  Note
   2669    that these section_offsets are not the objfile->section_offsets but
   2670    the pst->section_offsets.  All symbols that refer to memory
   2671    locations need to be offset by these amounts.
   2672    OBJFILE is the object file from which we are reading symbols.  It
   2673    is used in end_symtab.  */
   2674 
   2675 void
   2676 process_one_symbol (int type, int desc, CORE_ADDR valu, char *name,
   2677 		    const struct section_offsets *section_offsets,
   2678 		    struct objfile *objfile)
   2679 {
   2680   struct gdbarch *gdbarch = get_objfile_arch (objfile);
   2681   struct context_stack *newobj;
   2682   /* This remembers the address of the start of a function.  It is
   2683      used because in Solaris 2, N_LBRAC, N_RBRAC, and N_SLINE entries
   2684      are relative to the current function's start address.  On systems
   2685      other than Solaris 2, this just holds the SECT_OFF_TEXT value,
   2686      and is used to relocate these symbol types rather than
   2687      SECTION_OFFSETS.  */
   2688   static CORE_ADDR function_start_offset;
   2689 
   2690   /* This holds the address of the start of a function, without the
   2691      system peculiarities of function_start_offset.  */
   2692   static CORE_ADDR last_function_start;
   2693 
   2694   /* If this is nonzero, we've seen an N_SLINE since the start of the
   2695      current function.  We use this to tell us to move the first sline
   2696      to the beginning of the function regardless of what its given
   2697      value is.  */
   2698   static int sline_found_in_function = 1;
   2699 
   2700   /* If this is nonzero, we've seen a non-gcc N_OPT symbol for this
   2701      source file.  Used to detect the SunPRO solaris compiler.  */
   2702   static int n_opt_found;
   2703 
   2704   if (!block_address_function_relative)
   2705     {
   2706       /* N_LBRAC, N_RBRAC and N_SLINE entries are not relative to the
   2707 	 function start address, so just use the text offset.  */
   2708       function_start_offset =
   2709 	ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
   2710     }
   2711 
   2712   /* Something is wrong if we see real data before seeing a source
   2713      file name.  */
   2714 
   2715   if (get_last_source_file () == NULL && type != (unsigned char) N_SO)
   2716     {
   2717       /* Ignore any symbols which appear before an N_SO symbol.
   2718          Currently no one puts symbols there, but we should deal
   2719          gracefully with the case.  A complain()t might be in order,
   2720          but this should not be an error ().  */
   2721       return;
   2722     }
   2723 
   2724   switch (type)
   2725     {
   2726     case N_FUN:
   2727     case N_FNAME:
   2728 
   2729       if (*name == '\000')
   2730 	{
   2731 	  /* This N_FUN marks the end of a function.  This closes off
   2732 	     the current block.  */
   2733 	  struct block *block;
   2734 
   2735  	  if (context_stack_depth <= 0)
   2736  	    {
   2737 	      lbrac_mismatch_complaint (symnum);
   2738  	      break;
   2739  	    }
   2740 
   2741 	  /* The following check is added before recording line 0 at
   2742 	     end of function so as to handle hand-generated stabs
   2743 	     which may have an N_FUN stabs at the end of the function,
   2744 	     but no N_SLINE stabs.  */
   2745 	  if (sline_found_in_function)
   2746 	    {
   2747 	      CORE_ADDR addr = last_function_start + valu;
   2748 
   2749 	      record_line (current_subfile, 0,
   2750 			   gdbarch_addr_bits_remove (gdbarch, addr));
   2751 	    }
   2752 
   2753 	  within_function = 0;
   2754 	  newobj = pop_context ();
   2755 
   2756 	  /* Make a block for the local symbols within.  */
   2757 	  block = finish_block (newobj->name, &local_symbols,
   2758 				newobj->old_blocks, NULL,
   2759 				newobj->start_addr, newobj->start_addr + valu);
   2760 
   2761 	  /* For C++, set the block's scope.  */
   2762 	  if (SYMBOL_LANGUAGE (newobj->name) == language_cplus)
   2763 	    cp_set_block_scope (newobj->name, block, &objfile->objfile_obstack);
   2764 
   2765 	  /* May be switching to an assembler file which may not be using
   2766 	     block relative stabs, so reset the offset.  */
   2767 	  if (block_address_function_relative)
   2768 	    function_start_offset = 0;
   2769 
   2770 	  break;
   2771 	}
   2772 
   2773       sline_found_in_function = 0;
   2774 
   2775       /* Relocate for dynamic loading.  */
   2776       valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
   2777       valu = gdbarch_addr_bits_remove (gdbarch, valu);
   2778       last_function_start = valu;
   2779 
   2780       goto define_a_symbol;
   2781 
   2782     case N_LBRAC:
   2783       /* This "symbol" just indicates the start of an inner lexical
   2784          context within a function.  */
   2785 
   2786       /* Ignore extra outermost context from SunPRO cc and acc.  */
   2787       if (n_opt_found && desc == 1)
   2788 	break;
   2789 
   2790       if (block_address_function_relative)
   2791 	/* Relocate for Sun ELF acc fn-relative syms.  */
   2792 	valu += function_start_offset;
   2793       else
   2794 	/* On most machines, the block addresses are relative to the
   2795 	   N_SO, the linker did not relocate them (sigh).  */
   2796 	valu += last_source_start_addr;
   2797 
   2798       push_context (desc, valu);
   2799       break;
   2800 
   2801     case N_RBRAC:
   2802       /* This "symbol" just indicates the end of an inner lexical
   2803          context that was started with N_LBRAC.  */
   2804 
   2805       /* Ignore extra outermost context from SunPRO cc and acc.  */
   2806       if (n_opt_found && desc == 1)
   2807 	break;
   2808 
   2809       if (block_address_function_relative)
   2810 	/* Relocate for Sun ELF acc fn-relative syms.  */
   2811 	valu += function_start_offset;
   2812       else
   2813 	/* On most machines, the block addresses are relative to the
   2814 	   N_SO, the linker did not relocate them (sigh).  */
   2815 	valu += last_source_start_addr;
   2816 
   2817       if (context_stack_depth <= 0)
   2818 	{
   2819 	  lbrac_mismatch_complaint (symnum);
   2820 	  break;
   2821 	}
   2822 
   2823       newobj = pop_context ();
   2824       if (desc != newobj->depth)
   2825 	lbrac_mismatch_complaint (symnum);
   2826 
   2827       if (local_symbols != NULL)
   2828 	{
   2829 	  /* GCC development snapshots from March to December of
   2830 	     2000 would output N_LSYM entries after N_LBRAC
   2831 	     entries.  As a consequence, these symbols are simply
   2832 	     discarded.  Complain if this is the case.  */
   2833 	  complaint (&symfile_complaints,
   2834 		     _("misplaced N_LBRAC entry; discarding local "
   2835 		       "symbols which have no enclosing block"));
   2836 	}
   2837       local_symbols = newobj->locals;
   2838 
   2839       if (context_stack_depth > 1)
   2840 	{
   2841 	  /* This is not the outermost LBRAC...RBRAC pair in the
   2842 	     function, its local symbols preceded it, and are the ones
   2843 	     just recovered from the context stack.  Define the block
   2844 	     for them (but don't bother if the block contains no
   2845 	     symbols.  Should we complain on blocks without symbols?
   2846 	     I can't think of any useful purpose for them).  */
   2847 	  if (local_symbols != NULL)
   2848 	    {
   2849 	      /* Muzzle a compiler bug that makes end < start.
   2850 
   2851 		 ??? Which compilers?  Is this ever harmful?.  */
   2852 	      if (newobj->start_addr > valu)
   2853 		{
   2854 		  complaint (&symfile_complaints,
   2855 			     _("block start larger than block end"));
   2856 		  newobj->start_addr = valu;
   2857 		}
   2858 	      /* Make a block for the local symbols within.  */
   2859 	      finish_block (0, &local_symbols, newobj->old_blocks, NULL,
   2860 			    newobj->start_addr, valu);
   2861 	    }
   2862 	}
   2863       else
   2864 	{
   2865 	  /* This is the outermost LBRAC...RBRAC pair.  There is no
   2866 	     need to do anything; leave the symbols that preceded it
   2867 	     to be attached to the function's own block.  We need to
   2868 	     indicate that we just moved outside of the function.  */
   2869 	  within_function = 0;
   2870 	}
   2871 
   2872       break;
   2873 
   2874     case N_FN:
   2875     case N_FN_SEQ:
   2876       /* This kind of symbol indicates the start of an object file.
   2877          Relocate for dynamic loading.  */
   2878       valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
   2879       break;
   2880 
   2881     case N_SO:
   2882       /* This type of symbol indicates the start of data for one
   2883          source file.  Finish the symbol table of the previous source
   2884          file (if any) and start accumulating a new symbol table.
   2885          Relocate for dynamic loading.  */
   2886       valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
   2887 
   2888       n_opt_found = 0;
   2889 
   2890       if (get_last_source_file ())
   2891 	{
   2892 	  /* Check if previous symbol was also an N_SO (with some
   2893 	     sanity checks).  If so, that one was actually the
   2894 	     directory name, and the current one is the real file
   2895 	     name.  Patch things up.  */
   2896 	  if (previous_stab_code == (unsigned char) N_SO)
   2897 	    {
   2898 	      patch_subfile_names (current_subfile, name);
   2899 	      break;		/* Ignore repeated SOs.  */
   2900 	    }
   2901 	  end_symtab (valu, SECT_OFF_TEXT (objfile));
   2902 	  end_stabs ();
   2903 	}
   2904 
   2905       /* Null name means this just marks the end of text for this .o
   2906          file.  Don't start a new symtab in this case.  */
   2907       if (*name == '\000')
   2908 	break;
   2909 
   2910       if (block_address_function_relative)
   2911 	function_start_offset = 0;
   2912 
   2913       start_stabs ();
   2914       start_symtab (objfile, name, NULL, valu);
   2915       record_debugformat ("stabs");
   2916       break;
   2917 
   2918     case N_SOL:
   2919       /* This type of symbol indicates the start of data for a
   2920          sub-source-file, one whose contents were copied or included
   2921          in the compilation of the main source file (whose name was
   2922          given in the N_SO symbol).  Relocate for dynamic loading.  */
   2923       valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
   2924       start_subfile (name);
   2925       break;
   2926 
   2927     case N_BINCL:
   2928       push_subfile ();
   2929       add_new_header_file (name, valu);
   2930       start_subfile (name);
   2931       break;
   2932 
   2933     case N_EINCL:
   2934       start_subfile (pop_subfile ());
   2935       break;
   2936 
   2937     case N_EXCL:
   2938       add_old_header_file (name, valu);
   2939       break;
   2940 
   2941     case N_SLINE:
   2942       /* This type of "symbol" really just records one line-number --
   2943          core-address correspondence.  Enter it in the line list for
   2944          this symbol table.  */
   2945 
   2946       /* Relocate for dynamic loading and for ELF acc
   2947          function-relative symbols.  */
   2948       valu += function_start_offset;
   2949 
   2950       /* GCC 2.95.3 emits the first N_SLINE stab somwehere in the
   2951 	 middle of the prologue instead of right at the start of the
   2952 	 function.  To deal with this we record the address for the
   2953 	 first N_SLINE stab to be the start of the function instead of
   2954 	 the listed location.  We really shouldn't to this.  When
   2955 	 compiling with optimization, this first N_SLINE stab might be
   2956 	 optimized away.  Other (non-GCC) compilers don't emit this
   2957 	 stab at all.  There is no real harm in having an extra
   2958 	 numbered line, although it can be a bit annoying for the
   2959 	 user.  However, it totally screws up our testsuite.
   2960 
   2961 	 So for now, keep adjusting the address of the first N_SLINE
   2962 	 stab, but only for code compiled with GCC.  */
   2963 
   2964       if (within_function && sline_found_in_function == 0)
   2965 	{
   2966 	  CORE_ADDR addr = processing_gcc_compilation == 2 ?
   2967 			   last_function_start : valu;
   2968 
   2969 	  record_line (current_subfile, desc,
   2970 		       gdbarch_addr_bits_remove (gdbarch, addr));
   2971 	  sline_found_in_function = 1;
   2972 	}
   2973       else
   2974 	record_line (current_subfile, desc,
   2975 		     gdbarch_addr_bits_remove (gdbarch, valu));
   2976       break;
   2977 
   2978     case N_BCOMM:
   2979       common_block_start (name, objfile);
   2980       break;
   2981 
   2982     case N_ECOMM:
   2983       common_block_end (objfile);
   2984       break;
   2985 
   2986       /* The following symbol types need to have the appropriate
   2987          offset added to their value; then we process symbol
   2988          definitions in the name.  */
   2989 
   2990     case N_STSYM:		/* Static symbol in data segment.  */
   2991     case N_LCSYM:		/* Static symbol in BSS segment.  */
   2992     case N_ROSYM:		/* Static symbol in read-only data segment.  */
   2993       /* HORRID HACK DEPT.  However, it's Sun's furgin' fault.
   2994          Solaris 2's stabs-in-elf makes *most* symbols relative but
   2995          leaves a few absolute (at least for Solaris 2.1 and version
   2996          2.0.1 of the SunPRO compiler).  N_STSYM and friends sit on
   2997          the fence.  .stab "foo:S...",N_STSYM is absolute (ld
   2998          relocates it) .stab "foo:V...",N_STSYM is relative (section
   2999          base subtracted).  This leaves us no choice but to search for
   3000          the 'S' or 'V'...  (or pass the whole section_offsets stuff
   3001          down ONE MORE function call level, which we really don't want
   3002          to do).  */
   3003       {
   3004 	char *p;
   3005 
   3006 	/* Normal object file and NLMs have non-zero text seg offsets,
   3007 	   but don't need their static syms offset in this fashion.
   3008 	   XXX - This is really a crock that should be fixed in the
   3009 	   solib handling code so that I don't have to work around it
   3010 	   here.  */
   3011 
   3012 	if (!symfile_relocatable)
   3013 	  {
   3014 	    p = strchr (name, ':');
   3015 	    if (p != 0 && p[1] == 'S')
   3016 	      {
   3017 		/* The linker relocated it.  We don't want to add a
   3018 		   Sun-stabs Tfoo.foo-like offset, but we *do*
   3019 		   want to add whatever solib.c passed to
   3020 		   symbol_file_add as addr (this is known to affect
   3021 		   SunOS 4, and I suspect ELF too).  Since there is no
   3022 		   Ttext.text symbol, we can get addr from the text offset.  */
   3023 		valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
   3024 		goto define_a_symbol;
   3025 	      }
   3026 	  }
   3027 	/* Since it's not the kludge case, re-dispatch to the right
   3028            handler.  */
   3029 	switch (type)
   3030 	  {
   3031 	  case N_STSYM:
   3032 	    goto case_N_STSYM;
   3033 	  case N_LCSYM:
   3034 	    goto case_N_LCSYM;
   3035 	  case N_ROSYM:
   3036 	    goto case_N_ROSYM;
   3037 	  default:
   3038 	    internal_error (__FILE__, __LINE__,
   3039 			    _("failed internal consistency check"));
   3040 	  }
   3041       }
   3042 
   3043     case_N_STSYM:		/* Static symbol in data segment.  */
   3044     case N_DSLINE:		/* Source line number, data segment.  */
   3045       valu += ANOFFSET (section_offsets, SECT_OFF_DATA (objfile));
   3046       goto define_a_symbol;
   3047 
   3048     case_N_LCSYM:		/* Static symbol in BSS segment.  */
   3049     case N_BSLINE:		/* Source line number, BSS segment.  */
   3050       /* N_BROWS: overlaps with N_BSLINE.  */
   3051       valu += ANOFFSET (section_offsets, SECT_OFF_BSS (objfile));
   3052       goto define_a_symbol;
   3053 
   3054     case_N_ROSYM:		/* Static symbol in read-only data segment.  */
   3055       valu += ANOFFSET (section_offsets, SECT_OFF_RODATA (objfile));
   3056       goto define_a_symbol;
   3057 
   3058     case N_ENTRY:		/* Alternate entry point.  */
   3059       /* Relocate for dynamic loading.  */
   3060       valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
   3061       goto define_a_symbol;
   3062 
   3063       /* The following symbol types we don't know how to process.
   3064          Handle them in a "default" way, but complain to people who
   3065          care.  */
   3066     default:
   3067     case N_CATCH:		/* Exception handler catcher.  */
   3068     case N_EHDECL:		/* Exception handler name.  */
   3069     case N_PC:			/* Global symbol in Pascal.  */
   3070     case N_M2C:			/* Modula-2 compilation unit.  */
   3071       /* N_MOD2: overlaps with N_EHDECL.  */
   3072     case N_SCOPE:		/* Modula-2 scope information.  */
   3073     case N_ECOML:		/* End common (local name).  */
   3074     case N_NBTEXT:		/* Gould Non-Base-Register symbols???  */
   3075     case N_NBDATA:
   3076     case N_NBBSS:
   3077     case N_NBSTS:
   3078     case N_NBLCS:
   3079       unknown_symtype_complaint (hex_string (type));
   3080       /* FALLTHROUGH */
   3081 
   3082       /* The following symbol types don't need the address field
   3083          relocated, since it is either unused, or is absolute.  */
   3084     define_a_symbol:
   3085     case N_GSYM:		/* Global variable.  */
   3086     case N_NSYMS:		/* Number of symbols (Ultrix).  */
   3087     case N_NOMAP:		/* No map?  (Ultrix).  */
   3088     case N_RSYM:		/* Register variable.  */
   3089     case N_DEFD:		/* Modula-2 GNU module dependency.  */
   3090     case N_SSYM:		/* Struct or union element.  */
   3091     case N_LSYM:		/* Local symbol in stack.  */
   3092     case N_PSYM:		/* Parameter variable.  */
   3093     case N_LENG:		/* Length of preceding symbol type.  */
   3094       if (name)
   3095 	{
   3096 	  int deftype;
   3097 	  char *colon_pos = strchr (name, ':');
   3098 
   3099 	  if (colon_pos == NULL)
   3100 	    deftype = '\0';
   3101 	  else
   3102 	    deftype = colon_pos[1];
   3103 
   3104 	  switch (deftype)
   3105 	    {
   3106 	    case 'f':
   3107 	    case 'F':
   3108 	      /* Deal with the SunPRO 3.0 compiler which omits the
   3109 	         address from N_FUN symbols.  */
   3110 	      if (type == N_FUN
   3111 		  && valu == ANOFFSET (section_offsets,
   3112 				       SECT_OFF_TEXT (objfile))
   3113 		  && gdbarch_sofun_address_maybe_missing (gdbarch))
   3114 		{
   3115 		  CORE_ADDR minsym_valu =
   3116 		    find_stab_function_addr (name, get_last_source_file (),
   3117 					     objfile);
   3118 
   3119 		  /* The function find_stab_function_addr will return
   3120 		     0 if the minimal symbol wasn't found.
   3121 		     (Unfortunately, this might also be a valid
   3122 		     address.)  Anyway, if it *does* return 0, it is
   3123 		     likely that the value was set correctly to begin
   3124 		     with...  */
   3125 		  if (minsym_valu != 0)
   3126 		    valu = minsym_valu;
   3127 		}
   3128 
   3129 	      if (block_address_function_relative)
   3130 		/* For Solaris 2 compilers, the block addresses and
   3131 		   N_SLINE's are relative to the start of the
   3132 		   function.  On normal systems, and when using GCC on
   3133 		   Solaris 2, these addresses are just absolute, or
   3134 		   relative to the N_SO, depending on
   3135 		   BLOCK_ADDRESS_ABSOLUTE.  */
   3136 		function_start_offset = valu;
   3137 
   3138 	      within_function = 1;
   3139 
   3140 	      if (context_stack_depth > 1)
   3141 		{
   3142 		  complaint (&symfile_complaints,
   3143 			     _("unmatched N_LBRAC before symtab pos %d"),
   3144 			     symnum);
   3145 		  break;
   3146 		}
   3147 
   3148 	      if (context_stack_depth > 0)
   3149 		{
   3150 		  struct block *block;
   3151 
   3152 		  newobj = pop_context ();
   3153 		  /* Make a block for the local symbols within.  */
   3154 		  block = finish_block (newobj->name, &local_symbols,
   3155 					newobj->old_blocks, NULL,
   3156 					newobj->start_addr, valu);
   3157 
   3158 		  /* For C++, set the block's scope.  */
   3159 		  if (SYMBOL_LANGUAGE (newobj->name) == language_cplus)
   3160 		    cp_set_block_scope (newobj->name, block,
   3161 					&objfile->objfile_obstack);
   3162 		}
   3163 
   3164 	      newobj = push_context (0, valu);
   3165 	      newobj->name = define_symbol (valu, name, desc, type, objfile);
   3166 	      break;
   3167 
   3168 	    default:
   3169 	      define_symbol (valu, name, desc, type, objfile);
   3170 	      break;
   3171 	    }
   3172 	}
   3173       break;
   3174 
   3175       /* We use N_OPT to carry the gcc2_compiled flag.  Sun uses it
   3176          for a bunch of other flags, too.  Someday we may parse their
   3177          flags; for now we ignore theirs and hope they'll ignore ours.  */
   3178     case N_OPT:			/* Solaris 2: Compiler options.  */
   3179       if (name)
   3180 	{
   3181 	  if (strcmp (name, GCC2_COMPILED_FLAG_SYMBOL) == 0)
   3182 	    {
   3183 	      processing_gcc_compilation = 2;
   3184 	    }
   3185 	  else
   3186 	    n_opt_found = 1;
   3187 	}
   3188       break;
   3189 
   3190     case N_MAIN:		/* Name of main routine.  */
   3191       /* FIXME: If one has a symbol file with N_MAIN and then replaces
   3192 	 it with a symbol file with "main" and without N_MAIN.  I'm
   3193 	 not sure exactly what rule to follow but probably something
   3194 	 like: N_MAIN takes precedence over "main" no matter what
   3195 	 objfile it is in; If there is more than one N_MAIN, choose
   3196 	 the one in the symfile_objfile; If there is more than one
   3197 	 N_MAIN within a given objfile, complain() and choose
   3198 	 arbitrarily.  (kingdon) */
   3199       if (name != NULL)
   3200 	set_objfile_main_name (objfile, name, language_unknown);
   3201       break;
   3202 
   3203       /* The following symbol types can be ignored.  */
   3204     case N_OBJ:			/* Solaris 2: Object file dir and name.  */
   3205     case N_PATCH:		/* Solaris 2: Patch Run Time Checker.  */
   3206       /* N_UNDF:                   Solaris 2: File separator mark.  */
   3207       /* N_UNDF: -- we will never encounter it, since we only process
   3208          one file's symbols at once.  */
   3209     case N_ENDM:		/* Solaris 2: End of module.  */
   3210     case N_ALIAS:		/* SunPro F77: alias name, ignore for now.  */
   3211       break;
   3212     }
   3213 
   3214   /* '#' is a GNU C extension to allow one symbol to refer to another
   3215      related symbol.
   3216 
   3217      Generally this is used so that an alias can refer to its main
   3218      symbol.  */
   3219   gdb_assert (name);
   3220   if (name[0] == '#')
   3221     {
   3222       /* Initialize symbol reference names and determine if this is a
   3223          definition.  If a symbol reference is being defined, go ahead
   3224          and add it.  Otherwise, just return.  */
   3225 
   3226       char *s = name;
   3227       int refnum;
   3228 
   3229       /* If this stab defines a new reference ID that is not on the
   3230          reference list, then put it on the reference list.
   3231 
   3232          We go ahead and advance NAME past the reference, even though
   3233          it is not strictly necessary at this time.  */
   3234       refnum = symbol_reference_defined (&s);
   3235       if (refnum >= 0)
   3236 	if (!ref_search (refnum))
   3237 	  ref_add (refnum, 0, name, valu);
   3238       name = s;
   3239     }
   3240 
   3241   previous_stab_code = type;
   3242 }
   3243 
   3244 /* FIXME: The only difference between this and elfstab_build_psymtabs
   3246    is the call to install_minimal_symbols for elf, and the support for
   3247    split sections.  If the differences are really that small, the code
   3248    should be shared.  */
   3249 
   3250 /* Scan and build partial symbols for an coff symbol file.
   3251    The coff file has already been processed to get its minimal symbols.
   3252 
   3253    This routine is the equivalent of dbx_symfile_init and dbx_symfile_read
   3254    rolled into one.
   3255 
   3256    OBJFILE is the object file we are reading symbols from.
   3257    ADDR is the address relative to which the symbols are (e.g.
   3258    the base address of the text segment).
   3259    TEXTADDR is the address of the text section.
   3260    TEXTSIZE is the size of the text section.
   3261    STABSECTS is the list of .stab sections in OBJFILE.
   3262    STABSTROFFSET and STABSTRSIZE define the location in OBJFILE where the
   3263    .stabstr section exists.
   3264 
   3265    This routine is mostly copied from dbx_symfile_init and dbx_symfile_read,
   3266    adjusted for coff details.  */
   3267 
   3268 void
   3269 coffstab_build_psymtabs (struct objfile *objfile,
   3270 			 CORE_ADDR textaddr, unsigned int textsize,
   3271 			 struct stab_section_list *stabsects,
   3272 			 file_ptr stabstroffset, unsigned int stabstrsize)
   3273 {
   3274   int val;
   3275   bfd *sym_bfd = objfile->obfd;
   3276   char *name = bfd_get_filename (sym_bfd);
   3277   unsigned int stabsize;
   3278 
   3279   DBX_TEXT_ADDR (objfile) = textaddr;
   3280   DBX_TEXT_SIZE (objfile) = textsize;
   3281 
   3282 #define	COFF_STABS_SYMBOL_SIZE	12	/* XXX FIXME XXX */
   3283   DBX_SYMBOL_SIZE (objfile) = COFF_STABS_SYMBOL_SIZE;
   3284   DBX_STRINGTAB_SIZE (objfile) = stabstrsize;
   3285 
   3286   if (stabstrsize > bfd_get_size (sym_bfd))
   3287     error (_("ridiculous string table size: %d bytes"), stabstrsize);
   3288   DBX_STRINGTAB (objfile) = (char *)
   3289     obstack_alloc (&objfile->objfile_obstack, stabstrsize + 1);
   3290   OBJSTAT (objfile, sz_strtab += stabstrsize + 1);
   3291 
   3292   /* Now read in the string table in one big gulp.  */
   3293 
   3294   val = bfd_seek (sym_bfd, stabstroffset, SEEK_SET);
   3295   if (val < 0)
   3296     perror_with_name (name);
   3297   val = bfd_bread (DBX_STRINGTAB (objfile), stabstrsize, sym_bfd);
   3298   if (val != stabstrsize)
   3299     perror_with_name (name);
   3300 
   3301   stabsread_new_init ();
   3302   buildsym_new_init ();
   3303   free_header_files ();
   3304   init_header_files ();
   3305 
   3306   processing_acc_compilation = 1;
   3307 
   3308   /* In a coff file, we've already installed the minimal symbols that came
   3309      from the coff (non-stab) symbol table, so always act like an
   3310      incremental load here.  */
   3311   if (stabsects->next == NULL)
   3312     {
   3313       stabsize = bfd_section_size (sym_bfd, stabsects->section);
   3314       DBX_SYMCOUNT (objfile) = stabsize / DBX_SYMBOL_SIZE (objfile);
   3315       DBX_SYMTAB_OFFSET (objfile) = stabsects->section->filepos;
   3316     }
   3317   else
   3318     {
   3319       struct stab_section_list *stabsect;
   3320 
   3321       DBX_SYMCOUNT (objfile) = 0;
   3322       for (stabsect = stabsects; stabsect != NULL; stabsect = stabsect->next)
   3323 	{
   3324 	  stabsize = bfd_section_size (sym_bfd, stabsect->section);
   3325 	  DBX_SYMCOUNT (objfile) += stabsize / DBX_SYMBOL_SIZE (objfile);
   3326 	}
   3327 
   3328       DBX_SYMTAB_OFFSET (objfile) = stabsects->section->filepos;
   3329 
   3330       symbuf_sections = stabsects->next;
   3331       symbuf_left = bfd_section_size (sym_bfd, stabsects->section);
   3332       symbuf_read = 0;
   3333     }
   3334 
   3335   dbx_symfile_read (objfile, 0);
   3336 }
   3337 
   3338 /* Scan and build partial symbols for an ELF symbol file.
   3340    This ELF file has already been processed to get its minimal symbols.
   3341 
   3342    This routine is the equivalent of dbx_symfile_init and dbx_symfile_read
   3343    rolled into one.
   3344 
   3345    OBJFILE is the object file we are reading symbols from.
   3346    ADDR is the address relative to which the symbols are (e.g.
   3347    the base address of the text segment).
   3348    STABSECT is the BFD section information for the .stab section.
   3349    STABSTROFFSET and STABSTRSIZE define the location in OBJFILE where the
   3350    .stabstr section exists.
   3351 
   3352    This routine is mostly copied from dbx_symfile_init and dbx_symfile_read,
   3353    adjusted for elf details.  */
   3354 
   3355 void
   3356 elfstab_build_psymtabs (struct objfile *objfile, asection *stabsect,
   3357 			file_ptr stabstroffset, unsigned int stabstrsize)
   3358 {
   3359   int val;
   3360   bfd *sym_bfd = objfile->obfd;
   3361   char *name = bfd_get_filename (sym_bfd);
   3362   struct cleanup *back_to = make_cleanup (null_cleanup, NULL);
   3363 
   3364   /* Find the first and last text address.  dbx_symfile_read seems to
   3365      want this.  */
   3366   find_text_range (sym_bfd, objfile);
   3367 
   3368 #define	ELF_STABS_SYMBOL_SIZE	12	/* XXX FIXME XXX */
   3369   DBX_SYMBOL_SIZE (objfile) = ELF_STABS_SYMBOL_SIZE;
   3370   DBX_SYMCOUNT (objfile)
   3371     = bfd_section_size (objfile->obfd, stabsect) / DBX_SYMBOL_SIZE (objfile);
   3372   DBX_STRINGTAB_SIZE (objfile) = stabstrsize;
   3373   DBX_SYMTAB_OFFSET (objfile) = stabsect->filepos;
   3374   DBX_STAB_SECTION (objfile) = stabsect;
   3375 
   3376   if (stabstrsize > bfd_get_size (sym_bfd))
   3377     error (_("ridiculous string table size: %d bytes"), stabstrsize);
   3378   DBX_STRINGTAB (objfile) = (char *)
   3379     obstack_alloc (&objfile->objfile_obstack, stabstrsize + 1);
   3380   OBJSTAT (objfile, sz_strtab += stabstrsize + 1);
   3381 
   3382   /* Now read in the string table in one big gulp.  */
   3383 
   3384   val = bfd_seek (sym_bfd, stabstroffset, SEEK_SET);
   3385   if (val < 0)
   3386     perror_with_name (name);
   3387   val = bfd_bread (DBX_STRINGTAB (objfile), stabstrsize, sym_bfd);
   3388   if (val != stabstrsize)
   3389     perror_with_name (name);
   3390 
   3391   stabsread_new_init ();
   3392   buildsym_new_init ();
   3393   free_header_files ();
   3394   init_header_files ();
   3395 
   3396   processing_acc_compilation = 1;
   3397 
   3398   symbuf_read = 0;
   3399   symbuf_left = bfd_section_size (objfile->obfd, stabsect);
   3400   stabs_data = symfile_relocate_debug_section (objfile, stabsect, NULL);
   3401   if (stabs_data)
   3402     make_cleanup (free_current_contents, (void *) &stabs_data);
   3403 
   3404   /* In an elf file, we've already installed the minimal symbols that came
   3405      from the elf (non-stab) symbol table, so always act like an
   3406      incremental load here.  dbx_symfile_read should not generate any new
   3407      minimal symbols, since we will have already read the ELF dynamic symbol
   3408      table and normal symbol entries won't be in the ".stab" section; but in
   3409      case it does, it will install them itself.  */
   3410   dbx_symfile_read (objfile, 0);
   3411 
   3412   do_cleanups (back_to);
   3413 }
   3414 
   3415 /* Scan and build partial symbols for a file with special sections for stabs
   3417    and stabstrings.  The file has already been processed to get its minimal
   3418    symbols, and any other symbols that might be necessary to resolve GSYMs.
   3419 
   3420    This routine is the equivalent of dbx_symfile_init and dbx_symfile_read
   3421    rolled into one.
   3422 
   3423    OBJFILE is the object file we are reading symbols from.
   3424    ADDR is the address relative to which the symbols are (e.g. the base address
   3425    of the text segment).
   3426    STAB_NAME is the name of the section that contains the stabs.
   3427    STABSTR_NAME is the name of the section that contains the stab strings.
   3428 
   3429    This routine is mostly copied from dbx_symfile_init and
   3430    dbx_symfile_read.  */
   3431 
   3432 void
   3433 stabsect_build_psymtabs (struct objfile *objfile, char *stab_name,
   3434 			 char *stabstr_name, char *text_name)
   3435 {
   3436   int val;
   3437   bfd *sym_bfd = objfile->obfd;
   3438   char *name = bfd_get_filename (sym_bfd);
   3439   asection *stabsect;
   3440   asection *stabstrsect;
   3441   asection *text_sect;
   3442   struct dbx_symfile_info *dbx;
   3443 
   3444   stabsect = bfd_get_section_by_name (sym_bfd, stab_name);
   3445   stabstrsect = bfd_get_section_by_name (sym_bfd, stabstr_name);
   3446 
   3447   if (!stabsect)
   3448     return;
   3449 
   3450   if (!stabstrsect)
   3451     error (_("stabsect_build_psymtabs:  Found stabs (%s), "
   3452 	     "but not string section (%s)"),
   3453 	   stab_name, stabstr_name);
   3454 
   3455   dbx = XCNEW (struct dbx_symfile_info);
   3456   set_objfile_data (objfile, dbx_objfile_data_key, dbx);
   3457 
   3458   text_sect = bfd_get_section_by_name (sym_bfd, text_name);
   3459   if (!text_sect)
   3460     error (_("Can't find %s section in symbol file"), text_name);
   3461   DBX_TEXT_ADDR (objfile) = bfd_section_vma (sym_bfd, text_sect);
   3462   DBX_TEXT_SIZE (objfile) = bfd_section_size (sym_bfd, text_sect);
   3463 
   3464   DBX_SYMBOL_SIZE (objfile) = sizeof (struct external_nlist);
   3465   DBX_SYMCOUNT (objfile) = bfd_section_size (sym_bfd, stabsect)
   3466     / DBX_SYMBOL_SIZE (objfile);
   3467   DBX_STRINGTAB_SIZE (objfile) = bfd_section_size (sym_bfd, stabstrsect);
   3468   DBX_SYMTAB_OFFSET (objfile) = stabsect->filepos;	/* XXX - FIXME: POKING
   3469 							   INSIDE BFD DATA
   3470 							   STRUCTURES */
   3471 
   3472   if (DBX_STRINGTAB_SIZE (objfile) > bfd_get_size (sym_bfd))
   3473     error (_("ridiculous string table size: %d bytes"),
   3474 	   DBX_STRINGTAB_SIZE (objfile));
   3475   DBX_STRINGTAB (objfile) = (char *)
   3476     obstack_alloc (&objfile->objfile_obstack,
   3477 		   DBX_STRINGTAB_SIZE (objfile) + 1);
   3478   OBJSTAT (objfile, sz_strtab += DBX_STRINGTAB_SIZE (objfile) + 1);
   3479 
   3480   /* Now read in the string table in one big gulp.  */
   3481 
   3482   val = bfd_get_section_contents (sym_bfd,	/* bfd */
   3483 				  stabstrsect,	/* bfd section */
   3484 				  DBX_STRINGTAB (objfile), /* input buffer */
   3485 				  0,		/* offset into section */
   3486 				  DBX_STRINGTAB_SIZE (objfile)); /* amount to
   3487 								    read */
   3488 
   3489   if (!val)
   3490     perror_with_name (name);
   3491 
   3492   stabsread_new_init ();
   3493   buildsym_new_init ();
   3494   free_header_files ();
   3495   init_header_files ();
   3496 
   3497   /* Now, do an incremental load.  */
   3498 
   3499   processing_acc_compilation = 1;
   3500   dbx_symfile_read (objfile, 0);
   3501 }
   3502 
   3503 static const struct sym_fns aout_sym_fns =
   3505 {
   3506   dbx_new_init,			/* init anything gbl to entire symtab */
   3507   dbx_symfile_init,		/* read initial info, setup for sym_read() */
   3508   dbx_symfile_read,		/* read a symbol file into symtab */
   3509   NULL,				/* sym_read_psymbols */
   3510   dbx_symfile_finish,		/* finished with file, cleanup */
   3511   default_symfile_offsets, 	/* parse user's offsets to internal form */
   3512   default_symfile_segments,	/* Get segment information from a file.  */
   3513   NULL,
   3514   default_symfile_relocate,	/* Relocate a debug section.  */
   3515   NULL,				/* sym_probe_fns */
   3516   &psym_functions
   3517 };
   3518 
   3519 void
   3520 _initialize_dbxread (void)
   3521 {
   3522   add_symtab_fns (bfd_target_aout_flavour, &aout_sym_fns);
   3523 
   3524   dbx_objfile_data_key
   3525     = register_objfile_data_with_cleanup (NULL, dbx_free_symfile_info);
   3526 }
   3527