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