gdb/dbxread.c - gdb

Global variables defined

Data types defined

Functions defined

Macros defined

Source code

  1. /* Read dbx symbol tables and convert to internal format, for GDB.
  2.    Copyright (C) 1986-2015 Free Software Foundation, Inc.

  3.    This file is part of GDB.

  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 3 of the License, or
  7.    (at your option) any later version.

  8.    This program is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.    GNU General Public License for more details.

  12.    You should have received a copy of the GNU General Public License
  13.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  14. /* This module provides three functions: dbx_symfile_init,
  15.    which initializes to read a symbol file; dbx_new_init, which
  16.    discards existing cached information when all symbols are being
  17.    discarded; and dbx_symfile_read, which reads a symbol table
  18.    from a file.

  19.    dbx_symfile_read only does the minimum work necessary for letting the
  20.    user "name" things symbolically; it does not read the entire symtab.
  21.    Instead, it reads the external and static symbols and puts them in partial
  22.    symbol tables.  When more extensive information is requested of a
  23.    file, the corresponding partial symbol table is mutated into a full
  24.    fledged symbol table by going back and reading the symbols
  25.    for real.  dbx_psymtab_to_symtab() is the function that does this */

  26. #include "defs.h"
  27. #if defined(__CYGNUSCLIB__)
  28. #include <sys/types.h>
  29. #include <fcntl.h>
  30. #endif

  31. #include "gdb_obstack.h"
  32. #include <sys/stat.h>
  33. #include "symtab.h"
  34. #include "breakpoint.h"
  35. #include "target.h"
  36. #include "gdbcore.h"                /* for bfd stuff */
  37. #include "libaout.h"                /* FIXME Secret internal BFD stuff for a.out */
  38. #include "filenames.h"
  39. #include "objfiles.h"
  40. #include "buildsym.h"
  41. #include "stabsread.h"
  42. #include "gdb-stabs.h"
  43. #include "demangle.h"
  44. #include "complaints.h"
  45. #include "cp-abi.h"
  46. #include "cp-support.h"
  47. #include "psympriv.h"
  48. #include "block.h"

  49. #include "aout/aout64.h"
  50. #include "aout/stab_gnu.h"        /* We always use GNU stabs, not
  51.                                    native, now.  */


  52. /* Key for dbx-associated data.  */

  53. const struct objfile_data *dbx_objfile_data_key;

  54. /* We put a pointer to this structure in the read_symtab_private field
  55.    of the psymtab.  */

  56. struct symloc
  57.   {
  58.     /* Offset within the file symbol table of first local symbol for this
  59.        file.  */

  60.     int ldsymoff;

  61.     /* Length (in bytes) of the section of the symbol table devoted to
  62.        this file's symbols (actually, the section bracketed may contain
  63.        more than just this file's symbols).  If ldsymlen is 0, the only
  64.        reason for this thing's existence is the dependency list.  Nothing
  65.        else will happen when it is read in.  */

  66.     int ldsymlen;

  67.     /* The size of each symbol in the symbol file (in external form).  */

  68.     int symbol_size;

  69.     /* Further information needed to locate the symbols if they are in
  70.        an ELF file.  */

  71.     int symbol_offset;
  72.     int string_offset;
  73.     int file_string_offset;
  74.   };

  75. #define LDSYMOFF(p) (((struct symloc *)((p)->read_symtab_private))->ldsymoff)
  76. #define LDSYMLEN(p) (((struct symloc *)((p)->read_symtab_private))->ldsymlen)
  77. #define SYMLOC(p) ((struct symloc *)((p)->read_symtab_private))
  78. #define SYMBOL_SIZE(p) (SYMLOC(p)->symbol_size)
  79. #define SYMBOL_OFFSET(p) (SYMLOC(p)->symbol_offset)
  80. #define STRING_OFFSET(p) (SYMLOC(p)->string_offset)
  81. #define FILE_STRING_OFFSET(p) (SYMLOC(p)->file_string_offset)


  82. /* The objfile we are currently reading.  */

  83. static struct objfile *dbxread_objfile;

  84. /* Remember what we deduced to be the source language of this psymtab.  */

  85. static enum language psymtab_language = language_unknown;

  86. /* The BFD for this file -- implicit parameter to next_symbol_text.  */

  87. static bfd *symfile_bfd;

  88. /* The size of each symbol in the symbol file (in external form).
  89.    This is set by dbx_symfile_read when building psymtabs, and by
  90.    dbx_psymtab_to_symtab when building symtabs.  */

  91. static unsigned symbol_size;

  92. /* This is the offset of the symbol table in the executable file.  */

  93. static unsigned symbol_table_offset;

  94. /* This is the offset of the string table in the executable file.  */

  95. static unsigned string_table_offset;

  96. /* For elf+stab executables, the n_strx field is not a simple index
  97.    into the string table.  Instead, each .o file has a base offset in
  98.    the string table, and the associated symbols contain offsets from
  99.    this base.  The following two variables contain the base offset for
  100.    the current and next .o files.  */

  101. static unsigned int file_string_table_offset;
  102. static unsigned int next_file_string_table_offset;

  103. /* .o and NLM files contain unrelocated addresses which are based at
  104.    0.  When non-zero, this flag disables some of the special cases for
  105.    Solaris elf+stab text addresses at location 0.  */

  106. static int symfile_relocatable = 0;

  107. /* If this is nonzero, N_LBRAC, N_RBRAC, and N_SLINE entries are
  108.    relative to the function start address.  */

  109. static int block_address_function_relative = 0;

  110. /* The lowest text address we have yet encountered.  This is needed
  111.    because in an a.out file, there is no header field which tells us
  112.    what address the program is actually going to be loaded at, so we
  113.    need to make guesses based on the symbols (which *are* relocated to
  114.    reflect the address it will be loaded at).  */

  115. static CORE_ADDR lowest_text_address;

  116. /* Non-zero if there is any line number info in the objfile.  Prevents
  117.    end_psymtab from discarding an otherwise empty psymtab.  */

  118. static int has_line_numbers;

  119. /* Complaints about the symbols we have encountered.  */

  120. static void
  121. unknown_symtype_complaint (const char *arg1)
  122. {
  123.   complaint (&symfile_complaints, _("unknown symbol type %s"), arg1);
  124. }

  125. static void
  126. lbrac_mismatch_complaint (int arg1)
  127. {
  128.   complaint (&symfile_complaints,
  129.              _("N_LBRAC/N_RBRAC symbol mismatch at symtab pos %d"), arg1);
  130. }

  131. static void
  132. repeated_header_complaint (const char *arg1, int arg2)
  133. {
  134.   complaint (&symfile_complaints,
  135.              _("\"repeated\" header file %s not "
  136.                "previously seen, at symtab pos %d"),
  137.              arg1, arg2);
  138. }

  139. /* find_text_range --- find start and end of loadable code sections

  140.    The find_text_range function finds the shortest address range that
  141.    encloses all sections containing executable code, and stores it in
  142.    objfile's text_addr and text_size members.

  143.    dbx_symfile_read will use this to finish off the partial symbol
  144.    table, in some cases.  */

  145. static void
  146. find_text_range (bfd * sym_bfd, struct objfile *objfile)
  147. {
  148.   asection *sec;
  149.   int found_any = 0;
  150.   CORE_ADDR start = 0;
  151.   CORE_ADDR end = 0;

  152.   for (sec = sym_bfd->sections; sec; sec = sec->next)
  153.     if (bfd_get_section_flags (sym_bfd, sec) & SEC_CODE)
  154.       {
  155.         CORE_ADDR sec_start = bfd_section_vma (sym_bfd, sec);
  156.         CORE_ADDR sec_end = sec_start + bfd_section_size (sym_bfd, sec);

  157.         if (found_any)
  158.           {
  159.             if (sec_start < start)
  160.               start = sec_start;
  161.             if (sec_end > end)
  162.               end = sec_end;
  163.           }
  164.         else
  165.           {
  166.             start = sec_start;
  167.             end = sec_end;
  168.           }

  169.         found_any = 1;
  170.       }

  171.   if (!found_any)
  172.     error (_("Can't find any code sections in symbol file"));

  173.   DBX_TEXT_ADDR (objfile) = start;
  174.   DBX_TEXT_SIZE (objfile) = end - start;
  175. }



  176. /* During initial symbol readin, we need to have a structure to keep
  177.    track of which psymtabs have which bincls in them.  This structure
  178.    is used during readin to setup the list of dependencies within each
  179.    partial symbol table.  */

  180. struct header_file_location
  181. {
  182.   char *name;                        /* Name of header file */
  183.   int instance;                        /* See above */
  184.   struct partial_symtab *pst;        /* Partial symtab that has the
  185.                                    BINCL/EINCL defs for this file.  */
  186. };

  187. /* The actual list and controling variables.  */
  188. static struct header_file_location *bincl_list, *next_bincl;
  189. static int bincls_allocated;

  190. /* Local function prototypes.  */

  191. extern void _initialize_dbxread (void);

  192. static void read_ofile_symtab (struct objfile *, struct partial_symtab *);

  193. static void dbx_read_symtab (struct partial_symtab *self,
  194.                              struct objfile *objfile);

  195. static void dbx_psymtab_to_symtab_1 (struct objfile *, struct partial_symtab *);

  196. static void read_dbx_dynamic_symtab (struct objfile *objfile);

  197. static void read_dbx_symtab (struct objfile *);

  198. static void free_bincl_list (struct objfile *);

  199. static struct partial_symtab *find_corresponding_bincl_psymtab (char *, int);

  200. static void add_bincl_to_list (struct partial_symtab *, char *, int);

  201. static void init_bincl_list (int, struct objfile *);

  202. static char *dbx_next_symbol_text (struct objfile *);

  203. static void fill_symbuf (bfd *);

  204. static void dbx_symfile_init (struct objfile *);

  205. static void dbx_new_init (struct objfile *);

  206. static void dbx_symfile_read (struct objfile *, int);

  207. static void dbx_symfile_finish (struct objfile *);

  208. static void record_minimal_symbol (const char *, CORE_ADDR, int,
  209.                                    struct objfile *);

  210. static void add_new_header_file (char *, int);

  211. static void add_old_header_file (char *, int);

  212. static void add_this_object_header_file (int);

  213. static struct partial_symtab *start_psymtab (struct objfile *, char *,
  214.                                              CORE_ADDR, int,
  215.                                              struct partial_symbol **,
  216.                                              struct partial_symbol **);

  217. /* Free up old header file tables.  */

  218. void
  219. free_header_files (void)
  220. {
  221.   if (this_object_header_files)
  222.     {
  223.       xfree (this_object_header_files);
  224.       this_object_header_files = NULL;
  225.     }
  226.   n_allocated_this_object_header_files = 0;
  227. }

  228. /* Allocate new header file tables.  */

  229. void
  230. init_header_files (void)
  231. {
  232.   n_allocated_this_object_header_files = 10;
  233.   this_object_header_files = (int *) xmalloc (10 * sizeof (int));
  234. }

  235. /* Add header file number I for this object file
  236.    at the next successive FILENUM.  */

  237. static void
  238. add_this_object_header_file (int i)
  239. {
  240.   if (n_this_object_header_files == n_allocated_this_object_header_files)
  241.     {
  242.       n_allocated_this_object_header_files *= 2;
  243.       this_object_header_files
  244.         = (int *) xrealloc ((char *) this_object_header_files,
  245.                        n_allocated_this_object_header_files * sizeof (int));
  246.     }

  247.   this_object_header_files[n_this_object_header_files++] = i;
  248. }

  249. /* Add to this file an "old" header file, one already seen in
  250.    a previous object file.  NAME is the header file's name.
  251.    INSTANCE is its instance code, to select among multiple
  252.    symbol tables for the same header file.  */

  253. static void
  254. add_old_header_file (char *name, int instance)
  255. {
  256.   struct header_file *p = HEADER_FILES (dbxread_objfile);
  257.   int i;

  258.   for (i = 0; i < N_HEADER_FILES (dbxread_objfile); i++)
  259.     if (filename_cmp (p[i].name, name) == 0 && instance == p[i].instance)
  260.       {
  261.         add_this_object_header_file (i);
  262.         return;
  263.       }
  264.   repeated_header_complaint (name, symnum);
  265. }

  266. /* Add to this file a "new" header file: definitions for its types follow.
  267.    NAME is the header file's name.
  268.    Most often this happens only once for each distinct header file,
  269.    but not necessarily.  If it happens more than once, INSTANCE has
  270.    a different value each time, and references to the header file
  271.    use INSTANCE values to select among them.

  272.    dbx output contains "begin" and "end" markers for each new header file,
  273.    but at this level we just need to know which files there have been;
  274.    so we record the file when its "begin" is seen and ignore the "end".  */

  275. static void
  276. add_new_header_file (char *name, int instance)
  277. {
  278.   int i;
  279.   struct header_file *hfile;

  280.   /* Make sure there is room for one more header file.  */

  281.   i = N_ALLOCATED_HEADER_FILES (dbxread_objfile);

  282.   if (N_HEADER_FILES (dbxread_objfile) == i)
  283.     {
  284.       if (i == 0)
  285.         {
  286.           N_ALLOCATED_HEADER_FILES (dbxread_objfile) = 10;
  287.           HEADER_FILES (dbxread_objfile) = (struct header_file *)
  288.             xmalloc (10 * sizeof (struct header_file));
  289.         }
  290.       else
  291.         {
  292.           i *= 2;
  293.           N_ALLOCATED_HEADER_FILES (dbxread_objfile) = i;
  294.           HEADER_FILES (dbxread_objfile) = (struct header_file *)
  295.             xrealloc ((char *) HEADER_FILES (dbxread_objfile),
  296.                       (i * sizeof (struct header_file)));
  297.         }
  298.     }

  299.   /* Create an entry for this header file.  */

  300.   i = N_HEADER_FILES (dbxread_objfile)++;
  301.   hfile = HEADER_FILES (dbxread_objfile) + i;
  302.   hfile->name = xstrdup (name);
  303.   hfile->instance = instance;
  304.   hfile->length = 10;
  305.   hfile->vector
  306.     = (struct type **) xmalloc (10 * sizeof (struct type *));
  307.   memset (hfile->vector, 0, 10 * sizeof (struct type *));

  308.   add_this_object_header_file (i);
  309. }

  310. #if 0
  311. static struct type **
  312. explicit_lookup_type (int real_filenum, int index)
  313. {
  314.   struct header_file *f = &HEADER_FILES (dbxread_objfile)[real_filenum];

  315.   if (index >= f->length)
  316.     {
  317.       f->length *= 2;
  318.       f->vector = (struct type **)
  319.         xrealloc (f->vector, f->length * sizeof (struct type *));
  320.       memset (&f->vector[f->length / 2],
  321.               '\0', f->length * sizeof (struct type *) / 2);
  322.     }
  323.   return &f->vector[index];
  324. }
  325. #endif

  326. static void
  327. record_minimal_symbol (const char *name, CORE_ADDR address, int type,
  328.                        struct objfile *objfile)
  329. {
  330.   enum minimal_symbol_type ms_type;
  331.   int section;

  332.   switch (type)
  333.     {
  334.     case N_TEXT | N_EXT:
  335.       ms_type = mst_text;
  336.       section = SECT_OFF_TEXT (objfile);
  337.       break;
  338.     case N_DATA | N_EXT:
  339.       ms_type = mst_data;
  340.       section = SECT_OFF_DATA (objfile);
  341.       break;
  342.     case N_BSS | N_EXT:
  343.       ms_type = mst_bss;
  344.       section = SECT_OFF_BSS (objfile);
  345.       break;
  346.     case N_ABS | N_EXT:
  347.       ms_type = mst_abs;
  348.       section = -1;
  349.       break;
  350. #ifdef N_SETV
  351.     case N_SETV | N_EXT:
  352.       ms_type = mst_data;
  353.       section = SECT_OFF_DATA (objfile);
  354.       break;
  355.     case N_SETV:
  356.       /* I don't think this type actually exists; since a N_SETV is the result
  357.          of going over many .o files, it doesn't make sense to have one
  358.          file local.  */
  359.       ms_type = mst_file_data;
  360.       section = SECT_OFF_DATA (objfile);
  361.       break;
  362. #endif
  363.     case N_TEXT:
  364.     case N_NBTEXT:
  365.     case N_FN:
  366.     case N_FN_SEQ:
  367.       ms_type = mst_file_text;
  368.       section = SECT_OFF_TEXT (objfile);
  369.       break;
  370.     case N_DATA:
  371.       ms_type = mst_file_data;

  372.       /* Check for __DYNAMIC, which is used by Sun shared libraries.
  373.          Record it as global even if it's local, not global, so
  374.          lookup_minimal_symbol can find it.  We don't check symbol_leading_char
  375.          because for SunOS4 it always is '_'.  */
  376.       if (name[8] == 'C' && strcmp ("__DYNAMIC", name) == 0)
  377.         ms_type = mst_data;

  378.       /* Same with virtual function tables, both global and static.  */
  379.       {
  380.         const char *tempstring = name;

  381.         if (tempstring[0] == bfd_get_symbol_leading_char (objfile->obfd))
  382.           ++tempstring;
  383.         if (is_vtable_name (tempstring))
  384.           ms_type = mst_data;
  385.       }
  386.       section = SECT_OFF_DATA (objfile);
  387.       break;
  388.     case N_BSS:
  389.       ms_type = mst_file_bss;
  390.       section = SECT_OFF_BSS (objfile);
  391.       break;
  392.     default:
  393.       ms_type = mst_unknown;
  394.       section = -1;
  395.       break;
  396.     }

  397.   if ((ms_type == mst_file_text || ms_type == mst_text)
  398.       && address < lowest_text_address)
  399.     lowest_text_address = address;

  400.   prim_record_minimal_symbol_and_info
  401.     (name, address, ms_type, section, objfile);
  402. }

  403. /* Scan and build partial symbols for a symbol file.
  404.    We have been initialized by a call to dbx_symfile_init, which
  405.    put all the relevant info into a "struct dbx_symfile_info",
  406.    hung off the objfile structure.  */

  407. static void
  408. dbx_symfile_read (struct objfile *objfile, int symfile_flags)
  409. {
  410.   bfd *sym_bfd;
  411.   int val;
  412.   struct cleanup *back_to;

  413.   sym_bfd = objfile->obfd;

  414.   /* .o and .nlm files are relocatables with text, data and bss segs based at
  415.      0.  This flag disables special (Solaris stabs-in-elf only) fixups for
  416.      symbols with a value of 0.  */

  417.   symfile_relocatable = bfd_get_file_flags (sym_bfd) & HAS_RELOC;

  418.   /* This is true for Solaris (and all other systems which put stabs
  419.      in sections, hopefully, since it would be silly to do things
  420.      differently from Solaris), and false for SunOS4 and other a.out
  421.      file formats.  */
  422.   block_address_function_relative =
  423.     ((0 == strncmp (bfd_get_target (sym_bfd), "elf", 3))
  424.      || (0 == strncmp (bfd_get_target (sym_bfd), "som", 3))
  425.      || (0 == strncmp (bfd_get_target (sym_bfd), "coff", 4))
  426.      || (0 == strncmp (bfd_get_target (sym_bfd), "pe", 2))
  427.      || (0 == strncmp (bfd_get_target (sym_bfd), "epoc-pe", 7))
  428.      || (0 == strncmp (bfd_get_target (sym_bfd), "nlm", 3)));

  429.   val = bfd_seek (sym_bfd, DBX_SYMTAB_OFFSET (objfile), SEEK_SET);
  430.   if (val < 0)
  431.     perror_with_name (objfile_name (objfile));

  432.   /* Size the symbol table.  */
  433.   if (objfile->global_psymbols.size == 0 && objfile->static_psymbols.size == 0)
  434.     init_psymbol_list (objfile, DBX_SYMCOUNT (objfile));

  435.   symbol_size = DBX_SYMBOL_SIZE (objfile);
  436.   symbol_table_offset = DBX_SYMTAB_OFFSET (objfile);

  437.   free_pending_blocks ();
  438.   back_to = make_cleanup (really_free_pendings, 0);

  439.   init_minimal_symbol_collection ();
  440.   make_cleanup_discard_minimal_symbols ();

  441.   /* Read stabs data from executable file and define symbols.  */

  442.   read_dbx_symtab (objfile);

  443.   /* Add the dynamic symbols.  */

  444.   read_dbx_dynamic_symtab (objfile);

  445.   /* Install any minimal symbols that have been collected as the current
  446.      minimal symbols for this objfile.  */

  447.   install_minimal_symbols (objfile);

  448.   do_cleanups (back_to);
  449. }

  450. /* Initialize anything that needs initializing when a completely new
  451.    symbol file is specified (not just adding some symbols from another
  452.    file, e.g. a shared library).  */

  453. static void
  454. dbx_new_init (struct objfile *ignore)
  455. {
  456.   stabsread_new_init ();
  457.   buildsym_new_init ();
  458.   init_header_files ();
  459. }


  460. /* dbx_symfile_init ()
  461.    is the dbx-specific initialization routine for reading symbols.
  462.    It is passed a struct objfile which contains, among other things,
  463.    the BFD for the file whose symbols are being read, and a slot for a pointer
  464.    to "private data" which we fill with goodies.

  465.    We read the string table into malloc'd space and stash a pointer to it.

  466.    Since BFD doesn't know how to read debug symbols in a format-independent
  467.    way (and may never do so...), we have to do it ourselves.  We will never
  468.    be called unless this is an a.out (or very similar) file.
  469.    FIXME, there should be a cleaner peephole into the BFD environment here.  */

  470. #define DBX_STRINGTAB_SIZE_SIZE sizeof(long)        /* FIXME */

  471. static void
  472. dbx_symfile_init (struct objfile *objfile)
  473. {
  474.   int val;
  475.   bfd *sym_bfd = objfile->obfd;
  476.   char *name = bfd_get_filename (sym_bfd);
  477.   asection *text_sect;
  478.   unsigned char size_temp[DBX_STRINGTAB_SIZE_SIZE];
  479.   struct dbx_symfile_info *dbx;

  480.   /* Allocate struct to keep track of the symfile.  */
  481.   dbx = XCNEW (struct dbx_symfile_info);
  482.   set_objfile_data (objfile, dbx_objfile_data_key, dbx);

  483.   DBX_TEXT_SECTION (objfile) = bfd_get_section_by_name (sym_bfd, ".text");
  484.   DBX_DATA_SECTION (objfile) = bfd_get_section_by_name (sym_bfd, ".data");
  485.   DBX_BSS_SECTION (objfile) = bfd_get_section_by_name (sym_bfd, ".bss");

  486.   /* FIXME POKING INSIDE BFD DATA STRUCTURES.  */
  487. #define        STRING_TABLE_OFFSET        (sym_bfd->origin + obj_str_filepos (sym_bfd))
  488. #define        SYMBOL_TABLE_OFFSET        (sym_bfd->origin + obj_sym_filepos (sym_bfd))

  489.   /* FIXME POKING INSIDE BFD DATA STRUCTURES.  */

  490.   DBX_SYMFILE_INFO (objfile)->stab_section_info = NULL;

  491.   text_sect = bfd_get_section_by_name (sym_bfd, ".text");
  492.   if (!text_sect)
  493.     error (_("Can't find .text section in symbol file"));
  494.   DBX_TEXT_ADDR (objfile) = bfd_section_vma (sym_bfd, text_sect);
  495.   DBX_TEXT_SIZE (objfile) = bfd_section_size (sym_bfd, text_sect);

  496.   DBX_SYMBOL_SIZE (objfile) = obj_symbol_entry_size (sym_bfd);
  497.   DBX_SYMCOUNT (objfile) = bfd_get_symcount (sym_bfd);
  498.   DBX_SYMTAB_OFFSET (objfile) = SYMBOL_TABLE_OFFSET;

  499.   /* Read the string table and stash it away in the objfile_obstack.
  500.      When we blow away the objfile the string table goes away as well.
  501.      Note that gdb used to use the results of attempting to malloc the
  502.      string table, based on the size it read, as a form of sanity check
  503.      for botched byte swapping, on the theory that a byte swapped string
  504.      table size would be so totally bogus that the malloc would fail.  Now
  505.      that we put in on the objfile_obstack, we can't do this since gdb gets
  506.      a fatal error (out of virtual memory) if the size is bogus.  We can
  507.      however at least check to see if the size is less than the size of
  508.      the size field itself, or larger than the size of the entire file.
  509.      Note that all valid string tables have a size greater than zero, since
  510.      the bytes used to hold the size are included in the count.  */

  511.   if (STRING_TABLE_OFFSET == 0)
  512.     {
  513.       /* It appears that with the existing bfd code, STRING_TABLE_OFFSET
  514.          will never be zero, even when there is no string table.  This
  515.          would appear to be a bug in bfd.  */
  516.       DBX_STRINGTAB_SIZE (objfile) = 0;
  517.       DBX_STRINGTAB (objfile) = NULL;
  518.     }
  519.   else
  520.     {
  521.       val = bfd_seek (sym_bfd, STRING_TABLE_OFFSET, SEEK_SET);
  522.       if (val < 0)
  523.         perror_with_name (name);

  524.       memset (size_temp, 0, sizeof (size_temp));
  525.       val = bfd_bread (size_temp, sizeof (size_temp), sym_bfd);
  526.       if (val < 0)
  527.         {
  528.           perror_with_name (name);
  529.         }
  530.       else if (val == 0)
  531.         {
  532.           /* With the existing bfd code, STRING_TABLE_OFFSET will be set to
  533.              EOF if there is no string table, and attempting to read the size
  534.              from EOF will read zero bytes.  */
  535.           DBX_STRINGTAB_SIZE (objfile) = 0;
  536.           DBX_STRINGTAB (objfile) = NULL;
  537.         }
  538.       else
  539.         {
  540.           /* Read some data that would appear to be the string table size.
  541.              If there really is a string table, then it is probably the right
  542.              size.  Byteswap if necessary and validate the size.  Note that
  543.              the minimum is DBX_STRINGTAB_SIZE_SIZE.  If we just read some
  544.              random data that happened to be at STRING_TABLE_OFFSET, because
  545.              bfd can't tell us there is no string table, the sanity checks may
  546.              or may not catch this.  */
  547.           DBX_STRINGTAB_SIZE (objfile) = bfd_h_get_32 (sym_bfd, size_temp);

  548.           if (DBX_STRINGTAB_SIZE (objfile) < sizeof (size_temp)
  549.               || DBX_STRINGTAB_SIZE (objfile) > bfd_get_size (sym_bfd))
  550.             error (_("ridiculous string table size (%d bytes)."),
  551.                    DBX_STRINGTAB_SIZE (objfile));

  552.           DBX_STRINGTAB (objfile) =
  553.             (char *) obstack_alloc (&objfile->objfile_obstack,
  554.                                     DBX_STRINGTAB_SIZE (objfile));
  555.           OBJSTAT (objfile, sz_strtab += DBX_STRINGTAB_SIZE (objfile));

  556.           /* Now read in the string table in one big gulp.  */

  557.           val = bfd_seek (sym_bfd, STRING_TABLE_OFFSET, SEEK_SET);
  558.           if (val < 0)
  559.             perror_with_name (name);
  560.           val = bfd_bread (DBX_STRINGTAB (objfile),
  561.                            DBX_STRINGTAB_SIZE (objfile),
  562.                            sym_bfd);
  563.           if (val != DBX_STRINGTAB_SIZE (objfile))
  564.             perror_with_name (name);
  565.         }
  566.     }
  567. }

  568. /* Perform any local cleanups required when we are done with a particular
  569.    objfileI.E, we are in the process of discarding all symbol information
  570.    for an objfile, freeing up all memory held for it, and unlinking the
  571.    objfile struct from the global list of known objfiles.  */

  572. static void
  573. dbx_symfile_finish (struct objfile *objfile)
  574. {
  575.   free_header_files ();
  576. }

  577. static void
  578. dbx_free_symfile_info (struct objfile *objfile, void *arg)
  579. {
  580.   struct dbx_symfile_info *dbx = arg;

  581.   if (dbx->header_files != NULL)
  582.     {
  583.       int i = dbx->n_header_files;
  584.       struct header_file *hfiles = dbx->header_files;

  585.       while (--i >= 0)
  586.         {
  587.           xfree (hfiles[i].name);
  588.           xfree (hfiles[i].vector);
  589.         }
  590.       xfree (hfiles);
  591.     }

  592.   xfree (dbx);
  593. }



  594. /* Buffer for reading the symbol table entries.  */
  595. static struct external_nlist symbuf[4096];
  596. static int symbuf_idx;
  597. static int symbuf_end;

  598. /* Name of last function encountered.  Used in Solaris to approximate
  599.    object file boundaries.  */
  600. static char *last_function_name;

  601. /* The address in memory of the string table of the object file we are
  602.    reading (which might not be the "main" object file, but might be a
  603.    shared library or some other dynamically loaded thing).  This is
  604.    set by read_dbx_symtab when building psymtabs, and by
  605.    read_ofile_symtab when building symtabs, and is used only by
  606.    next_symbol_textFIXME: If that is true, we don't need it when
  607.    building psymtabs, right?  */
  608. static char *stringtab_global;

  609. /* These variables are used to control fill_symbuf when the stabs
  610.    symbols are not contiguous (as may be the case when a COFF file is
  611.    linked using --split-by-reloc).  */
  612. static struct stab_section_list *symbuf_sections;
  613. static unsigned int symbuf_left;
  614. static unsigned int symbuf_read;

  615. /* This variable stores a global stabs buffer, if we read stabs into
  616.    memory in one chunk in order to process relocations.  */
  617. static bfd_byte *stabs_data;

  618. /* Refill the symbol table input buffer
  619.    and set the variables that control fetching entries from it.
  620.    Reports an error if no data available.
  621.    This function can read past the end of the symbol table
  622.    (into the string table) but this does no harm.  */

  623. static void
  624. fill_symbuf (bfd *sym_bfd)
  625. {
  626.   unsigned int count;
  627.   int nbytes;

  628.   if (stabs_data)
  629.     {
  630.       nbytes = sizeof (symbuf);
  631.       if (nbytes > symbuf_left)
  632.         nbytes = symbuf_left;
  633.       memcpy (symbuf, stabs_data + symbuf_read, nbytes);
  634.     }
  635.   else if (symbuf_sections == NULL)
  636.     {
  637.       count = sizeof (symbuf);
  638.       nbytes = bfd_bread (symbuf, count, sym_bfd);
  639.     }
  640.   else
  641.     {
  642.       if (symbuf_left <= 0)
  643.         {
  644.           file_ptr filepos = symbuf_sections->section->filepos;

  645.           if (bfd_seek (sym_bfd, filepos, SEEK_SET) != 0)
  646.             perror_with_name (bfd_get_filename (sym_bfd));
  647.           symbuf_left = bfd_section_size (sym_bfd, symbuf_sections->section);
  648.           symbol_table_offset = filepos - symbuf_read;
  649.           symbuf_sections = symbuf_sections->next;
  650.         }

  651.       count = symbuf_left;
  652.       if (count > sizeof (symbuf))
  653.         count = sizeof (symbuf);
  654.       nbytes = bfd_bread (symbuf, count, sym_bfd);
  655.     }

  656.   if (nbytes < 0)
  657.     perror_with_name (bfd_get_filename (sym_bfd));
  658.   else if (nbytes == 0)
  659.     error (_("Premature end of file reading symbol table"));
  660.   symbuf_end = nbytes / symbol_size;
  661.   symbuf_idx = 0;
  662.   symbuf_left -= nbytes;
  663.   symbuf_read += nbytes;
  664. }

  665. static void
  666. stabs_seek (int sym_offset)
  667. {
  668.   if (stabs_data)
  669.     {
  670.       symbuf_read += sym_offset;
  671.       symbuf_left -= sym_offset;
  672.     }
  673.   else
  674.     bfd_seek (symfile_bfd, sym_offset, SEEK_CUR);
  675. }

  676. #define INTERNALIZE_SYMBOL(intern, extern, abfd)                        \
  677.   {                                                                        \
  678.     (intern).n_strx = bfd_h_get_32 (abfd, (extern)->e_strx);                \
  679.     (intern).n_type = bfd_h_get_8 (abfd, (extern)->e_type);                \
  680.     (intern).n_other = 0;                                                \
  681.     (intern).n_desc = bfd_h_get_16 (abfd, (extern)->e_desc);                  \
  682.     if (bfd_get_sign_extend_vma (abfd))                                        \
  683.       (intern).n_value = bfd_h_get_signed_32 (abfd, (extern)->e_value);        \
  684.     else                                                                \
  685.       (intern).n_value = bfd_h_get_32 (abfd, (extern)->e_value);        \
  686.   }

  687. /* Invariant: The symbol pointed to by symbuf_idx is the first one
  688.    that hasn't been swapped.  Swap the symbol at the same time
  689.    that symbuf_idx is incremented.  */

  690. /* dbx allows the text of a symbol name to be continued into the
  691.    next symbol name!  When such a continuation is encountered
  692.    (a \ at the end of the text of a name)
  693.    call this function to get the continuation.  */

  694. static char *
  695. dbx_next_symbol_text (struct objfile *objfile)
  696. {
  697.   struct internal_nlist nlist;

  698.   if (symbuf_idx == symbuf_end)
  699.     fill_symbuf (symfile_bfd);

  700.   symnum++;
  701.   INTERNALIZE_SYMBOL (nlist, &symbuf[symbuf_idx], symfile_bfd);
  702.   OBJSTAT (objfile, n_stabs++);

  703.   symbuf_idx++;

  704.   return nlist.n_strx + stringtab_global + file_string_table_offset;
  705. }

  706. /* Initialize the list of bincls to contain none and have some
  707.    allocated.  */

  708. static void
  709. init_bincl_list (int number, struct objfile *objfile)
  710. {
  711.   bincls_allocated = number;
  712.   next_bincl = bincl_list = (struct header_file_location *)
  713.     xmalloc (bincls_allocated * sizeof (struct header_file_location));
  714. }

  715. /* Add a bincl to the list.  */

  716. static void
  717. add_bincl_to_list (struct partial_symtab *pst, char *name, int instance)
  718. {
  719.   if (next_bincl >= bincl_list + bincls_allocated)
  720.     {
  721.       int offset = next_bincl - bincl_list;

  722.       bincls_allocated *= 2;
  723.       bincl_list = (struct header_file_location *)
  724.         xrealloc ((char *) bincl_list,
  725.                   bincls_allocated * sizeof (struct header_file_location));
  726.       next_bincl = bincl_list + offset;
  727.     }
  728.   next_bincl->pst = pst;
  729.   next_bincl->instance = instance;
  730.   next_bincl++->name = name;
  731. }

  732. /* Given a name, value pair, find the corresponding
  733.    bincl in the list.  Return the partial symtab associated
  734.    with that header_file_location.  */

  735. static struct partial_symtab *
  736. find_corresponding_bincl_psymtab (char *name, int instance)
  737. {
  738.   struct header_file_location *bincl;

  739.   for (bincl = bincl_list; bincl < next_bincl; bincl++)
  740.     if (bincl->instance == instance
  741.         && strcmp (name, bincl->name) == 0)
  742.       return bincl->pst;

  743.   repeated_header_complaint (name, symnum);
  744.   return (struct partial_symtab *) 0;
  745. }

  746. /* Free the storage allocated for the bincl list.  */

  747. static void
  748. free_bincl_list (struct objfile *objfile)
  749. {
  750.   xfree (bincl_list);
  751.   bincls_allocated = 0;
  752. }

  753. static void
  754. do_free_bincl_list_cleanup (void *objfile)
  755. {
  756.   free_bincl_list (objfile);
  757. }

  758. static struct cleanup *
  759. make_cleanup_free_bincl_list (struct objfile *objfile)
  760. {
  761.   return make_cleanup (do_free_bincl_list_cleanup, objfile);
  762. }

  763. /* Set namestring based on nlist.  If the string table index is invalid,
  764.    give a fake name, and print a single error message per symbol file read,
  765.    rather than abort the symbol reading or flood the user with messages.  */

  766. static char *
  767. set_namestring (struct objfile *objfile, const struct internal_nlist *nlist)
  768. {
  769.   char *namestring;

  770.   if (nlist->n_strx + file_string_table_offset
  771.       >= DBX_STRINGTAB_SIZE (objfile)
  772.       || nlist->n_strx + file_string_table_offset < nlist->n_strx)
  773.     {
  774.       complaint (&symfile_complaints,
  775.                  _("bad string table offset in symbol %d"),
  776.                  symnum);
  777.       namestring = "<bad string table offset>";
  778.     }
  779.   else
  780.     namestring = (nlist->n_strx + file_string_table_offset
  781.                   + DBX_STRINGTAB (objfile));
  782.   return namestring;
  783. }

  784. /* Scan a SunOs dynamic symbol table for symbols of interest and
  785.    add them to the minimal symbol table.  */

  786. static void
  787. read_dbx_dynamic_symtab (struct objfile *objfile)
  788. {
  789.   bfd *abfd = objfile->obfd;
  790.   struct cleanup *back_to;
  791.   int counter;
  792.   long dynsym_size;
  793.   long dynsym_count;
  794.   asymbol **dynsyms;
  795.   asymbol **symptr;
  796.   arelent **relptr;
  797.   long dynrel_size;
  798.   long dynrel_count;
  799.   arelent **dynrels;
  800.   CORE_ADDR sym_value;
  801.   const char *name;

  802.   /* Check that the symbol file has dynamic symbols that we know about.
  803.      bfd_arch_unknown can happen if we are reading a sun3 symbol file
  804.      on a sun4 host (and vice versa) and bfd is not configured
  805.      --with-target=all.  This would trigger an assertion in bfd/sunos.c,
  806.      so we ignore the dynamic symbols in this case.  */
  807.   if (bfd_get_flavour (abfd) != bfd_target_aout_flavour
  808.       || (bfd_get_file_flags (abfd) & DYNAMIC) == 0
  809.       || bfd_get_arch (abfd) == bfd_arch_unknown)
  810.     return;

  811.   dynsym_size = bfd_get_dynamic_symtab_upper_bound (abfd);
  812.   if (dynsym_size < 0)
  813.     return;

  814.   dynsyms = (asymbol **) xmalloc (dynsym_size);
  815.   back_to = make_cleanup (xfree, dynsyms);

  816.   dynsym_count = bfd_canonicalize_dynamic_symtab (abfd, dynsyms);
  817.   if (dynsym_count < 0)
  818.     {
  819.       do_cleanups (back_to);
  820.       return;
  821.     }

  822.   /* Enter dynamic symbols into the minimal symbol table
  823.      if this is a stripped executable.  */
  824.   if (bfd_get_symcount (abfd) <= 0)
  825.     {
  826.       symptr = dynsyms;
  827.       for (counter = 0; counter < dynsym_count; counter++, symptr++)
  828.         {
  829.           asymbol *sym = *symptr;
  830.           asection *sec;
  831.           int type;

  832.           sec = bfd_get_section (sym);

  833.           /* BFD symbols are section relative.  */
  834.           sym_value = sym->value + sec->vma;

  835.           if (bfd_get_section_flags (abfd, sec) & SEC_CODE)
  836.             {
  837.               type = N_TEXT;
  838.             }
  839.           else if (bfd_get_section_flags (abfd, sec) & SEC_DATA)
  840.             {
  841.               type = N_DATA;
  842.             }
  843.           else if (bfd_get_section_flags (abfd, sec) & SEC_ALLOC)
  844.             {
  845.               type = N_BSS;
  846.             }
  847.           else
  848.             continue;

  849.           if (sym->flags & BSF_GLOBAL)
  850.             type |= N_EXT;

  851.           record_minimal_symbol (bfd_asymbol_name (sym), sym_value,
  852.                                  type, objfile);
  853.         }
  854.     }

  855.   /* Symbols from shared libraries have a dynamic relocation entry
  856.      that points to the associated slot in the procedure linkage table.
  857.      We make a mininal symbol table entry with type mst_solib_trampoline
  858.      at the address in the procedure linkage table.  */
  859.   dynrel_size = bfd_get_dynamic_reloc_upper_bound (abfd);
  860.   if (dynrel_size < 0)
  861.     {
  862.       do_cleanups (back_to);
  863.       return;
  864.     }

  865.   dynrels = (arelent **) xmalloc (dynrel_size);
  866.   make_cleanup (xfree, dynrels);

  867.   dynrel_count = bfd_canonicalize_dynamic_reloc (abfd, dynrels, dynsyms);
  868.   if (dynrel_count < 0)
  869.     {
  870.       do_cleanups (back_to);
  871.       return;
  872.     }

  873.   for (counter = 0, relptr = dynrels;
  874.        counter < dynrel_count;
  875.        counter++, relptr++)
  876.     {
  877.       arelent *rel = *relptr;
  878.       CORE_ADDR address = rel->address;

  879.       switch (bfd_get_arch (abfd))
  880.         {
  881.         case bfd_arch_sparc:
  882.           if (rel->howto->type != RELOC_JMP_SLOT)
  883.             continue;
  884.           break;
  885.         case bfd_arch_m68k:
  886.           /* `16' is the type BFD produces for a jump table relocation.  */
  887.           if (rel->howto->type != 16)
  888.             continue;

  889.           /* Adjust address in the jump table to point to
  890.              the start of the bsr instruction.  */
  891.           address -= 2;
  892.           break;
  893.         default:
  894.           continue;
  895.         }

  896.       name = bfd_asymbol_name (*rel->sym_ptr_ptr);
  897.       prim_record_minimal_symbol (name, address, mst_solib_trampoline,
  898.                                   objfile);
  899.     }

  900.   do_cleanups (back_to);
  901. }

  902. static CORE_ADDR
  903. find_stab_function_addr (char *namestring, const char *filename,
  904.                          struct objfile *objfile)
  905. {
  906.   struct bound_minimal_symbol msym;
  907.   char *p;
  908.   int n;

  909.   p = strchr (namestring, ':');
  910.   if (p == NULL)
  911.     p = namestring;
  912.   n = p - namestring;
  913.   p = alloca (n + 2);
  914.   strncpy (p, namestring, n);
  915.   p[n] = 0;

  916.   msym = lookup_minimal_symbol (p, filename, objfile);
  917.   if (msym.minsym == NULL)
  918.     {
  919.       /* Sun Fortran appends an underscore to the minimal symbol name,
  920.          try again with an appended underscore if the minimal symbol
  921.          was not found.  */
  922.       p[n] = '_';
  923.       p[n + 1] = 0;
  924.       msym = lookup_minimal_symbol (p, filename, objfile);
  925.     }

  926.   if (msym.minsym == NULL && filename != NULL)
  927.     {
  928.       /* Try again without the filename.  */
  929.       p[n] = 0;
  930.       msym = lookup_minimal_symbol (p, NULL, objfile);
  931.     }
  932.   if (msym.minsym == NULL && filename != NULL)
  933.     {
  934.       /* And try again for Sun Fortran, but without the filename.  */
  935.       p[n] = '_';
  936.       p[n + 1] = 0;
  937.       msym = lookup_minimal_symbol (p, NULL, objfile);
  938.     }

  939.   return msym.minsym == NULL ? 0 : BMSYMBOL_VALUE_ADDRESS (msym);
  940. }

  941. static void
  942. function_outside_compilation_unit_complaint (const char *arg1)
  943. {
  944.   complaint (&symfile_complaints,
  945.              _("function `%s' appears to be defined "
  946.                "outside of all compilation units"),
  947.              arg1);
  948. }

  949. /* Setup partial_symtab's describing each source file for which
  950.    debugging information is available.  */

  951. static void
  952. read_dbx_symtab (struct objfile *objfile)
  953. {
  954.   struct gdbarch *gdbarch = get_objfile_arch (objfile);
  955.   struct external_nlist *bufp = 0;        /* =0 avoids gcc -Wall glitch.  */
  956.   struct internal_nlist nlist;
  957.   CORE_ADDR text_addr;
  958.   int text_size;
  959.   char *sym_name;
  960.   int sym_len;

  961.   char *namestring;
  962.   int nsl;
  963.   int past_first_source_file = 0;
  964.   CORE_ADDR last_function_start = 0;
  965.   struct cleanup *back_to;
  966.   bfd *abfd;
  967.   int textlow_not_set;
  968.   int data_sect_index;

  969.   /* Current partial symtab.  */
  970.   struct partial_symtab *pst;

  971.   /* List of current psymtab's include files.  */
  972.   const char **psymtab_include_list;
  973.   int includes_allocated;
  974.   int includes_used;

  975.   /* Index within current psymtab dependency list.  */
  976.   struct partial_symtab **dependency_list;
  977.   int dependencies_used, dependencies_allocated;

  978.   text_addr = DBX_TEXT_ADDR (objfile);
  979.   text_size = DBX_TEXT_SIZE (objfile);

  980.   /* FIXME.  We probably want to change stringtab_global rather than add this
  981.      while processing every symbol entryFIXME.  */
  982.   file_string_table_offset = 0;
  983.   next_file_string_table_offset = 0;

  984.   stringtab_global = DBX_STRINGTAB (objfile);

  985.   pst = (struct partial_symtab *) 0;

  986.   includes_allocated = 30;
  987.   includes_used = 0;
  988.   psymtab_include_list = (const char **) alloca (includes_allocated *
  989.                                                  sizeof (const char *));

  990.   dependencies_allocated = 30;
  991.   dependencies_used = 0;
  992.   dependency_list =
  993.     (struct partial_symtab **) alloca (dependencies_allocated *
  994.                                        sizeof (struct partial_symtab *));

  995.   /* Init bincl list */
  996.   init_bincl_list (20, objfile);
  997.   back_to = make_cleanup_free_bincl_list (objfile);

  998.   set_last_source_file (NULL);

  999.   lowest_text_address = (CORE_ADDR) -1;

  1000.   symfile_bfd = objfile->obfd;        /* For next_text_symbol.  */
  1001.   abfd = objfile->obfd;
  1002.   symbuf_end = symbuf_idx = 0;
  1003.   next_symbol_text_func = dbx_next_symbol_text;
  1004.   textlow_not_set = 1;
  1005.   has_line_numbers = 0;

  1006.   /* FIXME: jimb/2003-09-12: We don't apply the right section's offset
  1007.      to global and static variables.  The stab for a global or static
  1008.      variable doesn't give us any indication of which section it's in,
  1009.      so we can't tell immediately which offset in
  1010.      objfile->section_offsets we should apply to the variable's
  1011.      address.

  1012.      We could certainly find out which section contains the variable
  1013.      by looking up the variable's unrelocated address with
  1014.      find_pc_section, but that would be expensive; this is the
  1015.      function that constructs the partial symbol tables by examining
  1016.      every symbol in the entire executable, and it's
  1017.      performance-critical.  So that expense would not be welcome.  I'm
  1018.      not sure what to do about this at the moment.

  1019.      What we have done for years is to simply assume that the .data
  1020.      section's offset is appropriate for all global and static
  1021.      variables.  Recently, this was expanded to fall back to the .bss
  1022.      section's offset if there is no .data section, and then to the
  1023.      .rodata section's offset.  */
  1024.   data_sect_index = objfile->sect_index_data;
  1025.   if (data_sect_index == -1)
  1026.     data_sect_index = SECT_OFF_BSS (objfile);
  1027.   if (data_sect_index == -1)
  1028.     data_sect_index = SECT_OFF_RODATA (objfile);

  1029.   /* If data_sect_index is still -1, that's okay.  It's perfectly fine
  1030.      for the file to have no .data, no .bss, and no .text at all, if
  1031.      it also has no global or static variables.  If it does, we will
  1032.      get an internal error from an ANOFFSET macro below when we try to
  1033.      use data_sect_index.  */

  1034.   for (symnum = 0; symnum < DBX_SYMCOUNT (objfile); symnum++)
  1035.     {
  1036.       /* Get the symbol for this run and pull out some info.  */
  1037.       QUIT;                        /* Allow this to be interruptable.  */
  1038.       if (symbuf_idx == symbuf_end)
  1039.         fill_symbuf (abfd);
  1040.       bufp = &symbuf[symbuf_idx++];

  1041.       /*
  1042.        * Special case to speed up readin.
  1043.        */
  1044.       if (bfd_h_get_8 (abfd, bufp->e_type) == N_SLINE)
  1045.         {
  1046.           has_line_numbers = 1;
  1047.           continue;
  1048.         }

  1049.       INTERNALIZE_SYMBOL (nlist, bufp, abfd);
  1050.       OBJSTAT (objfile, n_stabs++);

  1051.       /* Ok.  There is a lot of code duplicated in the rest of this
  1052.          switch statement (for efficiency reasons).  Since I don't
  1053.          like duplicating code, I will do my penance here, and
  1054.          describe the code which is duplicated:

  1055.          *) The assignment to namestring.
  1056.          *) The call to strchr.
  1057.          *) The addition of a partial symbol the two partial
  1058.          symbol lists.  This last is a large section of code, so
  1059.          I've imbedded it in the following macro.  */

  1060.       switch (nlist.n_type)
  1061.         {
  1062.           /*
  1063.            * Standard, external, non-debugger, symbols
  1064.            */

  1065.         case N_TEXT | N_EXT:
  1066.         case N_NBTEXT | N_EXT:
  1067.           goto record_it;

  1068.         case N_DATA | N_EXT:
  1069.         case N_NBDATA | N_EXT:
  1070.           goto record_it;

  1071.         case N_BSS:
  1072.         case N_BSS | N_EXT:
  1073.         case N_NBBSS | N_EXT:
  1074.         case N_SETV | N_EXT:                /* FIXME, is this in BSS? */
  1075.           goto record_it;

  1076.         case N_ABS | N_EXT:
  1077.           record_it:
  1078.           namestring = set_namestring (objfile, &nlist);

  1079.           record_minimal_symbol (namestring, nlist.n_value,
  1080.                                  nlist.n_type, objfile);        /* Always */
  1081.           continue;

  1082.           /* Standard, local, non-debugger, symbols.  */

  1083.         case N_NBTEXT:

  1084.           /* We need to be able to deal with both N_FN or N_TEXT,
  1085.              because we have no way of knowing whether the sys-supplied ld
  1086.              or GNU ld was used to make the executable.  Sequents throw
  1087.              in another wrinkle -- they renumbered N_FN.  */

  1088.         case N_FN:
  1089.         case N_FN_SEQ:
  1090.         case N_TEXT:
  1091.           namestring = set_namestring (objfile, &nlist);

  1092.           if ((namestring[0] == '-' && namestring[1] == 'l')
  1093.               || (namestring[(nsl = strlen (namestring)) - 1] == 'o'
  1094.                   && namestring[nsl - 2] == '.'))
  1095.             {
  1096.               nlist.n_value += ANOFFSET (objfile->section_offsets,
  1097.                                          SECT_OFF_TEXT (objfile));

  1098.               if (past_first_source_file && pst
  1099.                   /* The gould NP1 uses low values for .o and -l symbols
  1100.                      which are not the address.  */
  1101.                   && nlist.n_value >= pst->textlow)
  1102.                 {
  1103.                   end_psymtab (objfile, pst, psymtab_include_list,
  1104.                                includes_used, symnum * symbol_size,
  1105.                                nlist.n_value > pst->texthigh
  1106.                                ? nlist.n_value : pst->texthigh,
  1107.                                dependency_list, dependencies_used,
  1108.                                textlow_not_set);
  1109.                   pst = (struct partial_symtab *) 0;
  1110.                   includes_used = 0;
  1111.                   dependencies_used = 0;
  1112.                   has_line_numbers = 0;
  1113.                 }
  1114.               else
  1115.                 past_first_source_file = 1;
  1116.             }
  1117.           else
  1118.             goto record_it;
  1119.           continue;

  1120.         case N_DATA:
  1121.           goto record_it;

  1122.         case N_UNDF | N_EXT:
  1123.           /* The case (nlist.n_value != 0) is a "Fortran COMMON" symbol.
  1124.              We used to rely on the target to tell us whether it knows
  1125.              where the symbol has been relocated to, but none of the
  1126.              target implementations actually provided that operation.
  1127.              So we just ignore the symbol, the same way we would do if
  1128.              we had a target-side symbol lookup which returned no match.

  1129.              All other symbols (with nlist.n_value == 0), are really
  1130.              undefined, and so we ignore them too.  */
  1131.           continue;

  1132.         case N_UNDF:
  1133.           if (processing_acc_compilation && nlist.n_strx == 1)
  1134.             {
  1135.               /* Deal with relative offsets in the string table
  1136.                  used in ELF+STAB under Solaris.  If we want to use the
  1137.                  n_strx field, which contains the name of the file,
  1138.                  we must adjust file_string_table_offset *before* calling
  1139.                  set_namestring().  */
  1140.               past_first_source_file = 1;
  1141.               file_string_table_offset = next_file_string_table_offset;
  1142.               next_file_string_table_offset =
  1143.                 file_string_table_offset + nlist.n_value;
  1144.               if (next_file_string_table_offset < file_string_table_offset)
  1145.                 error (_("string table offset backs up at %d"), symnum);
  1146.               /* FIXME -- replace error() with complaint.  */
  1147.               continue;
  1148.             }
  1149.           continue;

  1150.           /* Lots of symbol types we can just ignore.  */

  1151.         case N_ABS:
  1152.         case N_NBDATA:
  1153.         case N_NBBSS:
  1154.           continue;

  1155.           /* Keep going . . .  */

  1156.           /*
  1157.            * Special symbol types for GNU
  1158.            */
  1159.         case N_INDR:
  1160.         case N_INDR | N_EXT:
  1161.         case N_SETA:
  1162.         case N_SETA | N_EXT:
  1163.         case N_SETT:
  1164.         case N_SETT | N_EXT:
  1165.         case N_SETD:
  1166.         case N_SETD | N_EXT:
  1167.         case N_SETB:
  1168.         case N_SETB | N_EXT:
  1169.         case N_SETV:
  1170.           continue;

  1171.           /*
  1172.            * Debugger symbols
  1173.            */

  1174.         case N_SO:
  1175.           {
  1176.             CORE_ADDR valu;
  1177.             static int prev_so_symnum = -10;
  1178.             static int first_so_symnum;
  1179.             const char *p;
  1180.             static char *dirname_nso;
  1181.             int prev_textlow_not_set;

  1182.             valu = nlist.n_value + ANOFFSET (objfile->section_offsets,
  1183.                                              SECT_OFF_TEXT (objfile));

  1184.             prev_textlow_not_set = textlow_not_set;

  1185.             /* A zero value is probably an indication for the SunPRO 3.0
  1186.                compiler.  end_psymtab explicitly tests for zero, so
  1187.                don't relocate it.  */

  1188.             if (nlist.n_value == 0
  1189.                 && gdbarch_sofun_address_maybe_missing (gdbarch))
  1190.               {
  1191.                 textlow_not_set = 1;
  1192.                 valu = 0;
  1193.               }
  1194.             else
  1195.               textlow_not_set = 0;

  1196.             past_first_source_file = 1;

  1197.             if (prev_so_symnum != symnum - 1)
  1198.               {                        /* Here if prev stab wasn't N_SO.  */
  1199.                 first_so_symnum = symnum;

  1200.                 if (pst)
  1201.                   {
  1202.                     end_psymtab (objfile, pst, psymtab_include_list,
  1203.                                  includes_used, symnum * symbol_size,
  1204.                                  valu > pst->texthigh ? valu : pst->texthigh,
  1205.                                  dependency_list, dependencies_used,
  1206.                                  prev_textlow_not_set);
  1207.                     pst = (struct partial_symtab *) 0;
  1208.                     includes_used = 0;
  1209.                     dependencies_used = 0;
  1210.                     has_line_numbers = 0;
  1211.                   }
  1212.               }

  1213.             prev_so_symnum = symnum;

  1214.             /* End the current partial symtab and start a new one.  */

  1215.             namestring = set_namestring (objfile, &nlist);

  1216.             /* Null name means end of .o file.  Don't start a new one.  */
  1217.             if (*namestring == '\000')
  1218.               continue;

  1219.             /* Some compilers (including gcc) emit a pair of initial N_SOs.
  1220.                The first one is a directory name; the second the file name.
  1221.                If pst exists, is empty, and has a filename ending in '/',
  1222.                we assume the previous N_SO was a directory name.  */

  1223.             p = lbasename (namestring);
  1224.             if (p != namestring && *p == '\000')
  1225.               {
  1226.                 /* Save the directory name SOs locally, then save it into
  1227.                    the psymtab when it's created below.  */
  1228.                 dirname_nso = namestring;
  1229.                 continue;
  1230.               }

  1231.             /* Some other compilers (C++ ones in particular) emit useless
  1232.                SOs for non-existant .c files.  We ignore all subsequent SOs
  1233.                that immediately follow the first.  */

  1234.             if (!pst)
  1235.               {
  1236.                 pst = start_psymtab (objfile,
  1237.                                      namestring, valu,
  1238.                                      first_so_symnum * symbol_size,
  1239.                                      objfile->global_psymbols.next,
  1240.                                      objfile->static_psymbols.next);
  1241.                 pst->dirname = dirname_nso;
  1242.                 dirname_nso = NULL;
  1243.               }
  1244.             continue;
  1245.           }

  1246.         case N_BINCL:
  1247.           {
  1248.             enum language tmp_language;

  1249.             /* Add this bincl to the bincl_list for future EXCLs.  No
  1250.                need to save the string; it'll be around until
  1251.                read_dbx_symtab function returns.  */

  1252.             namestring = set_namestring (objfile, &nlist);
  1253.             tmp_language = deduce_language_from_filename (namestring);

  1254.             /* Only change the psymtab's language if we've learned
  1255.                something useful (eg. tmp_language is not language_unknown).
  1256.                In addition, to match what start_subfile does, never change
  1257.                from C++ to C.  */
  1258.             if (tmp_language != language_unknown
  1259.                 && (tmp_language != language_c
  1260.                     || psymtab_language != language_cplus))
  1261.               psymtab_language = tmp_language;

  1262.             if (pst == NULL)
  1263.               {
  1264.                 /* FIXME: we should not get here without a PST to work on.
  1265.                    Attempt to recover.  */
  1266.                 complaint (&symfile_complaints,
  1267.                            _("N_BINCL %s not in entries for "
  1268.                              "any file, at symtab pos %d"),
  1269.                            namestring, symnum);
  1270.                 continue;
  1271.               }
  1272.             add_bincl_to_list (pst, namestring, nlist.n_value);

  1273.             /* Mark down an include file in the current psymtab.  */

  1274.             goto record_include_file;
  1275.           }

  1276.         case N_SOL:
  1277.           {
  1278.             enum language tmp_language;

  1279.             /* Mark down an include file in the current psymtab.  */
  1280.             namestring = set_namestring (objfile, &nlist);
  1281.             tmp_language = deduce_language_from_filename (namestring);

  1282.             /* Only change the psymtab's language if we've learned
  1283.                something useful (eg. tmp_language is not language_unknown).
  1284.                In addition, to match what start_subfile does, never change
  1285.                from C++ to C.  */
  1286.             if (tmp_language != language_unknown
  1287.                 && (tmp_language != language_c
  1288.                     || psymtab_language != language_cplus))
  1289.               psymtab_language = tmp_language;

  1290.             /* In C++, one may expect the same filename to come round many
  1291.                times, when code is coming alternately from the main file
  1292.                and from inline functions in other files.  So I check to see
  1293.                if this is a file we've seen before -- either the main
  1294.                source file, or a previously included file.

  1295.                This seems to be a lot of time to be spending on N_SOL, but
  1296.                things like "break c-exp.y:435" need to work (I
  1297.                suppose the psymtab_include_list could be hashed or put
  1298.                in a binary tree, if profiling shows this is a major hog).  */
  1299.             if (pst && filename_cmp (namestring, pst->filename) == 0)
  1300.               continue;
  1301.             {
  1302.               int i;

  1303.               for (i = 0; i < includes_used; i++)
  1304.                 if (filename_cmp (namestring, psymtab_include_list[i]) == 0)
  1305.                   {
  1306.                     i = -1;
  1307.                     break;
  1308.                   }
  1309.               if (i == -1)
  1310.                 continue;
  1311.             }

  1312.           record_include_file:

  1313.             psymtab_include_list[includes_used++] = namestring;
  1314.             if (includes_used >= includes_allocated)
  1315.               {
  1316.                 const char **orig = psymtab_include_list;

  1317.                 psymtab_include_list = (const char **)
  1318.                   alloca ((includes_allocated *= 2) * sizeof (const char *));
  1319.                 memcpy (psymtab_include_list, orig,
  1320.                         includes_used * sizeof (const char *));
  1321.               }
  1322.             continue;
  1323.           }
  1324.         case N_LSYM:                /* Typedef or automatic variable.  */
  1325.         case N_STSYM:                /* Data seg var -- static.  */
  1326.         case N_LCSYM:                /* BSS      "  */
  1327.         case N_ROSYM:                /* Read-only data seg var -- static.  */
  1328.         case N_NBSTS:                /* Gould nobase.  */
  1329.         case N_NBLCS:                /* symbols.  */
  1330.         case N_FUN:
  1331.         case N_GSYM:                /* Global (extern) variable; can be
  1332.                                    data or bss (sigh FIXME).  */

  1333.           /* Following may probably be ignored; I'll leave them here
  1334.              for now (until I do Pascal and Modula 2 extensions).  */

  1335.         case N_PC:                /* I may or may not need this; I
  1336.                                    suspect not.  */
  1337.         case N_M2C:                /* I suspect that I can ignore this here.  */
  1338.         case N_SCOPE:                /* Same.   */
  1339.         {
  1340.           char *p;

  1341.           namestring = set_namestring (objfile, &nlist);

  1342.           /* See if this is an end of function stab.  */
  1343.           if (pst && nlist.n_type == N_FUN && *namestring == '\000')
  1344.             {
  1345.               CORE_ADDR valu;

  1346.               /* It's value is the size (in bytes) of the function for
  1347.                  function relative stabs, or the address of the function's
  1348.                  end for old style stabs.  */
  1349.               valu = nlist.n_value + last_function_start;
  1350.               if (pst->texthigh == 0 || valu > pst->texthigh)
  1351.                 pst->texthigh = valu;
  1352.               break;
  1353.             }

  1354.           p = (char *) strchr (namestring, ':');
  1355.           if (!p)
  1356.             continue;                /* Not a debugging symbol.   */

  1357.            sym_len = 0;
  1358.           sym_name = NULL;        /* pacify "gcc -Werror" */
  1359.            if (psymtab_language == language_cplus)
  1360.              {
  1361.                char *new_name, *name = xmalloc (p - namestring + 1);
  1362.                memcpy (name, namestring, p - namestring);

  1363.                name[p - namestring] = '\0';
  1364.                new_name = cp_canonicalize_string (name);
  1365.                if (new_name != NULL)
  1366.                  {
  1367.                    sym_len = strlen (new_name);
  1368.                    sym_name = obstack_copy0 (&objfile->objfile_obstack,
  1369.                                             new_name, sym_len);
  1370.                    xfree (new_name);
  1371.                  }
  1372.               xfree (name);
  1373.              }

  1374.            if (sym_len == 0)
  1375.              {
  1376.                sym_name = namestring;
  1377.                sym_len = p - namestring;
  1378.              }

  1379.           /* Main processing section for debugging symbols which
  1380.              the initial read through the symbol tables needs to worry
  1381.              about.  If we reach this point, the symbol which we are
  1382.              considering is definitely one we are interested in.
  1383.              p must also contain the (valid) index into the namestring
  1384.              which indicates the debugging type symbol.  */

  1385.           switch (p[1])
  1386.             {
  1387.             case 'S':
  1388.               nlist.n_value += ANOFFSET (objfile->section_offsets,
  1389.                                          data_sect_index);

  1390.               if (gdbarch_static_transform_name_p (gdbarch))
  1391.                 gdbarch_static_transform_name (gdbarch, namestring);

  1392.               add_psymbol_to_list (sym_name, sym_len, 1,
  1393.                                    VAR_DOMAIN, LOC_STATIC,
  1394.                                    &objfile->static_psymbols,
  1395.                                    0, nlist.n_value,
  1396.                                    psymtab_language, objfile);
  1397.               continue;

  1398.             case 'G':
  1399.               nlist.n_value += ANOFFSET (objfile->section_offsets,
  1400.                                          data_sect_index);
  1401.               /* The addresses in these entries are reported to be
  1402.                  wrong.  See the code that reads 'G's for symtabs.  */
  1403.               add_psymbol_to_list (sym_name, sym_len, 1,
  1404.                                    VAR_DOMAIN, LOC_STATIC,
  1405.                                    &objfile->global_psymbols,
  1406.                                    0, nlist.n_value,
  1407.                                    psymtab_language, objfile);
  1408.               continue;

  1409.             case 'T':
  1410.               /* When a 'T' entry is defining an anonymous enum, it
  1411.                  may have a name which is the empty string, or a
  1412.                  single space.  Since they're not really defining a
  1413.                  symbol, those shouldn't go in the partial symbol
  1414.                  table.  We do pick up the elements of such enums at
  1415.                  'check_enum:', below.  */
  1416.               if (p >= namestring + 2
  1417.                   || (p == namestring + 1
  1418.                       && namestring[0] != ' '))
  1419.                 {
  1420.                   add_psymbol_to_list (sym_name, sym_len, 1,
  1421.                                        STRUCT_DOMAIN, LOC_TYPEDEF,
  1422.                                        &objfile->static_psymbols,
  1423.                                        nlist.n_value, 0,
  1424.                                        psymtab_language, objfile);
  1425.                   if (p[2] == 't')
  1426.                     {
  1427.                       /* Also a typedef with the same name.  */
  1428.                       add_psymbol_to_list (sym_name, sym_len, 1,
  1429.                                            VAR_DOMAIN, LOC_TYPEDEF,
  1430.                                            &objfile->static_psymbols,
  1431.                                            nlist.n_value, 0,
  1432.                                            psymtab_language, objfile);
  1433.                       p += 1;
  1434.                     }
  1435.                 }
  1436.               goto check_enum;

  1437.             case 't':
  1438.               if (p != namestring)        /* a name is there, not just :T...  */
  1439.                 {
  1440.                   add_psymbol_to_list (sym_name, sym_len, 1,
  1441.                                        VAR_DOMAIN, LOC_TYPEDEF,
  1442.                                        &objfile->static_psymbols,
  1443.                                        nlist.n_value, 0,
  1444.                                        psymtab_language, objfile);
  1445.                 }
  1446.             check_enum:
  1447.               /* If this is an enumerated type, we need to
  1448.                  add all the enum constants to the partial symbol
  1449.                  table.  This does not cover enums without names, e.g.
  1450.                  "enum {a, b} c;" in C, but fortunately those are
  1451.                  rare.  There is no way for GDB to find those from the
  1452.                  enum type without spending too much time on it.  Thus
  1453.                  to solve this problem, the compiler needs to put out the
  1454.                  enum in a nameless type.  GCC2 does this.  */

  1455.               /* We are looking for something of the form
  1456.                  <name> ":" ("t" | "T") [<number> "="] "e"
  1457.                  {<constant> ":" <value> ","} ";".  */

  1458.               /* Skip over the colon and the 't' or 'T'.  */
  1459.               p += 2;
  1460.               /* This type may be given a number.  Also, numbers can come
  1461.                  in pairs like (0,26).  Skip over it.  */
  1462.               while ((*p >= '0' && *p <= '9')
  1463.                      || *p == '(' || *p == ',' || *p == ')'
  1464.                      || *p == '=')
  1465.                 p++;

  1466.               if (*p++ == 'e')
  1467.                 {
  1468.                   /* The aix4 compiler emits extra crud before the members.  */
  1469.                   if (*p == '-')
  1470.                     {
  1471.                       /* Skip over the type (?).  */
  1472.                       while (*p != ':')
  1473.                         p++;

  1474.                       /* Skip over the colon.  */
  1475.                       p++;
  1476.                     }

  1477.                   /* We have found an enumerated type.  */
  1478.                   /* According to comments in read_enum_type
  1479.                      a comma could end it instead of a semicolon.
  1480.                      I don't know where that happens.
  1481.                      Accept either.  */
  1482.                   while (*p && *p != ';' && *p != ',')
  1483.                     {
  1484.                       char *q;

  1485.                       /* Check for and handle cretinous dbx symbol name
  1486.                          continuation!  */
  1487.                       if (*p == '\\' || (*p == '?' && p[1] == '\0'))
  1488.                         p = next_symbol_text (objfile);

  1489.                       /* Point to the character after the name
  1490.                          of the enum constant.  */
  1491.                       for (q = p; *q && *q != ':'; q++)
  1492.                         ;
  1493.                       /* Note that the value doesn't matter for
  1494.                          enum constants in psymtabs, just in symtabs.  */
  1495.                       add_psymbol_to_list (p, q - p, 1,
  1496.                                            VAR_DOMAIN, LOC_CONST,
  1497.                                            &objfile->static_psymbols, 0,
  1498.                                            0, psymtab_language, objfile);
  1499.                       /* Point past the name.  */
  1500.                       p = q;
  1501.                       /* Skip over the value.  */
  1502.                       while (*p && *p != ',')
  1503.                         p++;
  1504.                       /* Advance past the comma.  */
  1505.                       if (*p)
  1506.                         p++;
  1507.                     }
  1508.                 }
  1509.               continue;

  1510.             case 'c':
  1511.               /* Constant, e.g. from "const" in Pascal.  */
  1512.               add_psymbol_to_list (sym_name, sym_len, 1,
  1513.                                    VAR_DOMAIN, LOC_CONST,
  1514.                                    &objfile->static_psymbols, nlist.n_value,
  1515.                                    0, psymtab_language, objfile);
  1516.               continue;

  1517.             case 'f':
  1518.               if (! pst)
  1519.                 {
  1520.                   int name_len = p - namestring;
  1521.                   char *name = xmalloc (name_len + 1);

  1522.                   memcpy (name, namestring, name_len);
  1523.                   name[name_len] = '\0';
  1524.                   function_outside_compilation_unit_complaint (name);
  1525.                   xfree (name);
  1526.                 }
  1527.               nlist.n_value += ANOFFSET (objfile->section_offsets,
  1528.                                          SECT_OFF_TEXT (objfile));
  1529.               /* Kludges for ELF/STABS with Sun ACC.  */
  1530.               last_function_name = namestring;
  1531.               /* Do not fix textlow==0 for .o or NLM files, as 0 is a legit
  1532.                  value for the bottom of the text seg in those cases.  */
  1533.               if (nlist.n_value == ANOFFSET (objfile->section_offsets,
  1534.                                              SECT_OFF_TEXT (objfile))
  1535.                   && gdbarch_sofun_address_maybe_missing (gdbarch))
  1536.                 {
  1537.                   CORE_ADDR minsym_valu =
  1538.                     find_stab_function_addr (namestring,
  1539.                                              pst ? pst->filename : NULL,
  1540.                                              objfile);

  1541.                   /* find_stab_function_addr will return 0 if the minimal
  1542.                      symbol wasn't found.  (Unfortunately, this might also
  1543.                      be a valid address.)  Anyway, if it *does* return 0,
  1544.                      it is likely that the value was set correctly to begin
  1545.                      with...  */
  1546.                   if (minsym_valu != 0)
  1547.                     nlist.n_value = minsym_valu;
  1548.                 }
  1549.               if (pst && textlow_not_set
  1550.                   && gdbarch_sofun_address_maybe_missing (gdbarch))
  1551.                 {
  1552.                   pst->textlow = nlist.n_value;
  1553.                   textlow_not_set = 0;
  1554.                 }
  1555.               /* End kludge.  */

  1556.               /* Keep track of the start of the last function so we
  1557.                  can handle end of function symbols.  */
  1558.               last_function_start = nlist.n_value;

  1559.               /* In reordered executables this function may lie outside
  1560.                  the bounds created by N_SO symbols.  If that's the case
  1561.                  use the address of this function as the low bound for
  1562.                  the partial symbol table.  */
  1563.               if (pst
  1564.                   && (textlow_not_set
  1565.                       || (nlist.n_value < pst->textlow
  1566.                           && (nlist.n_value
  1567.                               != ANOFFSET (objfile->section_offsets,
  1568.                                            SECT_OFF_TEXT (objfile))))))
  1569.                 {
  1570.                   pst->textlow = nlist.n_value;
  1571.                   textlow_not_set = 0;
  1572.                 }
  1573.               add_psymbol_to_list (sym_name, sym_len, 1,
  1574.                                    VAR_DOMAIN, LOC_BLOCK,
  1575.                                    &objfile->static_psymbols,
  1576.                                    0, nlist.n_value,
  1577.                                    psymtab_language, objfile);
  1578.               continue;

  1579.               /* Global functions were ignored here, but now they
  1580.                  are put into the global psymtab like one would expect.
  1581.                  They're also in the minimal symbol table.  */
  1582.             case 'F':
  1583.               if (! pst)
  1584.                 {
  1585.                   int name_len = p - namestring;
  1586.                   char *name = xmalloc (name_len + 1);

  1587.                   memcpy (name, namestring, name_len);
  1588.                   name[name_len] = '\0';
  1589.                   function_outside_compilation_unit_complaint (name);
  1590.                   xfree (name);
  1591.                 }
  1592.               nlist.n_value += ANOFFSET (objfile->section_offsets,
  1593.                                          SECT_OFF_TEXT (objfile));
  1594.               /* Kludges for ELF/STABS with Sun ACC.  */
  1595.               last_function_name = namestring;
  1596.               /* Do not fix textlow==0 for .o or NLM files, as 0 is a legit
  1597.                  value for the bottom of the text seg in those cases.  */
  1598.               if (nlist.n_value == ANOFFSET (objfile->section_offsets,
  1599.                                              SECT_OFF_TEXT (objfile))
  1600.                   && gdbarch_sofun_address_maybe_missing (gdbarch))
  1601.                 {
  1602.                   CORE_ADDR minsym_valu =
  1603.                     find_stab_function_addr (namestring,
  1604.                                              pst ? pst->filename : NULL,
  1605.                                              objfile);

  1606.                   /* find_stab_function_addr will return 0 if the minimal
  1607.                      symbol wasn't found.  (Unfortunately, this might also
  1608.                      be a valid address.)  Anyway, if it *does* return 0,
  1609.                      it is likely that the value was set correctly to begin
  1610.                      with...  */
  1611.                   if (minsym_valu != 0)
  1612.                     nlist.n_value = minsym_valu;
  1613.                 }
  1614.               if (pst && textlow_not_set
  1615.                   && gdbarch_sofun_address_maybe_missing (gdbarch))
  1616.                 {
  1617.                   pst->textlow = nlist.n_value;
  1618.                   textlow_not_set = 0;
  1619.                 }
  1620.               /* End kludge.  */

  1621.               /* Keep track of the start of the last function so we
  1622.                  can handle end of function symbols.  */
  1623.               last_function_start = nlist.n_value;

  1624.               /* In reordered executables this function may lie outside
  1625.                  the bounds created by N_SO symbols.  If that's the case
  1626.                  use the address of this function as the low bound for
  1627.                  the partial symbol table.  */
  1628.               if (pst
  1629.                   && (textlow_not_set
  1630.                       || (nlist.n_value < pst->textlow
  1631.                           && (nlist.n_value
  1632.                               != ANOFFSET (objfile->section_offsets,
  1633.                                            SECT_OFF_TEXT (objfile))))))
  1634.                 {
  1635.                   pst->textlow = nlist.n_value;
  1636.                   textlow_not_set = 0;
  1637.                 }
  1638.               add_psymbol_to_list (sym_name, sym_len, 1,
  1639.                                    VAR_DOMAIN, LOC_BLOCK,
  1640.                                    &objfile->global_psymbols,
  1641.                                    0, nlist.n_value,
  1642.                                    psymtab_language, objfile);
  1643.               continue;

  1644.               /* Two things show up here (hopefully); static symbols of
  1645.                  local scope (static used inside braces) or extensions
  1646.                  of structure symbols.  We can ignore both.  */
  1647.             case 'V':
  1648.             case '(':
  1649.             case '0':
  1650.             case '1':
  1651.             case '2':
  1652.             case '3':
  1653.             case '4':
  1654.             case '5':
  1655.             case '6':
  1656.             case '7':
  1657.             case '8':
  1658.             case '9':
  1659.             case '-':
  1660.             case '#':        /* For symbol identification (used in live ranges).  */
  1661.               continue;

  1662.             case ':':
  1663.               /* It is a C++ nested symbol.  We don't need to record it
  1664.                  (I don't think); if we try to look up foo::bar::baz,
  1665.                  then symbols for the symtab containing foo should get
  1666.                  read in, I think.  */
  1667.               /* Someone says sun cc puts out symbols like
  1668.                  /foo/baz/maclib::/usr/local/bin/maclib,
  1669.                  which would get here with a symbol type of ':'.  */
  1670.               continue;

  1671.             default:
  1672.               /* Unexpected symbol descriptor.  The second and subsequent stabs
  1673.                  of a continued stab can show up here.  The question is
  1674.                  whether they ever can mimic a normal stab--it would be
  1675.                  nice if not, since we certainly don't want to spend the
  1676.                  time searching to the end of every string looking for
  1677.                  a backslash.  */

  1678.               complaint (&symfile_complaints,
  1679.                          _("unknown symbol descriptor `%c'"),
  1680.                          p[1]);

  1681.               /* Ignore it; perhaps it is an extension that we don't
  1682.                  know about.  */
  1683.               continue;
  1684.             }
  1685.         }

  1686.         case N_EXCL:

  1687.           namestring = set_namestring (objfile, &nlist);

  1688.           /* Find the corresponding bincl and mark that psymtab on the
  1689.              psymtab dependency list.  */
  1690.           {
  1691.             struct partial_symtab *needed_pst =
  1692.               find_corresponding_bincl_psymtab (namestring, nlist.n_value);

  1693.             /* If this include file was defined earlier in this file,
  1694.                leave it alone.  */
  1695.             if (needed_pst == pst)
  1696.               continue;

  1697.             if (needed_pst)
  1698.               {
  1699.                 int i;
  1700.                 int found = 0;

  1701.                 for (i = 0; i < dependencies_used; i++)
  1702.                   if (dependency_list[i] == needed_pst)
  1703.                     {
  1704.                       found = 1;
  1705.                       break;
  1706.                     }

  1707.                 /* If it's already in the list, skip the rest.  */
  1708.                 if (found)
  1709.                   continue;

  1710.                 dependency_list[dependencies_used++] = needed_pst;
  1711.                 if (dependencies_used >= dependencies_allocated)
  1712.                   {
  1713.                     struct partial_symtab **orig = dependency_list;

  1714.                     dependency_list =
  1715.                       (struct partial_symtab **)
  1716.                       alloca ((dependencies_allocated *= 2)
  1717.                               * sizeof (struct partial_symtab *));
  1718.                     memcpy (dependency_list, orig,
  1719.                             (dependencies_used
  1720.                              * sizeof (struct partial_symtab *)));
  1721. #ifdef DEBUG_INFO
  1722.                     fprintf_unfiltered (gdb_stderr,
  1723.                                         "Had to reallocate "
  1724.                                         "dependency list.\n");
  1725.                     fprintf_unfiltered (gdb_stderr,
  1726.                                         "New dependencies allocated: %d\n",
  1727.                                         dependencies_allocated);
  1728. #endif
  1729.                   }
  1730.               }
  1731.           }
  1732.           continue;

  1733.         case N_ENDM:
  1734.           /* Solaris 2 end of module, finish current partial symbol table.
  1735.              end_psymtab will set pst->texthigh to the proper value, which
  1736.              is necessary if a module compiled without debugging info
  1737.              follows this module.  */
  1738.           if (pst && gdbarch_sofun_address_maybe_missing (gdbarch))
  1739.             {
  1740.               end_psymtab (objfile, pst, psymtab_include_list, includes_used,
  1741.                            symnum * symbol_size,
  1742.                            (CORE_ADDR) 0, dependency_list,
  1743.                            dependencies_used, textlow_not_set);
  1744.               pst = (struct partial_symtab *) 0;
  1745.               includes_used = 0;
  1746.               dependencies_used = 0;
  1747.               has_line_numbers = 0;
  1748.             }
  1749.           continue;

  1750.         case N_RBRAC:
  1751. #ifdef HANDLE_RBRAC
  1752.           HANDLE_RBRAC (nlist.n_value);
  1753.           continue;
  1754. #endif
  1755.         case N_EINCL:
  1756.         case N_DSLINE:
  1757.         case N_BSLINE:
  1758.         case N_SSYM:                /* Claim: Structure or union element.
  1759.                                    Hopefully, I can ignore this.  */
  1760.         case N_ENTRY:                /* Alternate entry point; can ignore.  */
  1761.         case N_MAIN:                /* Can definitely ignore this.   */
  1762.         case N_CATCH:                /* These are GNU C++ extensions */
  1763.         case N_EHDECL:                /* that can safely be ignored here.  */
  1764.         case N_LENG:
  1765.         case N_BCOMM:
  1766.         case N_ECOMM:
  1767.         case N_ECOML:
  1768.         case N_FNAME:
  1769.         case N_SLINE:
  1770.         case N_RSYM:
  1771.         case N_PSYM:
  1772.         case N_BNSYM:
  1773.         case N_ENSYM:
  1774.         case N_LBRAC:
  1775.         case N_NSYMS:                /* Ultrix 4.0: symbol count */
  1776.         case N_DEFD:                /* GNU Modula-2 */
  1777.         case N_ALIAS:                /* SunPro F77: alias name, ignore for now.  */

  1778.         case N_OBJ:                /* Useless types from Solaris.  */
  1779.         case N_OPT:
  1780.         case N_PATCH:
  1781.           /* These symbols aren't interesting; don't worry about them.  */
  1782.           continue;

  1783.         default:
  1784.           /* If we haven't found it yet, ignore it.  It's probably some
  1785.              new type we don't know about yet.  */
  1786.           unknown_symtype_complaint (hex_string (nlist.n_type));
  1787.           continue;
  1788.         }
  1789.     }

  1790.   /* If there's stuff to be cleaned up, clean it up.  */
  1791.   if (pst)
  1792.     {
  1793.       /* Don't set pst->texthigh lower than it already is.  */
  1794.       CORE_ADDR text_end =
  1795.         (lowest_text_address == (CORE_ADDR) -1
  1796.          ? (text_addr + ANOFFSET (objfile->section_offsets,
  1797.                                   SECT_OFF_TEXT (objfile)))
  1798.          : lowest_text_address)
  1799.         + text_size;

  1800.       end_psymtab (objfile, pst, psymtab_include_list, includes_used,
  1801.                    symnum * symbol_size,
  1802.                    text_end > pst->texthigh ? text_end : pst->texthigh,
  1803.                    dependency_list, dependencies_used, textlow_not_set);
  1804.     }

  1805.   do_cleanups (back_to);
  1806. }

  1807. /* Allocate and partially fill a partial symtab.  It will be
  1808.    completely filled at the end of the symbol list.

  1809.    SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
  1810.    is the address relative to which its symbols are (incremental) or 0
  1811.    (normal).  */

  1812. static struct partial_symtab *
  1813. start_psymtab (struct objfile *objfile, char *filename, CORE_ADDR textlow,
  1814.                int ldsymoff, struct partial_symbol **global_syms,
  1815.                struct partial_symbol **static_syms)
  1816. {
  1817.   struct partial_symtab *result =
  1818.     start_psymtab_common (objfile, objfile->section_offsets,
  1819.                           filename, textlow, global_syms, static_syms);

  1820.   result->read_symtab_private = obstack_alloc (&objfile->objfile_obstack,
  1821.                                                sizeof (struct symloc));
  1822.   LDSYMOFF (result) = ldsymoff;
  1823.   result->read_symtab = dbx_read_symtab;
  1824.   SYMBOL_SIZE (result) = symbol_size;
  1825.   SYMBOL_OFFSET (result) = symbol_table_offset;
  1826.   STRING_OFFSET (result) = string_table_offset;
  1827.   FILE_STRING_OFFSET (result) = file_string_table_offset;

  1828. #ifdef HAVE_ELF
  1829.   /* If we're handling an ELF file, drag some section-relocation info
  1830.      for this source file out of the ELF symbol table, to compensate for
  1831.      Sun brain death.  This replaces the section_offsets in this psymtab,
  1832.      if successful.  */
  1833.   elfstab_offset_sections (objfile, result);
  1834. #endif

  1835.   /* Deduce the source language from the filename for this psymtab.  */
  1836.   psymtab_language = deduce_language_from_filename (filename);

  1837.   return result;
  1838. }

  1839. /* Close off the current usage of PST.
  1840.    Returns PST or NULL if the partial symtab was empty and thrown away.

  1841.    FIXME:  List variables and peculiarities of same.  */

  1842. struct partial_symtab *
  1843. end_psymtab (struct objfile *objfile, struct partial_symtab *pst,
  1844.              const char **include_list, int num_includes,
  1845.              int capping_symbol_offset, CORE_ADDR capping_text,
  1846.              struct partial_symtab **dependency_list, int number_dependencies,
  1847.              int textlow_not_set)
  1848. {
  1849.   int i;
  1850.   struct gdbarch *gdbarch = get_objfile_arch (objfile);

  1851.   if (capping_symbol_offset != -1)
  1852.     LDSYMLEN (pst) = capping_symbol_offset - LDSYMOFF (pst);
  1853.   pst->texthigh = capping_text;

  1854.   /* Under Solaris, the N_SO symbols always have a value of 0,
  1855.      instead of the usual address of the .o file.  Therefore,
  1856.      we have to do some tricks to fill in texthigh and textlow.
  1857.      The first trick is: if we see a static
  1858.      or global function, and the textlow for the current pst
  1859.      is not set (ie: textlow_not_set), then we use that function's
  1860.      address for the textlow of the pst.  */

  1861.   /* Now, to fill in texthigh, we remember the last function seen
  1862.      in the .o file.  Also, there's a hack in
  1863.      bfd/elf.c and gdb/elfread.c to pass the ELF st_size field
  1864.      to here via the misc_info field.  Therefore, we can fill in
  1865.      a reliable texthigh by taking the address plus size of the
  1866.      last function in the file.  */

  1867.   if (pst->texthigh == 0 && last_function_name
  1868.       && gdbarch_sofun_address_maybe_missing (gdbarch))
  1869.     {
  1870.       char *p;
  1871.       int n;
  1872.       struct bound_minimal_symbol minsym;

  1873.       p = strchr (last_function_name, ':');
  1874.       if (p == NULL)
  1875.         p = last_function_name;
  1876.       n = p - last_function_name;
  1877.       p = alloca (n + 2);
  1878.       strncpy (p, last_function_name, n);
  1879.       p[n] = 0;

  1880.       minsym = lookup_minimal_symbol (p, pst->filename, objfile);
  1881.       if (minsym.minsym == NULL)
  1882.         {
  1883.           /* Sun Fortran appends an underscore to the minimal symbol name,
  1884.              try again with an appended underscore if the minimal symbol
  1885.              was not found.  */
  1886.           p[n] = '_';
  1887.           p[n + 1] = 0;
  1888.           minsym = lookup_minimal_symbol (p, pst->filename, objfile);
  1889.         }

  1890.       if (minsym.minsym)
  1891.         pst->texthigh = (BMSYMBOL_VALUE_ADDRESS (minsym)
  1892.                          + MSYMBOL_SIZE (minsym.minsym));

  1893.       last_function_name = NULL;
  1894.     }

  1895.   if (!gdbarch_sofun_address_maybe_missing (gdbarch))
  1896.     ;
  1897.   /* This test will be true if the last .o file is only data.  */
  1898.   else if (textlow_not_set)
  1899.     pst->textlow = pst->texthigh;
  1900.   else
  1901.     {
  1902.       struct partial_symtab *p1;

  1903.       /* If we know our own starting text address, then walk through all other
  1904.          psymtabs for this objfile, and if any didn't know their ending text
  1905.          address, set it to our starting address.  Take care to not set our
  1906.          own ending address to our starting address, nor to set addresses on
  1907.          `dependency' files that have both textlow and texthigh zero.  */

  1908.       ALL_OBJFILE_PSYMTABS (objfile, p1)
  1909.       {
  1910.         if (p1->texthigh == 0 && p1->textlow != 0 && p1 != pst)
  1911.           {
  1912.             p1->texthigh = pst->textlow;
  1913.             /* If this file has only data, then make textlow match
  1914.                texthigh.  */
  1915.             if (p1->textlow == 0)
  1916.               p1->textlow = p1->texthigh;
  1917.           }
  1918.       }
  1919.     }

  1920.   /* End of kludge for patching Solaris textlow and texthigh.  */

  1921.   pst->n_global_syms =
  1922.     objfile->global_psymbols.next - (objfile->global_psymbols.list
  1923.                                      + pst->globals_offset);
  1924.   pst->n_static_syms =
  1925.     objfile->static_psymbols.next - (objfile->static_psymbols.list
  1926.                                      + pst->statics_offset);

  1927.   pst->number_of_dependencies = number_dependencies;
  1928.   if (number_dependencies)
  1929.     {
  1930.       pst->dependencies = (struct partial_symtab **)
  1931.         obstack_alloc (&objfile->objfile_obstack,
  1932.                        number_dependencies * sizeof (struct partial_symtab *));
  1933.       memcpy (pst->dependencies, dependency_list,
  1934.               number_dependencies * sizeof (struct partial_symtab *));
  1935.     }
  1936.   else
  1937.     pst->dependencies = 0;

  1938.   for (i = 0; i < num_includes; i++)
  1939.     {
  1940.       struct partial_symtab *subpst =
  1941.         allocate_psymtab (include_list[i], objfile);

  1942.       /* Copy the sesction_offsets array from the main psymtab.  */
  1943.       subpst->section_offsets = pst->section_offsets;
  1944.       subpst->read_symtab_private =
  1945.         obstack_alloc (&objfile->objfile_obstack, sizeof (struct symloc));
  1946.       LDSYMOFF (subpst) =
  1947.         LDSYMLEN (subpst) =
  1948.         subpst->textlow =
  1949.         subpst->texthigh = 0;

  1950.       /* We could save slight bits of space by only making one of these,
  1951.          shared by the entire set of include files.  FIXME-someday.  */
  1952.       subpst->dependencies = (struct partial_symtab **)
  1953.         obstack_alloc (&objfile->objfile_obstack,
  1954.                        sizeof (struct partial_symtab *));
  1955.       subpst->dependencies[0] = pst;
  1956.       subpst->number_of_dependencies = 1;

  1957.       subpst->globals_offset =
  1958.         subpst->n_global_syms =
  1959.         subpst->statics_offset =
  1960.         subpst->n_static_syms = 0;

  1961.       subpst->readin = 0;
  1962.       subpst->compunit_symtab = 0;
  1963.       subpst->read_symtab = pst->read_symtab;
  1964.     }

  1965.   sort_pst_symbols (objfile, pst);

  1966.   if (num_includes == 0
  1967.       && number_dependencies == 0
  1968.       && pst->n_global_syms == 0
  1969.       && pst->n_static_syms == 0
  1970.       && has_line_numbers == 0)
  1971.     {
  1972.       /* Throw away this psymtab, it's empty.  We can't deallocate it, since
  1973.          it is on the obstack, but we can forget to chain it on the list.  */
  1974.       /* Empty psymtabs happen as a result of header files which don't have
  1975.          any symbols in them.  There can be a lot of them.  But this check
  1976.          is wrong, in that a psymtab with N_SLINE entries but nothing else
  1977.          is not empty, but we don't realize that.  Fixing that without slowing
  1978.          things down might be tricky.  */

  1979.       discard_psymtab (objfile, pst);

  1980.       /* Indicate that psymtab was thrown away.  */
  1981.       pst = (struct partial_symtab *) NULL;
  1982.     }
  1983.   return pst;
  1984. }

  1985. static void
  1986. dbx_psymtab_to_symtab_1 (struct objfile *objfile, struct partial_symtab *pst)
  1987. {
  1988.   struct cleanup *old_chain;
  1989.   int i;

  1990.   if (pst->readin)
  1991.     {
  1992.       fprintf_unfiltered (gdb_stderr, "Psymtab for %s already read in.  "
  1993.                           "Shouldn't happen.\n",
  1994.                           pst->filename);
  1995.       return;
  1996.     }

  1997.   /* Read in all partial symtabs on which this one is dependent.  */
  1998.   for (i = 0; i < pst->number_of_dependencies; i++)
  1999.     if (!pst->dependencies[i]->readin)
  2000.       {
  2001.         /* Inform about additional files that need to be read in.  */
  2002.         if (info_verbose)
  2003.           {
  2004.             fputs_filtered (" ", gdb_stdout);
  2005.             wrap_here ("");
  2006.             fputs_filtered ("and ", gdb_stdout);
  2007.             wrap_here ("");
  2008.             printf_filtered ("%s...", pst->dependencies[i]->filename);
  2009.             wrap_here ("");        /* Flush output.  */
  2010.             gdb_flush (gdb_stdout);
  2011.           }
  2012.         dbx_psymtab_to_symtab_1 (objfile, pst->dependencies[i]);
  2013.       }

  2014.   if (LDSYMLEN (pst))                /* Otherwise it's a dummy.  */
  2015.     {
  2016.       /* Init stuff necessary for reading in symbols */
  2017.       stabsread_init ();
  2018.       buildsym_init ();
  2019.       old_chain = make_cleanup (really_free_pendings, 0);
  2020.       file_string_table_offset = FILE_STRING_OFFSET (pst);
  2021.       symbol_size = SYMBOL_SIZE (pst);

  2022.       /* Read in this file's symbols.  */
  2023.       bfd_seek (objfile->obfd, SYMBOL_OFFSET (pst), SEEK_SET);
  2024.       read_ofile_symtab (objfile, pst);

  2025.       do_cleanups (old_chain);
  2026.     }

  2027.   pst->readin = 1;
  2028. }

  2029. /* Read in all of the symbols for a given psymtab for real.
  2030.    Be verbose about it if the user wants that.  SELF is not NULL.  */

  2031. static void
  2032. dbx_read_symtab (struct partial_symtab *self, struct objfile *objfile)
  2033. {
  2034.   bfd *sym_bfd;

  2035.   if (self->readin)
  2036.     {
  2037.       fprintf_unfiltered (gdb_stderr, "Psymtab for %s already read in.  "
  2038.                           "Shouldn't happen.\n",
  2039.                           self->filename);
  2040.       return;
  2041.     }

  2042.   if (LDSYMLEN (self) || self->number_of_dependencies)
  2043.     {
  2044.       struct cleanup *back_to;

  2045.       /* Print the message now, before reading the string table,
  2046.          to avoid disconcerting pauses.  */
  2047.       if (info_verbose)
  2048.         {
  2049.           printf_filtered ("Reading in symbols for %s...", self->filename);
  2050.           gdb_flush (gdb_stdout);
  2051.         }

  2052.       sym_bfd = objfile->obfd;

  2053.       next_symbol_text_func = dbx_next_symbol_text;

  2054.       back_to = make_cleanup (null_cleanup, NULL);

  2055.       if (DBX_STAB_SECTION (objfile))
  2056.         {
  2057.           stabs_data
  2058.             = symfile_relocate_debug_section (objfile,
  2059.                                               DBX_STAB_SECTION (objfile),
  2060.                                               NULL);

  2061.           if (stabs_data)
  2062.             make_cleanup (free_current_contents, (void *) &stabs_data);
  2063.         }

  2064.       dbx_psymtab_to_symtab_1 (objfile, self);

  2065.       do_cleanups (back_to);

  2066.       /* Match with global symbols.  This only needs to be done once,
  2067.          after all of the symtabs and dependencies have been read in.   */
  2068.       scan_file_globals (objfile);

  2069.       /* Finish up the debug error message.  */
  2070.       if (info_verbose)
  2071.         printf_filtered ("done.\n");
  2072.     }
  2073. }

  2074. /* Read in a defined section of a specific object file's symbols.  */

  2075. static void
  2076. read_ofile_symtab (struct objfile *objfile, struct partial_symtab *pst)
  2077. {
  2078.   char *namestring;
  2079.   struct external_nlist *bufp;
  2080.   struct internal_nlist nlist;
  2081.   unsigned char type;
  2082.   unsigned max_symnum;
  2083.   bfd *abfd;
  2084.   int sym_offset;                /* Offset to start of symbols to read */
  2085.   int sym_size;                        /* Size of symbols to read */
  2086.   CORE_ADDR text_offset;        /* Start of text segment for symbols */
  2087.   int text_size;                /* Size of text segment for symbols */
  2088.   struct section_offsets *section_offsets;

  2089.   sym_offset = LDSYMOFF (pst);
  2090.   sym_size = LDSYMLEN (pst);
  2091.   text_offset = pst->textlow;
  2092.   text_size = pst->texthigh - pst->textlow;
  2093.   /* This cannot be simply objfile->section_offsets because of
  2094.      elfstab_offset_sections() which initializes the psymtab section
  2095.      offsets information in a special way, and that is different from
  2096.      objfile->section_offsets.  */
  2097.   section_offsets = pst->section_offsets;

  2098.   dbxread_objfile = objfile;

  2099.   stringtab_global = DBX_STRINGTAB (objfile);
  2100.   set_last_source_file (NULL);

  2101.   abfd = objfile->obfd;
  2102.   symfile_bfd = objfile->obfd;        /* Implicit param to next_text_symbol.  */
  2103.   symbuf_end = symbuf_idx = 0;
  2104.   symbuf_read = 0;
  2105.   symbuf_left = sym_offset + sym_size;

  2106.   /* It is necessary to actually read one symbol *before* the start
  2107.      of this symtab's symbols, because the GCC_COMPILED_FLAG_SYMBOL
  2108.      occurs before the N_SO symbol.

  2109.      Detecting this in read_dbx_symtab
  2110.      would slow down initial readin, so we look for it here instead.  */
  2111.   if (!processing_acc_compilation && sym_offset >= (int) symbol_size)
  2112.     {
  2113.       stabs_seek (sym_offset - symbol_size);
  2114.       fill_symbuf (abfd);
  2115.       bufp = &symbuf[symbuf_idx++];
  2116.       INTERNALIZE_SYMBOL (nlist, bufp, abfd);
  2117.       OBJSTAT (objfile, n_stabs++);

  2118.       namestring = set_namestring (objfile, &nlist);

  2119.       processing_gcc_compilation = 0;
  2120.       if (nlist.n_type == N_TEXT)
  2121.         {
  2122.           const char *tempstring = namestring;

  2123.           if (strcmp (namestring, GCC_COMPILED_FLAG_SYMBOL) == 0)
  2124.             processing_gcc_compilation = 1;
  2125.           else if (strcmp (namestring, GCC2_COMPILED_FLAG_SYMBOL) == 0)
  2126.             processing_gcc_compilation = 2;
  2127.           if (tempstring[0] == bfd_get_symbol_leading_char (symfile_bfd))
  2128.             ++tempstring;
  2129.           if (strncmp (tempstring, "__gnu_compiled", 14) == 0)
  2130.             processing_gcc_compilation = 2;
  2131.         }
  2132.     }
  2133.   else
  2134.     {
  2135.       /* The N_SO starting this symtab is the first symbol, so we
  2136.          better not check the symbol before it.  I'm not this can
  2137.          happen, but it doesn't hurt to check for it.  */
  2138.       stabs_seek (sym_offset);
  2139.       processing_gcc_compilation = 0;
  2140.     }

  2141.   if (symbuf_idx == symbuf_end)
  2142.     fill_symbuf (abfd);
  2143.   bufp = &symbuf[symbuf_idx];
  2144.   if (bfd_h_get_8 (abfd, bufp->e_type) != N_SO)
  2145.     error (_("First symbol in segment of executable not a source symbol"));

  2146.   max_symnum = sym_size / symbol_size;

  2147.   for (symnum = 0;
  2148.        symnum < max_symnum;
  2149.        symnum++)
  2150.     {
  2151.       QUIT;                        /* Allow this to be interruptable.  */
  2152.       if (symbuf_idx == symbuf_end)
  2153.         fill_symbuf (abfd);
  2154.       bufp = &symbuf[symbuf_idx++];
  2155.       INTERNALIZE_SYMBOL (nlist, bufp, abfd);
  2156.       OBJSTAT (objfile, n_stabs++);

  2157.       type = bfd_h_get_8 (abfd, bufp->e_type);

  2158.       namestring = set_namestring (objfile, &nlist);

  2159.       if (type & N_STAB)
  2160.         {
  2161.           if (sizeof (nlist.n_value) > 4
  2162.               /* We are a 64-bit debugger debugging a 32-bit program.  */
  2163.               && (type == N_LSYM || type == N_PSYM))
  2164.               /* We have to be careful with the n_value in the case of N_LSYM
  2165.                  and N_PSYM entries, because they are signed offsets from frame
  2166.                  pointer, but we actually read them as unsigned 32-bit values.
  2167.                  This is not a problem for 32-bit debuggers, for which negative
  2168.                  values end up being interpreted correctly (as negative
  2169.                  offsets) due to integer overflow.
  2170.                  But we need to sign-extend the value for 64-bit debuggers,
  2171.                  or we'll end up interpreting negative values as very large
  2172.                  positive offsets.  */
  2173.             nlist.n_value = (nlist.n_value ^ 0x80000000) - 0x80000000;
  2174.           process_one_symbol (type, nlist.n_desc, nlist.n_value,
  2175.                               namestring, section_offsets, objfile);
  2176.         }
  2177.       /* We skip checking for a new .o or -l file; that should never
  2178.          happen in this routine.  */
  2179.       else if (type == N_TEXT)
  2180.         {
  2181.           /* I don't think this code will ever be executed, because
  2182.              the GCC_COMPILED_FLAG_SYMBOL usually is right before
  2183.              the N_SO symbol which starts this source file.
  2184.              However, there is no reason not to accept
  2185.              the GCC_COMPILED_FLAG_SYMBOL anywhere.  */

  2186.           if (strcmp (namestring, GCC_COMPILED_FLAG_SYMBOL) == 0)
  2187.             processing_gcc_compilation = 1;
  2188.           else if (strcmp (namestring, GCC2_COMPILED_FLAG_SYMBOL) == 0)
  2189.             processing_gcc_compilation = 2;
  2190.         }
  2191.       else if (type & N_EXT || type == (unsigned char) N_TEXT
  2192.                || type == (unsigned char) N_NBTEXT)
  2193.         {
  2194.           /* Global symbol: see if we came across a dbx defintion for
  2195.              a corresponding symbol.  If so, store the value.  Remove
  2196.              syms from the chain when their values are stored, but
  2197.              search the whole chain, as there may be several syms from
  2198.              different files with the same name.  */
  2199.           /* This is probably not true.  Since the files will be read
  2200.              in one at a time, each reference to a global symbol will
  2201.              be satisfied in each file as it appears.  So we skip this
  2202.              section.  */
  2203.           ;
  2204.         }
  2205.     }

  2206.   /* In a Solaris elf file, this variable, which comes from the
  2207.      value of the N_SO symbol, will still be 0.  Luckily, text_offset,
  2208.      which comes from pst->textlow is correct.  */
  2209.   if (last_source_start_addr == 0)
  2210.     last_source_start_addr = text_offset;

  2211.   /* In reordered executables last_source_start_addr may not be the
  2212.      lower bound for this symtab, instead use text_offset which comes
  2213.      from pst->textlow which is correct.  */
  2214.   if (last_source_start_addr > text_offset)
  2215.     last_source_start_addr = text_offset;

  2216.   pst->compunit_symtab = end_symtab (text_offset + text_size,
  2217.                                      SECT_OFF_TEXT (objfile));

  2218.   end_stabs ();

  2219.   dbxread_objfile = NULL;
  2220. }


  2221. /* Record the namespace that the function defined by SYMBOL was
  2222.    defined in, if necessary.  BLOCK is the associated block; use
  2223.    OBSTACK for allocation.  */

  2224. static void
  2225. cp_set_block_scope (const struct symbol *symbol,
  2226.                     struct block *block,
  2227.                     struct obstack *obstack)
  2228. {
  2229.   if (SYMBOL_DEMANGLED_NAME (symbol) != NULL)
  2230.     {
  2231.       /* Try to figure out the appropriate namespace from the
  2232.          demangled name.  */

  2233.       /* FIXME: carlton/2003-04-15: If the function in question is
  2234.          a method of a class, the name will actually include the
  2235.          name of the class as well.  This should be harmless, but
  2236.          is a little unfortunate.  */

  2237.       const char *name = SYMBOL_DEMANGLED_NAME (symbol);
  2238.       unsigned int prefix_len = cp_entire_prefix_len (name);

  2239.       block_set_scope (block,
  2240.                        obstack_copy0 (obstack, name, prefix_len),
  2241.                        obstack);
  2242.     }
  2243. }

  2244. /* This handles a single symbol from the symbol-file, building symbols
  2245.    into a GDB symtab.  It takes these arguments and an implicit argument.

  2246.    TYPE is the type field of the ".stab" symbol entry.
  2247.    DESC is the desc field of the ".stab" entry.
  2248.    VALU is the value field of the ".stab" entry.
  2249.    NAME is the symbol name, in our address space.
  2250.    SECTION_OFFSETS is a set of amounts by which the sections of this
  2251.    object file were relocated when it was loaded into memory.  Note
  2252.    that these section_offsets are not the objfile->section_offsets but
  2253.    the pst->section_offsets.  All symbols that refer to memory
  2254.    locations need to be offset by these amounts.
  2255.    OBJFILE is the object file from which we are reading symbols.  It
  2256.    is used in end_symtab.  */

  2257. void
  2258. process_one_symbol (int type, int desc, CORE_ADDR valu, char *name,
  2259.                     const struct section_offsets *section_offsets,
  2260.                     struct objfile *objfile)
  2261. {
  2262.   struct gdbarch *gdbarch = get_objfile_arch (objfile);
  2263.   struct context_stack *new;
  2264.   /* This remembers the address of the start of a function.  It is
  2265.      used because in Solaris 2, N_LBRAC, N_RBRAC, and N_SLINE entries
  2266.      are relative to the current function's start address.  On systems
  2267.      other than Solaris 2, this just holds the SECT_OFF_TEXT value,
  2268.      and is used to relocate these symbol types rather than
  2269.      SECTION_OFFSETS.  */
  2270.   static CORE_ADDR function_start_offset;

  2271.   /* This holds the address of the start of a function, without the
  2272.      system peculiarities of function_start_offset.  */
  2273.   static CORE_ADDR last_function_start;

  2274.   /* If this is nonzero, we've seen an N_SLINE since the start of the
  2275.      current function.  We use this to tell us to move the first sline
  2276.      to the beginning of the function regardless of what its given
  2277.      value is.  */
  2278.   static int sline_found_in_function = 1;

  2279.   /* If this is nonzero, we've seen a non-gcc N_OPT symbol for this
  2280.      source file.  Used to detect the SunPRO solaris compiler.  */
  2281.   static int n_opt_found;

  2282.   /* The stab type used for the definition of the last function.
  2283.      N_STSYM or N_GSYM for SunOS4 acc; N_FUN for other compilers.  */
  2284.   static int function_stab_type = 0;

  2285.   if (!block_address_function_relative)
  2286.     {
  2287.       /* N_LBRAC, N_RBRAC and N_SLINE entries are not relative to the
  2288.          function start address, so just use the text offset.  */
  2289.       function_start_offset =
  2290.         ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
  2291.     }

  2292.   /* Something is wrong if we see real data before seeing a source
  2293.      file name.  */

  2294.   if (get_last_source_file () == NULL && type != (unsigned char) N_SO)
  2295.     {
  2296.       /* Ignore any symbols which appear before an N_SO symbol.
  2297.          Currently no one puts symbols there, but we should deal
  2298.          gracefully with the case.  A complain()t might be in order,
  2299.          but this should not be an error ().  */
  2300.       return;
  2301.     }

  2302.   switch (type)
  2303.     {
  2304.     case N_FUN:
  2305.     case N_FNAME:

  2306.       if (*name == '\000')
  2307.         {
  2308.           /* This N_FUN marks the end of a function.  This closes off
  2309.              the current block.  */
  2310.           struct block *block;

  2311.            if (context_stack_depth <= 0)
  2312.              {
  2313.               lbrac_mismatch_complaint (symnum);
  2314.                break;
  2315.              }

  2316.           /* The following check is added before recording line 0 at
  2317.              end of function so as to handle hand-generated stabs
  2318.              which may have an N_FUN stabs at the end of the function,
  2319.              but no N_SLINE stabs.  */
  2320.           if (sline_found_in_function)
  2321.             {
  2322.               CORE_ADDR addr = last_function_start + valu;

  2323.               record_line (current_subfile, 0,
  2324.                            gdbarch_addr_bits_remove (gdbarch, addr));
  2325.             }

  2326.           within_function = 0;
  2327.           new = pop_context ();

  2328.           /* Make a block for the local symbols within.  */
  2329.           block = finish_block (new->name, &local_symbols, new->old_blocks,
  2330.                                 new->start_addr, new->start_addr + valu);

  2331.           /* For C++, set the block's scope.  */
  2332.           if (SYMBOL_LANGUAGE (new->name) == language_cplus)
  2333.             cp_set_block_scope (new->name, block, &objfile->objfile_obstack);

  2334.           /* May be switching to an assembler file which may not be using
  2335.              block relative stabs, so reset the offset.  */
  2336.           if (block_address_function_relative)
  2337.             function_start_offset = 0;

  2338.           break;
  2339.         }

  2340.       sline_found_in_function = 0;

  2341.       /* Relocate for dynamic loading.  */
  2342.       valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
  2343.       valu = gdbarch_addr_bits_remove (gdbarch, valu);
  2344.       last_function_start = valu;

  2345.       goto define_a_symbol;

  2346.     case N_LBRAC:
  2347.       /* This "symbol" just indicates the start of an inner lexical
  2348.          context within a function.  */

  2349.       /* Ignore extra outermost context from SunPRO cc and acc.  */
  2350.       if (n_opt_found && desc == 1)
  2351.         break;

  2352.       if (block_address_function_relative)
  2353.         /* Relocate for Sun ELF acc fn-relative syms.  */
  2354.         valu += function_start_offset;
  2355.       else
  2356.         /* On most machines, the block addresses are relative to the
  2357.            N_SO, the linker did not relocate them (sigh).  */
  2358.         valu += last_source_start_addr;

  2359.       push_context (desc, valu);
  2360.       break;

  2361.     case N_RBRAC:
  2362.       /* This "symbol" just indicates the end of an inner lexical
  2363.          context that was started with N_LBRAC.  */

  2364.       /* Ignore extra outermost context from SunPRO cc and acc.  */
  2365.       if (n_opt_found && desc == 1)
  2366.         break;

  2367.       if (block_address_function_relative)
  2368.         /* Relocate for Sun ELF acc fn-relative syms.  */
  2369.         valu += function_start_offset;
  2370.       else
  2371.         /* On most machines, the block addresses are relative to the
  2372.            N_SO, the linker did not relocate them (sigh).  */
  2373.         valu += last_source_start_addr;

  2374.       if (context_stack_depth <= 0)
  2375.         {
  2376.           lbrac_mismatch_complaint (symnum);
  2377.           break;
  2378.         }

  2379.       new = pop_context ();
  2380.       if (desc != new->depth)
  2381.         lbrac_mismatch_complaint (symnum);

  2382.       if (local_symbols != NULL)
  2383.         {
  2384.           /* GCC development snapshots from March to December of
  2385.              2000 would output N_LSYM entries after N_LBRAC
  2386.              entries.  As a consequence, these symbols are simply
  2387.              discarded.  Complain if this is the case.  */
  2388.           complaint (&symfile_complaints,
  2389.                      _("misplaced N_LBRAC entry; discarding local "
  2390.                        "symbols which have no enclosing block"));
  2391.         }
  2392.       local_symbols = new->locals;

  2393.       if (context_stack_depth > 1)
  2394.         {
  2395.           /* This is not the outermost LBRAC...RBRAC pair in the
  2396.              function, its local symbols preceded it, and are the ones
  2397.              just recovered from the context stack.  Define the block
  2398.              for them (but don't bother if the block contains no
  2399.              symbols.  Should we complain on blocks without symbols?
  2400.              I can't think of any useful purpose for them).  */
  2401.           if (local_symbols != NULL)
  2402.             {
  2403.               /* Muzzle a compiler bug that makes end < start.

  2404.                  ??? Which compilers?  Is this ever harmful?.  */
  2405.               if (new->start_addr > valu)
  2406.                 {
  2407.                   complaint (&symfile_complaints,
  2408.                              _("block start larger than block end"));
  2409.                   new->start_addr = valu;
  2410.                 }
  2411.               /* Make a block for the local symbols within.  */
  2412.               finish_block (0, &local_symbols, new->old_blocks,
  2413.                             new->start_addr, valu);
  2414.             }
  2415.         }
  2416.       else
  2417.         {
  2418.           /* This is the outermost LBRAC...RBRAC pair.  There is no
  2419.              need to do anything; leave the symbols that preceded it
  2420.              to be attached to the function's own block.  We need to
  2421.              indicate that we just moved outside of the function.  */
  2422.           within_function = 0;
  2423.         }

  2424.       break;

  2425.     case N_FN:
  2426.     case N_FN_SEQ:
  2427.       /* This kind of symbol indicates the start of an object file.
  2428.          Relocate for dynamic loading.  */
  2429.       valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
  2430.       break;

  2431.     case N_SO:
  2432.       /* This type of symbol indicates the start of data for one
  2433.          source file.  Finish the symbol table of the previous source
  2434.          file (if any) and start accumulating a new symbol table.
  2435.          Relocate for dynamic loading.  */
  2436.       valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));

  2437.       n_opt_found = 0;

  2438.       if (get_last_source_file ())
  2439.         {
  2440.           /* Check if previous symbol was also an N_SO (with some
  2441.              sanity checks).  If so, that one was actually the
  2442.              directory name, and the current one is the real file
  2443.              name.  Patch things up.  */
  2444.           if (previous_stab_code == (unsigned char) N_SO)
  2445.             {
  2446.               patch_subfile_names (current_subfile, name);
  2447.               break;                /* Ignore repeated SOs.  */
  2448.             }
  2449.           end_symtab (valu, SECT_OFF_TEXT (objfile));
  2450.           end_stabs ();
  2451.         }

  2452.       /* Null name means this just marks the end of text for this .o
  2453.          file.  Don't start a new symtab in this case.  */
  2454.       if (*name == '\000')
  2455.         break;

  2456.       if (block_address_function_relative)
  2457.         function_start_offset = 0;

  2458.       start_stabs ();
  2459.       start_symtab (objfile, name, NULL, valu);
  2460.       record_debugformat ("stabs");
  2461.       break;

  2462.     case N_SOL:
  2463.       /* This type of symbol indicates the start of data for a
  2464.          sub-source-file, one whose contents were copied or included
  2465.          in the compilation of the main source file (whose name was
  2466.          given in the N_SO symbol).  Relocate for dynamic loading.  */
  2467.       valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
  2468.       start_subfile (name);
  2469.       break;

  2470.     case N_BINCL:
  2471.       push_subfile ();
  2472.       add_new_header_file (name, valu);
  2473.       start_subfile (name);
  2474.       break;

  2475.     case N_EINCL:
  2476.       start_subfile (pop_subfile ());
  2477.       break;

  2478.     case N_EXCL:
  2479.       add_old_header_file (name, valu);
  2480.       break;

  2481.     case N_SLINE:
  2482.       /* This type of "symbol" really just records one line-number --
  2483.          core-address correspondence.  Enter it in the line list for
  2484.          this symbol table.  */

  2485.       /* Relocate for dynamic loading and for ELF acc
  2486.          function-relative symbols.  */
  2487.       valu += function_start_offset;

  2488.       /* GCC 2.95.3 emits the first N_SLINE stab somwehere in the
  2489.          middle of the prologue instead of right at the start of the
  2490.          function.  To deal with this we record the address for the
  2491.          first N_SLINE stab to be the start of the function instead of
  2492.          the listed location.  We really shouldn't to this.  When
  2493.          compiling with optimization, this first N_SLINE stab might be
  2494.          optimized away.  Other (non-GCC) compilers don't emit this
  2495.          stab at all.  There is no real harm in having an extra
  2496.          numbered line, although it can be a bit annoying for the
  2497.          user.  However, it totally screws up our testsuite.

  2498.          So for now, keep adjusting the address of the first N_SLINE
  2499.          stab, but only for code compiled with GCC.  */

  2500.       if (within_function && sline_found_in_function == 0)
  2501.         {
  2502.           CORE_ADDR addr = processing_gcc_compilation == 2 ?
  2503.                            last_function_start : valu;

  2504.           record_line (current_subfile, desc,
  2505.                        gdbarch_addr_bits_remove (gdbarch, addr));
  2506.           sline_found_in_function = 1;
  2507.         }
  2508.       else
  2509.         record_line (current_subfile, desc,
  2510.                      gdbarch_addr_bits_remove (gdbarch, valu));
  2511.       break;

  2512.     case N_BCOMM:
  2513.       common_block_start (name, objfile);
  2514.       break;

  2515.     case N_ECOMM:
  2516.       common_block_end (objfile);
  2517.       break;

  2518.       /* The following symbol types need to have the appropriate
  2519.          offset added to their value; then we process symbol
  2520.          definitions in the name.  */

  2521.     case N_STSYM:                /* Static symbol in data segment.  */
  2522.     case N_LCSYM:                /* Static symbol in BSS segment.  */
  2523.     case N_ROSYM:                /* Static symbol in read-only data segment.  */
  2524.       /* HORRID HACK DEPT.  However, it's Sun's furgin' fault.
  2525.          Solaris 2's stabs-in-elf makes *most* symbols relative but
  2526.          leaves a few absolute (at least for Solaris 2.1 and version
  2527.          2.0.1 of the SunPRO compiler).  N_STSYM and friends sit on
  2528.          the fence.  .stab "foo:S...",N_STSYM is absolute (ld
  2529.          relocates it) .stab "foo:V...",N_STSYM is relative (section
  2530.          base subtracted).  This leaves us no choice but to search for
  2531.          the 'S' or 'V'...  (or pass the whole section_offsets stuff
  2532.          down ONE MORE function call level, which we really don't want
  2533.          to do).  */
  2534.       {
  2535.         char *p;

  2536.         /* Normal object file and NLMs have non-zero text seg offsets,
  2537.            but don't need their static syms offset in this fashion.
  2538.            XXX - This is really a crock that should be fixed in the
  2539.            solib handling code so that I don't have to work around it
  2540.            here.  */

  2541.         if (!symfile_relocatable)
  2542.           {
  2543.             p = strchr (name, ':');
  2544.             if (p != 0 && p[1] == 'S')
  2545.               {
  2546.                 /* The linker relocated it.  We don't want to add an
  2547.                    elfstab_offset_sections-type offset, but we *do*
  2548.                    want to add whatever solib.c passed to
  2549.                    symbol_file_add as addr (this is known to affect
  2550.                    SunOS 4, and I suspect ELF too).  Since
  2551.                    elfstab_offset_sections currently does not muck
  2552.                    with the text offset (there is no Ttext.text
  2553.                    symbol), we can get addr from the text offset.  If
  2554.                    elfstab_offset_sections ever starts dealing with
  2555.                    the text offset, and we still need to do this, we
  2556.                    need to invent a SECT_OFF_ADDR_KLUDGE or something.  */
  2557.                 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
  2558.                 goto define_a_symbol;
  2559.               }
  2560.           }
  2561.         /* Since it's not the kludge case, re-dispatch to the right
  2562.            handler.  */
  2563.         switch (type)
  2564.           {
  2565.           case N_STSYM:
  2566.             goto case_N_STSYM;
  2567.           case N_LCSYM:
  2568.             goto case_N_LCSYM;
  2569.           case N_ROSYM:
  2570.             goto case_N_ROSYM;
  2571.           default:
  2572.             internal_error (__FILE__, __LINE__,
  2573.                             _("failed internal consistency check"));
  2574.           }
  2575.       }

  2576.     case_N_STSYM:                /* Static symbol in data segment.  */
  2577.     case N_DSLINE:                /* Source line number, data segment.  */
  2578.       valu += ANOFFSET (section_offsets, SECT_OFF_DATA (objfile));
  2579.       goto define_a_symbol;

  2580.     case_N_LCSYM:                /* Static symbol in BSS segment.  */
  2581.     case N_BSLINE:                /* Source line number, BSS segment.  */
  2582.       /* N_BROWS: overlaps with N_BSLINE.  */
  2583.       valu += ANOFFSET (section_offsets, SECT_OFF_BSS (objfile));
  2584.       goto define_a_symbol;

  2585.     case_N_ROSYM:                /* Static symbol in read-only data segment.  */
  2586.       valu += ANOFFSET (section_offsets, SECT_OFF_RODATA (objfile));
  2587.       goto define_a_symbol;

  2588.     case N_ENTRY:                /* Alternate entry point.  */
  2589.       /* Relocate for dynamic loading.  */
  2590.       valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
  2591.       goto define_a_symbol;

  2592.       /* The following symbol types we don't know how to process.
  2593.          Handle them in a "default" way, but complain to people who
  2594.          care.  */
  2595.     default:
  2596.     case N_CATCH:                /* Exception handler catcher.  */
  2597.     case N_EHDECL:                /* Exception handler name.  */
  2598.     case N_PC:                        /* Global symbol in Pascal.  */
  2599.     case N_M2C:                        /* Modula-2 compilation unit.  */
  2600.       /* N_MOD2: overlaps with N_EHDECL.  */
  2601.     case N_SCOPE:                /* Modula-2 scope information.  */
  2602.     case N_ECOML:                /* End common (local name).  */
  2603.     case N_NBTEXT:                /* Gould Non-Base-Register symbols???  */
  2604.     case N_NBDATA:
  2605.     case N_NBBSS:
  2606.     case N_NBSTS:
  2607.     case N_NBLCS:
  2608.       unknown_symtype_complaint (hex_string (type));
  2609.       /* FALLTHROUGH */

  2610.       /* The following symbol types don't need the address field
  2611.          relocated, since it is either unused, or is absolute.  */
  2612.     define_a_symbol:
  2613.     case N_GSYM:                /* Global variable.  */
  2614.     case N_NSYMS:                /* Number of symbols (Ultrix).  */
  2615.     case N_NOMAP:                /* No map?  (Ultrix).  */
  2616.     case N_RSYM:                /* Register variable.  */
  2617.     case N_DEFD:                /* Modula-2 GNU module dependency.  */
  2618.     case N_SSYM:                /* Struct or union element.  */
  2619.     case N_LSYM:                /* Local symbol in stack.  */
  2620.     case N_PSYM:                /* Parameter variable.  */
  2621.     case N_LENG:                /* Length of preceding symbol type.  */
  2622.       if (name)
  2623.         {
  2624.           int deftype;
  2625.           char *colon_pos = strchr (name, ':');

  2626.           if (colon_pos == NULL)
  2627.             deftype = '\0';
  2628.           else
  2629.             deftype = colon_pos[1];

  2630.           switch (deftype)
  2631.             {
  2632.             case 'f':
  2633.             case 'F':
  2634.               function_stab_type = type;

  2635.               /* Deal with the SunPRO 3.0 compiler which omits the
  2636.                  address from N_FUN symbols.  */
  2637.               if (type == N_FUN
  2638.                   && valu == ANOFFSET (section_offsets,
  2639.                                        SECT_OFF_TEXT (objfile))
  2640.                   && gdbarch_sofun_address_maybe_missing (gdbarch))
  2641.                 {
  2642.                   CORE_ADDR minsym_valu =
  2643.                     find_stab_function_addr (name, get_last_source_file (),
  2644.                                              objfile);

  2645.                   /* The function find_stab_function_addr will return
  2646.                      0 if the minimal symbol wasn't found.
  2647.                      (Unfortunately, this might also be a valid
  2648.                      address.)  Anyway, if it *does* return 0, it is
  2649.                      likely that the value was set correctly to begin
  2650.                      with...  */
  2651.                   if (minsym_valu != 0)
  2652.                     valu = minsym_valu;
  2653.                 }

  2654.               if (block_address_function_relative)
  2655.                 /* For Solaris 2 compilers, the block addresses and
  2656.                    N_SLINE's are relative to the start of the
  2657.                    function.  On normal systems, and when using GCC on
  2658.                    Solaris 2, these addresses are just absolute, or
  2659.                    relative to the N_SO, depending on
  2660.                    BLOCK_ADDRESS_ABSOLUTE.  */
  2661.                 function_start_offset = valu;

  2662.               within_function = 1;

  2663.               if (context_stack_depth > 1)
  2664.                 {
  2665.                   complaint (&symfile_complaints,
  2666.                              _("unmatched N_LBRAC before symtab pos %d"),
  2667.                              symnum);
  2668.                   break;
  2669.                 }

  2670.               if (context_stack_depth > 0)
  2671.                 {
  2672.                   struct block *block;

  2673.                   new = pop_context ();
  2674.                   /* Make a block for the local symbols within.  */
  2675.                   block = finish_block (new->name, &local_symbols,
  2676.                                         new->old_blocks, new->start_addr,
  2677.                                         valu);

  2678.                   /* For C++, set the block's scope.  */
  2679.                   if (SYMBOL_LANGUAGE (new->name) == language_cplus)
  2680.                     cp_set_block_scope (new->name, block,
  2681.                                         &objfile->objfile_obstack);
  2682.                 }

  2683.               new = push_context (0, valu);
  2684.               new->name = define_symbol (valu, name, desc, type, objfile);
  2685.               break;

  2686.             default:
  2687.               define_symbol (valu, name, desc, type, objfile);
  2688.               break;
  2689.             }
  2690.         }
  2691.       break;

  2692.       /* We use N_OPT to carry the gcc2_compiled flag.  Sun uses it
  2693.          for a bunch of other flags, too.  Someday we may parse their
  2694.          flags; for now we ignore theirs and hope they'll ignore ours.  */
  2695.     case N_OPT:                        /* Solaris 2: Compiler options.  */
  2696.       if (name)
  2697.         {
  2698.           if (strcmp (name, GCC2_COMPILED_FLAG_SYMBOL) == 0)
  2699.             {
  2700.               processing_gcc_compilation = 2;
  2701.             }
  2702.           else
  2703.             n_opt_found = 1;
  2704.         }
  2705.       break;

  2706.     case N_MAIN:                /* Name of main routine.  */
  2707.       /* FIXME: If one has a symbol file with N_MAIN and then replaces
  2708.          it with a symbol file with "main" and without N_MAIN.  I'm
  2709.          not sure exactly what rule to follow but probably something
  2710.          like: N_MAIN takes precedence over "main" no matter what
  2711.          objfile it is in; If there is more than one N_MAIN, choose
  2712.          the one in the symfile_objfile; If there is more than one
  2713.          N_MAIN within a given objfile, complain() and choose
  2714.          arbitrarily.  (kingdon) */
  2715.       if (name != NULL)
  2716.         set_objfile_main_name (objfile, name, language_unknown);
  2717.       break;

  2718.       /* The following symbol types can be ignored.  */
  2719.     case N_OBJ:                        /* Solaris 2: Object file dir and name.  */
  2720.     case N_PATCH:                /* Solaris 2: Patch Run Time Checker.  */
  2721.       /* N_UNDF:                   Solaris 2: File separator mark.  */
  2722.       /* N_UNDF: -- we will never encounter it, since we only process
  2723.          one file's symbols at once.  */
  2724.     case N_ENDM:                /* Solaris 2: End of module.  */
  2725.     case N_ALIAS:                /* SunPro F77: alias name, ignore for now.  */
  2726.       break;
  2727.     }

  2728.   /* '#' is a GNU C extension to allow one symbol to refer to another
  2729.      related symbol.

  2730.      Generally this is used so that an alias can refer to its main
  2731.      symbol.  */
  2732.   gdb_assert (name);
  2733.   if (name[0] == '#')
  2734.     {
  2735.       /* Initialize symbol reference names and determine if this is a
  2736.          definition.  If a symbol reference is being defined, go ahead
  2737.          and add it.  Otherwise, just return.  */

  2738.       char *s = name;
  2739.       int refnum;

  2740.       /* If this stab defines a new reference ID that is not on the
  2741.          reference list, then put it on the reference list.

  2742.          We go ahead and advance NAME past the reference, even though
  2743.          it is not strictly necessary at this time.  */
  2744.       refnum = symbol_reference_defined (&s);
  2745.       if (refnum >= 0)
  2746.         if (!ref_search (refnum))
  2747.           ref_add (refnum, 0, name, valu);
  2748.       name = s;
  2749.     }

  2750.   previous_stab_code = type;
  2751. }

  2752. /* FIXME: The only difference between this and elfstab_build_psymtabs
  2753.    is the call to install_minimal_symbols for elf, and the support for
  2754.    split sections.  If the differences are really that small, the code
  2755.    should be shared.  */

  2756. /* Scan and build partial symbols for an coff symbol file.
  2757.    The coff file has already been processed to get its minimal symbols.

  2758.    This routine is the equivalent of dbx_symfile_init and dbx_symfile_read
  2759.    rolled into one.

  2760.    OBJFILE is the object file we are reading symbols from.
  2761.    ADDR is the address relative to which the symbols are (e.g.
  2762.    the base address of the text segment).
  2763.    TEXTADDR is the address of the text section.
  2764.    TEXTSIZE is the size of the text section.
  2765.    STABSECTS is the list of .stab sections in OBJFILE.
  2766.    STABSTROFFSET and STABSTRSIZE define the location in OBJFILE where the
  2767.    .stabstr section exists.

  2768.    This routine is mostly copied from dbx_symfile_init and dbx_symfile_read,
  2769.    adjusted for coff details.  */

  2770. void
  2771. coffstab_build_psymtabs (struct objfile *objfile,
  2772.                          CORE_ADDR textaddr, unsigned int textsize,
  2773.                          struct stab_section_list *stabsects,
  2774.                          file_ptr stabstroffset, unsigned int stabstrsize)
  2775. {
  2776.   int val;
  2777.   bfd *sym_bfd = objfile->obfd;
  2778.   char *name = bfd_get_filename (sym_bfd);
  2779.   struct dbx_symfile_info *info;
  2780.   unsigned int stabsize;

  2781.   /* There is already a dbx_symfile_info allocated by our caller.
  2782.      It might even contain some info from the coff symtab to help us.  */
  2783.   info = DBX_SYMFILE_INFO (objfile);

  2784.   DBX_TEXT_ADDR (objfile) = textaddr;
  2785.   DBX_TEXT_SIZE (objfile) = textsize;

  2786. #define        COFF_STABS_SYMBOL_SIZE        12        /* XXX FIXME XXX */
  2787.   DBX_SYMBOL_SIZE (objfile) = COFF_STABS_SYMBOL_SIZE;
  2788.   DBX_STRINGTAB_SIZE (objfile) = stabstrsize;

  2789.   if (stabstrsize > bfd_get_size (sym_bfd))
  2790.     error (_("ridiculous string table size: %d bytes"), stabstrsize);
  2791.   DBX_STRINGTAB (objfile) = (char *)
  2792.     obstack_alloc (&objfile->objfile_obstack, stabstrsize + 1);
  2793.   OBJSTAT (objfile, sz_strtab += stabstrsize + 1);

  2794.   /* Now read in the string table in one big gulp.  */

  2795.   val = bfd_seek (sym_bfd, stabstroffset, SEEK_SET);
  2796.   if (val < 0)
  2797.     perror_with_name (name);
  2798.   val = bfd_bread (DBX_STRINGTAB (objfile), stabstrsize, sym_bfd);
  2799.   if (val != stabstrsize)
  2800.     perror_with_name (name);

  2801.   stabsread_new_init ();
  2802.   buildsym_new_init ();
  2803.   free_header_files ();
  2804.   init_header_files ();

  2805.   processing_acc_compilation = 1;

  2806.   /* In a coff file, we've already installed the minimal symbols that came
  2807.      from the coff (non-stab) symbol table, so always act like an
  2808.      incremental load here.  */
  2809.   if (stabsects->next == NULL)
  2810.     {
  2811.       stabsize = bfd_section_size (sym_bfd, stabsects->section);
  2812.       DBX_SYMCOUNT (objfile) = stabsize / DBX_SYMBOL_SIZE (objfile);
  2813.       DBX_SYMTAB_OFFSET (objfile) = stabsects->section->filepos;
  2814.     }
  2815.   else
  2816.     {
  2817.       struct stab_section_list *stabsect;

  2818.       DBX_SYMCOUNT (objfile) = 0;
  2819.       for (stabsect = stabsects; stabsect != NULL; stabsect = stabsect->next)
  2820.         {
  2821.           stabsize = bfd_section_size (sym_bfd, stabsect->section);
  2822.           DBX_SYMCOUNT (objfile) += stabsize / DBX_SYMBOL_SIZE (objfile);
  2823.         }

  2824.       DBX_SYMTAB_OFFSET (objfile) = stabsects->section->filepos;

  2825.       symbuf_sections = stabsects->next;
  2826.       symbuf_left = bfd_section_size (sym_bfd, stabsects->section);
  2827.       symbuf_read = 0;
  2828.     }

  2829.   dbx_symfile_read (objfile, 0);
  2830. }

  2831. /* Scan and build partial symbols for an ELF symbol file.
  2832.    This ELF file has already been processed to get its minimal symbols.

  2833.    This routine is the equivalent of dbx_symfile_init and dbx_symfile_read
  2834.    rolled into one.

  2835.    OBJFILE is the object file we are reading symbols from.
  2836.    ADDR is the address relative to which the symbols are (e.g.
  2837.    the base address of the text segment).
  2838.    STABSECT is the BFD section information for the .stab section.
  2839.    STABSTROFFSET and STABSTRSIZE define the location in OBJFILE where the
  2840.    .stabstr section exists.

  2841.    This routine is mostly copied from dbx_symfile_init and dbx_symfile_read,
  2842.    adjusted for elf details.  */

  2843. void
  2844. elfstab_build_psymtabs (struct objfile *objfile, asection *stabsect,
  2845.                         file_ptr stabstroffset, unsigned int stabstrsize)
  2846. {
  2847.   int val;
  2848.   bfd *sym_bfd = objfile->obfd;
  2849.   char *name = bfd_get_filename (sym_bfd);
  2850.   struct dbx_symfile_info *info;
  2851.   struct cleanup *back_to = make_cleanup (null_cleanup, NULL);

  2852.   /* There is already a dbx_symfile_info allocated by our caller.
  2853.      It might even contain some info from the ELF symtab to help us.  */
  2854.   info = DBX_SYMFILE_INFO (objfile);

  2855.   /* Find the first and last text addressdbx_symfile_read seems to
  2856.      want this.  */
  2857.   find_text_range (sym_bfd, objfile);

  2858. #define        ELF_STABS_SYMBOL_SIZE        12        /* XXX FIXME XXX */
  2859.   DBX_SYMBOL_SIZE (objfile) = ELF_STABS_SYMBOL_SIZE;
  2860.   DBX_SYMCOUNT (objfile)
  2861.     = bfd_section_size (objfile->obfd, stabsect) / DBX_SYMBOL_SIZE (objfile);
  2862.   DBX_STRINGTAB_SIZE (objfile) = stabstrsize;
  2863.   DBX_SYMTAB_OFFSET (objfile) = stabsect->filepos;
  2864.   DBX_STAB_SECTION (objfile) = stabsect;

  2865.   if (stabstrsize > bfd_get_size (sym_bfd))
  2866.     error (_("ridiculous string table size: %d bytes"), stabstrsize);
  2867.   DBX_STRINGTAB (objfile) = (char *)
  2868.     obstack_alloc (&objfile->objfile_obstack, stabstrsize + 1);
  2869.   OBJSTAT (objfile, sz_strtab += stabstrsize + 1);

  2870.   /* Now read in the string table in one big gulp.  */

  2871.   val = bfd_seek (sym_bfd, stabstroffset, SEEK_SET);
  2872.   if (val < 0)
  2873.     perror_with_name (name);
  2874.   val = bfd_bread (DBX_STRINGTAB (objfile), stabstrsize, sym_bfd);
  2875.   if (val != stabstrsize)
  2876.     perror_with_name (name);

  2877.   stabsread_new_init ();
  2878.   buildsym_new_init ();
  2879.   free_header_files ();
  2880.   init_header_files ();

  2881.   processing_acc_compilation = 1;

  2882.   symbuf_read = 0;
  2883.   symbuf_left = bfd_section_size (objfile->obfd, stabsect);
  2884.   stabs_data = symfile_relocate_debug_section (objfile, stabsect, NULL);
  2885.   if (stabs_data)
  2886.     make_cleanup (free_current_contents, (void *) &stabs_data);

  2887.   /* In an elf file, we've already installed the minimal symbols that came
  2888.      from the elf (non-stab) symbol table, so always act like an
  2889.      incremental load here.  dbx_symfile_read should not generate any new
  2890.      minimal symbols, since we will have already read the ELF dynamic symbol
  2891.      table and normal symbol entries won't be in the ".stab" section; but in
  2892.      case it does, it will install them itself.  */
  2893.   dbx_symfile_read (objfile, 0);

  2894.   do_cleanups (back_to);
  2895. }

  2896. /* Scan and build partial symbols for a file with special sections for stabs
  2897.    and stabstrings.  The file has already been processed to get its minimal
  2898.    symbols, and any other symbols that might be necessary to resolve GSYMs.

  2899.    This routine is the equivalent of dbx_symfile_init and dbx_symfile_read
  2900.    rolled into one.

  2901.    OBJFILE is the object file we are reading symbols from.
  2902.    ADDR is the address relative to which the symbols are (e.g. the base address
  2903.    of the text segment).
  2904.    STAB_NAME is the name of the section that contains the stabs.
  2905.    STABSTR_NAME is the name of the section that contains the stab strings.

  2906.    This routine is mostly copied from dbx_symfile_init and
  2907.    dbx_symfile_read.  */

  2908. void
  2909. stabsect_build_psymtabs (struct objfile *objfile, char *stab_name,
  2910.                          char *stabstr_name, char *text_name)
  2911. {
  2912.   int val;
  2913.   bfd *sym_bfd = objfile->obfd;
  2914.   char *name = bfd_get_filename (sym_bfd);
  2915.   asection *stabsect;
  2916.   asection *stabstrsect;
  2917.   asection *text_sect;
  2918.   struct dbx_symfile_info *dbx;

  2919.   stabsect = bfd_get_section_by_name (sym_bfd, stab_name);
  2920.   stabstrsect = bfd_get_section_by_name (sym_bfd, stabstr_name);

  2921.   if (!stabsect)
  2922.     return;

  2923.   if (!stabstrsect)
  2924.     error (_("stabsect_build_psymtabs:  Found stabs (%s), "
  2925.              "but not string section (%s)"),
  2926.            stab_name, stabstr_name);

  2927.   dbx = XCNEW (struct dbx_symfile_info);
  2928.   set_objfile_data (objfile, dbx_objfile_data_key, dbx);

  2929.   text_sect = bfd_get_section_by_name (sym_bfd, text_name);
  2930.   if (!text_sect)
  2931.     error (_("Can't find %s section in symbol file"), text_name);
  2932.   DBX_TEXT_ADDR (objfile) = bfd_section_vma (sym_bfd, text_sect);
  2933.   DBX_TEXT_SIZE (objfile) = bfd_section_size (sym_bfd, text_sect);

  2934.   DBX_SYMBOL_SIZE (objfile) = sizeof (struct external_nlist);
  2935.   DBX_SYMCOUNT (objfile) = bfd_section_size (sym_bfd, stabsect)
  2936.     / DBX_SYMBOL_SIZE (objfile);
  2937.   DBX_STRINGTAB_SIZE (objfile) = bfd_section_size (sym_bfd, stabstrsect);
  2938.   DBX_SYMTAB_OFFSET (objfile) = stabsect->filepos;        /* XXX - FIXME: POKING
  2939.                                                            INSIDE BFD DATA
  2940.                                                            STRUCTURES */

  2941.   if (DBX_STRINGTAB_SIZE (objfile) > bfd_get_size (sym_bfd))
  2942.     error (_("ridiculous string table size: %d bytes"),
  2943.            DBX_STRINGTAB_SIZE (objfile));
  2944.   DBX_STRINGTAB (objfile) = (char *)
  2945.     obstack_alloc (&objfile->objfile_obstack,
  2946.                    DBX_STRINGTAB_SIZE (objfile) + 1);
  2947.   OBJSTAT (objfile, sz_strtab += DBX_STRINGTAB_SIZE (objfile) + 1);

  2948.   /* Now read in the string table in one big gulp.  */

  2949.   val = bfd_get_section_contents (sym_bfd,        /* bfd */
  2950.                                   stabstrsect,        /* bfd section */
  2951.                                   DBX_STRINGTAB (objfile), /* input buffer */
  2952.                                   0,                /* offset into section */
  2953.                                   DBX_STRINGTAB_SIZE (objfile)); /* amount to
  2954.                                                                     read */

  2955.   if (!val)
  2956.     perror_with_name (name);

  2957.   stabsread_new_init ();
  2958.   buildsym_new_init ();
  2959.   free_header_files ();
  2960.   init_header_files ();

  2961.   /* Now, do an incremental load.  */

  2962.   processing_acc_compilation = 1;
  2963.   dbx_symfile_read (objfile, 0);
  2964. }

  2965. static const struct sym_fns aout_sym_fns =
  2966. {
  2967.   dbx_new_init,                        /* init anything gbl to entire symtab */
  2968.   dbx_symfile_init,                /* read initial info, setup for sym_read() */
  2969.   dbx_symfile_read,                /* read a symbol file into symtab */
  2970.   NULL,                                /* sym_read_psymbols */
  2971.   dbx_symfile_finish,                /* finished with file, cleanup */
  2972.   default_symfile_offsets,         /* parse user's offsets to internal form */
  2973.   default_symfile_segments,        /* Get segment information from a file.  */
  2974.   NULL,
  2975.   default_symfile_relocate,        /* Relocate a debug section.  */
  2976.   NULL,                                /* sym_probe_fns */
  2977.   &psym_functions
  2978. };

  2979. void
  2980. _initialize_dbxread (void)
  2981. {
  2982.   add_symtab_fns (bfd_target_aout_flavour, &aout_sym_fns);

  2983.   dbx_objfile_data_key
  2984.     = register_objfile_data_with_cleanup (NULL, dbx_free_symfile_info);
  2985. }