[2/5] gdb: Move process_one_symbol to stabsread.c

Message ID 20240917154018.3376944-3-blarsen@redhat.com
State New
Headers
Series Disentangle dbxread from other file format readers |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Test passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm fail Patch failed to apply

Commit Message

Guinevere Larsen Sept. 17, 2024, 3:40 p.m. UTC
  The function process_one_symbol was defined in the file dbxread.c, but
this function is used by all file formats that handle stabs debug
information. It makes much more sense for it to be in the stabsread.c
file instead.

To move that function, many other static functions had to be moved from
dbxread. A few were only used by process_one_symbol, so they're still
static, but most were used by other functions still in dbxread, so they
are being exported by stabsread.h

Finally, the registry key has been moved to stabsread as well, since it
is already used by other file formats and stabsread will start using it
in several functions. This is important to fully disentangle file format
readers.

With this change, reading mdebug file reading is totally independent of
reading dbx.
---
 gdb/dbxread.c   | 804 ------------------------------------------------
 gdb/gdb-stabs.h |  22 ++
 gdb/stabsread.c | 762 +++++++++++++++++++++++++++++++++++++++++++++
 gdb/stabsread.h |  36 +++
 4 files changed, 820 insertions(+), 804 deletions(-)
  

Patch

diff --git a/gdb/dbxread.c b/gdb/dbxread.c
index c8a33040208..ceb2a3e79db 100644
--- a/gdb/dbxread.c
+++ b/gdb/dbxread.c
@@ -57,10 +57,6 @@ 
 /* Required for the following registry.  */
 #include "gdb-stabs.h"
 
-/* Key for dbx-associated data.  */
-
-const registry<objfile>::key<dbx_symfile_info> dbx_objfile_data_key;
-
 /* We put a pointer to this structure in the read_symtab_private field
    of the psymtab.  */
 
@@ -102,28 +98,6 @@  struct symloc
 #define PST_LANGUAGE(p) (SYMLOC(p)->pst_language)
 
 
-/* Complaints about the symbols we have encountered.  */
-
-static void
-unknown_symtype_complaint (const char *arg1)
-{
-  complaint (_("unknown symbol type %s"), arg1);
-}
-
-static void
-lbrac_mismatch_complaint (int arg1)
-{
-  complaint (_("N_LBRAC/N_RBRAC symbol mismatch at symtab pos %d"), arg1);
-}
-
-static void
-repeated_header_complaint (const char *arg1, int arg2)
-{
-  complaint (_("\"repeated\" header file %s not "
-	       "previously seen, at symtab pos %d"),
-	     arg1, arg2);
-}
-
 /* find_text_range --- find start and end of loadable code sections
 
    The find_text_range function finds the shortest address range that
@@ -172,27 +146,6 @@  find_text_range (bfd * sym_bfd, struct objfile *objfile)
 
 
 
-/* During initial symbol readin, we need to have a structure to keep
-   track of which psymtabs have which bincls in them.  This structure
-   is used during readin to setup the list of dependencies within each
-   partial symbol table.  */
-
-struct header_file_location
-{
-  header_file_location (const char *name_, int instance_,
-			legacy_psymtab *pst_)
-    : name (name_),
-      instance (instance_),
-      pst (pst_)
-  {
-  }
-
-  const char *name;		/* Name of header file */
-  int instance;			/* See above */
-  legacy_psymtab *pst;	/* Partial symtab that has the
-				   BINCL/EINCL defs for this file.  */
-};
-
 /* Local function prototypes.  */
 
 static void read_ofile_symtab (struct objfile *, legacy_psymtab *);
@@ -225,12 +178,6 @@  static void record_minimal_symbol (minimal_symbol_reader &,
 				   const char *, unrelocated_addr, int,
 				   struct objfile *);
 
-static void add_new_header_file (const char *, int, struct objfile *);
-
-static void add_old_header_file (const char *, int, struct objfile *);
-
-static void add_this_object_header_file (int);
-
 static legacy_psymtab *start_psymtab (psymtab_storage *, struct objfile *,
 				      const char *, unrelocated_addr, int);
 
@@ -256,94 +203,6 @@  init_header_files (void)
   this_object_header_files = XNEWVEC (int, 10);
 }
 
-/* Add header file number I for this object file
-   at the next successive FILENUM.  */
-
-static void
-add_this_object_header_file (int i)
-{
-  if (n_this_object_header_files == n_allocated_this_object_header_files)
-    {
-      n_allocated_this_object_header_files *= 2;
-      this_object_header_files
-	= (int *) xrealloc ((char *) this_object_header_files,
-		       n_allocated_this_object_header_files * sizeof (int));
-    }
-
-  this_object_header_files[n_this_object_header_files++] = i;
-}
-
-/* Add to this file an "old" header file, one already seen in
-   a previous object file.  NAME is the header file's name.
-   INSTANCE is its instance code, to select among multiple
-   symbol tables for the same header file.  */
-
-static void
-add_old_header_file (const char *name, int instance, struct objfile *objfile)
-{
-  struct header_file *p = HEADER_FILES (objfile);
-  int i;
-
-  for (i = 0; i < N_HEADER_FILES (objfile); i++)
-    if (filename_cmp (p[i].name, name) == 0 && instance == p[i].instance)
-      {
-	add_this_object_header_file (i);
-	return;
-      }
-  repeated_header_complaint (name, symnum);
-}
-
-/* Add to this file a "new" header file: definitions for its types follow.
-   NAME is the header file's name.
-   Most often this happens only once for each distinct header file,
-   but not necessarily.  If it happens more than once, INSTANCE has
-   a different value each time, and references to the header file
-   use INSTANCE values to select among them.
-
-   dbx output contains "begin" and "end" markers for each new header file,
-   but at this level we just need to know which files there have been;
-   so we record the file when its "begin" is seen and ignore the "end".  */
-
-static void
-add_new_header_file (const char *name, int instance, struct objfile *objfile)
-{
-  int i;
-  struct header_file *hfile;
-
-  /* Make sure there is room for one more header file.  */
-
-  i = N_ALLOCATED_HEADER_FILES (objfile);
-
-  if (N_HEADER_FILES (objfile) == i)
-    {
-      if (i == 0)
-	{
-	  N_ALLOCATED_HEADER_FILES (objfile) = 10;
-	  HEADER_FILES (objfile) = (struct header_file *)
-	    xmalloc (10 * sizeof (struct header_file));
-	}
-      else
-	{
-	  i *= 2;
-	  N_ALLOCATED_HEADER_FILES (objfile) = i;
-	  HEADER_FILES (objfile) = (struct header_file *)
-	    xrealloc ((char *) HEADER_FILES (objfile),
-		      (i * sizeof (struct header_file)));
-	}
-    }
-
-  /* Create an entry for this header file.  */
-
-  i = N_HEADER_FILES (objfile)++;
-  hfile = HEADER_FILES (objfile) + i;
-  hfile->name = xstrdup (name);
-  hfile->instance = instance;
-  hfile->length = 10;
-  hfile->vector = XCNEWVEC (struct type *, 10);
-
-  add_this_object_header_file (i);
-}
-
 #if 0
 static struct type **
 explicit_lookup_type (int real_filenum, int index)
@@ -638,22 +497,6 @@  dbx_symfile_finish (struct objfile *objfile)
   free_header_files ();
 }
 
-dbx_symfile_info::~dbx_symfile_info ()
-{
-  if (header_files != NULL)
-    {
-      int i = n_header_files;
-      struct header_file *hfiles = header_files;
-
-      while (--i >= 0)
-	{
-	  xfree (hfiles[i].name);
-	  xfree (hfiles[i].vector);
-	}
-      xfree (hfiles);
-    }
-}
-
 
 
 /* Buffer for reading the symbol table entries.  */
