Home | History | Annotate | Line # | Download | only in gdb
stabsread.c revision 1.8
      1 /* Support routines for decoding "stabs" debugging information format.
      2 
      3    Copyright (C) 1986-2019 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 "defs.h"
     28 #include "bfd.h"
     29 #include "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"	/* We always use GNU stabs, not native.  */
     36 #include "libaout.h"
     37 #include "aout/aout64.h"
     38 #include "gdb-stabs.h"
     39 #include "buildsym-legacy.h"
     40 #include "complaints.h"
     41 #include "demangle.h"
     42 #include "gdb-demangle.h"
     43 #include "language.h"
     44 #include "target-float.h"
     45 #include "cp-abi.h"
     46 #include "cp-support.h"
     47 #include "bcache.h"
     48 #include <ctype.h>
     49 
     50 #include "stabsread.h"
     51 
     52 /* See stabsread.h for these globals.  */
     53 unsigned int symnum;
     54 const char *(*next_symbol_text_func) (struct objfile *);
     55 unsigned char processing_gcc_compilation;
     56 int within_function;
     57 struct symbol *global_sym_chain[HASHSIZE];
     58 struct pending_stabs *global_stabs;
     59 int previous_stab_code;
     60 int *this_object_header_files;
     61 int n_this_object_header_files;
     62 int n_allocated_this_object_header_files;
     63 
     64 struct nextfield
     65 {
     66   struct nextfield *next;
     67 
     68   /* This is the raw visibility from the stab.  It is not checked
     69      for being one of the visibilities we recognize, so code which
     70      examines this field better be able to deal.  */
     71   int visibility;
     72 
     73   struct field field;
     74 };
     75 
     76 struct next_fnfieldlist
     77 {
     78   struct next_fnfieldlist *next;
     79   struct fn_fieldlist fn_fieldlist;
     80 };
     81 
     82 /* The routines that read and process a complete stabs for a C struct or
     83    C++ class pass lists of data member fields and lists of member function
     84    fields in an instance of a field_info structure, as defined below.
     85    This is part of some reorganization of low level C++ support and is
     86    expected to eventually go away...  (FIXME) */
     87 
     88 struct field_info
     89   {
     90     struct nextfield *list;
     91     struct next_fnfieldlist *fnlist;
     92   };
     93 
     94 static void
     95 read_one_struct_field (struct field_info *, const char **, const char *,
     96 		       struct type *, struct objfile *);
     97 
     98 static struct type *dbx_alloc_type (int[2], struct objfile *);
     99 
    100 static long read_huge_number (const char **, int, int *, int);
    101 
    102 static struct type *error_type (const char **, struct objfile *);
    103 
    104 static void
    105 patch_block_stabs (struct pending *, struct pending_stabs *,
    106 		   struct objfile *);
    107 
    108 static void fix_common_block (struct symbol *, CORE_ADDR);
    109 
    110 static int read_type_number (const char **, int *);
    111 
    112 static struct type *read_type (const char **, struct objfile *);
    113 
    114 static struct type *read_range_type (const char **, int[2],
    115 				     int, struct objfile *);
    116 
    117 static struct type *read_sun_builtin_type (const char **,
    118 					   int[2], struct objfile *);
    119 
    120 static struct type *read_sun_floating_type (const char **, int[2],
    121 					    struct objfile *);
    122 
    123 static struct type *read_enum_type (const char **, struct type *, struct objfile *);
    124 
    125 static struct type *rs6000_builtin_type (int, struct objfile *);
    126 
    127 static int
    128 read_member_functions (struct field_info *, const char **, struct type *,
    129 		       struct objfile *);
    130 
    131 static int
    132 read_struct_fields (struct field_info *, const char **, struct type *,
    133 		    struct objfile *);
    134 
    135 static int
    136 read_baseclasses (struct field_info *, const char **, struct type *,
    137 		  struct objfile *);
    138 
    139 static int
    140 read_tilde_fields (struct field_info *, const char **, struct type *,
    141 		   struct objfile *);
    142 
    143 static int attach_fn_fields_to_type (struct field_info *, struct type *);
    144 
    145 static int attach_fields_to_type (struct field_info *, struct type *,
    146 				  struct objfile *);
    147 
    148 static struct type *read_struct_type (const char **, struct type *,
    149                                       enum type_code,
    150 				      struct objfile *);
    151 
    152 static struct type *read_array_type (const char **, struct type *,
    153 				     struct objfile *);
    154 
    155 static struct field *read_args (const char **, int, struct objfile *,
    156 				int *, int *);
    157 
    158 static void add_undefined_type (struct type *, int[2]);
    159 
    160 static int
    161 read_cpp_abbrev (struct field_info *, const char **, struct type *,
    162 		 struct objfile *);
    163 
    164 static const char *find_name_end (const char *name);
    165 
    166 static int process_reference (const char **string);
    167 
    168 void stabsread_clear_cache (void);
    169 
    170 static const char vptr_name[] = "_vptr$";
    171 static const char vb_name[] = "_vb$";
    172 
    173 static void
    174 invalid_cpp_abbrev_complaint (const char *arg1)
    175 {
    176   complaint (_("invalid C++ abbreviation `%s'"), arg1);
    177 }
    178 
    179 static void
    180 reg_value_complaint (int regnum, int num_regs, const char *sym)
    181 {
    182   complaint (_("bad register number %d (max %d) in symbol %s"),
    183              regnum, num_regs - 1, sym);
    184 }
    185 
    186 static void
    187 stabs_general_complaint (const char *arg1)
    188 {
    189   complaint ("%s", arg1);
    190 }
    191 
    192 /* Make a list of forward references which haven't been defined.  */
    193 
    194 static struct type **undef_types;
    195 static int undef_types_allocated;
    196 static int undef_types_length;
    197 static struct symbol *current_symbol = NULL;
    198 
    199 /* Make a list of nameless types that are undefined.
    200    This happens when another type is referenced by its number
    201    before this type is actually defined.  For instance "t(0,1)=k(0,2)"
    202    and type (0,2) is defined only later.  */
    203 
    204 struct nat
    205 {
    206   int typenums[2];
    207   struct type *type;
    208 };
    209 static struct nat *noname_undefs;
    210 static int noname_undefs_allocated;
    211 static int noname_undefs_length;
    212 
    213 /* Check for and handle cretinous stabs symbol name continuation!  */
    214 #define STABS_CONTINUE(pp,objfile)				\
    215   do {							\
    216     if (**(pp) == '\\' || (**(pp) == '?' && (*(pp))[1] == '\0')) \
    217       *(pp) = next_symbol_text (objfile);	\
    218   } while (0)
    219 
    220 /* Vector of types defined so far, indexed by their type numbers.
    221    (In newer sun systems, dbx uses a pair of numbers in parens,
    222    as in "(SUBFILENUM,NUMWITHINSUBFILE)".
    223    Then these numbers must be translated through the type_translations
    224    hash table to get the index into the type vector.)  */
    225 
    226 static struct type **type_vector;
    227 
    228 /* Number of elements allocated for type_vector currently.  */
    229 
    230 static int type_vector_length;
    231 
    232 /* Initial size of type vector.  Is realloc'd larger if needed, and
    233    realloc'd down to the size actually used, when completed.  */
    234 
    235 #define INITIAL_TYPE_VECTOR_LENGTH 160
    236 
    237 
    239 /* Look up a dbx type-number pair.  Return the address of the slot
    240    where the type for that number-pair is stored.
    241    The number-pair is in TYPENUMS.
    242 
    243    This can be used for finding the type associated with that pair
    244    or for associating a new type with the pair.  */
    245 
    246 static struct type **
    247 dbx_lookup_type (int typenums[2], struct objfile *objfile)
    248 {
    249   int filenum = typenums[0];
    250   int index = typenums[1];
    251   unsigned old_len;
    252   int real_filenum;
    253   struct header_file *f;
    254   int f_orig_length;
    255 
    256   if (filenum == -1)		/* -1,-1 is for temporary types.  */
    257     return 0;
    258 
    259   if (filenum < 0 || filenum >= n_this_object_header_files)
    260     {
    261       complaint (_("Invalid symbol data: type number "
    262 		   "(%d,%d) out of range at symtab pos %d."),
    263 		 filenum, index, symnum);
    264       goto error_return;
    265     }
    266 
    267   if (filenum == 0)
    268     {
    269       if (index < 0)
    270 	{
    271 	  /* Caller wants address of address of type.  We think
    272 	     that negative (rs6k builtin) types will never appear as
    273 	     "lvalues", (nor should they), so we stuff the real type
    274 	     pointer into a temp, and return its address.  If referenced,
    275 	     this will do the right thing.  */
    276 	  static struct type *temp_type;
    277 
    278 	  temp_type = rs6000_builtin_type (index, objfile);
    279 	  return &temp_type;
    280 	}
    281 
    282       /* Type is defined outside of header files.
    283          Find it in this object file's type vector.  */
    284       if (index >= type_vector_length)
    285 	{
    286 	  old_len = type_vector_length;
    287 	  if (old_len == 0)
    288 	    {
    289 	      type_vector_length = INITIAL_TYPE_VECTOR_LENGTH;
    290 	      type_vector = XNEWVEC (struct type *, type_vector_length);
    291 	    }
    292 	  while (index >= type_vector_length)
    293 	    {
    294 	      type_vector_length *= 2;
    295 	    }
    296 	  type_vector = (struct type **)
    297 	    xrealloc ((char *) type_vector,
    298 		      (type_vector_length * sizeof (struct type *)));
    299 	  memset (&type_vector[old_len], 0,
    300 		  (type_vector_length - old_len) * sizeof (struct type *));
    301 	}
    302       return (&type_vector[index]);
    303     }
    304   else
    305     {
    306       real_filenum = this_object_header_files[filenum];
    307 
    308       if (real_filenum >= N_HEADER_FILES (objfile))
    309 	{
    310 	  static struct type *temp_type;
    311 
    312 	  warning (_("GDB internal error: bad real_filenum"));
    313 
    314 	error_return:
    315 	  temp_type = objfile_type (objfile)->builtin_error;
    316 	  return &temp_type;
    317 	}
    318 
    319       f = HEADER_FILES (objfile) + real_filenum;
    320 
    321       f_orig_length = f->length;
    322       if (index >= f_orig_length)
    323 	{
    324 	  while (index >= f->length)
    325 	    {
    326 	      f->length *= 2;
    327 	    }
    328 	  f->vector = (struct type **)
    329 	    xrealloc ((char *) f->vector, f->length * sizeof (struct type *));
    330 	  memset (&f->vector[f_orig_length], 0,
    331 		  (f->length - f_orig_length) * sizeof (struct type *));
    332 	}
    333       return (&f->vector[index]);
    334     }
    335 }
    336 
    337 /* Make sure there is a type allocated for type numbers TYPENUMS
    338    and return the type object.
    339    This can create an empty (zeroed) type object.
    340    TYPENUMS may be (-1, -1) to return a new type object that is not
    341    put into the type vector, and so may not be referred to by number.  */
    342 
    343 static struct type *
    344 dbx_alloc_type (int typenums[2], struct objfile *objfile)
    345 {
    346   struct type **type_addr;
    347 
    348   if (typenums[0] == -1)
    349     {
    350       return (alloc_type (objfile));
    351     }
    352 
    353   type_addr = dbx_lookup_type (typenums, objfile);
    354 
    355   /* If we are referring to a type not known at all yet,
    356      allocate an empty type for it.
    357      We will fill it in later if we find out how.  */
    358   if (*type_addr == 0)
    359     {
    360       *type_addr = alloc_type (objfile);
    361     }
    362 
    363   return (*type_addr);
    364 }
    365 
    366 /* Allocate a floating-point type of size BITS.  */
    367 
    368 static struct type *
    369 dbx_init_float_type (struct objfile *objfile, int bits)
    370 {
    371   struct gdbarch *gdbarch = get_objfile_arch (objfile);
    372   const struct floatformat **format;
    373   struct type *type;
    374 
    375   format = gdbarch_floatformat_for_type (gdbarch, NULL, bits);
    376   if (format)
    377     type = init_float_type (objfile, bits, NULL, format);
    378   else
    379     type = init_type (objfile, TYPE_CODE_ERROR, bits, NULL);
    380 
    381   return type;
    382 }
    383 
    384 /* for all the stabs in a given stab vector, build appropriate types
    385    and fix their symbols in given symbol vector.  */
    386 
    387 static void
    388 patch_block_stabs (struct pending *symbols, struct pending_stabs *stabs,
    389 		   struct objfile *objfile)
    390 {
    391   int ii;
    392   char *name;
    393   const char *pp;
    394   struct symbol *sym;
    395 
    396   if (stabs)
    397     {
    398       /* for all the stab entries, find their corresponding symbols and
    399          patch their types!  */
    400 
    401       for (ii = 0; ii < stabs->count; ++ii)
    402 	{
    403 	  name = stabs->stab[ii];
    404 	  pp = (char *) strchr (name, ':');
    405 	  gdb_assert (pp);	/* Must find a ':' or game's over.  */
    406 	  while (pp[1] == ':')
    407 	    {
    408 	      pp += 2;
    409 	      pp = (char *) strchr (pp, ':');
    410 	    }
    411 	  sym = find_symbol_in_list (symbols, name, pp - name);
    412 	  if (!sym)
    413 	    {
    414 	      /* FIXME-maybe: it would be nice if we noticed whether
    415 	         the variable was defined *anywhere*, not just whether
    416 	         it is defined in this compilation unit.  But neither
    417 	         xlc or GCC seem to need such a definition, and until
    418 	         we do psymtabs (so that the minimal symbols from all
    419 	         compilation units are available now), I'm not sure
    420 	         how to get the information.  */
    421 
    422 	      /* On xcoff, if a global is defined and never referenced,
    423 	         ld will remove it from the executable.  There is then
    424 	         a N_GSYM stab for it, but no regular (C_EXT) symbol.  */
    425 	      sym = allocate_symbol (objfile);
    426 	      SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
    427 	      SYMBOL_ACLASS_INDEX (sym) = LOC_OPTIMIZED_OUT;
    428 	      SYMBOL_SET_LINKAGE_NAME
    429 		(sym, (char *) obstack_copy0 (&objfile->objfile_obstack,
    430 					      name, pp - name));
    431 	      pp += 2;
    432 	      if (*(pp - 1) == 'F' || *(pp - 1) == 'f')
    433 		{
    434 		  /* I don't think the linker does this with functions,
    435 		     so as far as I know this is never executed.
    436 		     But it doesn't hurt to check.  */
    437 		  SYMBOL_TYPE (sym) =
    438 		    lookup_function_type (read_type (&pp, objfile));
    439 		}
    440 	      else
    441 		{
    442 		  SYMBOL_TYPE (sym) = read_type (&pp, objfile);
    443 		}
    444 	      add_symbol_to_list (sym, get_global_symbols ());
    445 	    }
    446 	  else
    447 	    {
    448 	      pp += 2;
    449 	      if (*(pp - 1) == 'F' || *(pp - 1) == 'f')
    450 		{
    451 		  SYMBOL_TYPE (sym) =
    452 		    lookup_function_type (read_type (&pp, objfile));
    453 		}
    454 	      else
    455 		{
    456 		  SYMBOL_TYPE (sym) = read_type (&pp, objfile);
    457 		}
    458 	    }
    459 	}
    460     }
    461 }
    462 
    463 
    465 /* Read a number by which a type is referred to in dbx data,
    466    or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
    467    Just a single number N is equivalent to (0,N).
    468    Return the two numbers by storing them in the vector TYPENUMS.
    469    TYPENUMS will then be used as an argument to dbx_lookup_type.
    470 
    471    Returns 0 for success, -1 for error.  */
    472 
    473 static int
    474 read_type_number (const char **pp, int *typenums)
    475 {
    476   int nbits;
    477 
    478   if (**pp == '(')
    479     {
    480       (*pp)++;
    481       typenums[0] = read_huge_number (pp, ',', &nbits, 0);
    482       if (nbits != 0)
    483 	return -1;
    484       typenums[1] = read_huge_number (pp, ')', &nbits, 0);
    485       if (nbits != 0)
    486 	return -1;
    487     }
    488   else
    489     {
    490       typenums[0] = 0;
    491       typenums[1] = read_huge_number (pp, 0, &nbits, 0);
    492       if (nbits != 0)
    493 	return -1;
    494     }
    495   return 0;
    496 }
    497 
    498 
    500 #define VISIBILITY_PRIVATE	'0'	/* Stabs character for private field */
    501 #define VISIBILITY_PROTECTED	'1'	/* Stabs character for protected fld */
    502 #define VISIBILITY_PUBLIC	'2'	/* Stabs character for public field */
    503 #define VISIBILITY_IGNORE	'9'	/* Optimized out or zero length */
    504 
    505 /* Structure for storing pointers to reference definitions for fast lookup
    506    during "process_later".  */
    507 
    508 struct ref_map
    509 {
    510   const char *stabs;
    511   CORE_ADDR value;
    512   struct symbol *sym;
    513 };
    514 
    515 #define MAX_CHUNK_REFS 100
    516 #define REF_CHUNK_SIZE (MAX_CHUNK_REFS * sizeof (struct ref_map))
    517 #define REF_MAP_SIZE(ref_chunk) ((ref_chunk) * REF_CHUNK_SIZE)
    518 
    519 static struct ref_map *ref_map;
    520 
    521 /* Ptr to free cell in chunk's linked list.  */
    522 static int ref_count = 0;
    523 
    524 /* Number of chunks malloced.  */
    525 static int ref_chunk = 0;
    526 
    527 /* This file maintains a cache of stabs aliases found in the symbol
    528    table.  If the symbol table changes, this cache must be cleared
    529    or we are left holding onto data in invalid obstacks.  */
    530 void
    531 stabsread_clear_cache (void)
    532 {
    533   ref_count = 0;
    534   ref_chunk = 0;
    535 }
    536 
    537 /* Create array of pointers mapping refids to symbols and stab strings.
    538    Add pointers to reference definition symbols and/or their values as we
    539    find them, using their reference numbers as our index.
    540    These will be used later when we resolve references.  */
    541 void
    542 ref_add (int refnum, struct symbol *sym, const char *stabs, CORE_ADDR value)
    543 {
    544   if (ref_count == 0)
    545     ref_chunk = 0;
    546   if (refnum >= ref_count)
    547     ref_count = refnum + 1;
    548   if (ref_count > ref_chunk * MAX_CHUNK_REFS)
    549     {
    550       int new_slots = ref_count - ref_chunk * MAX_CHUNK_REFS;
    551       int new_chunks = new_slots / MAX_CHUNK_REFS + 1;
    552 
    553       ref_map = (struct ref_map *)
    554 	xrealloc (ref_map, REF_MAP_SIZE (ref_chunk + new_chunks));
    555       memset (ref_map + ref_chunk * MAX_CHUNK_REFS, 0,
    556 	      new_chunks * REF_CHUNK_SIZE);
    557       ref_chunk += new_chunks;
    558     }
    559   ref_map[refnum].stabs = stabs;
    560   ref_map[refnum].sym = sym;
    561   ref_map[refnum].value = value;
    562 }
    563 
    564 /* Return defined sym for the reference REFNUM.  */
    565 struct symbol *
    566 ref_search (int refnum)
    567 {
    568   if (refnum < 0 || refnum > ref_count)
    569     return 0;
    570   return ref_map[refnum].sym;
    571 }
    572 
    573 /* Parse a reference id in STRING and return the resulting
    574    reference number.  Move STRING beyond the reference id.  */
    575 
    576 static int
    577 process_reference (const char **string)
    578 {
    579   const char *p;
    580   int refnum = 0;
    581 
    582   if (**string != '#')
    583     return 0;
    584 
    585   /* Advance beyond the initial '#'.  */
    586   p = *string + 1;
    587 
    588   /* Read number as reference id.  */
    589   while (*p && isdigit (*p))
    590     {
    591       refnum = refnum * 10 + *p - '0';
    592       p++;
    593     }
    594   *string = p;
    595   return refnum;
    596 }
    597 
    598 /* If STRING defines a reference, store away a pointer to the reference
    599    definition for later use.  Return the reference number.  */
    600 
    601 int
    602 symbol_reference_defined (const char **string)
    603 {
    604   const char *p = *string;
    605   int refnum = 0;
    606 
    607   refnum = process_reference (&p);
    608 
    609   /* Defining symbols end in '='.  */
    610   if (*p == '=')
    611     {
    612       /* Symbol is being defined here.  */
    613       *string = p + 1;
    614       return refnum;
    615     }
    616   else
    617     {
    618       /* Must be a reference.  Either the symbol has already been defined,
    619          or this is a forward reference to it.  */
    620       *string = p;
    621       return -1;
    622     }
    623 }
    624 
    625 static int
    626 stab_reg_to_regnum (struct symbol *sym, struct gdbarch *gdbarch)
    627 {
    628   int regno = gdbarch_stab_reg_to_regnum (gdbarch, SYMBOL_VALUE (sym));
    629 
    630   if (regno < 0 || regno >= gdbarch_num_cooked_regs (gdbarch))
    631     {
    632       reg_value_complaint (regno, gdbarch_num_cooked_regs (gdbarch),
    633 			   SYMBOL_PRINT_NAME (sym));
    634 
    635       regno = gdbarch_sp_regnum (gdbarch); /* Known safe, though useless.  */
    636     }
    637 
    638   return regno;
    639 }
    640 
    641 static const struct symbol_register_ops stab_register_funcs = {
    642   stab_reg_to_regnum
    643 };
    644 
    645 /* The "aclass" indices for computed symbols.  */
    646 
    647 static int stab_register_index;
    648 static int stab_regparm_index;
    649 
    650 struct symbol *
    651 define_symbol (CORE_ADDR valu, const char *string, int desc, int type,
    652 	       struct objfile *objfile)
    653 {
    654   struct gdbarch *gdbarch = get_objfile_arch (objfile);
    655   struct symbol *sym;
    656   const char *p = find_name_end (string);
    657   int deftype;
    658   int synonym = 0;
    659   int i;
    660 
    661   /* We would like to eliminate nameless symbols, but keep their types.
    662      E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer
    663      to type 2, but, should not create a symbol to address that type.  Since
    664      the symbol will be nameless, there is no way any user can refer to it.  */
    665 
    666   int nameless;
    667 
    668   /* Ignore syms with empty names.  */
    669   if (string[0] == 0)
    670     return 0;
    671 
    672   /* Ignore old-style symbols from cc -go.  */
    673   if (p == 0)
    674     return 0;
    675 
    676   while (p[1] == ':')
    677     {
    678       p += 2;
    679       p = strchr (p, ':');
    680       if (p == NULL)
    681 	{
    682 	  complaint (
    683 		     _("Bad stabs string '%s'"), string);
    684 	  return NULL;
    685 	}
    686     }
    687 
    688   /* If a nameless stab entry, all we need is the type, not the symbol.
    689      e.g. ":t10=*2" or a nameless enum like " :T16=ered:0,green:1,blue:2,;" */
    690   nameless = (p == string || ((string[0] == ' ') && (string[1] == ':')));
    691 
    692   current_symbol = sym = allocate_symbol (objfile);
    693 
    694   if (processing_gcc_compilation)
    695     {
    696       /* GCC 2.x puts the line number in desc.  SunOS apparently puts in the
    697          number of bytes occupied by a type or object, which we ignore.  */
    698       SYMBOL_LINE (sym) = desc;
    699     }
    700   else
    701     {
    702       SYMBOL_LINE (sym) = 0;	/* unknown */
    703     }
    704 
    705   SYMBOL_SET_LANGUAGE (sym, get_current_subfile ()->language,
    706 		       &objfile->objfile_obstack);
    707 
    708   if (is_cplus_marker (string[0]))
    709     {
    710       /* Special GNU C++ names.  */
    711       switch (string[1])
    712 	{
    713 	case 't':
    714 	  SYMBOL_SET_LINKAGE_NAME (sym, "this");
    715 	  break;
    716 
    717 	case 'v':		/* $vtbl_ptr_type */
    718 	  goto normal;
    719 
    720 	case 'e':
    721 	  SYMBOL_SET_LINKAGE_NAME (sym, "eh_throw");
    722 	  break;
    723 
    724 	case '_':
    725 	  /* This was an anonymous type that was never fixed up.  */
    726 	  goto normal;
    727 
    728 	case 'X':
    729 	  /* SunPRO (3.0 at least) static variable encoding.  */
    730 	  if (gdbarch_static_transform_name_p (gdbarch))
    731 	    goto normal;
    732 	  /* fall through */
    733 
    734 	default:
    735 	  complaint (_("Unknown C++ symbol name `%s'"),
    736 		     string);
    737 	  goto normal;		/* Do *something* with it.  */
    738 	}
    739     }
    740   else
    741     {
    742     normal:
    743       std::string new_name;
    744 
    745       if (SYMBOL_LANGUAGE (sym) == language_cplus)
    746 	{
    747 	  char *name = (char *) alloca (p - string + 1);
    748 
    749 	  memcpy (name, string, p - string);
    750 	  name[p - string] = '\0';
    751 	  new_name = cp_canonicalize_string (name);
    752 	}
    753       if (!new_name.empty ())
    754 	{
    755 	  SYMBOL_SET_NAMES (sym,
    756 			    new_name.c_str (), new_name.length (),
    757 			    1, objfile);
    758 	}
    759       else
    760 	SYMBOL_SET_NAMES (sym, string, p - string, 1, objfile);
    761 
    762       if (SYMBOL_LANGUAGE (sym) == language_cplus)
    763 	cp_scan_for_anonymous_namespaces (get_buildsym_compunit (), sym,
    764 					  objfile);
    765 
    766     }
    767   p++;
    768 
    769   /* Determine the type of name being defined.  */
    770 #if 0
    771   /* Getting GDB to correctly skip the symbol on an undefined symbol
    772      descriptor and not ever dump core is a very dodgy proposition if
    773      we do things this way.  I say the acorn RISC machine can just
    774      fix their compiler.  */
    775   /* The Acorn RISC machine's compiler can put out locals that don't
    776      start with "234=" or "(3,4)=", so assume anything other than the
    777      deftypes we know how to handle is a local.  */
    778   if (!strchr ("cfFGpPrStTvVXCR", *p))
    779 #else
    780   if (isdigit (*p) || *p == '(' || *p == '-')
    781 #endif
    782     deftype = 'l';
    783   else
    784     deftype = *p++;
    785 
    786   switch (deftype)
    787     {
    788     case 'c':
    789       /* c is a special case, not followed by a type-number.
    790          SYMBOL:c=iVALUE for an integer constant symbol.
    791          SYMBOL:c=rVALUE for a floating constant symbol.
    792          SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
    793          e.g. "b:c=e6,0" for "const b = blob1"
    794          (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;").  */
    795       if (*p != '=')
    796 	{
    797 	  SYMBOL_ACLASS_INDEX (sym) = LOC_CONST;
    798 	  SYMBOL_TYPE (sym) = error_type (&p, objfile);
    799 	  SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
    800 	  add_symbol_to_list (sym, get_file_symbols ());
    801 	  return sym;
    802 	}
    803       ++p;
    804       switch (*p++)
    805 	{
    806 	case 'r':
    807 	  {
    808 	    gdb_byte *dbl_valu;
    809 	    struct type *dbl_type;
    810 
    811 	    dbl_type = objfile_type (objfile)->builtin_double;
    812 	    dbl_valu
    813 	      = (gdb_byte *) obstack_alloc (&objfile->objfile_obstack,
    814 					    TYPE_LENGTH (dbl_type));
    815 
    816 	    target_float_from_string (dbl_valu, dbl_type, std::string (p));
    817 
    818 	    SYMBOL_TYPE (sym) = dbl_type;
    819 	    SYMBOL_VALUE_BYTES (sym) = dbl_valu;
    820 	    SYMBOL_ACLASS_INDEX (sym) = LOC_CONST_BYTES;
    821 	  }
    822 	  break;
    823 	case 'i':
    824 	  {
    825 	    /* Defining integer constants this way is kind of silly,
    826 	       since 'e' constants allows the compiler to give not
    827 	       only the value, but the type as well.  C has at least
    828 	       int, long, unsigned int, and long long as constant
    829 	       types; other languages probably should have at least
    830 	       unsigned as well as signed constants.  */
    831 
    832 	    SYMBOL_TYPE (sym) = objfile_type (objfile)->builtin_long;
    833 	    SYMBOL_VALUE (sym) = atoi (p);
    834 	    SYMBOL_ACLASS_INDEX (sym) = LOC_CONST;
    835 	  }
    836 	  break;
    837 
    838 	case 'c':
    839 	  {
    840 	    SYMBOL_TYPE (sym) = objfile_type (objfile)->builtin_char;
    841 	    SYMBOL_VALUE (sym) = atoi (p);
    842 	    SYMBOL_ACLASS_INDEX (sym) = LOC_CONST;
    843 	  }
    844 	  break;
    845 
    846 	case 's':
    847 	  {
    848 	    struct type *range_type;
    849 	    int ind = 0;
    850 	    char quote = *p++;
    851 	    gdb_byte *string_local = (gdb_byte *) alloca (strlen (p));
    852 	    gdb_byte *string_value;
    853 
    854 	    if (quote != '\'' && quote != '"')
    855 	      {
    856 		SYMBOL_ACLASS_INDEX (sym) = LOC_CONST;
    857 		SYMBOL_TYPE (sym) = error_type (&p, objfile);
    858 		SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
    859 		add_symbol_to_list (sym, get_file_symbols ());
    860 		return sym;
    861 	      }
    862 
    863 	    /* Find matching quote, rejecting escaped quotes.  */
    864 	    while (*p && *p != quote)
    865 	      {
    866 		if (*p == '\\' && p[1] == quote)
    867 		  {
    868 		    string_local[ind] = (gdb_byte) quote;
    869 		    ind++;
    870 		    p += 2;
    871 		  }
    872 		else if (*p)
    873 		  {
    874 		    string_local[ind] = (gdb_byte) (*p);
    875 		    ind++;
    876 		    p++;
    877 		  }
    878 	      }
    879 	    if (*p != quote)
    880 	      {
    881 		SYMBOL_ACLASS_INDEX (sym) = LOC_CONST;
    882 		SYMBOL_TYPE (sym) = error_type (&p, objfile);
    883 		SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
    884 		add_symbol_to_list (sym, get_file_symbols ());
    885 		return sym;
    886 	      }
    887 
    888 	    /* NULL terminate the string.  */
    889 	    string_local[ind] = 0;
    890 	    range_type
    891 	      = create_static_range_type (NULL,
    892 					  objfile_type (objfile)->builtin_int,
    893 					  0, ind);
    894 	    SYMBOL_TYPE (sym) = create_array_type (NULL,
    895 				  objfile_type (objfile)->builtin_char,
    896 				  range_type);
    897 	    string_value
    898 	      = (gdb_byte *) obstack_alloc (&objfile->objfile_obstack, ind + 1);
    899 	    memcpy (string_value, string_local, ind + 1);
    900 	    p++;
    901 
    902 	    SYMBOL_VALUE_BYTES (sym) = string_value;
    903 	    SYMBOL_ACLASS_INDEX (sym) = LOC_CONST_BYTES;
    904 	  }
    905 	  break;
    906 
    907 	case 'e':
    908 	  /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
    909 	     can be represented as integral.
    910 	     e.g. "b:c=e6,0" for "const b = blob1"
    911 	     (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;").  */
    912 	  {
    913 	    SYMBOL_ACLASS_INDEX (sym) = LOC_CONST;
    914 	    SYMBOL_TYPE (sym) = read_type (&p, objfile);
    915 
    916 	    if (*p != ',')
    917 	      {
    918 		SYMBOL_TYPE (sym) = error_type (&p, objfile);
    919 		break;
    920 	      }
    921 	    ++p;
    922 
    923 	    /* If the value is too big to fit in an int (perhaps because
    924 	       it is unsigned), or something like that, we silently get
    925 	       a bogus value.  The type and everything else about it is
    926 	       correct.  Ideally, we should be using whatever we have
    927 	       available for parsing unsigned and long long values,
    928 	       however.  */
    929 	    SYMBOL_VALUE (sym) = atoi (p);
    930 	  }
    931 	  break;
    932 	default:
    933 	  {
    934 	    SYMBOL_ACLASS_INDEX (sym) = LOC_CONST;
    935 	    SYMBOL_TYPE (sym) = error_type (&p, objfile);
    936 	  }
    937 	}
    938       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
    939       add_symbol_to_list (sym, get_file_symbols ());
    940       return sym;
    941 
    942     case 'C':
    943       /* The name of a caught exception.  */
    944       SYMBOL_TYPE (sym) = read_type (&p, objfile);
    945       SYMBOL_ACLASS_INDEX (sym) = LOC_LABEL;
    946       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
    947       SYMBOL_VALUE_ADDRESS (sym) = valu;
    948       add_symbol_to_list (sym, get_local_symbols ());
    949       break;
    950 
    951     case 'f':
    952       /* A static function definition.  */
    953       SYMBOL_TYPE (sym) = read_type (&p, objfile);
    954       SYMBOL_ACLASS_INDEX (sym) = LOC_BLOCK;
    955       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
    956       add_symbol_to_list (sym, get_file_symbols ());
    957       /* fall into process_function_types.  */
    958 
    959     process_function_types:
    960       /* Function result types are described as the result type in stabs.
    961          We need to convert this to the function-returning-type-X type
    962          in GDB.  E.g. "int" is converted to "function returning int".  */
    963       if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_FUNC)
    964 	SYMBOL_TYPE (sym) = lookup_function_type (SYMBOL_TYPE (sym));
    965 
    966       /* All functions in C++ have prototypes.  Stabs does not offer an
    967          explicit way to identify prototyped or unprototyped functions,
    968          but both GCC and Sun CC emit stabs for the "call-as" type rather
    969          than the "declared-as" type for unprototyped functions, so
    970          we treat all functions as if they were prototyped.  This is used
    971          primarily for promotion when calling the function from GDB.  */
    972       TYPE_PROTOTYPED (SYMBOL_TYPE (sym)) = 1;
    973 
    974       /* fall into process_prototype_types.  */
    975 
    976     process_prototype_types:
    977       /* Sun acc puts declared types of arguments here.  */
    978       if (*p == ';')
    979 	{
    980 	  struct type *ftype = SYMBOL_TYPE (sym);
    981 	  int nsemi = 0;
    982 	  int nparams = 0;
    983 	  const char *p1 = p;
    984 
    985 	  /* Obtain a worst case guess for the number of arguments
    986 	     by counting the semicolons.  */
    987 	  while (*p1)
    988 	    {
    989 	      if (*p1++ == ';')
    990 		nsemi++;
    991 	    }
    992 
    993 	  /* Allocate parameter information fields and fill them in.  */
    994 	  TYPE_FIELDS (ftype) = (struct field *)
    995 	    TYPE_ALLOC (ftype, nsemi * sizeof (struct field));
    996 	  while (*p++ == ';')
    997 	    {
    998 	      struct type *ptype;
    999 
   1000 	      /* A type number of zero indicates the start of varargs.
   1001 	         FIXME: GDB currently ignores vararg functions.  */
   1002 	      if (p[0] == '0' && p[1] == '\0')
   1003 		break;
   1004 	      ptype = read_type (&p, objfile);
   1005 
   1006 	      /* The Sun compilers mark integer arguments, which should
   1007 	         be promoted to the width of the calling conventions, with
   1008 	         a type which references itself.  This type is turned into
   1009 	         a TYPE_CODE_VOID type by read_type, and we have to turn
   1010 	         it back into builtin_int here.
   1011 	         FIXME: Do we need a new builtin_promoted_int_arg ?  */
   1012 	      if (TYPE_CODE (ptype) == TYPE_CODE_VOID)
   1013 		ptype = objfile_type (objfile)->builtin_int;
   1014 	      TYPE_FIELD_TYPE (ftype, nparams) = ptype;
   1015 	      TYPE_FIELD_ARTIFICIAL (ftype, nparams++) = 0;
   1016 	    }
   1017 	  TYPE_NFIELDS (ftype) = nparams;
   1018 	  TYPE_PROTOTYPED (ftype) = 1;
   1019 	}
   1020       break;
   1021 
   1022     case 'F':
   1023       /* A global function definition.  */
   1024       SYMBOL_TYPE (sym) = read_type (&p, objfile);
   1025       SYMBOL_ACLASS_INDEX (sym) = LOC_BLOCK;
   1026       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
   1027       add_symbol_to_list (sym, get_global_symbols ());
   1028       goto process_function_types;
   1029 
   1030     case 'G':
   1031       /* For a class G (global) symbol, it appears that the
   1032          value is not correct.  It is necessary to search for the
   1033          corresponding linker definition to find the value.
   1034          These definitions appear at the end of the namelist.  */
   1035       SYMBOL_TYPE (sym) = read_type (&p, objfile);
   1036       SYMBOL_ACLASS_INDEX (sym) = LOC_STATIC;
   1037       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
   1038       /* Don't add symbol references to global_sym_chain.
   1039          Symbol references don't have valid names and wont't match up with
   1040          minimal symbols when the global_sym_chain is relocated.
   1041          We'll fixup symbol references when we fixup the defining symbol.  */
   1042       if (SYMBOL_LINKAGE_NAME (sym) && SYMBOL_LINKAGE_NAME (sym)[0] != '#')
   1043 	{
   1044 	  i = hashname (SYMBOL_LINKAGE_NAME (sym));
   1045 	  SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i];
   1046 	  global_sym_chain[i] = sym;
   1047 	}
   1048       add_symbol_to_list (sym, get_global_symbols ());
   1049       break;
   1050 
   1051       /* This case is faked by a conditional above,
   1052          when there is no code letter in the dbx data.
   1053          Dbx data never actually contains 'l'.  */
   1054     case 's':
   1055     case 'l':
   1056       SYMBOL_TYPE (sym) = read_type (&p, objfile);
   1057       SYMBOL_ACLASS_INDEX (sym) = LOC_LOCAL;
   1058       SYMBOL_VALUE (sym) = valu;
   1059       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
   1060       add_symbol_to_list (sym, get_local_symbols ());
   1061       break;
   1062 
   1063     case 'p':
   1064       if (*p == 'F')
   1065 	/* pF is a two-letter code that means a function parameter in Fortran.
   1066 	   The type-number specifies the type of the return value.
   1067 	   Translate it into a pointer-to-function type.  */
   1068 	{
   1069 	  p++;
   1070 	  SYMBOL_TYPE (sym)
   1071 	    = lookup_pointer_type
   1072 	    (lookup_function_type (read_type (&p, objfile)));
   1073 	}
   1074       else
   1075 	SYMBOL_TYPE (sym) = read_type (&p, objfile);
   1076 
   1077       SYMBOL_ACLASS_INDEX (sym) = LOC_ARG;
   1078       SYMBOL_VALUE (sym) = valu;
   1079       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
   1080       SYMBOL_IS_ARGUMENT (sym) = 1;
   1081       add_symbol_to_list (sym, get_local_symbols ());
   1082 
   1083       if (gdbarch_byte_order (gdbarch) != BFD_ENDIAN_BIG)
   1084 	{
   1085 	  /* On little-endian machines, this crud is never necessary,
   1086 	     and, if the extra bytes contain garbage, is harmful.  */
   1087 	  break;
   1088 	}
   1089 
   1090       /* If it's gcc-compiled, if it says `short', believe it.  */
   1091       if (processing_gcc_compilation
   1092 	  || gdbarch_believe_pcc_promotion (gdbarch))
   1093 	break;
   1094 
   1095       if (!gdbarch_believe_pcc_promotion (gdbarch))
   1096 	{
   1097 	  /* If PCC says a parameter is a short or a char, it is
   1098 	     really an int.  */
   1099 	  if (TYPE_LENGTH (SYMBOL_TYPE (sym))
   1100 	      < gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT
   1101 	      && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT)
   1102 	    {
   1103 	      SYMBOL_TYPE (sym) =
   1104 		TYPE_UNSIGNED (SYMBOL_TYPE (sym))
   1105 		? objfile_type (objfile)->builtin_unsigned_int
   1106 		: objfile_type (objfile)->builtin_int;
   1107 	    }
   1108 	  break;
   1109 	}
   1110       /* Fall through.  */
   1111 
   1112     case 'P':
   1113       /* acc seems to use P to declare the prototypes of functions that
   1114          are referenced by this file.  gdb is not prepared to deal
   1115          with this extra information.  FIXME, it ought to.  */
   1116       if (type == N_FUN)
   1117 	{
   1118 	  SYMBOL_TYPE (sym) = read_type (&p, objfile);
   1119 	  goto process_prototype_types;
   1120 	}
   1121       /*FALLTHROUGH */
   1122 
   1123     case 'R':
   1124       /* Parameter which is in a register.  */
   1125       SYMBOL_TYPE (sym) = read_type (&p, objfile);
   1126       SYMBOL_ACLASS_INDEX (sym) = stab_register_index;
   1127       SYMBOL_IS_ARGUMENT (sym) = 1;
   1128       SYMBOL_VALUE (sym) = valu;
   1129       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
   1130       add_symbol_to_list (sym, get_local_symbols ());
   1131       break;
   1132 
   1133     case 'r':
   1134       /* Register variable (either global or local).  */
   1135       SYMBOL_TYPE (sym) = read_type (&p, objfile);
   1136       SYMBOL_ACLASS_INDEX (sym) = stab_register_index;
   1137       SYMBOL_VALUE (sym) = valu;
   1138       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
   1139       if (within_function)
   1140 	{
   1141 	  /* Sun cc uses a pair of symbols, one 'p' and one 'r', with
   1142 	     the same name to represent an argument passed in a
   1143 	     register.  GCC uses 'P' for the same case.  So if we find
   1144 	     such a symbol pair we combine it into one 'P' symbol.
   1145 	     For Sun cc we need to do this regardless of
   1146 	     stabs_argument_has_addr, because the compiler puts out
   1147 	     the 'p' symbol even if it never saves the argument onto
   1148 	     the stack.
   1149 
   1150 	     On most machines, we want to preserve both symbols, so
   1151 	     that we can still get information about what is going on
   1152 	     with the stack (VAX for computing args_printed, using
   1153 	     stack slots instead of saved registers in backtraces,
   1154 	     etc.).
   1155 
   1156 	     Note that this code illegally combines
   1157 	     main(argc) struct foo argc; { register struct foo argc; }
   1158 	     but this case is considered pathological and causes a warning
   1159 	     from a decent compiler.  */
   1160 
   1161 	  struct pending *local_symbols = *get_local_symbols ();
   1162 	  if (local_symbols
   1163 	      && local_symbols->nsyms > 0
   1164 	      && gdbarch_stabs_argument_has_addr (gdbarch, SYMBOL_TYPE (sym)))
   1165 	    {
   1166 	      struct symbol *prev_sym;
   1167 
   1168 	      prev_sym = local_symbols->symbol[local_symbols->nsyms - 1];
   1169 	      if ((SYMBOL_CLASS (prev_sym) == LOC_REF_ARG
   1170 		   || SYMBOL_CLASS (prev_sym) == LOC_ARG)
   1171 		  && strcmp (SYMBOL_LINKAGE_NAME (prev_sym),
   1172 			     SYMBOL_LINKAGE_NAME (sym)) == 0)
   1173 		{
   1174 		  SYMBOL_ACLASS_INDEX (prev_sym) = stab_register_index;
   1175 		  /* Use the type from the LOC_REGISTER; that is the type
   1176 		     that is actually in that register.  */
   1177 		  SYMBOL_TYPE (prev_sym) = SYMBOL_TYPE (sym);
   1178 		  SYMBOL_VALUE (prev_sym) = SYMBOL_VALUE (sym);
   1179 		  sym = prev_sym;
   1180 		  break;
   1181 		}
   1182 	    }
   1183 	  add_symbol_to_list (sym, get_local_symbols ());
   1184 	}
   1185       else
   1186 	add_symbol_to_list (sym, get_file_symbols ());
   1187       break;
   1188 
   1189     case 'S':
   1190       /* Static symbol at top level of file.  */
   1191       SYMBOL_TYPE (sym) = read_type (&p, objfile);
   1192       SYMBOL_ACLASS_INDEX (sym) = LOC_STATIC;
   1193       SYMBOL_VALUE_ADDRESS (sym) = valu;
   1194       if (gdbarch_static_transform_name_p (gdbarch)
   1195 	  && gdbarch_static_transform_name (gdbarch,
   1196 					    SYMBOL_LINKAGE_NAME (sym))
   1197 	     != SYMBOL_LINKAGE_NAME (sym))
   1198 	{
   1199 	  struct bound_minimal_symbol msym;
   1200 
   1201 	  msym = lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (sym),
   1202 					NULL, objfile);
   1203 	  if (msym.minsym != NULL)
   1204 	    {
   1205 	      const char *new_name = gdbarch_static_transform_name
   1206 		(gdbarch, SYMBOL_LINKAGE_NAME (sym));
   1207 
   1208 	      SYMBOL_SET_LINKAGE_NAME (sym, new_name);
   1209 	      SYMBOL_VALUE_ADDRESS (sym) = BMSYMBOL_VALUE_ADDRESS (msym);
   1210 	    }
   1211 	}
   1212       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
   1213       add_symbol_to_list (sym, get_file_symbols ());
   1214       break;
   1215 
   1216     case 't':
   1217       /* In Ada, there is no distinction between typedef and non-typedef;
   1218          any type declaration implicitly has the equivalent of a typedef,
   1219          and thus 't' is in fact equivalent to 'Tt'.
   1220 
   1221          Therefore, for Ada units, we check the character immediately
   1222          before the 't', and if we do not find a 'T', then make sure to
   1223          create the associated symbol in the STRUCT_DOMAIN ('t' definitions
   1224          will be stored in the VAR_DOMAIN).  If the symbol was indeed
   1225          defined as 'Tt' then the STRUCT_DOMAIN symbol will be created
   1226          elsewhere, so we don't need to take care of that.
   1227 
   1228          This is important to do, because of forward references:
   1229          The cleanup of undefined types stored in undef_types only uses
   1230          STRUCT_DOMAIN symbols to perform the replacement.  */
   1231       synonym = (SYMBOL_LANGUAGE (sym) == language_ada && p[-2] != 'T');
   1232 
   1233       /* Typedef */
   1234       SYMBOL_TYPE (sym) = read_type (&p, objfile);
   1235 
   1236       /* For a nameless type, we don't want a create a symbol, thus we
   1237          did not use `sym'.  Return without further processing.  */
   1238       if (nameless)
   1239 	return NULL;
   1240 
   1241       SYMBOL_ACLASS_INDEX (sym) = LOC_TYPEDEF;
   1242       SYMBOL_VALUE (sym) = valu;
   1243       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
   1244       /* C++ vagaries: we may have a type which is derived from
   1245          a base type which did not have its name defined when the
   1246          derived class was output.  We fill in the derived class's
   1247          base part member's name here in that case.  */
   1248       if (TYPE_NAME (SYMBOL_TYPE (sym)) != NULL)
   1249 	if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
   1250 	     || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION)
   1251 	    && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)))
   1252 	  {
   1253 	    int j;
   1254 
   1255 	    for (j = TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)) - 1; j >= 0; j--)
   1256 	      if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) == 0)
   1257 		TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) =
   1258 		  TYPE_NAME (TYPE_BASECLASS (SYMBOL_TYPE (sym), j));
   1259 	  }
   1260 
   1261       if (TYPE_NAME (SYMBOL_TYPE (sym)) == NULL)
   1262 	{
   1263 	  /* gcc-2.6 or later (when using -fvtable-thunks)
   1264 	     emits a unique named type for a vtable entry.
   1265 	     Some gdb code depends on that specific name.  */
   1266 	  extern const char vtbl_ptr_name[];
   1267 
   1268 	  if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_PTR
   1269 	       && strcmp (SYMBOL_LINKAGE_NAME (sym), vtbl_ptr_name))
   1270 	      || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_FUNC)
   1271 	    {
   1272 	      /* If we are giving a name to a type such as "pointer to
   1273 	         foo" or "function returning foo", we better not set
   1274 	         the TYPE_NAME.  If the program contains "typedef char
   1275 	         *caddr_t;", we don't want all variables of type char
   1276 	         * to print as caddr_t.  This is not just a
   1277 	         consequence of GDB's type management; PCC and GCC (at
   1278 	         least through version 2.4) both output variables of
   1279 	         either type char * or caddr_t with the type number
   1280 	         defined in the 't' symbol for caddr_t.  If a future
   1281 	         compiler cleans this up it GDB is not ready for it
   1282 	         yet, but if it becomes ready we somehow need to
   1283 	         disable this check (without breaking the PCC/GCC2.4
   1284 	         case).
   1285 
   1286 	         Sigh.
   1287 
   1288 	         Fortunately, this check seems not to be necessary
   1289 	         for anything except pointers or functions.  */
   1290               /* ezannoni: 2000-10-26.  This seems to apply for
   1291 		 versions of gcc older than 2.8.  This was the original
   1292 		 problem: with the following code gdb would tell that
   1293 		 the type for name1 is caddr_t, and func is char().
   1294 
   1295 	         typedef char *caddr_t;
   1296 		 char *name2;
   1297 		 struct x
   1298 		 {
   1299 		   char *name1;
   1300 		 } xx;
   1301 		 char *func()
   1302 		 {
   1303 		 }
   1304 		 main () {}
   1305 		 */
   1306 
   1307 	      /* Pascal accepts names for pointer types.  */
   1308 	      if (get_current_subfile ()->language == language_pascal)
   1309 		{
   1310 		  TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_LINKAGE_NAME (sym);
   1311           	}
   1312 	    }
   1313 	  else
   1314 	    TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_LINKAGE_NAME (sym);
   1315 	}
   1316 
   1317       add_symbol_to_list (sym, get_file_symbols ());
   1318 
   1319       if (synonym)
   1320         {
   1321           /* Create the STRUCT_DOMAIN clone.  */
   1322           struct symbol *struct_sym = allocate_symbol (objfile);
   1323 
   1324           *struct_sym = *sym;
   1325           SYMBOL_ACLASS_INDEX (struct_sym) = LOC_TYPEDEF;
   1326           SYMBOL_VALUE (struct_sym) = valu;
   1327           SYMBOL_DOMAIN (struct_sym) = STRUCT_DOMAIN;
   1328           if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
   1329             TYPE_NAME (SYMBOL_TYPE (sym))
   1330 	      = obconcat (&objfile->objfile_obstack,
   1331 			  SYMBOL_LINKAGE_NAME (sym),
   1332 			  (char *) NULL);
   1333           add_symbol_to_list (struct_sym, get_file_symbols ());
   1334         }
   1335 
   1336       break;
   1337 
   1338     case 'T':
   1339       /* Struct, union, or enum tag.  For GNU C++, this can be be followed
   1340          by 't' which means we are typedef'ing it as well.  */
   1341       synonym = *p == 't';
   1342 
   1343       if (synonym)
   1344 	p++;
   1345 
   1346       SYMBOL_TYPE (sym) = read_type (&p, objfile);
   1347 
   1348       /* For a nameless type, we don't want a create a symbol, thus we
   1349          did not use `sym'.  Return without further processing.  */
   1350       if (nameless)
   1351 	return NULL;
   1352 
   1353       SYMBOL_ACLASS_INDEX (sym) = LOC_TYPEDEF;
   1354       SYMBOL_VALUE (sym) = valu;
   1355       SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN;
   1356       if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
   1357 	TYPE_NAME (SYMBOL_TYPE (sym))
   1358 	  = obconcat (&objfile->objfile_obstack,
   1359 		      SYMBOL_LINKAGE_NAME (sym),
   1360 		      (char *) NULL);
   1361       add_symbol_to_list (sym, get_file_symbols ());
   1362 
   1363       if (synonym)
   1364 	{
   1365 	  /* Clone the sym and then modify it.  */
   1366 	  struct symbol *typedef_sym = allocate_symbol (objfile);
   1367 
   1368 	  *typedef_sym = *sym;
   1369 	  SYMBOL_ACLASS_INDEX (typedef_sym) = LOC_TYPEDEF;
   1370 	  SYMBOL_VALUE (typedef_sym) = valu;
   1371 	  SYMBOL_DOMAIN (typedef_sym) = VAR_DOMAIN;
   1372 	  if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
   1373 	    TYPE_NAME (SYMBOL_TYPE (sym))
   1374 	      = obconcat (&objfile->objfile_obstack,
   1375 			  SYMBOL_LINKAGE_NAME (sym),
   1376 			  (char *) NULL);
   1377 	  add_symbol_to_list (typedef_sym, get_file_symbols ());
   1378 	}
   1379       break;
   1380 
   1381     case 'V':
   1382       /* Static symbol of local scope.  */
   1383       SYMBOL_TYPE (sym) = read_type (&p, objfile);
   1384       SYMBOL_ACLASS_INDEX (sym) = LOC_STATIC;
   1385       SYMBOL_VALUE_ADDRESS (sym) = valu;
   1386       if (gdbarch_static_transform_name_p (gdbarch)
   1387 	  && gdbarch_static_transform_name (gdbarch,
   1388 					    SYMBOL_LINKAGE_NAME (sym))
   1389 	     != SYMBOL_LINKAGE_NAME (sym))
   1390 	{
   1391 	  struct bound_minimal_symbol msym;
   1392 
   1393 	  msym = lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (sym),
   1394 					NULL, objfile);
   1395 	  if (msym.minsym != NULL)
   1396 	    {
   1397 	      const char *new_name = gdbarch_static_transform_name
   1398 		(gdbarch, SYMBOL_LINKAGE_NAME (sym));
   1399 
   1400 	      SYMBOL_SET_LINKAGE_NAME (sym, new_name);
   1401 	      SYMBOL_VALUE_ADDRESS (sym) = BMSYMBOL_VALUE_ADDRESS (msym);
   1402 	    }
   1403 	}
   1404       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
   1405 	add_symbol_to_list (sym, get_local_symbols ());
   1406       break;
   1407 
   1408     case 'v':
   1409       /* Reference parameter */
   1410       SYMBOL_TYPE (sym) = read_type (&p, objfile);
   1411       SYMBOL_ACLASS_INDEX (sym) = LOC_REF_ARG;
   1412       SYMBOL_IS_ARGUMENT (sym) = 1;
   1413       SYMBOL_VALUE (sym) = valu;
   1414       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
   1415       add_symbol_to_list (sym, get_local_symbols ());
   1416       break;
   1417 
   1418     case 'a':
   1419       /* Reference parameter which is in a register.  */
   1420       SYMBOL_TYPE (sym) = read_type (&p, objfile);
   1421       SYMBOL_ACLASS_INDEX (sym) = stab_regparm_index;
   1422       SYMBOL_IS_ARGUMENT (sym) = 1;
   1423       SYMBOL_VALUE (sym) = valu;
   1424       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
   1425       add_symbol_to_list (sym, get_local_symbols ());
   1426       break;
   1427 
   1428     case 'X':
   1429       /* This is used by Sun FORTRAN for "function result value".
   1430          Sun claims ("dbx and dbxtool interfaces", 2nd ed)
   1431          that Pascal uses it too, but when I tried it Pascal used
   1432          "x:3" (local symbol) instead.  */
   1433       SYMBOL_TYPE (sym) = read_type (&p, objfile);
   1434       SYMBOL_ACLASS_INDEX (sym) = LOC_LOCAL;
   1435       SYMBOL_VALUE (sym) = valu;
   1436       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
   1437       add_symbol_to_list (sym, get_local_symbols ());
   1438       break;
   1439 
   1440     default:
   1441       SYMBOL_TYPE (sym) = error_type (&p, objfile);
   1442       SYMBOL_ACLASS_INDEX (sym) = LOC_CONST;
   1443       SYMBOL_VALUE (sym) = 0;
   1444       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
   1445       add_symbol_to_list (sym, get_file_symbols ());
   1446       break;
   1447     }
   1448 
   1449   /* Some systems pass variables of certain types by reference instead
   1450      of by value, i.e. they will pass the address of a structure (in a
   1451      register or on the stack) instead of the structure itself.  */
   1452 
   1453   if (gdbarch_stabs_argument_has_addr (gdbarch, SYMBOL_TYPE (sym))
   1454       && SYMBOL_IS_ARGUMENT (sym))
   1455     {
   1456       /* We have to convert LOC_REGISTER to LOC_REGPARM_ADDR (for
   1457          variables passed in a register).  */
   1458       if (SYMBOL_CLASS (sym) == LOC_REGISTER)
   1459 	SYMBOL_ACLASS_INDEX (sym) = LOC_REGPARM_ADDR;
   1460       /* Likewise for converting LOC_ARG to LOC_REF_ARG (for the 7th
   1461 	 and subsequent arguments on SPARC, for example).  */
   1462       else if (SYMBOL_CLASS (sym) == LOC_ARG)
   1463 	SYMBOL_ACLASS_INDEX (sym) = LOC_REF_ARG;
   1464     }
   1465 
   1466   return sym;
   1467 }
   1468 
   1469 /* Skip rest of this symbol and return an error type.
   1470 
   1471    General notes on error recovery:  error_type always skips to the
   1472    end of the symbol (modulo cretinous dbx symbol name continuation).
   1473    Thus code like this:
   1474 
   1475    if (*(*pp)++ != ';')
   1476    return error_type (pp, objfile);
   1477 
   1478    is wrong because if *pp starts out pointing at '\0' (typically as the
   1479    result of an earlier error), it will be incremented to point to the
   1480    start of the next symbol, which might produce strange results, at least
   1481    if you run off the end of the string table.  Instead use
   1482 
   1483    if (**pp != ';')
   1484    return error_type (pp, objfile);
   1485    ++*pp;
   1486 
   1487    or
   1488 
   1489    if (**pp != ';')
   1490    foo = error_type (pp, objfile);
   1491    else
   1492    ++*pp;
   1493 
   1494    And in case it isn't obvious, the point of all this hair is so the compiler
   1495    can define new types and new syntaxes, and old versions of the
   1496    debugger will be able to read the new symbol tables.  */
   1497 
   1498 static struct type *
   1499 error_type (const char **pp, struct objfile *objfile)
   1500 {
   1501   complaint (_("couldn't parse type; debugger out of date?"));
   1502   while (1)
   1503     {
   1504       /* Skip to end of symbol.  */
   1505       while (**pp != '\0')
   1506 	{
   1507 	  (*pp)++;
   1508 	}
   1509 
   1510       /* Check for and handle cretinous dbx symbol name continuation!  */
   1511       if ((*pp)[-1] == '\\' || (*pp)[-1] == '?')
   1512 	{
   1513 	  *pp = next_symbol_text (objfile);
   1514 	}
   1515       else
   1516 	{
   1517 	  break;
   1518 	}
   1519     }
   1520   return objfile_type (objfile)->builtin_error;
   1521 }
   1522 
   1523 
   1525 /* Read type information or a type definition; return the type.  Even
   1526    though this routine accepts either type information or a type
   1527    definition, the distinction is relevant--some parts of stabsread.c
   1528    assume that type information starts with a digit, '-', or '(' in
   1529    deciding whether to call read_type.  */
   1530 
   1531 static struct type *
   1532 read_type (const char **pp, struct objfile *objfile)
   1533 {
   1534   struct type *type = 0;
   1535   struct type *type1;
   1536   int typenums[2];
   1537   char type_descriptor;
   1538 
   1539   /* Size in bits of type if specified by a type attribute, or -1 if
   1540      there is no size attribute.  */
   1541   int type_size = -1;
   1542 
   1543   /* Used to distinguish string and bitstring from char-array and set.  */
   1544   int is_string = 0;
   1545 
   1546   /* Used to distinguish vector from array.  */
   1547   int is_vector = 0;
   1548 
   1549   /* Read type number if present.  The type number may be omitted.
   1550      for instance in a two-dimensional array declared with type
   1551      "ar1;1;10;ar1;1;10;4".  */
   1552   if ((**pp >= '0' && **pp <= '9')
   1553       || **pp == '('
   1554       || **pp == '-')
   1555     {
   1556       if (read_type_number (pp, typenums) != 0)
   1557 	return error_type (pp, objfile);
   1558 
   1559       if (**pp != '=')
   1560         {
   1561           /* Type is not being defined here.  Either it already
   1562              exists, or this is a forward reference to it.
   1563              dbx_alloc_type handles both cases.  */
   1564           type = dbx_alloc_type (typenums, objfile);
   1565 
   1566           /* If this is a forward reference, arrange to complain if it
   1567              doesn't get patched up by the time we're done
   1568              reading.  */
   1569           if (TYPE_CODE (type) == TYPE_CODE_UNDEF)
   1570             add_undefined_type (type, typenums);
   1571 
   1572           return type;
   1573         }
   1574 
   1575       /* Type is being defined here.  */
   1576       /* Skip the '='.
   1577          Also skip the type descriptor - we get it below with (*pp)[-1].  */
   1578       (*pp) += 2;
   1579     }
   1580   else
   1581     {
   1582       /* 'typenums=' not present, type is anonymous.  Read and return
   1583          the definition, but don't put it in the type vector.  */
   1584       typenums[0] = typenums[1] = -1;
   1585       (*pp)++;
   1586     }
   1587 
   1588 again:
   1589   type_descriptor = (*pp)[-1];
   1590   switch (type_descriptor)
   1591     {
   1592     case 'x':
   1593       {
   1594 	enum type_code code;
   1595 
   1596 	/* Used to index through file_symbols.  */
   1597 	struct pending *ppt;
   1598 	int i;
   1599 
   1600 	/* Name including "struct", etc.  */
   1601 	char *type_name;
   1602 
   1603 	{
   1604 	  const char *from, *p, *q1, *q2;
   1605 
   1606 	  /* Set the type code according to the following letter.  */
   1607 	  switch ((*pp)[0])
   1608 	    {
   1609 	    case 's':
   1610 	      code = TYPE_CODE_STRUCT;
   1611 	      break;
   1612 	    case 'u':
   1613 	      code = TYPE_CODE_UNION;
   1614 	      break;
   1615 	    case 'e':
   1616 	      code = TYPE_CODE_ENUM;
   1617 	      break;
   1618 	    default:
   1619 	      {
   1620 		/* Complain and keep going, so compilers can invent new
   1621 		   cross-reference types.  */
   1622 		complaint (_("Unrecognized cross-reference type `%c'"),
   1623 			   (*pp)[0]);
   1624 		code = TYPE_CODE_STRUCT;
   1625 		break;
   1626 	      }
   1627 	    }
   1628 
   1629 	  q1 = strchr (*pp, '<');
   1630 	  p = strchr (*pp, ':');
   1631 	  if (p == NULL)
   1632 	    return error_type (pp, objfile);
   1633 	  if (q1 && p > q1 && p[1] == ':')
   1634 	    {
   1635 	      int nesting_level = 0;
   1636 
   1637 	      for (q2 = q1; *q2; q2++)
   1638 		{
   1639 		  if (*q2 == '<')
   1640 		    nesting_level++;
   1641 		  else if (*q2 == '>')
   1642 		    nesting_level--;
   1643 		  else if (*q2 == ':' && nesting_level == 0)
   1644 		    break;
   1645 		}
   1646 	      p = q2;
   1647 	      if (*p != ':')
   1648 		return error_type (pp, objfile);
   1649 	    }
   1650 	  type_name = NULL;
   1651 	  if (get_current_subfile ()->language == language_cplus)
   1652 	    {
   1653 	      char *name = (char *) alloca (p - *pp + 1);
   1654 
   1655 	      memcpy (name, *pp, p - *pp);
   1656 	      name[p - *pp] = '\0';
   1657 
   1658 	      std::string new_name = cp_canonicalize_string (name);
   1659 	      if (!new_name.empty ())
   1660 		{
   1661 		  type_name
   1662 		    = (char *) obstack_copy0 (&objfile->objfile_obstack,
   1663 					      new_name.c_str (),
   1664 					      new_name.length ());
   1665 		}
   1666 	    }
   1667 	  if (type_name == NULL)
   1668 	    {
   1669 	      char *to = type_name = (char *)
   1670 		obstack_alloc (&objfile->objfile_obstack, p - *pp + 1);
   1671 
   1672 	      /* Copy the name.  */
   1673 	      from = *pp + 1;
   1674 	      while (from < p)
   1675 		*to++ = *from++;
   1676 	      *to = '\0';
   1677 	    }
   1678 
   1679 	  /* Set the pointer ahead of the name which we just read, and
   1680 	     the colon.  */
   1681 	  *pp = p + 1;
   1682 	}
   1683 
   1684         /* If this type has already been declared, then reuse the same
   1685            type, rather than allocating a new one.  This saves some
   1686            memory.  */
   1687 
   1688 	for (ppt = *get_file_symbols (); ppt; ppt = ppt->next)
   1689 	  for (i = 0; i < ppt->nsyms; i++)
   1690 	    {
   1691 	      struct symbol *sym = ppt->symbol[i];
   1692 
   1693 	      if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
   1694 		  && SYMBOL_DOMAIN (sym) == STRUCT_DOMAIN
   1695 		  && (TYPE_CODE (SYMBOL_TYPE (sym)) == code)
   1696 		  && strcmp (SYMBOL_LINKAGE_NAME (sym), type_name) == 0)
   1697 		{
   1698 		  obstack_free (&objfile->objfile_obstack, type_name);
   1699 		  type = SYMBOL_TYPE (sym);
   1700 	          if (typenums[0] != -1)
   1701 	            *dbx_lookup_type (typenums, objfile) = type;
   1702 		  return type;
   1703 		}
   1704 	    }
   1705 
   1706 	/* Didn't find the type to which this refers, so we must
   1707 	   be dealing with a forward reference.  Allocate a type
   1708 	   structure for it, and keep track of it so we can
   1709 	   fill in the rest of the fields when we get the full
   1710 	   type.  */
   1711 	type = dbx_alloc_type (typenums, objfile);
   1712 	TYPE_CODE (type) = code;
   1713 	TYPE_NAME (type) = type_name;
   1714 	INIT_CPLUS_SPECIFIC (type);
   1715 	TYPE_STUB (type) = 1;
   1716 
   1717 	add_undefined_type (type, typenums);
   1718 	return type;
   1719       }
   1720 
   1721     case '-':			/* RS/6000 built-in type */
   1722     case '0':
   1723     case '1':
   1724     case '2':
   1725     case '3':
   1726     case '4':
   1727     case '5':
   1728     case '6':
   1729     case '7':
   1730     case '8':
   1731     case '9':
   1732     case '(':
   1733       (*pp)--;
   1734 
   1735       /* We deal with something like t(1,2)=(3,4)=... which
   1736          the Lucid compiler and recent gcc versions (post 2.7.3) use.  */
   1737 
   1738       /* Allocate and enter the typedef type first.
   1739          This handles recursive types.  */
   1740       type = dbx_alloc_type (typenums, objfile);
   1741       TYPE_CODE (type) = TYPE_CODE_TYPEDEF;
   1742       {
   1743 	struct type *xtype = read_type (pp, objfile);
   1744 
   1745 	if (type == xtype)
   1746 	  {
   1747 	    /* It's being defined as itself.  That means it is "void".  */
   1748 	    TYPE_CODE (type) = TYPE_CODE_VOID;
   1749 	    TYPE_LENGTH (type) = 1;
   1750 	  }
   1751 	else if (type_size >= 0 || is_string)
   1752 	  {
   1753 	    /* This is the absolute wrong way to construct types.  Every
   1754 	       other debug format has found a way around this problem and
   1755 	       the related problems with unnecessarily stubbed types;
   1756 	       someone motivated should attempt to clean up the issue
   1757 	       here as well.  Once a type pointed to has been created it
   1758 	       should not be modified.
   1759 
   1760                Well, it's not *absolutely* wrong.  Constructing recursive
   1761                types (trees, linked lists) necessarily entails modifying
   1762                types after creating them.  Constructing any loop structure
   1763                entails side effects.  The Dwarf 2 reader does handle this
   1764                more gracefully (it never constructs more than once
   1765                instance of a type object, so it doesn't have to copy type
   1766                objects wholesale), but it still mutates type objects after
   1767                other folks have references to them.
   1768 
   1769                Keep in mind that this circularity/mutation issue shows up
   1770                at the source language level, too: C's "incomplete types",
   1771                for example.  So the proper cleanup, I think, would be to
   1772                limit GDB's type smashing to match exactly those required
   1773                by the source language.  So GDB could have a
   1774                "complete_this_type" function, but never create unnecessary
   1775                copies of a type otherwise.  */
   1776 	    replace_type (type, xtype);
   1777 	    TYPE_NAME (type) = NULL;
   1778 	  }
   1779 	else
   1780 	  {
   1781 	    TYPE_TARGET_STUB (type) = 1;
   1782 	    TYPE_TARGET_TYPE (type) = xtype;
   1783 	  }
   1784       }
   1785       break;
   1786 
   1787       /* In the following types, we must be sure to overwrite any existing
   1788          type that the typenums refer to, rather than allocating a new one
   1789          and making the typenums point to the new one.  This is because there
   1790          may already be pointers to the existing type (if it had been
   1791          forward-referenced), and we must change it to a pointer, function,
   1792          reference, or whatever, *in-place*.  */
   1793 
   1794     case '*':			/* Pointer to another type */
   1795       type1 = read_type (pp, objfile);
   1796       type = make_pointer_type (type1, dbx_lookup_type (typenums, objfile));
   1797       break;
   1798 
   1799     case '&':			/* Reference to another type */
   1800       type1 = read_type (pp, objfile);
   1801       type = make_reference_type (type1, dbx_lookup_type (typenums, objfile),
   1802                                   TYPE_CODE_REF);
   1803       break;
   1804 
   1805     case 'f':			/* Function returning another type */
   1806       type1 = read_type (pp, objfile);
   1807       type = make_function_type (type1, dbx_lookup_type (typenums, objfile));
   1808       break;
   1809 
   1810     case 'g':                   /* Prototyped function.  (Sun)  */
   1811       {
   1812         /* Unresolved questions:
   1813 
   1814            - According to Sun's ``STABS Interface Manual'', for 'f'
   1815            and 'F' symbol descriptors, a `0' in the argument type list
   1816            indicates a varargs function.  But it doesn't say how 'g'
   1817            type descriptors represent that info.  Someone with access
   1818            to Sun's toolchain should try it out.
   1819 
   1820            - According to the comment in define_symbol (search for
   1821            `process_prototype_types:'), Sun emits integer arguments as
   1822            types which ref themselves --- like `void' types.  Do we
   1823            have to deal with that here, too?  Again, someone with
   1824            access to Sun's toolchain should try it out and let us
   1825            know.  */
   1826 
   1827         const char *type_start = (*pp) - 1;
   1828         struct type *return_type = read_type (pp, objfile);
   1829         struct type *func_type
   1830           = make_function_type (return_type,
   1831 				dbx_lookup_type (typenums, objfile));
   1832         struct type_list {
   1833           struct type *type;
   1834           struct type_list *next;
   1835         } *arg_types = 0;
   1836         int num_args = 0;
   1837 
   1838         while (**pp && **pp != '#')
   1839           {
   1840             struct type *arg_type = read_type (pp, objfile);
   1841             struct type_list *newobj = XALLOCA (struct type_list);
   1842             newobj->type = arg_type;
   1843             newobj->next = arg_types;
   1844             arg_types = newobj;
   1845             num_args++;
   1846           }
   1847         if (**pp == '#')
   1848           ++*pp;
   1849         else
   1850           {
   1851 	    complaint (_("Prototyped function type didn't "
   1852 			 "end arguments with `#':\n%s"),
   1853 		       type_start);
   1854           }
   1855 
   1856         /* If there is just one argument whose type is `void', then
   1857            that's just an empty argument list.  */
   1858         if (arg_types
   1859             && ! arg_types->next
   1860             && TYPE_CODE (arg_types->type) == TYPE_CODE_VOID)
   1861           num_args = 0;
   1862 
   1863         TYPE_FIELDS (func_type)
   1864           = (struct field *) TYPE_ALLOC (func_type,
   1865                                          num_args * sizeof (struct field));
   1866         memset (TYPE_FIELDS (func_type), 0, num_args * sizeof (struct field));
   1867         {
   1868           int i;
   1869           struct type_list *t;
   1870 
   1871           /* We stuck each argument type onto the front of the list
   1872              when we read it, so the list is reversed.  Build the
   1873              fields array right-to-left.  */
   1874           for (t = arg_types, i = num_args - 1; t; t = t->next, i--)
   1875             TYPE_FIELD_TYPE (func_type, i) = t->type;
   1876         }
   1877         TYPE_NFIELDS (func_type) = num_args;
   1878         TYPE_PROTOTYPED (func_type) = 1;
   1879 
   1880         type = func_type;
   1881         break;
   1882       }
   1883 
   1884     case 'k':			/* Const qualifier on some type (Sun) */
   1885       type = read_type (pp, objfile);
   1886       type = make_cv_type (1, TYPE_VOLATILE (type), type,
   1887 			   dbx_lookup_type (typenums, objfile));
   1888       break;
   1889 
   1890     case 'B':			/* Volatile qual on some type (Sun) */
   1891       type = read_type (pp, objfile);
   1892       type = make_cv_type (TYPE_CONST (type), 1, type,
   1893 			   dbx_lookup_type (typenums, objfile));
   1894       break;
   1895 
   1896     case '@':
   1897       if (isdigit (**pp) || **pp == '(' || **pp == '-')
   1898 	{			/* Member (class & variable) type */
   1899 	  /* FIXME -- we should be doing smash_to_XXX types here.  */
   1900 
   1901 	  struct type *domain = read_type (pp, objfile);
   1902 	  struct type *memtype;
   1903 
   1904 	  if (**pp != ',')
   1905 	    /* Invalid member type data format.  */
   1906 	    return error_type (pp, objfile);
   1907 	  ++*pp;
   1908 
   1909 	  memtype = read_type (pp, objfile);
   1910 	  type = dbx_alloc_type (typenums, objfile);
   1911 	  smash_to_memberptr_type (type, domain, memtype);
   1912 	}
   1913       else
   1914 	/* type attribute */
   1915 	{
   1916 	  const char *attr = *pp;
   1917 
   1918 	  /* Skip to the semicolon.  */
   1919 	  while (**pp != ';' && **pp != '\0')
   1920 	    ++(*pp);
   1921 	  if (**pp == '\0')
   1922 	    return error_type (pp, objfile);
   1923 	  else
   1924 	    ++ * pp;		/* Skip the semicolon.  */
   1925 
   1926 	  switch (*attr)
   1927 	    {
   1928 	    case 's':		/* Size attribute */
   1929 	      type_size = atoi (attr + 1);
   1930 	      if (type_size <= 0)
   1931 		type_size = -1;
   1932 	      break;
   1933 
   1934 	    case 'S':		/* String attribute */
   1935 	      /* FIXME: check to see if following type is array?  */
   1936 	      is_string = 1;
   1937 	      break;
   1938 
   1939 	    case 'V':		/* Vector attribute */
   1940 	      /* FIXME: check to see if following type is array?  */
   1941 	      is_vector = 1;
   1942 	      break;
   1943 
   1944 	    default:
   1945 	      /* Ignore unrecognized type attributes, so future compilers
   1946 	         can invent new ones.  */
   1947 	      break;
   1948 	    }
   1949 	  ++*pp;
   1950 	  goto again;
   1951 	}
   1952       break;
   1953 
   1954     case '#':			/* Method (class & fn) type */
   1955       if ((*pp)[0] == '#')
   1956 	{
   1957 	  /* We'll get the parameter types from the name.  */
   1958 	  struct type *return_type;
   1959 
   1960 	  (*pp)++;
   1961 	  return_type = read_type (pp, objfile);
   1962 	  if (*(*pp)++ != ';')
   1963 	    complaint (_("invalid (minimal) member type "
   1964 			 "data format at symtab pos %d."),
   1965 		       symnum);
   1966 	  type = allocate_stub_method (return_type);
   1967 	  if (typenums[0] != -1)
   1968 	    *dbx_lookup_type (typenums, objfile) = type;
   1969 	}
   1970       else
   1971 	{
   1972 	  struct type *domain = read_type (pp, objfile);
   1973 	  struct type *return_type;
   1974 	  struct field *args;
   1975 	  int nargs, varargs;
   1976 
   1977 	  if (**pp != ',')
   1978 	    /* Invalid member type data format.  */
   1979 	    return error_type (pp, objfile);
   1980 	  else
   1981 	    ++(*pp);
   1982 
   1983 	  return_type = read_type (pp, objfile);
   1984 	  args = read_args (pp, ';', objfile, &nargs, &varargs);
   1985 	  if (args == NULL)
   1986 	    return error_type (pp, objfile);
   1987 	  type = dbx_alloc_type (typenums, objfile);
   1988 	  smash_to_method_type (type, domain, return_type, args,
   1989 				nargs, varargs);
   1990 	}
   1991       break;
   1992 
   1993     case 'r':			/* Range type */
   1994       type = read_range_type (pp, typenums, type_size, objfile);
   1995       if (typenums[0] != -1)
   1996 	*dbx_lookup_type (typenums, objfile) = type;
   1997       break;
   1998 
   1999     case 'b':
   2000 	{
   2001 	  /* Sun ACC builtin int type */
   2002 	  type = read_sun_builtin_type (pp, typenums, objfile);
   2003 	  if (typenums[0] != -1)
   2004 	    *dbx_lookup_type (typenums, objfile) = type;
   2005 	}
   2006       break;
   2007 
   2008     case 'R':			/* Sun ACC builtin float type */
   2009       type = read_sun_floating_type (pp, typenums, objfile);
   2010       if (typenums[0] != -1)
   2011 	*dbx_lookup_type (typenums, objfile) = type;
   2012       break;
   2013 
   2014     case 'e':			/* Enumeration type */
   2015       type = dbx_alloc_type (typenums, objfile);
   2016       type = read_enum_type (pp, type, objfile);
   2017       if (typenums[0] != -1)
   2018 	*dbx_lookup_type (typenums, objfile) = type;
   2019       break;
   2020 
   2021     case 's':			/* Struct type */
   2022     case 'u':			/* Union type */
   2023       {
   2024         enum type_code type_code = TYPE_CODE_UNDEF;
   2025         type = dbx_alloc_type (typenums, objfile);
   2026         switch (type_descriptor)
   2027           {
   2028           case 's':
   2029             type_code = TYPE_CODE_STRUCT;
   2030             break;
   2031           case 'u':
   2032             type_code = TYPE_CODE_UNION;
   2033             break;
   2034           }
   2035         type = read_struct_type (pp, type, type_code, objfile);
   2036         break;
   2037       }
   2038 
   2039     case 'a':			/* Array type */
   2040       if (**pp != 'r')
   2041 	return error_type (pp, objfile);
   2042       ++*pp;
   2043 
   2044       type = dbx_alloc_type (typenums, objfile);
   2045       type = read_array_type (pp, type, objfile);
   2046       if (is_string)
   2047 	TYPE_CODE (type) = TYPE_CODE_STRING;
   2048       if (is_vector)
   2049 	make_vector_type (type);
   2050       break;
   2051 
   2052     case 'S':			/* Set type */
   2053       type1 = read_type (pp, objfile);
   2054       type = create_set_type ((struct type *) NULL, type1);
   2055       if (typenums[0] != -1)
   2056 	*dbx_lookup_type (typenums, objfile) = type;
   2057       break;
   2058 
   2059     default:
   2060       --*pp;			/* Go back to the symbol in error.  */
   2061       /* Particularly important if it was \0!  */
   2062       return error_type (pp, objfile);
   2063     }
   2064 
   2065   if (type == 0)
   2066     {
   2067       warning (_("GDB internal error, type is NULL in stabsread.c."));
   2068       return error_type (pp, objfile);
   2069     }
   2070 
   2071   /* Size specified in a type attribute overrides any other size.  */
   2072   if (type_size != -1)
   2073     TYPE_LENGTH (type) = (type_size + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;
   2074 
   2075   return type;
   2076 }
   2077 
   2078 /* RS/6000 xlc/dbx combination uses a set of builtin types, starting from -1.
   2080    Return the proper type node for a given builtin type number.  */
   2081 
   2082 static const struct objfile_data *rs6000_builtin_type_data;
   2083 
   2084 static struct type *
   2085 rs6000_builtin_type (int typenum, struct objfile *objfile)
   2086 {
   2087   struct type **negative_types
   2088     = (struct type **) objfile_data (objfile, rs6000_builtin_type_data);
   2089 
   2090   /* We recognize types numbered from -NUMBER_RECOGNIZED to -1.  */
   2091 #define NUMBER_RECOGNIZED 34
   2092   struct type *rettype = NULL;
   2093 
   2094   if (typenum >= 0 || typenum < -NUMBER_RECOGNIZED)
   2095     {
   2096       complaint (_("Unknown builtin type %d"), typenum);
   2097       return objfile_type (objfile)->builtin_error;
   2098     }
   2099 
   2100   if (!negative_types)
   2101     {
   2102       /* This includes an empty slot for type number -0.  */
   2103       negative_types = OBSTACK_CALLOC (&objfile->objfile_obstack,
   2104 				       NUMBER_RECOGNIZED + 1, struct type *);
   2105       set_objfile_data (objfile, rs6000_builtin_type_data, negative_types);
   2106     }
   2107 
   2108   if (negative_types[-typenum] != NULL)
   2109     return negative_types[-typenum];
   2110 
   2111 #if TARGET_CHAR_BIT != 8
   2112 #error This code wrong for TARGET_CHAR_BIT not 8
   2113   /* These definitions all assume that TARGET_CHAR_BIT is 8.  I think
   2114      that if that ever becomes not true, the correct fix will be to
   2115      make the size in the struct type to be in bits, not in units of
   2116      TARGET_CHAR_BIT.  */
   2117 #endif
   2118 
   2119   switch (-typenum)
   2120     {
   2121     case 1:
   2122       /* The size of this and all the other types are fixed, defined
   2123          by the debugging format.  If there is a type called "int" which
   2124          is other than 32 bits, then it should use a new negative type
   2125          number (or avoid negative type numbers for that case).
   2126          See stabs.texinfo.  */
   2127       rettype = init_integer_type (objfile, 32, 0, "int");
   2128       break;
   2129     case 2:
   2130       rettype = init_integer_type (objfile, 8, 0, "char");
   2131       TYPE_NOSIGN (rettype) = 1;
   2132       break;
   2133     case 3:
   2134       rettype = init_integer_type (objfile, 16, 0, "short");
   2135       break;
   2136     case 4:
   2137       rettype = init_integer_type (objfile, 32, 0, "long");
   2138       break;
   2139     case 5:
   2140       rettype = init_integer_type (objfile, 8, 1, "unsigned char");
   2141       break;
   2142     case 6:
   2143       rettype = init_integer_type (objfile, 8, 0, "signed char");
   2144       break;
   2145     case 7:
   2146       rettype = init_integer_type (objfile, 16, 1, "unsigned short");
   2147       break;
   2148     case 8:
   2149       rettype = init_integer_type (objfile, 32, 1, "unsigned int");
   2150       break;
   2151     case 9:
   2152       rettype = init_integer_type (objfile, 32, 1, "unsigned");
   2153       break;
   2154     case 10:
   2155       rettype = init_integer_type (objfile, 32, 1, "unsigned long");
   2156       break;
   2157     case 11:
   2158       rettype = init_type (objfile, TYPE_CODE_VOID, TARGET_CHAR_BIT, "void");
   2159       break;
   2160     case 12:
   2161       /* IEEE single precision (32 bit).  */
   2162       rettype = init_float_type (objfile, 32, "float",
   2163 				 floatformats_ieee_single);
   2164       break;
   2165     case 13:
   2166       /* IEEE double precision (64 bit).  */
   2167       rettype = init_float_type (objfile, 64, "double",
   2168 				 floatformats_ieee_double);
   2169       break;
   2170     case 14:
   2171       /* This is an IEEE double on the RS/6000, and different machines with
   2172          different sizes for "long double" should use different negative
   2173          type numbers.  See stabs.texinfo.  */
   2174       rettype = init_float_type (objfile, 64, "long double",
   2175 				 floatformats_ieee_double);
   2176       break;
   2177     case 15:
   2178       rettype = init_integer_type (objfile, 32, 0, "integer");
   2179       break;
   2180     case 16:
   2181       rettype = init_boolean_type (objfile, 32, 1, "boolean");
   2182       break;
   2183     case 17:
   2184       rettype = init_float_type (objfile, 32, "short real",
   2185 				 floatformats_ieee_single);
   2186       break;
   2187     case 18:
   2188       rettype = init_float_type (objfile, 64, "real",
   2189 				 floatformats_ieee_double);
   2190       break;
   2191     case 19:
   2192       rettype = init_type (objfile, TYPE_CODE_ERROR, 0, "stringptr");
   2193       break;
   2194     case 20:
   2195       rettype = init_character_type (objfile, 8, 1, "character");
   2196       break;
   2197     case 21:
   2198       rettype = init_boolean_type (objfile, 8, 1, "logical*1");
   2199       break;
   2200     case 22:
   2201       rettype = init_boolean_type (objfile, 16, 1, "logical*2");
   2202       break;
   2203     case 23:
   2204       rettype = init_boolean_type (objfile, 32, 1, "logical*4");
   2205       break;
   2206     case 24:
   2207       rettype = init_boolean_type (objfile, 32, 1, "logical");
   2208       break;
   2209     case 25:
   2210       /* Complex type consisting of two IEEE single precision values.  */
   2211       rettype = init_complex_type (objfile, "complex",
   2212 				   rs6000_builtin_type (12, objfile));
   2213       break;
   2214     case 26:
   2215       /* Complex type consisting of two IEEE double precision values.  */
   2216       rettype = init_complex_type (objfile, "double complex",
   2217 				   rs6000_builtin_type (13, objfile));
   2218       break;
   2219     case 27:
   2220       rettype = init_integer_type (objfile, 8, 0, "integer*1");
   2221       break;
   2222     case 28:
   2223       rettype = init_integer_type (objfile, 16, 0, "integer*2");
   2224       break;
   2225     case 29:
   2226       rettype = init_integer_type (objfile, 32, 0, "integer*4");
   2227       break;
   2228     case 30:
   2229       rettype = init_character_type (objfile, 16, 0, "wchar");
   2230       break;
   2231     case 31:
   2232       rettype = init_integer_type (objfile, 64, 0, "long long");
   2233       break;
   2234     case 32:
   2235       rettype = init_integer_type (objfile, 64, 1, "unsigned long long");
   2236       break;
   2237     case 33:
   2238       rettype = init_integer_type (objfile, 64, 1, "logical*8");
   2239       break;
   2240     case 34:
   2241       rettype = init_integer_type (objfile, 64, 0, "integer*8");
   2242       break;
   2243     }
   2244   negative_types[-typenum] = rettype;
   2245   return rettype;
   2246 }
   2247 
   2248 /* This page contains subroutines of read_type.  */
   2250 
   2251 /* Wrapper around method_name_from_physname to flag a complaint
   2252    if there is an error.  */
   2253 
   2254 static char *
   2255 stabs_method_name_from_physname (const char *physname)
   2256 {
   2257   char *method_name;
   2258 
   2259   method_name = method_name_from_physname (physname);
   2260 
   2261   if (method_name == NULL)
   2262     {
   2263       complaint (_("Method has bad physname %s\n"), physname);
   2264       return NULL;
   2265     }
   2266 
   2267   return method_name;
   2268 }
   2269 
   2270 /* Read member function stabs info for C++ classes.  The form of each member
   2271    function data is:
   2272 
   2273    NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
   2274 
   2275    An example with two member functions is:
   2276 
   2277    afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
   2278 
   2279    For the case of overloaded operators, the format is op$::*.funcs, where
   2280    $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
   2281    name (such as `+=') and `.' marks the end of the operator name.
   2282 
   2283    Returns 1 for success, 0 for failure.  */
   2284 
   2285 static int
   2286 read_member_functions (struct field_info *fip, const char **pp,
   2287 		       struct type *type, struct objfile *objfile)
   2288 {
   2289   int nfn_fields = 0;
   2290   int length = 0;
   2291   int i;
   2292   struct next_fnfield
   2293     {
   2294       struct next_fnfield *next;
   2295       struct fn_field fn_field;
   2296     }
   2297    *sublist;
   2298   struct type *look_ahead_type;
   2299   struct next_fnfieldlist *new_fnlist;
   2300   struct next_fnfield *new_sublist;
   2301   char *main_fn_name;
   2302   const char *p;
   2303 
   2304   /* Process each list until we find something that is not a member function
   2305      or find the end of the functions.  */
   2306 
   2307   while (**pp != ';')
   2308     {
   2309       /* We should be positioned at the start of the function name.
   2310          Scan forward to find the first ':' and if it is not the
   2311          first of a "::" delimiter, then this is not a member function.  */
   2312       p = *pp;
   2313       while (*p != ':')
   2314 	{
   2315 	  p++;
   2316 	}
   2317       if (p[1] != ':')
   2318 	{
   2319 	  break;
   2320 	}
   2321 
   2322       sublist = NULL;
   2323       look_ahead_type = NULL;
   2324       length = 0;
   2325 
   2326       new_fnlist = XCNEW (struct next_fnfieldlist);
   2327       make_cleanup (xfree, new_fnlist);
   2328 
   2329       if ((*pp)[0] == 'o' && (*pp)[1] == 'p' && is_cplus_marker ((*pp)[2]))
   2330 	{
   2331 	  /* This is a completely wierd case.  In order to stuff in the
   2332 	     names that might contain colons (the usual name delimiter),
   2333 	     Mike Tiemann defined a different name format which is
   2334 	     signalled if the identifier is "op$".  In that case, the
   2335 	     format is "op$::XXXX." where XXXX is the name.  This is
   2336 	     used for names like "+" or "=".  YUUUUUUUK!  FIXME!  */
   2337 	  /* This lets the user type "break operator+".
   2338 	     We could just put in "+" as the name, but that wouldn't
   2339 	     work for "*".  */
   2340 	  static char opname[32] = "op$";
   2341 	  char *o = opname + 3;
   2342 
   2343 	  /* Skip past '::'.  */
   2344 	  *pp = p + 2;
   2345 
   2346 	  STABS_CONTINUE (pp, objfile);
   2347 	  p = *pp;
   2348 	  while (*p != '.')
   2349 	    {
   2350 	      *o++ = *p++;
   2351 	    }
   2352 	  main_fn_name = savestring (opname, o - opname);
   2353 	  /* Skip past '.'  */
   2354 	  *pp = p + 1;
   2355 	}
   2356       else
   2357 	{
   2358 	  main_fn_name = savestring (*pp, p - *pp);
   2359 	  /* Skip past '::'.  */
   2360 	  *pp = p + 2;
   2361 	}
   2362       new_fnlist->fn_fieldlist.name = main_fn_name;
   2363 
   2364       do
   2365 	{
   2366 	  new_sublist = XCNEW (struct next_fnfield);
   2367 	  make_cleanup (xfree, new_sublist);
   2368 
   2369 	  /* Check for and handle cretinous dbx symbol name continuation!  */
   2370 	  if (look_ahead_type == NULL)
   2371 	    {
   2372 	      /* Normal case.  */
   2373 	      STABS_CONTINUE (pp, objfile);
   2374 
   2375 	      new_sublist->fn_field.type = read_type (pp, objfile);
   2376 	      if (**pp != ':')
   2377 		{
   2378 		  /* Invalid symtab info for member function.  */
   2379 		  return 0;
   2380 		}
   2381 	    }
   2382 	  else
   2383 	    {
   2384 	      /* g++ version 1 kludge */
   2385 	      new_sublist->fn_field.type = look_ahead_type;
   2386 	      look_ahead_type = NULL;
   2387 	    }
   2388 
   2389 	  (*pp)++;
   2390 	  p = *pp;
   2391 	  while (*p != ';')
   2392 	    {
   2393 	      p++;
   2394 	    }
   2395 
   2396 	  /* These are methods, not functions.  */
   2397 	  if (TYPE_CODE (new_sublist->fn_field.type) == TYPE_CODE_FUNC)
   2398 	    TYPE_CODE (new_sublist->fn_field.type) = TYPE_CODE_METHOD;
   2399 	  else
   2400 	    gdb_assert (TYPE_CODE (new_sublist->fn_field.type)
   2401 			== TYPE_CODE_METHOD);
   2402 
   2403 	  /* If this is just a stub, then we don't have the real name here.  */
   2404 	  if (TYPE_STUB (new_sublist->fn_field.type))
   2405 	    {
   2406 	      if (!TYPE_SELF_TYPE (new_sublist->fn_field.type))
   2407 		set_type_self_type (new_sublist->fn_field.type, type);
   2408 	      new_sublist->fn_field.is_stub = 1;
   2409 	    }
   2410 
   2411 	  new_sublist->fn_field.physname = savestring (*pp, p - *pp);
   2412 	  *pp = p + 1;
   2413 
   2414 	  /* Set this member function's visibility fields.  */
   2415 	  switch (*(*pp)++)
   2416 	    {
   2417 	    case VISIBILITY_PRIVATE:
   2418 	      new_sublist->fn_field.is_private = 1;
   2419 	      break;
   2420 	    case VISIBILITY_PROTECTED:
   2421 	      new_sublist->fn_field.is_protected = 1;
   2422 	      break;
   2423 	    }
   2424 
   2425 	  STABS_CONTINUE (pp, objfile);
   2426 	  switch (**pp)
   2427 	    {
   2428 	    case 'A':		/* Normal functions.  */
   2429 	      new_sublist->fn_field.is_const = 0;
   2430 	      new_sublist->fn_field.is_volatile = 0;
   2431 	      (*pp)++;
   2432 	      break;
   2433 	    case 'B':		/* `const' member functions.  */
   2434 	      new_sublist->fn_field.is_const = 1;
   2435 	      new_sublist->fn_field.is_volatile = 0;
   2436 	      (*pp)++;
   2437 	      break;
   2438 	    case 'C':		/* `volatile' member function.  */
   2439 	      new_sublist->fn_field.is_const = 0;
   2440 	      new_sublist->fn_field.is_volatile = 1;
   2441 	      (*pp)++;
   2442 	      break;
   2443 	    case 'D':		/* `const volatile' member function.  */
   2444 	      new_sublist->fn_field.is_const = 1;
   2445 	      new_sublist->fn_field.is_volatile = 1;
   2446 	      (*pp)++;
   2447 	      break;
   2448 	    case '*':		/* File compiled with g++ version 1 --
   2449 				   no info.  */
   2450 	    case '?':
   2451 	    case '.':
   2452 	      break;
   2453 	    default:
   2454 	      complaint (_("const/volatile indicator missing, got '%c'"),
   2455 			 **pp);
   2456 	      break;
   2457 	    }
   2458 
   2459 	  switch (*(*pp)++)
   2460 	    {
   2461 	    case '*':
   2462 	      {
   2463 		int nbits;
   2464 		/* virtual member function, followed by index.
   2465 		   The sign bit is set to distinguish pointers-to-methods
   2466 		   from virtual function indicies.  Since the array is
   2467 		   in words, the quantity must be shifted left by 1
   2468 		   on 16 bit machine, and by 2 on 32 bit machine, forcing
   2469 		   the sign bit out, and usable as a valid index into
   2470 		   the array.  Remove the sign bit here.  */
   2471 		new_sublist->fn_field.voffset =
   2472 		  (0x7fffffff & read_huge_number (pp, ';', &nbits, 0)) + 2;
   2473 		if (nbits != 0)
   2474 		  return 0;
   2475 
   2476 		STABS_CONTINUE (pp, objfile);
   2477 		if (**pp == ';' || **pp == '\0')
   2478 		  {
   2479 		    /* Must be g++ version 1.  */
   2480 		    new_sublist->fn_field.fcontext = 0;
   2481 		  }
   2482 		else
   2483 		  {
   2484 		    /* Figure out from whence this virtual function came.
   2485 		       It may belong to virtual function table of
   2486 		       one of its baseclasses.  */
   2487 		    look_ahead_type = read_type (pp, objfile);
   2488 		    if (**pp == ':')
   2489 		      {
   2490 			/* g++ version 1 overloaded methods.  */
   2491 		      }
   2492 		    else
   2493 		      {
   2494 			new_sublist->fn_field.fcontext = look_ahead_type;
   2495 			if (**pp != ';')
   2496 			  {
   2497 			    return 0;
   2498 			  }
   2499 			else
   2500 			  {
   2501 			    ++*pp;
   2502 			  }
   2503 			look_ahead_type = NULL;
   2504 		      }
   2505 		  }
   2506 		break;
   2507 	      }
   2508 	    case '?':
   2509 	      /* static member function.  */
   2510 	      {
   2511 		int slen = strlen (main_fn_name);
   2512 
   2513 		new_sublist->fn_field.voffset = VOFFSET_STATIC;
   2514 
   2515 		/* For static member functions, we can't tell if they
   2516 		   are stubbed, as they are put out as functions, and not as
   2517 		   methods.
   2518 		   GCC v2 emits the fully mangled name if
   2519 		   dbxout.c:flag_minimal_debug is not set, so we have to
   2520 		   detect a fully mangled physname here and set is_stub
   2521 		   accordingly.  Fully mangled physnames in v2 start with
   2522 		   the member function name, followed by two underscores.
   2523 		   GCC v3 currently always emits stubbed member functions,
   2524 		   but with fully mangled physnames, which start with _Z.  */
   2525 		if (!(strncmp (new_sublist->fn_field.physname,
   2526 			       main_fn_name, slen) == 0
   2527 		      && new_sublist->fn_field.physname[slen] == '_'
   2528 		      && new_sublist->fn_field.physname[slen + 1] == '_'))
   2529 		  {
   2530 		    new_sublist->fn_field.is_stub = 1;
   2531 		  }
   2532 		break;
   2533 	      }
   2534 
   2535 	    default:
   2536 	      /* error */
   2537 	      complaint (_("member function type missing, got '%c'"),
   2538 			 (*pp)[-1]);
   2539 	      /* Normal member function.  */
   2540 	      /* Fall through.  */
   2541 
   2542 	    case '.':
   2543 	      /* normal member function.  */
   2544 	      new_sublist->fn_field.voffset = 0;
   2545 	      new_sublist->fn_field.fcontext = 0;
   2546 	      break;
   2547 	    }
   2548 
   2549 	  new_sublist->next = sublist;
   2550 	  sublist = new_sublist;
   2551 	  length++;
   2552 	  STABS_CONTINUE (pp, objfile);
   2553 	}
   2554       while (**pp != ';' && **pp != '\0');
   2555 
   2556       (*pp)++;
   2557       STABS_CONTINUE (pp, objfile);
   2558 
   2559       /* Skip GCC 3.X member functions which are duplicates of the callable
   2560 	 constructor/destructor.  */
   2561       if (strcmp_iw (main_fn_name, "__base_ctor ") == 0
   2562 	  || strcmp_iw (main_fn_name, "__base_dtor ") == 0
   2563 	  || strcmp (main_fn_name, "__deleting_dtor") == 0)
   2564 	{
   2565 	  xfree (main_fn_name);
   2566 	}
   2567       else
   2568 	{
   2569 	  int has_destructor = 0, has_other = 0;
   2570 	  int is_v3 = 0;
   2571 	  struct next_fnfield *tmp_sublist;
   2572 
   2573 	  /* Various versions of GCC emit various mostly-useless
   2574 	     strings in the name field for special member functions.
   2575 
   2576 	     For stub methods, we need to defer correcting the name
   2577 	     until we are ready to unstub the method, because the current
   2578 	     name string is used by gdb_mangle_name.  The only stub methods
   2579 	     of concern here are GNU v2 operators; other methods have their
   2580 	     names correct (see caveat below).
   2581 
   2582 	     For non-stub methods, in GNU v3, we have a complete physname.
   2583 	     Therefore we can safely correct the name now.  This primarily
   2584 	     affects constructors and destructors, whose name will be
   2585 	     __comp_ctor or __comp_dtor instead of Foo or ~Foo.  Cast
   2586 	     operators will also have incorrect names; for instance,
   2587 	     "operator int" will be named "operator i" (i.e. the type is
   2588 	     mangled).
   2589 
   2590 	     For non-stub methods in GNU v2, we have no easy way to
   2591 	     know if we have a complete physname or not.  For most
   2592 	     methods the result depends on the platform (if CPLUS_MARKER
   2593 	     can be `$' or `.', it will use minimal debug information, or
   2594 	     otherwise the full physname will be included).
   2595 
   2596 	     Rather than dealing with this, we take a different approach.
   2597 	     For v3 mangled names, we can use the full physname; for v2,
   2598 	     we use cplus_demangle_opname (which is actually v2 specific),
   2599 	     because the only interesting names are all operators - once again
   2600 	     barring the caveat below.  Skip this process if any method in the
   2601 	     group is a stub, to prevent our fouling up the workings of
   2602 	     gdb_mangle_name.
   2603 
   2604 	     The caveat: GCC 2.95.x (and earlier?) put constructors and
   2605 	     destructors in the same method group.  We need to split this
   2606 	     into two groups, because they should have different names.
   2607 	     So for each method group we check whether it contains both
   2608 	     routines whose physname appears to be a destructor (the physnames
   2609 	     for and destructors are always provided, due to quirks in v2
   2610 	     mangling) and routines whose physname does not appear to be a
   2611 	     destructor.  If so then we break up the list into two halves.
   2612 	     Even if the constructors and destructors aren't in the same group
   2613 	     the destructor will still lack the leading tilde, so that also
   2614 	     needs to be fixed.
   2615 
   2616 	     So, to summarize what we expect and handle here:
   2617 
   2618 	        Given         Given          Real         Real       Action
   2619 	     method name     physname      physname   method name
   2620 
   2621 	     __opi            [none]     __opi__3Foo  operator int    opname
   2622 	                                                         [now or later]
   2623 	     Foo              _._3Foo       _._3Foo      ~Foo      separate and
   2624 	                                                               rename
   2625 	     operator i     _ZN3FoocviEv _ZN3FoocviEv operator int    demangle
   2626 	     __comp_ctor  _ZN3FooC1ERKS_ _ZN3FooC1ERKS_   Foo         demangle
   2627 	  */
   2628 
   2629 	  tmp_sublist = sublist;
   2630 	  while (tmp_sublist != NULL)
   2631 	    {
   2632 	      if (tmp_sublist->fn_field.physname[0] == '_'
   2633 		  && tmp_sublist->fn_field.physname[1] == 'Z')
   2634 		is_v3 = 1;
   2635 
   2636 	      if (is_destructor_name (tmp_sublist->fn_field.physname))
   2637 		has_destructor++;
   2638 	      else
   2639 		has_other++;
   2640 
   2641 	      tmp_sublist = tmp_sublist->next;
   2642 	    }
   2643 
   2644 	  if (has_destructor && has_other)
   2645 	    {
   2646 	      struct next_fnfieldlist *destr_fnlist;
   2647 	      struct next_fnfield *last_sublist;
   2648 
   2649 	      /* Create a new fn_fieldlist for the destructors.  */
   2650 
   2651 	      destr_fnlist = XCNEW (struct next_fnfieldlist);
   2652 	      make_cleanup (xfree, destr_fnlist);
   2653 
   2654 	      destr_fnlist->fn_fieldlist.name
   2655 		= obconcat (&objfile->objfile_obstack, "~",
   2656 			    new_fnlist->fn_fieldlist.name, (char *) NULL);
   2657 
   2658 	      destr_fnlist->fn_fieldlist.fn_fields =
   2659 		XOBNEWVEC (&objfile->objfile_obstack,
   2660 			   struct fn_field, has_destructor);
   2661 	      memset (destr_fnlist->fn_fieldlist.fn_fields, 0,
   2662 		  sizeof (struct fn_field) * has_destructor);
   2663 	      tmp_sublist = sublist;
   2664 	      last_sublist = NULL;
   2665 	      i = 0;
   2666 	      while (tmp_sublist != NULL)
   2667 		{
   2668 		  if (!is_destructor_name (tmp_sublist->fn_field.physname))
   2669 		    {
   2670 		      tmp_sublist = tmp_sublist->next;
   2671 		      continue;
   2672 		    }
   2673 
   2674 		  destr_fnlist->fn_fieldlist.fn_fields[i++]
   2675 		    = tmp_sublist->fn_field;
   2676 		  if (last_sublist)
   2677 		    last_sublist->next = tmp_sublist->next;
   2678 		  else
   2679 		    sublist = tmp_sublist->next;
   2680 		  last_sublist = tmp_sublist;
   2681 		  tmp_sublist = tmp_sublist->next;
   2682 		}
   2683 
   2684 	      destr_fnlist->fn_fieldlist.length = has_destructor;
   2685 	      destr_fnlist->next = fip->fnlist;
   2686 	      fip->fnlist = destr_fnlist;
   2687 	      nfn_fields++;
   2688 	      length -= has_destructor;
   2689 	    }
   2690 	  else if (is_v3)
   2691 	    {
   2692 	      /* v3 mangling prevents the use of abbreviated physnames,
   2693 		 so we can do this here.  There are stubbed methods in v3
   2694 		 only:
   2695 		 - in -gstabs instead of -gstabs+
   2696 		 - or for static methods, which are output as a function type
   2697 		   instead of a method type.  */
   2698 	      char *new_method_name =
   2699 		stabs_method_name_from_physname (sublist->fn_field.physname);
   2700 
   2701 	      if (new_method_name != NULL
   2702 		  && strcmp (new_method_name,
   2703 			     new_fnlist->fn_fieldlist.name) != 0)
   2704 		{
   2705 		  new_fnlist->fn_fieldlist.name = new_method_name;
   2706 		  xfree (main_fn_name);
   2707 		}
   2708 	      else
   2709 		xfree (new_method_name);
   2710 	    }
   2711 	  else if (has_destructor && new_fnlist->fn_fieldlist.name[0] != '~')
   2712 	    {
   2713 	      new_fnlist->fn_fieldlist.name =
   2714 		obconcat (&objfile->objfile_obstack,
   2715 			  "~", main_fn_name, (char *)NULL);
   2716 	      xfree (main_fn_name);
   2717 	    }
   2718 
   2719 	  new_fnlist->fn_fieldlist.fn_fields
   2720 	    = OBSTACK_CALLOC (&objfile->objfile_obstack, length, fn_field);
   2721 	  for (i = length; (i--, sublist); sublist = sublist->next)
   2722 	    {
   2723 	      new_fnlist->fn_fieldlist.fn_fields[i] = sublist->fn_field;
   2724 	    }
   2725 
   2726 	  new_fnlist->fn_fieldlist.length = length;
   2727 	  new_fnlist->next = fip->fnlist;
   2728 	  fip->fnlist = new_fnlist;
   2729 	  nfn_fields++;
   2730 	}
   2731     }
   2732 
   2733   if (nfn_fields)
   2734     {
   2735       ALLOCATE_CPLUS_STRUCT_TYPE (type);
   2736       TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
   2737 	TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * nfn_fields);
   2738       memset (TYPE_FN_FIELDLISTS (type), 0,
   2739 	      sizeof (struct fn_fieldlist) * nfn_fields);
   2740       TYPE_NFN_FIELDS (type) = nfn_fields;
   2741     }
   2742 
   2743   return 1;
   2744 }
   2745 
   2746 /* Special GNU C++ name.
   2747 
   2748    Returns 1 for success, 0 for failure.  "failure" means that we can't
   2749    keep parsing and it's time for error_type().  */
   2750 
   2751 static int
   2752 read_cpp_abbrev (struct field_info *fip, const char **pp, struct type *type,
   2753 		 struct objfile *objfile)
   2754 {
   2755   const char *p;
   2756   const char *name;
   2757   char cpp_abbrev;
   2758   struct type *context;
   2759 
   2760   p = *pp;
   2761   if (*++p == 'v')
   2762     {
   2763       name = NULL;
   2764       cpp_abbrev = *++p;
   2765 
   2766       *pp = p + 1;
   2767 
   2768       /* At this point, *pp points to something like "22:23=*22...",
   2769          where the type number before the ':' is the "context" and
   2770          everything after is a regular type definition.  Lookup the
   2771          type, find it's name, and construct the field name.  */
   2772 
   2773       context = read_type (pp, objfile);
   2774 
   2775       switch (cpp_abbrev)
   2776 	{
   2777 	case 'f':		/* $vf -- a virtual function table pointer */
   2778 	  name = TYPE_NAME (context);
   2779 	  if (name == NULL)
   2780 	    {
   2781 	      name = "";
   2782 	    }
   2783 	  fip->list->field.name = obconcat (&objfile->objfile_obstack,
   2784 					    vptr_name, name, (char *) NULL);
   2785 	  break;
   2786 
   2787 	case 'b':		/* $vb -- a virtual bsomethingorother */
   2788 	  name = TYPE_NAME (context);
   2789 	  if (name == NULL)
   2790 	    {
   2791 	      complaint (_("C++ abbreviated type name "
   2792 			   "unknown at symtab pos %d"),
   2793 			 symnum);
   2794 	      name = "FOO";
   2795 	    }
   2796 	  fip->list->field.name = obconcat (&objfile->objfile_obstack, vb_name,
   2797 					    name, (char *) NULL);
   2798 	  break;
   2799 
   2800 	default:
   2801 	  invalid_cpp_abbrev_complaint (*pp);
   2802 	  fip->list->field.name = obconcat (&objfile->objfile_obstack,
   2803 					    "INVALID_CPLUSPLUS_ABBREV",
   2804 					    (char *) NULL);
   2805 	  break;
   2806 	}
   2807 
   2808       /* At this point, *pp points to the ':'.  Skip it and read the
   2809          field type.  */
   2810 
   2811       p = ++(*pp);
   2812       if (p[-1] != ':')
   2813 	{
   2814 	  invalid_cpp_abbrev_complaint (*pp);
   2815 	  return 0;
   2816 	}
   2817       fip->list->field.type = read_type (pp, objfile);
   2818       if (**pp == ',')
   2819 	(*pp)++;		/* Skip the comma.  */
   2820       else
   2821 	return 0;
   2822 
   2823       {
   2824 	int nbits;
   2825 
   2826 	SET_FIELD_BITPOS (fip->list->field,
   2827 			  read_huge_number (pp, ';', &nbits, 0));
   2828 	if (nbits != 0)
   2829 	  return 0;
   2830       }
   2831       /* This field is unpacked.  */
   2832       FIELD_BITSIZE (fip->list->field) = 0;
   2833       fip->list->visibility = VISIBILITY_PRIVATE;
   2834     }
   2835   else
   2836     {
   2837       invalid_cpp_abbrev_complaint (*pp);
   2838       /* We have no idea what syntax an unrecognized abbrev would have, so
   2839          better return 0.  If we returned 1, we would need to at least advance
   2840          *pp to avoid an infinite loop.  */
   2841       return 0;
   2842     }
   2843   return 1;
   2844 }
   2845 
   2846 static void
   2847 read_one_struct_field (struct field_info *fip, const char **pp, const char *p,
   2848 		       struct type *type, struct objfile *objfile)
   2849 {
   2850   struct gdbarch *gdbarch = get_objfile_arch (objfile);
   2851 
   2852   fip->list->field.name
   2853     = (const char *) obstack_copy0 (&objfile->objfile_obstack, *pp, p - *pp);
   2854   *pp = p + 1;
   2855 
   2856   /* This means we have a visibility for a field coming.  */
   2857   if (**pp == '/')
   2858     {
   2859       (*pp)++;
   2860       fip->list->visibility = *(*pp)++;
   2861     }
   2862   else
   2863     {
   2864       /* normal dbx-style format, no explicit visibility */
   2865       fip->list->visibility = VISIBILITY_PUBLIC;
   2866     }
   2867 
   2868   fip->list->field.type = read_type (pp, objfile);
   2869   if (**pp == ':')
   2870     {
   2871       p = ++(*pp);
   2872 #if 0
   2873       /* Possible future hook for nested types.  */
   2874       if (**pp == '!')
   2875 	{
   2876 	  fip->list->field.bitpos = (long) -2;	/* nested type */
   2877 	  p = ++(*pp);
   2878 	}
   2879       else
   2880 	...;
   2881 #endif
   2882       while (*p != ';')
   2883 	{
   2884 	  p++;
   2885 	}
   2886       /* Static class member.  */
   2887       SET_FIELD_PHYSNAME (fip->list->field, savestring (*pp, p - *pp));
   2888       *pp = p + 1;
   2889       return;
   2890     }
   2891   else if (**pp != ',')
   2892     {
   2893       /* Bad structure-type format.  */
   2894       stabs_general_complaint ("bad structure-type format");
   2895       return;
   2896     }
   2897 
   2898   (*pp)++;			/* Skip the comma.  */
   2899 
   2900   {
   2901     int nbits;
   2902 
   2903     SET_FIELD_BITPOS (fip->list->field,
   2904 		      read_huge_number (pp, ',', &nbits, 0));
   2905     if (nbits != 0)
   2906       {
   2907 	stabs_general_complaint ("bad structure-type format");
   2908 	return;
   2909       }
   2910     FIELD_BITSIZE (fip->list->field) = read_huge_number (pp, ';', &nbits, 0);
   2911     if (nbits != 0)
   2912       {
   2913 	stabs_general_complaint ("bad structure-type format");
   2914 	return;
   2915       }
   2916   }
   2917 
   2918   if (FIELD_BITPOS (fip->list->field) == 0
   2919       && FIELD_BITSIZE (fip->list->field) == 0)
   2920     {
   2921       /* This can happen in two cases: (1) at least for gcc 2.4.5 or so,
   2922          it is a field which has been optimized out.  The correct stab for
   2923          this case is to use VISIBILITY_IGNORE, but that is a recent
   2924          invention.  (2) It is a 0-size array.  For example
   2925          union { int num; char str[0]; } foo.  Printing _("<no value>" for
   2926          str in "p foo" is OK, since foo.str (and thus foo.str[3])
   2927          will continue to work, and a 0-size array as a whole doesn't
   2928          have any contents to print.
   2929 
   2930          I suspect this probably could also happen with gcc -gstabs (not
   2931          -gstabs+) for static fields, and perhaps other C++ extensions.
   2932          Hopefully few people use -gstabs with gdb, since it is intended
   2933          for dbx compatibility.  */
   2934 
   2935       /* Ignore this field.  */
   2936       fip->list->visibility = VISIBILITY_IGNORE;
   2937     }
   2938   else
   2939     {
   2940       /* Detect an unpacked field and mark it as such.
   2941          dbx gives a bit size for all fields.
   2942          Note that forward refs cannot be packed,
   2943          and treat enums as if they had the width of ints.  */
   2944 
   2945       struct type *field_type = check_typedef (FIELD_TYPE (fip->list->field));
   2946 
   2947       if (TYPE_CODE (field_type) != TYPE_CODE_INT
   2948 	  && TYPE_CODE (field_type) != TYPE_CODE_RANGE
   2949 	  && TYPE_CODE (field_type) != TYPE_CODE_BOOL
   2950 	  && TYPE_CODE (field_type) != TYPE_CODE_ENUM)
   2951 	{
   2952 	  FIELD_BITSIZE (fip->list->field) = 0;
   2953 	}
   2954       if ((FIELD_BITSIZE (fip->list->field)
   2955 	   == TARGET_CHAR_BIT * TYPE_LENGTH (field_type)
   2956 	   || (TYPE_CODE (field_type) == TYPE_CODE_ENUM
   2957 	       && FIELD_BITSIZE (fip->list->field)
   2958 		  == gdbarch_int_bit (gdbarch))
   2959 	  )
   2960 	  &&
   2961 	  FIELD_BITPOS (fip->list->field) % 8 == 0)
   2962 	{
   2963 	  FIELD_BITSIZE (fip->list->field) = 0;
   2964 	}
   2965     }
   2966 }
   2967 
   2968 
   2969 /* Read struct or class data fields.  They have the form:
   2970 
   2971    NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
   2972 
   2973    At the end, we see a semicolon instead of a field.
   2974 
   2975    In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
   2976    a static field.
   2977 
   2978    The optional VISIBILITY is one of:
   2979 
   2980    '/0' (VISIBILITY_PRIVATE)
   2981    '/1' (VISIBILITY_PROTECTED)
   2982    '/2' (VISIBILITY_PUBLIC)
   2983    '/9' (VISIBILITY_IGNORE)
   2984 
   2985    or nothing, for C style fields with public visibility.
   2986 
   2987    Returns 1 for success, 0 for failure.  */
   2988 
   2989 static int
   2990 read_struct_fields (struct field_info *fip, const char **pp, struct type *type,
   2991 		    struct objfile *objfile)
   2992 {
   2993   const char *p;
   2994   struct nextfield *newobj;
   2995 
   2996   /* We better set p right now, in case there are no fields at all...    */
   2997 
   2998   p = *pp;
   2999 
   3000   /* Read each data member type until we find the terminating ';' at the end of
   3001      the data member list, or break for some other reason such as finding the
   3002      start of the member function list.  */
   3003   /* Stab string for structure/union does not end with two ';' in
   3004      SUN C compiler 5.3 i.e. F6U2, hence check for end of string.  */
   3005 
   3006   while (**pp != ';' && **pp != '\0')
   3007     {
   3008       STABS_CONTINUE (pp, objfile);
   3009       /* Get space to record the next field's data.  */
   3010       newobj = XCNEW (struct nextfield);
   3011       make_cleanup (xfree, newobj);
   3012 
   3013       newobj->next = fip->list;
   3014       fip->list = newobj;
   3015 
   3016       /* Get the field name.  */
   3017       p = *pp;
   3018 
   3019       /* If is starts with CPLUS_MARKER it is a special abbreviation,
   3020          unless the CPLUS_MARKER is followed by an underscore, in
   3021          which case it is just the name of an anonymous type, which we
   3022          should handle like any other type name.  */
   3023 
   3024       if (is_cplus_marker (p[0]) && p[1] != '_')
   3025 	{
   3026 	  if (!read_cpp_abbrev (fip, pp, type, objfile))
   3027 	    return 0;
   3028 	  continue;
   3029 	}
   3030 
   3031       /* Look for the ':' that separates the field name from the field
   3032          values.  Data members are delimited by a single ':', while member
   3033          functions are delimited by a pair of ':'s.  When we hit the member
   3034          functions (if any), terminate scan loop and return.  */
   3035 
   3036       while (*p != ':' && *p != '\0')
   3037 	{
   3038 	  p++;
   3039 	}
   3040       if (*p == '\0')
   3041 	return 0;
   3042 
   3043       /* Check to see if we have hit the member functions yet.  */
   3044       if (p[1] == ':')
   3045 	{
   3046 	  break;
   3047 	}
   3048       read_one_struct_field (fip, pp, p, type, objfile);
   3049     }
   3050   if (p[0] == ':' && p[1] == ':')
   3051     {
   3052       /* (the deleted) chill the list of fields: the last entry (at
   3053          the head) is a partially constructed entry which we now
   3054          scrub.  */
   3055       fip->list = fip->list->next;
   3056     }
   3057   return 1;
   3058 }
   3059 /* *INDENT-OFF* */
   3060 /* The stabs for C++ derived classes contain baseclass information which
   3061    is marked by a '!' character after the total size.  This function is
   3062    called when we encounter the baseclass marker, and slurps up all the
   3063    baseclass information.
   3064 
   3065    Immediately following the '!' marker is the number of base classes that
   3066    the class is derived from, followed by information for each base class.
   3067    For each base class, there are two visibility specifiers, a bit offset
   3068    to the base class information within the derived class, a reference to
   3069    the type for the base class, and a terminating semicolon.
   3070 
   3071    A typical example, with two base classes, would be "!2,020,19;0264,21;".
   3072    						       ^^ ^ ^ ^  ^ ^  ^
   3073 	Baseclass information marker __________________|| | | |  | |  |
   3074 	Number of baseclasses __________________________| | | |  | |  |
   3075 	Visibility specifiers (2) ________________________| | |  | |  |
   3076 	Offset in bits from start of class _________________| |  | |  |
   3077 	Type number for base class ___________________________|  | |  |
   3078 	Visibility specifiers (2) _______________________________| |  |
   3079 	Offset in bits from start of class ________________________|  |
   3080 	Type number of base class ____________________________________|
   3081 
   3082   Return 1 for success, 0 for (error-type-inducing) failure.  */
   3083 /* *INDENT-ON* */
   3084 
   3085 
   3086 
   3087 static int
   3088 read_baseclasses (struct field_info *fip, const char **pp, struct type *type,
   3089 		  struct objfile *objfile)
   3090 {
   3091   int i;
   3092   struct nextfield *newobj;
   3093 
   3094   if (**pp != '!')
   3095     {
   3096       return 1;
   3097     }
   3098   else
   3099     {
   3100       /* Skip the '!' baseclass information marker.  */
   3101       (*pp)++;
   3102     }
   3103 
   3104   ALLOCATE_CPLUS_STRUCT_TYPE (type);
   3105   {
   3106     int nbits;
   3107 
   3108     TYPE_N_BASECLASSES (type) = read_huge_number (pp, ',', &nbits, 0);
   3109     if (nbits != 0)
   3110       return 0;
   3111   }
   3112 
   3113 #if 0
   3114   /* Some stupid compilers have trouble with the following, so break
   3115      it up into simpler expressions.  */
   3116   TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *)
   3117     TYPE_ALLOC (type, B_BYTES (TYPE_N_BASECLASSES (type)));
   3118 #else
   3119   {
   3120     int num_bytes = B_BYTES (TYPE_N_BASECLASSES (type));
   3121     char *pointer;
   3122 
   3123     pointer = (char *) TYPE_ALLOC (type, num_bytes);
   3124     TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) pointer;
   3125   }
   3126 #endif /* 0 */
   3127 
   3128   B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), TYPE_N_BASECLASSES (type));
   3129 
   3130   for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
   3131     {
   3132       newobj = XCNEW (struct nextfield);
   3133       make_cleanup (xfree, newobj);
   3134 
   3135       newobj->next = fip->list;
   3136       fip->list = newobj;
   3137       FIELD_BITSIZE (newobj->field) = 0;	/* This should be an unpacked
   3138 					   field!  */
   3139 
   3140       STABS_CONTINUE (pp, objfile);
   3141       switch (**pp)
   3142 	{
   3143 	case '0':
   3144 	  /* Nothing to do.  */
   3145 	  break;
   3146 	case '1':
   3147 	  SET_TYPE_FIELD_VIRTUAL (type, i);
   3148 	  break;
   3149 	default:
   3150 	  /* Unknown character.  Complain and treat it as non-virtual.  */
   3151 	  {
   3152 	    complaint (_("Unknown virtual character `%c' for baseclass"),
   3153 		       **pp);
   3154 	  }
   3155 	}
   3156       ++(*pp);
   3157 
   3158       newobj->visibility = *(*pp)++;
   3159       switch (newobj->visibility)
   3160 	{
   3161 	case VISIBILITY_PRIVATE:
   3162 	case VISIBILITY_PROTECTED:
   3163 	case VISIBILITY_PUBLIC:
   3164 	  break;
   3165 	default:
   3166 	  /* Bad visibility format.  Complain and treat it as
   3167 	     public.  */
   3168 	  {
   3169 	    complaint (_("Unknown visibility `%c' for baseclass"),
   3170 		       newobj->visibility);
   3171 	    newobj->visibility = VISIBILITY_PUBLIC;
   3172 	  }
   3173 	}
   3174 
   3175       {
   3176 	int nbits;
   3177 
   3178 	/* The remaining value is the bit offset of the portion of the object
   3179 	   corresponding to this baseclass.  Always zero in the absence of
   3180 	   multiple inheritance.  */
   3181 
   3182 	SET_FIELD_BITPOS (newobj->field, read_huge_number (pp, ',', &nbits, 0));
   3183 	if (nbits != 0)
   3184 	  return 0;
   3185       }
   3186 
   3187       /* The last piece of baseclass information is the type of the
   3188          base class.  Read it, and remember it's type name as this
   3189          field's name.  */
   3190 
   3191       newobj->field.type = read_type (pp, objfile);
   3192       newobj->field.name = TYPE_NAME (newobj->field.type);
   3193 
   3194       /* Skip trailing ';' and bump count of number of fields seen.  */
   3195       if (**pp == ';')
   3196 	(*pp)++;
   3197       else
   3198 	return 0;
   3199     }
   3200   return 1;
   3201 }
   3202 
   3203 /* The tail end of stabs for C++ classes that contain a virtual function
   3204    pointer contains a tilde, a %, and a type number.
   3205    The type number refers to the base class (possibly this class itself) which
   3206    contains the vtable pointer for the current class.
   3207 
   3208    This function is called when we have parsed all the method declarations,
   3209    so we can look for the vptr base class info.  */
   3210 
   3211 static int
   3212 read_tilde_fields (struct field_info *fip, const char **pp, struct type *type,
   3213 		   struct objfile *objfile)
   3214 {
   3215   const char *p;
   3216 
   3217   STABS_CONTINUE (pp, objfile);
   3218 
   3219   /* If we are positioned at a ';', then skip it.  */
   3220   if (**pp == ';')
   3221     {
   3222       (*pp)++;
   3223     }
   3224 
   3225   if (**pp == '~')
   3226     {
   3227       (*pp)++;
   3228 
   3229       if (**pp == '=' || **pp == '+' || **pp == '-')
   3230 	{
   3231 	  /* Obsolete flags that used to indicate the presence
   3232 	     of constructors and/or destructors.  */
   3233 	  (*pp)++;
   3234 	}
   3235 
   3236       /* Read either a '%' or the final ';'.  */
   3237       if (*(*pp)++ == '%')
   3238 	{
   3239 	  /* The next number is the type number of the base class
   3240 	     (possibly our own class) which supplies the vtable for
   3241 	     this class.  Parse it out, and search that class to find
   3242 	     its vtable pointer, and install those into TYPE_VPTR_BASETYPE
   3243 	     and TYPE_VPTR_FIELDNO.  */
   3244 
   3245 	  struct type *t;
   3246 	  int i;
   3247 
   3248 	  t = read_type (pp, objfile);
   3249 	  p = (*pp)++;
   3250 	  while (*p != '\0' && *p != ';')
   3251 	    {
   3252 	      p++;
   3253 	    }
   3254 	  if (*p == '\0')
   3255 	    {
   3256 	      /* Premature end of symbol.  */
   3257 	      return 0;
   3258 	    }
   3259 
   3260 	  set_type_vptr_basetype (type, t);
   3261 	  if (type == t)	/* Our own class provides vtbl ptr.  */
   3262 	    {
   3263 	      for (i = TYPE_NFIELDS (t) - 1;
   3264 		   i >= TYPE_N_BASECLASSES (t);
   3265 		   --i)
   3266 		{
   3267 		  const char *name = TYPE_FIELD_NAME (t, i);
   3268 
   3269 		  if (!strncmp (name, vptr_name, sizeof (vptr_name) - 2)
   3270 		      && is_cplus_marker (name[sizeof (vptr_name) - 2]))
   3271 		    {
   3272 		      set_type_vptr_fieldno (type, i);
   3273 		      goto gotit;
   3274 		    }
   3275 		}
   3276 	      /* Virtual function table field not found.  */
   3277 	      complaint (_("virtual function table pointer "
   3278 			   "not found when defining class `%s'"),
   3279 			 TYPE_NAME (type));
   3280 	      return 0;
   3281 	    }
   3282 	  else
   3283 	    {
   3284 	      set_type_vptr_fieldno (type, TYPE_VPTR_FIELDNO (t));
   3285 	    }
   3286 
   3287 	gotit:
   3288 	  *pp = p + 1;
   3289 	}
   3290     }
   3291   return 1;
   3292 }
   3293 
   3294 static int
   3295 attach_fn_fields_to_type (struct field_info *fip, struct type *type)
   3296 {
   3297   int n;
   3298 
   3299   for (n = TYPE_NFN_FIELDS (type);
   3300        fip->fnlist != NULL;
   3301        fip->fnlist = fip->fnlist->next)
   3302     {
   3303       --n;			/* Circumvent Sun3 compiler bug.  */
   3304       TYPE_FN_FIELDLISTS (type)[n] = fip->fnlist->fn_fieldlist;
   3305     }
   3306   return 1;
   3307 }
   3308 
   3309 /* Create the vector of fields, and record how big it is.
   3310    We need this info to record proper virtual function table information
   3311    for this class's virtual functions.  */
   3312 
   3313 static int
   3314 attach_fields_to_type (struct field_info *fip, struct type *type,
   3315 		       struct objfile *objfile)
   3316 {
   3317   int nfields = 0;
   3318   int non_public_fields = 0;
   3319   struct nextfield *scan;
   3320 
   3321   /* Count up the number of fields that we have, as well as taking note of
   3322      whether or not there are any non-public fields, which requires us to
   3323      allocate and build the private_field_bits and protected_field_bits
   3324      bitfields.  */
   3325 
   3326   for (scan = fip->list; scan != NULL; scan = scan->next)
   3327     {
   3328       nfields++;
   3329       if (scan->visibility != VISIBILITY_PUBLIC)
   3330 	{
   3331 	  non_public_fields++;
   3332 	}
   3333     }
   3334 
   3335   /* Now we know how many fields there are, and whether or not there are any
   3336      non-public fields.  Record the field count, allocate space for the
   3337      array of fields, and create blank visibility bitfields if necessary.  */
   3338 
   3339   TYPE_NFIELDS (type) = nfields;
   3340   TYPE_FIELDS (type) = (struct field *)
   3341     TYPE_ALLOC (type, sizeof (struct field) * nfields);
   3342   memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
   3343 
   3344   if (non_public_fields)
   3345     {
   3346       ALLOCATE_CPLUS_STRUCT_TYPE (type);
   3347 
   3348       TYPE_FIELD_PRIVATE_BITS (type) =
   3349 	(B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
   3350       B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
   3351 
   3352       TYPE_FIELD_PROTECTED_BITS (type) =
   3353 	(B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
   3354       B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
   3355 
   3356       TYPE_FIELD_IGNORE_BITS (type) =
   3357 	(B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
   3358       B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields);
   3359     }
   3360 
   3361   /* Copy the saved-up fields into the field vector.  Start from the
   3362      head of the list, adding to the tail of the field array, so that
   3363      they end up in the same order in the array in which they were
   3364      added to the list.  */
   3365 
   3366   while (nfields-- > 0)
   3367     {
   3368       TYPE_FIELD (type, nfields) = fip->list->field;
   3369       switch (fip->list->visibility)
   3370 	{
   3371 	case VISIBILITY_PRIVATE:
   3372 	  SET_TYPE_FIELD_PRIVATE (type, nfields);
   3373 	  break;
   3374 
   3375 	case VISIBILITY_PROTECTED:
   3376 	  SET_TYPE_FIELD_PROTECTED (type, nfields);
   3377 	  break;
   3378 
   3379 	case VISIBILITY_IGNORE:
   3380 	  SET_TYPE_FIELD_IGNORE (type, nfields);
   3381 	  break;
   3382 
   3383 	case VISIBILITY_PUBLIC:
   3384 	  break;
   3385 
   3386 	default:
   3387 	  /* Unknown visibility.  Complain and treat it as public.  */
   3388 	  {
   3389 	    complaint (_("Unknown visibility `%c' for field"),
   3390 		       fip->list->visibility);
   3391 	  }
   3392 	  break;
   3393 	}
   3394       fip->list = fip->list->next;
   3395     }
   3396   return 1;
   3397 }
   3398 
   3399 
   3400 /* Complain that the compiler has emitted more than one definition for the
   3401    structure type TYPE.  */
   3402 static void
   3403 complain_about_struct_wipeout (struct type *type)
   3404 {
   3405   const char *name = "";
   3406   const char *kind = "";
   3407 
   3408   if (TYPE_NAME (type))
   3409     {
   3410       name = TYPE_NAME (type);
   3411       switch (TYPE_CODE (type))
   3412         {
   3413         case TYPE_CODE_STRUCT: kind = "struct "; break;
   3414         case TYPE_CODE_UNION:  kind = "union ";  break;
   3415         case TYPE_CODE_ENUM:   kind = "enum ";   break;
   3416         default: kind = "";
   3417         }
   3418     }
   3419   else
   3420     {
   3421       name = "<unknown>";
   3422       kind = "";
   3423     }
   3424 
   3425   complaint (_("struct/union type gets multiply defined: %s%s"), kind, name);
   3426 }
   3427 
   3428 /* Set the length for all variants of a same main_type, which are
   3429    connected in the closed chain.
   3430 
   3431    This is something that needs to be done when a type is defined *after*
   3432    some cross references to this type have already been read.  Consider
   3433    for instance the following scenario where we have the following two
   3434    stabs entries:
   3435 
   3436         .stabs  "t:p(0,21)=*(0,22)=k(0,23)=xsdummy:",160,0,28,-24
   3437         .stabs  "dummy:T(0,23)=s16x:(0,1),0,3[...]"
   3438 
   3439    A stubbed version of type dummy is created while processing the first
   3440    stabs entry.  The length of that type is initially set to zero, since
   3441    it is unknown at this point.  Also, a "constant" variation of type
   3442    "dummy" is created as well (this is the "(0,22)=k(0,23)" section of
   3443    the stabs line).
   3444 
   3445    The second stabs entry allows us to replace the stubbed definition
   3446    with the real definition.  However, we still need to adjust the length
   3447    of the "constant" variation of that type, as its length was left
   3448    untouched during the main type replacement...  */
   3449 
   3450 static void
   3451 set_length_in_type_chain (struct type *type)
   3452 {
   3453   struct type *ntype = TYPE_CHAIN (type);
   3454 
   3455   while (ntype != type)
   3456     {
   3457       if (TYPE_LENGTH(ntype) == 0)
   3458 	TYPE_LENGTH (ntype) = TYPE_LENGTH (type);
   3459       else
   3460         complain_about_struct_wipeout (ntype);
   3461       ntype = TYPE_CHAIN (ntype);
   3462     }
   3463 }
   3464 
   3465 /* Read the description of a structure (or union type) and return an object
   3466    describing the type.
   3467 
   3468    PP points to a character pointer that points to the next unconsumed token
   3469    in the stabs string.  For example, given stabs "A:T4=s4a:1,0,32;;",
   3470    *PP will point to "4a:1,0,32;;".
   3471 
   3472    TYPE points to an incomplete type that needs to be filled in.
   3473 
   3474    OBJFILE points to the current objfile from which the stabs information is
   3475    being read.  (Note that it is redundant in that TYPE also contains a pointer
   3476    to this same objfile, so it might be a good idea to eliminate it.  FIXME).
   3477  */
   3478 
   3479 static struct type *
   3480 read_struct_type (const char **pp, struct type *type, enum type_code type_code,
   3481                   struct objfile *objfile)
   3482 {
   3483   struct cleanup *back_to;
   3484   struct field_info fi;
   3485 
   3486   fi.list = NULL;
   3487   fi.fnlist = NULL;
   3488 
   3489   /* When describing struct/union/class types in stabs, G++ always drops
   3490      all qualifications from the name.  So if you've got:
   3491        struct A { ... struct B { ... }; ... };
   3492      then G++ will emit stabs for `struct A::B' that call it simply
   3493      `struct B'.  Obviously, if you've got a real top-level definition for
   3494      `struct B', or other nested definitions, this is going to cause
   3495      problems.
   3496 
   3497      Obviously, GDB can't fix this by itself, but it can at least avoid
   3498      scribbling on existing structure type objects when new definitions
   3499      appear.  */
   3500   if (! (TYPE_CODE (type) == TYPE_CODE_UNDEF
   3501          || TYPE_STUB (type)))
   3502     {
   3503       complain_about_struct_wipeout (type);
   3504 
   3505       /* It's probably best to return the type unchanged.  */
   3506       return type;
   3507     }
   3508 
   3509   back_to = make_cleanup (null_cleanup, 0);
   3510 
   3511   INIT_CPLUS_SPECIFIC (type);
   3512   TYPE_CODE (type) = type_code;
   3513   TYPE_STUB (type) = 0;
   3514 
   3515   /* First comes the total size in bytes.  */
   3516 
   3517   {
   3518     int nbits;
   3519 
   3520     TYPE_LENGTH (type) = read_huge_number (pp, 0, &nbits, 0);
   3521     if (nbits != 0)
   3522       {
   3523 	do_cleanups (back_to);
   3524 	return error_type (pp, objfile);
   3525       }
   3526     set_length_in_type_chain (type);
   3527   }
   3528 
   3529   /* Now read the baseclasses, if any, read the regular C struct or C++
   3530      class member fields, attach the fields to the type, read the C++
   3531      member functions, attach them to the type, and then read any tilde
   3532      field (baseclass specifier for the class holding the main vtable).  */
   3533 
   3534   if (!read_baseclasses (&fi, pp, type, objfile)
   3535       || !read_struct_fields (&fi, pp, type, objfile)
   3536       || !attach_fields_to_type (&fi, type, objfile)
   3537       || !read_member_functions (&fi, pp, type, objfile)
   3538       || !attach_fn_fields_to_type (&fi, type)
   3539       || !read_tilde_fields (&fi, pp, type, objfile))
   3540     {
   3541       type = error_type (pp, objfile);
   3542     }
   3543 
   3544   do_cleanups (back_to);
   3545   return (type);
   3546 }
   3547 
   3548 /* Read a definition of an array type,
   3549    and create and return a suitable type object.
   3550    Also creates a range type which represents the bounds of that
   3551    array.  */
   3552 
   3553 static struct type *
   3554 read_array_type (const char **pp, struct type *type,
   3555 		 struct objfile *objfile)
   3556 {
   3557   struct type *index_type, *element_type, *range_type;
   3558   int lower, upper;
   3559   int adjustable = 0;
   3560   int nbits;
   3561 
   3562   /* Format of an array type:
   3563      "ar<index type>;lower;upper;<array_contents_type>".
   3564      OS9000: "arlower,upper;<array_contents_type>".
   3565 
   3566      Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
   3567      for these, produce a type like float[][].  */
   3568 
   3569     {
   3570       index_type = read_type (pp, objfile);
   3571       if (**pp != ';')
   3572 	/* Improper format of array type decl.  */
   3573 	return error_type (pp, objfile);
   3574       ++*pp;
   3575     }
   3576 
   3577   if (!(**pp >= '0' && **pp <= '9') && **pp != '-')
   3578     {
   3579       (*pp)++;
   3580       adjustable = 1;
   3581     }
   3582   lower = read_huge_number (pp, ';', &nbits, 0);
   3583 
   3584   if (nbits != 0)
   3585     return error_type (pp, objfile);
   3586 
   3587   if (!(**pp >= '0' && **pp <= '9') && **pp != '-')
   3588     {
   3589       (*pp)++;
   3590       adjustable = 1;
   3591     }
   3592   upper = read_huge_number (pp, ';', &nbits, 0);
   3593   if (nbits != 0)
   3594     return error_type (pp, objfile);
   3595 
   3596   element_type = read_type (pp, objfile);
   3597 
   3598   if (adjustable)
   3599     {
   3600       lower = 0;
   3601       upper = -1;
   3602     }
   3603 
   3604   range_type =
   3605     create_static_range_type ((struct type *) NULL, index_type, lower, upper);
   3606   type = create_array_type (type, element_type, range_type);
   3607 
   3608   return type;
   3609 }
   3610 
   3611 
   3612 /* Read a definition of an enumeration type,
   3613    and create and return a suitable type object.
   3614    Also defines the symbols that represent the values of the type.  */
   3615 
   3616 static struct type *
   3617 read_enum_type (const char **pp, struct type *type,
   3618 		struct objfile *objfile)
   3619 {
   3620   struct gdbarch *gdbarch = get_objfile_arch (objfile);
   3621   const char *p;
   3622   char *name;
   3623   long n;
   3624   struct symbol *sym;
   3625   int nsyms = 0;
   3626   struct pending **symlist;
   3627   struct pending *osyms, *syms;
   3628   int o_nsyms;
   3629   int nbits;
   3630   int unsigned_enum = 1;
   3631 
   3632 #if 0
   3633   /* FIXME!  The stabs produced by Sun CC merrily define things that ought
   3634      to be file-scope, between N_FN entries, using N_LSYM.  What's a mother
   3635      to do?  For now, force all enum values to file scope.  */
   3636   if (within_function)
   3637     symlist = get_local_symbols ();
   3638   else
   3639 #endif
   3640     symlist = get_file_symbols ();
   3641   osyms = *symlist;
   3642   o_nsyms = osyms ? osyms->nsyms : 0;
   3643 
   3644   /* The aix4 compiler emits an extra field before the enum members;
   3645      my guess is it's a type of some sort.  Just ignore it.  */
   3646   if (**pp == '-')
   3647     {
   3648       /* Skip over the type.  */
   3649       while (**pp != ':')
   3650 	(*pp)++;
   3651 
   3652       /* Skip over the colon.  */
   3653       (*pp)++;
   3654     }
   3655 
   3656   /* Read the value-names and their values.
   3657      The input syntax is NAME:VALUE,NAME:VALUE, and so on.
   3658      A semicolon or comma instead of a NAME means the end.  */
   3659   while (**pp && **pp != ';' && **pp != ',')
   3660     {
   3661       STABS_CONTINUE (pp, objfile);
   3662       p = *pp;
   3663       while (*p != ':')
   3664 	p++;
   3665       name = (char *) obstack_copy0 (&objfile->objfile_obstack, *pp, p - *pp);
   3666       *pp = p + 1;
   3667       n = read_huge_number (pp, ',', &nbits, 0);
   3668       if (nbits != 0)
   3669 	return error_type (pp, objfile);
   3670 
   3671       sym = allocate_symbol (objfile);
   3672       SYMBOL_SET_LINKAGE_NAME (sym, name);
   3673       SYMBOL_SET_LANGUAGE (sym, get_current_subfile ()->language,
   3674 			   &objfile->objfile_obstack);
   3675       SYMBOL_ACLASS_INDEX (sym) = LOC_CONST;
   3676       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
   3677       SYMBOL_VALUE (sym) = n;
   3678       if (n < 0)
   3679 	unsigned_enum = 0;
   3680       add_symbol_to_list (sym, symlist);
   3681       nsyms++;
   3682     }
   3683 
   3684   if (**pp == ';')
   3685     (*pp)++;			/* Skip the semicolon.  */
   3686 
   3687   /* Now fill in the fields of the type-structure.  */
   3688 
   3689   TYPE_LENGTH (type) = gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT;
   3690   set_length_in_type_chain (type);
   3691   TYPE_CODE (type) = TYPE_CODE_ENUM;
   3692   TYPE_STUB (type) = 0;
   3693   if (unsigned_enum)
   3694     TYPE_UNSIGNED (type) = 1;
   3695   TYPE_NFIELDS (type) = nsyms;
   3696   TYPE_FIELDS (type) = (struct field *)
   3697     TYPE_ALLOC (type, sizeof (struct field) * nsyms);
   3698   memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nsyms);
   3699 
   3700   /* Find the symbols for the values and put them into the type.
   3701      The symbols can be found in the symlist that we put them on
   3702      to cause them to be defined.  osyms contains the old value
   3703      of that symlist; everything up to there was defined by us.  */
   3704   /* Note that we preserve the order of the enum constants, so
   3705      that in something like "enum {FOO, LAST_THING=FOO}" we print
   3706      FOO, not LAST_THING.  */
   3707 
   3708   for (syms = *symlist, n = nsyms - 1; syms; syms = syms->next)
   3709     {
   3710       int last = syms == osyms ? o_nsyms : 0;
   3711       int j = syms->nsyms;
   3712 
   3713       for (; --j >= last; --n)
   3714 	{
   3715 	  struct symbol *xsym = syms->symbol[j];
   3716 
   3717 	  SYMBOL_TYPE (xsym) = type;
   3718 	  TYPE_FIELD_NAME (type, n) = SYMBOL_LINKAGE_NAME (xsym);
   3719 	  SET_FIELD_ENUMVAL (TYPE_FIELD (type, n), SYMBOL_VALUE (xsym));
   3720 	  TYPE_FIELD_BITSIZE (type, n) = 0;
   3721 	}
   3722       if (syms == osyms)
   3723 	break;
   3724     }
   3725 
   3726   return type;
   3727 }
   3728 
   3729 /* Sun's ACC uses a somewhat saner method for specifying the builtin
   3730    typedefs in every file (for int, long, etc):
   3731 
   3732    type = b <signed> <width> <format type>; <offset>; <nbits>
   3733    signed = u or s.
   3734    optional format type = c or b for char or boolean.
   3735    offset = offset from high order bit to start bit of type.
   3736    width is # bytes in object of this type, nbits is # bits in type.
   3737 
   3738    The width/offset stuff appears to be for small objects stored in
   3739    larger ones (e.g. `shorts' in `int' registers).  We ignore it for now,
   3740    FIXME.  */
   3741 
   3742 static struct type *
   3743 read_sun_builtin_type (const char **pp, int typenums[2], struct objfile *objfile)
   3744 {
   3745   int type_bits;
   3746   int nbits;
   3747   int unsigned_type;
   3748   int boolean_type = 0;
   3749 
   3750   switch (**pp)
   3751     {
   3752     case 's':
   3753       unsigned_type = 0;
   3754       break;
   3755     case 'u':
   3756       unsigned_type = 1;
   3757       break;
   3758     default:
   3759       return error_type (pp, objfile);
   3760     }
   3761   (*pp)++;
   3762 
   3763   /* For some odd reason, all forms of char put a c here.  This is strange
   3764      because no other type has this honor.  We can safely ignore this because
   3765      we actually determine 'char'acterness by the number of bits specified in
   3766      the descriptor.
   3767      Boolean forms, e.g Fortran logical*X, put a b here.  */
   3768 
   3769   if (**pp == 'c')
   3770     (*pp)++;
   3771   else if (**pp == 'b')
   3772     {
   3773       boolean_type = 1;
   3774       (*pp)++;
   3775     }
   3776 
   3777   /* The first number appears to be the number of bytes occupied
   3778      by this type, except that unsigned short is 4 instead of 2.
   3779      Since this information is redundant with the third number,
   3780      we will ignore it.  */
   3781   read_huge_number (pp, ';', &nbits, 0);
   3782   if (nbits != 0)
   3783     return error_type (pp, objfile);
   3784 
   3785   /* The second number is always 0, so ignore it too.  */
   3786   read_huge_number (pp, ';', &nbits, 0);
   3787   if (nbits != 0)
   3788     return error_type (pp, objfile);
   3789 
   3790   /* The third number is the number of bits for this type.  */
   3791   type_bits = read_huge_number (pp, 0, &nbits, 0);
   3792   if (nbits != 0)
   3793     return error_type (pp, objfile);
   3794   /* The type *should* end with a semicolon.  If it are embedded
   3795      in a larger type the semicolon may be the only way to know where
   3796      the type ends.  If this type is at the end of the stabstring we
   3797      can deal with the omitted semicolon (but we don't have to like
   3798      it).  Don't bother to complain(), Sun's compiler omits the semicolon
   3799      for "void".  */
   3800   if (**pp == ';')
   3801     ++(*pp);
   3802 
   3803   if (type_bits == 0)
   3804     {
   3805       struct type *type = init_type (objfile, TYPE_CODE_VOID,
   3806 				     TARGET_CHAR_BIT, NULL);
   3807       if (unsigned_type)
   3808         TYPE_UNSIGNED (type) = 1;
   3809       return type;
   3810     }
   3811 
   3812   if (boolean_type)
   3813     return init_boolean_type (objfile, type_bits, unsigned_type, NULL);
   3814   else
   3815     return init_integer_type (objfile, type_bits, unsigned_type, NULL);
   3816 }
   3817 
   3818 static struct type *
   3819 read_sun_floating_type (const char **pp, int typenums[2],
   3820 			struct objfile *objfile)
   3821 {
   3822   int nbits;
   3823   int details;
   3824   int nbytes;
   3825   struct type *rettype;
   3826 
   3827   /* The first number has more details about the type, for example
   3828      FN_COMPLEX.  */
   3829   details = read_huge_number (pp, ';', &nbits, 0);
   3830   if (nbits != 0)
   3831     return error_type (pp, objfile);
   3832 
   3833   /* The second number is the number of bytes occupied by this type.  */
   3834   nbytes = read_huge_number (pp, ';', &nbits, 0);
   3835   if (nbits != 0)
   3836     return error_type (pp, objfile);
   3837 
   3838   nbits = nbytes * TARGET_CHAR_BIT;
   3839 
   3840   if (details == NF_COMPLEX || details == NF_COMPLEX16
   3841       || details == NF_COMPLEX32)
   3842     {
   3843       rettype = dbx_init_float_type (objfile, nbits / 2);
   3844       return init_complex_type (objfile, NULL, rettype);
   3845     }
   3846 
   3847   return dbx_init_float_type (objfile, nbits);
   3848 }
   3849 
   3850 /* Read a number from the string pointed to by *PP.
   3851    The value of *PP is advanced over the number.
   3852    If END is nonzero, the character that ends the
   3853    number must match END, or an error happens;
   3854    and that character is skipped if it does match.
   3855    If END is zero, *PP is left pointing to that character.
   3856 
   3857    If TWOS_COMPLEMENT_BITS is set to a strictly positive value and if
   3858    the number is represented in an octal representation, assume that
   3859    it is represented in a 2's complement representation with a size of
   3860    TWOS_COMPLEMENT_BITS.
   3861 
   3862    If the number fits in a long, set *BITS to 0 and return the value.
   3863    If not, set *BITS to be the number of bits in the number and return 0.
   3864 
   3865    If encounter garbage, set *BITS to -1 and return 0.  */
   3866 
   3867 static long
   3868 read_huge_number (const char **pp, int end, int *bits,
   3869 		  int twos_complement_bits)
   3870 {
   3871   const char *p = *pp;
   3872   int sign = 1;
   3873   int sign_bit = 0;
   3874   long n = 0;
   3875   int radix = 10;
   3876   char overflow = 0;
   3877   int nbits = 0;
   3878   int c;
   3879   long upper_limit;
   3880   int twos_complement_representation = 0;
   3881 
   3882   if (*p == '-')
   3883     {
   3884       sign = -1;
   3885       p++;
   3886     }
   3887 
   3888   /* Leading zero means octal.  GCC uses this to output values larger
   3889      than an int (because that would be hard in decimal).  */
   3890   if (*p == '0')
   3891     {
   3892       radix = 8;
   3893       p++;
   3894     }
   3895 
   3896   /* Skip extra zeros.  */
   3897   while (*p == '0')
   3898     p++;
   3899 
   3900   if (sign > 0 && radix == 8 && twos_complement_bits > 0)
   3901     {
   3902       /* Octal, possibly signed.  Check if we have enough chars for a
   3903 	 negative number.  */
   3904 
   3905       size_t len;
   3906       const char *p1 = p;
   3907 
   3908       while ((c = *p1) >= '0' && c < '8')
   3909 	p1++;
   3910 
   3911       len = p1 - p;
   3912       if (len > twos_complement_bits / 3
   3913 	  || (twos_complement_bits % 3 == 0
   3914 	      && len == twos_complement_bits / 3))
   3915 	{
   3916 	  /* Ok, we have enough characters for a signed value, check
   3917 	     for signness by testing if the sign bit is set.  */
   3918 	  sign_bit = (twos_complement_bits % 3 + 2) % 3;
   3919 	  c = *p - '0';
   3920 	  if (c & (1 << sign_bit))
   3921 	    {
   3922 	      /* Definitely signed.  */
   3923 	      twos_complement_representation = 1;
   3924 	      sign = -1;
   3925 	    }
   3926 	}
   3927     }
   3928 
   3929   upper_limit = LONG_MAX / radix;
   3930 
   3931   while ((c = *p++) >= '0' && c < ('0' + radix))
   3932     {
   3933       if (n <= upper_limit)
   3934         {
   3935           if (twos_complement_representation)
   3936             {
   3937 	      /* Octal, signed, twos complement representation.  In
   3938 		 this case, n is the corresponding absolute value.  */
   3939 	      if (n == 0)
   3940 		{
   3941 		  long sn = c - '0' - ((2 * (c - '0')) | (2 << sign_bit));
   3942 
   3943 		  n = -sn;
   3944 		}
   3945               else
   3946                 {
   3947                   n *= radix;
   3948                   n -= c - '0';
   3949                 }
   3950             }
   3951           else
   3952             {
   3953               /* unsigned representation */
   3954               n *= radix;
   3955               n += c - '0';		/* FIXME this overflows anyway.  */
   3956             }
   3957         }
   3958       else
   3959         overflow = 1;
   3960 
   3961       /* This depends on large values being output in octal, which is
   3962          what GCC does.  */
   3963       if (radix == 8)
   3964 	{
   3965 	  if (nbits == 0)
   3966 	    {
   3967 	      if (c == '0')
   3968 		/* Ignore leading zeroes.  */
   3969 		;
   3970 	      else if (c == '1')
   3971 		nbits = 1;
   3972 	      else if (c == '2' || c == '3')
   3973 		nbits = 2;
   3974 	      else
   3975 		nbits = 3;
   3976 	    }
   3977 	  else
   3978 	    nbits += 3;
   3979 	}
   3980     }
   3981   if (end)
   3982     {
   3983       if (c && c != end)
   3984 	{
   3985 	  if (bits != NULL)
   3986 	    *bits = -1;
   3987 	  return 0;
   3988 	}
   3989     }
   3990   else
   3991     --p;
   3992 
   3993   if (radix == 8 && twos_complement_bits > 0 && nbits > twos_complement_bits)
   3994     {
   3995       /* We were supposed to parse a number with maximum
   3996 	 TWOS_COMPLEMENT_BITS bits, but something went wrong.  */
   3997       if (bits != NULL)
   3998 	*bits = -1;
   3999       return 0;
   4000     }
   4001 
   4002   *pp = p;
   4003   if (overflow)
   4004     {
   4005       if (nbits == 0)
   4006 	{
   4007 	  /* Large decimal constants are an error (because it is hard to
   4008 	     count how many bits are in them).  */
   4009 	  if (bits != NULL)
   4010 	    *bits = -1;
   4011 	  return 0;
   4012 	}
   4013 
   4014       /* -0x7f is the same as 0x80.  So deal with it by adding one to
   4015          the number of bits.  Two's complement represention octals
   4016          can't have a '-' in front.  */
   4017       if (sign == -1 && !twos_complement_representation)
   4018 	++nbits;
   4019       if (bits)
   4020 	*bits = nbits;
   4021     }
   4022   else
   4023     {
   4024       if (bits)
   4025 	*bits = 0;
   4026       return n * sign;
   4027     }
   4028   /* It's *BITS which has the interesting information.  */
   4029   return 0;
   4030 }
   4031 
   4032 static struct type *
   4033 read_range_type (const char **pp, int typenums[2], int type_size,
   4034                  struct objfile *objfile)
   4035 {
   4036   struct gdbarch *gdbarch = get_objfile_arch (objfile);
   4037   const char *orig_pp = *pp;
   4038   int rangenums[2];
   4039   long n2, n3;
   4040   int n2bits, n3bits;
   4041   int self_subrange;
   4042   struct type *result_type;
   4043   struct type *index_type = NULL;
   4044 
   4045   /* First comes a type we are a subrange of.
   4046      In C it is usually 0, 1 or the type being defined.  */
   4047   if (read_type_number (pp, rangenums) != 0)
   4048     return error_type (pp, objfile);
   4049   self_subrange = (rangenums[0] == typenums[0] &&
   4050 		   rangenums[1] == typenums[1]);
   4051 
   4052   if (**pp == '=')
   4053     {
   4054       *pp = orig_pp;
   4055       index_type = read_type (pp, objfile);
   4056     }
   4057 
   4058   /* A semicolon should now follow; skip it.  */
   4059   if (**pp == ';')
   4060     (*pp)++;
   4061 
   4062   /* The remaining two operands are usually lower and upper bounds
   4063      of the range.  But in some special cases they mean something else.  */
   4064   n2 = read_huge_number (pp, ';', &n2bits, type_size);
   4065   n3 = read_huge_number (pp, ';', &n3bits, type_size);
   4066 
   4067   if (n2bits == -1 || n3bits == -1)
   4068     return error_type (pp, objfile);
   4069 
   4070   if (index_type)
   4071     goto handle_true_range;
   4072 
   4073   /* If limits are huge, must be large integral type.  */
   4074   if (n2bits != 0 || n3bits != 0)
   4075     {
   4076       char got_signed = 0;
   4077       char got_unsigned = 0;
   4078       /* Number of bits in the type.  */
   4079       int nbits = 0;
   4080 
   4081       /* If a type size attribute has been specified, the bounds of
   4082          the range should fit in this size.  If the lower bounds needs
   4083          more bits than the upper bound, then the type is signed.  */
   4084       if (n2bits <= type_size && n3bits <= type_size)
   4085         {
   4086           if (n2bits == type_size && n2bits > n3bits)
   4087             got_signed = 1;
   4088           else
   4089             got_unsigned = 1;
   4090           nbits = type_size;
   4091         }
   4092       /* Range from 0 to <large number> is an unsigned large integral type.  */
   4093       else if ((n2bits == 0 && n2 == 0) && n3bits != 0)
   4094 	{
   4095 	  got_unsigned = 1;
   4096 	  nbits = n3bits;
   4097 	}
   4098       /* Range from <large number> to <large number>-1 is a large signed
   4099          integral type.  Take care of the case where <large number> doesn't
   4100          fit in a long but <large number>-1 does.  */
   4101       else if ((n2bits != 0 && n3bits != 0 && n2bits == n3bits + 1)
   4102 	       || (n2bits != 0 && n3bits == 0
   4103 		   && (n2bits == sizeof (long) * HOST_CHAR_BIT)
   4104 		   && n3 == LONG_MAX))
   4105 	{
   4106 	  got_signed = 1;
   4107 	  nbits = n2bits;
   4108 	}
   4109 
   4110       if (got_signed || got_unsigned)
   4111 	return init_integer_type (objfile, nbits, got_unsigned, NULL);
   4112       else
   4113 	return error_type (pp, objfile);
   4114     }
   4115 
   4116   /* A type defined as a subrange of itself, with bounds both 0, is void.  */
   4117   if (self_subrange && n2 == 0 && n3 == 0)
   4118     return init_type (objfile, TYPE_CODE_VOID, TARGET_CHAR_BIT, NULL);
   4119 
   4120   /* If n3 is zero and n2 is positive, we want a floating type, and n2
   4121      is the width in bytes.
   4122 
   4123      Fortran programs appear to use this for complex types also.  To
   4124      distinguish between floats and complex, g77 (and others?)  seem
   4125      to use self-subranges for the complexes, and subranges of int for
   4126      the floats.
   4127 
   4128      Also note that for complexes, g77 sets n2 to the size of one of
   4129      the member floats, not the whole complex beast.  My guess is that
   4130      this was to work well with pre-COMPLEX versions of gdb.  */
   4131 
   4132   if (n3 == 0 && n2 > 0)
   4133     {
   4134       struct type *float_type
   4135 	= dbx_init_float_type (objfile, n2 * TARGET_CHAR_BIT);
   4136 
   4137       if (self_subrange)
   4138 	return init_complex_type (objfile, NULL, float_type);
   4139       else
   4140 	return float_type;
   4141     }
   4142 
   4143   /* If the upper bound is -1, it must really be an unsigned integral.  */
   4144 
   4145   else if (n2 == 0 && n3 == -1)
   4146     {
   4147       int bits = type_size;
   4148 
   4149       if (bits <= 0)
   4150 	{
   4151 	  /* We don't know its size.  It is unsigned int or unsigned
   4152 	     long.  GCC 2.3.3 uses this for long long too, but that is
   4153 	     just a GDB 3.5 compatibility hack.  */
   4154 	  bits = gdbarch_int_bit (gdbarch);
   4155 	}
   4156 
   4157       return init_integer_type (objfile, bits, 1, NULL);
   4158     }
   4159 
   4160   /* Special case: char is defined (Who knows why) as a subrange of
   4161      itself with range 0-127.  */
   4162   else if (self_subrange && n2 == 0 && n3 == 127)
   4163     {
   4164       struct type *type = init_integer_type (objfile, TARGET_CHAR_BIT,
   4165 					     0, NULL);
   4166       TYPE_NOSIGN (type) = 1;
   4167       return type;
   4168     }
   4169   /* We used to do this only for subrange of self or subrange of int.  */
   4170   else if (n2 == 0)
   4171     {
   4172       /* -1 is used for the upper bound of (4 byte) "unsigned int" and
   4173          "unsigned long", and we already checked for that,
   4174          so don't need to test for it here.  */
   4175 
   4176       if (n3 < 0)
   4177 	/* n3 actually gives the size.  */
   4178 	return init_integer_type (objfile, -n3 * TARGET_CHAR_BIT, 1, NULL);
   4179 
   4180       /* Is n3 == 2**(8n)-1 for some integer n?  Then it's an
   4181          unsigned n-byte integer.  But do require n to be a power of
   4182          two; we don't want 3- and 5-byte integers flying around.  */
   4183       {
   4184 	int bytes;
   4185 	unsigned long bits;
   4186 
   4187 	bits = n3;
   4188 	for (bytes = 0; (bits & 0xff) == 0xff; bytes++)
   4189 	  bits >>= 8;
   4190 	if (bits == 0
   4191 	    && ((bytes - 1) & bytes) == 0) /* "bytes is a power of two" */
   4192 	  return init_integer_type (objfile, bytes * TARGET_CHAR_BIT, 1, NULL);
   4193       }
   4194     }
   4195   /* I think this is for Convex "long long".  Since I don't know whether
   4196      Convex sets self_subrange, I also accept that particular size regardless
   4197      of self_subrange.  */
   4198   else if (n3 == 0 && n2 < 0
   4199 	   && (self_subrange
   4200 	       || n2 == -gdbarch_long_long_bit
   4201 			  (gdbarch) / TARGET_CHAR_BIT))
   4202     return init_integer_type (objfile, -n2 * TARGET_CHAR_BIT, 0, NULL);
   4203   else if (n2 == -n3 - 1)
   4204     {
   4205       if (n3 == 0x7f)
   4206 	return init_integer_type (objfile, 8, 0, NULL);
   4207       if (n3 == 0x7fff)
   4208 	return init_integer_type (objfile, 16, 0, NULL);
   4209       if (n3 == 0x7fffffff)
   4210 	return init_integer_type (objfile, 32, 0, NULL);
   4211     }
   4212 
   4213   /* We have a real range type on our hands.  Allocate space and
   4214      return a real pointer.  */
   4215 handle_true_range:
   4216 
   4217   if (self_subrange)
   4218     index_type = objfile_type (objfile)->builtin_int;
   4219   else
   4220     index_type = *dbx_lookup_type (rangenums, objfile);
   4221   if (index_type == NULL)
   4222     {
   4223       /* Does this actually ever happen?  Is that why we are worrying
   4224          about dealing with it rather than just calling error_type?  */
   4225 
   4226       complaint (_("base type %d of range type is not defined"), rangenums[1]);
   4227 
   4228       index_type = objfile_type (objfile)->builtin_int;
   4229     }
   4230 
   4231   result_type
   4232     = create_static_range_type ((struct type *) NULL, index_type, n2, n3);
   4233   return (result_type);
   4234 }
   4235 
   4236 /* Read in an argument list.  This is a list of types, separated by commas
   4237    and terminated with END.  Return the list of types read in, or NULL
   4238    if there is an error.  */
   4239 
   4240 static struct field *
   4241 read_args (const char **pp, int end, struct objfile *objfile, int *nargsp,
   4242 	   int *varargsp)
   4243 {
   4244   /* FIXME!  Remove this arbitrary limit!  */
   4245   struct type *types[1024];	/* Allow for fns of 1023 parameters.  */
   4246   int n = 0, i;
   4247   struct field *rval;
   4248 
   4249   while (**pp != end)
   4250     {
   4251       if (**pp != ',')
   4252 	/* Invalid argument list: no ','.  */
   4253 	return NULL;
   4254       (*pp)++;
   4255       STABS_CONTINUE (pp, objfile);
   4256       types[n++] = read_type (pp, objfile);
   4257     }
   4258   (*pp)++;			/* get past `end' (the ':' character).  */
   4259 
   4260   if (n == 0)
   4261     {
   4262       /* We should read at least the THIS parameter here.  Some broken stabs
   4263 	 output contained `(0,41),(0,42)=@s8;-16;,(0,43),(0,1);' where should
   4264 	 have been present ";-16,(0,43)" reference instead.  This way the
   4265 	 excessive ";" marker prematurely stops the parameters parsing.  */
   4266 
   4267       complaint (_("Invalid (empty) method arguments"));
   4268       *varargsp = 0;
   4269     }
   4270   else if (TYPE_CODE (types[n - 1]) != TYPE_CODE_VOID)
   4271     *varargsp = 1;
   4272   else
   4273     {
   4274       n--;
   4275       *varargsp = 0;
   4276     }
   4277 
   4278   rval = XCNEWVEC (struct field, n);
   4279   for (i = 0; i < n; i++)
   4280     rval[i].type = types[i];
   4281   *nargsp = n;
   4282   return rval;
   4283 }
   4284 
   4285 /* Common block handling.  */
   4287 
   4288 /* List of symbols declared since the last BCOMM.  This list is a tail
   4289    of local_symbols.  When ECOMM is seen, the symbols on the list
   4290    are noted so their proper addresses can be filled in later,
   4291    using the common block base address gotten from the assembler
   4292    stabs.  */
   4293 
   4294 static struct pending *common_block;
   4295 static int common_block_i;
   4296 
   4297 /* Name of the current common block.  We get it from the BCOMM instead of the
   4298    ECOMM to match IBM documentation (even though IBM puts the name both places
   4299    like everyone else).  */
   4300 static char *common_block_name;
   4301 
   4302 /* Process a N_BCOMM symbol.  The storage for NAME is not guaranteed
   4303    to remain after this function returns.  */
   4304 
   4305 void
   4306 common_block_start (const char *name, struct objfile *objfile)
   4307 {
   4308   if (common_block_name != NULL)
   4309     {
   4310       complaint (_("Invalid symbol data: common block within common block"));
   4311     }
   4312   common_block = *get_local_symbols ();
   4313   common_block_i = common_block ? common_block->nsyms : 0;
   4314   common_block_name = (char *) obstack_copy0 (&objfile->objfile_obstack, name,
   4315 					      strlen (name));
   4316 }
   4317 
   4318 /* Process a N_ECOMM symbol.  */
   4319 
   4320 void
   4321 common_block_end (struct objfile *objfile)
   4322 {
   4323   /* Symbols declared since the BCOMM are to have the common block
   4324      start address added in when we know it.  common_block and
   4325      common_block_i point to the first symbol after the BCOMM in
   4326      the local_symbols list; copy the list and hang it off the
   4327      symbol for the common block name for later fixup.  */
   4328   int i;
   4329   struct symbol *sym;
   4330   struct pending *newobj = 0;
   4331   struct pending *next;
   4332   int j;
   4333 
   4334   if (common_block_name == NULL)
   4335     {
   4336       complaint (_("ECOMM symbol unmatched by BCOMM"));
   4337       return;
   4338     }
   4339 
   4340   sym = allocate_symbol (objfile);
   4341   /* Note: common_block_name already saved on objfile_obstack.  */
   4342   SYMBOL_SET_LINKAGE_NAME (sym, common_block_name);
   4343   SYMBOL_ACLASS_INDEX (sym) = LOC_BLOCK;
   4344 
   4345   /* Now we copy all the symbols which have been defined since the BCOMM.  */
   4346 
   4347   /* Copy all the struct pendings before common_block.  */
   4348   for (next = *get_local_symbols ();
   4349        next != NULL && next != common_block;
   4350        next = next->next)
   4351     {
   4352       for (j = 0; j < next->nsyms; j++)
   4353 	add_symbol_to_list (next->symbol[j], &newobj);
   4354     }
   4355 
   4356   /* Copy however much of COMMON_BLOCK we need.  If COMMON_BLOCK is
   4357      NULL, it means copy all the local symbols (which we already did
   4358      above).  */
   4359 
   4360   if (common_block != NULL)
   4361     for (j = common_block_i; j < common_block->nsyms; j++)
   4362       add_symbol_to_list (common_block->symbol[j], &newobj);
   4363 
   4364   SYMBOL_TYPE (sym) = (struct type *) newobj;
   4365 
   4366   /* Should we be putting local_symbols back to what it was?
   4367      Does it matter?  */
   4368 
   4369   i = hashname (SYMBOL_LINKAGE_NAME (sym));
   4370   SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i];
   4371   global_sym_chain[i] = sym;
   4372   common_block_name = NULL;
   4373 }
   4374 
   4375 /* Add a common block's start address to the offset of each symbol
   4376    declared to be in it (by being between a BCOMM/ECOMM pair that uses
   4377    the common block name).  */
   4378 
   4379 static void
   4380 fix_common_block (struct symbol *sym, CORE_ADDR valu)
   4381 {
   4382   struct pending *next = (struct pending *) SYMBOL_TYPE (sym);
   4383 
   4384   for (; next; next = next->next)
   4385     {
   4386       int j;
   4387 
   4388       for (j = next->nsyms - 1; j >= 0; j--)
   4389 	SYMBOL_VALUE_ADDRESS (next->symbol[j]) += valu;
   4390     }
   4391 }
   4392 
   4393 
   4395 
   4396 /* Add {TYPE, TYPENUMS} to the NONAME_UNDEFS vector.
   4397    See add_undefined_type for more details.  */
   4398 
   4399 static void
   4400 add_undefined_type_noname (struct type *type, int typenums[2])
   4401 {
   4402   struct nat nat;
   4403 
   4404   nat.typenums[0] = typenums [0];
   4405   nat.typenums[1] = typenums [1];
   4406   nat.type = type;
   4407 
   4408   if (noname_undefs_length == noname_undefs_allocated)
   4409     {
   4410       noname_undefs_allocated *= 2;
   4411       noname_undefs = (struct nat *)
   4412 	xrealloc ((char *) noname_undefs,
   4413 		  noname_undefs_allocated * sizeof (struct nat));
   4414     }
   4415   noname_undefs[noname_undefs_length++] = nat;
   4416 }
   4417 
   4418 /* Add TYPE to the UNDEF_TYPES vector.
   4419    See add_undefined_type for more details.  */
   4420 
   4421 static void
   4422 add_undefined_type_1 (struct type *type)
   4423 {
   4424   if (undef_types_length == undef_types_allocated)
   4425     {
   4426       undef_types_allocated *= 2;
   4427       undef_types = (struct type **)
   4428 	xrealloc ((char *) undef_types,
   4429 		  undef_types_allocated * sizeof (struct type *));
   4430     }
   4431   undef_types[undef_types_length++] = type;
   4432 }
   4433 
   4434 /* What about types defined as forward references inside of a small lexical
   4435    scope?  */
   4436 /* Add a type to the list of undefined types to be checked through
   4437    once this file has been read in.
   4438 
   4439    In practice, we actually maintain two such lists: The first list
   4440    (UNDEF_TYPES) is used for types whose name has been provided, and
   4441    concerns forward references (eg 'xs' or 'xu' forward references);
   4442    the second list (NONAME_UNDEFS) is used for types whose name is
   4443    unknown at creation time, because they were referenced through
   4444    their type number before the actual type was declared.
   4445    This function actually adds the given type to the proper list.  */
   4446 
   4447 static void
   4448 add_undefined_type (struct type *type, int typenums[2])
   4449 {
   4450   if (TYPE_NAME (type) == NULL)
   4451     add_undefined_type_noname (type, typenums);
   4452   else
   4453     add_undefined_type_1 (type);
   4454 }
   4455 
   4456 /* Try to fix all undefined types pushed on the UNDEF_TYPES vector.  */
   4457 
   4458 static void
   4459 cleanup_undefined_types_noname (struct objfile *objfile)
   4460 {
   4461   int i;
   4462 
   4463   for (i = 0; i < noname_undefs_length; i++)
   4464     {
   4465       struct nat nat = noname_undefs[i];
   4466       struct type **type;
   4467 
   4468       type = dbx_lookup_type (nat.typenums, objfile);
   4469       if (nat.type != *type && TYPE_CODE (*type) != TYPE_CODE_UNDEF)
   4470         {
   4471           /* The instance flags of the undefined type are still unset,
   4472              and needs to be copied over from the reference type.
   4473              Since replace_type expects them to be identical, we need
   4474              to set these flags manually before hand.  */
   4475           TYPE_INSTANCE_FLAGS (nat.type) = TYPE_INSTANCE_FLAGS (*type);
   4476           replace_type (nat.type, *type);
   4477         }
   4478     }
   4479 
   4480   noname_undefs_length = 0;
   4481 }
   4482 
   4483 /* Go through each undefined type, see if it's still undefined, and fix it
   4484    up if possible.  We have two kinds of undefined types:
   4485 
   4486    TYPE_CODE_ARRAY:  Array whose target type wasn't defined yet.
   4487    Fix:  update array length using the element bounds
   4488    and the target type's length.
   4489    TYPE_CODE_STRUCT, TYPE_CODE_UNION:  Structure whose fields were not
   4490    yet defined at the time a pointer to it was made.
   4491    Fix:  Do a full lookup on the struct/union tag.  */
   4492 
   4493 static void
   4494 cleanup_undefined_types_1 (void)
   4495 {
   4496   struct type **type;
   4497 
   4498   /* Iterate over every undefined type, and look for a symbol whose type
   4499      matches our undefined type.  The symbol matches if:
   4500        1. It is a typedef in the STRUCT domain;
   4501        2. It has the same name, and same type code;
   4502        3. The instance flags are identical.
   4503 
   4504      It is important to check the instance flags, because we have seen
   4505      examples where the debug info contained definitions such as:
   4506 
   4507          "foo_t:t30=B31=xefoo_t:"
   4508 
   4509      In this case, we have created an undefined type named "foo_t" whose
   4510      instance flags is null (when processing "xefoo_t"), and then created
   4511      another type with the same name, but with different instance flags
   4512      ('B' means volatile).  I think that the definition above is wrong,
   4513      since the same type cannot be volatile and non-volatile at the same
   4514      time, but we need to be able to cope with it when it happens.  The
   4515      approach taken here is to treat these two types as different.  */
   4516 
   4517   for (type = undef_types; type < undef_types + undef_types_length; type++)
   4518     {
   4519       switch (TYPE_CODE (*type))
   4520 	{
   4521 
   4522 	case TYPE_CODE_STRUCT:
   4523 	case TYPE_CODE_UNION:
   4524 	case TYPE_CODE_ENUM:
   4525 	  {
   4526 	    /* Check if it has been defined since.  Need to do this here
   4527 	       as well as in check_typedef to deal with the (legitimate in
   4528 	       C though not C++) case of several types with the same name
   4529 	       in different source files.  */
   4530 	    if (TYPE_STUB (*type))
   4531 	      {
   4532 		struct pending *ppt;
   4533 		int i;
   4534 		/* Name of the type, without "struct" or "union".  */
   4535 		const char *type_name = TYPE_NAME (*type);
   4536 
   4537 		if (type_name == NULL)
   4538 		  {
   4539 		    complaint (_("need a type name"));
   4540 		    break;
   4541 		  }
   4542 		for (ppt = *get_file_symbols (); ppt; ppt = ppt->next)
   4543 		  {
   4544 		    for (i = 0; i < ppt->nsyms; i++)
   4545 		      {
   4546 			struct symbol *sym = ppt->symbol[i];
   4547 
   4548 			if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
   4549 			    && SYMBOL_DOMAIN (sym) == STRUCT_DOMAIN
   4550 			    && (TYPE_CODE (SYMBOL_TYPE (sym)) ==
   4551 				TYPE_CODE (*type))
   4552 			    && (TYPE_INSTANCE_FLAGS (*type) ==
   4553 				TYPE_INSTANCE_FLAGS (SYMBOL_TYPE (sym)))
   4554 			    && strcmp (SYMBOL_LINKAGE_NAME (sym),
   4555 				       type_name) == 0)
   4556                           replace_type (*type, SYMBOL_TYPE (sym));
   4557 		      }
   4558 		  }
   4559 	      }
   4560 	  }
   4561 	  break;
   4562 
   4563 	default:
   4564 	  {
   4565 	    complaint (_("forward-referenced types left unresolved, "
   4566                        "type code %d."),
   4567 		       TYPE_CODE (*type));
   4568 	  }
   4569 	  break;
   4570 	}
   4571     }
   4572 
   4573   undef_types_length = 0;
   4574 }
   4575 
   4576 /* Try to fix all the undefined types we ecountered while processing
   4577    this unit.  */
   4578 
   4579 void
   4580 cleanup_undefined_stabs_types (struct objfile *objfile)
   4581 {
   4582   cleanup_undefined_types_1 ();
   4583   cleanup_undefined_types_noname (objfile);
   4584 }
   4585 
   4586 /* See stabsread.h.  */
   4587 
   4588 void
   4589 scan_file_globals (struct objfile *objfile)
   4590 {
   4591   int hash;
   4592   struct symbol *sym, *prev;
   4593   struct objfile *resolve_objfile;
   4594 
   4595   /* SVR4 based linkers copy referenced global symbols from shared
   4596      libraries to the main executable.
   4597      If we are scanning the symbols for a shared library, try to resolve
   4598      them from the minimal symbols of the main executable first.  */
   4599 
   4600   if (symfile_objfile && objfile != symfile_objfile)
   4601     resolve_objfile = symfile_objfile;
   4602   else
   4603     resolve_objfile = objfile;
   4604 
   4605   while (1)
   4606     {
   4607       /* Avoid expensive loop through all minimal symbols if there are
   4608          no unresolved symbols.  */
   4609       for (hash = 0; hash < HASHSIZE; hash++)
   4610 	{
   4611 	  if (global_sym_chain[hash])
   4612 	    break;
   4613 	}
   4614       if (hash >= HASHSIZE)
   4615 	return;
   4616 
   4617       for (minimal_symbol *msymbol : resolve_objfile->msymbols ())
   4618 	{
   4619 	  QUIT;
   4620 
   4621 	  /* Skip static symbols.  */
   4622 	  switch (MSYMBOL_TYPE (msymbol))
   4623 	    {
   4624 	    case mst_file_text:
   4625 	    case mst_file_data:
   4626 	    case mst_file_bss:
   4627 	      continue;
   4628 	    default:
   4629 	      break;
   4630 	    }
   4631 
   4632 	  prev = NULL;
   4633 
   4634 	  /* Get the hash index and check all the symbols
   4635 	     under that hash index.  */
   4636 
   4637 	  hash = hashname (MSYMBOL_LINKAGE_NAME (msymbol));
   4638 
   4639 	  for (sym = global_sym_chain[hash]; sym;)
   4640 	    {
   4641 	      if (strcmp (MSYMBOL_LINKAGE_NAME (msymbol),
   4642 			  SYMBOL_LINKAGE_NAME (sym)) == 0)
   4643 		{
   4644 		  /* Splice this symbol out of the hash chain and
   4645 		     assign the value we have to it.  */
   4646 		  if (prev)
   4647 		    {
   4648 		      SYMBOL_VALUE_CHAIN (prev) = SYMBOL_VALUE_CHAIN (sym);
   4649 		    }
   4650 		  else
   4651 		    {
   4652 		      global_sym_chain[hash] = SYMBOL_VALUE_CHAIN (sym);
   4653 		    }
   4654 
   4655 		  /* Check to see whether we need to fix up a common block.  */
   4656 		  /* Note: this code might be executed several times for
   4657 		     the same symbol if there are multiple references.  */
   4658 		  if (sym)
   4659 		    {
   4660 		      if (SYMBOL_CLASS (sym) == LOC_BLOCK)
   4661 			{
   4662 			  fix_common_block (sym,
   4663 					    MSYMBOL_VALUE_ADDRESS (resolve_objfile,
   4664 								   msymbol));
   4665 			}
   4666 		      else
   4667 			{
   4668 			  SYMBOL_VALUE_ADDRESS (sym)
   4669 			    = MSYMBOL_VALUE_ADDRESS (resolve_objfile, msymbol);
   4670 			}
   4671 		      SYMBOL_SECTION (sym) = MSYMBOL_SECTION (msymbol);
   4672 		    }
   4673 
   4674 		  if (prev)
   4675 		    {
   4676 		      sym = SYMBOL_VALUE_CHAIN (prev);
   4677 		    }
   4678 		  else
   4679 		    {
   4680 		      sym = global_sym_chain[hash];
   4681 		    }
   4682 		}
   4683 	      else
   4684 		{
   4685 		  prev = sym;
   4686 		  sym = SYMBOL_VALUE_CHAIN (sym);
   4687 		}
   4688 	    }
   4689 	}
   4690       if (resolve_objfile == objfile)
   4691 	break;
   4692       resolve_objfile = objfile;
   4693     }
   4694 
   4695   /* Change the storage class of any remaining unresolved globals to
   4696      LOC_UNRESOLVED and remove them from the chain.  */
   4697   for (hash = 0; hash < HASHSIZE; hash++)
   4698     {
   4699       sym = global_sym_chain[hash];
   4700       while (sym)
   4701 	{
   4702 	  prev = sym;
   4703 	  sym = SYMBOL_VALUE_CHAIN (sym);
   4704 
   4705 	  /* Change the symbol address from the misleading chain value
   4706 	     to address zero.  */
   4707 	  SYMBOL_VALUE_ADDRESS (prev) = 0;
   4708 
   4709 	  /* Complain about unresolved common block symbols.  */
   4710 	  if (SYMBOL_CLASS (prev) == LOC_STATIC)
   4711 	    SYMBOL_ACLASS_INDEX (prev) = LOC_UNRESOLVED;
   4712 	  else
   4713 	    complaint (_("%s: common block `%s' from "
   4714 			 "global_sym_chain unresolved"),
   4715 		       objfile_name (objfile), SYMBOL_PRINT_NAME (prev));
   4716 	}
   4717     }
   4718   memset (global_sym_chain, 0, sizeof (global_sym_chain));
   4719 }
   4720 
   4721 /* Initialize anything that needs initializing when starting to read
   4722    a fresh piece of a symbol file, e.g. reading in the stuff corresponding
   4723    to a psymtab.  */
   4724 
   4725 void
   4726 stabsread_init (void)
   4727 {
   4728 }
   4729 
   4730 /* Initialize anything that needs initializing when a completely new
   4731    symbol file is specified (not just adding some symbols from another
   4732    file, e.g. a shared library).  */
   4733 
   4734 void
   4735 stabsread_new_init (void)
   4736 {
   4737   /* Empty the hash table of global syms looking for values.  */
   4738   memset (global_sym_chain, 0, sizeof (global_sym_chain));
   4739 }
   4740 
   4741 /* Initialize anything that needs initializing at the same time as
   4742    start_symtab() is called.  */
   4743 
   4744 void
   4745 start_stabs (void)
   4746 {
   4747   global_stabs = NULL;		/* AIX COFF */
   4748   /* Leave FILENUM of 0 free for builtin types and this file's types.  */
   4749   n_this_object_header_files = 1;
   4750   type_vector_length = 0;
   4751   type_vector = (struct type **) 0;
   4752   within_function = 0;
   4753 
   4754   /* FIXME: If common_block_name is not already NULL, we should complain().  */
   4755   common_block_name = NULL;
   4756 }
   4757 
   4758 /* Call after end_symtab().  */
   4759 
   4760 void
   4761 end_stabs (void)
   4762 {
   4763   if (type_vector)
   4764     {
   4765       xfree (type_vector);
   4766     }
   4767   type_vector = 0;
   4768   type_vector_length = 0;
   4769   previous_stab_code = 0;
   4770 }
   4771 
   4772 void
   4773 finish_global_stabs (struct objfile *objfile)
   4774 {
   4775   if (global_stabs)
   4776     {
   4777       patch_block_stabs (*get_global_symbols (), global_stabs, objfile);
   4778       xfree (global_stabs);
   4779       global_stabs = NULL;
   4780     }
   4781 }
   4782 
   4783 /* Find the end of the name, delimited by a ':', but don't match
   4784    ObjC symbols which look like -[Foo bar::]:bla.  */
   4785 static const char *
   4786 find_name_end (const char *name)
   4787 {
   4788   const char *s = name;
   4789 
   4790   if (s[0] == '-' || *s == '+')
   4791     {
   4792       /* Must be an ObjC method symbol.  */
   4793       if (s[1] != '[')
   4794 	{
   4795 	  error (_("invalid symbol name \"%s\""), name);
   4796 	}
   4797       s = strchr (s, ']');
   4798       if (s == NULL)
   4799 	{
   4800 	  error (_("invalid symbol name \"%s\""), name);
   4801 	}
   4802       return strchr (s, ':');
   4803     }
   4804   else
   4805     {
   4806       return strchr (s, ':');
   4807     }
   4808 }
   4809 
   4810 /* See stabsread.h.  */
   4811 
   4812 int
   4813 hashname (const char *name)
   4814 {
   4815   return hash (name, strlen (name)) % HASHSIZE;
   4816 }
   4817 
   4818 /* Initializer for this module.  */
   4819 
   4820 void
   4821 _initialize_stabsread (void)
   4822 {
   4823   rs6000_builtin_type_data = register_objfile_data ();
   4824 
   4825   undef_types_allocated = 20;
   4826   undef_types_length = 0;
   4827   undef_types = XNEWVEC (struct type *, undef_types_allocated);
   4828 
   4829   noname_undefs_allocated = 20;
   4830   noname_undefs_length = 0;
   4831   noname_undefs = XNEWVEC (struct nat, noname_undefs_allocated);
   4832 
   4833   stab_register_index = register_symbol_register_impl (LOC_REGISTER,
   4834 						       &stab_register_funcs);
   4835   stab_regparm_index = register_symbol_register_impl (LOC_REGPARM_ADDR,
   4836 						      &stab_register_funcs);
   4837 }
   4838