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