@@ -812,52 +655,6 @@  set_namestring (struct objfile *objfile, const struct internal_nlist *nlist)
   return namestring;
 }
 
-static bound_minimal_symbol
-find_stab_function (const char *namestring, const char *filename,
-		    struct objfile *objfile)
-{
-  int n;
-
-  const char *colon = strchr (namestring, ':');
-  if (colon == NULL)
-    n = 0;
-  else
-    n = colon - namestring;
-
-  char *p = (char *) alloca (n + 2);
-  strncpy (p, namestring, n);
-  p[n] = 0;
-
-  bound_minimal_symbol msym
-    = lookup_minimal_symbol (current_program_space, p, objfile, filename);
-  if (msym.minsym == NULL)
-    {
-      /* Sun Fortran appends an underscore to the minimal symbol name,
-	 try again with an appended underscore if the minimal symbol
-	 was not found.  */
-      p[n] = '_';
-      p[n + 1] = 0;
-      msym
-	= lookup_minimal_symbol (current_program_space, p, objfile, filename);
-    }
-
-  if (msym.minsym == NULL && filename != NULL)
-    {
-      /* Try again without the filename.  */
-      p[n] = 0;
-      msym = lookup_minimal_symbol (current_program_space, p, objfile);
-    }
-  if (msym.minsym == NULL && filename != NULL)
-    {
-      /* And try again for Sun Fortran, but without the filename.  */
-      p[n] = '_';
-      p[n + 1] = 0;
-      msym = lookup_minimal_symbol (current_program_space, p, objfile);
-    }
-
-  return msym;
-}
-
 static void
 function_outside_compilation_unit_complaint (const char *arg1)
 {
@@ -2287,607 +2084,6 @@  read_ofile_symtab (struct objfile *objfile, legacy_psymtab *pst)
 
 }
 
