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