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