-
-/* Record the namespace that the function defined by SYMBOL was
-   defined in, if necessary.  BLOCK is the associated block; use
-   OBSTACK for allocation.  */
-
-static void
-cp_set_block_scope (const struct symbol *symbol,
-		    struct block *block,
-		    struct obstack *obstack)
-{
-  if (symbol->demangled_name () != NULL)
-    {
-      /* Try to figure out the appropriate namespace from the
-	 demangled name.  */
-
-      /* FIXME: carlton/2003-04-15: If the function in question is
-	 a method of a class, the name will actually include the
-	 name of the class as well.  This should be harmless, but
-	 is a little unfortunate.  */
-
-      const char *name = symbol->demangled_name ();
-      unsigned int prefix_len = cp_entire_prefix_len (name);
-
-      block->set_scope (obstack_strndup (obstack, name, prefix_len),
-			obstack);
-    }
-}
-
-/* This handles a single symbol from the symbol-file, building symbols
-   into a GDB symtab.  It takes these arguments and an implicit argument.
-
-   TYPE is the type field of the ".stab" symbol entry.
-   DESC is the desc field of the ".stab" entry.
-   VALU is the value field of the ".stab" entry.
-   NAME is the symbol name, in our address space.
-   SECTION_OFFSETS is a set of amounts by which the sections of this
-   object file were relocated when it was loaded into memory.  Note
-   that these section_offsets are not the objfile->section_offsets but
-   the pst->section_offsets.  All symbols that refer to memory
-   locations need to be offset by these amounts.
-   OBJFILE is the object file from which we are reading symbols.  It
-   is used in end_compunit_symtab.
-   LANGUAGE is the language of the symtab.
-*/
-
-void
-process_one_symbol (int type, int desc, CORE_ADDR valu, const char *name,
-		    const section_offsets &section_offsets,
-		    struct objfile *objfile, enum language language)
-{
-  struct gdbarch *gdbarch = objfile->arch ();
-  struct context_stack *newobj;
-  struct context_stack cstk;
-  /* This remembers the address of the start of a function.  It is
-     used because in Solaris 2, N_LBRAC, N_RBRAC, and N_SLINE entries
-     are relative to the current function's start address.  On systems
-     other than Solaris 2, this just holds the SECT_OFF_TEXT value,
-     and is used to relocate these symbol types rather than
-     SECTION_OFFSETS.  */
-  static CORE_ADDR function_start_offset;
-
-  /* This holds the address of the start of a function, without the
-     system peculiarities of function_start_offset.  */
-  static CORE_ADDR last_function_start;
-
-  /* If this is nonzero, we've seen an N_SLINE since the start of the
-     current function.  We use this to tell us to move the first sline
-     to the beginning of the function regardless of what its given
-     value is.  */
-  static int sline_found_in_function = 1;
-
-  /* If this is nonzero, we've seen a non-gcc N_OPT symbol for this
-     source file.  Used to detect the SunPRO solaris compiler.  */
-  static int n_opt_found;
-
-  /* The section index for this symbol.  */
-  int section_index = -1;
-
-  struct dbx_symfile_info *key = dbx_objfile_data_key.get (objfile);
-
-  /* Something is wrong if we see real data before seeing a source
-     file name.  */
-
-  if (get_last_source_file () == NULL && type != (unsigned char) N_SO)
-    {
-      /* Ignore any symbols which appear before an N_SO symbol.
-	 Currently no one puts symbols there, but we should deal
-	 gracefully with the case.  A complain()t might be in order,
-	 but this should not be an error ().  */
-      return;
-    }
-
-  switch (type)
-    {
-    case N_FUN:
-    case N_FNAME:
-
-      if (*name == '\000')
-	{
-	  /* This N_FUN marks the end of a function.  This closes off
-	     the current block.  */
-	  struct block *block;
-
-	  if (outermost_context_p ())
-	    {
-	      lbrac_mismatch_complaint (symnum);
-	      break;
-	    }
-
-	  /* The following check is added before recording line 0 at
-	     end of function so as to handle hand-generated stabs
-	     which may have an N_FUN stabs at the end of the function,
-	     but no N_SLINE stabs.  */
-	  if (sline_found_in_function)
-	    {
-	      CORE_ADDR addr = last_function_start + valu;
-
-	      record_line
-		(get_current_subfile (), 0,
-		 unrelocated_addr (gdbarch_addr_bits_remove (gdbarch, addr)
-				   - objfile->text_section_offset ()));
-	    }
-
-	  within_function = 0;
-	  cstk = pop_context ();
-
-	  /* Make a block for the local symbols within.  */
-	  block = finish_block (cstk.name,
-				cstk.old_blocks, NULL,
-				cstk.start_addr, cstk.start_addr + valu);
-
-	  /* For C++, set the block's scope.  */
-	  if (cstk.name->language () == language_cplus)
-	    cp_set_block_scope (cstk.name, block, &objfile->objfile_obstack);
-
-	  /* May be switching to an assembler file which may not be using
-	     block relative stabs, so reset the offset.  */
-	  function_start_offset = 0;
-
-	  break;
-	}
-
-      sline_found_in_function = 0;
-
-      /* Relocate for dynamic loading.  */
-      section_index = SECT_OFF_TEXT (objfile);
-      valu += section_offsets[SECT_OFF_TEXT (objfile)];
-      valu = gdbarch_addr_bits_remove (gdbarch, valu);
-      last_function_start = valu;
-
-      goto define_a_symbol;
-
-    case N_LBRAC:
-      /* This "symbol" just indicates the start of an inner lexical
-	 context within a function.  */
-
-      /* Ignore extra outermost context from SunPRO cc and acc.  */
-      if (n_opt_found && desc == 1)
-	break;
-
-      valu += function_start_offset;
-
-      push_context (desc, valu);
-      break;
-
-    case N_RBRAC:
-      /* This "symbol" just indicates the end of an inner lexical
-	 context that was started with N_LBRAC.  */
-
-      /* Ignore extra outermost context from SunPRO cc and acc.  */
-      if (n_opt_found && desc == 1)
-	break;
-
-      valu += function_start_offset;
-
-      if (outermost_context_p ())
-	{
-	  lbrac_mismatch_complaint (symnum);
-	  break;
-	}
-
-      cstk = pop_context ();
-      if (desc != cstk.depth)
-	lbrac_mismatch_complaint (symnum);
-
-      if (*get_local_symbols () != NULL)
-	{
-	  /* GCC development snapshots from March to December of
-	     2000 would output N_LSYM entries after N_LBRAC
-	     entries.  As a consequence, these symbols are simply
-	     discarded.  Complain if this is the case.  */
-	  complaint (_("misplaced N_LBRAC entry; discarding local "
-		       "symbols which have no enclosing block"));
-	}
-      *get_local_symbols () = cstk.locals;
-
-      if (get_context_stack_depth () > 1)
-	{
-	  /* This is not the outermost LBRAC...RBRAC pair in the
-	     function, its local symbols preceded it, and are the ones
-	     just recovered from the context stack.  Define the block
-	     for them (but don't bother if the block contains no
-	     symbols.  Should we complain on blocks without symbols?
-	     I can't think of any useful purpose for them).  */
-	  if (*get_local_symbols () != NULL)
-	    {
-	      /* Muzzle a compiler bug that makes end < start.
-
-		 ??? Which compilers?  Is this ever harmful?.  */
-	      if (cstk.start_addr > valu)
-		{
-		  complaint (_("block start larger than block end"));
-		  cstk.start_addr = valu;
-		}
-	      /* Make a block for the local symbols within.  */
-	      finish_block (0, cstk.old_blocks, NULL,
-			    cstk.start_addr, valu);
-	    }
-	}
-      else
-	{
-	  /* This is the outermost LBRAC...RBRAC pair.  There is no
-	     need to do anything; leave the symbols that preceded it
-	     to be attached to the function's own block.  We need to
-	     indicate that we just moved outside of the function.  */
-	  within_function = 0;
-	}
-
-      break;
-
-    case N_FN:
-    case N_FN_SEQ:
-      /* This kind of symbol indicates the start of an object file.
-	 Relocate for dynamic loading.  */
-      section_index = SECT_OFF_TEXT (objfile);
-      valu += section_offsets[SECT_OFF_TEXT (objfile)];
-      break;
-
-    case N_SO:
-      /* This type of symbol indicates the start of data for one
-	 source file.  Finish the symbol table of the previous source
-	 file (if any) and start accumulating a new symbol table.
-	 Relocate for dynamic loading.  */
-      section_index = SECT_OFF_TEXT (objfile);
-      valu += section_offsets[SECT_OFF_TEXT (objfile)];
-
-      n_opt_found = 0;
-
-      if (get_last_source_file ())
-	{
-	  /* Check if previous symbol was also an N_SO (with some
-	     sanity checks).  If so, that one was actually the
-	     directory name, and the current one is the real file
-	     name.  Patch things up.  */
-	  if (previous_stab_code == (unsigned char) N_SO)
-	    {
-	      patch_subfile_names (get_current_subfile (), name);
-	      break;		/* Ignore repeated SOs.  */
-	    }
-	  end_compunit_symtab (valu);
-	  end_stabs ();
-	}
-
-      /* Null name means this just marks the end of text for this .o
-	 file.  Don't start a new symtab in this case.  */
-      if (*name == '\000')
-	break;
-
-      function_start_offset = 0;
-
-      start_stabs ();
-      start_compunit_symtab (objfile, name, NULL, valu, language);
-      record_debugformat ("stabs");
-      break;
-
-    case N_SOL:
-      /* This type of symbol indicates the start of data for a
-	 sub-source-file, one whose contents were copied or included
-	 in the compilation of the main source file (whose name was
-	 given in the N_SO symbol).  Relocate for dynamic loading.  */
-      section_index = SECT_OFF_TEXT (objfile);
-      valu += section_offsets[SECT_OFF_TEXT (objfile)];
-      start_subfile (name);
-      break;
-
-    case N_BINCL:
-      push_subfile ();
-      add_new_header_file (name, valu, objfile);
-      start_subfile (name);
-      break;
-
-    case N_EINCL:
-      start_subfile (pop_subfile ());
-      break;
-
-    case N_EXCL:
-      add_old_header_file (name, valu, objfile);
-      break;
-
-    case N_SLINE:
-      /* This type of "symbol" really just records one line-number --
-	 core-address correspondence.  Enter it in the line list for
-	 this symbol table.  */
-
-      /* Relocate for dynamic loading and for ELF acc
-	 function-relative symbols.  */
-      valu += function_start_offset;
-
-      /* GCC 2.95.3 emits the first N_SLINE stab somewhere in the
-	 middle of the prologue instead of right at the start of the
-	 function.  To deal with this we record the address for the
-	 first N_SLINE stab to be the start of the function instead of
-	 the listed location.  We really shouldn't to this.  When
-	 compiling with optimization, this first N_SLINE stab might be
-	 optimized away.  Other (non-GCC) compilers don't emit this
-	 stab at all.  There is no real harm in having an extra
-	 numbered line, although it can be a bit annoying for the
-	 user.  However, it totally screws up our testsuite.
-
-	 So for now, keep adjusting the address of the first N_SLINE
-	 stab, but only for code compiled with GCC.  */
-
-      if (within_function && sline_found_in_function == 0)
-	{
-	  CORE_ADDR addr = processing_gcc_compilation == 2 ?
-			   last_function_start : valu;
-
-	  record_line
-	    (get_current_subfile (), desc,
-	     unrelocated_addr (gdbarch_addr_bits_remove (gdbarch, addr)
-			       - objfile->text_section_offset ()));
-	  sline_found_in_function = 1;
-	}
-      else
-	record_line
-	  (get_current_subfile (), desc,
-	   unrelocated_addr (gdbarch_addr_bits_remove (gdbarch, valu)
-			     - objfile->text_section_offset ()));
-      break;
-
-    case N_BCOMM:
-      common_block_start (name, objfile);
-      break;
-
-    case N_ECOMM:
-      common_block_end (objfile);
-      break;
-
-      /* The following symbol types need to have the appropriate
-	 offset added to their value; then we process symbol
-	 definitions in the name.  */
-
-    case N_STSYM:		/* Static symbol in data segment.  */
-    case N_LCSYM:		/* Static symbol in BSS segment.  */
-    case N_ROSYM:		/* Static symbol in read-only data segment.  */
-      /* HORRID HACK DEPT.  However, it's Sun's furgin' fault.
-	 Solaris 2's stabs-in-elf makes *most* symbols relative but
-	 leaves a few absolute (at least for Solaris 2.1 and version
-	 2.0.1 of the SunPRO compiler).  N_STSYM and friends sit on
-	 the fence.  .stab "foo:S...",N_STSYM is absolute (ld
-	 relocates it) .stab "foo:V...",N_STSYM is relative (section
-	 base subtracted).  This leaves us no choice but to search for
-	 the 'S' or 'V'...  (or pass the whole section_offsets stuff
-	 down ONE MORE function call level, which we really don't want
-	 to do).  */
-      {
-	const char *p;
-
-	/* Normal object file and NLMs have non-zero text seg offsets,
-	   but don't need their static syms offset in this fashion.
-	   XXX - This is really a crock that should be fixed in the
-	   solib handling code so that I don't have to work around it
-	   here.  */
-
-	if (!key->ctx.symfile_relocatable)
-	  {
-	    p = strchr (name, ':');
-	    if (p != 0 && p[1] == 'S')
-	      {
-		/* The linker relocated it.  We don't want to add a
-		   Sun-stabs Tfoo.foo-like offset, but we *do*
-		   want to add whatever solib.c passed to
-		   symbol_file_add as addr (this is known to affect
-		   SunOS 4, and I suspect ELF too).  Since there is no
-		   Ttext.text symbol, we can get addr from the text offset.  */
-		section_index = SECT_OFF_TEXT (objfile);
-		valu += section_offsets[SECT_OFF_TEXT (objfile)];
-		goto define_a_symbol;
-	      }
-	  }
-	/* Since it's not the kludge case, re-dispatch to the right
-	   handler.  */
-	switch (type)
-	  {
-	  case N_STSYM:
-	    goto case_N_STSYM;
-	  case N_LCSYM:
-	    goto case_N_LCSYM;
-	  case N_ROSYM:
-	    goto case_N_ROSYM;
-	  default:
-	    internal_error (_("failed internal consistency check"));
-	  }
-      }
-
-    case_N_STSYM:		/* Static symbol in data segment.  */
-    case N_DSLINE:		/* Source line number, data segment.  */
-      section_index = SECT_OFF_DATA (objfile);
-      valu += section_offsets[SECT_OFF_DATA (objfile)];
-      goto define_a_symbol;
-
-    case_N_LCSYM:		/* Static symbol in BSS segment.  */
-    case N_BSLINE:		/* Source line number, BSS segment.  */
-      /* N_BROWS: overlaps with N_BSLINE.  */
-      section_index = SECT_OFF_BSS (objfile);
-      valu += section_offsets[SECT_OFF_BSS (objfile)];
-      goto define_a_symbol;
-
-    case_N_ROSYM:		/* Static symbol in read-only data segment.  */
-      section_index = SECT_OFF_RODATA (objfile);
-      valu += section_offsets[SECT_OFF_RODATA (objfile)];
-      goto define_a_symbol;
-
-    case N_ENTRY:		/* Alternate entry point.  */
-      /* Relocate for dynamic loading.  */
-      section_index = SECT_OFF_TEXT (objfile);
-      valu += section_offsets[SECT_OFF_TEXT (objfile)];
-      goto define_a_symbol;
-
-      /* The following symbol types we don't know how to process.
-	 Handle them in a "default" way, but complain to people who
-	 care.  */
-    default:
-    case N_CATCH:		/* Exception handler catcher.  */
-    case N_EHDECL:		/* Exception handler name.  */
-    case N_PC:			/* Global symbol in Pascal.  */
-    case N_M2C:			/* Modula-2 compilation unit.  */
-      /* N_MOD2: overlaps with N_EHDECL.  */
-    case N_SCOPE:		/* Modula-2 scope information.  */
-    case N_ECOML:		/* End common (local name).  */
-    case N_NBTEXT:		/* Gould Non-Base-Register symbols???  */
-    case N_NBDATA:
-    case N_NBBSS:
-    case N_NBSTS:
-    case N_NBLCS:
-      unknown_symtype_complaint (hex_string (type));
-
-    define_a_symbol:
-      [[fallthrough]];
-      /* These symbol types don't need the address field relocated,
-	 since it is either unused, or is absolute.  */
-    case N_GSYM:		/* Global variable.  */
-    case N_NSYMS:		/* Number of symbols (Ultrix).  */
-    case N_NOMAP:		/* No map?  (Ultrix).  */
-    case N_RSYM:		/* Register variable.  */
-    case N_DEFD:		/* Modula-2 GNU module dependency.  */
-    case N_SSYM:		/* Struct or union element.  */
-    case N_LSYM:		/* Local symbol in stack.  */
-    case N_PSYM:		/* Parameter variable.  */
-    case N_LENG:		/* Length of preceding symbol type.  */
-      if (name)
-	{
-	  int deftype;
-	  const char *colon_pos = strchr (name, ':');
-
-	  if (colon_pos == NULL)
-	    deftype = '\0';
-	  else
-	    deftype = colon_pos[1];
-
-	  switch (deftype)
-	    {
-	    case 'f':
-	    case 'F':
-	      /* Deal with the SunPRO 3.0 compiler which omits the
-		 address from N_FUN symbols.  */
-	      if (type == N_FUN
-		  && valu == section_offsets[SECT_OFF_TEXT (objfile)]
-		  && gdbarch_sofun_address_maybe_missing (gdbarch))
-		{
-		  bound_minimal_symbol minsym
-		    = find_stab_function (name, get_last_source_file (),
-					  objfile);
-		  if (minsym.minsym != NULL)
-		    valu = minsym.value_address ();
-		}
-
-	      /* These addresses are absolute.  */
-	      function_start_offset = valu;
-
-	      within_function = 1;
-
-	      if (get_context_stack_depth () > 1)
-		{
-		  complaint (_("unmatched N_LBRAC before symtab pos %d"),
-			     symnum);
-		  break;
-		}
-
-	      if (!outermost_context_p ())
-		{
-		  struct block *block;
-
-		  cstk = pop_context ();
-		  /* Make a block for the local symbols within.  */
-		  block = finish_block (cstk.name,
-					cstk.old_blocks, NULL,
-					cstk.start_addr, valu);
-
-		  /* For C++, set the block's scope.  */
-		  if (cstk.name->language () == language_cplus)
-		    cp_set_block_scope (cstk.name, block,
-					&objfile->objfile_obstack);
-		}
-
-	      newobj = push_context (0, valu);
-	      newobj->name = define_symbol (valu, name, desc, type, objfile);
-	      if (newobj->name != nullptr)
-		newobj->name->set_section_index (section_index);
-	      break;
-
-	    default:
-	      {
-		struct symbol *sym = define_symbol (valu, name, desc, type,
-						    objfile);
-		if (sym != nullptr)
-		  sym->set_section_index (section_index);
-	      }
-	      break;
-	    }
-	}
-      break;
-
-      /* We use N_OPT to carry the gcc2_compiled flag.  Sun uses it
-	 for a bunch of other flags, too.  Someday we may parse their
-	 flags; for now we ignore theirs and hope they'll ignore ours.  */
-    case N_OPT:			/* Solaris 2: Compiler options.  */
-      if (name)
-	{
-	  if (strcmp (name, GCC2_COMPILED_FLAG_SYMBOL) == 0)
-	    {
-	      processing_gcc_compilation = 2;
-	    }
-	  else
-	    n_opt_found = 1;
-	}
-      break;
-
-    case N_MAIN:		/* Name of main routine.  */
-      /* FIXME: If one has a symbol file with N_MAIN and then replaces
-	 it with a symbol file with "main" and without N_MAIN.  I'm
-	 not sure exactly what rule to follow but probably something
-	 like: N_MAIN takes precedence over "main" no matter what
-	 objfile it is in; If there is more than one N_MAIN, choose
-	 the one in the symfile_objfile; If there is more than one
-	 N_MAIN within a given objfile, complain() and choose
-	 arbitrarily.  (kingdon) */
-      if (name != NULL)
-	set_objfile_main_name (objfile, name, language_unknown);
-      break;
-
-      /* The following symbol types can be ignored.  */
-    case N_OBJ:			/* Solaris 2: Object file dir and name.  */
-    case N_PATCH:		/* Solaris 2: Patch Run Time Checker.  */
-      /* N_UNDF:                   Solaris 2: File separator mark.  */
-      /* N_UNDF: -- we will never encounter it, since we only process
-	 one file's symbols at once.  */
-    case N_ENDM:		/* Solaris 2: End of module.  */
-    case N_ALIAS:		/* SunPro F77: alias name, ignore for now.  */
-      break;
-    }
-
-  /* '#' is a GNU C extension to allow one symbol to refer to another
-     related symbol.
-
-     Generally this is used so that an alias can refer to its main
-     symbol.  */
-  gdb_assert (name);
-  if (name[0] == '#')
-    {
-      /* Initialize symbol reference names and determine if this is a
-	 definition.  If a symbol reference is being defined, go ahead
-	 and add it.  Otherwise, just return.  */
-
-      const char *s = name;
-      int refnum;
-
-      /* If this stab defines a new reference ID that is not on the
-	 reference list, then put it on the reference list.
-
-	 We go ahead and advance NAME past the reference, even though
-	 it is not strictly necessary at this time.  */
-      refnum = symbol_reference_defined (&s);
-      if (refnum >= 0)
-	if (!ref_search (refnum))
-	  ref_add (refnum, 0, name, valu);
-      name = s;
-    }
-
-  previous_stab_code = type;
-}
 
 /* FIXME: The only difference between this and elfstab_build_psymtabs
    is the call to install_minimal_symbols for elf, and the support for
diff --git a/gdb/gdb-stabs.h b/gdb/gdb-stabs.h
index 4bf8da5cf66..20fb8fafc34 100644
--- a/gdb/gdb-stabs.h
+++ b/gdb/gdb-stabs.h
@@ -20,6 +20,28 @@ 
 #ifndef GDB_STABS_H
 #define GDB_STABS_H
 
+/* During initial symbol readin, we need to have a structure to keep
+   track of which psymtabs have which bincls in them.  This structure
+   is used during readin to setup the list of dependencies within each
+   partial symbol table.  */
+struct legacy_psymtab;
+
+struct header_file_location
+{
+  header_file_location (const char *name_, int instance_,
+			legacy_psymtab *pst_)
+    : name (name_),
+      instance (instance_),
+      pst (pst_)
+  {
+  }
+
+  const char *name;		/* Name of header file */
+  int instance;			/* See above */
+  legacy_psymtab *pst;	/* Partial symtab that has the
+				   BINCL/EINCL defs for this file.  */
+};
+
 /* This file exists to hold the common definitions required of most of
    the symbol-readers that end up using stabs.  The common use of
    these `symbol-type-specific' customizations of the generic data
diff --git a/gdb/stabsread.c b/gdb/stabsread.c
index 46536ba21c7..b614423fb37 100644
--- a/gdb/stabsread.c
+++ b/gdb/stabsread.c
@@ -46,6 +46,8 @@ 
 #include "cp-abi.h"
 #include "cp-support.h"
 #include <ctype.h>
+#include "block.h"
+#include "filenames.h"
 
 #include "stabsread.h"
 
@@ -61,6 +63,26 @@  int *this_object_header_files;
 int n_this_object_header_files;
 int n_allocated_this_object_header_files;
 
+/* See stabsread.h.  */
+
+const registry<objfile>::key<dbx_symfile_info> dbx_objfile_data_key;
+
+dbx_symfile_info::~dbx_symfile_info ()
+{
+  if (header_files != NULL)
+    {
+      int i = n_header_files;
+      struct header_file *hfiles = header_files;
+
+      while (--i >= 0)
+	{
+	  xfree (hfiles[i].name);
+	  xfree (hfiles[i].vector);
+	}
+      xfree (hfiles);
+    }
+}
+
 struct stabs_nextfield
 {
   struct stabs_nextfield *next;
@@ -165,6 +187,26 @@  void stabsread_clear_cache (void);
 static const char vptr_name[] = "_vptr$";
 static const char vb_name[] = "_vb$";
 
+void
+unknown_symtype_complaint (const char *arg1)
+{
+  complaint (_("unknown symbol type %s"), arg1);
+}
+
+void
+lbrac_mismatch_complaint (int arg1)
+{
+  complaint (_("N_LBRAC/N_RBRAC symbol mismatch at symtab pos %d"), arg1);
+}
+
+void
+repeated_header_complaint (const char *arg1, int arg2)
+{
+  complaint (_("\"repeated\" header file %s not "
+	       "previously seen, at symtab pos %d"),
+	     arg1, arg2);
+}
+
 static void
 invalid_cpp_abbrev_complaint (const char *arg1)
 {
@@ -491,6 +533,726 @@  read_type_number (const char **pp, int *typenums)
 }
 
 
+/* Record the namespace that the function defined by SYMBOL was
+   defined in, if necessary.  BLOCK is the associated block; use
+   OBSTACK for allocation.  */
+
+static void
+cp_set_block_scope (const struct symbol *symbol,
+		    struct block *block,
+		    struct obstack *obstack)
+{
+  if (symbol->demangled_name () != NULL)
+    {
+      /* Try to figure out the appropriate namespace from the
+	 demangled name.  */
+
+      /* FIXME: carlton/2003-04-15: If the function in question is
+	 a method of a class, the name will actually include the
+	 name of the class as well.  This should be harmless, but
+	 is a little unfortunate.  */
+
+      const char *name = symbol->demangled_name ();
+      unsigned int prefix_len = cp_entire_prefix_len (name);
+
+      block->set_scope (obstack_strndup (obstack, name, prefix_len),
+			obstack);
+    }
+}
+
+bound_minimal_symbol
+find_stab_function (const char *namestring, const char *filename,
+		    struct objfile *objfile)
+{
+  int n;
+
+  const char *colon = strchr (namestring, ':');
+  if (colon == NULL)
+    n = 0;
+  else
+    n = colon - namestring;
+
+  char *p = (char *) alloca (n + 2);
+  strncpy (p, namestring, n);
+  p[n] = 0;
+
+  bound_minimal_symbol msym
+    = lookup_minimal_symbol (current_program_space, p, objfile, filename);
+  if (msym.minsym == NULL)
+    {
+      /* Sun Fortran appends an underscore to the minimal symbol name,
+	 try again with an appended underscore if the minimal symbol
+	 was not found.  */
+      p[n] = '_';
+      p[n + 1] = 0;
+      msym
+	= lookup_minimal_symbol (current_program_space, p, objfile, filename);
+    }
+
+  if (msym.minsym == NULL && filename != NULL)
+    {
+      /* Try again without the filename.  */
+      p[n] = 0;
+      msym = lookup_minimal_symbol (current_program_space, p, objfile);
+    }
+  if (msym.minsym == NULL && filename != NULL)
+    {
+      /* And try again for Sun Fortran, but without the filename.  */
+      p[n] = '_';
+      p[n + 1] = 0;
+      msym = lookup_minimal_symbol (current_program_space, p, objfile);
+    }
+
+  return msym;
+}
+
+/* Add header file number I for this object file
+   at the next successive FILENUM.  */
+
+static void
+add_this_object_header_file (int i)
+{
+  if (n_this_object_header_files == n_allocated_this_object_header_files)
+    {
+      n_allocated_this_object_header_files *= 2;
+      this_object_header_files
+	= (int *) xrealloc ((char *) this_object_header_files,
+		       n_allocated_this_object_header_files * sizeof (int));
+    }
+
+  this_object_header_files[n_this_object_header_files++] = i;
+}
+
+/* Add to this file an "old" header file, one already seen in
+   a previous object file.  NAME is the header file's name.
+   INSTANCE is its instance code, to select among multiple
+   symbol tables for the same header file.  */
+
+static void
+add_old_header_file (const char *name, int instance, struct objfile *objfile)
+{
+  struct header_file *p = HEADER_FILES (objfile);
+  int i;
+
+  for (i = 0; i < N_HEADER_FILES (objfile); i++)
+    if (filename_cmp (p[i].name, name) == 0 && instance == p[i].instance)
+      {
+	add_this_object_header_file (i);
+	return;
+      }
+  repeated_header_complaint (name, symnum);
+}
+
+/* Add to this file a "new" header file: definitions for its types follow.
+   NAME is the header file's name.
+   Most often this happens only once for each distinct header file,
+   but not necessarily.  If it happens more than once, INSTANCE has
+   a different value each time, and references to the header file
+   use INSTANCE values to select among them.
+
+   dbx output contains "begin" and "end" markers for each new header file,
+   but at this level we just need to know which files there have been;
+   so we record the file when its "begin" is seen and ignore the "end".  */
+
+static void
+add_new_header_file (const char *name, int instance, struct objfile *objfile)
+{
+  int i;
+  struct header_file *hfile;
+
+  /* Make sure there is room for one more header file.  */
+
+  i = N_ALLOCATED_HEADER_FILES (objfile);
+
+  if (N_HEADER_FILES (objfile) == i)
+    {
+      if (i == 0)
+	{
+	  N_ALLOCATED_HEADER_FILES (objfile) = 10;
+	  HEADER_FILES (objfile) = (struct header_file *)
+	    xmalloc (10 * sizeof (struct header_file));
+	}
+      else
+	{
+	  i *= 2;
+	  N_ALLOCATED_HEADER_FILES (objfile) = i;
+	  HEADER_FILES (objfile) = (struct header_file *)
+	    xrealloc ((char *) HEADER_FILES (objfile),
+		      (i * sizeof (struct header_file)));
+	}
+    }
+
+  /* Create an entry for this header file.  */
+
+  i = N_HEADER_FILES (objfile)++;
+  hfile = HEADER_FILES (objfile) + i;
+  hfile->name = xstrdup (name);
+  hfile->instance = instance;
+  hfile->length = 10;
+  hfile->vector = XCNEWVEC (struct type *, 10);
+
+  add_this_object_header_file (i);
+}
+
+/* See stabsread.h.  */
+
+void
+process_one_symbol (int type, int desc, CORE_ADDR valu, const char *name,
+		    const section_offsets &section_offsets,
+		    struct objfile *objfile, enum language language)
+{
+  struct gdbarch *gdbarch = objfile->arch ();
+  struct context_stack *newobj;
+  struct context_stack cstk;
+  /* This remembers the address of the start of a function.  It is
+     used because in Solaris 2, N_LBRAC, N_RBRAC, and N_SLINE entries
+     are relative to the current function's start address.  On systems
+     other than Solaris 2, this just holds the SECT_OFF_TEXT value,
+     and is used to relocate these symbol types rather than
+     SECTION_OFFSETS.  */
+  static CORE_ADDR function_start_offset;
+
+  /* This holds the address of the start of a function, without the
+     system peculiarities of function_start_offset.  */
+  static CORE_ADDR last_function_start;
+
+  /* If this is nonzero, we've seen an N_SLINE since the start of the
+     current function.  We use this to tell us to move the first sline
+     to the beginning of the function regardless of what its given
+     value is.  */
+  static int sline_found_in_function = 1;
+
+  /* If this is nonzero, we've seen a non-gcc N_OPT symbol for this
+     source file.  Used to detect the SunPRO solaris compiler.  */
+  static int n_opt_found;
+
+  /* The section index for this symbol.  */
+  int section_index = -1;
+
+  struct dbx_symfile_info *key = dbx_objfile_data_key.get (objfile);
+
+  /* Something is wrong if we see real data before seeing a source
+     file name.  */
+
+  if (get_last_source_file () == NULL && type != (unsigned char) N_SO)
+    {
+      /* Ignore any symbols which appear before an N_SO symbol.
+	 Currently no one puts symbols there, but we should deal
+	 gracefully with the case.  A complain()t might be in order,
+	 but this should not be an error ().  */
+      return;
+    }
+
+  switch (type)
+    {
+    case N_FUN:
+    case N_FNAME:
+
+      if (*name == '\000')
+	{
+	  /* This N_FUN marks the end of a function.  This closes off
+	     the current block.  */
+	  struct block *block;
+
+	  if (outermost_context_p ())
+	    {
+	      lbrac_mismatch_complaint (symnum);
+	      break;
+	    }
+
+	  /* The following check is added before recording line 0 at
+	     end of function so as to handle hand-generated stabs
+	     which may have an N_FUN stabs at the end of the function,
+	     but no N_SLINE stabs.  */
+	  if (sline_found_in_function)
+	    {
+	      CORE_ADDR addr = last_function_start + valu;
+
+	      record_line
+		(get_current_subfile (), 0,
+		 unrelocated_addr (gdbarch_addr_bits_remove (gdbarch, addr)
+				   - objfile->text_section_offset ()));
+	    }
+
+	  within_function = 0;
+	  cstk = pop_context ();
+
+	  /* Make a block for the local symbols within.  */
+	  block = finish_block (cstk.name,
+				cstk.old_blocks, NULL,
+				cstk.start_addr, cstk.start_addr + valu);
+
+	  /* For C++, set the block's scope.  */
+	  if (cstk.name->language () == language_cplus)
+	    cp_set_block_scope (cstk.name, block, &objfile->objfile_obstack);
+
+	  /* May be switching to an assembler file which may not be using
+	     block relative stabs, so reset the offset.  */
+	  function_start_offset = 0;
+
+	  break;
+	}
+
+      sline_found_in_function = 0;
+
+      /* Relocate for dynamic loading.  */
+      section_index = SECT_OFF_TEXT (objfile);
+      valu += section_offsets[SECT_OFF_TEXT (objfile)];
+      valu = gdbarch_addr_bits_remove (gdbarch, valu);
+      last_function_start = valu;
+
+      goto define_a_symbol;
+
+    case N_LBRAC:
+      /* This "symbol" just indicates the start of an inner lexical
+	 context within a function.  */
+
+      /* Ignore extra outermost context from SunPRO cc and acc.  */
+      if (n_opt_found && desc == 1)
+	break;
+
+      valu += function_start_offset;
+
+      push_context (desc, valu);
+      break;
+
+    case N_RBRAC:
+      /* This "symbol" just indicates the end of an inner lexical
+	 context that was started with N_LBRAC.  */
+
+      /* Ignore extra outermost context from SunPRO cc and acc.  */
+      if (n_opt_found && desc == 1)
+	break;
+
+      valu += function_start_offset;
+
+      if (outermost_context_p ())
+	{
+	  lbrac_mismatch_complaint (symnum);
+	  break;
+	}
+
+      cstk = pop_context ();
+      if (desc != cstk.depth)
+	lbrac_mismatch_complaint (symnum);
+
+      if (*get_local_symbols () != NULL)
+	{
+	  /* GCC development snapshots from March to December of
+	     2000 would output N_LSYM entries after N_LBRAC
+	     entries.  As a consequence, these symbols are simply
+	     discarded.  Complain if this is the case.  */
+	  complaint (_("misplaced N_LBRAC entry; discarding local "
+		       "symbols which have no enclosing block"));
+	}
+      *get_local_symbols () = cstk.locals;
+
+      if (get_context_stack_depth () > 1)
+	{
+	  /* This is not the outermost LBRAC...RBRAC pair in the
+	     function, its local symbols preceded it, and are the ones
+	     just recovered from the context stack.  Define the block
+	     for them (but don't bother if the block contains no
+	     symbols.  Should we complain on blocks without symbols?
+	     I can't think of any useful purpose for them).  */
+	  if (*get_local_symbols () != NULL)
+	    {
+	      /* Muzzle a compiler bug that makes end < start.
+
+		 ??? Which compilers?  Is this ever harmful?.  */
+	      if (cstk.start_addr > valu)
+		{
+		  complaint (_("block start larger than block end"));
+		  cstk.start_addr = valu;
+		}
+	      /* Make a block for the local symbols within.  */
+	      finish_block (0, cstk.old_blocks, NULL,
+			    cstk.start_addr, valu);
+	    }
+	}
+      else
+	{
+	  /* This is the outermost LBRAC...RBRAC pair.  There is no
+	     need to do anything; leave the symbols that preceded it
+	     to be attached to the function's own block.  We need to
+	     indicate that we just moved outside of the function.  */
+	  within_function = 0;
+	}
+
+      break;
+
+    case N_FN:
+    case N_FN_SEQ:
+      /* This kind of symbol indicates the start of an object file.
+	 Relocate for dynamic loading.  */
+      section_index = SECT_OFF_TEXT (objfile);
+      valu += section_offsets[SECT_OFF_TEXT (objfile)];
+      break;
+
+    case N_SO:
+      /* This type of symbol indicates the start of data for one
+	 source file.  Finish the symbol table of the previous source
+	 file (if any) and start accumulating a new symbol table.
+	 Relocate for dynamic loading.  */
+      section_index = SECT_OFF_TEXT (objfile);
+      valu += section_offsets[SECT_OFF_TEXT (objfile)];
+
+      n_opt_found = 0;
+
+      if (get_last_source_file ())
+	{
+	  /* Check if previous symbol was also an N_SO (with some
+	     sanity checks).  If so, that one was actually the
+	     directory name, and the current one is the real file
+	     name.  Patch things up.  */
+	  if (previous_stab_code == (unsigned char) N_SO)
+	    {
+	      patch_subfile_names (get_current_subfile (), name);
+	      break;		/* Ignore repeated SOs.  */
+	    }
+	  end_compunit_symtab (valu);
+	  end_stabs ();
+	}
+
+      /* Null name means this just marks the end of text for this .o
+	 file.  Don't start a new symtab in this case.  */
+      if (*name == '\000')
+	break;
+
+      function_start_offset = 0;
+
+      start_stabs ();
+      start_compunit_symtab (objfile, name, NULL, valu, language);
+      record_debugformat ("stabs");
+      break;
+
+    case N_SOL:
+      /* This type of symbol indicates the start of data for a
+	 sub-source-file, one whose contents were copied or included
+	 in the compilation of the main source file (whose name was
+	 given in the N_SO symbol).  Relocate for dynamic loading.  */
+      section_index = SECT_OFF_TEXT (objfile);
+      valu += section_offsets[SECT_OFF_TEXT (objfile)];
+      start_subfile (name);
+      break;
+
+    case N_BINCL:
+      push_subfile ();
+      add_new_header_file (name, valu, objfile);
+      start_subfile (name);
+      break;
+
+    case N_EINCL:
+      start_subfile (pop_subfile ());
+      break;
+
+    case N_EXCL:
+      add_old_header_file (name, valu, objfile);
+      break;
+
+    case N_SLINE:
+      /* This type of "symbol" really just records one line-number --
+	 core-address correspondence.  Enter it in the line list for
+	 this symbol table.  */
+
+      /* Relocate for dynamic loading and for ELF acc
+	 function-relative symbols.  */
+      valu += function_start_offset;
+
+      /* GCC 2.95.3 emits the first N_SLINE stab somewhere in the
+	 middle of the prologue instead of right at the start of the
+	 function.  To deal with this we record the address for the
+	 first N_SLINE stab to be the start of the function instead of
+	 the listed location.  We really shouldn't to this.  When
+	 compiling with optimization, this first N_SLINE stab might be
+	 optimized away.  Other (non-GCC) compilers don't emit this
+	 stab at all.  There is no real harm in having an extra
+	 numbered line, although it can be a bit annoying for the
+	 user.  However, it totally screws up our testsuite.
+
+	 So for now, keep adjusting the address of the first N_SLINE
+	 stab, but only for code compiled with GCC.  */
+
+      if (within_function && sline_found_in_function == 0)
+	{
+	  CORE_ADDR addr = processing_gcc_compilation == 2 ?
+			   last_function_start : valu;
+
+	  record_line
+	    (get_current_subfile (), desc,
+	     unrelocated_addr (gdbarch_addr_bits_remove (gdbarch, addr)
+			       - objfile->text_section_offset ()));
+	  sline_found_in_function = 1;
+	}
+      else
+	record_line
+	  (get_current_subfile (), desc,
+	   unrelocated_addr (gdbarch_addr_bits_remove (gdbarch, valu)
+			     - objfile->text_section_offset ()));
+      break;
+
+    case N_BCOMM:
+      common_block_start (name, objfile);
+      break;
+
+    case N_ECOMM:
+      common_block_end (objfile);
+      break;
+
+      /* The following symbol types need to have the appropriate
+	 offset added to their value; then we process symbol
+	 definitions in the name.  */
+
+    case N_STSYM:		/* Static symbol in data segment.  */
+    case N_LCSYM:		/* Static symbol in BSS segment.  */
+    case N_ROSYM:		/* Static symbol in read-only data segment.  */
+      /* HORRID HACK DEPT.  However, it's Sun's furgin' fault.
+	 Solaris 2's stabs-in-elf makes *most* symbols relative but
+	 leaves a few absolute (at least for Solaris 2.1 and version
+	 2.0.1 of the SunPRO compiler).  N_STSYM and friends sit on
+	 the fence.  .stab "foo:S...",N_STSYM is absolute (ld
+	 relocates it) .stab "foo:V...",N_STSYM is relative (section
+	 base subtracted).  This leaves us no choice but to search for
+	 the 'S' or 'V'...  (or pass the whole section_offsets stuff
+	 down ONE MORE function call level, which we really don't want
+	 to do).  */
+      {
+	const char *p;
+
+	/* Normal object file and NLMs have non-zero text seg offsets,
+	   but don't need their static syms offset in this fashion.
+	   XXX - This is really a crock that should be fixed in the
+	   solib handling code so that I don't have to work around it
+	   here.  */
+
+	if (!key->ctx.symfile_relocatable)
+	  {
+	    p = strchr (name, ':');
+	    if (p != 0 && p[1] == 'S')
+	      {
+		/* The linker relocated it.  We don't want to add a
+		   Sun-stabs Tfoo.foo-like offset, but we *do*
+		   want to add whatever solib.c passed to
+		   symbol_file_add as addr (this is known to affect
+		   SunOS 4, and I suspect ELF too).  Since there is no
+		   Ttext.text symbol, we can get addr from the text offset.  */
+		section_index = SECT_OFF_TEXT (objfile);
+		valu += section_offsets[SECT_OFF_TEXT (objfile)];
+		goto define_a_symbol;
+	      }
+	  }
+	/* Since it's not the kludge case, re-dispatch to the right
+	   handler.  */
+	switch (type)
+	  {
+	  case N_STSYM:
+	    goto case_N_STSYM;
+	  case N_LCSYM:
+	    goto case_N_LCSYM;
+	  case N_ROSYM:
+	    goto case_N_ROSYM;
+	  default:
+	    internal_error (_("failed internal consistency check"));
+	  }
+      }
+
+    case_N_STSYM:		/* Static symbol in data segment.  */
+    case N_DSLINE:		/* Source line number, data segment.  */
+      section_index = SECT_OFF_DATA (objfile);
+      valu += section_offsets[SECT_OFF_DATA (objfile)];
+      goto define_a_symbol;
+
+    case_N_LCSYM:		/* Static symbol in BSS segment.  */
+    case N_BSLINE:		/* Source line number, BSS segment.  */
+      /* N_BROWS: overlaps with N_BSLINE.  */
+      section_index = SECT_OFF_BSS (objfile);
+      valu += section_offsets[SECT_OFF_BSS (objfile)];
+      goto define_a_symbol;
+
+    case_N_ROSYM:		/* Static symbol in read-only data segment.  */
+      section_index = SECT_OFF_RODATA (objfile);
+      valu += section_offsets[SECT_OFF_RODATA (objfile)];
+      goto define_a_symbol;
+
+    case N_ENTRY:		/* Alternate entry point.  */
+      /* Relocate for dynamic loading.  */
+      section_index = SECT_OFF_TEXT (objfile);
+      valu += section_offsets[SECT_OFF_TEXT (objfile)];
+      goto define_a_symbol;
+
+      /* The following symbol types we don't know how to process.
+	 Handle them in a "default" way, but complain to people who
+	 care.  */
+    default:
+    case N_CATCH:		/* Exception handler catcher.  */
+    case N_EHDECL:		/* Exception handler name.  */
+    case N_PC:			/* Global symbol in Pascal.  */
+    case N_M2C:			/* Modula-2 compilation unit.  */
+      /* N_MOD2: overlaps with N_EHDECL.  */
+    case N_SCOPE:		/* Modula-2 scope information.  */
+    case N_ECOML:		/* End common (local name).  */
+    case N_NBTEXT:		/* Gould Non-Base-Register symbols???  */
+    case N_NBDATA:
+    case N_NBBSS:
+    case N_NBSTS:
+    case N_NBLCS:
+      unknown_symtype_complaint (hex_string (type));
+
+    define_a_symbol:
+      [[fallthrough]];
+      /* These symbol types don't need the address field relocated,
+	 since it is either unused, or is absolute.  */
+    case N_GSYM:		/* Global variable.  */
+    case N_NSYMS:		/* Number of symbols (Ultrix).  */
+    case N_NOMAP:		/* No map?  (Ultrix).  */
+    case N_RSYM:		/* Register variable.  */
+    case N_DEFD:		/* Modula-2 GNU module dependency.  */
+    case N_SSYM:		/* Struct or union element.  */
+    case N_LSYM:		/* Local symbol in stack.  */
+    case N_PSYM:		/* Parameter variable.  */
+    case N_LENG:		/* Length of preceding symbol type.  */
+      if (name)
+	{
+	  int deftype;
+	  const char *colon_pos = strchr (name, ':');
+
+	  if (colon_pos == NULL)
+	    deftype = '\0';
+	  else
+	    deftype = colon_pos[1];
+
+	  switch (deftype)
+	    {
+	    case 'f':
+	    case 'F':
+	      /* Deal with the SunPRO 3.0 compiler which omits the
+		 address from N_FUN symbols.  */
+	      if (type == N_FUN
+		  && valu == section_offsets[SECT_OFF_TEXT (objfile)]
+		  && gdbarch_sofun_address_maybe_missing (gdbarch))
+		{
+		  bound_minimal_symbol minsym
+		    = find_stab_function (name, get_last_source_file (),
+					  objfile);
+		  if (minsym.minsym != NULL)
+		    valu = minsym.value_address ();
+		}
+
+	      /* These addresses are absolute.  */
+	      function_start_offset = valu;
+
+	      within_function = 1;
+
+	      if (get_context_stack_depth () > 1)
+		{
+		  complaint (_("unmatched N_LBRAC before symtab pos %d"),
+			     symnum);
+		  break;
+		}
+
+	      if (!outermost_context_p ())
+		{
+		  struct block *block;
+
+		  cstk = pop_context ();
+		  /* Make a block for the local symbols within.  */
+		  block = finish_block (cstk.name,
+					cstk.old_blocks, NULL,
+					cstk.start_addr, valu);
+
+		  /* For C++, set the block's scope.  */
+		  if (cstk.name->language () == language_cplus)
+		    cp_set_block_scope (cstk.name, block,
+					&objfile->objfile_obstack);
+		}
+
+	      newobj = push_context (0, valu);
+	      newobj->name = define_symbol (valu, name, desc, type, objfile);
+	      if (newobj->name != nullptr)
+		newobj->name->set_section_index (section_index);
+	      break;
+
+	    default:
+	      {
+		struct symbol *sym = define_symbol (valu, name, desc, type,
+						    objfile);
+		if (sym != nullptr)
+		  sym->set_section_index (section_index);
+	      }
+	      break;
+	    }
+	}
+      break;
+
+      /* We use N_OPT to carry the gcc2_compiled flag.  Sun uses it
+	 for a bunch of other flags, too.  Someday we may parse their
+	 flags; for now we ignore theirs and hope they'll ignore ours.  */
+    case N_OPT:			/* Solaris 2: Compiler options.  */
+      if (name)
+	{
+	  if (strcmp (name, GCC2_COMPILED_FLAG_SYMBOL) == 0)
+	    {
+	      processing_gcc_compilation = 2;
+	    }
+	  else
+	    n_opt_found = 1;
+	}
+      break;
+
+    case N_MAIN:		/* Name of main routine.  */
+      /* FIXME: If one has a symbol file with N_MAIN and then replaces
+	 it with a symbol file with "main" and without N_MAIN.  I'm
+	 not sure exactly what rule to follow but probably something
+	 like: N_MAIN takes precedence over "main" no matter what
+	 objfile it is in; If there is more than one N_MAIN, choose
+	 the one in the symfile_objfile; If there is more than one
+	 N_MAIN within a given objfile, complain() and choose
+	 arbitrarily.  (kingdon) */
+      if (name != NULL)
+	set_objfile_main_name (objfile, name, language_unknown);
+      break;
+
+      /* The following symbol types can be ignored.  */
+    case N_OBJ:			/* Solaris 2: Object file dir and name.  */
+    case N_PATCH:		/* Solaris 2: Patch Run Time Checker.  */
+      /* N_UNDF:                   Solaris 2: File separator mark.  */
+      /* N_UNDF: -- we will never encounter it, since we only process
+	 one file's symbols at once.  */
+    case N_ENDM:		/* Solaris 2: End of module.  */
+    case N_ALIAS:		/* SunPro F77: alias name, ignore for now.  */
+      break;
+    }
+
+  /* '#' is a GNU C extension to allow one symbol to refer to another
+     related symbol.
+
+     Generally this is used so that an alias can refer to its main
+     symbol.  */
+  gdb_assert (name);
+  if (name[0] == '#')
+    {
+      /* Initialize symbol reference names and determine if this is a
+	 definition.  If a symbol reference is being defined, go ahead
+	 and add it.  Otherwise, just return.  */
+
+      const char *s = name;
+      int refnum;
+
+      /* If this stab defines a new reference ID that is not on the
+	 reference list, then put it on the reference list.
+
+	 We go ahead and advance NAME past the reference, even though
+	 it is not strictly necessary at this time.  */
+      refnum = symbol_reference_defined (&s);
+      if (refnum >= 0)
+	if (!ref_search (refnum))
+	  ref_add (refnum, 0, name, valu);
+      name = s;
+    }
+
+  previous_stab_code = type;
+}
+
 #define VISIBILITY_PRIVATE	'0'	/* Stabs character for private field */
 #define VISIBILITY_PROTECTED	'1'	/* Stabs character for protected fld */
 #define VISIBILITY_PUBLIC	'2'	/* Stabs character for public field */
diff --git a/gdb/stabsread.h b/gdb/stabsread.h
index 0a868409470..33c57d97c64 100644
--- a/gdb/stabsread.h
+++ b/gdb/stabsread.h
@@ -215,4 +215,40 @@  extern void init_header_files (void);
 
 extern void scan_file_globals (struct objfile *objfile);
 
+/* Complaints about the symbols we have encountered.  */
+
+void
+unknown_symtype_complaint (const char *);
+
+void
+lbrac_mismatch_complaint (int);
+
+void
+repeated_header_complaint (const char *, int);
+
+bound_minimal_symbol
+find_stab_function (const char *, const char *, struct objfile *);
+
+/* This handles a single symbol from the symbol-file, building symbols
+   into a GDB symtab.  It takes these arguments and an implicit argument.
+
+   TYPE is the type field of the ".stab" symbol entry.
+   DESC is the desc field of the ".stab" entry.
+   VALU is the value field of the ".stab" entry.
+   NAME is the symbol name, in our address space.
+   SECTION_OFFSETS is a set of amounts by which the sections of this
+   object file were relocated when it was loaded into memory.  Note
+   that these section_offsets are not the objfile->section_offsets but
+   the pst->section_offsets.  All symbols that refer to memory
+   locations need to be offset by these amounts.
+   OBJFILE is the object file from which we are reading symbols.  It
+   is used in end_compunit_symtab.
+   LANGUAGE is the language of the symtab.
+*/
+
+void
+process_one_symbol (int, int, CORE_ADDR, const char *,
+		    const section_offsets &,
+		    struct objfile *, enum language);
+
 #endif /* STABSREAD_H */