Home | History | Annotate | Line # | Download | only in gdb
stabsread.c revision 1.12
      1 /* Support routines for decoding "stabs" debugging information format.
      2 
      3    Copyright (C) 1986-2024 Free Software Foundation, Inc.
      4 
      5    This file is part of GDB.
      6 
      7    This program is free software; you can redistribute it and/or modify
      8    it under the terms of the GNU General Public License as published by
      9    the Free Software Foundation; either version 3 of the License, or
     10    (at your option) any later version.
     11 
     12    This program is distributed in the hope that it will be useful,
     13    but WITHOUT ANY WARRANTY; without even the implied warranty of
     14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15    GNU General Public License for more details.
     16 
     17    You should have received a copy of the GNU General Public License
     18    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
     19 
     20 /* Support routines for reading and decoding debugging information in
     21    the "stabs" format.  This format is used by some systems that use
     22    COFF or ELF where the stabs data is placed in a special section (as
     23    well as with many old systems that used the a.out object file
     24    format).  Avoid placing any object file format specific code in
     25    this file.  */
     26 
     27 #include "bfd.h"
     28 #include "event-top.h"
     29 #include "gdbsupport/gdb_obstack.h"
     30 #include "symtab.h"
     31 #include "gdbtypes.h"
     32 #include "expression.h"
     33 #include "symfile.h"
     34 #include "objfiles.h"
     35 #include "aout/stab_gnu.h"
     36 #include "psymtab.h"
     37 #include "libaout.h"
     38 #include "aout/aout64.h"
     39 #include "gdb-stabs.h"
     40 #include "buildsym-legacy.h"
     41 #include "complaints.h"
     42 #include "demangle.h"
     43 #include "gdb-demangle.h"
     44 #include "language.h"
     45 #include "target-float.h"
     46 #include "c-lang.h"
     47 #include "cp-abi.h"
     48 #include "cp-support.h"
     49 #include <ctype.h>
     50 #include "block.h"
     51 #include "filenames.h"
     52 
     53 #include "stabsread.h"
     54 
     55 /* See stabsread.h for these globals.  */
     56 unsigned int symnum;
     57 const char *(*next_symbol_text_func) (struct objfile *);
     58 unsigned char processing_gcc_compilation;
     59 int within_function;
     60 struct symbol *global_sym_chain[HASHSIZE];
     61 struct pending_stabs *global_stabs;
     62 int previous_stab_code;
     63 int *this_object_header_files;
     64 int n_this_object_header_files;
     65 int n_allocated_this_object_header_files;
     66 
     67 /* See stabsread.h.  */
     68 
     69 const registry<objfile>::key<dbx_symfile_info> dbx_objfile_data_key;
     70 
     71 dbx_symfile_info::~dbx_symfile_info ()
     72 {
     73   if (header_files != NULL)
     74     {
     75       int i = n_header_files;
     76       struct header_file *hfiles = header_files;
     77 
     78       while (--i >= 0)
     79 	{
     80 	  xfree (hfiles[i].name);
     81 	  xfree (hfiles[i].vector);
     82 	}
     83       xfree (hfiles);
     84     }
     85 }
     86 
     87 struct stabs_nextfield
     88 {
     89   struct stabs_nextfield *next;
     90 
     91   struct field field;
     92 };
     93 
     94 struct next_fnfieldlist
     95 {
     96   struct next_fnfieldlist *next;
     97   struct fn_fieldlist fn_fieldlist;
     98 };
     99 
    100 /* The routines that read and process a complete stabs for a C struct or
    101    C++ class pass lists of data member fields and lists of member function
    102    fields in an instance of a field_info structure, as defined below.
    103    This is part of some reorganization of low level C++ support and is
    104    expected to eventually go away...  (FIXME) */
    105 
    106 struct stab_field_info
    107   {
    108     struct stabs_nextfield *list = nullptr;
    109     struct next_fnfieldlist *fnlist = nullptr;
    110 
    111     auto_obstack obstack;
    112   };
    113 
    114 static void
    115 read_one_struct_field (struct stab_field_info *, const char **, const char *,
    116 		       struct type *, struct objfile *);
    117 
    118 static struct type *dbx_alloc_type (int[2], struct objfile *);
    119 
    120 static long read_huge_number (const char **, int, int *, int);
    121 
    122 static struct type *error_type (const char **, struct objfile *);
    123 
    124 static void
    125 patch_block_stabs (struct pending *, struct pending_stabs *,
    126 		   struct objfile *);
    127 
    128 static int read_type_number (const char **, int *);
    129 
    130 static struct type *read_type (const char **, struct objfile *);
    131 
    132 static struct type *read_range_type (const char **, int[2],
    133 				     int, struct objfile *);
    134 
    135 static struct type *read_sun_builtin_type (const char **,
    136 					   int[2], struct objfile *);
    137 
    138 static struct type *read_sun_floating_type (const char **, int[2],
    139 					    struct objfile *);
    140 
    141 static struct type *read_enum_type (const char **, struct type *, struct objfile *);
    142 
    143 static struct type *rs6000_builtin_type (int, struct objfile *);
    144 
    145 static int
    146 read_member_functions (struct stab_field_info *, const char **, struct type *,
    147 		       struct objfile *);
    148 
    149 static int
    150 read_struct_fields (struct stab_field_info *, const char **, struct type *,
    151 		    struct objfile *);
    152 
    153 static int
    154 read_baseclasses (struct stab_field_info *, const char **, struct type *,
    155 		  struct objfile *);
    156 
    157 static int
    158 read_tilde_fields (struct stab_field_info *, const char **, struct type *,
    159 		   struct objfile *);
    160 
    161 static int attach_fn_fields_to_type (struct stab_field_info *, struct type *);
    162 
    163 static int attach_fields_to_type (struct stab_field_info *, struct type *,
    164 				  struct objfile *);
    165 
    166 static struct type *read_struct_type (const char **, struct type *,
    167 				      enum type_code,
    168 				      struct objfile *);
    169 
    170 static struct type *read_array_type (const char **, struct type *,
    171 				     struct objfile *);
    172 
    173 static struct field *read_args (const char **, int, struct objfile *,
    174 				int *, int *);
    175 
    176 static void add_undefined_type (struct type *, int[2]);
    177 
    178 static int
    179 read_cpp_abbrev (struct stab_field_info *, const char **, struct type *,
    180 		 struct objfile *);
    181 
    182 static const char *find_name_end (const char *name);
    183 
    184 static int process_reference (const char **string);
    185 
    186 void stabsread_clear_cache (void);
    187 
    188 static const char vptr_name[] = "_vptr$";
    189 static const char vb_name[] = "_vb$";
    190 
    191 void
    192 unknown_symtype_complaint (const char *arg1)
    193 {
    194   complaint (_("unknown symbol type %s"), arg1);
    195 }
    196 
    197 void
    198 lbrac_mismatch_complaint (int arg1)
    199 {
    200   complaint (_("N_LBRAC/N_RBRAC symbol mismatch at symtab pos %d"), arg1);
    201 }
    202 
    203 void
    204 repeated_header_complaint (const char *arg1, int arg2)
    205 {
    206   complaint (_("\"repeated\" header file %s not "
    207 	       "previously seen, at symtab pos %d"),
    208 	     arg1, arg2);
    209 }
    210 
    211 static void
    212 invalid_cpp_abbrev_complaint (const char *arg1)
    213 {
    214   complaint (_("invalid C++ abbreviation `%s'"), arg1);
    215 }
    216 
    217 static void
    218 reg_value_complaint (int regnum, int num_regs, const char *sym)
    219 {
    220   complaint (_("bad register number %d (max %d) in symbol %s"),
    221 	     regnum, num_regs - 1, sym);
    222 }
    223 
    224 static void
    225 stabs_general_complaint (const char *arg1)
    226 {
    227   complaint ("%s", arg1);
    228 }
    229 
    230 static void
    231 function_outside_compilation_unit_complaint (const char *arg1)
    232 {
    233   complaint (_("function `%s' appears to be defined "
    234 	       "outside of all compilation units"),
    235 	     arg1);
    236 }
    237 
    238 /* Make a list of forward references which haven't been defined.  */
    239 
    240 static struct type **undef_types;
    241 static int undef_types_allocated;
    242 static int undef_types_length;
    243 static struct symbol *current_symbol = NULL;
    244 
    245 /* Make a list of nameless types that are undefined.
    246    This happens when another type is referenced by its number
    247    before this type is actually defined.  For instance "t(0,1)=k(0,2)"
    248    and type (0,2) is defined only later.  */
    249 
    250 struct nat
    251 {
    252   int typenums[2];
    253   struct type *type;
    254 };
    255 static struct nat *noname_undefs;
    256 static int noname_undefs_allocated;
    257 static int noname_undefs_length;
    258 
    259 /* Check for and handle cretinous stabs symbol name continuation!  */
    260 #define STABS_CONTINUE(pp,objfile)				\
    261   do {							\
    262     if (**(pp) == '\\' || (**(pp) == '?' && (*(pp))[1] == '\0')) \
    263       *(pp) = next_symbol_text (objfile);	\
    264   } while (0)
    265 
    266 /* Vector of types defined so far, indexed by their type numbers.
    267    (In newer sun systems, dbx uses a pair of numbers in parens,
    268    as in "(SUBFILENUM,NUMWITHINSUBFILE)".
    269    Then these numbers must be translated through the type_translations
    270    hash table to get the index into the type vector.)  */
    271 
    272 static struct type **type_vector;
    273 
    274 /* Number of elements allocated for type_vector currently.  */
    275 
    276 static int type_vector_length;
    277 
    278 /* Initial size of type vector.  Is realloc'd larger if needed, and
    279    realloc'd down to the size actually used, when completed.  */
    280 
    281 #define INITIAL_TYPE_VECTOR_LENGTH 160
    282 
    283 
    285 /* Look up a dbx type-number pair.  Return the address of the slot
    286    where the type for that number-pair is stored.
    287    The number-pair is in TYPENUMS.
    288 
    289    This can be used for finding the type associated with that pair
    290    or for associating a new type with the pair.  */
    291 
    292 static struct type **
    293 dbx_lookup_type (int typenums[2], struct objfile *objfile)
    294 {
    295   int filenum = typenums[0];
    296   int index = typenums[1];
    297   unsigned old_len;
    298   int real_filenum;
    299   struct header_file *f;
    300   int f_orig_length;
    301 
    302   if (filenum == -1)		/* -1,-1 is for temporary types.  */
    303     return 0;
    304 
    305   if (filenum < 0 || filenum >= n_this_object_header_files)
    306     {
    307       complaint (_("Invalid symbol data: type number "
    308 		   "(%d,%d) out of range at symtab pos %d."),
    309 		 filenum, index, symnum);
    310       goto error_return;
    311     }
    312 
    313   if (filenum == 0)
    314     {
    315       if (index < 0)
    316 	{
    317 	  /* Caller wants address of address of type.  We think
    318 	     that negative (rs6k builtin) types will never appear as
    319 	     "lvalues", (nor should they), so we stuff the real type
    320 	     pointer into a temp, and return its address.  If referenced,
    321 	     this will do the right thing.  */
    322 	  static struct type *temp_type;
    323 
    324 	  temp_type = rs6000_builtin_type (index, objfile);
    325 	  return &temp_type;
    326 	}
    327 
    328       /* Type is defined outside of header files.
    329 	 Find it in this object file's type vector.  */
    330       if (index >= type_vector_length)
    331 	{
    332 	  old_len = type_vector_length;
    333 	  if (old_len == 0)
    334 	    {
    335 	      type_vector_length = INITIAL_TYPE_VECTOR_LENGTH;
    336 	      type_vector = XNEWVEC (struct type *, type_vector_length);
    337 	    }
    338 	  while (index >= type_vector_length)
    339 	    {
    340 	      type_vector_length *= 2;
    341 	    }
    342 	  type_vector = (struct type **)
    343 	    xrealloc ((char *) type_vector,
    344 		      (type_vector_length * sizeof (struct type *)));
    345 	  memset (&type_vector[old_len], 0,
    346 		  (type_vector_length - old_len) * sizeof (struct type *));
    347 	}
    348       return (&type_vector[index]);
    349     }
    350   else
    351     {
    352       real_filenum = this_object_header_files[filenum];
    353 
    354       if (real_filenum >= N_HEADER_FILES (objfile))
    355 	{
    356 	  static struct type *temp_type;
    357 
    358 	  warning (_("GDB internal error: bad real_filenum"));
    359 
    360 	error_return:
    361 	  temp_type = builtin_type (objfile)->builtin_error;
    362 	  return &temp_type;
    363 	}
    364 
    365       f = HEADER_FILES (objfile) + real_filenum;
    366 
    367       f_orig_length = f->length;
    368       if (index >= f_orig_length)
    369 	{
    370 	  while (index >= f->length)
    371 	    {
    372 	      f->length *= 2;
    373 	    }
    374 	  f->vector = (struct type **)
    375 	    xrealloc ((char *) f->vector, f->length * sizeof (struct type *));
    376 	  memset (&f->vector[f_orig_length], 0,
    377 		  (f->length - f_orig_length) * sizeof (struct type *));
    378 	}
    379       return (&f->vector[index]);
    380     }
    381 }
    382 
    383 /* Make sure there is a type allocated for type numbers TYPENUMS
    384    and return the type object.
    385    This can create an empty (zeroed) type object.
    386    TYPENUMS may be (-1, -1) to return a new type object that is not
    387    put into the type vector, and so may not be referred to by number.  */
    388 
    389 static struct type *
    390 dbx_alloc_type (int typenums[2], struct objfile *objfile)
    391 {
    392   struct type **type_addr;
    393 
    394   if (typenums[0] == -1)
    395     {
    396       return type_allocator (objfile,
    397 			     get_current_subfile ()->language).new_type ();
    398     }
    399 
    400   type_addr = dbx_lookup_type (typenums, objfile);
    401 
    402   /* If we are referring to a type not known at all yet,
    403      allocate an empty type for it.
    404      We will fill it in later if we find out how.  */
    405   if (*type_addr == 0)
    406     {
    407       *type_addr = type_allocator (objfile,
    408 				   get_current_subfile ()->language).new_type ();
    409     }
    410 
    411   return (*type_addr);
    412 }
    413 
    414 /* Allocate a floating-point type of size BITS.  */
    415 
    416 static struct type *
    417 dbx_init_float_type (struct objfile *objfile, int bits)
    418 {
    419   struct gdbarch *gdbarch = objfile->arch ();
    420   const struct floatformat **format;
    421   struct type *type;
    422 
    423   format = gdbarch_floatformat_for_type (gdbarch, NULL, bits);
    424   type_allocator alloc (objfile, get_current_subfile ()->language);
    425   if (format)
    426     type = init_float_type (alloc, bits, NULL, format);
    427   else
    428     type = alloc.new_type (TYPE_CODE_ERROR, bits, NULL);
    429 
    430   return type;
    431 }
    432 
    433 /* for all the stabs in a given stab vector, build appropriate types
    434    and fix their symbols in given symbol vector.  */
    435 
    436 static void
    437 patch_block_stabs (struct pending *symbols, struct pending_stabs *stabs,
    438 		   struct objfile *objfile)
    439 {
    440   int ii;
    441   char *name;
    442   const char *pp;
    443   struct symbol *sym;
    444 
    445   if (stabs)
    446     {
    447       /* for all the stab entries, find their corresponding symbols and
    448 	 patch their types!  */
    449 
    450       for (ii = 0; ii < stabs->count; ++ii)
    451 	{
    452 	  name = stabs->stab[ii];
    453 	  pp = (char *) strchr (name, ':');
    454 	  gdb_assert (pp);	/* Must find a ':' or game's over.  */
    455 	  while (pp[1] == ':')
    456 	    {
    457 	      pp += 2;
    458 	      pp = (char *) strchr (pp, ':');
    459 	    }
    460 	  sym = find_symbol_in_list (symbols, name, pp - name);
    461 	  if (!sym)
    462 	    {
    463 	      /* FIXME-maybe: it would be nice if we noticed whether
    464 		 the variable was defined *anywhere*, not just whether
    465 		 it is defined in this compilation unit.  But neither
    466 		 xlc or GCC seem to need such a definition, and until
    467 		 we do psymtabs (so that the minimal symbols from all
    468 		 compilation units are available now), I'm not sure
    469 		 how to get the information.  */
    470 
    471 	      /* On xcoff, if a global is defined and never referenced,
    472 		 ld will remove it from the executable.  There is then
    473 		 a N_GSYM stab for it, but no regular (C_EXT) symbol.  */
    474 	      sym = new (&objfile->objfile_obstack) symbol;
    475 	      sym->set_domain (VAR_DOMAIN);
    476 	      sym->set_aclass_index (LOC_OPTIMIZED_OUT);
    477 	      sym->set_linkage_name
    478 		(obstack_strndup (&objfile->objfile_obstack, name, pp - name));
    479 	      pp += 2;
    480 	      if (*(pp - 1) == 'F' || *(pp - 1) == 'f')
    481 		{
    482 		  /* I don't think the linker does this with functions,
    483 		     so as far as I know this is never executed.
    484 		     But it doesn't hurt to check.  */
    485 		  sym->set_type
    486 		    (lookup_function_type (read_type (&pp, objfile)));
    487 		}
    488 	      else
    489 		{
    490 		  sym->set_type (read_type (&pp, objfile));
    491 		}
    492 	      add_symbol_to_list (sym, get_global_symbols ());
    493 	    }
    494 	  else
    495 	    {
    496 	      pp += 2;
    497 	      if (*(pp - 1) == 'F' || *(pp - 1) == 'f')
    498 		{
    499 		  sym->set_type
    500 		    (lookup_function_type (read_type (&pp, objfile)));
    501 		}
    502 	      else
    503 		{
    504 		  sym->set_type (read_type (&pp, objfile));
    505 		}
    506 	    }
    507 	}
    508     }
    509 }
    510 
    511 
    513 /* Read a number by which a type is referred to in dbx data,
    514    or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
    515    Just a single number N is equivalent to (0,N).
    516    Return the two numbers by storing them in the vector TYPENUMS.
    517    TYPENUMS will then be used as an argument to dbx_lookup_type.
    518 
    519    Returns 0 for success, -1 for error.  */
    520 
    521 static int
    522 read_type_number (const char **pp, int *typenums)
    523 {
    524   int nbits;
    525 
    526   if (**pp == '(')
    527     {
    528       (*pp)++;
    529       typenums[0] = read_huge_number (pp, ',', &nbits, 0);
    530       if (nbits != 0)
    531 	return -1;
    532       typenums[1] = read_huge_number (pp, ')', &nbits, 0);
    533       if (nbits != 0)
    534 	return -1;
    535     }
    536   else
    537     {
    538       typenums[0] = 0;
    539       typenums[1] = read_huge_number (pp, 0, &nbits, 0);
    540       if (nbits != 0)
    541 	return -1;
    542     }
    543   return 0;
    544 }
    545 
    546 
    548 /* Free up old header file tables.  */
    549 
    550 void
    551 free_header_files (void)
    552 {
    553   if (this_object_header_files)
    554     {
    555       xfree (this_object_header_files);
    556       this_object_header_files = NULL;
    557     }
    558   n_allocated_this_object_header_files = 0;
    559 }
    560 
    561 /* Allocate new header file tables.  */
    562 
    563 void
    564 init_header_files (void)
    565 {
    566   n_allocated_this_object_header_files = 10;
    567   this_object_header_files = XNEWVEC (int, 10);
    568 }
    569 
    570 /* Close off the current usage of PST.
    571    Returns PST or NULL if the partial symtab was empty and thrown away.
    572 
    573    FIXME:  List variables and peculiarities of same.  */
    574 
    575 legacy_psymtab *
    576 stabs_end_psymtab (struct objfile *objfile, psymtab_storage *partial_symtabs,
    577 		   legacy_psymtab *pst,
    578 		   const char **include_list, int num_includes,
    579 		   int capping_symbol_offset, unrelocated_addr capping_text,
    580 		   legacy_psymtab **dependency_list,
    581 		   int number_dependencies,
    582 		   int textlow_not_set)
    583 {
    584   int i;
    585   struct gdbarch *gdbarch = objfile->arch ();
    586   dbx_symfile_info *key = dbx_objfile_data_key. get (objfile);
    587 
    588   if (capping_symbol_offset != -1)
    589     LDSYMLEN (pst) = capping_symbol_offset - LDSYMOFF (pst);
    590   pst->set_text_high (capping_text);
    591 
    592   /* Under Solaris, the N_SO symbols always have a value of 0,
    593      instead of the usual address of the .o file.  Therefore,
    594      we have to do some tricks to fill in texthigh and textlow.
    595      The first trick is: if we see a static
    596      or global function, and the textlow for the current pst
    597      is not set (ie: textlow_not_set), then we use that function's
    598      address for the textlow of the pst.  */
    599 
    600   /* Now, to fill in texthigh, we remember the last function seen
    601      in the .o file.  Also, there's a hack in
    602      bfd/elf.c and gdb/elfread.c to pass the ELF st_size field
    603      to here via the misc_info field.  Therefore, we can fill in
    604      a reliable texthigh by taking the address plus size of the
    605      last function in the file.  */
    606 
    607   if (!pst->text_high_valid && key->ctx.last_function_name
    608       && gdbarch_sofun_address_maybe_missing (gdbarch))
    609     {
    610       int n;
    611 
    612       const char *colon = strchr (key->ctx.last_function_name, ':');
    613       if (colon == NULL)
    614 	n = 0;
    615       else
    616 	n = colon - key->ctx.last_function_name;
    617       char *p = (char *) alloca (n + 2);
    618       strncpy (p, key->ctx.last_function_name, n);
    619       p[n] = 0;
    620 
    621       bound_minimal_symbol minsym
    622 	= lookup_minimal_symbol (current_program_space, p, objfile,
    623 				 pst->filename);
    624       if (minsym.minsym == NULL)
    625 	{
    626 	  /* Sun Fortran appends an underscore to the minimal symbol name,
    627 	     try again with an appended underscore if the minimal symbol
    628 	     was not found.  */
    629 	  p[n] = '_';
    630 	  p[n + 1] = 0;
    631 	  minsym = lookup_minimal_symbol (current_program_space, p, objfile,
    632 					  pst->filename);
    633 	}
    634 
    635       if (minsym.minsym)
    636 	pst->set_text_high
    637 	  (unrelocated_addr (CORE_ADDR (minsym.minsym->unrelocated_address ())
    638 			     + minsym.minsym->size ()));
    639 
    640       key->ctx.last_function_name = NULL;
    641     }
    642 
    643   if (!gdbarch_sofun_address_maybe_missing (gdbarch))
    644     ;
    645   /* This test will be true if the last .o file is only data.  */
    646   else if (textlow_not_set)
    647     pst->set_text_low (pst->unrelocated_text_high ());
    648   else
    649     {
    650       /* If we know our own starting text address, then walk through all other
    651 	 psymtabs for this objfile, and if any didn't know their ending text
    652 	 address, set it to our starting address.  Take care to not set our
    653 	 own ending address to our starting address.  */
    654 
    655       for (partial_symtab *p1 : partial_symtabs->range ())
    656 	if (!p1->text_high_valid && p1->text_low_valid && p1 != pst)
    657 	  p1->set_text_high (pst->unrelocated_text_low ());
    658     }
    659 
    660   /* End of kludge for patching Solaris textlow and texthigh.  */
    661 
    662   pst->end ();
    663 
    664   pst->number_of_dependencies = number_dependencies;
    665   if (number_dependencies)
    666     {
    667       pst->dependencies
    668 	= partial_symtabs->allocate_dependencies (number_dependencies);
    669       memcpy (pst->dependencies, dependency_list,
    670 	      number_dependencies * sizeof (legacy_psymtab *));
    671     }
    672   else
    673     pst->dependencies = 0;
    674 
    675   for (i = 0; i < num_includes; i++)
    676     {
    677       legacy_psymtab *subpst =
    678 	new legacy_psymtab (include_list[i], partial_symtabs, objfile->per_bfd);
    679 
    680       subpst->read_symtab_private =
    681 	XOBNEW (&objfile->objfile_obstack, struct symloc);
    682       LDSYMOFF (subpst) =
    683 	LDSYMLEN (subpst) = 0;
    684 
    685       /* We could save slight bits of space by only making one of these,
    686 	 shared by the entire set of include files.  FIXME-someday.  */
    687       subpst->dependencies =
    688 	partial_symtabs->allocate_dependencies (1);
    689       subpst->dependencies[0] = pst;
    690       subpst->number_of_dependencies = 1;
    691 
    692       subpst->legacy_read_symtab = pst->legacy_read_symtab;
    693       subpst->legacy_expand_psymtab = pst->legacy_expand_psymtab;
    694     }
    695 
    696   if (num_includes == 0
    697       && number_dependencies == 0
    698       && pst->empty ()
    699       && key->ctx.has_line_numbers == 0)
    700     {
    701       /* Throw away this psymtab, it's empty.  */
    702       /* Empty psymtabs happen as a result of header files which don't have
    703 	 any symbols in them.  There can be a lot of them.  But this check
    704 	 is wrong, in that a psymtab with N_SLINE entries but nothing else
    705 	 is not empty, but we don't realize that.  Fixing that without slowing
    706 	 things down might be tricky.  */
    707 
    708       partial_symtabs->discard_psymtab (pst);
    709 
    710       /* Indicate that psymtab was thrown away.  */
    711       pst = NULL;
    712     }
    713   return pst;
    714 }
    715 
    716 /* Set namestring based on nlist.  If the string table index is invalid,
    717    give a fake name, and print a single error message per symbol file read,
    718    rather than abort the symbol reading or flood the user with messages.  */
    719 
    720 static const char *
    721 set_namestring (struct objfile *objfile, const struct internal_nlist *nlist)
    722 {
    723   const char *namestring;
    724   struct dbx_symfile_info *key = dbx_objfile_data_key.get (objfile);
    725 
    726   if (nlist->n_strx + key->ctx.file_string_table_offset
    727       >= DBX_STRINGTAB_SIZE (objfile)
    728       || nlist->n_strx + key->ctx.file_string_table_offset < nlist->n_strx)
    729     {
    730       complaint (_("bad string table offset in symbol %d"),
    731 		 symnum);
    732       namestring = "<bad string table offset>";
    733     }
    734   else
    735     namestring = (nlist->n_strx + key->ctx.file_string_table_offset
    736 		  + DBX_STRINGTAB (objfile));
    737   return namestring;
    738 }
    739 
    740 static void
    741 stabs_seek (int sym_offset, struct objfile *objfile)
    742 {
    743   dbx_symfile_info *key = dbx_objfile_data_key.get (objfile);
    744   if (key->ctx.stabs_data)
    745     {
    746       key->ctx.symbuf_read += sym_offset;
    747       key->ctx.symbuf_left -= sym_offset;
    748     }
    749   else
    750     if (bfd_seek (objfile->obfd.get (), sym_offset, SEEK_CUR) != 0)
    751       perror_with_name (bfd_get_filename (objfile->obfd.get ()));
    752 }
    753 
    754 /* Buffer for reading the symbol table entries.  */
    755 static struct external_nlist symbuf[4096];
    756 static int symbuf_idx;
    757 static int symbuf_end;
    758 
    759 /* Refill the symbol table input buffer
    760    and set the variables that control fetching entries from it.
    761    Reports an error if no data available.
    762    This function can read past the end of the symbol table
    763    (into the string table) but this does no harm.  */
    764 
    765 static void
    766 fill_symbuf (bfd *sym_bfd, struct objfile *objfile)
    767 {
    768   unsigned int count;
    769   int nbytes;
    770   struct dbx_symfile_info *key = dbx_objfile_data_key.get (objfile);
    771 
    772   if (key->ctx.stabs_data)
    773     {
    774       nbytes = sizeof (symbuf);
    775       if (nbytes > key->ctx.symbuf_left)
    776 	nbytes = key->ctx.symbuf_left;
    777       memcpy (symbuf, key->ctx.stabs_data + key->ctx.symbuf_read, nbytes);
    778     }
    779   else if (key->ctx.symbuf_sections == NULL)
    780     {
    781       count = sizeof (symbuf);
    782       nbytes = bfd_read (symbuf, count, sym_bfd);
    783     }
    784   else
    785     {
    786       if (key->ctx.symbuf_left <= 0)
    787 	{
    788 	  file_ptr filepos = (*key->ctx.symbuf_sections)[key->ctx.sect_idx]->filepos;
    789 
    790 	  if (bfd_seek (sym_bfd, filepos, SEEK_SET) != 0)
    791 	    perror_with_name (bfd_get_filename (sym_bfd));
    792 	  key->ctx.symbuf_left = bfd_section_size ((*key->ctx.symbuf_sections)[key->ctx.sect_idx]);
    793 	  key->ctx.symbol_table_offset = filepos - key->ctx.symbuf_read;
    794 	  ++key->ctx.sect_idx;
    795 	}
    796 
    797       count = key->ctx.symbuf_left;
    798       if (count > sizeof (symbuf))
    799 	count = sizeof (symbuf);
    800       nbytes = bfd_read (symbuf, count, sym_bfd);
    801     }
    802 
    803   if (nbytes < 0)
    804     perror_with_name (bfd_get_filename (sym_bfd));
    805   else if (nbytes == 0)
    806     error (_("Premature end of file reading symbol table"));
    807   symbuf_end = nbytes / key->ctx.symbol_size;
    808   symbuf_idx = 0;
    809   key->ctx.symbuf_left -= nbytes;
    810   key->ctx.symbuf_read += nbytes;
    811 }
    812 
    813 /* Read in a defined section of a specific object file's symbols.  */
    814 
    815 static void
    816 read_ofile_symtab (struct objfile *objfile, legacy_psymtab *pst)
    817 {
    818   const char *namestring;
    819   struct external_nlist *bufp;
    820   struct internal_nlist nlist;
    821   unsigned char type;
    822   unsigned max_symnum;
    823   bfd *abfd;
    824   int sym_offset;		/* Offset to start of symbols to read */
    825   int sym_size;			/* Size of symbols to read */
    826   CORE_ADDR text_offset;	/* Start of text segment for symbols */
    827   int text_size;		/* Size of text segment for symbols */
    828   struct dbx_symfile_info *key = dbx_objfile_data_key.get (objfile);
    829 
    830   sym_offset = LDSYMOFF (pst);
    831   sym_size = LDSYMLEN (pst);
    832   text_offset = pst->text_low (objfile);
    833   text_size = pst->text_high (objfile) - pst->text_low (objfile);
    834   const section_offsets &section_offsets = objfile->section_offsets;
    835 
    836   key->ctx.stringtab_global = DBX_STRINGTAB (objfile);
    837   set_last_source_file (NULL);
    838 
    839   abfd = objfile->obfd.get ();
    840   symbuf_end = symbuf_idx = 0;
    841   key->ctx.symbuf_read = 0;
    842   key->ctx.symbuf_left = sym_offset + sym_size;
    843 
    844   /* It is necessary to actually read one symbol *before* the start
    845      of this symtab's symbols, because the GCC_COMPILED_FLAG_SYMBOL
    846      occurs before the N_SO symbol.
    847 
    848      Detecting this in read_stabs_symtab
    849      would slow down initial readin, so we look for it here instead.  */
    850   if (!key->ctx.processing_acc_compilation && sym_offset >= (int) key->ctx.symbol_size)
    851     {
    852       stabs_seek (sym_offset - key->ctx.symbol_size, objfile);
    853       fill_symbuf (abfd, objfile);
    854       bufp = &symbuf[symbuf_idx++];
    855       INTERNALIZE_SYMBOL (nlist, bufp, abfd);
    856       OBJSTAT (objfile, n_stabs++);
    857 
    858       namestring = set_namestring (objfile, &nlist);
    859 
    860       processing_gcc_compilation = 0;
    861       if (nlist.n_type == N_TEXT)
    862 	{
    863 	  const char *tempstring = namestring;
    864 
    865 	  if (strcmp (namestring, GCC_COMPILED_FLAG_SYMBOL) == 0)
    866 	    processing_gcc_compilation = 1;
    867 	  else if (strcmp (namestring, GCC2_COMPILED_FLAG_SYMBOL) == 0)
    868 	    processing_gcc_compilation = 2;
    869 	  if (*tempstring != '\0'
    870 	      && *tempstring == bfd_get_symbol_leading_char (objfile->obfd.get ()))
    871 	    ++tempstring;
    872 	  if (startswith (tempstring, "__gnu_compiled"))
    873 	    processing_gcc_compilation = 2;
    874 	}
    875     }
    876   else
    877     {
    878       /* The N_SO starting this symtab is the first symbol, so we
    879 	 better not check the symbol before it.  I'm not this can
    880 	 happen, but it doesn't hurt to check for it.  */
    881       stabs_seek (sym_offset, objfile);
    882       processing_gcc_compilation = 0;
    883     }
    884 
    885   if (symbuf_idx == symbuf_end)
    886     fill_symbuf (abfd, objfile);
    887   bufp = &symbuf[symbuf_idx];
    888   if (bfd_h_get_8 (abfd, bufp->e_type) != N_SO)
    889     error (_("First symbol in segment of executable not a source symbol"));
    890 
    891   max_symnum = sym_size / key->ctx.symbol_size;
    892 
    893   for (symnum = 0;
    894        symnum < max_symnum;
    895        symnum++)
    896     {
    897       QUIT;			/* Allow this to be interruptable.  */
    898       if (symbuf_idx == symbuf_end)
    899 	fill_symbuf (abfd, objfile);
    900       bufp = &symbuf[symbuf_idx++];
    901       INTERNALIZE_SYMBOL (nlist, bufp, abfd);
    902       OBJSTAT (objfile, n_stabs++);
    903 
    904       type = bfd_h_get_8 (abfd, bufp->e_type);
    905 
    906       namestring = set_namestring (objfile, &nlist);
    907 
    908       if (type & N_STAB)
    909 	{
    910 	  if (sizeof (nlist.n_value) > 4
    911 	      /* We are a 64-bit debugger debugging a 32-bit program.  */
    912 	      && (type == N_LSYM || type == N_PSYM))
    913 	      /* We have to be careful with the n_value in the case of N_LSYM
    914 		 and N_PSYM entries, because they are signed offsets from frame
    915 		 pointer, but we actually read them as unsigned 32-bit values.
    916 		 This is not a problem for 32-bit debuggers, for which negative
    917 		 values end up being interpreted correctly (as negative
    918 		 offsets) due to integer overflow.
    919 		 But we need to sign-extend the value for 64-bit debuggers,
    920 		 or we'll end up interpreting negative values as very large
    921 		 positive offsets.  */
    922 	    nlist.n_value = (nlist.n_value ^ 0x80000000) - 0x80000000;
    923 	  process_one_symbol (type, nlist.n_desc, nlist.n_value,
    924 			      namestring, section_offsets, objfile,
    925 			      PST_LANGUAGE (pst));
    926 	}
    927       /* We skip checking for a new .o or -l file; that should never
    928 	 happen in this routine.  */
    929       else if (type == N_TEXT)
    930 	{
    931 	  /* I don't think this code will ever be executed, because
    932 	     the GCC_COMPILED_FLAG_SYMBOL usually is right before
    933 	     the N_SO symbol which starts this source file.
    934 	     However, there is no reason not to accept
    935 	     the GCC_COMPILED_FLAG_SYMBOL anywhere.  */
    936 
    937 	  if (strcmp (namestring, GCC_COMPILED_FLAG_SYMBOL) == 0)
    938 	    processing_gcc_compilation = 1;
    939 	  else if (strcmp (namestring, GCC2_COMPILED_FLAG_SYMBOL) == 0)
    940 	    processing_gcc_compilation = 2;
    941 	}
    942       else if (type & N_EXT || type == (unsigned char) N_TEXT
    943 	       || type == (unsigned char) N_NBTEXT)
    944 	{
    945 	  /* Global symbol: see if we came across a dbx definition for
    946 	     a corresponding symbol.  If so, store the value.  Remove
    947 	     syms from the chain when their values are stored, but
    948 	     search the whole chain, as there may be several syms from
    949 	     different files with the same name.  */
    950 	  /* This is probably not true.  Since the files will be read
    951 	     in one at a time, each reference to a global symbol will
    952 	     be satisfied in each file as it appears.  So we skip this
    953 	     section.  */
    954 	  ;
    955 	}
    956     }
    957 
    958   /* In a Solaris elf file, this variable, which comes from the value
    959      of the N_SO symbol, will still be 0.  Luckily, text_offset, which
    960      comes from low text address of PST, is correct.  */
    961   if (get_last_source_start_addr () == 0)
    962     set_last_source_start_addr (text_offset);
    963 
    964   /* In reordered executables last_source_start_addr may not be the
    965      lower bound for this symtab, instead use text_offset which comes
    966      from the low text address of PST, which is correct.  */
    967   if (get_last_source_start_addr () > text_offset)
    968     set_last_source_start_addr (text_offset);
    969 
    970   pst->compunit_symtab = end_compunit_symtab (text_offset + text_size);
    971 
    972   end_stabs ();
    973 
    974 }
    975 
    976 static void
    977 dbx_expand_psymtab (legacy_psymtab *pst, struct objfile *objfile)
    978 {
    979   gdb_assert (!pst->readin);
    980   struct dbx_symfile_info *key = dbx_objfile_data_key.get (objfile);
    981 
    982   /* Read in all partial symtabs on which this one is dependent.  */
    983   pst->expand_dependencies (objfile);
    984 
    985   if (LDSYMLEN (pst))		/* Otherwise it's a dummy.  */
    986     {
    987       /* Init stuff necessary for reading in symbols */
    988       stabsread_init ();
    989       scoped_free_pendings free_pending;
    990       key->ctx.file_string_table_offset = FILE_STRING_OFFSET (pst);
    991       key->ctx.symbol_size = SYMBOL_SIZE (pst);
    992 
    993       /* Read in this file's symbols.  */
    994       if (bfd_seek (objfile->obfd.get (), SYMBOL_OFFSET (pst), SEEK_SET) == 0)
    995 	read_ofile_symtab (objfile, pst);
    996     }
    997 
    998   pst->readin = true;
    999 }
   1000 
   1001 /* Invariant: The symbol pointed to by symbuf_idx is the first one
   1002    that hasn't been swapped.  Swap the symbol at the same time
   1003    that symbuf_idx is incremented.  */
   1004 
   1005 /* dbx allows the text of a symbol name to be continued into the
   1006    next symbol name!  When such a continuation is encountered
   1007    (a \ at the end of the text of a name)
   1008    call this function to get the continuation.  */
   1009 
   1010 static const char *
   1011 dbx_next_symbol_text (struct objfile *objfile)
   1012 {
   1013   struct internal_nlist nlist;
   1014   dbx_symfile_info *key = dbx_objfile_data_key.get (objfile);
   1015 
   1016   if (symbuf_idx == symbuf_end)
   1017     fill_symbuf (objfile->obfd.get (), objfile);
   1018 
   1019   symnum++;
   1020   INTERNALIZE_SYMBOL (nlist, &symbuf[symbuf_idx], objfile->obfd.get ());
   1021   OBJSTAT (objfile, n_stabs++);
   1022 
   1023   symbuf_idx++;
   1024 
   1025   return nlist.n_strx + key->ctx.stringtab_global
   1026     + key->ctx.file_string_table_offset;
   1027 }
   1028 
   1029 /* Read in all of the symbols for a given psymtab for real.
   1030    Be verbose about it if the user wants that.  SELF is not NULL.  */
   1031 
   1032 static void
   1033 stabs_read_symtab (legacy_psymtab *self, struct objfile *objfile)
   1034 {
   1035   gdb_assert (!self->readin);
   1036 
   1037   if (LDSYMLEN (self) || self->number_of_dependencies)
   1038     {
   1039       next_symbol_text_func = dbx_next_symbol_text;
   1040       dbx_symfile_info *key = dbx_objfile_data_key.get (objfile);
   1041 
   1042       {
   1043 	scoped_restore restore_stabs_data = make_scoped_restore (&key->ctx.stabs_data);
   1044 	gdb::unique_xmalloc_ptr<gdb_byte> data_holder;
   1045 	if (DBX_STAB_SECTION (objfile))
   1046 	  {
   1047 	    key->ctx.stabs_data
   1048 	      = symfile_relocate_debug_section (objfile,
   1049 						DBX_STAB_SECTION (objfile),
   1050 						NULL);
   1051 	    data_holder.reset (key->ctx.stabs_data);
   1052 	  }
   1053 
   1054 	self->expand_psymtab (objfile);
   1055       }
   1056 
   1057       /* Match with global symbols.  This only needs to be done once,
   1058 	 after all of the symtabs and dependencies have been read in.   */
   1059       scan_file_globals (objfile);
   1060     }
   1061 }
   1062 
   1063 static void
   1064 record_minimal_symbol (minimal_symbol_reader &reader,
   1065 		       const char *name, unrelocated_addr address, int type,
   1066 		       struct objfile *objfile)
   1067 {
   1068   enum minimal_symbol_type ms_type;
   1069   int section;
   1070   struct dbx_symfile_info *key = dbx_objfile_data_key.get (objfile);
   1071 
   1072   switch (type)
   1073     {
   1074     case N_TEXT | N_EXT:
   1075       ms_type = mst_text;
   1076       section = SECT_OFF_TEXT (objfile);
   1077       break;
   1078     case N_DATA | N_EXT:
   1079       ms_type = mst_data;
   1080       section = SECT_OFF_DATA (objfile);
   1081       break;
   1082     case N_BSS | N_EXT:
   1083       ms_type = mst_bss;
   1084       section = SECT_OFF_BSS (objfile);
   1085       break;
   1086     case N_ABS | N_EXT:
   1087       ms_type = mst_abs;
   1088       section = -1;
   1089       break;
   1090 #ifdef N_SETV
   1091     case N_SETV | N_EXT:
   1092       ms_type = mst_data;
   1093       section = SECT_OFF_DATA (objfile);
   1094       break;
   1095     case N_SETV:
   1096       /* I don't think this type actually exists; since a N_SETV is the result
   1097 	 of going over many .o files, it doesn't make sense to have one
   1098 	 file local.  */
   1099       ms_type = mst_file_data;
   1100       section = SECT_OFF_DATA (objfile);
   1101       break;
   1102 #endif
   1103     case N_TEXT:
   1104     case N_NBTEXT:
   1105     case N_FN:
   1106     case N_FN_SEQ:
   1107       ms_type = mst_file_text;
   1108       section = SECT_OFF_TEXT (objfile);
   1109       break;
   1110     case N_DATA:
   1111       ms_type = mst_file_data;
   1112 
   1113       /* Check for __DYNAMIC, which is used by Sun shared libraries.
   1114 	 Record it as global even if it's local, not global, so
   1115 	 lookup_minimal_symbol can find it.  We don't check symbol_leading_char
   1116 	 because for SunOS4 it always is '_'.  */
   1117       if (strcmp ("__DYNAMIC", name) == 0)
   1118 	ms_type = mst_data;
   1119 
   1120       /* Same with virtual function tables, both global and static.  */
   1121       {
   1122 	const char *tempstring = name;
   1123 
   1124 	if (*tempstring != '\0'
   1125 	    && *tempstring == bfd_get_symbol_leading_char (objfile->obfd.get ()))
   1126 	  ++tempstring;
   1127 	if (is_vtable_name (tempstring))
   1128 	  ms_type = mst_data;
   1129       }
   1130       section = SECT_OFF_DATA (objfile);
   1131       break;
   1132     case N_BSS:
   1133       ms_type = mst_file_bss;
   1134       section = SECT_OFF_BSS (objfile);
   1135       break;
   1136     default:
   1137       ms_type = mst_unknown;
   1138       section = -1;
   1139       break;
   1140     }
   1141 
   1142   if ((ms_type == mst_file_text || ms_type == mst_text)
   1143       && address < key->ctx.lowest_text_address)
   1144     key->ctx.lowest_text_address = address;
   1145 
   1146   reader.record_with_info (name, address, ms_type, section);
   1147 }
   1148 
   1149 /* Given a name, value pair, find the corresponding
   1150    bincl in the list.  Return the partial symtab associated
   1151    with that header_file_location.  */
   1152 
   1153 static legacy_psymtab *
   1154 find_corresponding_bincl_psymtab (const char *name, int instance,
   1155 				  struct objfile* objfile)
   1156 {
   1157   stabsread_context ctx = dbx_objfile_data_key.get (objfile) -> ctx;
   1158   for (const header_file_location &bincl : ctx.bincl_list)
   1159     if (bincl.instance == instance
   1160 	&& strcmp (name, bincl.name) == 0)
   1161       return bincl.pst;
   1162 
   1163   repeated_header_complaint (name, symnum);
   1164   return (legacy_psymtab *) 0;
   1165 }
   1166 
   1167 /* Allocate and partially fill a partial symtab.  It will be
   1168    completely filled at the end of the symbol list.
   1169 
   1170    SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
   1171    is the address relative to which its symbols are (incremental) or 0
   1172    (normal).  */
   1173 
   1174 static legacy_psymtab *
   1175 start_psymtab (psymtab_storage *partial_symtabs, struct objfile *objfile,
   1176 	       const char *filename, unrelocated_addr textlow, int ldsymoff)
   1177 {
   1178   legacy_psymtab *result = new legacy_psymtab (filename, partial_symtabs,
   1179 					       objfile->per_bfd, textlow);
   1180 
   1181   struct dbx_symfile_info *key = dbx_objfile_data_key.get(objfile);
   1182 
   1183   result->read_symtab_private =
   1184     XOBNEW (&objfile->objfile_obstack, struct symloc);
   1185   LDSYMOFF (result) = ldsymoff;
   1186   result->legacy_read_symtab = stabs_read_symtab;
   1187   result->legacy_expand_psymtab = dbx_expand_psymtab;
   1188   SYMBOL_SIZE (result) = key->ctx.symbol_size;
   1189   SYMBOL_OFFSET (result) = key->ctx.symbol_table_offset;
   1190   STRING_OFFSET (result) = 0; /* This used to be an uninitialized global.  */
   1191   FILE_STRING_OFFSET (result) = key->ctx.file_string_table_offset;
   1192 
   1193   /* Deduce the source language from the filename for this psymtab.  */
   1194   key->ctx.psymtab_language = deduce_language_from_filename (filename);
   1195   PST_LANGUAGE (result) = key->ctx.psymtab_language;
   1196 
   1197   return result;
   1198 }
   1199 
   1200 /* See stabsread.h. */
   1201 
   1202 static void
   1203 read_stabs_symtab_1 (minimal_symbol_reader &reader,
   1204 		     psymtab_storage *partial_symtabs,
   1205 		     struct objfile *objfile)
   1206 {
   1207   struct gdbarch *gdbarch = objfile->arch ();
   1208   struct external_nlist *bufp = 0;	/* =0 avoids gcc -Wall glitch.  */
   1209   struct internal_nlist nlist;
   1210   CORE_ADDR text_addr;
   1211   int text_size;
   1212   const char *sym_name;
   1213   int sym_len;
   1214   unsigned int next_file_string_table_offset = 0;
   1215   struct dbx_symfile_info *dbx = dbx_objfile_data_key.get(objfile);
   1216 
   1217   const char *namestring;
   1218   int nsl;
   1219   int past_first_source_file = 0;
   1220   CORE_ADDR last_function_start = 0;
   1221   bfd *abfd;
   1222   int textlow_not_set;
   1223   int data_sect_index;
   1224 
   1225   /* Current partial symtab.  */
   1226   legacy_psymtab *pst;
   1227 
   1228   /* List of current psymtab's include files.  */
   1229   const char **psymtab_include_list;
   1230   int includes_allocated;
   1231   int includes_used;
   1232 
   1233   /* Index within current psymtab dependency list.  */
   1234   legacy_psymtab **dependency_list;
   1235   int dependencies_used, dependencies_allocated;
   1236 
   1237   text_addr = DBX_TEXT_ADDR (objfile);
   1238   text_size = DBX_TEXT_SIZE (objfile);
   1239 
   1240   /* FIXME.  We probably want to change stringtab_global rather than add this
   1241      while processing every symbol entry.  FIXME.  */
   1242   dbx->ctx.file_string_table_offset = 0;
   1243 
   1244   dbx->ctx.stringtab_global = DBX_STRINGTAB (objfile);
   1245 
   1246   pst = (legacy_psymtab *) 0;
   1247 
   1248   includes_allocated = 30;
   1249   includes_used = 0;
   1250   psymtab_include_list = (const char **) alloca (includes_allocated *
   1251 						 sizeof (const char *));
   1252 
   1253   dependencies_allocated = 30;
   1254   dependencies_used = 0;
   1255   dependency_list =
   1256     (legacy_psymtab **) alloca (dependencies_allocated *
   1257 				sizeof (legacy_psymtab *));
   1258 
   1259   /* Init bincl list */
   1260   std::vector<struct header_file_location> bincl_storage;
   1261   scoped_restore restore_bincl_global
   1262     = make_scoped_restore (&(dbx->ctx.bincl_list), bincl_storage);
   1263 
   1264   set_last_source_file (NULL);
   1265 
   1266   dbx->ctx.lowest_text_address = (unrelocated_addr) -1;
   1267 
   1268   abfd = objfile->obfd.get ();
   1269   symbuf_end = symbuf_idx = 0;
   1270   next_symbol_text_func = dbx_next_symbol_text;
   1271   textlow_not_set = 1;
   1272   dbx->ctx.has_line_numbers = 0;
   1273 
   1274   /* FIXME: jimb/2003-09-12: We don't apply the right section's offset
   1275      to global and static variables.  The stab for a global or static
   1276      variable doesn't give us any indication of which section it's in,
   1277      so we can't tell immediately which offset in
   1278      objfile->section_offsets we should apply to the variable's
   1279      address.
   1280 
   1281      We could certainly find out which section contains the variable
   1282      by looking up the variable's unrelocated address with
   1283      find_pc_section, but that would be expensive; this is the
   1284      function that constructs the partial symbol tables by examining
   1285      every symbol in the entire executable, and it's
   1286      performance-critical.  So that expense would not be welcome.  I'm
   1287      not sure what to do about this at the moment.
   1288 
   1289      What we have done for years is to simply assume that the .data
   1290      section's offset is appropriate for all global and static
   1291      variables.  Recently, this was expanded to fall back to the .bss
   1292      section's offset if there is no .data section, and then to the
   1293      .rodata section's offset.  */
   1294   data_sect_index = objfile->sect_index_data;
   1295   if (data_sect_index == -1)
   1296     data_sect_index = SECT_OFF_BSS (objfile);
   1297   if (data_sect_index == -1)
   1298     data_sect_index = SECT_OFF_RODATA (objfile);
   1299 
   1300   /* If data_sect_index is still -1, that's okay.  It's perfectly fine
   1301      for the file to have no .data, no .bss, and no .text at all, if
   1302      it also has no global or static variables.  */
   1303 
   1304   for (symnum = 0; symnum < DBX_SYMCOUNT (objfile); symnum++)
   1305     {
   1306       /* Get the symbol for this run and pull out some info.  */
   1307       QUIT;			/* Allow this to be interruptable.  */
   1308       if (symbuf_idx == symbuf_end)
   1309 	fill_symbuf (abfd, objfile);
   1310       bufp = &symbuf[symbuf_idx++];
   1311 
   1312       /*
   1313        * Special case to speed up readin.
   1314        */
   1315       if (bfd_h_get_8 (abfd, bufp->e_type) == N_SLINE)
   1316 	{
   1317 	  dbx->ctx.has_line_numbers = 1;
   1318 	  continue;
   1319 	}
   1320 
   1321       INTERNALIZE_SYMBOL (nlist, bufp, abfd);
   1322       OBJSTAT (objfile, n_stabs++);
   1323 
   1324       /* Ok.  There is a lot of code duplicated in the rest of this
   1325 	 switch statement (for efficiency reasons).  Since I don't
   1326 	 like duplicating code, I will do my penance here, and
   1327 	 describe the code which is duplicated:
   1328 
   1329 	 *) The assignment to namestring.
   1330 	 *) The call to strchr.
   1331 	 *) The addition of a partial symbol the two partial
   1332 	 symbol lists.  This last is a large section of code, so
   1333 	 I've embedded it in the following macro.  */
   1334 
   1335       switch (nlist.n_type)
   1336 	{
   1337 	  /*
   1338 	   * Standard, external, non-debugger, symbols
   1339 	   */
   1340 
   1341 	case N_TEXT | N_EXT:
   1342 	case N_NBTEXT | N_EXT:
   1343 	  goto record_it;
   1344 
   1345 	case N_DATA | N_EXT:
   1346 	case N_NBDATA | N_EXT:
   1347 	  goto record_it;
   1348 
   1349 	case N_BSS:
   1350 	case N_BSS | N_EXT:
   1351 	case N_NBBSS | N_EXT:
   1352 	case N_SETV | N_EXT:		/* FIXME, is this in BSS? */
   1353 	  goto record_it;
   1354 
   1355 	case N_ABS | N_EXT:
   1356 	  record_it:
   1357 	  namestring = set_namestring (objfile, &nlist);
   1358 
   1359 	  record_minimal_symbol (reader, namestring,
   1360 				 unrelocated_addr (nlist.n_value),
   1361 				 nlist.n_type, objfile);	/* Always */
   1362 	  continue;
   1363 
   1364 	  /* Standard, local, non-debugger, symbols.  */
   1365 
   1366 	case N_NBTEXT:
   1367 
   1368 	  /* We need to be able to deal with both N_FN or N_TEXT,
   1369 	     because we have no way of knowing whether the sys-supplied ld
   1370 	     or GNU ld was used to make the executable.  Sequents throw
   1371 	     in another wrinkle -- they renumbered N_FN.  */
   1372 
   1373 	case N_FN:
   1374 	case N_FN_SEQ:
   1375 	case N_TEXT:
   1376 	  namestring = set_namestring (objfile, &nlist);
   1377 
   1378 	  if ((namestring[0] == '-' && namestring[1] == 'l')
   1379 	      || (namestring[(nsl = strlen (namestring)) - 1] == 'o'
   1380 		  && namestring[nsl - 2] == '.'))
   1381 	    {
   1382 	      unrelocated_addr unrel_val = unrelocated_addr (nlist.n_value);
   1383 
   1384 	      if (past_first_source_file && pst
   1385 		  /* The gould NP1 uses low values for .o and -l symbols
   1386 		     which are not the address.  */
   1387 		  && unrel_val >= pst->unrelocated_text_low ())
   1388 		{
   1389 		  stabs_end_psymtab (objfile, partial_symtabs,
   1390 				     pst, psymtab_include_list,
   1391 				     includes_used, symnum * dbx->ctx.symbol_size,
   1392 				     unrel_val > pst->unrelocated_text_high ()
   1393 				     ? unrel_val : pst->unrelocated_text_high (),
   1394 				     dependency_list, dependencies_used,
   1395 				     textlow_not_set);
   1396 		  pst = (legacy_psymtab *) 0;
   1397 		  includes_used = 0;
   1398 		  dependencies_used = 0;
   1399 		  dbx->ctx.has_line_numbers = 0;
   1400 		}
   1401 	      else
   1402 		past_first_source_file = 1;
   1403 	    }
   1404 	  else
   1405 	    goto record_it;
   1406 	  continue;
   1407 
   1408 	case N_DATA:
   1409 	  goto record_it;
   1410 
   1411 	case N_UNDF | N_EXT:
   1412 	  /* The case (nlist.n_value != 0) is a "Fortran COMMON" symbol.
   1413 	     We used to rely on the target to tell us whether it knows
   1414 	     where the symbol has been relocated to, but none of the
   1415 	     target implementations actually provided that operation.
   1416 	     So we just ignore the symbol, the same way we would do if
   1417 	     we had a target-side symbol lookup which returned no match.
   1418 
   1419 	     All other symbols (with nlist.n_value == 0), are really
   1420 	     undefined, and so we ignore them too.  */
   1421 	  continue;
   1422 
   1423 	case N_UNDF:
   1424 	  if (dbx->ctx.processing_acc_compilation && nlist.n_strx == 1)
   1425 	    {
   1426 	      /* Deal with relative offsets in the string table
   1427 		 used in ELF+STAB under Solaris.  If we want to use the
   1428 		 n_strx field, which contains the name of the file,
   1429 		 we must adjust file_string_table_offset *before* calling
   1430 		 set_namestring().  */
   1431 	      past_first_source_file = 1;
   1432 	      dbx->ctx.file_string_table_offset = next_file_string_table_offset;
   1433 	     next_file_string_table_offset =
   1434 		dbx->ctx.file_string_table_offset + nlist.n_value;
   1435 	      if (next_file_string_table_offset < dbx->ctx.file_string_table_offset)
   1436 		error (_("string table offset backs up at %d"), symnum);
   1437 	      /* FIXME -- replace error() with complaint.  */
   1438 	      continue;
   1439 	    }
   1440 	  continue;
   1441 
   1442 	  /* Lots of symbol types we can just ignore.  */
   1443 
   1444 	case N_ABS:
   1445 	case N_NBDATA:
   1446 	case N_NBBSS:
   1447 	  continue;
   1448 
   1449 	  /* Keep going . . .  */
   1450 
   1451 	  /*
   1452 	   * Special symbol types for GNU
   1453 	   */
   1454 	case N_INDR:
   1455 	case N_INDR | N_EXT:
   1456 	case N_SETA:
   1457 	case N_SETA | N_EXT:
   1458 	case N_SETT:
   1459 	case N_SETT | N_EXT:
   1460 	case N_SETD:
   1461 	case N_SETD | N_EXT:
   1462 	case N_SETB:
   1463 	case N_SETB | N_EXT:
   1464 	case N_SETV:
   1465 	  continue;
   1466 
   1467 	  /*
   1468 	   * Debugger symbols
   1469 	   */
   1470 
   1471 	case N_SO:
   1472 	  {
   1473 	    CORE_ADDR valu;
   1474 	    static int prev_so_symnum = -10;
   1475 	    static int first_so_symnum;
   1476 	    const char *p;
   1477 	    static const char *dirname_nso;
   1478 	    int prev_textlow_not_set;
   1479 
   1480 	    valu = nlist.n_value;
   1481 
   1482 	    prev_textlow_not_set = textlow_not_set;
   1483 
   1484 	    /* A zero value is probably an indication for the SunPRO 3.0
   1485 	       compiler.  stabs_end_psymtab explicitly tests for zero, so
   1486 	       don't relocate it.  */
   1487 
   1488 	    if (nlist.n_value == 0
   1489 		&& gdbarch_sofun_address_maybe_missing (gdbarch))
   1490 	      {
   1491 		textlow_not_set = 1;
   1492 		valu = 0;
   1493 	      }
   1494 	    else
   1495 	      textlow_not_set = 0;
   1496 
   1497 	    past_first_source_file = 1;
   1498 
   1499 	    if (prev_so_symnum != symnum - 1)
   1500 	      {			/* Here if prev stab wasn't N_SO.  */
   1501 		first_so_symnum = symnum;
   1502 
   1503 		if (pst)
   1504 		  {
   1505 		    unrelocated_addr unrel_value = unrelocated_addr (valu);
   1506 		    stabs_end_psymtab (objfile, partial_symtabs,
   1507 				       pst, psymtab_include_list,
   1508 				       includes_used, symnum * dbx->ctx.symbol_size,
   1509 				       unrel_value > pst->unrelocated_text_high ()
   1510 				       ? unrel_value
   1511 				       : pst->unrelocated_text_high (),
   1512 				       dependency_list, dependencies_used,
   1513 				       prev_textlow_not_set);
   1514 		    pst = (legacy_psymtab *) 0;
   1515 		    includes_used = 0;
   1516 		    dependencies_used = 0;
   1517 		    dbx->ctx.has_line_numbers = 0;
   1518 		  }
   1519 	      }
   1520 
   1521 	    prev_so_symnum = symnum;
   1522 
   1523 	    /* End the current partial symtab and start a new one.  */
   1524 
   1525 	    namestring = set_namestring (objfile, &nlist);
   1526 
   1527 	    /* Null name means end of .o file.  Don't start a new one.  */
   1528 	    if (*namestring == '\000')
   1529 	      continue;
   1530 
   1531 	    /* Some compilers (including gcc) emit a pair of initial N_SOs.
   1532 	       The first one is a directory name; the second the file name.
   1533 	       If pst exists, is empty, and has a filename ending in '/',
   1534 	       we assume the previous N_SO was a directory name.  */
   1535 
   1536 	    p = lbasename (namestring);
   1537 	    if (p != namestring && *p == '\000')
   1538 	      {
   1539 		/* Save the directory name SOs locally, then save it into
   1540 		   the psymtab when it's created below.  */
   1541 		dirname_nso = namestring;
   1542 		continue;
   1543 	      }
   1544 
   1545 	    /* Some other compilers (C++ ones in particular) emit useless
   1546 	       SOs for non-existant .c files.  We ignore all subsequent SOs
   1547 	       that immediately follow the first.  */
   1548 
   1549 	    if (!pst)
   1550 	      {
   1551 		pst = start_psymtab (partial_symtabs, objfile,
   1552 				     namestring,
   1553 				     unrelocated_addr (valu),
   1554 				     first_so_symnum * dbx->ctx.symbol_size);
   1555 		pst->dirname = dirname_nso;
   1556 		dirname_nso = NULL;
   1557 	      }
   1558 	    continue;
   1559 	  }
   1560 
   1561 	case N_BINCL:
   1562 	  {
   1563 	    enum language tmp_language;
   1564 
   1565 	    /* Add this bincl to the bincl_list for future EXCLs.  No
   1566 	       need to save the string; it'll be around until
   1567 	       read_stabs_symtab function returns.  */
   1568 
   1569 	    namestring = set_namestring (objfile, &nlist);
   1570 	    tmp_language = deduce_language_from_filename (namestring);
   1571 
   1572 	    /* Only change the psymtab's language if we've learned
   1573 	       something useful (eg. tmp_language is not language_unknown).
   1574 	       In addition, to match what start_subfile does, never change
   1575 	       from C++ to C.  */
   1576 	    if (tmp_language != language_unknown
   1577 		&& (tmp_language != language_c
   1578 		    || dbx->ctx.psymtab_language != language_cplus))
   1579 	      dbx->ctx.psymtab_language = tmp_language;
   1580 
   1581 	    if (pst == NULL)
   1582 	      {
   1583 		/* FIXME: we should not get here without a PST to work on.
   1584 		   Attempt to recover.  */
   1585 		complaint (_("N_BINCL %s not in entries for "
   1586 			     "any file, at symtab pos %d"),
   1587 			   namestring, symnum);
   1588 		continue;
   1589 	      }
   1590 	    dbx->ctx.bincl_list.emplace_back (namestring, nlist.n_value, pst);
   1591 
   1592 	    /* Mark down an include file in the current psymtab.  */
   1593 
   1594 	    goto record_include_file;
   1595 	  }
   1596 
   1597 	case N_SOL:
   1598 	  {
   1599 	    enum language tmp_language;
   1600 
   1601 	    /* Mark down an include file in the current psymtab.  */
   1602 	    namestring = set_namestring (objfile, &nlist);
   1603 	    tmp_language = deduce_language_from_filename (namestring);
   1604 
   1605 	    /* Only change the psymtab's language if we've learned
   1606 	       something useful (eg. tmp_language is not language_unknown).
   1607 	       In addition, to match what start_subfile does, never change
   1608 	       from C++ to C.  */
   1609 	    if (tmp_language != language_unknown
   1610 		&& (tmp_language != language_c
   1611 		    || dbx->ctx.psymtab_language != language_cplus))
   1612 	      dbx->ctx.psymtab_language = tmp_language;
   1613 
   1614 	    /* In C++, one may expect the same filename to come round many
   1615 	       times, when code is coming alternately from the main file
   1616 	       and from inline functions in other files.  So I check to see
   1617 	       if this is a file we've seen before -- either the main
   1618 	       source file, or a previously included file.
   1619 
   1620 	       This seems to be a lot of time to be spending on N_SOL, but
   1621 	       things like "break c-exp.y:435" need to work (I
   1622 	       suppose the psymtab_include_list could be hashed or put
   1623 	       in a binary tree, if profiling shows this is a major hog).  */
   1624 	    if (pst && filename_cmp (namestring, pst->filename) == 0)
   1625 	      continue;
   1626 	    {
   1627 	      int i;
   1628 
   1629 	      for (i = 0; i < includes_used; i++)
   1630 		if (filename_cmp (namestring, psymtab_include_list[i]) == 0)
   1631 		  {
   1632 		    i = -1;
   1633 		    break;
   1634 		  }
   1635 	      if (i == -1)
   1636 		continue;
   1637 	    }
   1638 
   1639 	  record_include_file:
   1640 
   1641 	    psymtab_include_list[includes_used++] = namestring;
   1642 	    if (includes_used >= includes_allocated)
   1643 	      {
   1644 		const char **orig = psymtab_include_list;
   1645 
   1646 		psymtab_include_list = (const char **)
   1647 		  alloca ((includes_allocated *= 2) * sizeof (const char *));
   1648 		memcpy (psymtab_include_list, orig,
   1649 			includes_used * sizeof (const char *));
   1650 	      }
   1651 	    continue;
   1652 	  }
   1653 	case N_LSYM:		/* Typedef or automatic variable.  */
   1654 	case N_STSYM:		/* Data seg var -- static.  */
   1655 	case N_LCSYM:		/* BSS      "  */
   1656 	case N_ROSYM:		/* Read-only data seg var -- static.  */
   1657 	case N_NBSTS:		/* Gould nobase.  */
   1658 	case N_NBLCS:		/* symbols.  */
   1659 	case N_FUN:
   1660 	case N_GSYM:		/* Global (extern) variable; can be
   1661 				   data or bss (sigh FIXME).  */
   1662 
   1663 	  /* Following may probably be ignored; I'll leave them here
   1664 	     for now (until I do Pascal and Modula 2 extensions).  */
   1665 
   1666 	case N_PC:		/* I may or may not need this; I
   1667 				   suspect not.  */
   1668 	case N_M2C:		/* I suspect that I can ignore this here.  */
   1669 	case N_SCOPE:		/* Same.   */
   1670 	{
   1671 	  const char *p;
   1672 
   1673 	  namestring = set_namestring (objfile, &nlist);
   1674 
   1675 	  /* See if this is an end of function stab.  */
   1676 	  if (pst && nlist.n_type == N_FUN && *namestring == '\000')
   1677 	    {
   1678 	      unrelocated_addr valu;
   1679 
   1680 	      /* It's value is the size (in bytes) of the function for
   1681 		 function relative stabs, or the address of the function's
   1682 		 end for old style stabs.  */
   1683 	      valu = unrelocated_addr (nlist.n_value + last_function_start);
   1684 	      if (pst->unrelocated_text_high () == unrelocated_addr (0)
   1685 		  || valu > pst->unrelocated_text_high ())
   1686 		pst->set_text_high (valu);
   1687 	      break;
   1688 	    }
   1689 
   1690 	  p = (char *) strchr (namestring, ':');
   1691 	  if (!p)
   1692 	    continue;		/* Not a debugging symbol.   */
   1693 
   1694 	  sym_len = 0;
   1695 	  sym_name = NULL;	/* pacify "gcc -Werror" */
   1696 	  if (dbx->ctx.psymtab_language == language_cplus)
   1697 	    {
   1698 	      std::string name (namestring, p - namestring);
   1699 	      gdb::unique_xmalloc_ptr<char> new_name
   1700 		= cp_canonicalize_string (name.c_str ());
   1701 	      if (new_name != nullptr)
   1702 		{
   1703 		  sym_len = strlen (new_name.get ());
   1704 		  sym_name = obstack_strdup (&objfile->objfile_obstack,
   1705 					     new_name.get ());
   1706 		}
   1707 	    }
   1708 	  else if (dbx->ctx.psymtab_language == language_c)
   1709 	    {
   1710 	      std::string name (namestring, p - namestring);
   1711 	      gdb::unique_xmalloc_ptr<char> new_name
   1712 		= c_canonicalize_name (name.c_str ());
   1713 	      if (new_name != nullptr)
   1714 		{
   1715 		  sym_len = strlen (new_name.get ());
   1716 		  sym_name = obstack_strdup (&objfile->objfile_obstack,
   1717 					     new_name.get ());
   1718 		}
   1719 	    }
   1720 
   1721 	  if (sym_len == 0)
   1722 	    {
   1723 	      sym_name = namestring;
   1724 	      sym_len = p - namestring;
   1725 	    }
   1726 
   1727 	  /* Main processing section for debugging symbols which
   1728 	     the initial read through the symbol tables needs to worry
   1729 	     about.  If we reach this point, the symbol which we are
   1730 	     considering is definitely one we are interested in.
   1731 	     p must also contain the (valid) index into the namestring
   1732 	     which indicates the debugging type symbol.  */
   1733 
   1734 	  switch (p[1])
   1735 	    {
   1736 	    case 'S':
   1737 	      if (pst != nullptr)
   1738 		pst->add_psymbol (std::string_view (sym_name, sym_len), true,
   1739 				  VAR_DOMAIN, LOC_STATIC,
   1740 				  data_sect_index,
   1741 				  psymbol_placement::STATIC,
   1742 				  unrelocated_addr (nlist.n_value),
   1743 				  dbx->ctx.psymtab_language,
   1744 				  partial_symtabs, objfile);
   1745 	      else
   1746 		complaint (_("static `%*s' appears to be defined "
   1747 			     "outside of all compilation units"),
   1748 			   sym_len, sym_name);
   1749 	      continue;
   1750 
   1751 	    case 'G':
   1752 	      /* The addresses in these entries are reported to be
   1753 		 wrong.  See the code that reads 'G's for symtabs.  */
   1754 	      if (pst != nullptr)
   1755 		pst->add_psymbol (std::string_view (sym_name, sym_len), true,
   1756 				  VAR_DOMAIN, LOC_STATIC,
   1757 				  data_sect_index,
   1758 				  psymbol_placement::GLOBAL,
   1759 				  unrelocated_addr (nlist.n_value),
   1760 				  dbx->ctx.psymtab_language,
   1761 				  partial_symtabs, objfile);
   1762 	      else
   1763 		complaint (_("global `%*s' appears to be defined "
   1764 			     "outside of all compilation units"),
   1765 			   sym_len, sym_name);
   1766 	      continue;
   1767 
   1768 	    case 'T':
   1769 	      /* When a 'T' entry is defining an anonymous enum, it
   1770 		 may have a name which is the empty string, or a
   1771 		 single space.  Since they're not really defining a
   1772 		 symbol, those shouldn't go in the partial symbol
   1773 		 table.  We do pick up the elements of such enums at
   1774 		 'check_enum:', below.  */
   1775 	      if (p >= namestring + 2
   1776 		  || (p == namestring + 1
   1777 		      && namestring[0] != ' '))
   1778 		{
   1779 		  if (pst != nullptr)
   1780 		    pst->add_psymbol (std::string_view (sym_name, sym_len),
   1781 				      true, STRUCT_DOMAIN, LOC_TYPEDEF, -1,
   1782 				      psymbol_placement::STATIC,
   1783 				      unrelocated_addr (0),
   1784 				      dbx->ctx.psymtab_language,
   1785 				      partial_symtabs, objfile);
   1786 		  else
   1787 		    complaint (_("enum, struct, or union `%*s' appears "
   1788 				 "to be defined outside of all "
   1789 				 "compilation units"),
   1790 			       sym_len, sym_name);
   1791 		  if (p[2] == 't')
   1792 		    {
   1793 		      /* Also a typedef with the same name.  */
   1794 		      if (pst != nullptr)
   1795 			pst->add_psymbol (std::string_view (sym_name, sym_len),
   1796 					  true, VAR_DOMAIN, LOC_TYPEDEF, -1,
   1797 					  psymbol_placement::STATIC,
   1798 					  unrelocated_addr (0),
   1799 					  dbx->ctx.psymtab_language,
   1800 					  partial_symtabs, objfile);
   1801 		      else
   1802 			complaint (_("typedef `%*s' appears to be defined "
   1803 				     "outside of all compilation units"),
   1804 				   sym_len, sym_name);
   1805 		      p += 1;
   1806 		    }
   1807 		}
   1808 	      goto check_enum;
   1809 
   1810 	    case 't':
   1811 	      if (p != namestring)	/* a name is there, not just :T...  */
   1812 		{
   1813 		  if (pst != nullptr)
   1814 		    pst->add_psymbol (std::string_view (sym_name, sym_len),
   1815 				      true, VAR_DOMAIN, LOC_TYPEDEF, -1,
   1816 				      psymbol_placement::STATIC,
   1817 				      unrelocated_addr (0),
   1818 				      dbx->ctx.psymtab_language,
   1819 				      partial_symtabs, objfile);
   1820 		  else
   1821 		    complaint (_("typename `%*s' appears to be defined "
   1822 				 "outside of all compilation units"),
   1823 			       sym_len, sym_name);
   1824 		}
   1825 	    check_enum:
   1826 	      /* If this is an enumerated type, we need to
   1827 		 add all the enum constants to the partial symbol
   1828 		 table.  This does not cover enums without names, e.g.
   1829 		 "enum {a, b} c;" in C, but fortunately those are
   1830 		 rare.  There is no way for GDB to find those from the
   1831 		 enum type without spending too much time on it.  Thus
   1832 		 to solve this problem, the compiler needs to put out the
   1833 		 enum in a nameless type.  GCC2 does this.  */
   1834 
   1835 	      /* We are looking for something of the form
   1836 		 <name> ":" ("t" | "T") [<number> "="] "e"
   1837 		 {<constant> ":" <value> ","} ";".  */
   1838 
   1839 	      /* Skip over the colon and the 't' or 'T'.  */
   1840 	      p += 2;
   1841 	      /* This type may be given a number.  Also, numbers can come
   1842 		 in pairs like (0,26).  Skip over it.  */
   1843 	      while ((*p >= '0' && *p <= '9')
   1844 		     || *p == '(' || *p == ',' || *p == ')'
   1845 		     || *p == '=')
   1846 		p++;
   1847 
   1848 	      if (*p++ == 'e')
   1849 		{
   1850 		  /* The aix4 compiler emits extra crud before the members.  */
   1851 		  if (*p == '-')
   1852 		    {
   1853 		      /* Skip over the type (?).  */
   1854 		      while (*p != ':')
   1855 			p++;
   1856 
   1857 		      /* Skip over the colon.  */
   1858 		      p++;
   1859 		    }
   1860 
   1861 		  /* We have found an enumerated type.  */
   1862 		  /* According to comments in read_enum_type
   1863 		     a comma could end it instead of a semicolon.
   1864 		     I don't know where that happens.
   1865 		     Accept either.  */
   1866 		  while (*p && *p != ';' && *p != ',')
   1867 		    {
   1868 		      const char *q;
   1869 
   1870 		      /* Check for and handle cretinous dbx symbol name
   1871 			 continuation!  */
   1872 		      if (*p == '\\' || (*p == '?' && p[1] == '\0'))
   1873 			p = next_symbol_text (objfile);
   1874 
   1875 		      /* Point to the character after the name
   1876 			 of the enum constant.  */
   1877 		      for (q = p; *q && *q != ':'; q++)
   1878 			;
   1879 		      /* Note that the value doesn't matter for
   1880 			 enum constants in psymtabs, just in symtabs.  */
   1881 		      if (pst != nullptr)
   1882 			pst->add_psymbol (std::string_view (p, q - p), true,
   1883 					  VAR_DOMAIN, LOC_CONST, -1,
   1884 					  psymbol_placement::STATIC,
   1885 					  unrelocated_addr (0),
   1886 					  dbx->ctx.psymtab_language,
   1887 					  partial_symtabs, objfile);
   1888 		      else
   1889 			complaint (_("enum constant `%*s' appears to be defined "
   1890 				     "outside of all compilation units"),
   1891 				   ((int) (q - p)), p);
   1892 		      /* Point past the name.  */
   1893 		      p = q;
   1894 		      /* Skip over the value.  */
   1895 		      while (*p && *p != ',')
   1896 			p++;
   1897 		      /* Advance past the comma.  */
   1898 		      if (*p)
   1899 			p++;
   1900 		    }
   1901 		}
   1902 	      continue;
   1903 
   1904 	    case 'c':
   1905 	      /* Constant, e.g. from "const" in Pascal.  */
   1906 	      if (pst != nullptr)
   1907 		pst->add_psymbol (std::string_view (sym_name, sym_len), true,
   1908 				  VAR_DOMAIN, LOC_CONST, -1,
   1909 				  psymbol_placement::STATIC,
   1910 				  unrelocated_addr (0),
   1911 				  dbx->ctx.psymtab_language,
   1912 				  partial_symtabs, objfile);
   1913 	      else
   1914 		complaint (_("constant `%*s' appears to be defined "
   1915 			     "outside of all compilation units"),
   1916 			   sym_len, sym_name);
   1917 
   1918 	      continue;
   1919 
   1920 	    case 'f':
   1921 	      if (! pst)
   1922 		{
   1923 		  std::string name (namestring, (p - namestring));
   1924 		  function_outside_compilation_unit_complaint (name.c_str ());
   1925 		}
   1926 	      /* Kludges for ELF/STABS with Sun ACC.  */
   1927 	      dbx->ctx.last_function_name = namestring;
   1928 	      /* Do not fix textlow==0 for .o or NLM files, as 0 is a legit
   1929 		 value for the bottom of the text seg in those cases.  */
   1930 	      if (nlist.n_value == 0
   1931 		  && gdbarch_sofun_address_maybe_missing (gdbarch))
   1932 		{
   1933 		  bound_minimal_symbol minsym
   1934 		    = find_stab_function (namestring,
   1935 					  pst ? pst->filename : NULL, objfile);
   1936 		  if (minsym.minsym != NULL)
   1937 		    nlist.n_value
   1938 		      = CORE_ADDR (minsym.minsym->unrelocated_address ());
   1939 		}
   1940 	      if (pst && textlow_not_set
   1941 		  && gdbarch_sofun_address_maybe_missing (gdbarch))
   1942 		{
   1943 		  pst->set_text_low (unrelocated_addr (nlist.n_value));
   1944 		  textlow_not_set = 0;
   1945 		}
   1946 	      /* End kludge.  */
   1947 
   1948 	      /* Keep track of the start of the last function so we
   1949 		 can handle end of function symbols.  */
   1950 	      last_function_start = nlist.n_value;
   1951 
   1952 	      /* In reordered executables this function may lie outside
   1953 		 the bounds created by N_SO symbols.  If that's the case
   1954 		 use the address of this function as the low bound for
   1955 		 the partial symbol table.  */
   1956 	      if (pst
   1957 		  && (textlow_not_set
   1958 		      || (unrelocated_addr (nlist.n_value)
   1959 			  < pst->unrelocated_text_low ()
   1960 			  && (nlist.n_value != 0))))
   1961 		{
   1962 		  pst->set_text_low (unrelocated_addr (nlist.n_value));
   1963 		  textlow_not_set = 0;
   1964 		}
   1965 	      if (pst != nullptr)
   1966 		pst->add_psymbol (std::string_view (sym_name, sym_len), true,
   1967 				  VAR_DOMAIN, LOC_BLOCK,
   1968 				  SECT_OFF_TEXT (objfile),
   1969 				  psymbol_placement::STATIC,
   1970 				  unrelocated_addr (nlist.n_value),
   1971 				  dbx->ctx.psymtab_language,
   1972 				  partial_symtabs, objfile);
   1973 	      continue;
   1974 
   1975 	      /* Global functions were ignored here, but now they
   1976 		 are put into the global psymtab like one would expect.
   1977 		 They're also in the minimal symbol table.  */
   1978 	    case 'F':
   1979 	      if (! pst)
   1980 		{
   1981 		  std::string name (namestring, (p - namestring));
   1982 		  function_outside_compilation_unit_complaint (name.c_str ());
   1983 		}
   1984 	      /* Kludges for ELF/STABS with Sun ACC.  */
   1985 	      dbx->ctx.last_function_name = namestring;
   1986 	      /* Do not fix textlow==0 for .o or NLM files, as 0 is a legit
   1987 		 value for the bottom of the text seg in those cases.  */
   1988 	      if (nlist.n_value == 0
   1989 		  && gdbarch_sofun_address_maybe_missing (gdbarch))
   1990 		{
   1991 		  bound_minimal_symbol minsym
   1992 		    = find_stab_function (namestring,
   1993 					  pst ? pst->filename : NULL, objfile);
   1994 		  if (minsym.minsym != NULL)
   1995 		    nlist.n_value
   1996 		      = CORE_ADDR (minsym.minsym->unrelocated_address ());
   1997 		}
   1998 	      if (pst && textlow_not_set
   1999 		  && gdbarch_sofun_address_maybe_missing (gdbarch))
   2000 		{
   2001 		  pst->set_text_low (unrelocated_addr (nlist.n_value));
   2002 		  textlow_not_set = 0;
   2003 		}
   2004 	      /* End kludge.  */
   2005 
   2006 	      /* Keep track of the start of the last function so we
   2007 		 can handle end of function symbols.  */
   2008 	      last_function_start = nlist.n_value;
   2009 
   2010 	      /* In reordered executables this function may lie outside
   2011 		 the bounds created by N_SO symbols.  If that's the case
   2012 		 use the address of this function as the low bound for
   2013 		 the partial symbol table.  */
   2014 	      if (pst
   2015 		  && (textlow_not_set
   2016 		      || (unrelocated_addr (nlist.n_value)
   2017 			  < pst->unrelocated_text_low ()
   2018 			  && (nlist.n_value != 0))))
   2019 		{
   2020 		  pst->set_text_low (unrelocated_addr (nlist.n_value));
   2021 		  textlow_not_set = 0;
   2022 		}
   2023 	      if (pst != nullptr)
   2024 		pst->add_psymbol (std::string_view (sym_name, sym_len), true,
   2025 				  VAR_DOMAIN, LOC_BLOCK,
   2026 				  SECT_OFF_TEXT (objfile),
   2027 				  psymbol_placement::GLOBAL,
   2028 				  unrelocated_addr (nlist.n_value),
   2029 				  dbx->ctx.psymtab_language,
   2030 				  partial_symtabs, objfile);
   2031 	      continue;
   2032 
   2033 	      /* Two things show up here (hopefully); static symbols of
   2034 		 local scope (static used inside braces) or extensions
   2035 		 of structure symbols.  We can ignore both.  */
   2036 	    case 'V':
   2037 	    case '(':
   2038 	    case '0':
   2039 	    case '1':
   2040 	    case '2':
   2041 	    case '3':
   2042 	    case '4':
   2043 	    case '5':
   2044 	    case '6':
   2045 	    case '7':
   2046 	    case '8':
   2047 	    case '9':
   2048 	    case '-':
   2049 	    case '#':	/* For symbol identification (used in live ranges).  */
   2050 	      continue;
   2051 
   2052 	    case ':':
   2053 	      /* It is a C++ nested symbol.  We don't need to record it
   2054 		 (I don't think); if we try to look up foo::bar::baz,
   2055 		 then symbols for the symtab containing foo should get
   2056 		 read in, I think.  */
   2057 	      /* Someone says sun cc puts out symbols like
   2058 		 /foo/baz/maclib::/usr/local/bin/maclib,
   2059 		 which would get here with a symbol type of ':'.  */
   2060 	      continue;
   2061 
   2062 	    default:
   2063 	      /* Unexpected symbol descriptor.  The second and subsequent stabs
   2064 		 of a continued stab can show up here.  The question is
   2065 		 whether they ever can mimic a normal stab--it would be
   2066 		 nice if not, since we certainly don't want to spend the
   2067 		 time searching to the end of every string looking for
   2068 		 a backslash.  */
   2069 
   2070 	      complaint (_("unknown symbol descriptor `%c'"),
   2071 			 p[1]);
   2072 
   2073 	      /* Ignore it; perhaps it is an extension that we don't
   2074 		 know about.  */
   2075 	      continue;
   2076 	    }
   2077 	}
   2078 
   2079 	case N_EXCL:
   2080 
   2081 	  namestring = set_namestring (objfile, &nlist);
   2082 
   2083 	  /* Find the corresponding bincl and mark that psymtab on the
   2084 	     psymtab dependency list.  */
   2085 	  {
   2086 	    legacy_psymtab *needed_pst =
   2087 	      find_corresponding_bincl_psymtab (namestring, nlist.n_value, objfile);
   2088 
   2089 	    /* If this include file was defined earlier in this file,
   2090 	       leave it alone.  */
   2091 	    if (needed_pst == pst)
   2092 	      continue;
   2093 
   2094 	    if (needed_pst)
   2095 	      {
   2096 		int i;
   2097 		int found = 0;
   2098 
   2099 		for (i = 0; i < dependencies_used; i++)
   2100 		  if (dependency_list[i] == needed_pst)
   2101 		    {
   2102 		      found = 1;
   2103 		      break;
   2104 		    }
   2105 
   2106 		/* If it's already in the list, skip the rest.  */
   2107 		if (found)
   2108 		  continue;
   2109 
   2110 		dependency_list[dependencies_used++] = needed_pst;
   2111 		if (dependencies_used >= dependencies_allocated)
   2112 		  {
   2113 		    legacy_psymtab **orig = dependency_list;
   2114 
   2115 		    dependency_list =
   2116 		      (legacy_psymtab **)
   2117 		      alloca ((dependencies_allocated *= 2)
   2118 			      * sizeof (legacy_psymtab *));
   2119 		    memcpy (dependency_list, orig,
   2120 			    (dependencies_used
   2121 			     * sizeof (legacy_psymtab *)));
   2122 #ifdef DEBUG_INFO
   2123 		    gdb_printf (gdb_stderr,
   2124 				"Had to reallocate "
   2125 				"dependency list.\n");
   2126 		    gdb_printf (gdb_stderr,
   2127 				"New dependencies allocated: %d\n",
   2128 				dependencies_allocated);
   2129 #endif
   2130 		  }
   2131 	      }
   2132 	  }
   2133 	  continue;
   2134 
   2135 	case N_ENDM:
   2136 	  /* Solaris 2 end of module, finish current partial symbol
   2137 	     table.  stabs_end_psymtab will set the high text address of
   2138 	     PST to the proper value, which is necessary if a module
   2139 	     compiled without debugging info follows this module.  */
   2140 	  if (pst && gdbarch_sofun_address_maybe_missing (gdbarch))
   2141 	    {
   2142 	      stabs_end_psymtab (objfile, partial_symtabs, pst,
   2143 				 psymtab_include_list, includes_used,
   2144 				 symnum * dbx->ctx.symbol_size,
   2145 				 (unrelocated_addr) 0, dependency_list,
   2146 				 dependencies_used, textlow_not_set);
   2147 	      pst = (legacy_psymtab *) 0;
   2148 	      includes_used = 0;
   2149 	      dependencies_used = 0;
   2150 	      dbx->ctx.has_line_numbers = 0;
   2151 	    }
   2152 	  continue;
   2153 
   2154 	case N_RBRAC:
   2155 #ifdef HANDLE_RBRAC
   2156 	  HANDLE_RBRAC (nlist.n_value);
   2157 	  continue;
   2158 #endif
   2159 	case N_EINCL:
   2160 	case N_DSLINE:
   2161 	case N_BSLINE:
   2162 	case N_SSYM:		/* Claim: Structure or union element.
   2163 				   Hopefully, I can ignore this.  */
   2164 	case N_ENTRY:		/* Alternate entry point; can ignore.  */
   2165 	case N_MAIN:		/* Can definitely ignore this.   */
   2166 	case N_CATCH:		/* These are GNU C++ extensions */
   2167 	case N_EHDECL:		/* that can safely be ignored here.  */
   2168 	case N_LENG:
   2169 	case N_BCOMM:
   2170 	case N_ECOMM:
   2171 	case N_ECOML:
   2172 	case N_FNAME:
   2173 	case N_SLINE:
   2174 	case N_RSYM:
   2175 	case N_PSYM:
   2176 	case N_BNSYM:
   2177 	case N_ENSYM:
   2178 	case N_LBRAC:
   2179 	case N_NSYMS:		/* Ultrix 4.0: symbol count */
   2180 	case N_DEFD:		/* GNU Modula-2 */
   2181 	case N_ALIAS:		/* SunPro F77: alias name, ignore for now.  */
   2182 
   2183 	case N_OBJ:		/* Useless types from Solaris.  */
   2184 	case N_OPT:
   2185 	case N_PATCH:
   2186 	  /* These symbols aren't interesting; don't worry about them.  */
   2187 	  continue;
   2188 
   2189 	default:
   2190 	  /* If we haven't found it yet, ignore it.  It's probably some
   2191 	     new type we don't know about yet.  */
   2192 	  unknown_symtype_complaint (hex_string (nlist.n_type));
   2193 	  continue;
   2194 	}
   2195     }
   2196 
   2197   /* If there's stuff to be cleaned up, clean it up.  */
   2198   if (pst)
   2199     {
   2200       /* Don't set high text address of PST lower than it already
   2201 	 is.  */
   2202       unrelocated_addr text_end
   2203 	= (unrelocated_addr
   2204 	   ((dbx->ctx.lowest_text_address == (unrelocated_addr) -1
   2205 	     ? text_addr
   2206 	     : CORE_ADDR (dbx->ctx.lowest_text_address))
   2207 	    + text_size));
   2208 
   2209       stabs_end_psymtab (objfile, partial_symtabs,
   2210 			 pst, psymtab_include_list, includes_used,
   2211 			 symnum * dbx->ctx.symbol_size,
   2212 			 (text_end > pst->unrelocated_text_high ()
   2213 			  ? text_end : pst->unrelocated_text_high ()),
   2214 			 dependency_list, dependencies_used, textlow_not_set);
   2215     }
   2216 }
   2217 
   2218 /* Scan and build partial symbols for a symbol file.
   2219    We have been initialized by a call to dbx_symfile_init, which
   2220    put all the relevant info into a "struct dbx_symfile_info",
   2221    hung off the objfile structure.  */
   2222 
   2223 void
   2224 read_stabs_symtab (struct objfile *objfile, symfile_add_flags symfile_flags)
   2225 {
   2226   bfd *sym_bfd;
   2227   int val;
   2228   struct dbx_symfile_info *key = dbx_objfile_data_key.get (objfile);
   2229 
   2230   sym_bfd = objfile->obfd.get ();
   2231 
   2232   /* .o and .nlm files are relocatables with text, data and bss segs based at
   2233      0.  This flag disables special (Solaris stabs-in-elf only) fixups for
   2234      symbols with a value of 0.  */
   2235 
   2236   key->ctx.symfile_relocatable = bfd_get_file_flags (sym_bfd) & HAS_RELOC;
   2237 
   2238   val = bfd_seek (sym_bfd, DBX_SYMTAB_OFFSET (objfile), SEEK_SET);
   2239   if (val < 0)
   2240     perror_with_name (objfile_name (objfile));
   2241 
   2242   key->ctx.symbol_size = DBX_SYMBOL_SIZE (objfile);
   2243   key->ctx.symbol_table_offset = DBX_SYMTAB_OFFSET (objfile);
   2244 
   2245   scoped_free_pendings free_pending;
   2246 
   2247   minimal_symbol_reader reader (objfile);
   2248 
   2249   /* Read stabs data from executable file and define symbols.  */
   2250 
   2251   psymbol_functions *psf = new psymbol_functions ();
   2252   psymtab_storage *partial_symtabs = psf->get_partial_symtabs ().get ();
   2253   objfile->qf.emplace_front (psf);
   2254   read_stabs_symtab_1 (reader, partial_symtabs, objfile);
   2255 
   2256   /* Install any minimal symbols that have been collected as the current
   2257      minimal symbols for this objfile.  */
   2258 
   2259   reader.install ();
   2260 }
   2261 
   2262 /* Record the namespace that the function defined by SYMBOL was
   2263    defined in, if necessary.  BLOCK is the associated block; use
   2264    OBSTACK for allocation.  */
   2265 
   2266 static void
   2267 cp_set_block_scope (const struct symbol *symbol,
   2268 		    struct block *block,
   2269 		    struct obstack *obstack)
   2270 {
   2271   if (symbol->demangled_name () != NULL)
   2272     {
   2273       /* Try to figure out the appropriate namespace from the
   2274 	 demangled name.  */
   2275 
   2276       /* FIXME: carlton/2003-04-15: If the function in question is
   2277 	 a method of a class, the name will actually include the
   2278 	 name of the class as well.  This should be harmless, but
   2279 	 is a little unfortunate.  */
   2280 
   2281       const char *name = symbol->demangled_name ();
   2282       unsigned int prefix_len = cp_entire_prefix_len (name);
   2283 
   2284       block->set_scope (obstack_strndup (obstack, name, prefix_len),
   2285 			obstack);
   2286     }
   2287 }
   2288 
   2289 bound_minimal_symbol
   2290 find_stab_function (const char *namestring, const char *filename,
   2291 		    struct objfile *objfile)
   2292 {
   2293   int n;
   2294 
   2295   const char *colon = strchr (namestring, ':');
   2296   if (colon == NULL)
   2297     n = 0;
   2298   else
   2299     n = colon - namestring;
   2300 
   2301   char *p = (char *) alloca (n + 2);
   2302   strncpy (p, namestring, n);
   2303   p[n] = 0;
   2304 
   2305   bound_minimal_symbol msym
   2306     = lookup_minimal_symbol (current_program_space, p, objfile, filename);
   2307   if (msym.minsym == NULL)
   2308     {
   2309       /* Sun Fortran appends an underscore to the minimal symbol name,
   2310 	 try again with an appended underscore if the minimal symbol
   2311 	 was not found.  */
   2312       p[n] = '_';
   2313       p[n + 1] = 0;
   2314       msym
   2315 	= lookup_minimal_symbol (current_program_space, p, objfile, filename);
   2316     }
   2317 
   2318   if (msym.minsym == NULL && filename != NULL)
   2319     {
   2320       /* Try again without the filename.  */
   2321       p[n] = 0;
   2322       msym = lookup_minimal_symbol (current_program_space, p, objfile);
   2323     }
   2324   if (msym.minsym == NULL && filename != NULL)
   2325     {
   2326       /* And try again for Sun Fortran, but without the filename.  */
   2327       p[n] = '_';
   2328       p[n + 1] = 0;
   2329       msym = lookup_minimal_symbol (current_program_space, p, objfile);
   2330     }
   2331 
   2332   return msym;
   2333 }
   2334 
   2335 /* Add header file number I for this object file
   2336    at the next successive FILENUM.  */
   2337 
   2338 static void
   2339 add_this_object_header_file (int i)
   2340 {
   2341   if (n_this_object_header_files == n_allocated_this_object_header_files)
   2342     {
   2343       n_allocated_this_object_header_files *= 2;
   2344       this_object_header_files
   2345 	= (int *) xrealloc ((char *) this_object_header_files,
   2346 		       n_allocated_this_object_header_files * sizeof (int));
   2347     }
   2348 
   2349   this_object_header_files[n_this_object_header_files++] = i;
   2350 }
   2351 
   2352 /* Add to this file an "old" header file, one already seen in
   2353    a previous object file.  NAME is the header file's name.
   2354    INSTANCE is its instance code, to select among multiple
   2355    symbol tables for the same header file.  */
   2356 
   2357 static void
   2358 add_old_header_file (const char *name, int instance, struct objfile *objfile)
   2359 {
   2360   struct header_file *p = HEADER_FILES (objfile);
   2361   int i;
   2362 
   2363   for (i = 0; i < N_HEADER_FILES (objfile); i++)
   2364     if (filename_cmp (p[i].name, name) == 0 && instance == p[i].instance)
   2365       {
   2366 	add_this_object_header_file (i);
   2367 	return;
   2368       }
   2369   repeated_header_complaint (name, symnum);
   2370 }
   2371 
   2372 /* Add to this file a "new" header file: definitions for its types follow.
   2373    NAME is the header file's name.
   2374    Most often this happens only once for each distinct header file,
   2375    but not necessarily.  If it happens more than once, INSTANCE has
   2376    a different value each time, and references to the header file
   2377    use INSTANCE values to select among them.
   2378 
   2379    dbx output contains "begin" and "end" markers for each new header file,
   2380    but at this level we just need to know which files there have been;
   2381    so we record the file when its "begin" is seen and ignore the "end".  */
   2382 
   2383 static void
   2384 add_new_header_file (const char *name, int instance, struct objfile *objfile)
   2385 {
   2386   int i;
   2387   struct header_file *hfile;
   2388 
   2389   /* Make sure there is room for one more header file.  */
   2390 
   2391   i = N_ALLOCATED_HEADER_FILES (objfile);
   2392 
   2393   if (N_HEADER_FILES (objfile) == i)
   2394     {
   2395       if (i == 0)
   2396 	{
   2397 	  N_ALLOCATED_HEADER_FILES (objfile) = 10;
   2398 	  HEADER_FILES (objfile) = (struct header_file *)
   2399 	    xmalloc (10 * sizeof (struct header_file));
   2400 	}
   2401       else
   2402 	{
   2403 	  i *= 2;
   2404 	  N_ALLOCATED_HEADER_FILES (objfile) = i;
   2405 	  HEADER_FILES (objfile) = (struct header_file *)
   2406 	    xrealloc ((char *) HEADER_FILES (objfile),
   2407 		      (i * sizeof (struct header_file)));
   2408 	}
   2409     }
   2410 
   2411   /* Create an entry for this header file.  */
   2412 
   2413   i = N_HEADER_FILES (objfile)++;
   2414   hfile = HEADER_FILES (objfile) + i;
   2415   hfile->name = xstrdup (name);
   2416   hfile->instance = instance;
   2417   hfile->length = 10;
   2418   hfile->vector = XCNEWVEC (struct type *, 10);
   2419 
   2420   add_this_object_header_file (i);
   2421 }
   2422 
   2423 /* See stabsread.h.  */
   2424 
   2425 void
   2426 process_one_symbol (int type, int desc, CORE_ADDR valu, const char *name,
   2427 		    const section_offsets &section_offsets,
   2428 		    struct objfile *objfile, enum language language)
   2429 {
   2430   struct gdbarch *gdbarch = objfile->arch ();
   2431   struct context_stack *newobj;
   2432   struct context_stack cstk;
   2433   /* This remembers the address of the start of a function.  It is
   2434      used because in Solaris 2, N_LBRAC, N_RBRAC, and N_SLINE entries
   2435      are relative to the current function's start address.  On systems
   2436      other than Solaris 2, this just holds the SECT_OFF_TEXT value,
   2437      and is used to relocate these symbol types rather than
   2438      SECTION_OFFSETS.  */
   2439   static CORE_ADDR function_start_offset;
   2440 
   2441   /* This holds the address of the start of a function, without the
   2442      system peculiarities of function_start_offset.  */
   2443   static CORE_ADDR last_function_start;
   2444 
   2445   /* If this is nonzero, we've seen an N_SLINE since the start of the
   2446      current function.  We use this to tell us to move the first sline
   2447      to the beginning of the function regardless of what its given
   2448      value is.  */
   2449   static int sline_found_in_function = 1;
   2450 
   2451   /* If this is nonzero, we've seen a non-gcc N_OPT symbol for this
   2452      source file.  Used to detect the SunPRO solaris compiler.  */
   2453   static int n_opt_found;
   2454 
   2455   /* The section index for this symbol.  */
   2456   int section_index = -1;
   2457 
   2458   struct dbx_symfile_info *key = dbx_objfile_data_key.get (objfile);
   2459 
   2460   /* Something is wrong if we see real data before seeing a source
   2461      file name.  */
   2462 
   2463   if (get_last_source_file () == NULL && type != (unsigned char) N_SO)
   2464     {
   2465       /* Ignore any symbols which appear before an N_SO symbol.
   2466 	 Currently no one puts symbols there, but we should deal
   2467 	 gracefully with the case.  A complain()t might be in order,
   2468 	 but this should not be an error ().  */
   2469       return;
   2470     }
   2471 
   2472   switch (type)
   2473     {
   2474     case N_FUN:
   2475     case N_FNAME:
   2476 
   2477       if (*name == '\000')
   2478 	{
   2479 	  /* This N_FUN marks the end of a function.  This closes off
   2480 	     the current block.  */
   2481 	  struct block *block;
   2482 
   2483 	  if (outermost_context_p ())
   2484 	    {
   2485 	      lbrac_mismatch_complaint (symnum);
   2486 	      break;
   2487 	    }
   2488 
   2489 	  /* The following check is added before recording line 0 at
   2490 	     end of function so as to handle hand-generated stabs
   2491 	     which may have an N_FUN stabs at the end of the function,
   2492 	     but no N_SLINE stabs.  */
   2493 	  if (sline_found_in_function)
   2494 	    {
   2495 	      CORE_ADDR addr = last_function_start + valu;
   2496 
   2497 	      record_line
   2498 		(get_current_subfile (), 0,
   2499 		 unrelocated_addr (gdbarch_addr_bits_remove (gdbarch, addr)
   2500 				   - objfile->text_section_offset ()));
   2501 	    }
   2502 
   2503 	  within_function = 0;
   2504 	  cstk = pop_context ();
   2505 
   2506 	  /* Make a block for the local symbols within.  */
   2507 	  block = finish_block (cstk.name,
   2508 				cstk.old_blocks, NULL,
   2509 				cstk.start_addr, cstk.start_addr + valu);
   2510 
   2511 	  /* For C++, set the block's scope.  */
   2512 	  if (cstk.name->language () == language_cplus)
   2513 	    cp_set_block_scope (cstk.name, block, &objfile->objfile_obstack);
   2514 
   2515 	  /* May be switching to an assembler file which may not be using
   2516 	     block relative stabs, so reset the offset.  */
   2517 	  function_start_offset = 0;
   2518 
   2519 	  break;
   2520 	}
   2521 
   2522       sline_found_in_function = 0;
   2523 
   2524       /* Relocate for dynamic loading.  */
   2525       section_index = SECT_OFF_TEXT (objfile);
   2526       valu += section_offsets[SECT_OFF_TEXT (objfile)];
   2527       valu = gdbarch_addr_bits_remove (gdbarch, valu);
   2528       last_function_start = valu;
   2529 
   2530       goto define_a_symbol;
   2531 
   2532     case N_LBRAC:
   2533       /* This "symbol" just indicates the start of an inner lexical
   2534 	 context within a function.  */
   2535 
   2536       /* Ignore extra outermost context from SunPRO cc and acc.  */
   2537       if (n_opt_found && desc == 1)
   2538 	break;
   2539 
   2540       valu += function_start_offset;
   2541 
   2542       push_context (desc, valu);
   2543       break;
   2544 
   2545     case N_RBRAC:
   2546       /* This "symbol" just indicates the end of an inner lexical
   2547 	 context that was started with N_LBRAC.  */
   2548 
   2549       /* Ignore extra outermost context from SunPRO cc and acc.  */
   2550       if (n_opt_found && desc == 1)
   2551 	break;
   2552 
   2553       valu += function_start_offset;
   2554 
   2555       if (outermost_context_p ())
   2556 	{
   2557 	  lbrac_mismatch_complaint (symnum);
   2558 	  break;
   2559 	}
   2560 
   2561       cstk = pop_context ();
   2562       if (desc != cstk.depth)
   2563 	lbrac_mismatch_complaint (symnum);
   2564 
   2565       if (*get_local_symbols () != NULL)
   2566 	{
   2567 	  /* GCC development snapshots from March to December of
   2568 	     2000 would output N_LSYM entries after N_LBRAC
   2569 	     entries.  As a consequence, these symbols are simply
   2570 	     discarded.  Complain if this is the case.  */
   2571 	  complaint (_("misplaced N_LBRAC entry; discarding local "
   2572 		       "symbols which have no enclosing block"));
   2573 	}
   2574       *get_local_symbols () = cstk.locals;
   2575 
   2576       if (get_context_stack_depth () > 1)
   2577 	{
   2578 	  /* This is not the outermost LBRAC...RBRAC pair in the
   2579 	     function, its local symbols preceded it, and are the ones
   2580 	     just recovered from the context stack.  Define the block
   2581 	     for them (but don't bother if the block contains no
   2582 	     symbols.  Should we complain on blocks without symbols?
   2583 	     I can't think of any useful purpose for them).  */
   2584 	  if (*get_local_symbols () != NULL)
   2585 	    {
   2586 	      /* Muzzle a compiler bug that makes end < start.
   2587 
   2588 		 ??? Which compilers?  Is this ever harmful?.  */
   2589 	      if (cstk.start_addr > valu)
   2590 		{
   2591 		  complaint (_("block start larger than block end"));
   2592 		  cstk.start_addr = valu;
   2593 		}
   2594 	      /* Make a block for the local symbols within.  */
   2595 	      finish_block (0, cstk.old_blocks, NULL,
   2596 			    cstk.start_addr, valu);
   2597 	    }
   2598 	}
   2599       else
   2600 	{
   2601 	  /* This is the outermost LBRAC...RBRAC pair.  There is no
   2602 	     need to do anything; leave the symbols that preceded it
   2603 	     to be attached to the function's own block.  We need to
   2604 	     indicate that we just moved outside of the function.  */
   2605 	  within_function = 0;
   2606 	}
   2607 
   2608       break;
   2609 
   2610     case N_FN:
   2611     case N_FN_SEQ:
   2612       /* This kind of symbol indicates the start of an object file.
   2613 	 Relocate for dynamic loading.  */
   2614       section_index = SECT_OFF_TEXT (objfile);
   2615       valu += section_offsets[SECT_OFF_TEXT (objfile)];
   2616       break;
   2617 
   2618     case N_SO:
   2619       /* This type of symbol indicates the start of data for one
   2620 	 source file.  Finish the symbol table of the previous source
   2621 	 file (if any) and start accumulating a new symbol table.
   2622 	 Relocate for dynamic loading.  */
   2623       section_index = SECT_OFF_TEXT (objfile);
   2624       valu += section_offsets[SECT_OFF_TEXT (objfile)];
   2625 
   2626       n_opt_found = 0;
   2627 
   2628       if (get_last_source_file ())
   2629 	{
   2630 	  /* Check if previous symbol was also an N_SO (with some
   2631 	     sanity checks).  If so, that one was actually the
   2632 	     directory name, and the current one is the real file
   2633 	     name.  Patch things up.  */
   2634 	  if (previous_stab_code == (unsigned char) N_SO)
   2635 	    {
   2636 	      patch_subfile_names (get_current_subfile (), name);
   2637 	      break;		/* Ignore repeated SOs.  */
   2638 	    }
   2639 	  end_compunit_symtab (valu);
   2640 	  end_stabs ();
   2641 	}
   2642 
   2643       /* Null name means this just marks the end of text for this .o
   2644 	 file.  Don't start a new symtab in this case.  */
   2645       if (*name == '\000')
   2646 	break;
   2647 
   2648       function_start_offset = 0;
   2649 
   2650       start_stabs ();
   2651       start_compunit_symtab (objfile, name, NULL, valu, language);
   2652       record_debugformat ("stabs");
   2653       break;
   2654 
   2655     case N_SOL:
   2656       /* This type of symbol indicates the start of data for a
   2657 	 sub-source-file, one whose contents were copied or included
   2658 	 in the compilation of the main source file (whose name was
   2659 	 given in the N_SO symbol).  Relocate for dynamic loading.  */
   2660       section_index = SECT_OFF_TEXT (objfile);
   2661       valu += section_offsets[SECT_OFF_TEXT (objfile)];
   2662       start_subfile (name);
   2663       break;
   2664 
   2665     case N_BINCL:
   2666       push_subfile ();
   2667       add_new_header_file (name, valu, objfile);
   2668       start_subfile (name);
   2669       break;
   2670 
   2671     case N_EINCL:
   2672       start_subfile (pop_subfile ());
   2673       break;
   2674 
   2675     case N_EXCL:
   2676       add_old_header_file (name, valu, objfile);
   2677       break;
   2678 
   2679     case N_SLINE:
   2680       /* This type of "symbol" really just records one line-number --
   2681 	 core-address correspondence.  Enter it in the line list for
   2682 	 this symbol table.  */
   2683 
   2684       /* Relocate for dynamic loading and for ELF acc
   2685 	 function-relative symbols.  */
   2686       valu += function_start_offset;
   2687 
   2688       /* GCC 2.95.3 emits the first N_SLINE stab somewhere in the
   2689 	 middle of the prologue instead of right at the start of the
   2690 	 function.  To deal with this we record the address for the
   2691 	 first N_SLINE stab to be the start of the function instead of
   2692 	 the listed location.  We really shouldn't to this.  When
   2693 	 compiling with optimization, this first N_SLINE stab might be
   2694 	 optimized away.  Other (non-GCC) compilers don't emit this
   2695 	 stab at all.  There is no real harm in having an extra
   2696 	 numbered line, although it can be a bit annoying for the
   2697 	 user.  However, it totally screws up our testsuite.
   2698 
   2699 	 So for now, keep adjusting the address of the first N_SLINE
   2700 	 stab, but only for code compiled with GCC.  */
   2701 
   2702       if (within_function && sline_found_in_function == 0)
   2703 	{
   2704 	  CORE_ADDR addr = processing_gcc_compilation == 2 ?
   2705 			   last_function_start : valu;
   2706 
   2707 	  record_line
   2708 	    (get_current_subfile (), desc,
   2709 	     unrelocated_addr (gdbarch_addr_bits_remove (gdbarch, addr)
   2710 			       - objfile->text_section_offset ()));
   2711 	  sline_found_in_function = 1;
   2712 	}
   2713       else
   2714 	record_line
   2715 	  (get_current_subfile (), desc,
   2716 	   unrelocated_addr (gdbarch_addr_bits_remove (gdbarch, valu)
   2717 			     - objfile->text_section_offset ()));
   2718       break;
   2719 
   2720     case N_BCOMM:
   2721       common_block_start (name, objfile);
   2722       break;
   2723 
   2724     case N_ECOMM:
   2725       common_block_end (objfile);
   2726       break;
   2727 
   2728       /* The following symbol types need to have the appropriate
   2729 	 offset added to their value; then we process symbol
   2730 	 definitions in the name.  */
   2731 
   2732     case N_STSYM:		/* Static symbol in data segment.  */
   2733     case N_LCSYM:		/* Static symbol in BSS segment.  */
   2734     case N_ROSYM:		/* Static symbol in read-only data segment.  */
   2735       /* HORRID HACK DEPT.  However, it's Sun's furgin' fault.
   2736 	 Solaris 2's stabs-in-elf makes *most* symbols relative but
   2737 	 leaves a few absolute (at least for Solaris 2.1 and version
   2738 	 2.0.1 of the SunPRO compiler).  N_STSYM and friends sit on
   2739 	 the fence.  .stab "foo:S...",N_STSYM is absolute (ld
   2740 	 relocates it) .stab "foo:V...",N_STSYM is relative (section
   2741 	 base subtracted).  This leaves us no choice but to search for
   2742 	 the 'S' or 'V'...  (or pass the whole section_offsets stuff
   2743 	 down ONE MORE function call level, which we really don't want
   2744 	 to do).  */
   2745       {
   2746 	const char *p;
   2747 
   2748 	/* Normal object file and NLMs have non-zero text seg offsets,
   2749 	   but don't need their static syms offset in this fashion.
   2750 	   XXX - This is really a crock that should be fixed in the
   2751 	   solib handling code so that I don't have to work around it
   2752 	   here.  */
   2753 
   2754 	if (!key->ctx.symfile_relocatable)
   2755 	  {
   2756 	    p = strchr (name, ':');
   2757 	    if (p != 0 && p[1] == 'S')
   2758 	      {
   2759 		/* The linker relocated it.  We don't want to add a
   2760 		   Sun-stabs Tfoo.foo-like offset, but we *do*
   2761 		   want to add whatever solib.c passed to
   2762 		   symbol_file_add as addr (this is known to affect
   2763 		   SunOS 4, and I suspect ELF too).  Since there is no
   2764 		   Ttext.text symbol, we can get addr from the text offset.  */
   2765 		section_index = SECT_OFF_TEXT (objfile);
   2766 		valu += section_offsets[SECT_OFF_TEXT (objfile)];
   2767 		goto define_a_symbol;
   2768 	      }
   2769 	  }
   2770 	/* Since it's not the kludge case, re-dispatch to the right
   2771 	   handler.  */
   2772 	switch (type)
   2773 	  {
   2774 	  case N_STSYM:
   2775 	    goto case_N_STSYM;
   2776 	  case N_LCSYM:
   2777 	    goto case_N_LCSYM;
   2778 	  case N_ROSYM:
   2779 	    goto case_N_ROSYM;
   2780 	  default:
   2781 	    internal_error (_("failed internal consistency check"));
   2782 	  }
   2783       }
   2784 
   2785     case_N_STSYM:		/* Static symbol in data segment.  */
   2786     case N_DSLINE:		/* Source line number, data segment.  */
   2787       section_index = SECT_OFF_DATA (objfile);
   2788       valu += section_offsets[SECT_OFF_DATA (objfile)];
   2789       goto define_a_symbol;
   2790 
   2791     case_N_LCSYM:		/* Static symbol in BSS segment.  */
   2792     case N_BSLINE:		/* Source line number, BSS segment.  */
   2793       /* N_BROWS: overlaps with N_BSLINE.  */
   2794       section_index = SECT_OFF_BSS (objfile);
   2795       valu += section_offsets[SECT_OFF_BSS (objfile)];
   2796       goto define_a_symbol;
   2797 
   2798     case_N_ROSYM:		/* Static symbol in read-only data segment.  */
   2799       section_index = SECT_OFF_RODATA (objfile);
   2800       valu += section_offsets[SECT_OFF_RODATA (objfile)];
   2801       goto define_a_symbol;
   2802 
   2803     case N_ENTRY:		/* Alternate entry point.  */
   2804       /* Relocate for dynamic loading.  */
   2805       section_index = SECT_OFF_TEXT (objfile);
   2806       valu += section_offsets[SECT_OFF_TEXT (objfile)];
   2807       goto define_a_symbol;
   2808 
   2809       /* The following symbol types we don't know how to process.
   2810 	 Handle them in a "default" way, but complain to people who
   2811 	 care.  */
   2812     default:
   2813     case N_CATCH:		/* Exception handler catcher.  */
   2814     case N_EHDECL:		/* Exception handler name.  */
   2815     case N_PC:			/* Global symbol in Pascal.  */
   2816     case N_M2C:			/* Modula-2 compilation unit.  */
   2817       /* N_MOD2: overlaps with N_EHDECL.  */
   2818     case N_SCOPE:		/* Modula-2 scope information.  */
   2819     case N_ECOML:		/* End common (local name).  */
   2820     case N_NBTEXT:		/* Gould Non-Base-Register symbols???  */
   2821     case N_NBDATA:
   2822     case N_NBBSS:
   2823     case N_NBSTS:
   2824     case N_NBLCS:
   2825       unknown_symtype_complaint (hex_string (type));
   2826 
   2827     define_a_symbol:
   2828       [[fallthrough]];
   2829       /* These symbol types don't need the address field relocated,
   2830 	 since it is either unused, or is absolute.  */
   2831     case N_GSYM:		/* Global variable.  */
   2832     case N_NSYMS:		/* Number of symbols (Ultrix).  */
   2833     case N_NOMAP:		/* No map?  (Ultrix).  */
   2834     case N_RSYM:		/* Register variable.  */
   2835     case N_DEFD:		/* Modula-2 GNU module dependency.  */
   2836     case N_SSYM:		/* Struct or union element.  */
   2837     case N_LSYM:		/* Local symbol in stack.  */
   2838     case N_PSYM:		/* Parameter variable.  */
   2839     case N_LENG:		/* Length of preceding symbol type.  */
   2840       if (name)
   2841 	{
   2842 	  int deftype;
   2843 	  const char *colon_pos = strchr (name, ':');
   2844 
   2845 	  if (colon_pos == NULL)
   2846 	    deftype = '\0';
   2847 	  else
   2848 	    deftype = colon_pos[1];
   2849 
   2850 	  switch (deftype)
   2851 	    {
   2852 	    case 'f':
   2853 	    case 'F':
   2854 	      /* Deal with the SunPRO 3.0 compiler which omits the
   2855 		 address from N_FUN symbols.  */
   2856 	      if (type == N_FUN
   2857 		  && valu == section_offsets[SECT_OFF_TEXT (objfile)]
   2858 		  && gdbarch_sofun_address_maybe_missing (gdbarch))
   2859 		{
   2860 		  bound_minimal_symbol minsym
   2861 		    = find_stab_function (name, get_last_source_file (),
   2862 					  objfile);
   2863 		  if (minsym.minsym != NULL)
   2864 		    valu = minsym.value_address ();
   2865 		}
   2866 
   2867 	      /* These addresses are absolute.  */
   2868 	      function_start_offset = valu;
   2869 
   2870 	      within_function = 1;
   2871 
   2872 	      if (get_context_stack_depth () > 1)
   2873 		{
   2874 		  complaint (_("unmatched N_LBRAC before symtab pos %d"),
   2875 			     symnum);
   2876 		  break;
   2877 		}
   2878 
   2879 	      if (!outermost_context_p ())
   2880 		{
   2881 		  struct block *block;
   2882 
   2883 		  cstk = pop_context ();
   2884 		  /* Make a block for the local symbols within.  */
   2885 		  block = finish_block (cstk.name,
   2886 					cstk.old_blocks, NULL,
   2887 					cstk.start_addr, valu);
   2888 
   2889 		  /* For C++, set the block's scope.  */
   2890 		  if (cstk.name->language () == language_cplus)
   2891 		    cp_set_block_scope (cstk.name, block,
   2892 					&objfile->objfile_obstack);
   2893 		}
   2894 
   2895 	      newobj = push_context (0, valu);
   2896 	      newobj->name = define_symbol (valu, name, desc, type, objfile);
   2897 	      if (newobj->name != nullptr)
   2898 		newobj->name->set_section_index (section_index);
   2899 	      break;
   2900 
   2901 	    default:
   2902 	      {
   2903 		struct symbol *sym = define_symbol (valu, name, desc, type,
   2904 						    objfile);
   2905 		if (sym != nullptr)
   2906 		  sym->set_section_index (section_index);
   2907 	      }
   2908 	      break;
   2909 	    }
   2910 	}
   2911       break;
   2912 
   2913       /* We use N_OPT to carry the gcc2_compiled flag.  Sun uses it
   2914 	 for a bunch of other flags, too.  Someday we may parse their
   2915 	 flags; for now we ignore theirs and hope they'll ignore ours.  */
   2916     case N_OPT:			/* Solaris 2: Compiler options.  */
   2917       if (name)
   2918 	{
   2919 	  if (strcmp (name, GCC2_COMPILED_FLAG_SYMBOL) == 0)
   2920 	    {
   2921 	      processing_gcc_compilation = 2;
   2922 	    }
   2923 	  else
   2924 	    n_opt_found = 1;
   2925 	}
   2926       break;
   2927 
   2928     case N_MAIN:		/* Name of main routine.  */
   2929       /* FIXME: If one has a symbol file with N_MAIN and then replaces
   2930 	 it with a symbol file with "main" and without N_MAIN.  I'm
   2931 	 not sure exactly what rule to follow but probably something
   2932 	 like: N_MAIN takes precedence over "main" no matter what
   2933 	 objfile it is in; If there is more than one N_MAIN, choose
   2934 	 the one in the symfile_objfile; If there is more than one
   2935 	 N_MAIN within a given objfile, complain() and choose
   2936 	 arbitrarily.  (kingdon) */
   2937       if (name != NULL)
   2938 	set_objfile_main_name (objfile, name, language_unknown);
   2939       break;
   2940 
   2941       /* The following symbol types can be ignored.  */
   2942     case N_OBJ:			/* Solaris 2: Object file dir and name.  */
   2943     case N_PATCH:		/* Solaris 2: Patch Run Time Checker.  */
   2944       /* N_UNDF:                   Solaris 2: File separator mark.  */
   2945       /* N_UNDF: -- we will never encounter it, since we only process
   2946 	 one file's symbols at once.  */
   2947     case N_ENDM:		/* Solaris 2: End of module.  */
   2948     case N_ALIAS:		/* SunPro F77: alias name, ignore for now.  */
   2949       break;
   2950     }
   2951 
   2952   /* '#' is a GNU C extension to allow one symbol to refer to another
   2953      related symbol.
   2954 
   2955      Generally this is used so that an alias can refer to its main
   2956      symbol.  */
   2957   gdb_assert (name);
   2958   if (name[0] == '#')
   2959     {
   2960       /* Initialize symbol reference names and determine if this is a
   2961 	 definition.  If a symbol reference is being defined, go ahead
   2962 	 and add it.  Otherwise, just return.  */
   2963 
   2964       const char *s = name;
   2965       int refnum;
   2966 
   2967       /* If this stab defines a new reference ID that is not on the
   2968 	 reference list, then put it on the reference list.
   2969 
   2970 	 We go ahead and advance NAME past the reference, even though
   2971 	 it is not strictly necessary at this time.  */
   2972       refnum = symbol_reference_defined (&s);
   2973       if (refnum >= 0)
   2974 	if (!ref_search (refnum))
   2975 	  ref_add (refnum, 0, name, valu);
   2976       name = s;
   2977     }
   2978 
   2979   previous_stab_code = type;
   2980 }
   2981 
   2982 #define VISIBILITY_PRIVATE	'0'	/* Stabs character for private field */
   2983 #define VISIBILITY_PROTECTED	'1'	/* Stabs character for protected fld */
   2984 #define VISIBILITY_PUBLIC	'2'	/* Stabs character for public field */
   2985 #define VISIBILITY_IGNORE	'9'	/* Optimized out or zero length */
   2986 
   2987 /* Structure for storing pointers to reference definitions for fast lookup
   2988    during "process_later".  */
   2989 
   2990 struct ref_map
   2991 {
   2992   const char *stabs;
   2993   CORE_ADDR value;
   2994   struct symbol *sym;
   2995 };
   2996 
   2997 #define MAX_CHUNK_REFS 100
   2998 #define REF_CHUNK_SIZE (MAX_CHUNK_REFS * sizeof (struct ref_map))
   2999 #define REF_MAP_SIZE(ref_chunk) ((ref_chunk) * REF_CHUNK_SIZE)
   3000 
   3001 static struct ref_map *ref_map;
   3002 
   3003 /* Ptr to free cell in chunk's linked list.  */
   3004 static int ref_count = 0;
   3005 
   3006 /* Number of chunks malloced.  */
   3007 static int ref_chunk = 0;
   3008 
   3009 /* This file maintains a cache of stabs aliases found in the symbol
   3010    table.  If the symbol table changes, this cache must be cleared
   3011    or we are left holding onto data in invalid obstacks.  */
   3012 void
   3013 stabsread_clear_cache (void)
   3014 {
   3015   ref_count = 0;
   3016   ref_chunk = 0;
   3017 }
   3018 
   3019 /* Create array of pointers mapping refids to symbols and stab strings.
   3020    Add pointers to reference definition symbols and/or their values as we
   3021    find them, using their reference numbers as our index.
   3022    These will be used later when we resolve references.  */
   3023 void
   3024 ref_add (int refnum, struct symbol *sym, const char *stabs, CORE_ADDR value)
   3025 {
   3026   if (ref_count == 0)
   3027     ref_chunk = 0;
   3028   if (refnum >= ref_count)
   3029     ref_count = refnum + 1;
   3030   if (ref_count > ref_chunk * MAX_CHUNK_REFS)
   3031     {
   3032       int new_slots = ref_count - ref_chunk * MAX_CHUNK_REFS;
   3033       int new_chunks = new_slots / MAX_CHUNK_REFS + 1;
   3034 
   3035       ref_map = (struct ref_map *)
   3036 	xrealloc (ref_map, REF_MAP_SIZE (ref_chunk + new_chunks));
   3037       memset (ref_map + ref_chunk * MAX_CHUNK_REFS, 0,
   3038 	      new_chunks * REF_CHUNK_SIZE);
   3039       ref_chunk += new_chunks;
   3040     }
   3041   ref_map[refnum].stabs = stabs;
   3042   ref_map[refnum].sym = sym;
   3043   ref_map[refnum].value = value;
   3044 }
   3045 
   3046 /* Return defined sym for the reference REFNUM.  */
   3047 struct symbol *
   3048 ref_search (int refnum)
   3049 {
   3050   if (refnum < 0 || refnum > ref_count)
   3051     return 0;
   3052   return ref_map[refnum].sym;
   3053 }
   3054 
   3055 /* Parse a reference id in STRING and return the resulting
   3056    reference number.  Move STRING beyond the reference id.  */
   3057 
   3058 static int
   3059 process_reference (const char **string)
   3060 {
   3061   const char *p;
   3062   int refnum = 0;
   3063 
   3064   if (**string != '#')
   3065     return 0;
   3066 
   3067   /* Advance beyond the initial '#'.  */
   3068   p = *string + 1;
   3069 
   3070   /* Read number as reference id.  */
   3071   while (*p && isdigit ((unsigned char)*p))
   3072     {
   3073       refnum = refnum * 10 + *p - '0';
   3074       p++;
   3075     }
   3076   *string = p;
   3077   return refnum;
   3078 }
   3079 
   3080 /* If STRING defines a reference, store away a pointer to the reference
   3081    definition for later use.  Return the reference number.  */
   3082 
   3083 int
   3084 symbol_reference_defined (const char **string)
   3085 {
   3086   const char *p = *string;
   3087   int refnum = 0;
   3088 
   3089   refnum = process_reference (&p);
   3090 
   3091   /* Defining symbols end in '='.  */
   3092   if (*p == '=')
   3093     {
   3094       /* Symbol is being defined here.  */
   3095       *string = p + 1;
   3096       return refnum;
   3097     }
   3098   else
   3099     {
   3100       /* Must be a reference.  Either the symbol has already been defined,
   3101 	 or this is a forward reference to it.  */
   3102       *string = p;
   3103       return -1;
   3104     }
   3105 }
   3106 
   3107 static int
   3108 stab_reg_to_regnum (struct symbol *sym, struct gdbarch *gdbarch)
   3109 {
   3110   int regno = gdbarch_stab_reg_to_regnum (gdbarch, sym->value_longest ());
   3111 
   3112   if (regno < 0 || regno >= gdbarch_num_cooked_regs (gdbarch))
   3113     {
   3114       reg_value_complaint (regno, gdbarch_num_cooked_regs (gdbarch),
   3115 			   sym->print_name ());
   3116 
   3117       regno = gdbarch_sp_regnum (gdbarch); /* Known safe, though useless.  */
   3118     }
   3119 
   3120   return regno;
   3121 }
   3122 
   3123 static const struct symbol_register_ops stab_register_funcs = {
   3124   stab_reg_to_regnum
   3125 };
   3126 
   3127 /* The "aclass" indices for computed symbols.  */
   3128 
   3129 static int stab_register_index;
   3130 static int stab_regparm_index;
   3131 
   3132 struct symbol *
   3133 define_symbol (CORE_ADDR valu, const char *string, int desc, int type,
   3134 	       struct objfile *objfile)
   3135 {
   3136   struct gdbarch *gdbarch = objfile->arch ();
   3137   struct symbol *sym;
   3138   const char *p = find_name_end (string);
   3139   int deftype;
   3140   int synonym = 0;
   3141   int i;
   3142 
   3143   /* We would like to eliminate nameless symbols, but keep their types.
   3144      E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer
   3145      to type 2, but, should not create a symbol to address that type.  Since
   3146      the symbol will be nameless, there is no way any user can refer to it.  */
   3147 
   3148   int nameless;
   3149 
   3150   /* Ignore syms with empty names.  */
   3151   if (string[0] == 0)
   3152     return 0;
   3153 
   3154   /* Ignore old-style symbols from cc -go.  */
   3155   if (p == 0)
   3156     return 0;
   3157 
   3158   while (p[1] == ':')
   3159     {
   3160       p += 2;
   3161       p = strchr (p, ':');
   3162       if (p == NULL)
   3163 	{
   3164 	  complaint (
   3165 		     _("Bad stabs string '%s'"), string);
   3166 	  return NULL;
   3167 	}
   3168     }
   3169 
   3170   /* If a nameless stab entry, all we need is the type, not the symbol.
   3171      e.g. ":t10=*2" or a nameless enum like " :T16=ered:0,green:1,blue:2,;" */
   3172   nameless = (p == string || ((string[0] == ' ') && (string[1] == ':')));
   3173 
   3174   current_symbol = sym = new (&objfile->objfile_obstack) symbol;
   3175 
   3176   if (processing_gcc_compilation)
   3177     {
   3178       /* GCC 2.x puts the line number in desc.  SunOS apparently puts in the
   3179 	 number of bytes occupied by a type or object, which we ignore.  */
   3180       sym->set_line (desc);
   3181     }
   3182   else
   3183     {
   3184       sym->set_line (0);	/* unknown */
   3185     }
   3186 
   3187   sym->set_language (get_current_subfile ()->language,
   3188 		     &objfile->objfile_obstack);
   3189 
   3190   if (is_cplus_marker (string[0]))
   3191     {
   3192       /* Special GNU C++ names.  */
   3193       switch (string[1])
   3194 	{
   3195 	case 't':
   3196 	  sym->set_linkage_name ("this");
   3197 	  break;
   3198 
   3199 	case 'v':		/* $vtbl_ptr_type */
   3200 	  goto normal;
   3201 
   3202 	case 'e':
   3203 	  sym->set_linkage_name ("eh_throw");
   3204 	  break;
   3205 
   3206 	case '_':
   3207 	  /* This was an anonymous type that was never fixed up.  */
   3208 	  goto normal;
   3209 
   3210 	default:
   3211 	  complaint (_("Unknown C++ symbol name `%s'"),
   3212 		     string);
   3213 	  goto normal;		/* Do *something* with it.  */
   3214 	}
   3215     }
   3216   else
   3217     {
   3218     normal:
   3219       gdb::unique_xmalloc_ptr<char> new_name;
   3220 
   3221       if (sym->language () == language_cplus)
   3222 	{
   3223 	  std::string name (string, p - string);
   3224 	  new_name = cp_canonicalize_string (name.c_str ());
   3225 	}
   3226       else if (sym->language () == language_c)
   3227 	{
   3228 	  std::string name (string, p - string);
   3229 	  new_name = c_canonicalize_name (name.c_str ());
   3230 	}
   3231       if (new_name != nullptr)
   3232 	sym->compute_and_set_names (new_name.get (), true, objfile->per_bfd);
   3233       else
   3234 	sym->compute_and_set_names (std::string_view (string, p - string), true,
   3235 				    objfile->per_bfd);
   3236 
   3237       if (sym->language () == language_cplus)
   3238 	cp_scan_for_anonymous_namespaces (get_buildsym_compunit (), sym,
   3239 					  objfile);
   3240 
   3241     }
   3242   p++;
   3243 
   3244   /* Determine the type of name being defined.  */
   3245 #if 0
   3246   /* Getting GDB to correctly skip the symbol on an undefined symbol
   3247      descriptor and not ever dump core is a very dodgy proposition if
   3248      we do things this way.  I say the acorn RISC machine can just
   3249      fix their compiler.  */
   3250   /* The Acorn RISC machine's compiler can put out locals that don't
   3251      start with "234=" or "(3,4)=", so assume anything other than the
   3252      deftypes we know how to handle is a local.  */
   3253   if (!strchr ("cfFGpPrStTvVXCR", *p))
   3254 #else
   3255   if (isdigit ((unsigned char)*p) || *p == '(' || *p == '-')
   3256 #endif
   3257     deftype = 'l';
   3258   else
   3259     deftype = *p++;
   3260 
   3261   switch (deftype)
   3262     {
   3263     case 'c':
   3264       /* c is a special case, not followed by a type-number.
   3265 	 SYMBOL:c=iVALUE for an integer constant symbol.
   3266 	 SYMBOL:c=rVALUE for a floating constant symbol.
   3267 	 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
   3268 	 e.g. "b:c=e6,0" for "const b = blob1"
   3269 	 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;").  */
   3270       if (*p != '=')
   3271 	{
   3272 	  sym->set_aclass_index (LOC_CONST);
   3273 	  sym->set_type (error_type (&p, objfile));
   3274 	  sym->set_domain (VAR_DOMAIN);
   3275 	  add_symbol_to_list (sym, get_file_symbols ());
   3276 	  return sym;
   3277 	}
   3278       ++p;
   3279       switch (*p++)
   3280 	{
   3281 	case 'r':
   3282 	  {
   3283 	    gdb_byte *dbl_valu;
   3284 	    struct type *dbl_type;
   3285 
   3286 	    dbl_type = builtin_type (objfile)->builtin_double;
   3287 	    dbl_valu
   3288 	      = (gdb_byte *) obstack_alloc (&objfile->objfile_obstack,
   3289 					    dbl_type->length ());
   3290 
   3291 	    target_float_from_string (dbl_valu, dbl_type, std::string (p));
   3292 
   3293 	    sym->set_type (dbl_type);
   3294 	    sym->set_value_bytes (dbl_valu);
   3295 	    sym->set_aclass_index (LOC_CONST_BYTES);
   3296 	  }
   3297 	  break;
   3298 	case 'i':
   3299 	  {
   3300 	    /* Defining integer constants this way is kind of silly,
   3301 	       since 'e' constants allows the compiler to give not
   3302 	       only the value, but the type as well.  C has at least
   3303 	       int, long, unsigned int, and long long as constant
   3304 	       types; other languages probably should have at least
   3305 	       unsigned as well as signed constants.  */
   3306 
   3307 	    sym->set_type (builtin_type (objfile)->builtin_long);
   3308 	    sym->set_value_longest (atoi (p));
   3309 	    sym->set_aclass_index (LOC_CONST);
   3310 	  }
   3311 	  break;
   3312 
   3313 	case 'c':
   3314 	  {
   3315 	    sym->set_type (builtin_type (objfile)->builtin_char);
   3316 	    sym->set_value_longest (atoi (p));
   3317 	    sym->set_aclass_index (LOC_CONST);
   3318 	  }
   3319 	  break;
   3320 
   3321 	case 's':
   3322 	  {
   3323 	    struct type *range_type;
   3324 	    int ind = 0;
   3325 	    char quote = *p++;
   3326 	    gdb_byte *string_local = (gdb_byte *) alloca (strlen (p));
   3327 	    gdb_byte *string_value;
   3328 
   3329 	    if (quote != '\'' && quote != '"')
   3330 	      {
   3331 		sym->set_aclass_index (LOC_CONST);
   3332 		sym->set_type (error_type (&p, objfile));
   3333 		sym->set_domain (VAR_DOMAIN);
   3334 		add_symbol_to_list (sym, get_file_symbols ());
   3335 		return sym;
   3336 	      }
   3337 
   3338 	    /* Find matching quote, rejecting escaped quotes.  */
   3339 	    while (*p && *p != quote)
   3340 	      {
   3341 		if (*p == '\\' && p[1] == quote)
   3342 		  {
   3343 		    string_local[ind] = (gdb_byte) quote;
   3344 		    ind++;
   3345 		    p += 2;
   3346 		  }
   3347 		else if (*p)
   3348 		  {
   3349 		    string_local[ind] = (gdb_byte) (*p);
   3350 		    ind++;
   3351 		    p++;
   3352 		  }
   3353 	      }
   3354 	    if (*p != quote)
   3355 	      {
   3356 		sym->set_aclass_index (LOC_CONST);
   3357 		sym->set_type (error_type (&p, objfile));
   3358 		sym->set_domain (VAR_DOMAIN);
   3359 		add_symbol_to_list (sym, get_file_symbols ());
   3360 		return sym;
   3361 	      }
   3362 
   3363 	    /* NULL terminate the string.  */
   3364 	    string_local[ind] = 0;
   3365 	    type_allocator alloc (objfile, get_current_subfile ()->language);
   3366 	    range_type
   3367 	      = create_static_range_type (alloc,
   3368 					  builtin_type (objfile)->builtin_int,
   3369 					  0, ind);
   3370 	    sym->set_type
   3371 	      (create_array_type (alloc, builtin_type (objfile)->builtin_char,
   3372 				  range_type));
   3373 	    string_value
   3374 	      = (gdb_byte *) obstack_alloc (&objfile->objfile_obstack, ind + 1);
   3375 	    memcpy (string_value, string_local, ind + 1);
   3376 	    p++;
   3377 
   3378 	    sym->set_value_bytes (string_value);
   3379 	    sym->set_aclass_index (LOC_CONST_BYTES);
   3380 	  }
   3381 	  break;
   3382 
   3383 	case 'e':
   3384 	  /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
   3385 	     can be represented as integral.
   3386 	     e.g. "b:c=e6,0" for "const b = blob1"
   3387 	     (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;").  */
   3388 	  {
   3389 	    sym->set_aclass_index (LOC_CONST);
   3390 	    sym->set_type (read_type (&p, objfile));
   3391 
   3392 	    if (*p != ',')
   3393 	      {
   3394 		sym->set_type (error_type (&p, objfile));
   3395 		break;
   3396 	      }
   3397 	    ++p;
   3398 
   3399 	    /* If the value is too big to fit in an int (perhaps because
   3400 	       it is unsigned), or something like that, we silently get
   3401 	       a bogus value.  The type and everything else about it is
   3402 	       correct.  Ideally, we should be using whatever we have
   3403 	       available for parsing unsigned and long long values,
   3404 	       however.  */
   3405 	    sym->set_value_longest (atoi (p));
   3406 	  }
   3407 	  break;
   3408 	default:
   3409 	  {
   3410 	    sym->set_aclass_index (LOC_CONST);
   3411 	    sym->set_type (error_type (&p, objfile));
   3412 	  }
   3413 	}
   3414       sym->set_domain (VAR_DOMAIN);
   3415       add_symbol_to_list (sym, get_file_symbols ());
   3416       return sym;
   3417 
   3418     case 'C':
   3419       /* The name of a caught exception.  */
   3420       sym->set_type (read_type (&p, objfile));
   3421       sym->set_aclass_index (LOC_LABEL);
   3422       sym->set_domain (VAR_DOMAIN);
   3423       sym->set_value_address (valu);
   3424       add_symbol_to_list (sym, get_local_symbols ());
   3425       break;
   3426 
   3427     case 'f':
   3428       /* A static function definition.  */
   3429       sym->set_type (read_type (&p, objfile));
   3430       sym->set_aclass_index (LOC_BLOCK);
   3431       sym->set_domain (FUNCTION_DOMAIN);
   3432       add_symbol_to_list (sym, get_file_symbols ());
   3433       /* fall into process_function_types.  */
   3434 
   3435     process_function_types:
   3436       /* Function result types are described as the result type in stabs.
   3437 	 We need to convert this to the function-returning-type-X type
   3438 	 in GDB.  E.g. "int" is converted to "function returning int".  */
   3439       if (sym->type ()->code () != TYPE_CODE_FUNC)
   3440 	sym->set_type (lookup_function_type (sym->type ()));
   3441 
   3442       /* All functions in C++ have prototypes.  Stabs does not offer an
   3443 	 explicit way to identify prototyped or unprototyped functions,
   3444 	 but both GCC and Sun CC emit stabs for the "call-as" type rather
   3445 	 than the "declared-as" type for unprototyped functions, so
   3446 	 we treat all functions as if they were prototyped.  This is used
   3447 	 primarily for promotion when calling the function from GDB.  */
   3448       sym->type ()->set_is_prototyped (true);
   3449 
   3450       /* fall into process_prototype_types.  */
   3451 
   3452     process_prototype_types:
   3453       /* Sun acc puts declared types of arguments here.  */
   3454       if (*p == ';')
   3455 	{
   3456 	  struct type *ftype = sym->type ();
   3457 	  int nsemi = 0;
   3458 	  int nparams = 0;
   3459 	  const char *p1 = p;
   3460 
   3461 	  /* Obtain a worst case guess for the number of arguments
   3462 	     by counting the semicolons.  */
   3463 	  while (*p1)
   3464 	    {
   3465 	      if (*p1++ == ';')
   3466 		nsemi++;
   3467 	    }
   3468 
   3469 	  /* Allocate parameter information fields and fill them in.  */
   3470 	  ftype->alloc_fields (nsemi);
   3471 	  while (*p++ == ';')
   3472 	    {
   3473 	      struct type *ptype;
   3474 
   3475 	      /* A type number of zero indicates the start of varargs.
   3476 		 FIXME: GDB currently ignores vararg functions.  */
   3477 	      if (p[0] == '0' && p[1] == '\0')
   3478 		break;
   3479 	      ptype = read_type (&p, objfile);
   3480 
   3481 	      /* The Sun compilers mark integer arguments, which should
   3482 		 be promoted to the width of the calling conventions, with
   3483 		 a type which references itself.  This type is turned into
   3484 		 a TYPE_CODE_VOID type by read_type, and we have to turn
   3485 		 it back into builtin_int here.
   3486 		 FIXME: Do we need a new builtin_promoted_int_arg ?  */
   3487 	      if (ptype->code () == TYPE_CODE_VOID)
   3488 		ptype = builtin_type (objfile)->builtin_int;
   3489 	      ftype->field (nparams).set_type (ptype);
   3490 	      ftype->field (nparams).set_is_artificial (false);
   3491 	      nparams++;
   3492 	    }
   3493 	  ftype->set_num_fields (nparams);
   3494 	  ftype->set_is_prototyped (true);
   3495 	}
   3496       break;
   3497 
   3498     case 'F':
   3499       /* A global function definition.  */
   3500       sym->set_type (read_type (&p, objfile));
   3501       sym->set_aclass_index (LOC_BLOCK);
   3502       sym->set_domain (FUNCTION_DOMAIN);
   3503       add_symbol_to_list (sym, get_global_symbols ());
   3504       goto process_function_types;
   3505 
   3506     case 'G':
   3507       /* For a class G (global) symbol, it appears that the
   3508 	 value is not correct.  It is necessary to search for the
   3509 	 corresponding linker definition to find the value.
   3510 	 These definitions appear at the end of the namelist.  */
   3511       sym->set_type (read_type (&p, objfile));
   3512       sym->set_aclass_index (LOC_STATIC);
   3513       sym->set_domain (VAR_DOMAIN);
   3514       /* Don't add symbol references to global_sym_chain.
   3515 	 Symbol references don't have valid names and wont't match up with
   3516 	 minimal symbols when the global_sym_chain is relocated.
   3517 	 We'll fixup symbol references when we fixup the defining symbol.  */
   3518       if (sym->linkage_name () && sym->linkage_name ()[0] != '#')
   3519 	{
   3520 	  i = hashname (sym->linkage_name ());
   3521 	  sym->set_value_chain (global_sym_chain[i]);
   3522 	  global_sym_chain[i] = sym;
   3523 	}
   3524       add_symbol_to_list (sym, get_global_symbols ());
   3525       break;
   3526 
   3527       /* This case is faked by a conditional above,
   3528 	 when there is no code letter in the dbx data.
   3529 	 Dbx data never actually contains 'l'.  */
   3530     case 's':
   3531     case 'l':
   3532       sym->set_type (read_type (&p, objfile));
   3533       sym->set_aclass_index (LOC_LOCAL);
   3534       sym->set_value_longest (valu);
   3535       sym->set_domain (VAR_DOMAIN);
   3536       add_symbol_to_list (sym, get_local_symbols ());
   3537       break;
   3538 
   3539     case 'p':
   3540       if (*p == 'F')
   3541 	/* pF is a two-letter code that means a function parameter in Fortran.
   3542 	   The type-number specifies the type of the return value.
   3543 	   Translate it into a pointer-to-function type.  */
   3544 	{
   3545 	  p++;
   3546 	  sym->set_type
   3547 	    (lookup_pointer_type
   3548 	       (lookup_function_type (read_type (&p, objfile))));
   3549 	}
   3550       else
   3551 	sym->set_type (read_type (&p, objfile));
   3552 
   3553       sym->set_aclass_index (LOC_ARG);
   3554       sym->set_value_longest (valu);
   3555       sym->set_domain (VAR_DOMAIN);
   3556       sym->set_is_argument (1);
   3557       add_symbol_to_list (sym, get_local_symbols ());
   3558 
   3559       if (gdbarch_byte_order (gdbarch) != BFD_ENDIAN_BIG)
   3560 	{
   3561 	  /* On little-endian machines, this crud is never necessary,
   3562 	     and, if the extra bytes contain garbage, is harmful.  */
   3563 	  break;
   3564 	}
   3565 
   3566       /* If it's gcc-compiled, if it says `short', believe it.  */
   3567       if (processing_gcc_compilation
   3568 	  || gdbarch_believe_pcc_promotion (gdbarch))
   3569 	break;
   3570 
   3571       if (!gdbarch_believe_pcc_promotion (gdbarch))
   3572 	{
   3573 	  /* If PCC says a parameter is a short or a char, it is
   3574 	     really an int.  */
   3575 	  if (sym->type ()->length ()
   3576 	      < gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT
   3577 	      && sym->type ()->code () == TYPE_CODE_INT)
   3578 	    {
   3579 	      sym->set_type
   3580 		(sym->type ()->is_unsigned ()
   3581 		 ? builtin_type (objfile)->builtin_unsigned_int
   3582 		 : builtin_type (objfile)->builtin_int);
   3583 	    }
   3584 	  break;
   3585 	}
   3586       [[fallthrough]];
   3587 
   3588     case 'P':
   3589       /* acc seems to use P to declare the prototypes of functions that
   3590 	 are referenced by this file.  gdb is not prepared to deal
   3591 	 with this extra information.  FIXME, it ought to.  */
   3592       if (type == N_FUN)
   3593 	{
   3594 	  sym->set_type (read_type (&p, objfile));
   3595 	  goto process_prototype_types;
   3596 	}
   3597       [[fallthrough]];
   3598 
   3599     case 'R':
   3600       /* Parameter which is in a register.  */
   3601       sym->set_type (read_type (&p, objfile));
   3602       sym->set_aclass_index (stab_register_index);
   3603       sym->set_is_argument (1);
   3604       sym->set_value_longest (valu);
   3605       sym->set_domain (VAR_DOMAIN);
   3606       add_symbol_to_list (sym, get_local_symbols ());
   3607       break;
   3608 
   3609     case 'r':
   3610       /* Register variable (either global or local).  */
   3611       sym->set_type (read_type (&p, objfile));
   3612       sym->set_aclass_index (stab_register_index);
   3613       sym->set_value_longest (valu);
   3614       sym->set_domain (VAR_DOMAIN);
   3615       if (within_function)
   3616 	{
   3617 	  /* Sun cc uses a pair of symbols, one 'p' and one 'r', with
   3618 	     the same name to represent an argument passed in a
   3619 	     register.  GCC uses 'P' for the same case.  So if we find
   3620 	     such a symbol pair we combine it into one 'P' symbol.
   3621 	     For Sun cc we need to do this regardless of stabs_argument_has_addr, because the compiler puts out
   3622 	     the 'p' symbol even if it never saves the argument onto
   3623 	     the stack.
   3624 
   3625 	     On most machines, we want to preserve both symbols, so
   3626 	     that we can still get information about what is going on
   3627 	     with the stack (VAX for computing args_printed, using
   3628 	     stack slots instead of saved registers in backtraces,
   3629 	     etc.).
   3630 
   3631 	     Note that this code illegally combines
   3632 	     main(argc) struct foo argc; { register struct foo argc; }
   3633 	     but this case is considered pathological and causes a warning
   3634 	     from a decent compiler.  */
   3635 
   3636 	  struct pending *local_symbols = *get_local_symbols ();
   3637 	  if (local_symbols
   3638 	      && local_symbols->nsyms > 0
   3639 	      && gdbarch_stabs_argument_has_addr (gdbarch, sym->type ()))
   3640 	    {
   3641 	      struct symbol *prev_sym;
   3642 
   3643 	      prev_sym = local_symbols->symbol[local_symbols->nsyms - 1];
   3644 	      if ((prev_sym->aclass () == LOC_REF_ARG
   3645 		   || prev_sym->aclass () == LOC_ARG)
   3646 		  && strcmp (prev_sym->linkage_name (),
   3647 			     sym->linkage_name ()) == 0)
   3648 		{
   3649 		  prev_sym->set_aclass_index (stab_register_index);
   3650 		  /* Use the type from the LOC_REGISTER; that is the type
   3651 		     that is actually in that register.  */
   3652 		  prev_sym->set_type (sym->type ());
   3653 		  prev_sym->set_value_longest (sym->value_longest ());
   3654 		  sym = prev_sym;
   3655 		  break;
   3656 		}
   3657 	    }
   3658 	  add_symbol_to_list (sym, get_local_symbols ());
   3659 	}
   3660       else
   3661 	add_symbol_to_list (sym, get_file_symbols ());
   3662       break;
   3663 
   3664     case 'S':
   3665       /* Static symbol at top level of file.  */
   3666       sym->set_type (read_type (&p, objfile));
   3667       sym->set_aclass_index (LOC_STATIC);
   3668       sym->set_value_address (valu);
   3669       sym->set_domain (VAR_DOMAIN);
   3670       add_symbol_to_list (sym, get_file_symbols ());
   3671       break;
   3672 
   3673     case 't':
   3674       /* In Ada, there is no distinction between typedef and non-typedef;
   3675 	 any type declaration implicitly has the equivalent of a typedef,
   3676 	 and thus 't' is in fact equivalent to 'Tt'.
   3677 
   3678 	 Therefore, for Ada units, we check the character immediately
   3679 	 before the 't', and if we do not find a 'T', then make sure to
   3680 	 create the associated symbol in the STRUCT_DOMAIN ('t' definitions
   3681 	 will be stored in the VAR_DOMAIN).  If the symbol was indeed
   3682 	 defined as 'Tt' then the STRUCT_DOMAIN symbol will be created
   3683 	 elsewhere, so we don't need to take care of that.
   3684 
   3685 	 This is important to do, because of forward references:
   3686 	 The cleanup of undefined types stored in undef_types only uses
   3687 	 STRUCT_DOMAIN symbols to perform the replacement.  */
   3688       synonym = (sym->language () == language_ada && p[-2] != 'T');
   3689 
   3690       /* Typedef */
   3691       sym->set_type (read_type (&p, objfile));
   3692 
   3693       /* For a nameless type, we don't want a create a symbol, thus we
   3694 	 did not use `sym'.  Return without further processing.  */
   3695       if (nameless)
   3696 	return NULL;
   3697 
   3698       sym->set_aclass_index (LOC_TYPEDEF);
   3699       sym->set_value_longest (valu);
   3700       sym->set_domain (TYPE_DOMAIN);
   3701       /* C++ vagaries: we may have a type which is derived from
   3702 	 a base type which did not have its name defined when the
   3703 	 derived class was output.  We fill in the derived class's
   3704 	 base part member's name here in that case.  */
   3705       if (sym->type ()->name () != NULL)
   3706 	if ((sym->type ()->code () == TYPE_CODE_STRUCT
   3707 	     || sym->type ()->code () == TYPE_CODE_UNION)
   3708 	    && TYPE_N_BASECLASSES (sym->type ()))
   3709 	  {
   3710 	    int j;
   3711 
   3712 	    for (j = TYPE_N_BASECLASSES (sym->type ()) - 1; j >= 0; j--)
   3713 	      if (TYPE_BASECLASS_NAME (sym->type (), j) == 0)
   3714 		sym->type ()->field (j).set_name
   3715 		  (TYPE_BASECLASS (sym->type (), j)->name ());
   3716 	  }
   3717 
   3718       if (sym->type ()->name () == NULL)
   3719 	{
   3720 	  if ((sym->type ()->code () == TYPE_CODE_PTR
   3721 	       && strcmp (sym->linkage_name (), vtbl_ptr_name))
   3722 	      || sym->type ()->code () == TYPE_CODE_FUNC)
   3723 	    {
   3724 	      /* If we are giving a name to a type such as "pointer to
   3725 		 foo" or "function returning foo", we better not set
   3726 		 the TYPE_NAME.  If the program contains "typedef char
   3727 		 *caddr_t;", we don't want all variables of type char
   3728 		 * to print as caddr_t.  This is not just a
   3729 		 consequence of GDB's type management; PCC and GCC (at
   3730 		 least through version 2.4) both output variables of
   3731 		 either type char * or caddr_t with the type number
   3732 		 defined in the 't' symbol for caddr_t.  If a future
   3733 		 compiler cleans this up it GDB is not ready for it
   3734 		 yet, but if it becomes ready we somehow need to
   3735 		 disable this check (without breaking the PCC/GCC2.4
   3736 		 case).
   3737 
   3738 		 Sigh.
   3739 
   3740 		 Fortunately, this check seems not to be necessary
   3741 		 for anything except pointers or functions.  */
   3742 	      /* ezannoni: 2000-10-26.  This seems to apply for
   3743 		 versions of gcc older than 2.8.  This was the original
   3744 		 problem: with the following code gdb would tell that
   3745 		 the type for name1 is caddr_t, and func is char().
   3746 
   3747 		 typedef char *caddr_t;
   3748 		 char *name2;
   3749 		 struct x
   3750 		 {
   3751 		   char *name1;
   3752 		 } xx;
   3753 		 char *func()
   3754 		 {
   3755 		 }
   3756 		 main () {}
   3757 		 */
   3758 
   3759 	      /* Pascal accepts names for pointer types.  */
   3760 	      if (get_current_subfile ()->language == language_pascal)
   3761 		sym->type ()->set_name (sym->linkage_name ());
   3762 	    }
   3763 	  else
   3764 	    sym->type ()->set_name (sym->linkage_name ());
   3765 	}
   3766 
   3767       add_symbol_to_list (sym, get_file_symbols ());
   3768 
   3769       if (synonym)
   3770 	{
   3771 	  /* Create the STRUCT_DOMAIN clone.  */
   3772 	  struct symbol *struct_sym = new (&objfile->objfile_obstack) symbol;
   3773 
   3774 	  *struct_sym = *sym;
   3775 	  struct_sym->set_aclass_index (LOC_TYPEDEF);
   3776 	  struct_sym->set_value_longest (valu);
   3777 	  struct_sym->set_domain (STRUCT_DOMAIN);
   3778 	  if (sym->type ()->name () == 0)
   3779 	    sym->type ()->set_name
   3780 	      (obconcat (&objfile->objfile_obstack, sym->linkage_name (),
   3781 			 (char *) NULL));
   3782 	  add_symbol_to_list (struct_sym, get_file_symbols ());
   3783 	}
   3784 
   3785       break;
   3786 
   3787     case 'T':
   3788       /* Struct, union, or enum tag.  For GNU C++, this can be be followed
   3789 	 by 't' which means we are typedef'ing it as well.  */
   3790       synonym = *p == 't';
   3791 
   3792       if (synonym)
   3793 	p++;
   3794 
   3795       sym->set_type (read_type (&p, objfile));
   3796 
   3797       /* For a nameless type, we don't want a create a symbol, thus we
   3798 	 did not use `sym'.  Return without further processing.  */
   3799       if (nameless)
   3800 	return NULL;
   3801 
   3802       sym->set_aclass_index (LOC_TYPEDEF);
   3803       sym->set_value_longest (valu);
   3804       sym->set_domain (STRUCT_DOMAIN);
   3805       if (sym->type ()->name () == 0)
   3806 	sym->type ()->set_name
   3807 	  (obconcat (&objfile->objfile_obstack, sym->linkage_name (),
   3808 		     (char *) NULL));
   3809       add_symbol_to_list (sym, get_file_symbols ());
   3810 
   3811       if (synonym)
   3812 	{
   3813 	  /* Clone the sym and then modify it.  */
   3814 	  struct symbol *typedef_sym = new (&objfile->objfile_obstack) symbol;
   3815 
   3816 	  *typedef_sym = *sym;
   3817 	  typedef_sym->set_aclass_index (LOC_TYPEDEF);
   3818 	  typedef_sym->set_value_longest (valu);
   3819 	  typedef_sym->set_domain (TYPE_DOMAIN);
   3820 	  if (sym->type ()->name () == 0)
   3821 	    sym->type ()->set_name
   3822 	      (obconcat (&objfile->objfile_obstack, sym->linkage_name (),
   3823 			 (char *) NULL));
   3824 	  add_symbol_to_list (typedef_sym, get_file_symbols ());
   3825 	}
   3826       break;
   3827 
   3828     case 'V':
   3829       /* Static symbol of local scope.  */
   3830       sym->set_type (read_type (&p, objfile));
   3831       sym->set_aclass_index (LOC_STATIC);
   3832       sym->set_value_address (valu);
   3833       sym->set_domain (VAR_DOMAIN);
   3834       add_symbol_to_list (sym, get_local_symbols ());
   3835       break;
   3836 
   3837     case 'v':
   3838       /* Reference parameter */
   3839       sym->set_type (read_type (&p, objfile));
   3840       sym->set_aclass_index (LOC_REF_ARG);
   3841       sym->set_is_argument (1);
   3842       sym->set_value_longest (valu);
   3843       sym->set_domain (VAR_DOMAIN);
   3844       add_symbol_to_list (sym, get_local_symbols ());
   3845       break;
   3846 
   3847     case 'a':
   3848       /* Reference parameter which is in a register.  */
   3849       sym->set_type (read_type (&p, objfile));
   3850       sym->set_aclass_index (stab_regparm_index);
   3851       sym->set_is_argument (1);
   3852       sym->set_value_longest (valu);
   3853       sym->set_domain (VAR_DOMAIN);
   3854       add_symbol_to_list (sym, get_local_symbols ());
   3855       break;
   3856 
   3857     case 'X':
   3858       /* This is used by Sun FORTRAN for "function result value".
   3859 	 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
   3860 	 that Pascal uses it too, but when I tried it Pascal used
   3861 	 "x:3" (local symbol) instead.  */
   3862       sym->set_type (read_type (&p, objfile));
   3863       sym->set_aclass_index (LOC_LOCAL);
   3864       sym->set_value_longest (valu);
   3865       sym->set_domain (VAR_DOMAIN);
   3866       add_symbol_to_list (sym, get_local_symbols ());
   3867       break;
   3868 
   3869     default:
   3870       sym->set_type (error_type (&p, objfile));
   3871       sym->set_aclass_index (LOC_CONST);
   3872       sym->set_value_longest (0);
   3873       sym->set_domain (VAR_DOMAIN);
   3874       add_symbol_to_list (sym, get_file_symbols ());
   3875       break;
   3876     }
   3877 
   3878   /* Some systems pass variables of certain types by reference instead
   3879      of by value, i.e. they will pass the address of a structure (in a
   3880      register or on the stack) instead of the structure itself.  */
   3881 
   3882   if (gdbarch_stabs_argument_has_addr (gdbarch, sym->type ())
   3883       && sym->is_argument ())
   3884     {
   3885       /* We have to convert LOC_REGISTER to LOC_REGPARM_ADDR (for
   3886 	 variables passed in a register).  */
   3887       if (sym->aclass () == LOC_REGISTER)
   3888 	sym->set_aclass_index (LOC_REGPARM_ADDR);
   3889       /* Likewise for converting LOC_ARG to LOC_REF_ARG (for the 7th
   3890 	 and subsequent arguments on SPARC, for example).  */
   3891       else if (sym->aclass () == LOC_ARG)
   3892 	sym->set_aclass_index (LOC_REF_ARG);
   3893     }
   3894 
   3895   return sym;
   3896 }
   3897 
   3898 /* Skip rest of this symbol and return an error type.
   3899 
   3900    General notes on error recovery:  error_type always skips to the
   3901    end of the symbol (modulo cretinous dbx symbol name continuation).
   3902    Thus code like this:
   3903 
   3904    if (*(*pp)++ != ';')
   3905    return error_type (pp, objfile);
   3906 
   3907    is wrong because if *pp starts out pointing at '\0' (typically as the
   3908    result of an earlier error), it will be incremented to point to the
   3909    start of the next symbol, which might produce strange results, at least
   3910    if you run off the end of the string table.  Instead use
   3911 
   3912    if (**pp != ';')
   3913    return error_type (pp, objfile);
   3914    ++*pp;
   3915 
   3916    or
   3917 
   3918    if (**pp != ';')
   3919    foo = error_type (pp, objfile);
   3920    else
   3921    ++*pp;
   3922 
   3923    And in case it isn't obvious, the point of all this hair is so the compiler
   3924    can define new types and new syntaxes, and old versions of the
   3925    debugger will be able to read the new symbol tables.  */
   3926 
   3927 static struct type *
   3928 error_type (const char **pp, struct objfile *objfile)
   3929 {
   3930   complaint (_("couldn't parse type; debugger out of date?"));
   3931   while (1)
   3932     {
   3933       /* Skip to end of symbol.  */
   3934       while (**pp != '\0')
   3935 	{
   3936 	  (*pp)++;
   3937 	}
   3938 
   3939       /* Check for and handle cretinous dbx symbol name continuation!  */
   3940       if ((*pp)[-1] == '\\' || (*pp)[-1] == '?')
   3941 	{
   3942 	  *pp = next_symbol_text (objfile);
   3943 	}
   3944       else
   3945 	{
   3946 	  break;
   3947 	}
   3948     }
   3949   return builtin_type (objfile)->builtin_error;
   3950 }
   3951 
   3952 
   3954 /* Allocate a stub method whose return type is TYPE.  This apparently
   3955    happens for speed of symbol reading, since parsing out the
   3956    arguments to the method is cpu-intensive, the way we are doing it.
   3957    So, we will fill in arguments later.  This always returns a fresh
   3958    type.  */
   3959 
   3960 static struct type *
   3961 allocate_stub_method (struct type *type)
   3962 {
   3963   struct type *mtype;
   3964 
   3965   mtype = type_allocator (type).new_type ();
   3966   mtype->set_code (TYPE_CODE_METHOD);
   3967   mtype->set_length (1);
   3968   mtype->set_is_stub (true);
   3969   mtype->set_target_type (type);
   3970   /* TYPE_SELF_TYPE (mtype) = unknown yet */
   3971   return mtype;
   3972 }
   3973 
   3974 /* Read type information or a type definition; return the type.  Even
   3975    though this routine accepts either type information or a type
   3976    definition, the distinction is relevant--some parts of stabsread.c
   3977    assume that type information starts with a digit, '-', or '(' in
   3978    deciding whether to call read_type.  */
   3979 
   3980 static struct type *
   3981 read_type (const char **pp, struct objfile *objfile)
   3982 {
   3983   struct type *type = 0;
   3984   struct type *type1;
   3985   int typenums[2];
   3986   char type_descriptor;
   3987 
   3988   /* Size in bits of type if specified by a type attribute, or -1 if
   3989      there is no size attribute.  */
   3990   int type_size = -1;
   3991 
   3992   /* Used to distinguish string and bitstring from char-array and set.  */
   3993   int is_string = 0;
   3994 
   3995   /* Used to distinguish vector from array.  */
   3996   int is_vector = 0;
   3997 
   3998   /* Read type number if present.  The type number may be omitted.
   3999      for instance in a two-dimensional array declared with type
   4000      "ar1;1;10;ar1;1;10;4".  */
   4001   if ((**pp >= '0' && **pp <= '9')
   4002       || **pp == '('
   4003       || **pp == '-')
   4004     {
   4005       if (read_type_number (pp, typenums) != 0)
   4006 	return error_type (pp, objfile);
   4007 
   4008       if (**pp != '=')
   4009 	{
   4010 	  /* Type is not being defined here.  Either it already
   4011 	     exists, or this is a forward reference to it.
   4012 	     dbx_alloc_type handles both cases.  */
   4013 	  type = dbx_alloc_type (typenums, objfile);
   4014 
   4015 	  /* If this is a forward reference, arrange to complain if it
   4016 	     doesn't get patched up by the time we're done
   4017 	     reading.  */
   4018 	  if (type->code () == TYPE_CODE_UNDEF)
   4019 	    add_undefined_type (type, typenums);
   4020 
   4021 	  return type;
   4022 	}
   4023 
   4024       /* Type is being defined here.  */
   4025       /* Skip the '='.
   4026 	 Also skip the type descriptor - we get it below with (*pp)[-1].  */
   4027       (*pp) += 2;
   4028     }
   4029   else
   4030     {
   4031       /* 'typenums=' not present, type is anonymous.  Read and return
   4032 	 the definition, but don't put it in the type vector.  */
   4033       typenums[0] = typenums[1] = -1;
   4034       (*pp)++;
   4035     }
   4036 
   4037 again:
   4038   type_descriptor = (*pp)[-1];
   4039   switch (type_descriptor)
   4040     {
   4041     case 'x':
   4042       {
   4043 	enum type_code code;
   4044 
   4045 	/* Used to index through file_symbols.  */
   4046 	struct pending *ppt;
   4047 	int i;
   4048 
   4049 	/* Name including "struct", etc.  */
   4050 	char *type_name;
   4051 
   4052 	{
   4053 	  const char *from, *p, *q1, *q2;
   4054 
   4055 	  /* Set the type code according to the following letter.  */
   4056 	  switch ((*pp)[0])
   4057 	    {
   4058 	    case 's':
   4059 	      code = TYPE_CODE_STRUCT;
   4060 	      break;
   4061 	    case 'u':
   4062 	      code = TYPE_CODE_UNION;
   4063 	      break;
   4064 	    case 'e':
   4065 	      code = TYPE_CODE_ENUM;
   4066 	      break;
   4067 	    default:
   4068 	      {
   4069 		/* Complain and keep going, so compilers can invent new
   4070 		   cross-reference types.  */
   4071 		complaint (_("Unrecognized cross-reference type `%c'"),
   4072 			   (*pp)[0]);
   4073 		code = TYPE_CODE_STRUCT;
   4074 		break;
   4075 	      }
   4076 	    }
   4077 
   4078 	  q1 = strchr (*pp, '<');
   4079 	  p = strchr (*pp, ':');
   4080 	  if (p == NULL)
   4081 	    return error_type (pp, objfile);
   4082 	  if (q1 && p > q1 && p[1] == ':')
   4083 	    {
   4084 	      int nesting_level = 0;
   4085 
   4086 	      for (q2 = q1; *q2; q2++)
   4087 		{
   4088 		  if (*q2 == '<')
   4089 		    nesting_level++;
   4090 		  else if (*q2 == '>')
   4091 		    nesting_level--;
   4092 		  else if (*q2 == ':' && nesting_level == 0)
   4093 		    break;
   4094 		}
   4095 	      p = q2;
   4096 	      if (*p != ':')
   4097 		return error_type (pp, objfile);
   4098 	    }
   4099 	  type_name = NULL;
   4100 	  if (get_current_subfile ()->language == language_cplus)
   4101 	    {
   4102 	      std::string name (*pp, p - *pp);
   4103 	      gdb::unique_xmalloc_ptr<char> new_name
   4104 		= cp_canonicalize_string (name.c_str ());
   4105 	      if (new_name != nullptr)
   4106 		type_name = obstack_strdup (&objfile->objfile_obstack,
   4107 					    new_name.get ());
   4108 	    }
   4109 	  else if (get_current_subfile ()->language == language_c)
   4110 	    {
   4111 	      std::string name (*pp, p - *pp);
   4112 	      gdb::unique_xmalloc_ptr<char> new_name
   4113 		= c_canonicalize_name (name.c_str ());
   4114 	      if (new_name != nullptr)
   4115 		type_name = obstack_strdup (&objfile->objfile_obstack,
   4116 					    new_name.get ());
   4117 	    }
   4118 	  if (type_name == NULL)
   4119 	    {
   4120 	      char *to = type_name = (char *)
   4121 		obstack_alloc (&objfile->objfile_obstack, p - *pp + 1);
   4122 
   4123 	      /* Copy the name.  */
   4124 	      from = *pp + 1;
   4125 	      while (from < p)
   4126 		*to++ = *from++;
   4127 	      *to = '\0';
   4128 	    }
   4129 
   4130 	  /* Set the pointer ahead of the name which we just read, and
   4131 	     the colon.  */
   4132 	  *pp = p + 1;
   4133 	}
   4134 
   4135 	/* If this type has already been declared, then reuse the same
   4136 	   type, rather than allocating a new one.  This saves some
   4137 	   memory.  */
   4138 
   4139 	for (ppt = *get_file_symbols (); ppt; ppt = ppt->next)
   4140 	  for (i = 0; i < ppt->nsyms; i++)
   4141 	    {
   4142 	      struct symbol *sym = ppt->symbol[i];
   4143 
   4144 	      if (sym->aclass () == LOC_TYPEDEF
   4145 		  && sym->domain () == STRUCT_DOMAIN
   4146 		  && (sym->type ()->code () == code)
   4147 		  && strcmp (sym->linkage_name (), type_name) == 0)
   4148 		{
   4149 		  obstack_free (&objfile->objfile_obstack, type_name);
   4150 		  type = sym->type ();
   4151 		  if (typenums[0] != -1)
   4152 		    *dbx_lookup_type (typenums, objfile) = type;
   4153 		  return type;
   4154 		}
   4155 	    }
   4156 
   4157 	/* Didn't find the type to which this refers, so we must
   4158 	   be dealing with a forward reference.  Allocate a type
   4159 	   structure for it, and keep track of it so we can
   4160 	   fill in the rest of the fields when we get the full
   4161 	   type.  */
   4162 	type = dbx_alloc_type (typenums, objfile);
   4163 	type->set_code (code);
   4164 	type->set_name (type_name);
   4165 	INIT_CPLUS_SPECIFIC (type);
   4166 	type->set_is_stub (true);
   4167 
   4168 	add_undefined_type (type, typenums);
   4169 	return type;
   4170       }
   4171 
   4172     case '-':			/* RS/6000 built-in type */
   4173     case '0':
   4174     case '1':
   4175     case '2':
   4176     case '3':
   4177     case '4':
   4178     case '5':
   4179     case '6':
   4180     case '7':
   4181     case '8':
   4182     case '9':
   4183     case '(':
   4184       (*pp)--;
   4185 
   4186       /* We deal with something like t(1,2)=(3,4)=... which
   4187 	 the Lucid compiler and recent gcc versions (post 2.7.3) use.  */
   4188 
   4189       /* Allocate and enter the typedef type first.
   4190 	 This handles recursive types.  */
   4191       type = dbx_alloc_type (typenums, objfile);
   4192       type->set_code (TYPE_CODE_TYPEDEF);
   4193       {
   4194 	struct type *xtype = read_type (pp, objfile);
   4195 
   4196 	if (type == xtype)
   4197 	  {
   4198 	    /* It's being defined as itself.  That means it is "void".  */
   4199 	    type->set_code (TYPE_CODE_VOID);
   4200 	    type->set_length (1);
   4201 	  }
   4202 	else if (type_size >= 0 || is_string)
   4203 	  {
   4204 	    /* This is the absolute wrong way to construct types.  Every
   4205 	       other debug format has found a way around this problem and
   4206 	       the related problems with unnecessarily stubbed types;
   4207 	       someone motivated should attempt to clean up the issue
   4208 	       here as well.  Once a type pointed to has been created it
   4209 	       should not be modified.
   4210 
   4211 	       Well, it's not *absolutely* wrong.  Constructing recursive
   4212 	       types (trees, linked lists) necessarily entails modifying
   4213 	       types after creating them.  Constructing any loop structure
   4214 	       entails side effects.  The Dwarf 2 reader does handle this
   4215 	       more gracefully (it never constructs more than once
   4216 	       instance of a type object, so it doesn't have to copy type
   4217 	       objects wholesale), but it still mutates type objects after
   4218 	       other folks have references to them.
   4219 
   4220 	       Keep in mind that this circularity/mutation issue shows up
   4221 	       at the source language level, too: C's "incomplete types",
   4222 	       for example.  So the proper cleanup, I think, would be to
   4223 	       limit GDB's type smashing to match exactly those required
   4224 	       by the source language.  So GDB could have a
   4225 	       "complete_this_type" function, but never create unnecessary
   4226 	       copies of a type otherwise.  */
   4227 	    replace_type (type, xtype);
   4228 	    type->set_name (NULL);
   4229 	  }
   4230 	else
   4231 	  {
   4232 	    type->set_target_is_stub (true);
   4233 	    type->set_target_type (xtype);
   4234 	  }
   4235       }
   4236       break;
   4237 
   4238       /* In the following types, we must be sure to overwrite any existing
   4239 	 type that the typenums refer to, rather than allocating a new one
   4240 	 and making the typenums point to the new one.  This is because there
   4241 	 may already be pointers to the existing type (if it had been
   4242 	 forward-referenced), and we must change it to a pointer, function,
   4243 	 reference, or whatever, *in-place*.  */
   4244 
   4245     case '*':			/* Pointer to another type */
   4246       type1 = read_type (pp, objfile);
   4247       type = make_pointer_type (type1, dbx_lookup_type (typenums, objfile));
   4248       break;
   4249 
   4250     case '&':			/* Reference to another type */
   4251       type1 = read_type (pp, objfile);
   4252       type = make_reference_type (type1, dbx_lookup_type (typenums, objfile),
   4253 				  TYPE_CODE_REF);
   4254       break;
   4255 
   4256     case 'f':			/* Function returning another type */
   4257       type1 = read_type (pp, objfile);
   4258       type = make_function_type (type1, dbx_lookup_type (typenums, objfile));
   4259       break;
   4260 
   4261     case 'g':                   /* Prototyped function.  (Sun)  */
   4262       {
   4263 	/* Unresolved questions:
   4264 
   4265 	   - According to Sun's ``STABS Interface Manual'', for 'f'
   4266 	   and 'F' symbol descriptors, a `0' in the argument type list
   4267 	   indicates a varargs function.  But it doesn't say how 'g'
   4268 	   type descriptors represent that info.  Someone with access
   4269 	   to Sun's toolchain should try it out.
   4270 
   4271 	   - According to the comment in define_symbol (search for
   4272 	   `process_prototype_types:'), Sun emits integer arguments as
   4273 	   types which ref themselves --- like `void' types.  Do we
   4274 	   have to deal with that here, too?  Again, someone with
   4275 	   access to Sun's toolchain should try it out and let us
   4276 	   know.  */
   4277 
   4278 	const char *type_start = (*pp) - 1;
   4279 	struct type *return_type = read_type (pp, objfile);
   4280 	struct type *func_type
   4281 	  = make_function_type (return_type,
   4282 				dbx_lookup_type (typenums, objfile));
   4283 	struct type_list {
   4284 	  struct type *type;
   4285 	  struct type_list *next;
   4286 	} *arg_types = 0;
   4287 	int num_args = 0;
   4288 
   4289 	while (**pp && **pp != '#')
   4290 	  {
   4291 	    struct type *arg_type = read_type (pp, objfile);
   4292 	    struct type_list *newobj = XALLOCA (struct type_list);
   4293 	    newobj->type = arg_type;
   4294 	    newobj->next = arg_types;
   4295 	    arg_types = newobj;
   4296 	    num_args++;
   4297 	  }
   4298 	if (**pp == '#')
   4299 	  ++*pp;
   4300 	else
   4301 	  {
   4302 	    complaint (_("Prototyped function type didn't "
   4303 			 "end arguments with `#':\n%s"),
   4304 		       type_start);
   4305 	  }
   4306 
   4307 	/* If there is just one argument whose type is `void', then
   4308 	   that's just an empty argument list.  */
   4309 	if (arg_types
   4310 	    && ! arg_types->next
   4311 	    && arg_types->type->code () == TYPE_CODE_VOID)
   4312 	  num_args = 0;
   4313 
   4314 	func_type->alloc_fields (num_args);
   4315 	{
   4316 	  int i;
   4317 	  struct type_list *t;
   4318 
   4319 	  /* We stuck each argument type onto the front of the list
   4320 	     when we read it, so the list is reversed.  Build the
   4321 	     fields array right-to-left.  */
   4322 	  for (t = arg_types, i = num_args - 1; t; t = t->next, i--)
   4323 	    func_type->field (i).set_type (t->type);
   4324 	}
   4325 	func_type->set_num_fields (num_args);
   4326 	func_type->set_is_prototyped (true);
   4327 
   4328 	type = func_type;
   4329 	break;
   4330       }
   4331 
   4332     case 'k':			/* Const qualifier on some type (Sun) */
   4333       type = read_type (pp, objfile);
   4334       type = make_cv_type (1, TYPE_VOLATILE (type), type,
   4335 			   dbx_lookup_type (typenums, objfile));
   4336       break;
   4337 
   4338     case 'B':			/* Volatile qual on some type (Sun) */
   4339       type = read_type (pp, objfile);
   4340       type = make_cv_type (TYPE_CONST (type), 1, type,
   4341 			   dbx_lookup_type (typenums, objfile));
   4342       break;
   4343 
   4344     case '@':
   4345       if (isdigit ((unsigned char)**pp) || **pp == '(' || **pp == '-')
   4346 	{			/* Member (class & variable) type */
   4347 	  /* FIXME -- we should be doing smash_to_XXX types here.  */
   4348 
   4349 	  struct type *domain = read_type (pp, objfile);
   4350 	  struct type *memtype;
   4351 
   4352 	  if (**pp != ',')
   4353 	    /* Invalid member type data format.  */
   4354 	    return error_type (pp, objfile);
   4355 	  ++*pp;
   4356 
   4357 	  memtype = read_type (pp, objfile);
   4358 	  type = dbx_alloc_type (typenums, objfile);
   4359 	  smash_to_memberptr_type (type, domain, memtype);
   4360 	}
   4361       else
   4362 	/* type attribute */
   4363 	{
   4364 	  const char *attr = *pp;
   4365 
   4366 	  /* Skip to the semicolon.  */
   4367 	  while (**pp != ';' && **pp != '\0')
   4368 	    ++(*pp);
   4369 	  if (**pp == '\0')
   4370 	    return error_type (pp, objfile);
   4371 	  else
   4372 	    ++ * pp;		/* Skip the semicolon.  */
   4373 
   4374 	  switch (*attr)
   4375 	    {
   4376 	    case 's':		/* Size attribute */
   4377 	      type_size = atoi (attr + 1);
   4378 	      if (type_size <= 0)
   4379 		type_size = -1;
   4380 	      break;
   4381 
   4382 	    case 'S':		/* String attribute */
   4383 	      /* FIXME: check to see if following type is array?  */
   4384 	      is_string = 1;
   4385 	      break;
   4386 
   4387 	    case 'V':		/* Vector attribute */
   4388 	      /* FIXME: check to see if following type is array?  */
   4389 	      is_vector = 1;
   4390 	      break;
   4391 
   4392 	    default:
   4393 	      /* Ignore unrecognized type attributes, so future compilers
   4394 		 can invent new ones.  */
   4395 	      break;
   4396 	    }
   4397 	  ++*pp;
   4398 	  goto again;
   4399 	}
   4400       break;
   4401 
   4402     case '#':			/* Method (class & fn) type */
   4403       if ((*pp)[0] == '#')
   4404 	{
   4405 	  /* We'll get the parameter types from the name.  */
   4406 	  struct type *return_type;
   4407 
   4408 	  (*pp)++;
   4409 	  return_type = read_type (pp, objfile);
   4410 	  if (*(*pp)++ != ';')
   4411 	    complaint (_("invalid (minimal) member type "
   4412 			 "data format at symtab pos %d."),
   4413 		       symnum);
   4414 	  type = allocate_stub_method (return_type);
   4415 	  if (typenums[0] != -1)
   4416 	    *dbx_lookup_type (typenums, objfile) = type;
   4417 	}
   4418       else
   4419 	{
   4420 	  struct type *domain = read_type (pp, objfile);
   4421 	  struct type *return_type;
   4422 	  struct field *args;
   4423 	  int nargs, varargs;
   4424 
   4425 	  if (**pp != ',')
   4426 	    /* Invalid member type data format.  */
   4427 	    return error_type (pp, objfile);
   4428 	  else
   4429 	    ++(*pp);
   4430 
   4431 	  return_type = read_type (pp, objfile);
   4432 	  args = read_args (pp, ';', objfile, &nargs, &varargs);
   4433 	  if (args == NULL)
   4434 	    return error_type (pp, objfile);
   4435 	  type = dbx_alloc_type (typenums, objfile);
   4436 	  smash_to_method_type (type, domain, return_type, args,
   4437 				nargs, varargs);
   4438 	}
   4439       break;
   4440 
   4441     case 'r':			/* Range type */
   4442       type = read_range_type (pp, typenums, type_size, objfile);
   4443       if (typenums[0] != -1)
   4444 	*dbx_lookup_type (typenums, objfile) = type;
   4445       break;
   4446 
   4447     case 'b':
   4448 	{
   4449 	  /* Sun ACC builtin int type */
   4450 	  type = read_sun_builtin_type (pp, typenums, objfile);
   4451 	  if (typenums[0] != -1)
   4452 	    *dbx_lookup_type (typenums, objfile) = type;
   4453 	}
   4454       break;
   4455 
   4456     case 'R':			/* Sun ACC builtin float type */
   4457       type = read_sun_floating_type (pp, typenums, objfile);
   4458       if (typenums[0] != -1)
   4459 	*dbx_lookup_type (typenums, objfile) = type;
   4460       break;
   4461 
   4462     case 'e':			/* Enumeration type */
   4463       type = dbx_alloc_type (typenums, objfile);
   4464       type = read_enum_type (pp, type, objfile);
   4465       if (typenums[0] != -1)
   4466 	*dbx_lookup_type (typenums, objfile) = type;
   4467       break;
   4468 
   4469     case 's':			/* Struct type */
   4470     case 'u':			/* Union type */
   4471       {
   4472 	enum type_code type_code = TYPE_CODE_UNDEF;
   4473 	type = dbx_alloc_type (typenums, objfile);
   4474 	switch (type_descriptor)
   4475 	  {
   4476 	  case 's':
   4477 	    type_code = TYPE_CODE_STRUCT;
   4478 	    break;
   4479 	  case 'u':
   4480 	    type_code = TYPE_CODE_UNION;
   4481 	    break;
   4482 	  }
   4483 	type = read_struct_type (pp, type, type_code, objfile);
   4484 	break;
   4485       }
   4486 
   4487     case 'a':			/* Array type */
   4488       if (**pp != 'r')
   4489 	return error_type (pp, objfile);
   4490       ++*pp;
   4491 
   4492       type = dbx_alloc_type (typenums, objfile);
   4493       type = read_array_type (pp, type, objfile);
   4494       if (is_string)
   4495 	type->set_code (TYPE_CODE_STRING);
   4496       if (is_vector)
   4497 	make_vector_type (type);
   4498       break;
   4499 
   4500     case 'S':			/* Set type */
   4501       {
   4502 	type1 = read_type (pp, objfile);
   4503 	type_allocator alloc (objfile, get_current_subfile ()->language);
   4504 	type = create_set_type (alloc, type1);
   4505 	if (typenums[0] != -1)
   4506 	  *dbx_lookup_type (typenums, objfile) = type;
   4507       }
   4508       break;
   4509 
   4510     default:
   4511       --*pp;			/* Go back to the symbol in error.  */
   4512       /* Particularly important if it was \0!  */
   4513       return error_type (pp, objfile);
   4514     }
   4515 
   4516   if (type == 0)
   4517     {
   4518       warning (_("GDB internal error, type is NULL in stabsread.c."));
   4519       return error_type (pp, objfile);
   4520     }
   4521 
   4522   /* Size specified in a type attribute overrides any other size.  */
   4523   if (type_size != -1)
   4524     type->set_length ((type_size + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT);
   4525 
   4526   return type;
   4527 }
   4528 
   4529 /* RS/6000 xlc/dbx combination uses a set of builtin types, starting from -1.
   4531    Return the proper type node for a given builtin type number.  */
   4532 
   4533 static const registry<objfile>::key<struct type *,
   4534 				    gdb::noop_deleter<struct type *>>
   4535   rs6000_builtin_type_data;
   4536 
   4537 static struct type *
   4538 rs6000_builtin_type (int typenum, struct objfile *objfile)
   4539 {
   4540   struct type **negative_types = rs6000_builtin_type_data.get (objfile);
   4541 
   4542   /* We recognize types numbered from -NUMBER_RECOGNIZED to -1.  */
   4543 #define NUMBER_RECOGNIZED 34
   4544   struct type *rettype = NULL;
   4545 
   4546   if (typenum >= 0 || typenum < -NUMBER_RECOGNIZED)
   4547     {
   4548       complaint (_("Unknown builtin type %d"), typenum);
   4549       return builtin_type (objfile)->builtin_error;
   4550     }
   4551 
   4552   if (!negative_types)
   4553     {
   4554       /* This includes an empty slot for type number -0.  */
   4555       negative_types = OBSTACK_CALLOC (&objfile->objfile_obstack,
   4556 				       NUMBER_RECOGNIZED + 1, struct type *);
   4557       rs6000_builtin_type_data.set (objfile, negative_types);
   4558     }
   4559 
   4560   if (negative_types[-typenum] != NULL)
   4561     return negative_types[-typenum];
   4562 
   4563 #if TARGET_CHAR_BIT != 8
   4564 #error This code wrong for TARGET_CHAR_BIT not 8
   4565   /* These definitions all assume that TARGET_CHAR_BIT is 8.  I think
   4566      that if that ever becomes not true, the correct fix will be to
   4567      make the size in the struct type to be in bits, not in units of
   4568      TARGET_CHAR_BIT.  */
   4569 #endif
   4570 
   4571   type_allocator alloc (objfile, get_current_subfile ()->language);
   4572   switch (-typenum)
   4573     {
   4574     case 1:
   4575       /* The size of this and all the other types are fixed, defined
   4576 	 by the debugging format.  If there is a type called "int" which
   4577 	 is other than 32 bits, then it should use a new negative type
   4578 	 number (or avoid negative type numbers for that case).
   4579 	 See stabs.texinfo.  */
   4580       rettype = init_integer_type (alloc, 32, 0, "int");
   4581       break;
   4582     case 2:
   4583       rettype = init_integer_type (alloc, 8, 0, "char");
   4584       rettype->set_has_no_signedness (true);
   4585       break;
   4586     case 3:
   4587       rettype = init_integer_type (alloc, 16, 0, "short");
   4588       break;
   4589     case 4:
   4590       rettype = init_integer_type (alloc, 32, 0, "long");
   4591       break;
   4592     case 5:
   4593       rettype = init_integer_type (alloc, 8, 1, "unsigned char");
   4594       break;
   4595     case 6:
   4596       rettype = init_integer_type (alloc, 8, 0, "signed char");
   4597       break;
   4598     case 7:
   4599       rettype = init_integer_type (alloc, 16, 1, "unsigned short");
   4600       break;
   4601     case 8:
   4602       rettype = init_integer_type (alloc, 32, 1, "unsigned int");
   4603       break;
   4604     case 9:
   4605       rettype = init_integer_type (alloc, 32, 1, "unsigned");
   4606       break;
   4607     case 10:
   4608       rettype = init_integer_type (alloc, 32, 1, "unsigned long");
   4609       break;
   4610     case 11:
   4611       rettype = alloc.new_type (TYPE_CODE_VOID, TARGET_CHAR_BIT, "void");
   4612       break;
   4613     case 12:
   4614       /* IEEE single precision (32 bit).  */
   4615       rettype = init_float_type (alloc, 32, "float",
   4616 				 floatformats_ieee_single);
   4617       break;
   4618     case 13:
   4619       /* IEEE double precision (64 bit).  */
   4620       rettype = init_float_type (alloc, 64, "double",
   4621 				 floatformats_ieee_double);
   4622       break;
   4623     case 14:
   4624       /* This is an IEEE double on the RS/6000, and different machines with
   4625 	 different sizes for "long double" should use different negative
   4626 	 type numbers.  See stabs.texinfo.  */
   4627       rettype = init_float_type (alloc, 64, "long double",
   4628 				 floatformats_ieee_double);
   4629       break;
   4630     case 15:
   4631       rettype = init_integer_type (alloc, 32, 0, "integer");
   4632       break;
   4633     case 16:
   4634       rettype = init_boolean_type (alloc, 32, 1, "boolean");
   4635       break;
   4636     case 17:
   4637       rettype = init_float_type (alloc, 32, "short real",
   4638 				 floatformats_ieee_single);
   4639       break;
   4640     case 18:
   4641       rettype = init_float_type (alloc, 64, "real",
   4642 				 floatformats_ieee_double);
   4643       break;
   4644     case 19:
   4645       rettype = alloc.new_type (TYPE_CODE_ERROR, 0, "stringptr");
   4646       break;
   4647     case 20:
   4648       rettype = init_character_type (alloc, 8, 1, "character");
   4649       break;
   4650     case 21:
   4651       rettype = init_boolean_type (alloc, 8, 1, "logical*1");
   4652       break;
   4653     case 22:
   4654       rettype = init_boolean_type (alloc, 16, 1, "logical*2");
   4655       break;
   4656     case 23:
   4657       rettype = init_boolean_type (alloc, 32, 1, "logical*4");
   4658       break;
   4659     case 24:
   4660       rettype = init_boolean_type (alloc, 32, 1, "logical");
   4661       break;
   4662     case 25:
   4663       /* Complex type consisting of two IEEE single precision values.  */
   4664       rettype = init_complex_type ("complex",
   4665 				   rs6000_builtin_type (12, objfile));
   4666       break;
   4667     case 26:
   4668       /* Complex type consisting of two IEEE double precision values.  */
   4669       rettype = init_complex_type ("double complex",
   4670 				   rs6000_builtin_type (13, objfile));
   4671       break;
   4672     case 27:
   4673       rettype = init_integer_type (alloc, 8, 0, "integer*1");
   4674       break;
   4675     case 28:
   4676       rettype = init_integer_type (alloc, 16, 0, "integer*2");
   4677       break;
   4678     case 29:
   4679       rettype = init_integer_type (alloc, 32, 0, "integer*4");
   4680       break;
   4681     case 30:
   4682       rettype = init_character_type (alloc, 16, 0, "wchar");
   4683       break;
   4684     case 31:
   4685       rettype = init_integer_type (alloc, 64, 0, "long long");
   4686       break;
   4687     case 32:
   4688       rettype = init_integer_type (alloc, 64, 1, "unsigned long long");
   4689       break;
   4690     case 33:
   4691       rettype = init_integer_type (alloc, 64, 1, "logical*8");
   4692       break;
   4693     case 34:
   4694       rettype = init_integer_type (alloc, 64, 0, "integer*8");
   4695       break;
   4696     }
   4697   negative_types[-typenum] = rettype;
   4698   return rettype;
   4699 }
   4700 
   4701 /* This page contains subroutines of read_type.  */
   4703 
   4704 /* Wrapper around method_name_from_physname to flag a complaint
   4705    if there is an error.  */
   4706 
   4707 static char *
   4708 stabs_method_name_from_physname (const char *physname)
   4709 {
   4710   char *method_name;
   4711 
   4712   method_name = method_name_from_physname (physname);
   4713 
   4714   if (method_name == NULL)
   4715     {
   4716       complaint (_("Method has bad physname %s\n"), physname);
   4717       return NULL;
   4718     }
   4719 
   4720   return method_name;
   4721 }
   4722 
   4723 /* Read member function stabs info for C++ classes.  The form of each member
   4724    function data is:
   4725 
   4726    NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
   4727 
   4728    An example with two member functions is:
   4729 
   4730    afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
   4731 
   4732    For the case of overloaded operators, the format is op$::*.funcs, where
   4733    $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
   4734    name (such as `+=') and `.' marks the end of the operator name.
   4735 
   4736    Returns 1 for success, 0 for failure.  */
   4737 
   4738 static int
   4739 read_member_functions (struct stab_field_info *fip, const char **pp,
   4740 		       struct type *type, struct objfile *objfile)
   4741 {
   4742   int nfn_fields = 0;
   4743   int length = 0;
   4744   int i;
   4745   struct next_fnfield
   4746     {
   4747       struct next_fnfield *next;
   4748       struct fn_field fn_field;
   4749     }
   4750    *sublist;
   4751   struct type *look_ahead_type;
   4752   struct next_fnfieldlist *new_fnlist;
   4753   struct next_fnfield *new_sublist;
   4754   char *main_fn_name;
   4755   const char *p;
   4756 
   4757   /* Process each list until we find something that is not a member function
   4758      or find the end of the functions.  */
   4759 
   4760   while (**pp != ';')
   4761     {
   4762       /* We should be positioned at the start of the function name.
   4763 	 Scan forward to find the first ':' and if it is not the
   4764 	 first of a "::" delimiter, then this is not a member function.  */
   4765       p = *pp;
   4766       while (*p != ':')
   4767 	{
   4768 	  p++;
   4769 	}
   4770       if (p[1] != ':')
   4771 	{
   4772 	  break;
   4773 	}
   4774 
   4775       sublist = NULL;
   4776       look_ahead_type = NULL;
   4777       length = 0;
   4778 
   4779       new_fnlist = OBSTACK_ZALLOC (&fip->obstack, struct next_fnfieldlist);
   4780 
   4781       if ((*pp)[0] == 'o' && (*pp)[1] == 'p' && is_cplus_marker ((*pp)[2]))
   4782 	{
   4783 	  /* This is a completely weird case.  In order to stuff in the
   4784 	     names that might contain colons (the usual name delimiter),
   4785 	     Mike Tiemann defined a different name format which is
   4786 	     signalled if the identifier is "op$".  In that case, the
   4787 	     format is "op$::XXXX." where XXXX is the name.  This is
   4788 	     used for names like "+" or "=".  YUUUUUUUK!  FIXME!  */
   4789 	  /* This lets the user type "break operator+".
   4790 	     We could just put in "+" as the name, but that wouldn't
   4791 	     work for "*".  */
   4792 	  static char opname[32] = "op$";
   4793 	  char *o = opname + 3;
   4794 
   4795 	  /* Skip past '::'.  */
   4796 	  *pp = p + 2;
   4797 
   4798 	  STABS_CONTINUE (pp, objfile);
   4799 	  p = *pp;
   4800 	  while (*p != '.')
   4801 	    {
   4802 	      *o++ = *p++;
   4803 	    }
   4804 	  main_fn_name = savestring (opname, o - opname);
   4805 	  /* Skip past '.'  */
   4806 	  *pp = p + 1;
   4807 	}
   4808       else
   4809 	{
   4810 	  main_fn_name = savestring (*pp, p - *pp);
   4811 	  /* Skip past '::'.  */
   4812 	  *pp = p + 2;
   4813 	}
   4814       new_fnlist->fn_fieldlist.name = main_fn_name;
   4815 
   4816       do
   4817 	{
   4818 	  new_sublist = OBSTACK_ZALLOC (&fip->obstack, struct next_fnfield);
   4819 
   4820 	  /* Check for and handle cretinous dbx symbol name continuation!  */
   4821 	  if (look_ahead_type == NULL)
   4822 	    {
   4823 	      /* Normal case.  */
   4824 	      STABS_CONTINUE (pp, objfile);
   4825 
   4826 	      new_sublist->fn_field.type = read_type (pp, objfile);
   4827 	      if (**pp != ':')
   4828 		{
   4829 		  /* Invalid symtab info for member function.  */
   4830 		  return 0;
   4831 		}
   4832 	    }
   4833 	  else
   4834 	    {
   4835 	      /* g++ version 1 kludge */
   4836 	      new_sublist->fn_field.type = look_ahead_type;
   4837 	      look_ahead_type = NULL;
   4838 	    }
   4839 
   4840 	  (*pp)++;
   4841 	  p = *pp;
   4842 	  while (*p != ';')
   4843 	    {
   4844 	      p++;
   4845 	    }
   4846 
   4847 	  /* These are methods, not functions.  */
   4848 	  if (new_sublist->fn_field.type->code () == TYPE_CODE_FUNC)
   4849 	    new_sublist->fn_field.type->set_code (TYPE_CODE_METHOD);
   4850 
   4851 	  /* If this is just a stub, then we don't have the real name here.  */
   4852 	  if (new_sublist->fn_field.type->is_stub ())
   4853 	    {
   4854 	      if (!TYPE_SELF_TYPE (new_sublist->fn_field.type))
   4855 		set_type_self_type (new_sublist->fn_field.type, type);
   4856 	      new_sublist->fn_field.is_stub = 1;
   4857 	    }
   4858 
   4859 	  new_sublist->fn_field.physname = savestring (*pp, p - *pp);
   4860 	  *pp = p + 1;
   4861 
   4862 	  /* Set this member function's visibility fields.  */
   4863 	  switch (*(*pp)++)
   4864 	    {
   4865 	    case VISIBILITY_PRIVATE:
   4866 	      new_sublist->fn_field.accessibility = accessibility::PRIVATE;
   4867 	      break;
   4868 	    case VISIBILITY_PROTECTED:
   4869 	      new_sublist->fn_field.accessibility = accessibility::PROTECTED;
   4870 	      break;
   4871 	    }
   4872 
   4873 	  STABS_CONTINUE (pp, objfile);
   4874 	  switch (**pp)
   4875 	    {
   4876 	    case 'A':		/* Normal functions.  */
   4877 	      new_sublist->fn_field.is_const = 0;
   4878 	      new_sublist->fn_field.is_volatile = 0;
   4879 	      (*pp)++;
   4880 	      break;
   4881 	    case 'B':		/* `const' member functions.  */
   4882 	      new_sublist->fn_field.is_const = 1;
   4883 	      new_sublist->fn_field.is_volatile = 0;
   4884 	      (*pp)++;
   4885 	      break;
   4886 	    case 'C':		/* `volatile' member function.  */
   4887 	      new_sublist->fn_field.is_const = 0;
   4888 	      new_sublist->fn_field.is_volatile = 1;
   4889 	      (*pp)++;
   4890 	      break;
   4891 	    case 'D':		/* `const volatile' member function.  */
   4892 	      new_sublist->fn_field.is_const = 1;
   4893 	      new_sublist->fn_field.is_volatile = 1;
   4894 	      (*pp)++;
   4895 	      break;
   4896 	    case '*':		/* File compiled with g++ version 1 --
   4897 				   no info.  */
   4898 	    case '?':
   4899 	    case '.':
   4900 	      break;
   4901 	    default:
   4902 	      complaint (_("const/volatile indicator missing, got '%c'"),
   4903 			 **pp);
   4904 	      break;
   4905 	    }
   4906 
   4907 	  switch (*(*pp)++)
   4908 	    {
   4909 	    case '*':
   4910 	      {
   4911 		int nbits;
   4912 		/* virtual member function, followed by index.
   4913 		   The sign bit is set to distinguish pointers-to-methods
   4914 		   from virtual function indicies.  Since the array is
   4915 		   in words, the quantity must be shifted left by 1
   4916 		   on 16 bit machine, and by 2 on 32 bit machine, forcing
   4917 		   the sign bit out, and usable as a valid index into
   4918 		   the array.  Remove the sign bit here.  */
   4919 		new_sublist->fn_field.voffset =
   4920 		  (0x7fffffff & read_huge_number (pp, ';', &nbits, 0)) + 2;
   4921 		if (nbits != 0)
   4922 		  return 0;
   4923 
   4924 		STABS_CONTINUE (pp, objfile);
   4925 		if (**pp == ';' || **pp == '\0')
   4926 		  {
   4927 		    /* Must be g++ version 1.  */
   4928 		    new_sublist->fn_field.fcontext = 0;
   4929 		  }
   4930 		else
   4931 		  {
   4932 		    /* Figure out from whence this virtual function came.
   4933 		       It may belong to virtual function table of
   4934 		       one of its baseclasses.  */
   4935 		    look_ahead_type = read_type (pp, objfile);
   4936 		    if (**pp == ':')
   4937 		      {
   4938 			/* g++ version 1 overloaded methods.  */
   4939 		      }
   4940 		    else
   4941 		      {
   4942 			new_sublist->fn_field.fcontext = look_ahead_type;
   4943 			if (**pp != ';')
   4944 			  {
   4945 			    return 0;
   4946 			  }
   4947 			else
   4948 			  {
   4949 			    ++*pp;
   4950 			  }
   4951 			look_ahead_type = NULL;
   4952 		      }
   4953 		  }
   4954 		break;
   4955 	      }
   4956 	    case '?':
   4957 	      /* static member function.  */
   4958 	      {
   4959 		int slen = strlen (main_fn_name);
   4960 
   4961 		new_sublist->fn_field.voffset = VOFFSET_STATIC;
   4962 
   4963 		/* For static member functions, we can't tell if they
   4964 		   are stubbed, as they are put out as functions, and not as
   4965 		   methods.
   4966 		   GCC v2 emits the fully mangled name if
   4967 		   dbxout.c:flag_minimal_debug is not set, so we have to
   4968 		   detect a fully mangled physname here and set is_stub
   4969 		   accordingly.  Fully mangled physnames in v2 start with
   4970 		   the member function name, followed by two underscores.
   4971 		   GCC v3 currently always emits stubbed member functions,
   4972 		   but with fully mangled physnames, which start with _Z.  */
   4973 		if (!(strncmp (new_sublist->fn_field.physname,
   4974 			       main_fn_name, slen) == 0
   4975 		      && new_sublist->fn_field.physname[slen] == '_'
   4976 		      && new_sublist->fn_field.physname[slen + 1] == '_'))
   4977 		  {
   4978 		    new_sublist->fn_field.is_stub = 1;
   4979 		  }
   4980 		break;
   4981 	      }
   4982 
   4983 	    default:
   4984 	      /* error */
   4985 	      complaint (_("member function type missing, got '%c'"),
   4986 			 (*pp)[-1]);
   4987 	      /* Normal member function.  */
   4988 	      [[fallthrough]];
   4989 
   4990 	    case '.':
   4991 	      /* normal member function.  */
   4992 	      new_sublist->fn_field.voffset = 0;
   4993 	      new_sublist->fn_field.fcontext = 0;
   4994 	      break;
   4995 	    }
   4996 
   4997 	  new_sublist->next = sublist;
   4998 	  sublist = new_sublist;
   4999 	  length++;
   5000 	  STABS_CONTINUE (pp, objfile);
   5001 	}
   5002       while (**pp != ';' && **pp != '\0');
   5003 
   5004       (*pp)++;
   5005       STABS_CONTINUE (pp, objfile);
   5006 
   5007       /* Skip GCC 3.X member functions which are duplicates of the callable
   5008 	 constructor/destructor.  */
   5009       if (strcmp_iw (main_fn_name, "__base_ctor ") == 0
   5010 	  || strcmp_iw (main_fn_name, "__base_dtor ") == 0
   5011 	  || strcmp (main_fn_name, "__deleting_dtor") == 0)
   5012 	{
   5013 	  xfree (main_fn_name);
   5014 	}
   5015       else
   5016 	{
   5017 	  int has_destructor = 0, has_other = 0;
   5018 	  int is_v3 = 0;
   5019 	  struct next_fnfield *tmp_sublist;
   5020 
   5021 	  /* Various versions of GCC emit various mostly-useless
   5022 	     strings in the name field for special member functions.
   5023 
   5024 	     For stub methods, we need to defer correcting the name
   5025 	     until we are ready to unstub the method, because the current
   5026 	     name string is used by gdb_mangle_name.  The only stub methods
   5027 	     of concern here are GNU v2 operators; other methods have their
   5028 	     names correct (see caveat below).
   5029 
   5030 	     For non-stub methods, in GNU v3, we have a complete physname.
   5031 	     Therefore we can safely correct the name now.  This primarily
   5032 	     affects constructors and destructors, whose name will be
   5033 	     __comp_ctor or __comp_dtor instead of Foo or ~Foo.  Cast
   5034 	     operators will also have incorrect names; for instance,
   5035 	     "operator int" will be named "operator i" (i.e. the type is
   5036 	     mangled).
   5037 
   5038 	     For non-stub methods in GNU v2, we have no easy way to
   5039 	     know if we have a complete physname or not.  For most
   5040 	     methods the result depends on the platform (if CPLUS_MARKER
   5041 	     can be `$' or `.', it will use minimal debug information, or
   5042 	     otherwise the full physname will be included).
   5043 
   5044 	     Rather than dealing with this, we take a different approach.
   5045 	     For v3 mangled names, we can use the full physname; for v2,
   5046 	     we use cplus_demangle_opname (which is actually v2 specific),
   5047 	     because the only interesting names are all operators - once again
   5048 	     barring the caveat below.  Skip this process if any method in the
   5049 	     group is a stub, to prevent our fouling up the workings of
   5050 	     gdb_mangle_name.
   5051 
   5052 	     The caveat: GCC 2.95.x (and earlier?) put constructors and
   5053 	     destructors in the same method group.  We need to split this
   5054 	     into two groups, because they should have different names.
   5055 	     So for each method group we check whether it contains both
   5056 	     routines whose physname appears to be a destructor (the physnames
   5057 	     for and destructors are always provided, due to quirks in v2
   5058 	     mangling) and routines whose physname does not appear to be a
   5059 	     destructor.  If so then we break up the list into two halves.
   5060 	     Even if the constructors and destructors aren't in the same group
   5061 	     the destructor will still lack the leading tilde, so that also
   5062 	     needs to be fixed.
   5063 
   5064 	     So, to summarize what we expect and handle here:
   5065 
   5066 		Given         Given          Real         Real       Action
   5067 	     method name     physname      physname   method name
   5068 
   5069 	     __opi            [none]     __opi__3Foo  operator int    opname
   5070 								 [now or later]
   5071 	     Foo              _._3Foo       _._3Foo      ~Foo      separate and
   5072 								       rename
   5073 	     operator i     _ZN3FoocviEv _ZN3FoocviEv operator int    demangle
   5074 	     __comp_ctor  _ZN3FooC1ERKS_ _ZN3FooC1ERKS_   Foo         demangle
   5075 	  */
   5076 
   5077 	  tmp_sublist = sublist;
   5078 	  while (tmp_sublist != NULL)
   5079 	    {
   5080 	      if (tmp_sublist->fn_field.physname[0] == '_'
   5081 		  && tmp_sublist->fn_field.physname[1] == 'Z')
   5082 		is_v3 = 1;
   5083 
   5084 	      if (is_destructor_name (tmp_sublist->fn_field.physname))
   5085 		has_destructor++;
   5086 	      else
   5087 		has_other++;
   5088 
   5089 	      tmp_sublist = tmp_sublist->next;
   5090 	    }
   5091 
   5092 	  if (has_destructor && has_other)
   5093 	    {
   5094 	      struct next_fnfieldlist *destr_fnlist;
   5095 	      struct next_fnfield *last_sublist;
   5096 
   5097 	      /* Create a new fn_fieldlist for the destructors.  */
   5098 
   5099 	      destr_fnlist = OBSTACK_ZALLOC (&fip->obstack,
   5100 					     struct next_fnfieldlist);
   5101 
   5102 	      destr_fnlist->fn_fieldlist.name
   5103 		= obconcat (&objfile->objfile_obstack, "~",
   5104 			    new_fnlist->fn_fieldlist.name, (char *) NULL);
   5105 
   5106 	      destr_fnlist->fn_fieldlist.fn_fields =
   5107 		XOBNEWVEC (&objfile->objfile_obstack,
   5108 			   struct fn_field, has_destructor);
   5109 	      memset (destr_fnlist->fn_fieldlist.fn_fields, 0,
   5110 		  sizeof (struct fn_field) * has_destructor);
   5111 	      tmp_sublist = sublist;
   5112 	      last_sublist = NULL;
   5113 	      i = 0;
   5114 	      while (tmp_sublist != NULL)
   5115 		{
   5116 		  if (!is_destructor_name (tmp_sublist->fn_field.physname))
   5117 		    {
   5118 		      tmp_sublist = tmp_sublist->next;
   5119 		      continue;
   5120 		    }
   5121 
   5122 		  destr_fnlist->fn_fieldlist.fn_fields[i++]
   5123 		    = tmp_sublist->fn_field;
   5124 		  if (last_sublist)
   5125 		    last_sublist->next = tmp_sublist->next;
   5126 		  else
   5127 		    sublist = tmp_sublist->next;
   5128 		  last_sublist = tmp_sublist;
   5129 		  tmp_sublist = tmp_sublist->next;
   5130 		}
   5131 
   5132 	      destr_fnlist->fn_fieldlist.length = has_destructor;
   5133 	      destr_fnlist->next = fip->fnlist;
   5134 	      fip->fnlist = destr_fnlist;
   5135 	      nfn_fields++;
   5136 	      length -= has_destructor;
   5137 	    }
   5138 	  else if (is_v3)
   5139 	    {
   5140 	      /* v3 mangling prevents the use of abbreviated physnames,
   5141 		 so we can do this here.  There are stubbed methods in v3
   5142 		 only:
   5143 		 - in -gstabs instead of -gstabs+
   5144 		 - or for static methods, which are output as a function type
   5145 		   instead of a method type.  */
   5146 	      char *new_method_name =
   5147 		stabs_method_name_from_physname (sublist->fn_field.physname);
   5148 
   5149 	      if (new_method_name != NULL
   5150 		  && strcmp (new_method_name,
   5151 			     new_fnlist->fn_fieldlist.name) != 0)
   5152 		{
   5153 		  new_fnlist->fn_fieldlist.name = new_method_name;
   5154 		  xfree (main_fn_name);
   5155 		}
   5156 	      else
   5157 		xfree (new_method_name);
   5158 	    }
   5159 	  else if (has_destructor && new_fnlist->fn_fieldlist.name[0] != '~')
   5160 	    {
   5161 	      new_fnlist->fn_fieldlist.name =
   5162 		obconcat (&objfile->objfile_obstack,
   5163 			  "~", main_fn_name, (char *)NULL);
   5164 	      xfree (main_fn_name);
   5165 	    }
   5166 
   5167 	  new_fnlist->fn_fieldlist.fn_fields
   5168 	    = OBSTACK_CALLOC (&objfile->objfile_obstack, length, fn_field);
   5169 	  for (i = length; (i--, sublist); sublist = sublist->next)
   5170 	    {
   5171 	      new_fnlist->fn_fieldlist.fn_fields[i] = sublist->fn_field;
   5172 	    }
   5173 
   5174 	  new_fnlist->fn_fieldlist.length = length;
   5175 	  new_fnlist->next = fip->fnlist;
   5176 	  fip->fnlist = new_fnlist;
   5177 	  nfn_fields++;
   5178 	}
   5179     }
   5180 
   5181   if (nfn_fields)
   5182     {
   5183       ALLOCATE_CPLUS_STRUCT_TYPE (type);
   5184       TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
   5185 	TYPE_ZALLOC (type, sizeof (struct fn_fieldlist) * nfn_fields);
   5186       TYPE_NFN_FIELDS (type) = nfn_fields;
   5187     }
   5188 
   5189   return 1;
   5190 }
   5191 
   5192 /* Special GNU C++ name.
   5193 
   5194    Returns 1 for success, 0 for failure.  "failure" means that we can't
   5195    keep parsing and it's time for error_type().  */
   5196 
   5197 static int
   5198 read_cpp_abbrev (struct stab_field_info *fip, const char **pp,
   5199 		 struct type *type, struct objfile *objfile)
   5200 {
   5201   const char *p;
   5202   const char *name;
   5203   char cpp_abbrev;
   5204   struct type *context;
   5205 
   5206   p = *pp;
   5207   if (*++p == 'v')
   5208     {
   5209       name = NULL;
   5210       cpp_abbrev = *++p;
   5211 
   5212       *pp = p + 1;
   5213 
   5214       /* At this point, *pp points to something like "22:23=*22...",
   5215 	 where the type number before the ':' is the "context" and
   5216 	 everything after is a regular type definition.  Lookup the
   5217 	 type, find it's name, and construct the field name.  */
   5218 
   5219       context = read_type (pp, objfile);
   5220 
   5221       switch (cpp_abbrev)
   5222 	{
   5223 	case 'f':		/* $vf -- a virtual function table pointer */
   5224 	  name = context->name ();
   5225 	  if (name == NULL)
   5226 	    {
   5227 	      name = "";
   5228 	    }
   5229 	  fip->list->field.set_name (obconcat (&objfile->objfile_obstack,
   5230 					       vptr_name, name, (char *) NULL));
   5231 	  break;
   5232 
   5233 	case 'b':		/* $vb -- a virtual bsomethingorother */
   5234 	  name = context->name ();
   5235 	  if (name == NULL)
   5236 	    {
   5237 	      complaint (_("C++ abbreviated type name "
   5238 			   "unknown at symtab pos %d"),
   5239 			 symnum);
   5240 	      name = "FOO";
   5241 	    }
   5242 	  fip->list->field.set_name (obconcat (&objfile->objfile_obstack,
   5243 					       vb_name, name, (char *) NULL));
   5244 	  break;
   5245 
   5246 	default:
   5247 	  invalid_cpp_abbrev_complaint (*pp);
   5248 	  fip->list->field.set_name (obconcat (&objfile->objfile_obstack,
   5249 					       "INVALID_CPLUSPLUS_ABBREV",
   5250 					       (char *) NULL));
   5251 	  break;
   5252 	}
   5253 
   5254       /* At this point, *pp points to the ':'.  Skip it and read the
   5255 	 field type.  */
   5256 
   5257       p = ++(*pp);
   5258       if (p[-1] != ':')
   5259 	{
   5260 	  invalid_cpp_abbrev_complaint (*pp);
   5261 	  return 0;
   5262 	}
   5263       fip->list->field.set_type (read_type (pp, objfile));
   5264       if (**pp == ',')
   5265 	(*pp)++;		/* Skip the comma.  */
   5266       else
   5267 	return 0;
   5268 
   5269       {
   5270 	int nbits;
   5271 
   5272 	fip->list->field.set_loc_bitpos (read_huge_number (pp, ';', &nbits, 0));
   5273 	if (nbits != 0)
   5274 	  return 0;
   5275       }
   5276       /* This field is unpacked.  */
   5277       fip->list->field.set_bitsize (0);
   5278       fip->list->field.set_accessibility (accessibility::PRIVATE);
   5279     }
   5280   else
   5281     {
   5282       invalid_cpp_abbrev_complaint (*pp);
   5283       /* We have no idea what syntax an unrecognized abbrev would have, so
   5284 	 better return 0.  If we returned 1, we would need to at least advance
   5285 	 *pp to avoid an infinite loop.  */
   5286       return 0;
   5287     }
   5288   return 1;
   5289 }
   5290 
   5291 static void
   5292 read_one_struct_field (struct stab_field_info *fip, const char **pp,
   5293 		       const char *p, struct type *type,
   5294 		       struct objfile *objfile)
   5295 {
   5296   struct gdbarch *gdbarch = objfile->arch ();
   5297 
   5298   fip->list->field.set_name
   5299     (obstack_strndup (&objfile->objfile_obstack, *pp, p - *pp));
   5300   *pp = p + 1;
   5301 
   5302   /* This means we have a visibility for a field coming.  */
   5303   int visibility;
   5304   if (**pp == '/')
   5305     {
   5306       (*pp)++;
   5307       visibility = *(*pp)++;
   5308     }
   5309   else
   5310     {
   5311       /* normal dbx-style format, no explicit visibility */
   5312       visibility = VISIBILITY_PUBLIC;
   5313     }
   5314 
   5315   switch (visibility)
   5316     {
   5317     case VISIBILITY_PRIVATE:
   5318       fip->list->field.set_accessibility (accessibility::PRIVATE);
   5319       break;
   5320 
   5321     case VISIBILITY_PROTECTED:
   5322       fip->list->field.set_accessibility (accessibility::PROTECTED);
   5323       break;
   5324 
   5325     case VISIBILITY_IGNORE:
   5326       fip->list->field.set_ignored ();
   5327       break;
   5328 
   5329     case VISIBILITY_PUBLIC:
   5330       break;
   5331 
   5332     default:
   5333       /* Unknown visibility.  Complain and treat it as public.  */
   5334       {
   5335 	complaint (_("Unknown visibility `%c' for field"),
   5336 		   visibility);
   5337       }
   5338       break;
   5339     }
   5340 
   5341   fip->list->field.set_type (read_type (pp, objfile));
   5342   if (**pp == ':')
   5343     {
   5344       p = ++(*pp);
   5345 #if 0
   5346       /* Possible future hook for nested types.  */
   5347       if (**pp == '!')
   5348 	{
   5349 	  fip->list->field.bitpos = (long) -2;	/* nested type */
   5350 	  p = ++(*pp);
   5351 	}
   5352       else
   5353 	...;
   5354 #endif
   5355       while (*p != ';')
   5356 	{
   5357 	  p++;
   5358 	}
   5359       /* Static class member.  */
   5360       fip->list->field.set_loc_physname (savestring (*pp, p - *pp));
   5361       *pp = p + 1;
   5362       return;
   5363     }
   5364   else if (**pp != ',')
   5365     {
   5366       /* Bad structure-type format.  */
   5367       stabs_general_complaint ("bad structure-type format");
   5368       return;
   5369     }
   5370 
   5371   (*pp)++;			/* Skip the comma.  */
   5372 
   5373   {
   5374     int nbits;
   5375 
   5376     fip->list->field.set_loc_bitpos (read_huge_number (pp, ',', &nbits, 0));
   5377     if (nbits != 0)
   5378       {
   5379 	stabs_general_complaint ("bad structure-type format");
   5380 	return;
   5381       }
   5382     fip->list->field.set_bitsize (read_huge_number (pp, ';', &nbits, 0));
   5383     if (nbits != 0)
   5384       {
   5385 	stabs_general_complaint ("bad structure-type format");
   5386 	return;
   5387       }
   5388   }
   5389 
   5390   if (fip->list->field.loc_bitpos () == 0
   5391       && fip->list->field.bitsize () == 0)
   5392     {
   5393       /* This can happen in two cases: (1) at least for gcc 2.4.5 or so,
   5394 	 it is a field which has been optimized out.  The correct stab for
   5395 	 this case is to use VISIBILITY_IGNORE, but that is a recent
   5396 	 invention.  (2) It is a 0-size array.  For example
   5397 	 union { int num; char str[0]; } foo.  Printing _("<no value>" for
   5398 	 str in "p foo" is OK, since foo.str (and thus foo.str[3])
   5399 	 will continue to work, and a 0-size array as a whole doesn't
   5400 	 have any contents to print.
   5401 
   5402 	 I suspect this probably could also happen with gcc -gstabs (not
   5403 	 -gstabs+) for static fields, and perhaps other C++ extensions.
   5404 	 Hopefully few people use -gstabs with gdb, since it is intended
   5405 	 for dbx compatibility.  */
   5406 
   5407       /* Ignore this field.  */
   5408       fip->list->field.set_ignored ();
   5409     }
   5410   else
   5411     {
   5412       /* Detect an unpacked field and mark it as such.
   5413 	 dbx gives a bit size for all fields.
   5414 	 Note that forward refs cannot be packed,
   5415 	 and treat enums as if they had the width of ints.  */
   5416 
   5417       struct type *field_type = check_typedef (fip->list->field.type ());
   5418 
   5419       if (field_type->code () != TYPE_CODE_INT
   5420 	  && field_type->code () != TYPE_CODE_RANGE
   5421 	  && field_type->code () != TYPE_CODE_BOOL
   5422 	  && field_type->code () != TYPE_CODE_ENUM)
   5423 	{
   5424 	  fip->list->field.set_bitsize (0);
   5425 	}
   5426       if ((fip->list->field.bitsize ()
   5427 	   == TARGET_CHAR_BIT * field_type->length ()
   5428 	   || (field_type->code () == TYPE_CODE_ENUM
   5429 	       && (fip->list->field.bitsize ()
   5430 		   == gdbarch_int_bit (gdbarch)))
   5431 	  )
   5432 	  &&
   5433 	  fip->list->field.loc_bitpos () % 8 == 0)
   5434 	{
   5435 	  fip->list->field.set_bitsize (0);
   5436 	}
   5437     }
   5438 }
   5439 
   5440 
   5441 /* Read struct or class data fields.  They have the form:
   5442 
   5443    NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
   5444 
   5445    At the end, we see a semicolon instead of a field.
   5446 
   5447    In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
   5448    a static field.
   5449 
   5450    The optional VISIBILITY is one of:
   5451 
   5452    '/0' (VISIBILITY_PRIVATE)
   5453    '/1' (VISIBILITY_PROTECTED)
   5454    '/2' (VISIBILITY_PUBLIC)
   5455    '/9' (VISIBILITY_IGNORE)
   5456 
   5457    or nothing, for C style fields with public visibility.
   5458 
   5459    Returns 1 for success, 0 for failure.  */
   5460 
   5461 static int
   5462 read_struct_fields (struct stab_field_info *fip, const char **pp,
   5463 		    struct type *type, struct objfile *objfile)
   5464 {
   5465   const char *p;
   5466   struct stabs_nextfield *newobj;
   5467 
   5468   /* We better set p right now, in case there are no fields at all...    */
   5469 
   5470   p = *pp;
   5471 
   5472   /* Read each data member type until we find the terminating ';' at the end of
   5473      the data member list, or break for some other reason such as finding the
   5474      start of the member function list.  */
   5475   /* Stab string for structure/union does not end with two ';' in
   5476      SUN C compiler 5.3 i.e. F6U2, hence check for end of string.  */
   5477 
   5478   while (**pp != ';' && **pp != '\0')
   5479     {
   5480       STABS_CONTINUE (pp, objfile);
   5481       /* Get space to record the next field's data.  */
   5482       newobj = OBSTACK_ZALLOC (&fip->obstack, struct stabs_nextfield);
   5483 
   5484       newobj->next = fip->list;
   5485       fip->list = newobj;
   5486 
   5487       /* Get the field name.  */
   5488       p = *pp;
   5489 
   5490       /* If is starts with CPLUS_MARKER it is a special abbreviation,
   5491 	 unless the CPLUS_MARKER is followed by an underscore, in
   5492 	 which case it is just the name of an anonymous type, which we
   5493 	 should handle like any other type name.  */
   5494 
   5495       if (is_cplus_marker (p[0]) && p[1] != '_')
   5496 	{
   5497 	  if (!read_cpp_abbrev (fip, pp, type, objfile))
   5498 	    return 0;
   5499 	  continue;
   5500 	}
   5501 
   5502       /* Look for the ':' that separates the field name from the field
   5503 	 values.  Data members are delimited by a single ':', while member
   5504 	 functions are delimited by a pair of ':'s.  When we hit the member
   5505 	 functions (if any), terminate scan loop and return.  */
   5506 
   5507       while (*p != ':' && *p != '\0')
   5508 	{
   5509 	  p++;
   5510 	}
   5511       if (*p == '\0')
   5512 	return 0;
   5513 
   5514       /* Check to see if we have hit the member functions yet.  */
   5515       if (p[1] == ':')
   5516 	{
   5517 	  break;
   5518 	}
   5519       read_one_struct_field (fip, pp, p, type, objfile);
   5520     }
   5521   if (p[0] == ':' && p[1] == ':')
   5522     {
   5523       /* (the deleted) chill the list of fields: the last entry (at
   5524 	 the head) is a partially constructed entry which we now
   5525 	 scrub.  */
   5526       fip->list = fip->list->next;
   5527     }
   5528   return 1;
   5529 }
   5530 /* The stabs for C++ derived classes contain baseclass information which
   5531    is marked by a '!' character after the total size.  This function is
   5532    called when we encounter the baseclass marker, and slurps up all the
   5533    baseclass information.
   5534 
   5535    Immediately following the '!' marker is the number of base classes that
   5536    the class is derived from, followed by information for each base class.
   5537    For each base class, there are two visibility specifiers, a bit offset
   5538    to the base class information within the derived class, a reference to
   5539    the type for the base class, and a terminating semicolon.
   5540 
   5541    A typical example, with two base classes, would be "!2,020,19;0264,21;".
   5542 						       ^^ ^ ^ ^  ^ ^  ^
   5543 	Baseclass information marker __________________|| | | |  | |  |
   5544 	Number of baseclasses __________________________| | | |  | |  |
   5545 	Visibility specifiers (2) ________________________| | |  | |  |
   5546 	Offset in bits from start of class _________________| |  | |  |
   5547 	Type number for base class ___________________________|  | |  |
   5548 	Visibility specifiers (2) _______________________________| |  |
   5549 	Offset in bits from start of class ________________________|  |
   5550 	Type number of base class ____________________________________|
   5551 
   5552   Return 1 for success, 0 for (error-type-inducing) failure.  */
   5553 
   5554 
   5555 
   5556 static int
   5557 read_baseclasses (struct stab_field_info *fip, const char **pp,
   5558 		  struct type *type, struct objfile *objfile)
   5559 {
   5560   int i;
   5561   struct stabs_nextfield *newobj;
   5562 
   5563   if (**pp != '!')
   5564     {
   5565       return 1;
   5566     }
   5567   else
   5568     {
   5569       /* Skip the '!' baseclass information marker.  */
   5570       (*pp)++;
   5571     }
   5572 
   5573   ALLOCATE_CPLUS_STRUCT_TYPE (type);
   5574   {
   5575     int nbits;
   5576 
   5577     TYPE_N_BASECLASSES (type) = read_huge_number (pp, ',', &nbits, 0);
   5578     if (nbits != 0)
   5579       return 0;
   5580   }
   5581 
   5582   for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
   5583     {
   5584       newobj = OBSTACK_ZALLOC (&fip->obstack, struct stabs_nextfield);
   5585 
   5586       newobj->next = fip->list;
   5587       fip->list = newobj;
   5588       newobj->field.set_bitsize (0);	/* This should be an unpacked
   5589 					   field!  */
   5590 
   5591       STABS_CONTINUE (pp, objfile);
   5592       switch (**pp)
   5593 	{
   5594 	case '0':
   5595 	  /* Nothing to do.  */
   5596 	  break;
   5597 	case '1':
   5598 	  newobj->field.set_virtual ();
   5599 	  break;
   5600 	default:
   5601 	  /* Unknown character.  Complain and treat it as non-virtual.  */
   5602 	  {
   5603 	    complaint (_("Unknown virtual character `%c' for baseclass"),
   5604 		       **pp);
   5605 	  }
   5606 	}
   5607       ++(*pp);
   5608 
   5609       int visibility = *(*pp)++;
   5610       switch (visibility)
   5611 	{
   5612 	case VISIBILITY_PRIVATE:
   5613 	  newobj->field.set_accessibility (accessibility::PRIVATE);
   5614 	  break;
   5615 	case VISIBILITY_PROTECTED:
   5616 	  newobj->field.set_accessibility (accessibility::PROTECTED);
   5617 	  break;
   5618 	case VISIBILITY_PUBLIC:
   5619 	  break;
   5620 	default:
   5621 	  /* Bad visibility format.  Complain and treat it as
   5622 	     public.  */
   5623 	  {
   5624 	    complaint (_("Unknown visibility `%c' for baseclass"),
   5625 		       visibility);
   5626 	  }
   5627 	}
   5628 
   5629       {
   5630 	int nbits;
   5631 
   5632 	/* The remaining value is the bit offset of the portion of the object
   5633 	   corresponding to this baseclass.  Always zero in the absence of
   5634 	   multiple inheritance.  */
   5635 
   5636 	newobj->field.set_loc_bitpos (read_huge_number (pp, ',', &nbits, 0));
   5637 	if (nbits != 0)
   5638 	  return 0;
   5639       }
   5640 
   5641       /* The last piece of baseclass information is the type of the
   5642 	 base class.  Read it, and remember it's type name as this
   5643 	 field's name.  */
   5644 
   5645       newobj->field.set_type (read_type (pp, objfile));
   5646       newobj->field.set_name (newobj->field.type ()->name ());
   5647 
   5648       /* Skip trailing ';' and bump count of number of fields seen.  */
   5649       if (**pp == ';')
   5650 	(*pp)++;
   5651       else
   5652 	return 0;
   5653     }
   5654   return 1;
   5655 }
   5656 
   5657 /* The tail end of stabs for C++ classes that contain a virtual function
   5658    pointer contains a tilde, a %, and a type number.
   5659    The type number refers to the base class (possibly this class itself) which
   5660    contains the vtable pointer for the current class.
   5661 
   5662    This function is called when we have parsed all the method declarations,
   5663    so we can look for the vptr base class info.  */
   5664 
   5665 static int
   5666 read_tilde_fields (struct stab_field_info *fip, const char **pp,
   5667 		   struct type *type, struct objfile *objfile)
   5668 {
   5669   const char *p;
   5670 
   5671   STABS_CONTINUE (pp, objfile);
   5672 
   5673   /* If we are positioned at a ';', then skip it.  */
   5674   if (**pp == ';')
   5675     {
   5676       (*pp)++;
   5677     }
   5678 
   5679   if (**pp == '~')
   5680     {
   5681       (*pp)++;
   5682 
   5683       if (**pp == '=' || **pp == '+' || **pp == '-')
   5684 	{
   5685 	  /* Obsolete flags that used to indicate the presence
   5686 	     of constructors and/or destructors.  */
   5687 	  (*pp)++;
   5688 	}
   5689 
   5690       /* Read either a '%' or the final ';'.  */
   5691       if (*(*pp)++ == '%')
   5692 	{
   5693 	  /* The next number is the type number of the base class
   5694 	     (possibly our own class) which supplies the vtable for
   5695 	     this class.  Parse it out, and search that class to find
   5696 	     its vtable pointer, and install those into TYPE_VPTR_BASETYPE
   5697 	     and TYPE_VPTR_FIELDNO.  */
   5698 
   5699 	  struct type *t;
   5700 	  int i;
   5701 
   5702 	  t = read_type (pp, objfile);
   5703 	  p = (*pp)++;
   5704 	  while (*p != '\0' && *p != ';')
   5705 	    {
   5706 	      p++;
   5707 	    }
   5708 	  if (*p == '\0')
   5709 	    {
   5710 	      /* Premature end of symbol.  */
   5711 	      return 0;
   5712 	    }
   5713 
   5714 	  set_type_vptr_basetype (type, t);
   5715 	  if (type == t)	/* Our own class provides vtbl ptr.  */
   5716 	    {
   5717 	      for (i = t->num_fields () - 1;
   5718 		   i >= TYPE_N_BASECLASSES (t);
   5719 		   --i)
   5720 		{
   5721 		  const char *name = t->field (i).name ();
   5722 
   5723 		  if (!strncmp (name, vptr_name, sizeof (vptr_name) - 2)
   5724 		      && is_cplus_marker (name[sizeof (vptr_name) - 2]))
   5725 		    {
   5726 		      set_type_vptr_fieldno (type, i);
   5727 		      goto gotit;
   5728 		    }
   5729 		}
   5730 	      /* Virtual function table field not found.  */
   5731 	      complaint (_("virtual function table pointer "
   5732 			   "not found when defining class `%s'"),
   5733 			 type->name ());
   5734 	      return 0;
   5735 	    }
   5736 	  else
   5737 	    {
   5738 	      set_type_vptr_fieldno (type, TYPE_VPTR_FIELDNO (t));
   5739 	    }
   5740 
   5741 	gotit:
   5742 	  *pp = p + 1;
   5743 	}
   5744     }
   5745   return 1;
   5746 }
   5747 
   5748 static int
   5749 attach_fn_fields_to_type (struct stab_field_info *fip, struct type *type)
   5750 {
   5751   int n;
   5752 
   5753   for (n = TYPE_NFN_FIELDS (type);
   5754        fip->fnlist != NULL;
   5755        fip->fnlist = fip->fnlist->next)
   5756     {
   5757       --n;			/* Circumvent Sun3 compiler bug.  */
   5758       TYPE_FN_FIELDLISTS (type)[n] = fip->fnlist->fn_fieldlist;
   5759     }
   5760   return 1;
   5761 }
   5762 
   5763 /* Create the vector of fields, and record how big it is.
   5764    We need this info to record proper virtual function table information
   5765    for this class's virtual functions.  */
   5766 
   5767 static int
   5768 attach_fields_to_type (struct stab_field_info *fip, struct type *type,
   5769 		       struct objfile *objfile)
   5770 {
   5771   int nfields = 0;
   5772   struct stabs_nextfield *scan;
   5773 
   5774   /* Count up the number of fields that we have.  */
   5775 
   5776   for (scan = fip->list; scan != NULL; scan = scan->next)
   5777     nfields++;
   5778 
   5779   /* Now we know how many fields there are, and whether or not there are any
   5780      non-public fields.  Record the field count, allocate space for the
   5781      array of fields.  */
   5782 
   5783   type->alloc_fields (nfields);
   5784 
   5785   /* Copy the saved-up fields into the field vector.  Start from the
   5786      head of the list, adding to the tail of the field array, so that
   5787      they end up in the same order in the array in which they were
   5788      added to the list.  */
   5789 
   5790   while (nfields-- > 0)
   5791     {
   5792       type->field (nfields) = fip->list->field;
   5793       fip->list = fip->list->next;
   5794     }
   5795   return 1;
   5796 }
   5797 
   5798 
   5799 /* Complain that the compiler has emitted more than one definition for the
   5800    structure type TYPE.  */
   5801 static void
   5802 complain_about_struct_wipeout (struct type *type)
   5803 {
   5804   const char *name = "";
   5805   const char *kind = "";
   5806 
   5807   if (type->name ())
   5808     {
   5809       name = type->name ();
   5810       switch (type->code ())
   5811 	{
   5812 	case TYPE_CODE_STRUCT: kind = "struct "; break;
   5813 	case TYPE_CODE_UNION:  kind = "union ";  break;
   5814 	case TYPE_CODE_ENUM:   kind = "enum ";   break;
   5815 	default: kind = "";
   5816 	}
   5817     }
   5818   else
   5819     {
   5820       name = "<unknown>";
   5821       kind = "";
   5822     }
   5823 
   5824   complaint (_("struct/union type gets multiply defined: %s%s"), kind, name);
   5825 }
   5826 
   5827 /* Set the length for all variants of a same main_type, which are
   5828    connected in the closed chain.
   5829 
   5830    This is something that needs to be done when a type is defined *after*
   5831    some cross references to this type have already been read.  Consider
   5832    for instance the following scenario where we have the following two
   5833    stabs entries:
   5834 
   5835 	.stabs  "t:p(0,21)=*(0,22)=k(0,23)=xsdummy:",160,0,28,-24
   5836 	.stabs  "dummy:T(0,23)=s16x:(0,1),0,3[...]"
   5837 
   5838    A stubbed version of type dummy is created while processing the first
   5839    stabs entry.  The length of that type is initially set to zero, since
   5840    it is unknown at this point.  Also, a "constant" variation of type
   5841    "dummy" is created as well (this is the "(0,22)=k(0,23)" section of
   5842    the stabs line).
   5843 
   5844    The second stabs entry allows us to replace the stubbed definition
   5845    with the real definition.  However, we still need to adjust the length
   5846    of the "constant" variation of that type, as its length was left
   5847    untouched during the main type replacement...  */
   5848 
   5849 static void
   5850 set_length_in_type_chain (struct type *type)
   5851 {
   5852   struct type *ntype = TYPE_CHAIN (type);
   5853 
   5854   while (ntype != type)
   5855     {
   5856       if (ntype->length () == 0)
   5857 	ntype->set_length (type->length ());
   5858       else
   5859 	complain_about_struct_wipeout (ntype);
   5860       ntype = TYPE_CHAIN (ntype);
   5861     }
   5862 }
   5863 
   5864 /* Read the description of a structure (or union type) and return an object
   5865    describing the type.
   5866 
   5867    PP points to a character pointer that points to the next unconsumed token
   5868    in the stabs string.  For example, given stabs "A:T4=s4a:1,0,32;;",
   5869    *PP will point to "4a:1,0,32;;".
   5870 
   5871    TYPE points to an incomplete type that needs to be filled in.
   5872 
   5873    OBJFILE points to the current objfile from which the stabs information is
   5874    being read.  (Note that it is redundant in that TYPE also contains a pointer
   5875    to this same objfile, so it might be a good idea to eliminate it.  FIXME).
   5876  */
   5877 
   5878 static struct type *
   5879 read_struct_type (const char **pp, struct type *type, enum type_code type_code,
   5880 		  struct objfile *objfile)
   5881 {
   5882   struct stab_field_info fi;
   5883 
   5884   /* When describing struct/union/class types in stabs, G++ always drops
   5885      all qualifications from the name.  So if you've got:
   5886        struct A { ... struct B { ... }; ... };
   5887      then G++ will emit stabs for `struct A::B' that call it simply
   5888      `struct B'.  Obviously, if you've got a real top-level definition for
   5889      `struct B', or other nested definitions, this is going to cause
   5890      problems.
   5891 
   5892      Obviously, GDB can't fix this by itself, but it can at least avoid
   5893      scribbling on existing structure type objects when new definitions
   5894      appear.  */
   5895   if (! (type->code () == TYPE_CODE_UNDEF
   5896 	 || type->is_stub ()))
   5897     {
   5898       complain_about_struct_wipeout (type);
   5899 
   5900       /* It's probably best to return the type unchanged.  */
   5901       return type;
   5902     }
   5903 
   5904   INIT_CPLUS_SPECIFIC (type);
   5905   type->set_code (type_code);
   5906   type->set_is_stub (false);
   5907 
   5908   /* First comes the total size in bytes.  */
   5909 
   5910   {
   5911     int nbits;
   5912 
   5913     type->set_length (read_huge_number (pp, 0, &nbits, 0));
   5914     if (nbits != 0)
   5915       return error_type (pp, objfile);
   5916     set_length_in_type_chain (type);
   5917   }
   5918 
   5919   /* Now read the baseclasses, if any, read the regular C struct or C++
   5920      class member fields, attach the fields to the type, read the C++
   5921      member functions, attach them to the type, and then read any tilde
   5922      field (baseclass specifier for the class holding the main vtable).  */
   5923 
   5924   if (!read_baseclasses (&fi, pp, type, objfile)
   5925       || !read_struct_fields (&fi, pp, type, objfile)
   5926       || !attach_fields_to_type (&fi, type, objfile)
   5927       || !read_member_functions (&fi, pp, type, objfile)
   5928       || !attach_fn_fields_to_type (&fi, type)
   5929       || !read_tilde_fields (&fi, pp, type, objfile))
   5930     {
   5931       type = error_type (pp, objfile);
   5932     }
   5933 
   5934   return (type);
   5935 }
   5936 
   5937 /* Read a definition of an array type,
   5938    and create and return a suitable type object.
   5939    Also creates a range type which represents the bounds of that
   5940    array.  */
   5941 
   5942 static struct type *
   5943 read_array_type (const char **pp, struct type *type,
   5944 		 struct objfile *objfile)
   5945 {
   5946   struct type *index_type, *element_type, *range_type;
   5947   int lower, upper;
   5948   int adjustable = 0;
   5949   int nbits;
   5950 
   5951   /* Format of an array type:
   5952      "ar<index type>;lower;upper;<array_contents_type>".
   5953      OS9000: "arlower,upper;<array_contents_type>".
   5954 
   5955      Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
   5956      for these, produce a type like float[][].  */
   5957 
   5958     {
   5959       index_type = read_type (pp, objfile);
   5960       if (**pp != ';')
   5961 	/* Improper format of array type decl.  */
   5962 	return error_type (pp, objfile);
   5963       ++*pp;
   5964     }
   5965 
   5966   if (!(**pp >= '0' && **pp <= '9') && **pp != '-')
   5967     {
   5968       (*pp)++;
   5969       adjustable = 1;
   5970     }
   5971   lower = read_huge_number (pp, ';', &nbits, 0);
   5972 
   5973   if (nbits != 0)
   5974     return error_type (pp, objfile);
   5975 
   5976   if (!(**pp >= '0' && **pp <= '9') && **pp != '-')
   5977     {
   5978       (*pp)++;
   5979       adjustable = 1;
   5980     }
   5981   upper = read_huge_number (pp, ';', &nbits, 0);
   5982   if (nbits != 0)
   5983     return error_type (pp, objfile);
   5984 
   5985   element_type = read_type (pp, objfile);
   5986 
   5987   if (adjustable)
   5988     {
   5989       lower = 0;
   5990       upper = -1;
   5991     }
   5992 
   5993   type_allocator alloc (objfile, get_current_subfile ()->language);
   5994   range_type =
   5995     create_static_range_type (alloc, index_type, lower, upper);
   5996   type_allocator smash_alloc (type, type_allocator::SMASH);
   5997   type = create_array_type (smash_alloc, element_type, range_type);
   5998 
   5999   return type;
   6000 }
   6001 
   6002 
   6003 /* Read a definition of an enumeration type,
   6004    and create and return a suitable type object.
   6005    Also defines the symbols that represent the values of the type.  */
   6006 
   6007 static struct type *
   6008 read_enum_type (const char **pp, struct type *type,
   6009 		struct objfile *objfile)
   6010 {
   6011   struct gdbarch *gdbarch = objfile->arch ();
   6012   const char *p;
   6013   char *name;
   6014   long n;
   6015   struct symbol *sym;
   6016   int nsyms = 0;
   6017   struct pending **symlist;
   6018   struct pending *osyms, *syms;
   6019   int o_nsyms;
   6020   int nbits;
   6021   int unsigned_enum = 1;
   6022 
   6023 #if 0
   6024   /* FIXME!  The stabs produced by Sun CC merrily define things that ought
   6025      to be file-scope, between N_FN entries, using N_LSYM.  What's a mother
   6026      to do?  For now, force all enum values to file scope.  */
   6027   if (within_function)
   6028     symlist = get_local_symbols ();
   6029   else
   6030 #endif
   6031     symlist = get_file_symbols ();
   6032   osyms = *symlist;
   6033   o_nsyms = osyms ? osyms->nsyms : 0;
   6034 
   6035   /* The aix4 compiler emits an extra field before the enum members;
   6036      my guess is it's a type of some sort.  Just ignore it.  */
   6037   if (**pp == '-')
   6038     {
   6039       /* Skip over the type.  */
   6040       while (**pp != ':')
   6041 	(*pp)++;
   6042 
   6043       /* Skip over the colon.  */
   6044       (*pp)++;
   6045     }
   6046 
   6047   /* Read the value-names and their values.
   6048      The input syntax is NAME:VALUE,NAME:VALUE, and so on.
   6049      A semicolon or comma instead of a NAME means the end.  */
   6050   while (**pp && **pp != ';' && **pp != ',')
   6051     {
   6052       STABS_CONTINUE (pp, objfile);
   6053       p = *pp;
   6054       while (*p != ':')
   6055 	p++;
   6056       name = obstack_strndup (&objfile->objfile_obstack, *pp, p - *pp);
   6057       *pp = p + 1;
   6058       n = read_huge_number (pp, ',', &nbits, 0);
   6059       if (nbits != 0)
   6060 	return error_type (pp, objfile);
   6061 
   6062       sym = new (&objfile->objfile_obstack) symbol;
   6063       sym->set_linkage_name (name);
   6064       sym->set_language (get_current_subfile ()->language,
   6065 			 &objfile->objfile_obstack);
   6066       sym->set_aclass_index (LOC_CONST);
   6067       sym->set_domain (VAR_DOMAIN);
   6068       sym->set_value_longest (n);
   6069       if (n < 0)
   6070 	unsigned_enum = 0;
   6071       add_symbol_to_list (sym, symlist);
   6072       nsyms++;
   6073     }
   6074 
   6075   if (**pp == ';')
   6076     (*pp)++;			/* Skip the semicolon.  */
   6077 
   6078   /* Now fill in the fields of the type-structure.  */
   6079 
   6080   type->set_length (gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT);
   6081   set_length_in_type_chain (type);
   6082   type->set_code (TYPE_CODE_ENUM);
   6083   type->set_is_stub (false);
   6084   if (unsigned_enum)
   6085     type->set_is_unsigned (true);
   6086   type->alloc_fields (nsyms);
   6087 
   6088   /* Find the symbols for the values and put them into the type.
   6089      The symbols can be found in the symlist that we put them on
   6090      to cause them to be defined.  osyms contains the old value
   6091      of that symlist; everything up to there was defined by us.  */
   6092   /* Note that we preserve the order of the enum constants, so
   6093      that in something like "enum {FOO, LAST_THING=FOO}" we print
   6094      FOO, not LAST_THING.  */
   6095 
   6096   for (syms = *symlist, n = nsyms - 1; syms; syms = syms->next)
   6097     {
   6098       int last = syms == osyms ? o_nsyms : 0;
   6099       int j = syms->nsyms;
   6100 
   6101       for (; --j >= last; --n)
   6102 	{
   6103 	  struct symbol *xsym = syms->symbol[j];
   6104 
   6105 	  xsym->set_type (type);
   6106 	  type->field (n).set_name (xsym->linkage_name ());
   6107 	  type->field (n).set_loc_enumval (xsym->value_longest ());
   6108 	  type->field (n).set_bitsize (0);
   6109 	}
   6110       if (syms == osyms)
   6111 	break;
   6112     }
   6113 
   6114   return type;
   6115 }
   6116 
   6117 /* Sun's ACC uses a somewhat saner method for specifying the builtin
   6118    typedefs in every file (for int, long, etc):
   6119 
   6120    type = b <signed> <width> <format type>; <offset>; <nbits>
   6121    signed = u or s.
   6122    optional format type = c or b for char or boolean.
   6123    offset = offset from high order bit to start bit of type.
   6124    width is # bytes in object of this type, nbits is # bits in type.
   6125 
   6126    The width/offset stuff appears to be for small objects stored in
   6127    larger ones (e.g. `shorts' in `int' registers).  We ignore it for now,
   6128    FIXME.  */
   6129 
   6130 static struct type *
   6131 read_sun_builtin_type (const char **pp, int typenums[2], struct objfile *objfile)
   6132 {
   6133   int type_bits;
   6134   int nbits;
   6135   int unsigned_type;
   6136   int boolean_type = 0;
   6137 
   6138   switch (**pp)
   6139     {
   6140     case 's':
   6141       unsigned_type = 0;
   6142       break;
   6143     case 'u':
   6144       unsigned_type = 1;
   6145       break;
   6146     default:
   6147       return error_type (pp, objfile);
   6148     }
   6149   (*pp)++;
   6150 
   6151   /* For some odd reason, all forms of char put a c here.  This is strange
   6152      because no other type has this honor.  We can safely ignore this because
   6153      we actually determine 'char'acterness by the number of bits specified in
   6154      the descriptor.
   6155      Boolean forms, e.g Fortran logical*X, put a b here.  */
   6156 
   6157   if (**pp == 'c')
   6158     (*pp)++;
   6159   else if (**pp == 'b')
   6160     {
   6161       boolean_type = 1;
   6162       (*pp)++;
   6163     }
   6164 
   6165   /* The first number appears to be the number of bytes occupied
   6166      by this type, except that unsigned short is 4 instead of 2.
   6167      Since this information is redundant with the third number,
   6168      we will ignore it.  */
   6169   read_huge_number (pp, ';', &nbits, 0);
   6170   if (nbits != 0)
   6171     return error_type (pp, objfile);
   6172 
   6173   /* The second number is always 0, so ignore it too.  */
   6174   read_huge_number (pp, ';', &nbits, 0);
   6175   if (nbits != 0)
   6176     return error_type (pp, objfile);
   6177 
   6178   /* The third number is the number of bits for this type.  */
   6179   type_bits = read_huge_number (pp, 0, &nbits, 0);
   6180   if (nbits != 0)
   6181     return error_type (pp, objfile);
   6182   /* The type *should* end with a semicolon.  If it are embedded
   6183      in a larger type the semicolon may be the only way to know where
   6184      the type ends.  If this type is at the end of the stabstring we
   6185      can deal with the omitted semicolon (but we don't have to like
   6186      it).  Don't bother to complain(), Sun's compiler omits the semicolon
   6187      for "void".  */
   6188   if (**pp == ';')
   6189     ++(*pp);
   6190 
   6191   type_allocator alloc (objfile, get_current_subfile ()->language);
   6192   if (type_bits == 0)
   6193     {
   6194       struct type *type = alloc.new_type (TYPE_CODE_VOID,
   6195 					  TARGET_CHAR_BIT, nullptr);
   6196       if (unsigned_type)
   6197 	type->set_is_unsigned (true);
   6198 
   6199       return type;
   6200     }
   6201 
   6202   if (boolean_type)
   6203     return init_boolean_type (alloc, type_bits, unsigned_type, NULL);
   6204   else
   6205     return init_integer_type (alloc, type_bits, unsigned_type, NULL);
   6206 }
   6207 
   6208 static struct type *
   6209 read_sun_floating_type (const char **pp, int typenums[2],
   6210 			struct objfile *objfile)
   6211 {
   6212   int nbits;
   6213   int details;
   6214   int nbytes;
   6215   struct type *rettype;
   6216 
   6217   /* The first number has more details about the type, for example
   6218      FN_COMPLEX.  */
   6219   details = read_huge_number (pp, ';', &nbits, 0);
   6220   if (nbits != 0)
   6221     return error_type (pp, objfile);
   6222 
   6223   /* The second number is the number of bytes occupied by this type.  */
   6224   nbytes = read_huge_number (pp, ';', &nbits, 0);
   6225   if (nbits != 0)
   6226     return error_type (pp, objfile);
   6227 
   6228   nbits = nbytes * TARGET_CHAR_BIT;
   6229 
   6230   if (details == NF_COMPLEX || details == NF_COMPLEX16
   6231       || details == NF_COMPLEX32)
   6232     {
   6233       rettype = dbx_init_float_type (objfile, nbits / 2);
   6234       return init_complex_type (NULL, rettype);
   6235     }
   6236 
   6237   return dbx_init_float_type (objfile, nbits);
   6238 }
   6239 
   6240 /* Read a number from the string pointed to by *PP.
   6241    The value of *PP is advanced over the number.
   6242    If END is nonzero, the character that ends the
   6243    number must match END, or an error happens;
   6244    and that character is skipped if it does match.
   6245    If END is zero, *PP is left pointing to that character.
   6246 
   6247    If TWOS_COMPLEMENT_BITS is set to a strictly positive value and if
   6248    the number is represented in an octal representation, assume that
   6249    it is represented in a 2's complement representation with a size of
   6250    TWOS_COMPLEMENT_BITS.
   6251 
   6252    If the number fits in a long, set *BITS to 0 and return the value.
   6253    If not, set *BITS to be the number of bits in the number and return 0.
   6254 
   6255    If encounter garbage, set *BITS to -1 and return 0.  */
   6256 
   6257 static long
   6258 read_huge_number (const char **pp, int end, int *bits,
   6259 		  int twos_complement_bits)
   6260 {
   6261   const char *p = *pp;
   6262   int sign = 1;
   6263   int sign_bit = 0;
   6264   long n = 0;
   6265   int radix = 10;
   6266   char overflow = 0;
   6267   int nbits = 0;
   6268   int c;
   6269   long upper_limit;
   6270   int twos_complement_representation = 0;
   6271 
   6272   if (*p == '-')
   6273     {
   6274       sign = -1;
   6275       p++;
   6276     }
   6277 
   6278   /* Leading zero means octal.  GCC uses this to output values larger
   6279      than an int (because that would be hard in decimal).  */
   6280   if (*p == '0')
   6281     {
   6282       radix = 8;
   6283       p++;
   6284     }
   6285 
   6286   /* Skip extra zeros.  */
   6287   while (*p == '0')
   6288     p++;
   6289 
   6290   if (sign > 0 && radix == 8 && twos_complement_bits > 0)
   6291     {
   6292       /* Octal, possibly signed.  Check if we have enough chars for a
   6293 	 negative number.  */
   6294 
   6295       size_t len;
   6296       const char *p1 = p;
   6297 
   6298       while ((c = *p1) >= '0' && c < '8')
   6299 	p1++;
   6300 
   6301       len = p1 - p;
   6302       if (len > twos_complement_bits / 3
   6303 	  || (twos_complement_bits % 3 == 0
   6304 	      && len == twos_complement_bits / 3))
   6305 	{
   6306 	  /* Ok, we have enough characters for a signed value, check
   6307 	     for signedness by testing if the sign bit is set.  */
   6308 	  sign_bit = (twos_complement_bits % 3 + 2) % 3;
   6309 	  c = *p - '0';
   6310 	  if (c & (1 << sign_bit))
   6311 	    {
   6312 	      /* Definitely signed.  */
   6313 	      twos_complement_representation = 1;
   6314 	      sign = -1;
   6315 	    }
   6316 	}
   6317     }
   6318 
   6319   upper_limit = LONG_MAX / radix;
   6320 
   6321   while ((c = *p++) >= '0' && c < ('0' + radix))
   6322     {
   6323       if (n <= upper_limit)
   6324 	{
   6325 	  if (twos_complement_representation)
   6326 	    {
   6327 	      /* Octal, signed, twos complement representation.  In
   6328 		 this case, n is the corresponding absolute value.  */
   6329 	      if (n == 0)
   6330 		{
   6331 		  long sn = c - '0' - ((2 * (c - '0')) | (2 << sign_bit));
   6332 
   6333 		  n = -sn;
   6334 		}
   6335 	      else
   6336 		{
   6337 		  n *= radix;
   6338 		  n -= c - '0';
   6339 		}
   6340 	    }
   6341 	  else
   6342 	    {
   6343 	      /* unsigned representation */
   6344 	      n *= radix;
   6345 	      n += c - '0';		/* FIXME this overflows anyway.  */
   6346 	    }
   6347 	}
   6348       else
   6349 	overflow = 1;
   6350 
   6351       /* This depends on large values being output in octal, which is
   6352 	 what GCC does.  */
   6353       if (radix == 8)
   6354 	{
   6355 	  if (nbits == 0)
   6356 	    {
   6357 	      if (c == '0')
   6358 		/* Ignore leading zeroes.  */
   6359 		;
   6360 	      else if (c == '1')
   6361 		nbits = 1;
   6362 	      else if (c == '2' || c == '3')
   6363 		nbits = 2;
   6364 	      else
   6365 		nbits = 3;
   6366 	    }
   6367 	  else
   6368 	    nbits += 3;
   6369 	}
   6370     }
   6371   if (end)
   6372     {
   6373       if (c && c != end)
   6374 	{
   6375 	  if (bits != NULL)
   6376 	    *bits = -1;
   6377 	  return 0;
   6378 	}
   6379     }
   6380   else
   6381     --p;
   6382 
   6383   if (radix == 8 && twos_complement_bits > 0 && nbits > twos_complement_bits)
   6384     {
   6385       /* We were supposed to parse a number with maximum
   6386 	 TWOS_COMPLEMENT_BITS bits, but something went wrong.  */
   6387       if (bits != NULL)
   6388 	*bits = -1;
   6389       return 0;
   6390     }
   6391 
   6392   *pp = p;
   6393   if (overflow)
   6394     {
   6395       if (nbits == 0)
   6396 	{
   6397 	  /* Large decimal constants are an error (because it is hard to
   6398 	     count how many bits are in them).  */
   6399 	  if (bits != NULL)
   6400 	    *bits = -1;
   6401 	  return 0;
   6402 	}
   6403 
   6404       /* -0x7f is the same as 0x80.  So deal with it by adding one to
   6405 	 the number of bits.  Two's complement representation octals
   6406 	 can't have a '-' in front.  */
   6407       if (sign == -1 && !twos_complement_representation)
   6408 	++nbits;
   6409       if (bits)
   6410 	*bits = nbits;
   6411     }
   6412   else
   6413     {
   6414       if (bits)
   6415 	*bits = 0;
   6416       return n * sign;
   6417     }
   6418   /* It's *BITS which has the interesting information.  */
   6419   return 0;
   6420 }
   6421 
   6422 static struct type *
   6423 read_range_type (const char **pp, int typenums[2], int type_size,
   6424 		 struct objfile *objfile)
   6425 {
   6426   struct gdbarch *gdbarch = objfile->arch ();
   6427   const char *orig_pp = *pp;
   6428   int rangenums[2];
   6429   long n2, n3;
   6430   int n2bits, n3bits;
   6431   int self_subrange;
   6432   struct type *result_type;
   6433   struct type *index_type = NULL;
   6434 
   6435   /* First comes a type we are a subrange of.
   6436      In C it is usually 0, 1 or the type being defined.  */
   6437   if (read_type_number (pp, rangenums) != 0)
   6438     return error_type (pp, objfile);
   6439   self_subrange = (rangenums[0] == typenums[0] &&
   6440 		   rangenums[1] == typenums[1]);
   6441 
   6442   if (**pp == '=')
   6443     {
   6444       *pp = orig_pp;
   6445       index_type = read_type (pp, objfile);
   6446     }
   6447 
   6448   /* A semicolon should now follow; skip it.  */
   6449   if (**pp == ';')
   6450     (*pp)++;
   6451 
   6452   /* The remaining two operands are usually lower and upper bounds
   6453      of the range.  But in some special cases they mean something else.  */
   6454   n2 = read_huge_number (pp, ';', &n2bits, type_size);
   6455   n3 = read_huge_number (pp, ';', &n3bits, type_size);
   6456 
   6457   if (n2bits == -1 || n3bits == -1)
   6458     return error_type (pp, objfile);
   6459 
   6460   type_allocator alloc (objfile, get_current_subfile ()->language);
   6461 
   6462   if (index_type)
   6463     goto handle_true_range;
   6464 
   6465   /* If limits are huge, must be large integral type.  */
   6466   if (n2bits != 0 || n3bits != 0)
   6467     {
   6468       char got_signed = 0;
   6469       char got_unsigned = 0;
   6470       /* Number of bits in the type.  */
   6471       int nbits = 0;
   6472 
   6473       /* If a type size attribute has been specified, the bounds of
   6474 	 the range should fit in this size.  If the lower bounds needs
   6475 	 more bits than the upper bound, then the type is signed.  */
   6476       if (n2bits <= type_size && n3bits <= type_size)
   6477 	{
   6478 	  if (n2bits == type_size && n2bits > n3bits)
   6479 	    got_signed = 1;
   6480 	  else
   6481 	    got_unsigned = 1;
   6482 	  nbits = type_size;
   6483 	}
   6484       /* Range from 0 to <large number> is an unsigned large integral type.  */
   6485       else if ((n2bits == 0 && n2 == 0) && n3bits != 0)
   6486 	{
   6487 	  got_unsigned = 1;
   6488 	  nbits = n3bits;
   6489 	}
   6490       /* Range from <large number> to <large number>-1 is a large signed
   6491 	 integral type.  Take care of the case where <large number> doesn't
   6492 	 fit in a long but <large number>-1 does.  */
   6493       else if ((n2bits != 0 && n3bits != 0 && n2bits == n3bits + 1)
   6494 	       || (n2bits != 0 && n3bits == 0
   6495 		   && (n2bits == sizeof (long) * HOST_CHAR_BIT)
   6496 		   && n3 == LONG_MAX))
   6497 	{
   6498 	  got_signed = 1;
   6499 	  nbits = n2bits;
   6500 	}
   6501 
   6502       if (got_signed || got_unsigned)
   6503 	return init_integer_type (alloc, nbits, got_unsigned, NULL);
   6504       else
   6505 	return error_type (pp, objfile);
   6506     }
   6507 
   6508   /* A type defined as a subrange of itself, with bounds both 0, is void.  */
   6509   if (self_subrange && n2 == 0 && n3 == 0)
   6510     return alloc.new_type (TYPE_CODE_VOID, TARGET_CHAR_BIT, nullptr);
   6511 
   6512   /* If n3 is zero and n2 is positive, we want a floating type, and n2
   6513      is the width in bytes.
   6514 
   6515      Fortran programs appear to use this for complex types also.  To
   6516      distinguish between floats and complex, g77 (and others?)  seem
   6517      to use self-subranges for the complexes, and subranges of int for
   6518      the floats.
   6519 
   6520      Also note that for complexes, g77 sets n2 to the size of one of
   6521      the member floats, not the whole complex beast.  My guess is that
   6522      this was to work well with pre-COMPLEX versions of gdb.  */
   6523 
   6524   if (n3 == 0 && n2 > 0)
   6525     {
   6526       struct type *float_type
   6527 	= dbx_init_float_type (objfile, n2 * TARGET_CHAR_BIT);
   6528 
   6529       if (self_subrange)
   6530 	return init_complex_type (NULL, float_type);
   6531       else
   6532 	return float_type;
   6533     }
   6534 
   6535   /* If the upper bound is -1, it must really be an unsigned integral.  */
   6536 
   6537   else if (n2 == 0 && n3 == -1)
   6538     {
   6539       int bits = type_size;
   6540 
   6541       if (bits <= 0)
   6542 	{
   6543 	  /* We don't know its size.  It is unsigned int or unsigned
   6544 	     long.  GCC 2.3.3 uses this for long long too, but that is
   6545 	     just a GDB 3.5 compatibility hack.  */
   6546 	  bits = gdbarch_int_bit (gdbarch);
   6547 	}
   6548 
   6549       return init_integer_type (alloc, bits, 1, NULL);
   6550     }
   6551 
   6552   /* Special case: char is defined (Who knows why) as a subrange of
   6553      itself with range 0-127.  */
   6554   else if (self_subrange && n2 == 0 && n3 == 127)
   6555     {
   6556       struct type *type = init_integer_type (alloc, TARGET_CHAR_BIT,
   6557 					     0, NULL);
   6558       type->set_has_no_signedness (true);
   6559       return type;
   6560     }
   6561   /* We used to do this only for subrange of self or subrange of int.  */
   6562   else if (n2 == 0)
   6563     {
   6564       /* -1 is used for the upper bound of (4 byte) "unsigned int" and
   6565 	 "unsigned long", and we already checked for that,
   6566 	 so don't need to test for it here.  */
   6567 
   6568       if (n3 < 0)
   6569 	/* n3 actually gives the size.  */
   6570 	return init_integer_type (alloc, -n3 * TARGET_CHAR_BIT, 1, NULL);
   6571 
   6572       /* Is n3 == 2**(8n)-1 for some integer n?  Then it's an
   6573 	 unsigned n-byte integer.  But do require n to be a power of
   6574 	 two; we don't want 3- and 5-byte integers flying around.  */
   6575       {
   6576 	int bytes;
   6577 	unsigned long bits;
   6578 
   6579 	bits = n3;
   6580 	for (bytes = 0; (bits & 0xff) == 0xff; bytes++)
   6581 	  bits >>= 8;
   6582 	if (bits == 0
   6583 	    && ((bytes - 1) & bytes) == 0) /* "bytes is a power of two" */
   6584 	  return init_integer_type (alloc, bytes * TARGET_CHAR_BIT, 1, NULL);
   6585       }
   6586     }
   6587   /* I think this is for Convex "long long".  Since I don't know whether
   6588      Convex sets self_subrange, I also accept that particular size regardless
   6589      of self_subrange.  */
   6590   else if (n3 == 0 && n2 < 0
   6591 	   && (self_subrange
   6592 	       || n2 == -gdbarch_long_long_bit
   6593 			  (gdbarch) / TARGET_CHAR_BIT))
   6594     return init_integer_type (alloc, -n2 * TARGET_CHAR_BIT, 0, NULL);
   6595   else if (n2 == -n3 - 1)
   6596     {
   6597       if (n3 == 0x7f)
   6598 	return init_integer_type (alloc, 8, 0, NULL);
   6599       if (n3 == 0x7fff)
   6600 	return init_integer_type (alloc, 16, 0, NULL);
   6601       if (n3 == 0x7fffffff)
   6602 	return init_integer_type (alloc, 32, 0, NULL);
   6603     }
   6604 
   6605   /* We have a real range type on our hands.  Allocate space and
   6606      return a real pointer.  */
   6607 handle_true_range:
   6608 
   6609   if (self_subrange)
   6610     index_type = builtin_type (objfile)->builtin_int;
   6611   else
   6612     index_type = *dbx_lookup_type (rangenums, objfile);
   6613   if (index_type == NULL)
   6614     {
   6615       /* Does this actually ever happen?  Is that why we are worrying
   6616 	 about dealing with it rather than just calling error_type?  */
   6617 
   6618       complaint (_("base type %d of range type is not defined"), rangenums[1]);
   6619 
   6620       index_type = builtin_type (objfile)->builtin_int;
   6621     }
   6622 
   6623   result_type
   6624     = create_static_range_type (alloc, index_type, n2, n3);
   6625   return (result_type);
   6626 }
   6627 
   6628 /* Read in an argument list.  This is a list of types, separated by commas
   6629    and terminated with END.  Return the list of types read in, or NULL
   6630    if there is an error.  */
   6631 
   6632 static struct field *
   6633 read_args (const char **pp, int end, struct objfile *objfile, int *nargsp,
   6634 	   int *varargsp)
   6635 {
   6636   /* FIXME!  Remove this arbitrary limit!  */
   6637   struct type *types[1024];	/* Allow for fns of 1023 parameters.  */
   6638   int n = 0, i;
   6639   struct field *rval;
   6640 
   6641   while (**pp != end)
   6642     {
   6643       if (**pp != ',')
   6644 	/* Invalid argument list: no ','.  */
   6645 	return NULL;
   6646       (*pp)++;
   6647       STABS_CONTINUE (pp, objfile);
   6648       types[n++] = read_type (pp, objfile);
   6649     }
   6650   (*pp)++;			/* get past `end' (the ':' character).  */
   6651 
   6652   if (n == 0)
   6653     {
   6654       /* We should read at least the THIS parameter here.  Some broken stabs
   6655 	 output contained `(0,41),(0,42)=@s8;-16;,(0,43),(0,1);' where should
   6656 	 have been present ";-16,(0,43)" reference instead.  This way the
   6657 	 excessive ";" marker prematurely stops the parameters parsing.  */
   6658 
   6659       complaint (_("Invalid (empty) method arguments"));
   6660       *varargsp = 0;
   6661     }
   6662   else if (types[n - 1]->code () != TYPE_CODE_VOID)
   6663     *varargsp = 1;
   6664   else
   6665     {
   6666       n--;
   6667       *varargsp = 0;
   6668     }
   6669 
   6670   rval = XCNEWVEC (struct field, n);
   6671   for (i = 0; i < n; i++)
   6672     rval[i].set_type (types[i]);
   6673   *nargsp = n;
   6674   return rval;
   6675 }
   6676 
   6677 /* Common block handling.  */
   6679 
   6680 /* List of symbols declared since the last BCOMM.  This list is a tail
   6681    of local_symbols.  When ECOMM is seen, the symbols on the list
   6682    are noted so their proper addresses can be filled in later,
   6683    using the common block base address gotten from the assembler
   6684    stabs.  */
   6685 
   6686 static struct pending *common_block;
   6687 static int common_block_i;
   6688 
   6689 /* Name of the current common block.  We get it from the BCOMM instead of the
   6690    ECOMM to match IBM documentation (even though IBM puts the name both places
   6691    like everyone else).  */
   6692 static char *common_block_name;
   6693 
   6694 /* Process a N_BCOMM symbol.  The storage for NAME is not guaranteed
   6695    to remain after this function returns.  */
   6696 
   6697 void
   6698 common_block_start (const char *name, struct objfile *objfile)
   6699 {
   6700   if (common_block_name != NULL)
   6701     {
   6702       complaint (_("Invalid symbol data: common block within common block"));
   6703     }
   6704   common_block = *get_local_symbols ();
   6705   common_block_i = common_block ? common_block->nsyms : 0;
   6706   common_block_name = obstack_strdup (&objfile->objfile_obstack, name);
   6707 }
   6708 
   6709 /* Process a N_ECOMM symbol.  */
   6710 
   6711 void
   6712 common_block_end (struct objfile *objfile)
   6713 {
   6714   /* Symbols declared since the BCOMM are to have the common block
   6715      start address added in when we know it.  common_block and
   6716      common_block_i point to the first symbol after the BCOMM in
   6717      the local_symbols list; copy the list and hang it off the
   6718      symbol for the common block name for later fixup.  */
   6719   int i;
   6720   struct symbol *sym;
   6721   struct pending *newobj = 0;
   6722   struct pending *next;
   6723   int j;
   6724 
   6725   if (common_block_name == NULL)
   6726     {
   6727       complaint (_("ECOMM symbol unmatched by BCOMM"));
   6728       return;
   6729     }
   6730 
   6731   sym = new (&objfile->objfile_obstack) symbol;
   6732   /* Note: common_block_name already saved on objfile_obstack.  */
   6733   sym->set_linkage_name (common_block_name);
   6734   sym->set_aclass_index (LOC_BLOCK);
   6735 
   6736   /* Now we copy all the symbols which have been defined since the BCOMM.  */
   6737 
   6738   /* Copy all the struct pendings before common_block.  */
   6739   for (next = *get_local_symbols ();
   6740        next != NULL && next != common_block;
   6741        next = next->next)
   6742     {
   6743       for (j = 0; j < next->nsyms; j++)
   6744 	add_symbol_to_list (next->symbol[j], &newobj);
   6745     }
   6746 
   6747   /* Copy however much of COMMON_BLOCK we need.  If COMMON_BLOCK is
   6748      NULL, it means copy all the local symbols (which we already did
   6749      above).  */
   6750 
   6751   if (common_block != NULL)
   6752     for (j = common_block_i; j < common_block->nsyms; j++)
   6753       add_symbol_to_list (common_block->symbol[j], &newobj);
   6754 
   6755   sym->set_type ((struct type *) newobj);
   6756 
   6757   /* Should we be putting local_symbols back to what it was?
   6758      Does it matter?  */
   6759 
   6760   i = hashname (sym->linkage_name ());
   6761   sym->set_value_chain (global_sym_chain[i]);
   6762   global_sym_chain[i] = sym;
   6763   common_block_name = NULL;
   6764 }
   6765 
   6766 /* Add a common block's start address to the offset of each symbol
   6767    declared to be in it (by being between a BCOMM/ECOMM pair that uses
   6768    the common block name).  */
   6769 
   6770 static void
   6771 fix_common_block (struct symbol *sym, CORE_ADDR valu, int section_index)
   6772 {
   6773   struct pending *next = (struct pending *) sym->type ();
   6774 
   6775   for (; next; next = next->next)
   6776     {
   6777       int j;
   6778 
   6779       for (j = next->nsyms - 1; j >= 0; j--)
   6780 	{
   6781 	  next->symbol[j]->set_value_address
   6782 	    (next->symbol[j]->value_address () + valu);
   6783 	  next->symbol[j]->set_section_index (section_index);
   6784 	}
   6785     }
   6786 }
   6787 
   6788 
   6790 
   6791 /* Add {TYPE, TYPENUMS} to the NONAME_UNDEFS vector.
   6792    See add_undefined_type for more details.  */
   6793 
   6794 static void
   6795 add_undefined_type_noname (struct type *type, int typenums[2])
   6796 {
   6797   struct nat nat;
   6798 
   6799   nat.typenums[0] = typenums [0];
   6800   nat.typenums[1] = typenums [1];
   6801   nat.type = type;
   6802 
   6803   if (noname_undefs_length == noname_undefs_allocated)
   6804     {
   6805       noname_undefs_allocated *= 2;
   6806       noname_undefs = (struct nat *)
   6807 	xrealloc ((char *) noname_undefs,
   6808 		  noname_undefs_allocated * sizeof (struct nat));
   6809     }
   6810   noname_undefs[noname_undefs_length++] = nat;
   6811 }
   6812 
   6813 /* Add TYPE to the UNDEF_TYPES vector.
   6814    See add_undefined_type for more details.  */
   6815 
   6816 static void
   6817 add_undefined_type_1 (struct type *type)
   6818 {
   6819   if (undef_types_length == undef_types_allocated)
   6820     {
   6821       undef_types_allocated *= 2;
   6822       undef_types = (struct type **)
   6823 	xrealloc ((char *) undef_types,
   6824 		  undef_types_allocated * sizeof (struct type *));
   6825     }
   6826   undef_types[undef_types_length++] = type;
   6827 }
   6828 
   6829 /* What about types defined as forward references inside of a small lexical
   6830    scope?  */
   6831 /* Add a type to the list of undefined types to be checked through
   6832    once this file has been read in.
   6833 
   6834    In practice, we actually maintain two such lists: The first list
   6835    (UNDEF_TYPES) is used for types whose name has been provided, and
   6836    concerns forward references (eg 'xs' or 'xu' forward references);
   6837    the second list (NONAME_UNDEFS) is used for types whose name is
   6838    unknown at creation time, because they were referenced through
   6839    their type number before the actual type was declared.
   6840    This function actually adds the given type to the proper list.  */
   6841 
   6842 static void
   6843 add_undefined_type (struct type *type, int typenums[2])
   6844 {
   6845   if (type->name () == NULL)
   6846     add_undefined_type_noname (type, typenums);
   6847   else
   6848     add_undefined_type_1 (type);
   6849 }
   6850 
   6851 /* Try to fix all undefined types pushed on the UNDEF_TYPES vector.  */
   6852 
   6853 static void
   6854 cleanup_undefined_types_noname (struct objfile *objfile)
   6855 {
   6856   int i;
   6857 
   6858   for (i = 0; i < noname_undefs_length; i++)
   6859     {
   6860       struct nat nat = noname_undefs[i];
   6861       struct type **type;
   6862 
   6863       type = dbx_lookup_type (nat.typenums, objfile);
   6864       if (nat.type != *type && (*type)->code () != TYPE_CODE_UNDEF)
   6865 	{
   6866 	  /* The instance flags of the undefined type are still unset,
   6867 	     and needs to be copied over from the reference type.
   6868 	     Since replace_type expects them to be identical, we need
   6869 	     to set these flags manually before hand.  */
   6870 	  nat.type->set_instance_flags ((*type)->instance_flags ());
   6871 	  replace_type (nat.type, *type);
   6872 	}
   6873     }
   6874 
   6875   noname_undefs_length = 0;
   6876 }
   6877 
   6878 /* Go through each undefined type, see if it's still undefined, and fix it
   6879    up if possible.  We have two kinds of undefined types:
   6880 
   6881    TYPE_CODE_ARRAY:  Array whose target type wasn't defined yet.
   6882    Fix:  update array length using the element bounds
   6883    and the target type's length.
   6884    TYPE_CODE_STRUCT, TYPE_CODE_UNION:  Structure whose fields were not
   6885    yet defined at the time a pointer to it was made.
   6886    Fix:  Do a full lookup on the struct/union tag.  */
   6887 
   6888 static void
   6889 cleanup_undefined_types_1 (void)
   6890 {
   6891   struct type **type;
   6892 
   6893   /* Iterate over every undefined type, and look for a symbol whose type
   6894      matches our undefined type.  The symbol matches if:
   6895        1. It is a typedef in the STRUCT domain;
   6896        2. It has the same name, and same type code;
   6897        3. The instance flags are identical.
   6898 
   6899      It is important to check the instance flags, because we have seen
   6900      examples where the debug info contained definitions such as:
   6901 
   6902 	 "foo_t:t30=B31=xefoo_t:"
   6903 
   6904      In this case, we have created an undefined type named "foo_t" whose
   6905      instance flags is null (when processing "xefoo_t"), and then created
   6906      another type with the same name, but with different instance flags
   6907      ('B' means volatile).  I think that the definition above is wrong,
   6908      since the same type cannot be volatile and non-volatile at the same
   6909      time, but we need to be able to cope with it when it happens.  The
   6910      approach taken here is to treat these two types as different.  */
   6911 
   6912   for (type = undef_types; type < undef_types + undef_types_length; type++)
   6913     {
   6914       switch ((*type)->code ())
   6915 	{
   6916 
   6917 	case TYPE_CODE_STRUCT:
   6918 	case TYPE_CODE_UNION:
   6919 	case TYPE_CODE_ENUM:
   6920 	  {
   6921 	    /* Check if it has been defined since.  Need to do this here
   6922 	       as well as in check_typedef to deal with the (legitimate in
   6923 	       C though not C++) case of several types with the same name
   6924 	       in different source files.  */
   6925 	    if ((*type)->is_stub ())
   6926 	      {
   6927 		struct pending *ppt;
   6928 		int i;
   6929 		/* Name of the type, without "struct" or "union".  */
   6930 		const char *type_name = (*type)->name ();
   6931 
   6932 		if (type_name == NULL)
   6933 		  {
   6934 		    complaint (_("need a type name"));
   6935 		    break;
   6936 		  }
   6937 		for (ppt = *get_file_symbols (); ppt; ppt = ppt->next)
   6938 		  {
   6939 		    for (i = 0; i < ppt->nsyms; i++)
   6940 		      {
   6941 			struct symbol *sym = ppt->symbol[i];
   6942 
   6943 			if (sym->aclass () == LOC_TYPEDEF
   6944 			    && sym->domain () == STRUCT_DOMAIN
   6945 			    && (sym->type ()->code () == (*type)->code ())
   6946 			    && ((*type)->instance_flags ()
   6947 				== sym->type ()->instance_flags ())
   6948 			    && strcmp (sym->linkage_name (), type_name) == 0)
   6949 			  replace_type (*type, sym->type ());
   6950 		      }
   6951 		  }
   6952 	      }
   6953 	  }
   6954 	  break;
   6955 
   6956 	default:
   6957 	  {
   6958 	    complaint (_("forward-referenced types left unresolved, "
   6959 		       "type code %d."),
   6960 		       (*type)->code ());
   6961 	  }
   6962 	  break;
   6963 	}
   6964     }
   6965 
   6966   undef_types_length = 0;
   6967 }
   6968 
   6969 /* Try to fix all the undefined types we encountered while processing
   6970    this unit.  */
   6971 
   6972 void
   6973 cleanup_undefined_stabs_types (struct objfile *objfile)
   6974 {
   6975   cleanup_undefined_types_1 ();
   6976   cleanup_undefined_types_noname (objfile);
   6977 }
   6978 
   6979 /* See stabsread.h.  */
   6980 
   6981 void
   6982 scan_file_globals (struct objfile *objfile)
   6983 {
   6984   int hash;
   6985   struct symbol *sym, *prev;
   6986   struct objfile *resolve_objfile;
   6987 
   6988   /* SVR4 based linkers copy referenced global symbols from shared
   6989      libraries to the main executable.
   6990      If we are scanning the symbols for a shared library, try to resolve
   6991      them from the minimal symbols of the main executable first.  */
   6992 
   6993   if (current_program_space->symfile_object_file
   6994       && objfile != current_program_space->symfile_object_file)
   6995     resolve_objfile = current_program_space->symfile_object_file;
   6996   else
   6997     resolve_objfile = objfile;
   6998 
   6999   while (1)
   7000     {
   7001       /* Avoid expensive loop through all minimal symbols if there are
   7002 	 no unresolved symbols.  */
   7003       for (hash = 0; hash < HASHSIZE; hash++)
   7004 	{
   7005 	  if (global_sym_chain[hash])
   7006 	    break;
   7007 	}
   7008       if (hash >= HASHSIZE)
   7009 	return;
   7010 
   7011       for (minimal_symbol *msymbol : resolve_objfile->msymbols ())
   7012 	{
   7013 	  QUIT;
   7014 
   7015 	  /* Skip static symbols.  */
   7016 	  switch (msymbol->type ())
   7017 	    {
   7018 	    case mst_file_text:
   7019 	    case mst_file_data:
   7020 	    case mst_file_bss:
   7021 	      continue;
   7022 	    default:
   7023 	      break;
   7024 	    }
   7025 
   7026 	  prev = NULL;
   7027 
   7028 	  /* Get the hash index and check all the symbols
   7029 	     under that hash index.  */
   7030 
   7031 	  hash = hashname (msymbol->linkage_name ());
   7032 
   7033 	  for (sym = global_sym_chain[hash]; sym;)
   7034 	    {
   7035 	      if (strcmp (msymbol->linkage_name (), sym->linkage_name ()) == 0)
   7036 		{
   7037 		  /* Splice this symbol out of the hash chain and
   7038 		     assign the value we have to it.  */
   7039 		  if (prev)
   7040 		    {
   7041 		      prev->set_value_chain (sym->value_chain ());
   7042 		    }
   7043 		  else
   7044 		    {
   7045 		      global_sym_chain[hash] = sym->value_chain ();
   7046 		    }
   7047 
   7048 		  /* Check to see whether we need to fix up a common block.  */
   7049 		  /* Note: this code might be executed several times for
   7050 		     the same symbol if there are multiple references.  */
   7051 		  if (sym)
   7052 		    {
   7053 		      if (sym->aclass () == LOC_BLOCK)
   7054 			fix_common_block
   7055 			  (sym, msymbol->value_address (resolve_objfile),
   7056 			   msymbol->section_index ());
   7057 		      else
   7058 			sym->set_value_address
   7059 			  (msymbol->value_address (resolve_objfile));
   7060 		      sym->set_section_index (msymbol->section_index ());
   7061 		    }
   7062 
   7063 		  if (prev)
   7064 		    {
   7065 		      sym = prev->value_chain ();
   7066 		    }
   7067 		  else
   7068 		    {
   7069 		      sym = global_sym_chain[hash];
   7070 		    }
   7071 		}
   7072 	      else
   7073 		{
   7074 		  prev = sym;
   7075 		  sym = sym->value_chain ();
   7076 		}
   7077 	    }
   7078 	}
   7079       if (resolve_objfile == objfile)
   7080 	break;
   7081       resolve_objfile = objfile;
   7082     }
   7083 
   7084   /* Change the storage class of any remaining unresolved globals to
   7085      LOC_UNRESOLVED and remove them from the chain.  */
   7086   for (hash = 0; hash < HASHSIZE; hash++)
   7087     {
   7088       sym = global_sym_chain[hash];
   7089       while (sym)
   7090 	{
   7091 	  prev = sym;
   7092 	  sym = sym->value_chain ();
   7093 
   7094 	  /* Change the symbol address from the misleading chain value
   7095 	     to address zero.  */
   7096 	  prev->set_value_address (0);
   7097 
   7098 	  /* Complain about unresolved common block symbols.  */
   7099 	  if (prev->aclass () == LOC_STATIC)
   7100 	    prev->set_aclass_index (LOC_UNRESOLVED);
   7101 	  else
   7102 	    complaint (_("%s: common block `%s' from "
   7103 			 "global_sym_chain unresolved"),
   7104 		       objfile_name (objfile), prev->print_name ());
   7105 	}
   7106     }
   7107   memset (global_sym_chain, 0, sizeof (global_sym_chain));
   7108 }
   7109 
   7110 /* Initialize anything that needs initializing when starting to read
   7111    a fresh piece of a symbol file, e.g. reading in the stuff corresponding
   7112    to a psymtab.  */
   7113 
   7114 void
   7115 stabsread_init (void)
   7116 {
   7117 }
   7118 
   7119 /* Initialize anything that needs initializing when a completely new
   7120    symbol file is specified (not just adding some symbols from another
   7121    file, e.g. a shared library).  */
   7122 
   7123 void
   7124 stabsread_new_init (void)
   7125 {
   7126   /* Empty the hash table of global syms looking for values.  */
   7127   memset (global_sym_chain, 0, sizeof (global_sym_chain));
   7128 }
   7129 
   7130 /* Initialize anything that needs initializing at the same time as
   7131    start_compunit_symtab() is called.  */
   7132 
   7133 void
   7134 start_stabs (void)
   7135 {
   7136   global_stabs = NULL;		/* AIX COFF */
   7137   /* Leave FILENUM of 0 free for builtin types and this file's types.  */
   7138   n_this_object_header_files = 1;
   7139   type_vector_length = 0;
   7140   type_vector = (struct type **) 0;
   7141   within_function = 0;
   7142 
   7143   /* FIXME: If common_block_name is not already NULL, we should complain().  */
   7144   common_block_name = NULL;
   7145 }
   7146 
   7147 /* Call after end_compunit_symtab().  */
   7148 
   7149 void
   7150 end_stabs (void)
   7151 {
   7152   if (type_vector)
   7153     {
   7154       xfree (type_vector);
   7155     }
   7156   type_vector = 0;
   7157   type_vector_length = 0;
   7158   previous_stab_code = 0;
   7159 }
   7160 
   7161 void
   7162 finish_global_stabs (struct objfile *objfile)
   7163 {
   7164   if (global_stabs)
   7165     {
   7166       patch_block_stabs (*get_global_symbols (), global_stabs, objfile);
   7167       xfree (global_stabs);
   7168       global_stabs = NULL;
   7169     }
   7170 }
   7171 
   7172 /* Find the end of the name, delimited by a ':', but don't match
   7173    ObjC symbols which look like -[Foo bar::]:bla.  */
   7174 static const char *
   7175 find_name_end (const char *name)
   7176 {
   7177   const char *s = name;
   7178 
   7179   if (s[0] == '-' || *s == '+')
   7180     {
   7181       /* Must be an ObjC method symbol.  */
   7182       if (s[1] != '[')
   7183 	{
   7184 	  error (_("invalid symbol name \"%s\""), name);
   7185 	}
   7186       s = strchr (s, ']');
   7187       if (s == NULL)
   7188 	{
   7189 	  error (_("invalid symbol name \"%s\""), name);
   7190 	}
   7191       return strchr (s, ':');
   7192     }
   7193   else
   7194     {
   7195       return strchr (s, ':');
   7196     }
   7197 }
   7198 
   7199 /* See stabsread.h.  */
   7200 
   7201 int
   7202 hashname (const char *name)
   7203 {
   7204   return fast_hash (name, strlen (name)) % HASHSIZE;
   7205 }
   7206 
   7207 /* Initializer for this module.  */
   7208 
   7209 void _initialize_stabsread ();
   7210 void
   7211 _initialize_stabsread ()
   7212 {
   7213   undef_types_allocated = 20;
   7214   undef_types_length = 0;
   7215   undef_types = XNEWVEC (struct type *, undef_types_allocated);
   7216 
   7217   noname_undefs_allocated = 20;
   7218   noname_undefs_length = 0;
   7219   noname_undefs = XNEWVEC (struct nat, noname_undefs_allocated);
   7220 
   7221   stab_register_index = register_symbol_register_impl (LOC_REGISTER,
   7222 						       &stab_register_funcs);
   7223   stab_regparm_index = register_symbol_register_impl (LOC_REGPARM_ADDR,
   7224 						      &stab_register_funcs);
   7225 }
   7226