GDB (API)
/home/stan/gdb/src/gdb/stabsread.c
Go to the documentation of this file.
00001 /* Support routines for decoding "stabs" debugging information format.
00002 
00003    Copyright (C) 1986-2013 Free Software Foundation, Inc.
00004 
00005    This file is part of GDB.
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 3 of the License, or
00010    (at your option) any later version.
00011 
00012    This program is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015    GNU General Public License for more details.
00016 
00017    You should have received a copy of the GNU General Public License
00018    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00019 
00020 /* Support routines for reading and decoding debugging information in
00021    the "stabs" format.  This format is used with many systems that use
00022    the a.out object file format, as well as some systems that use
00023    COFF or ELF where the stabs data is placed in a special section.
00024    Avoid placing any object file format specific code in this file.  */
00025 
00026 #include "defs.h"
00027 #include "gdb_string.h"
00028 #include "bfd.h"
00029 #include "gdb_obstack.h"
00030 #include "symtab.h"
00031 #include "gdbtypes.h"
00032 #include "expression.h"
00033 #include "symfile.h"
00034 #include "objfiles.h"
00035 #include "aout/stab_gnu.h"      /* We always use GNU stabs, not native.  */
00036 #include "libaout.h"
00037 #include "aout/aout64.h"
00038 #include "gdb-stabs.h"
00039 #include "buildsym.h"
00040 #include "complaints.h"
00041 #include "demangle.h"
00042 #include "gdb-demangle.h"
00043 #include "language.h"
00044 #include "doublest.h"
00045 #include "cp-abi.h"
00046 #include "cp-support.h"
00047 #include "gdb_assert.h"
00048 
00049 #include <ctype.h>
00050 
00051 /* Ask stabsread.h to define the vars it normally declares `extern'.  */
00052 #define EXTERN
00053 
00054 #include "stabsread.h"          /* Our own declarations */
00055 #undef  EXTERN
00056 
00057 extern void _initialize_stabsread (void);
00058 
00059 /* The routines that read and process a complete stabs for a C struct or 
00060    C++ class pass lists of data member fields and lists of member function
00061    fields in an instance of a field_info structure, as defined below.
00062    This is part of some reorganization of low level C++ support and is
00063    expected to eventually go away...  (FIXME) */
00064 
00065 struct field_info
00066   {
00067     struct nextfield
00068       {
00069         struct nextfield *next;
00070 
00071         /* This is the raw visibility from the stab.  It is not checked
00072            for being one of the visibilities we recognize, so code which
00073            examines this field better be able to deal.  */
00074         int visibility;
00075 
00076         struct field field;
00077       }
00078      *list;
00079     struct next_fnfieldlist
00080       {
00081         struct next_fnfieldlist *next;
00082         struct fn_fieldlist fn_fieldlist;
00083       }
00084      *fnlist;
00085   };
00086 
00087 static void
00088 read_one_struct_field (struct field_info *, char **, char *,
00089                        struct type *, struct objfile *);
00090 
00091 static struct type *dbx_alloc_type (int[2], struct objfile *);
00092 
00093 static long read_huge_number (char **, int, int *, int);
00094 
00095 static struct type *error_type (char **, struct objfile *);
00096 
00097 static void
00098 patch_block_stabs (struct pending *, struct pending_stabs *,
00099                    struct objfile *);
00100 
00101 static void fix_common_block (struct symbol *, CORE_ADDR);
00102 
00103 static int read_type_number (char **, int *);
00104 
00105 static struct type *read_type (char **, struct objfile *);
00106 
00107 static struct type *read_range_type (char **, int[2], int, struct objfile *);
00108 
00109 static struct type *read_sun_builtin_type (char **, int[2], struct objfile *);
00110 
00111 static struct type *read_sun_floating_type (char **, int[2],
00112                                             struct objfile *);
00113 
00114 static struct type *read_enum_type (char **, struct type *, struct objfile *);
00115 
00116 static struct type *rs6000_builtin_type (int, struct objfile *);
00117 
00118 static int
00119 read_member_functions (struct field_info *, char **, struct type *,
00120                        struct objfile *);
00121 
00122 static int
00123 read_struct_fields (struct field_info *, char **, struct type *,
00124                     struct objfile *);
00125 
00126 static int
00127 read_baseclasses (struct field_info *, char **, struct type *,
00128                   struct objfile *);
00129 
00130 static int
00131 read_tilde_fields (struct field_info *, char **, struct type *,
00132                    struct objfile *);
00133 
00134 static int attach_fn_fields_to_type (struct field_info *, struct type *);
00135 
00136 static int attach_fields_to_type (struct field_info *, struct type *,
00137                                   struct objfile *);
00138 
00139 static struct type *read_struct_type (char **, struct type *,
00140                                       enum type_code,
00141                                       struct objfile *);
00142 
00143 static struct type *read_array_type (char **, struct type *,
00144                                      struct objfile *);
00145 
00146 static struct field *read_args (char **, int, struct objfile *, int *, int *);
00147 
00148 static void add_undefined_type (struct type *, int[2]);
00149 
00150 static int
00151 read_cpp_abbrev (struct field_info *, char **, struct type *,
00152                  struct objfile *);
00153 
00154 static char *find_name_end (char *name);
00155 
00156 static int process_reference (char **string);
00157 
00158 void stabsread_clear_cache (void);
00159 
00160 static const char vptr_name[] = "_vptr$";
00161 static const char vb_name[] = "_vb$";
00162 
00163 static void
00164 invalid_cpp_abbrev_complaint (const char *arg1)
00165 {
00166   complaint (&symfile_complaints, _("invalid C++ abbreviation `%s'"), arg1);
00167 }
00168 
00169 static void
00170 reg_value_complaint (int regnum, int num_regs, const char *sym)
00171 {
00172   complaint (&symfile_complaints,
00173              _("register number %d too large (max %d) in symbol %s"),
00174              regnum, num_regs - 1, sym);
00175 }
00176 
00177 static void
00178 stabs_general_complaint (const char *arg1)
00179 {
00180   complaint (&symfile_complaints, "%s", arg1);
00181 }
00182 
00183 /* Make a list of forward references which haven't been defined.  */
00184 
00185 static struct type **undef_types;
00186 static int undef_types_allocated;
00187 static int undef_types_length;
00188 static struct symbol *current_symbol = NULL;
00189 
00190 /* Make a list of nameless types that are undefined.
00191    This happens when another type is referenced by its number
00192    before this type is actually defined.  For instance "t(0,1)=k(0,2)"
00193    and type (0,2) is defined only later.  */
00194 
00195 struct nat
00196 {
00197   int typenums[2];
00198   struct type *type;
00199 };
00200 static struct nat *noname_undefs;
00201 static int noname_undefs_allocated;
00202 static int noname_undefs_length;
00203 
00204 /* Check for and handle cretinous stabs symbol name continuation!  */
00205 #define STABS_CONTINUE(pp,objfile)                              \
00206   do {                                                  \
00207     if (**(pp) == '\\' || (**(pp) == '?' && (*(pp))[1] == '\0')) \
00208       *(pp) = next_symbol_text (objfile);       \
00209   } while (0)
00210 
00211 /* Vector of types defined so far, indexed by their type numbers.
00212    (In newer sun systems, dbx uses a pair of numbers in parens,
00213    as in "(SUBFILENUM,NUMWITHINSUBFILE)".
00214    Then these numbers must be translated through the type_translations
00215    hash table to get the index into the type vector.)  */
00216 
00217 static struct type **type_vector;
00218 
00219 /* Number of elements allocated for type_vector currently.  */
00220 
00221 static int type_vector_length;
00222 
00223 /* Initial size of type vector.  Is realloc'd larger if needed, and
00224    realloc'd down to the size actually used, when completed.  */
00225 
00226 #define INITIAL_TYPE_VECTOR_LENGTH 160
00227 
00228 
00229 /* Look up a dbx type-number pair.  Return the address of the slot
00230    where the type for that number-pair is stored.
00231    The number-pair is in TYPENUMS.
00232 
00233    This can be used for finding the type associated with that pair
00234    or for associating a new type with the pair.  */
00235 
00236 static struct type **
00237 dbx_lookup_type (int typenums[2], struct objfile *objfile)
00238 {
00239   int filenum = typenums[0];
00240   int index = typenums[1];
00241   unsigned old_len;
00242   int real_filenum;
00243   struct header_file *f;
00244   int f_orig_length;
00245 
00246   if (filenum == -1)            /* -1,-1 is for temporary types.  */
00247     return 0;
00248 
00249   if (filenum < 0 || filenum >= n_this_object_header_files)
00250     {
00251       complaint (&symfile_complaints,
00252                  _("Invalid symbol data: type number "
00253                    "(%d,%d) out of range at symtab pos %d."),
00254                  filenum, index, symnum);
00255       goto error_return;
00256     }
00257 
00258   if (filenum == 0)
00259     {
00260       if (index < 0)
00261         {
00262           /* Caller wants address of address of type.  We think
00263              that negative (rs6k builtin) types will never appear as
00264              "lvalues", (nor should they), so we stuff the real type
00265              pointer into a temp, and return its address.  If referenced,
00266              this will do the right thing.  */
00267           static struct type *temp_type;
00268 
00269           temp_type = rs6000_builtin_type (index, objfile);
00270           return &temp_type;
00271         }
00272 
00273       /* Type is defined outside of header files.
00274          Find it in this object file's type vector.  */
00275       if (index >= type_vector_length)
00276         {
00277           old_len = type_vector_length;
00278           if (old_len == 0)
00279             {
00280               type_vector_length = INITIAL_TYPE_VECTOR_LENGTH;
00281               type_vector = (struct type **)
00282                 xmalloc (type_vector_length * sizeof (struct type *));
00283             }
00284           while (index >= type_vector_length)
00285             {
00286               type_vector_length *= 2;
00287             }
00288           type_vector = (struct type **)
00289             xrealloc ((char *) type_vector,
00290                       (type_vector_length * sizeof (struct type *)));
00291           memset (&type_vector[old_len], 0,
00292                   (type_vector_length - old_len) * sizeof (struct type *));
00293         }
00294       return (&type_vector[index]);
00295     }
00296   else
00297     {
00298       real_filenum = this_object_header_files[filenum];
00299 
00300       if (real_filenum >= N_HEADER_FILES (objfile))
00301         {
00302           static struct type *temp_type;
00303 
00304           warning (_("GDB internal error: bad real_filenum"));
00305 
00306         error_return:
00307           temp_type = objfile_type (objfile)->builtin_error;
00308           return &temp_type;
00309         }
00310 
00311       f = HEADER_FILES (objfile) + real_filenum;
00312 
00313       f_orig_length = f->length;
00314       if (index >= f_orig_length)
00315         {
00316           while (index >= f->length)
00317             {
00318               f->length *= 2;
00319             }
00320           f->vector = (struct type **)
00321             xrealloc ((char *) f->vector, f->length * sizeof (struct type *));
00322           memset (&f->vector[f_orig_length], 0,
00323                   (f->length - f_orig_length) * sizeof (struct type *));
00324         }
00325       return (&f->vector[index]);
00326     }
00327 }
00328 
00329 /* Make sure there is a type allocated for type numbers TYPENUMS
00330    and return the type object.
00331    This can create an empty (zeroed) type object.
00332    TYPENUMS may be (-1, -1) to return a new type object that is not
00333    put into the type vector, and so may not be referred to by number.  */
00334 
00335 static struct type *
00336 dbx_alloc_type (int typenums[2], struct objfile *objfile)
00337 {
00338   struct type **type_addr;
00339 
00340   if (typenums[0] == -1)
00341     {
00342       return (alloc_type (objfile));
00343     }
00344 
00345   type_addr = dbx_lookup_type (typenums, objfile);
00346 
00347   /* If we are referring to a type not known at all yet,
00348      allocate an empty type for it.
00349      We will fill it in later if we find out how.  */
00350   if (*type_addr == 0)
00351     {
00352       *type_addr = alloc_type (objfile);
00353     }
00354 
00355   return (*type_addr);
00356 }
00357 
00358 /* for all the stabs in a given stab vector, build appropriate types 
00359    and fix their symbols in given symbol vector.  */
00360 
00361 static void
00362 patch_block_stabs (struct pending *symbols, struct pending_stabs *stabs,
00363                    struct objfile *objfile)
00364 {
00365   int ii;
00366   char *name;
00367   char *pp;
00368   struct symbol *sym;
00369 
00370   if (stabs)
00371     {
00372       /* for all the stab entries, find their corresponding symbols and 
00373          patch their types!  */
00374 
00375       for (ii = 0; ii < stabs->count; ++ii)
00376         {
00377           name = stabs->stab[ii];
00378           pp = (char *) strchr (name, ':');
00379           gdb_assert (pp);      /* Must find a ':' or game's over.  */
00380           while (pp[1] == ':')
00381             {
00382               pp += 2;
00383               pp = (char *) strchr (pp, ':');
00384             }
00385           sym = find_symbol_in_list (symbols, name, pp - name);
00386           if (!sym)
00387             {
00388               /* FIXME-maybe: it would be nice if we noticed whether
00389                  the variable was defined *anywhere*, not just whether
00390                  it is defined in this compilation unit.  But neither
00391                  xlc or GCC seem to need such a definition, and until
00392                  we do psymtabs (so that the minimal symbols from all
00393                  compilation units are available now), I'm not sure
00394                  how to get the information.  */
00395 
00396               /* On xcoff, if a global is defined and never referenced,
00397                  ld will remove it from the executable.  There is then
00398                  a N_GSYM stab for it, but no regular (C_EXT) symbol.  */
00399               sym = allocate_symbol (objfile);
00400               SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
00401               SYMBOL_ACLASS_INDEX (sym) = LOC_OPTIMIZED_OUT;
00402               SYMBOL_SET_LINKAGE_NAME
00403                 (sym, obstack_copy0 (&objfile->objfile_obstack,
00404                                      name, pp - name));
00405               pp += 2;
00406               if (*(pp - 1) == 'F' || *(pp - 1) == 'f')
00407                 {
00408                   /* I don't think the linker does this with functions,
00409                      so as far as I know this is never executed.
00410                      But it doesn't hurt to check.  */
00411                   SYMBOL_TYPE (sym) =
00412                     lookup_function_type (read_type (&pp, objfile));
00413                 }
00414               else
00415                 {
00416                   SYMBOL_TYPE (sym) = read_type (&pp, objfile);
00417                 }
00418               add_symbol_to_list (sym, &global_symbols);
00419             }
00420           else
00421             {
00422               pp += 2;
00423               if (*(pp - 1) == 'F' || *(pp - 1) == 'f')
00424                 {
00425                   SYMBOL_TYPE (sym) =
00426                     lookup_function_type (read_type (&pp, objfile));
00427                 }
00428               else
00429                 {
00430                   SYMBOL_TYPE (sym) = read_type (&pp, objfile);
00431                 }
00432             }
00433         }
00434     }
00435 }
00436 
00437 
00438 /* Read a number by which a type is referred to in dbx data,
00439    or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
00440    Just a single number N is equivalent to (0,N).
00441    Return the two numbers by storing them in the vector TYPENUMS.
00442    TYPENUMS will then be used as an argument to dbx_lookup_type.
00443 
00444    Returns 0 for success, -1 for error.  */
00445 
00446 static int
00447 read_type_number (char **pp, int *typenums)
00448 {
00449   int nbits;
00450 
00451   if (**pp == '(')
00452     {
00453       (*pp)++;
00454       typenums[0] = read_huge_number (pp, ',', &nbits, 0);
00455       if (nbits != 0)
00456         return -1;
00457       typenums[1] = read_huge_number (pp, ')', &nbits, 0);
00458       if (nbits != 0)
00459         return -1;
00460     }
00461   else
00462     {
00463       typenums[0] = 0;
00464       typenums[1] = read_huge_number (pp, 0, &nbits, 0);
00465       if (nbits != 0)
00466         return -1;
00467     }
00468   return 0;
00469 }
00470 
00471 
00472 #define VISIBILITY_PRIVATE      '0'     /* Stabs character for private field */
00473 #define VISIBILITY_PROTECTED    '1'     /* Stabs character for protected fld */
00474 #define VISIBILITY_PUBLIC       '2'     /* Stabs character for public field */
00475 #define VISIBILITY_IGNORE       '9'     /* Optimized out or zero length */
00476 
00477 /* Structure for storing pointers to reference definitions for fast lookup 
00478    during "process_later".  */
00479 
00480 struct ref_map
00481 {
00482   char *stabs;
00483   CORE_ADDR value;
00484   struct symbol *sym;
00485 };
00486 
00487 #define MAX_CHUNK_REFS 100
00488 #define REF_CHUNK_SIZE (MAX_CHUNK_REFS * sizeof (struct ref_map))
00489 #define REF_MAP_SIZE(ref_chunk) ((ref_chunk) * REF_CHUNK_SIZE)
00490 
00491 static struct ref_map *ref_map;
00492 
00493 /* Ptr to free cell in chunk's linked list.  */
00494 static int ref_count = 0;
00495 
00496 /* Number of chunks malloced.  */
00497 static int ref_chunk = 0;
00498 
00499 /* This file maintains a cache of stabs aliases found in the symbol
00500    table.  If the symbol table changes, this cache must be cleared
00501    or we are left holding onto data in invalid obstacks.  */
00502 void
00503 stabsread_clear_cache (void)
00504 {
00505   ref_count = 0;
00506   ref_chunk = 0;
00507 }
00508 
00509 /* Create array of pointers mapping refids to symbols and stab strings.
00510    Add pointers to reference definition symbols and/or their values as we 
00511    find them, using their reference numbers as our index.
00512    These will be used later when we resolve references.  */
00513 void
00514 ref_add (int refnum, struct symbol *sym, char *stabs, CORE_ADDR value)
00515 {
00516   if (ref_count == 0)
00517     ref_chunk = 0;
00518   if (refnum >= ref_count)
00519     ref_count = refnum + 1;
00520   if (ref_count > ref_chunk * MAX_CHUNK_REFS)
00521     {
00522       int new_slots = ref_count - ref_chunk * MAX_CHUNK_REFS;
00523       int new_chunks = new_slots / MAX_CHUNK_REFS + 1;
00524 
00525       ref_map = (struct ref_map *)
00526         xrealloc (ref_map, REF_MAP_SIZE (ref_chunk + new_chunks));
00527       memset (ref_map + ref_chunk * MAX_CHUNK_REFS, 0, 
00528               new_chunks * REF_CHUNK_SIZE);
00529       ref_chunk += new_chunks;
00530     }
00531   ref_map[refnum].stabs = stabs;
00532   ref_map[refnum].sym = sym;
00533   ref_map[refnum].value = value;
00534 }
00535 
00536 /* Return defined sym for the reference REFNUM.  */
00537 struct symbol *
00538 ref_search (int refnum)
00539 {
00540   if (refnum < 0 || refnum > ref_count)
00541     return 0;
00542   return ref_map[refnum].sym;
00543 }
00544 
00545 /* Parse a reference id in STRING and return the resulting
00546    reference number.  Move STRING beyond the reference id.  */
00547 
00548 static int
00549 process_reference (char **string)
00550 {
00551   char *p;
00552   int refnum = 0;
00553 
00554   if (**string != '#')
00555     return 0;
00556 
00557   /* Advance beyond the initial '#'.  */
00558   p = *string + 1;
00559 
00560   /* Read number as reference id.  */
00561   while (*p && isdigit (*p))
00562     {
00563       refnum = refnum * 10 + *p - '0';
00564       p++;
00565     }
00566   *string = p;
00567   return refnum;
00568 }
00569 
00570 /* If STRING defines a reference, store away a pointer to the reference 
00571    definition for later use.  Return the reference number.  */
00572 
00573 int
00574 symbol_reference_defined (char **string)
00575 {
00576   char *p = *string;
00577   int refnum = 0;
00578 
00579   refnum = process_reference (&p);
00580 
00581   /* Defining symbols end in '='.  */
00582   if (*p == '=')
00583     {
00584       /* Symbol is being defined here.  */
00585       *string = p + 1;
00586       return refnum;
00587     }
00588   else
00589     {
00590       /* Must be a reference.  Either the symbol has already been defined,
00591          or this is a forward reference to it.  */
00592       *string = p;
00593       return -1;
00594     }
00595 }
00596 
00597 static int
00598 stab_reg_to_regnum (struct symbol *sym, struct gdbarch *gdbarch)
00599 {
00600   int regno = gdbarch_stab_reg_to_regnum (gdbarch, SYMBOL_VALUE (sym));
00601 
00602   if (regno >= gdbarch_num_regs (gdbarch)
00603                 + gdbarch_num_pseudo_regs (gdbarch))
00604     {
00605       reg_value_complaint (regno,
00606                            gdbarch_num_regs (gdbarch)
00607                              + gdbarch_num_pseudo_regs (gdbarch),
00608                            SYMBOL_PRINT_NAME (sym));
00609 
00610       regno = gdbarch_sp_regnum (gdbarch); /* Known safe, though useless.  */
00611     }
00612 
00613   return regno;
00614 }
00615 
00616 static const struct symbol_register_ops stab_register_funcs = {
00617   stab_reg_to_regnum
00618 };
00619 
00620 /* The "aclass" indices for computed symbols.  */
00621 
00622 static int stab_register_index;
00623 static int stab_regparm_index;
00624 
00625 struct symbol *
00626 define_symbol (CORE_ADDR valu, char *string, int desc, int type,
00627                struct objfile *objfile)
00628 {
00629   struct gdbarch *gdbarch = get_objfile_arch (objfile);
00630   struct symbol *sym;
00631   char *p = (char *) find_name_end (string);
00632   int deftype;
00633   int synonym = 0;
00634   int i;
00635   char *new_name = NULL;
00636 
00637   /* We would like to eliminate nameless symbols, but keep their types.
00638      E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer
00639      to type 2, but, should not create a symbol to address that type.  Since
00640      the symbol will be nameless, there is no way any user can refer to it.  */
00641 
00642   int nameless;
00643 
00644   /* Ignore syms with empty names.  */
00645   if (string[0] == 0)
00646     return 0;
00647 
00648   /* Ignore old-style symbols from cc -go.  */
00649   if (p == 0)
00650     return 0;
00651 
00652   while (p[1] == ':')
00653     {
00654       p += 2;
00655       p = strchr (p, ':');
00656       if (p == NULL)
00657         {
00658           complaint (&symfile_complaints, 
00659                      _("Bad stabs string '%s'"), string);
00660           return NULL;
00661         }
00662     }
00663 
00664   /* If a nameless stab entry, all we need is the type, not the symbol.
00665      e.g. ":t10=*2" or a nameless enum like " :T16=ered:0,green:1,blue:2,;" */
00666   nameless = (p == string || ((string[0] == ' ') && (string[1] == ':')));
00667 
00668   current_symbol = sym = allocate_symbol (objfile);
00669 
00670   if (processing_gcc_compilation)
00671     {
00672       /* GCC 2.x puts the line number in desc.  SunOS apparently puts in the
00673          number of bytes occupied by a type or object, which we ignore.  */
00674       SYMBOL_LINE (sym) = desc;
00675     }
00676   else
00677     {
00678       SYMBOL_LINE (sym) = 0;    /* unknown */
00679     }
00680 
00681   if (is_cplus_marker (string[0]))
00682     {
00683       /* Special GNU C++ names.  */
00684       switch (string[1])
00685         {
00686         case 't':
00687           SYMBOL_SET_LINKAGE_NAME (sym, "this");
00688           break;
00689 
00690         case 'v':               /* $vtbl_ptr_type */
00691           goto normal;
00692 
00693         case 'e':
00694           SYMBOL_SET_LINKAGE_NAME (sym, "eh_throw");
00695           break;
00696 
00697         case '_':
00698           /* This was an anonymous type that was never fixed up.  */
00699           goto normal;
00700 
00701         case 'X':
00702           /* SunPRO (3.0 at least) static variable encoding.  */
00703           if (gdbarch_static_transform_name_p (gdbarch))
00704             goto normal;
00705           /* ... fall through ...  */
00706 
00707         default:
00708           complaint (&symfile_complaints, _("Unknown C++ symbol name `%s'"),
00709                      string);
00710           goto normal;          /* Do *something* with it.  */
00711         }
00712     }
00713   else
00714     {
00715     normal:
00716       SYMBOL_SET_LANGUAGE (sym, current_subfile->language,
00717                            &objfile->objfile_obstack);
00718       if (SYMBOL_LANGUAGE (sym) == language_cplus)
00719         {
00720           char *name = alloca (p - string + 1);
00721 
00722           memcpy (name, string, p - string);
00723           name[p - string] = '\0';
00724           new_name = cp_canonicalize_string (name);
00725         }
00726       if (new_name != NULL)
00727         {
00728           SYMBOL_SET_NAMES (sym, new_name, strlen (new_name), 1, objfile);
00729           xfree (new_name);
00730         }
00731       else
00732         SYMBOL_SET_NAMES (sym, string, p - string, 1, objfile);
00733 
00734       if (SYMBOL_LANGUAGE (sym) == language_cplus)
00735         cp_scan_for_anonymous_namespaces (sym, objfile);
00736 
00737     }
00738   p++;
00739 
00740   /* Determine the type of name being defined.  */
00741 #if 0
00742   /* Getting GDB to correctly skip the symbol on an undefined symbol
00743      descriptor and not ever dump core is a very dodgy proposition if
00744      we do things this way.  I say the acorn RISC machine can just
00745      fix their compiler.  */
00746   /* The Acorn RISC machine's compiler can put out locals that don't
00747      start with "234=" or "(3,4)=", so assume anything other than the
00748      deftypes we know how to handle is a local.  */
00749   if (!strchr ("cfFGpPrStTvVXCR", *p))
00750 #else
00751   if (isdigit (*p) || *p == '(' || *p == '-')
00752 #endif
00753     deftype = 'l';
00754   else
00755     deftype = *p++;
00756 
00757   switch (deftype)
00758     {
00759     case 'c':
00760       /* c is a special case, not followed by a type-number.
00761          SYMBOL:c=iVALUE for an integer constant symbol.
00762          SYMBOL:c=rVALUE for a floating constant symbol.
00763          SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
00764          e.g. "b:c=e6,0" for "const b = blob1"
00765          (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;").  */
00766       if (*p != '=')
00767         {
00768           SYMBOL_ACLASS_INDEX (sym) = LOC_CONST;
00769           SYMBOL_TYPE (sym) = error_type (&p, objfile);
00770           SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
00771           add_symbol_to_list (sym, &file_symbols);
00772           return sym;
00773         }
00774       ++p;
00775       switch (*p++)
00776         {
00777         case 'r':
00778           {
00779             double d = atof (p);
00780             gdb_byte *dbl_valu;
00781             struct type *dbl_type;
00782 
00783             /* FIXME-if-picky-about-floating-accuracy: Should be using
00784                target arithmetic to get the value.  real.c in GCC
00785                probably has the necessary code.  */
00786 
00787             dbl_type = objfile_type (objfile)->builtin_double;
00788             dbl_valu =
00789               obstack_alloc (&objfile->objfile_obstack,
00790                              TYPE_LENGTH (dbl_type));
00791             store_typed_floating (dbl_valu, dbl_type, d);
00792 
00793             SYMBOL_TYPE (sym) = dbl_type;
00794             SYMBOL_VALUE_BYTES (sym) = dbl_valu;
00795             SYMBOL_ACLASS_INDEX (sym) = LOC_CONST_BYTES;
00796           }
00797           break;
00798         case 'i':
00799           {
00800             /* Defining integer constants this way is kind of silly,
00801                since 'e' constants allows the compiler to give not
00802                only the value, but the type as well.  C has at least
00803                int, long, unsigned int, and long long as constant
00804                types; other languages probably should have at least
00805                unsigned as well as signed constants.  */
00806 
00807             SYMBOL_TYPE (sym) = objfile_type (objfile)->builtin_long;
00808             SYMBOL_VALUE (sym) = atoi (p);
00809             SYMBOL_ACLASS_INDEX (sym) = LOC_CONST;
00810           }
00811           break;
00812 
00813         case 'c':
00814           {
00815             SYMBOL_TYPE (sym) = objfile_type (objfile)->builtin_char;
00816             SYMBOL_VALUE (sym) = atoi (p);
00817             SYMBOL_ACLASS_INDEX (sym) = LOC_CONST;
00818           }
00819           break;
00820 
00821         case 's':
00822           {
00823             struct type *range_type;
00824             int ind = 0;
00825             char quote = *p++;
00826             gdb_byte *string_local = (gdb_byte *) alloca (strlen (p));
00827             gdb_byte *string_value;
00828 
00829             if (quote != '\'' && quote != '"')
00830               {
00831                 SYMBOL_ACLASS_INDEX (sym) = LOC_CONST;
00832                 SYMBOL_TYPE (sym) = error_type (&p, objfile);
00833                 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
00834                 add_symbol_to_list (sym, &file_symbols);
00835                 return sym;
00836               }
00837 
00838             /* Find matching quote, rejecting escaped quotes.  */
00839             while (*p && *p != quote)
00840               {
00841                 if (*p == '\\' && p[1] == quote)
00842                   {
00843                     string_local[ind] = (gdb_byte) quote;
00844                     ind++;
00845                     p += 2;
00846                   }
00847                 else if (*p) 
00848                   {
00849                     string_local[ind] = (gdb_byte) (*p);
00850                     ind++;
00851                     p++;
00852                   }
00853               }
00854             if (*p != quote)
00855               {
00856                 SYMBOL_ACLASS_INDEX (sym) = LOC_CONST;
00857                 SYMBOL_TYPE (sym) = error_type (&p, objfile);
00858                 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
00859                 add_symbol_to_list (sym, &file_symbols);
00860                 return sym;
00861               }
00862 
00863             /* NULL terminate the string.  */
00864             string_local[ind] = 0;
00865             range_type
00866               = create_range_type (NULL,
00867                                    objfile_type (objfile)->builtin_int,
00868                                    0, ind);
00869             SYMBOL_TYPE (sym) = create_array_type (NULL,
00870                                   objfile_type (objfile)->builtin_char,
00871                                   range_type);
00872             string_value = obstack_alloc (&objfile->objfile_obstack, ind + 1);
00873             memcpy (string_value, string_local, ind + 1);
00874             p++;
00875 
00876             SYMBOL_VALUE_BYTES (sym) = string_value;
00877             SYMBOL_ACLASS_INDEX (sym) = LOC_CONST_BYTES;
00878           }
00879           break;
00880 
00881         case 'e':
00882           /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
00883              can be represented as integral.
00884              e.g. "b:c=e6,0" for "const b = blob1"
00885              (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;").  */
00886           {
00887             SYMBOL_ACLASS_INDEX (sym) = LOC_CONST;
00888             SYMBOL_TYPE (sym) = read_type (&p, objfile);
00889 
00890             if (*p != ',')
00891               {
00892                 SYMBOL_TYPE (sym) = error_type (&p, objfile);
00893                 break;
00894               }
00895             ++p;
00896 
00897             /* If the value is too big to fit in an int (perhaps because
00898                it is unsigned), or something like that, we silently get
00899                a bogus value.  The type and everything else about it is
00900                correct.  Ideally, we should be using whatever we have
00901                available for parsing unsigned and long long values,
00902                however.  */
00903             SYMBOL_VALUE (sym) = atoi (p);
00904           }
00905           break;
00906         default:
00907           {
00908             SYMBOL_ACLASS_INDEX (sym) = LOC_CONST;
00909             SYMBOL_TYPE (sym) = error_type (&p, objfile);
00910           }
00911         }
00912       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
00913       add_symbol_to_list (sym, &file_symbols);
00914       return sym;
00915 
00916     case 'C':
00917       /* The name of a caught exception.  */
00918       SYMBOL_TYPE (sym) = read_type (&p, objfile);
00919       SYMBOL_ACLASS_INDEX (sym) = LOC_LABEL;
00920       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
00921       SYMBOL_VALUE_ADDRESS (sym) = valu;
00922       add_symbol_to_list (sym, &local_symbols);
00923       break;
00924 
00925     case 'f':
00926       /* A static function definition.  */
00927       SYMBOL_TYPE (sym) = read_type (&p, objfile);
00928       SYMBOL_ACLASS_INDEX (sym) = LOC_BLOCK;
00929       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
00930       add_symbol_to_list (sym, &file_symbols);
00931       /* fall into process_function_types.  */
00932 
00933     process_function_types:
00934       /* Function result types are described as the result type in stabs.
00935          We need to convert this to the function-returning-type-X type
00936          in GDB.  E.g. "int" is converted to "function returning int".  */
00937       if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_FUNC)
00938         SYMBOL_TYPE (sym) = lookup_function_type (SYMBOL_TYPE (sym));
00939 
00940       /* All functions in C++ have prototypes.  Stabs does not offer an
00941          explicit way to identify prototyped or unprototyped functions,
00942          but both GCC and Sun CC emit stabs for the "call-as" type rather
00943          than the "declared-as" type for unprototyped functions, so
00944          we treat all functions as if they were prototyped.  This is used
00945          primarily for promotion when calling the function from GDB.  */
00946       TYPE_PROTOTYPED (SYMBOL_TYPE (sym)) = 1;
00947 
00948       /* fall into process_prototype_types.  */
00949 
00950     process_prototype_types:
00951       /* Sun acc puts declared types of arguments here.  */
00952       if (*p == ';')
00953         {
00954           struct type *ftype = SYMBOL_TYPE (sym);
00955           int nsemi = 0;
00956           int nparams = 0;
00957           char *p1 = p;
00958 
00959           /* Obtain a worst case guess for the number of arguments
00960              by counting the semicolons.  */
00961           while (*p1)
00962             {
00963               if (*p1++ == ';')
00964                 nsemi++;
00965             }
00966 
00967           /* Allocate parameter information fields and fill them in.  */
00968           TYPE_FIELDS (ftype) = (struct field *)
00969             TYPE_ALLOC (ftype, nsemi * sizeof (struct field));
00970           while (*p++ == ';')
00971             {
00972               struct type *ptype;
00973 
00974               /* A type number of zero indicates the start of varargs.
00975                  FIXME: GDB currently ignores vararg functions.  */
00976               if (p[0] == '0' && p[1] == '\0')
00977                 break;
00978               ptype = read_type (&p, objfile);
00979 
00980               /* The Sun compilers mark integer arguments, which should
00981                  be promoted to the width of the calling conventions, with
00982                  a type which references itself.  This type is turned into
00983                  a TYPE_CODE_VOID type by read_type, and we have to turn
00984                  it back into builtin_int here.
00985                  FIXME: Do we need a new builtin_promoted_int_arg ?  */
00986               if (TYPE_CODE (ptype) == TYPE_CODE_VOID)
00987                 ptype = objfile_type (objfile)->builtin_int;
00988               TYPE_FIELD_TYPE (ftype, nparams) = ptype;
00989               TYPE_FIELD_ARTIFICIAL (ftype, nparams++) = 0;
00990             }
00991           TYPE_NFIELDS (ftype) = nparams;
00992           TYPE_PROTOTYPED (ftype) = 1;
00993         }
00994       break;
00995 
00996     case 'F':
00997       /* A global function definition.  */
00998       SYMBOL_TYPE (sym) = read_type (&p, objfile);
00999       SYMBOL_ACLASS_INDEX (sym) = LOC_BLOCK;
01000       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
01001       add_symbol_to_list (sym, &global_symbols);
01002       goto process_function_types;
01003 
01004     case 'G':
01005       /* For a class G (global) symbol, it appears that the
01006          value is not correct.  It is necessary to search for the
01007          corresponding linker definition to find the value.
01008          These definitions appear at the end of the namelist.  */
01009       SYMBOL_TYPE (sym) = read_type (&p, objfile);
01010       SYMBOL_ACLASS_INDEX (sym) = LOC_STATIC;
01011       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
01012       /* Don't add symbol references to global_sym_chain.
01013          Symbol references don't have valid names and wont't match up with
01014          minimal symbols when the global_sym_chain is relocated.
01015          We'll fixup symbol references when we fixup the defining symbol.  */
01016       if (SYMBOL_LINKAGE_NAME (sym) && SYMBOL_LINKAGE_NAME (sym)[0] != '#')
01017         {
01018           i = hashname (SYMBOL_LINKAGE_NAME (sym));
01019           SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i];
01020           global_sym_chain[i] = sym;
01021         }
01022       add_symbol_to_list (sym, &global_symbols);
01023       break;
01024 
01025       /* This case is faked by a conditional above,
01026          when there is no code letter in the dbx data.
01027          Dbx data never actually contains 'l'.  */
01028     case 's':
01029     case 'l':
01030       SYMBOL_TYPE (sym) = read_type (&p, objfile);
01031       SYMBOL_ACLASS_INDEX (sym) = LOC_LOCAL;
01032       SYMBOL_VALUE (sym) = valu;
01033       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
01034       add_symbol_to_list (sym, &local_symbols);
01035       break;
01036 
01037     case 'p':
01038       if (*p == 'F')
01039         /* pF is a two-letter code that means a function parameter in Fortran.
01040            The type-number specifies the type of the return value.
01041            Translate it into a pointer-to-function type.  */
01042         {
01043           p++;
01044           SYMBOL_TYPE (sym)
01045             = lookup_pointer_type
01046             (lookup_function_type (read_type (&p, objfile)));
01047         }
01048       else
01049         SYMBOL_TYPE (sym) = read_type (&p, objfile);
01050 
01051       SYMBOL_ACLASS_INDEX (sym) = LOC_ARG;
01052       SYMBOL_VALUE (sym) = valu;
01053       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
01054       SYMBOL_IS_ARGUMENT (sym) = 1;
01055       add_symbol_to_list (sym, &local_symbols);
01056 
01057       if (gdbarch_byte_order (gdbarch) != BFD_ENDIAN_BIG)
01058         {
01059           /* On little-endian machines, this crud is never necessary,
01060              and, if the extra bytes contain garbage, is harmful.  */
01061           break;
01062         }
01063 
01064       /* If it's gcc-compiled, if it says `short', believe it.  */
01065       if (processing_gcc_compilation
01066           || gdbarch_believe_pcc_promotion (gdbarch))
01067         break;
01068 
01069       if (!gdbarch_believe_pcc_promotion (gdbarch))
01070         {
01071           /* If PCC says a parameter is a short or a char, it is
01072              really an int.  */
01073           if (TYPE_LENGTH (SYMBOL_TYPE (sym))
01074               < gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT
01075               && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT)
01076             {
01077               SYMBOL_TYPE (sym) =
01078                 TYPE_UNSIGNED (SYMBOL_TYPE (sym))
01079                 ? objfile_type (objfile)->builtin_unsigned_int
01080                 : objfile_type (objfile)->builtin_int;
01081             }
01082           break;
01083         }
01084 
01085     case 'P':
01086       /* acc seems to use P to declare the prototypes of functions that
01087          are referenced by this file.  gdb is not prepared to deal
01088          with this extra information.  FIXME, it ought to.  */
01089       if (type == N_FUN)
01090         {
01091           SYMBOL_TYPE (sym) = read_type (&p, objfile);
01092           goto process_prototype_types;
01093         }
01094       /*FALLTHROUGH */
01095 
01096     case 'R':
01097       /* Parameter which is in a register.  */
01098       SYMBOL_TYPE (sym) = read_type (&p, objfile);
01099       SYMBOL_ACLASS_INDEX (sym) = stab_register_index;
01100       SYMBOL_IS_ARGUMENT (sym) = 1;
01101       SYMBOL_VALUE (sym) = valu;
01102       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
01103       add_symbol_to_list (sym, &local_symbols);
01104       break;
01105 
01106     case 'r':
01107       /* Register variable (either global or local).  */
01108       SYMBOL_TYPE (sym) = read_type (&p, objfile);
01109       SYMBOL_ACLASS_INDEX (sym) = stab_register_index;
01110       SYMBOL_VALUE (sym) = valu;
01111       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
01112       if (within_function)
01113         {
01114           /* Sun cc uses a pair of symbols, one 'p' and one 'r', with
01115              the same name to represent an argument passed in a
01116              register.  GCC uses 'P' for the same case.  So if we find
01117              such a symbol pair we combine it into one 'P' symbol.
01118              For Sun cc we need to do this regardless of
01119              stabs_argument_has_addr, because the compiler puts out
01120              the 'p' symbol even if it never saves the argument onto
01121              the stack.
01122 
01123              On most machines, we want to preserve both symbols, so
01124              that we can still get information about what is going on
01125              with the stack (VAX for computing args_printed, using
01126              stack slots instead of saved registers in backtraces,
01127              etc.).
01128 
01129              Note that this code illegally combines
01130              main(argc) struct foo argc; { register struct foo argc; }
01131              but this case is considered pathological and causes a warning
01132              from a decent compiler.  */
01133 
01134           if (local_symbols
01135               && local_symbols->nsyms > 0
01136               && gdbarch_stabs_argument_has_addr (gdbarch, SYMBOL_TYPE (sym)))
01137             {
01138               struct symbol *prev_sym;
01139 
01140               prev_sym = local_symbols->symbol[local_symbols->nsyms - 1];
01141               if ((SYMBOL_CLASS (prev_sym) == LOC_REF_ARG
01142                    || SYMBOL_CLASS (prev_sym) == LOC_ARG)
01143                   && strcmp (SYMBOL_LINKAGE_NAME (prev_sym),
01144                              SYMBOL_LINKAGE_NAME (sym)) == 0)
01145                 {
01146                   SYMBOL_ACLASS_INDEX (prev_sym) = stab_register_index;
01147                   /* Use the type from the LOC_REGISTER; that is the type
01148                      that is actually in that register.  */
01149                   SYMBOL_TYPE (prev_sym) = SYMBOL_TYPE (sym);
01150                   SYMBOL_VALUE (prev_sym) = SYMBOL_VALUE (sym);
01151                   sym = prev_sym;
01152                   break;
01153                 }
01154             }
01155           add_symbol_to_list (sym, &local_symbols);
01156         }
01157       else
01158         add_symbol_to_list (sym, &file_symbols);
01159       break;
01160 
01161     case 'S':
01162       /* Static symbol at top level of file.  */
01163       SYMBOL_TYPE (sym) = read_type (&p, objfile);
01164       SYMBOL_ACLASS_INDEX (sym) = LOC_STATIC;
01165       SYMBOL_VALUE_ADDRESS (sym) = valu;
01166       if (gdbarch_static_transform_name_p (gdbarch)
01167           && gdbarch_static_transform_name (gdbarch,
01168                                             SYMBOL_LINKAGE_NAME (sym))
01169              != SYMBOL_LINKAGE_NAME (sym))
01170         {
01171           struct minimal_symbol *msym;
01172 
01173           msym = lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (sym),
01174                                         NULL, objfile);
01175           if (msym != NULL)
01176             {
01177               const char *new_name = gdbarch_static_transform_name
01178                 (gdbarch, SYMBOL_LINKAGE_NAME (sym));
01179 
01180               SYMBOL_SET_LINKAGE_NAME (sym, new_name);
01181               SYMBOL_VALUE_ADDRESS (sym) = SYMBOL_VALUE_ADDRESS (msym);
01182             }
01183         }
01184       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
01185       add_symbol_to_list (sym, &file_symbols);
01186       break;
01187 
01188     case 't':
01189       /* In Ada, there is no distinction between typedef and non-typedef;
01190          any type declaration implicitly has the equivalent of a typedef,
01191          and thus 't' is in fact equivalent to 'Tt'.
01192 
01193          Therefore, for Ada units, we check the character immediately
01194          before the 't', and if we do not find a 'T', then make sure to
01195          create the associated symbol in the STRUCT_DOMAIN ('t' definitions
01196          will be stored in the VAR_DOMAIN).  If the symbol was indeed
01197          defined as 'Tt' then the STRUCT_DOMAIN symbol will be created
01198          elsewhere, so we don't need to take care of that.
01199          
01200          This is important to do, because of forward references:
01201          The cleanup of undefined types stored in undef_types only uses
01202          STRUCT_DOMAIN symbols to perform the replacement.  */
01203       synonym = (SYMBOL_LANGUAGE (sym) == language_ada && p[-2] != 'T');
01204 
01205       /* Typedef */
01206       SYMBOL_TYPE (sym) = read_type (&p, objfile);
01207 
01208       /* For a nameless type, we don't want a create a symbol, thus we
01209          did not use `sym'.  Return without further processing.  */
01210       if (nameless)
01211         return NULL;
01212 
01213       SYMBOL_ACLASS_INDEX (sym) = LOC_TYPEDEF;
01214       SYMBOL_VALUE (sym) = valu;
01215       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
01216       /* C++ vagaries: we may have a type which is derived from
01217          a base type which did not have its name defined when the
01218          derived class was output.  We fill in the derived class's
01219          base part member's name here in that case.  */
01220       if (TYPE_NAME (SYMBOL_TYPE (sym)) != NULL)
01221         if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
01222              || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION)
01223             && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)))
01224           {
01225             int j;
01226 
01227             for (j = TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)) - 1; j >= 0; j--)
01228               if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) == 0)
01229                 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) =
01230                   type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym), j));
01231           }
01232 
01233       if (TYPE_NAME (SYMBOL_TYPE (sym)) == NULL)
01234         {
01235           /* gcc-2.6 or later (when using -fvtable-thunks)
01236              emits a unique named type for a vtable entry.
01237              Some gdb code depends on that specific name.  */
01238           extern const char vtbl_ptr_name[];
01239 
01240           if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_PTR
01241                && strcmp (SYMBOL_LINKAGE_NAME (sym), vtbl_ptr_name))
01242               || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_FUNC)
01243             {
01244               /* If we are giving a name to a type such as "pointer to
01245                  foo" or "function returning foo", we better not set
01246                  the TYPE_NAME.  If the program contains "typedef char
01247                  *caddr_t;", we don't want all variables of type char
01248                  * to print as caddr_t.  This is not just a
01249                  consequence of GDB's type management; PCC and GCC (at
01250                  least through version 2.4) both output variables of
01251                  either type char * or caddr_t with the type number
01252                  defined in the 't' symbol for caddr_t.  If a future
01253                  compiler cleans this up it GDB is not ready for it
01254                  yet, but if it becomes ready we somehow need to
01255                  disable this check (without breaking the PCC/GCC2.4
01256                  case).
01257 
01258                  Sigh.
01259 
01260                  Fortunately, this check seems not to be necessary
01261                  for anything except pointers or functions.  */
01262               /* ezannoni: 2000-10-26.  This seems to apply for
01263                  versions of gcc older than 2.8.  This was the original
01264                  problem: with the following code gdb would tell that
01265                  the type for name1 is caddr_t, and func is char().
01266 
01267                  typedef char *caddr_t;
01268                  char *name2;
01269                  struct x
01270                  {
01271                    char *name1;
01272                  } xx;
01273                  char *func()
01274                  {
01275                  }
01276                  main () {}
01277                  */
01278 
01279               /* Pascal accepts names for pointer types.  */
01280               if (current_subfile->language == language_pascal)
01281                 {
01282                   TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_LINKAGE_NAME (sym);
01283                 }
01284             }
01285           else
01286             TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_LINKAGE_NAME (sym);
01287         }
01288 
01289       add_symbol_to_list (sym, &file_symbols);
01290 
01291       if (synonym)
01292         {
01293           /* Create the STRUCT_DOMAIN clone.  */
01294           struct symbol *struct_sym = allocate_symbol (objfile);
01295 
01296           *struct_sym = *sym;
01297           SYMBOL_ACLASS_INDEX (struct_sym) = LOC_TYPEDEF;
01298           SYMBOL_VALUE (struct_sym) = valu;
01299           SYMBOL_DOMAIN (struct_sym) = STRUCT_DOMAIN;
01300           if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
01301             TYPE_NAME (SYMBOL_TYPE (sym))
01302               = obconcat (&objfile->objfile_obstack,
01303                           SYMBOL_LINKAGE_NAME (sym),
01304                           (char *) NULL);
01305           add_symbol_to_list (struct_sym, &file_symbols);
01306         }
01307       
01308       break;
01309 
01310     case 'T':
01311       /* Struct, union, or enum tag.  For GNU C++, this can be be followed
01312          by 't' which means we are typedef'ing it as well.  */
01313       synonym = *p == 't';
01314 
01315       if (synonym)
01316         p++;
01317 
01318       SYMBOL_TYPE (sym) = read_type (&p, objfile);
01319  
01320       /* For a nameless type, we don't want a create a symbol, thus we
01321          did not use `sym'.  Return without further processing.  */
01322       if (nameless)
01323         return NULL;
01324 
01325       SYMBOL_ACLASS_INDEX (sym) = LOC_TYPEDEF;
01326       SYMBOL_VALUE (sym) = valu;
01327       SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN;
01328       if (TYPE_TAG_NAME (SYMBOL_TYPE (sym)) == 0)
01329         TYPE_TAG_NAME (SYMBOL_TYPE (sym))
01330           = obconcat (&objfile->objfile_obstack,
01331                       SYMBOL_LINKAGE_NAME (sym),
01332                       (char *) NULL);
01333       add_symbol_to_list (sym, &file_symbols);
01334 
01335       if (synonym)
01336         {
01337           /* Clone the sym and then modify it.  */
01338           struct symbol *typedef_sym = allocate_symbol (objfile);
01339 
01340           *typedef_sym = *sym;
01341           SYMBOL_ACLASS_INDEX (typedef_sym) = LOC_TYPEDEF;
01342           SYMBOL_VALUE (typedef_sym) = valu;
01343           SYMBOL_DOMAIN (typedef_sym) = VAR_DOMAIN;
01344           if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
01345             TYPE_NAME (SYMBOL_TYPE (sym))
01346               = obconcat (&objfile->objfile_obstack,
01347                           SYMBOL_LINKAGE_NAME (sym),
01348                           (char *) NULL);
01349           add_symbol_to_list (typedef_sym, &file_symbols);
01350         }
01351       break;
01352 
01353     case 'V':
01354       /* Static symbol of local scope.  */
01355       SYMBOL_TYPE (sym) = read_type (&p, objfile);
01356       SYMBOL_ACLASS_INDEX (sym) = LOC_STATIC;
01357       SYMBOL_VALUE_ADDRESS (sym) = valu;
01358       if (gdbarch_static_transform_name_p (gdbarch)
01359           && gdbarch_static_transform_name (gdbarch,
01360                                             SYMBOL_LINKAGE_NAME (sym))
01361              != SYMBOL_LINKAGE_NAME (sym))
01362         {
01363           struct minimal_symbol *msym;
01364 
01365           msym = lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (sym), 
01366                                         NULL, objfile);
01367           if (msym != NULL)
01368             {
01369               const char *new_name = gdbarch_static_transform_name
01370                 (gdbarch, SYMBOL_LINKAGE_NAME (sym));
01371 
01372               SYMBOL_SET_LINKAGE_NAME (sym, new_name);
01373               SYMBOL_VALUE_ADDRESS (sym) = SYMBOL_VALUE_ADDRESS (msym);
01374             }
01375         }
01376       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
01377         add_symbol_to_list (sym, &local_symbols);
01378       break;
01379 
01380     case 'v':
01381       /* Reference parameter */
01382       SYMBOL_TYPE (sym) = read_type (&p, objfile);
01383       SYMBOL_ACLASS_INDEX (sym) = LOC_REF_ARG;
01384       SYMBOL_IS_ARGUMENT (sym) = 1;
01385       SYMBOL_VALUE (sym) = valu;
01386       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
01387       add_symbol_to_list (sym, &local_symbols);
01388       break;
01389 
01390     case 'a':
01391       /* Reference parameter which is in a register.  */
01392       SYMBOL_TYPE (sym) = read_type (&p, objfile);
01393       SYMBOL_ACLASS_INDEX (sym) = stab_regparm_index;
01394       SYMBOL_IS_ARGUMENT (sym) = 1;
01395       SYMBOL_VALUE (sym) = valu;
01396       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
01397       add_symbol_to_list (sym, &local_symbols);
01398       break;
01399 
01400     case 'X':
01401       /* This is used by Sun FORTRAN for "function result value".
01402          Sun claims ("dbx and dbxtool interfaces", 2nd ed)
01403          that Pascal uses it too, but when I tried it Pascal used
01404          "x:3" (local symbol) instead.  */
01405       SYMBOL_TYPE (sym) = read_type (&p, objfile);
01406       SYMBOL_ACLASS_INDEX (sym) = LOC_LOCAL;
01407       SYMBOL_VALUE (sym) = valu;
01408       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
01409       add_symbol_to_list (sym, &local_symbols);
01410       break;
01411 
01412     default:
01413       SYMBOL_TYPE (sym) = error_type (&p, objfile);
01414       SYMBOL_ACLASS_INDEX (sym) = LOC_CONST;
01415       SYMBOL_VALUE (sym) = 0;
01416       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
01417       add_symbol_to_list (sym, &file_symbols);
01418       break;
01419     }
01420 
01421   /* Some systems pass variables of certain types by reference instead
01422      of by value, i.e. they will pass the address of a structure (in a
01423      register or on the stack) instead of the structure itself.  */
01424 
01425   if (gdbarch_stabs_argument_has_addr (gdbarch, SYMBOL_TYPE (sym))
01426       && SYMBOL_IS_ARGUMENT (sym))
01427     {
01428       /* We have to convert LOC_REGISTER to LOC_REGPARM_ADDR (for
01429          variables passed in a register).  */
01430       if (SYMBOL_CLASS (sym) == LOC_REGISTER)
01431         SYMBOL_ACLASS_INDEX (sym) = LOC_REGPARM_ADDR;
01432       /* Likewise for converting LOC_ARG to LOC_REF_ARG (for the 7th
01433          and subsequent arguments on SPARC, for example).  */
01434       else if (SYMBOL_CLASS (sym) == LOC_ARG)
01435         SYMBOL_ACLASS_INDEX (sym) = LOC_REF_ARG;
01436     }
01437 
01438   return sym;
01439 }
01440 
01441 /* Skip rest of this symbol and return an error type.
01442 
01443    General notes on error recovery:  error_type always skips to the
01444    end of the symbol (modulo cretinous dbx symbol name continuation).
01445    Thus code like this:
01446 
01447    if (*(*pp)++ != ';')
01448    return error_type (pp, objfile);
01449 
01450    is wrong because if *pp starts out pointing at '\0' (typically as the
01451    result of an earlier error), it will be incremented to point to the
01452    start of the next symbol, which might produce strange results, at least
01453    if you run off the end of the string table.  Instead use
01454 
01455    if (**pp != ';')
01456    return error_type (pp, objfile);
01457    ++*pp;
01458 
01459    or
01460 
01461    if (**pp != ';')
01462    foo = error_type (pp, objfile);
01463    else
01464    ++*pp;
01465 
01466    And in case it isn't obvious, the point of all this hair is so the compiler
01467    can define new types and new syntaxes, and old versions of the
01468    debugger will be able to read the new symbol tables.  */
01469 
01470 static struct type *
01471 error_type (char **pp, struct objfile *objfile)
01472 {
01473   complaint (&symfile_complaints,
01474              _("couldn't parse type; debugger out of date?"));
01475   while (1)
01476     {
01477       /* Skip to end of symbol.  */
01478       while (**pp != '\0')
01479         {
01480           (*pp)++;
01481         }
01482 
01483       /* Check for and handle cretinous dbx symbol name continuation!  */
01484       if ((*pp)[-1] == '\\' || (*pp)[-1] == '?')
01485         {
01486           *pp = next_symbol_text (objfile);
01487         }
01488       else
01489         {
01490           break;
01491         }
01492     }
01493   return objfile_type (objfile)->builtin_error;
01494 }
01495 
01496 
01497 /* Read type information or a type definition; return the type.  Even
01498    though this routine accepts either type information or a type
01499    definition, the distinction is relevant--some parts of stabsread.c
01500    assume that type information starts with a digit, '-', or '(' in
01501    deciding whether to call read_type.  */
01502 
01503 static struct type *
01504 read_type (char **pp, struct objfile *objfile)
01505 {
01506   struct type *type = 0;
01507   struct type *type1;
01508   int typenums[2];
01509   char type_descriptor;
01510 
01511   /* Size in bits of type if specified by a type attribute, or -1 if
01512      there is no size attribute.  */
01513   int type_size = -1;
01514 
01515   /* Used to distinguish string and bitstring from char-array and set.  */
01516   int is_string = 0;
01517 
01518   /* Used to distinguish vector from array.  */
01519   int is_vector = 0;
01520 
01521   /* Read type number if present.  The type number may be omitted.
01522      for instance in a two-dimensional array declared with type
01523      "ar1;1;10;ar1;1;10;4".  */
01524   if ((**pp >= '0' && **pp <= '9')
01525       || **pp == '('
01526       || **pp == '-')
01527     {
01528       if (read_type_number (pp, typenums) != 0)
01529         return error_type (pp, objfile);
01530 
01531       if (**pp != '=')
01532         {
01533           /* Type is not being defined here.  Either it already
01534              exists, or this is a forward reference to it.
01535              dbx_alloc_type handles both cases.  */
01536           type = dbx_alloc_type (typenums, objfile);
01537 
01538           /* If this is a forward reference, arrange to complain if it
01539              doesn't get patched up by the time we're done
01540              reading.  */
01541           if (TYPE_CODE (type) == TYPE_CODE_UNDEF)
01542             add_undefined_type (type, typenums);
01543 
01544           return type;
01545         }
01546 
01547       /* Type is being defined here.  */
01548       /* Skip the '='.
01549          Also skip the type descriptor - we get it below with (*pp)[-1].  */
01550       (*pp) += 2;
01551     }
01552   else
01553     {
01554       /* 'typenums=' not present, type is anonymous.  Read and return
01555          the definition, but don't put it in the type vector.  */
01556       typenums[0] = typenums[1] = -1;
01557       (*pp)++;
01558     }
01559 
01560 again:
01561   type_descriptor = (*pp)[-1];
01562   switch (type_descriptor)
01563     {
01564     case 'x':
01565       {
01566         enum type_code code;
01567 
01568         /* Used to index through file_symbols.  */
01569         struct pending *ppt;
01570         int i;
01571 
01572         /* Name including "struct", etc.  */
01573         char *type_name;
01574 
01575         {
01576           char *from, *to, *p, *q1, *q2;
01577 
01578           /* Set the type code according to the following letter.  */
01579           switch ((*pp)[0])
01580             {
01581             case 's':
01582               code = TYPE_CODE_STRUCT;
01583               break;
01584             case 'u':
01585               code = TYPE_CODE_UNION;
01586               break;
01587             case 'e':
01588               code = TYPE_CODE_ENUM;
01589               break;
01590             default:
01591               {
01592                 /* Complain and keep going, so compilers can invent new
01593                    cross-reference types.  */
01594                 complaint (&symfile_complaints,
01595                            _("Unrecognized cross-reference type `%c'"),
01596                            (*pp)[0]);
01597                 code = TYPE_CODE_STRUCT;
01598                 break;
01599               }
01600             }
01601 
01602           q1 = strchr (*pp, '<');
01603           p = strchr (*pp, ':');
01604           if (p == NULL)
01605             return error_type (pp, objfile);
01606           if (q1 && p > q1 && p[1] == ':')
01607             {
01608               int nesting_level = 0;
01609 
01610               for (q2 = q1; *q2; q2++)
01611                 {
01612                   if (*q2 == '<')
01613                     nesting_level++;
01614                   else if (*q2 == '>')
01615                     nesting_level--;
01616                   else if (*q2 == ':' && nesting_level == 0)
01617                     break;
01618                 }
01619               p = q2;
01620               if (*p != ':')
01621                 return error_type (pp, objfile);
01622             }
01623           type_name = NULL;
01624           if (current_subfile->language == language_cplus)
01625             {
01626               char *new_name, *name = alloca (p - *pp + 1);
01627 
01628               memcpy (name, *pp, p - *pp);
01629               name[p - *pp] = '\0';
01630               new_name = cp_canonicalize_string (name);
01631               if (new_name != NULL)
01632                 {
01633                   type_name = obstack_copy0 (&objfile->objfile_obstack,
01634                                              new_name, strlen (new_name));
01635                   xfree (new_name);
01636                 }
01637             }
01638           if (type_name == NULL)
01639             {
01640               to = type_name = (char *)
01641                 obstack_alloc (&objfile->objfile_obstack, p - *pp + 1);
01642 
01643               /* Copy the name.  */
01644               from = *pp + 1;
01645               while (from < p)
01646                 *to++ = *from++;
01647               *to = '\0';
01648             }
01649 
01650           /* Set the pointer ahead of the name which we just read, and
01651              the colon.  */
01652           *pp = p + 1;
01653         }
01654 
01655         /* If this type has already been declared, then reuse the same
01656            type, rather than allocating a new one.  This saves some
01657            memory.  */
01658 
01659         for (ppt = file_symbols; ppt; ppt = ppt->next)
01660           for (i = 0; i < ppt->nsyms; i++)
01661             {
01662               struct symbol *sym = ppt->symbol[i];
01663 
01664               if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
01665                   && SYMBOL_DOMAIN (sym) == STRUCT_DOMAIN
01666                   && (TYPE_CODE (SYMBOL_TYPE (sym)) == code)
01667                   && strcmp (SYMBOL_LINKAGE_NAME (sym), type_name) == 0)
01668                 {
01669                   obstack_free (&objfile->objfile_obstack, type_name);
01670                   type = SYMBOL_TYPE (sym);
01671                   if (typenums[0] != -1)
01672                     *dbx_lookup_type (typenums, objfile) = type;
01673                   return type;
01674                 }
01675             }
01676 
01677         /* Didn't find the type to which this refers, so we must
01678            be dealing with a forward reference.  Allocate a type
01679            structure for it, and keep track of it so we can
01680            fill in the rest of the fields when we get the full
01681            type.  */
01682         type = dbx_alloc_type (typenums, objfile);
01683         TYPE_CODE (type) = code;
01684         TYPE_TAG_NAME (type) = type_name;
01685         INIT_CPLUS_SPECIFIC (type);
01686         TYPE_STUB (type) = 1;
01687 
01688         add_undefined_type (type, typenums);
01689         return type;
01690       }
01691 
01692     case '-':                   /* RS/6000 built-in type */
01693     case '0':
01694     case '1':
01695     case '2':
01696     case '3':
01697     case '4':
01698     case '5':
01699     case '6':
01700     case '7':
01701     case '8':
01702     case '9':
01703     case '(':
01704       (*pp)--;
01705 
01706       /* We deal with something like t(1,2)=(3,4)=... which
01707          the Lucid compiler and recent gcc versions (post 2.7.3) use.  */
01708 
01709       /* Allocate and enter the typedef type first.
01710          This handles recursive types.  */
01711       type = dbx_alloc_type (typenums, objfile);
01712       TYPE_CODE (type) = TYPE_CODE_TYPEDEF;
01713       {
01714         struct type *xtype = read_type (pp, objfile);
01715 
01716         if (type == xtype)
01717           {
01718             /* It's being defined as itself.  That means it is "void".  */
01719             TYPE_CODE (type) = TYPE_CODE_VOID;
01720             TYPE_LENGTH (type) = 1;
01721           }
01722         else if (type_size >= 0 || is_string)
01723           {
01724             /* This is the absolute wrong way to construct types.  Every
01725                other debug format has found a way around this problem and
01726                the related problems with unnecessarily stubbed types;
01727                someone motivated should attempt to clean up the issue
01728                here as well.  Once a type pointed to has been created it
01729                should not be modified.
01730 
01731                Well, it's not *absolutely* wrong.  Constructing recursive
01732                types (trees, linked lists) necessarily entails modifying
01733                types after creating them.  Constructing any loop structure
01734                entails side effects.  The Dwarf 2 reader does handle this
01735                more gracefully (it never constructs more than once
01736                instance of a type object, so it doesn't have to copy type
01737                objects wholesale), but it still mutates type objects after
01738                other folks have references to them.
01739 
01740                Keep in mind that this circularity/mutation issue shows up
01741                at the source language level, too: C's "incomplete types",
01742                for example.  So the proper cleanup, I think, would be to
01743                limit GDB's type smashing to match exactly those required
01744                by the source language.  So GDB could have a
01745                "complete_this_type" function, but never create unnecessary
01746                copies of a type otherwise.  */
01747             replace_type (type, xtype);
01748             TYPE_NAME (type) = NULL;
01749             TYPE_TAG_NAME (type) = NULL;
01750           }
01751         else
01752           {
01753             TYPE_TARGET_STUB (type) = 1;
01754             TYPE_TARGET_TYPE (type) = xtype;
01755           }
01756       }
01757       break;
01758 
01759       /* In the following types, we must be sure to overwrite any existing
01760          type that the typenums refer to, rather than allocating a new one
01761          and making the typenums point to the new one.  This is because there
01762          may already be pointers to the existing type (if it had been
01763          forward-referenced), and we must change it to a pointer, function,
01764          reference, or whatever, *in-place*.  */
01765 
01766     case '*':                   /* Pointer to another type */
01767       type1 = read_type (pp, objfile);
01768       type = make_pointer_type (type1, dbx_lookup_type (typenums, objfile));
01769       break;
01770 
01771     case '&':                   /* Reference to another type */
01772       type1 = read_type (pp, objfile);
01773       type = make_reference_type (type1, dbx_lookup_type (typenums, objfile));
01774       break;
01775 
01776     case 'f':                   /* Function returning another type */
01777       type1 = read_type (pp, objfile);
01778       type = make_function_type (type1, dbx_lookup_type (typenums, objfile));
01779       break;
01780 
01781     case 'g':                   /* Prototyped function.  (Sun)  */
01782       {
01783         /* Unresolved questions:
01784 
01785            - According to Sun's ``STABS Interface Manual'', for 'f'
01786            and 'F' symbol descriptors, a `0' in the argument type list
01787            indicates a varargs function.  But it doesn't say how 'g'
01788            type descriptors represent that info.  Someone with access
01789            to Sun's toolchain should try it out.
01790 
01791            - According to the comment in define_symbol (search for
01792            `process_prototype_types:'), Sun emits integer arguments as
01793            types which ref themselves --- like `void' types.  Do we
01794            have to deal with that here, too?  Again, someone with
01795            access to Sun's toolchain should try it out and let us
01796            know.  */
01797 
01798         const char *type_start = (*pp) - 1;
01799         struct type *return_type = read_type (pp, objfile);
01800         struct type *func_type
01801           = make_function_type (return_type,
01802                                 dbx_lookup_type (typenums, objfile));
01803         struct type_list {
01804           struct type *type;
01805           struct type_list *next;
01806         } *arg_types = 0;
01807         int num_args = 0;
01808 
01809         while (**pp && **pp != '#')
01810           {
01811             struct type *arg_type = read_type (pp, objfile);
01812             struct type_list *new = alloca (sizeof (*new));
01813             new->type = arg_type;
01814             new->next = arg_types;
01815             arg_types = new;
01816             num_args++;
01817           }
01818         if (**pp == '#')
01819           ++*pp;
01820         else
01821           {
01822             complaint (&symfile_complaints,
01823                        _("Prototyped function type didn't "
01824                          "end arguments with `#':\n%s"),
01825                        type_start);
01826           }
01827 
01828         /* If there is just one argument whose type is `void', then
01829            that's just an empty argument list.  */
01830         if (arg_types
01831             && ! arg_types->next
01832             && TYPE_CODE (arg_types->type) == TYPE_CODE_VOID)
01833           num_args = 0;
01834 
01835         TYPE_FIELDS (func_type)
01836           = (struct field *) TYPE_ALLOC (func_type,
01837                                          num_args * sizeof (struct field));
01838         memset (TYPE_FIELDS (func_type), 0, num_args * sizeof (struct field));
01839         {
01840           int i;
01841           struct type_list *t;
01842 
01843           /* We stuck each argument type onto the front of the list
01844              when we read it, so the list is reversed.  Build the
01845              fields array right-to-left.  */
01846           for (t = arg_types, i = num_args - 1; t; t = t->next, i--)
01847             TYPE_FIELD_TYPE (func_type, i) = t->type;
01848         }
01849         TYPE_NFIELDS (func_type) = num_args;
01850         TYPE_PROTOTYPED (func_type) = 1;
01851 
01852         type = func_type;
01853         break;
01854       }
01855 
01856     case 'k':                   /* Const qualifier on some type (Sun) */
01857       type = read_type (pp, objfile);
01858       type = make_cv_type (1, TYPE_VOLATILE (type), type,
01859                            dbx_lookup_type (typenums, objfile));
01860       break;
01861 
01862     case 'B':                   /* Volatile qual on some type (Sun) */
01863       type = read_type (pp, objfile);
01864       type = make_cv_type (TYPE_CONST (type), 1, type,
01865                            dbx_lookup_type (typenums, objfile));
01866       break;
01867 
01868     case '@':
01869       if (isdigit (**pp) || **pp == '(' || **pp == '-')
01870         {                       /* Member (class & variable) type */
01871           /* FIXME -- we should be doing smash_to_XXX types here.  */
01872 
01873           struct type *domain = read_type (pp, objfile);
01874           struct type *memtype;
01875 
01876           if (**pp != ',')
01877             /* Invalid member type data format.  */
01878             return error_type (pp, objfile);
01879           ++*pp;
01880 
01881           memtype = read_type (pp, objfile);
01882           type = dbx_alloc_type (typenums, objfile);
01883           smash_to_memberptr_type (type, domain, memtype);
01884         }
01885       else
01886         /* type attribute */
01887         {
01888           char *attr = *pp;
01889 
01890           /* Skip to the semicolon.  */
01891           while (**pp != ';' && **pp != '\0')
01892             ++(*pp);
01893           if (**pp == '\0')
01894             return error_type (pp, objfile);
01895           else
01896             ++ * pp;            /* Skip the semicolon.  */
01897 
01898           switch (*attr)
01899             {
01900             case 's':           /* Size attribute */
01901               type_size = atoi (attr + 1);
01902               if (type_size <= 0)
01903                 type_size = -1;
01904               break;
01905 
01906             case 'S':           /* String attribute */
01907               /* FIXME: check to see if following type is array?  */
01908               is_string = 1;
01909               break;
01910 
01911             case 'V':           /* Vector attribute */
01912               /* FIXME: check to see if following type is array?  */
01913               is_vector = 1;
01914               break;
01915 
01916             default:
01917               /* Ignore unrecognized type attributes, so future compilers
01918                  can invent new ones.  */
01919               break;
01920             }
01921           ++*pp;
01922           goto again;
01923         }
01924       break;
01925 
01926     case '#':                   /* Method (class & fn) type */
01927       if ((*pp)[0] == '#')
01928         {
01929           /* We'll get the parameter types from the name.  */
01930           struct type *return_type;
01931 
01932           (*pp)++;
01933           return_type = read_type (pp, objfile);
01934           if (*(*pp)++ != ';')
01935             complaint (&symfile_complaints,
01936                        _("invalid (minimal) member type "
01937                          "data format at symtab pos %d."),
01938                        symnum);
01939           type = allocate_stub_method (return_type);
01940           if (typenums[0] != -1)
01941             *dbx_lookup_type (typenums, objfile) = type;
01942         }
01943       else
01944         {
01945           struct type *domain = read_type (pp, objfile);
01946           struct type *return_type;
01947           struct field *args;
01948           int nargs, varargs;
01949 
01950           if (**pp != ',')
01951             /* Invalid member type data format.  */
01952             return error_type (pp, objfile);
01953           else
01954             ++(*pp);
01955 
01956           return_type = read_type (pp, objfile);
01957           args = read_args (pp, ';', objfile, &nargs, &varargs);
01958           if (args == NULL)
01959             return error_type (pp, objfile);
01960           type = dbx_alloc_type (typenums, objfile);
01961           smash_to_method_type (type, domain, return_type, args,
01962                                 nargs, varargs);
01963         }
01964       break;
01965 
01966     case 'r':                   /* Range type */
01967       type = read_range_type (pp, typenums, type_size, objfile);
01968       if (typenums[0] != -1)
01969         *dbx_lookup_type (typenums, objfile) = type;
01970       break;
01971 
01972     case 'b':
01973         {
01974           /* Sun ACC builtin int type */
01975           type = read_sun_builtin_type (pp, typenums, objfile);
01976           if (typenums[0] != -1)
01977             *dbx_lookup_type (typenums, objfile) = type;
01978         }
01979       break;
01980 
01981     case 'R':                   /* Sun ACC builtin float type */
01982       type = read_sun_floating_type (pp, typenums, objfile);
01983       if (typenums[0] != -1)
01984         *dbx_lookup_type (typenums, objfile) = type;
01985       break;
01986 
01987     case 'e':                   /* Enumeration type */
01988       type = dbx_alloc_type (typenums, objfile);
01989       type = read_enum_type (pp, type, objfile);
01990       if (typenums[0] != -1)
01991         *dbx_lookup_type (typenums, objfile) = type;
01992       break;
01993 
01994     case 's':                   /* Struct type */
01995     case 'u':                   /* Union type */
01996       {
01997         enum type_code type_code = TYPE_CODE_UNDEF;
01998         type = dbx_alloc_type (typenums, objfile);
01999         switch (type_descriptor)
02000           {
02001           case 's':
02002             type_code = TYPE_CODE_STRUCT;
02003             break;
02004           case 'u':
02005             type_code = TYPE_CODE_UNION;
02006             break;
02007           }
02008         type = read_struct_type (pp, type, type_code, objfile);
02009         break;
02010       }
02011 
02012     case 'a':                   /* Array type */
02013       if (**pp != 'r')
02014         return error_type (pp, objfile);
02015       ++*pp;
02016 
02017       type = dbx_alloc_type (typenums, objfile);
02018       type = read_array_type (pp, type, objfile);
02019       if (is_string)
02020         TYPE_CODE (type) = TYPE_CODE_STRING;
02021       if (is_vector)
02022         make_vector_type (type);
02023       break;
02024 
02025     case 'S':                   /* Set type */
02026       type1 = read_type (pp, objfile);
02027       type = create_set_type ((struct type *) NULL, type1);
02028       if (typenums[0] != -1)
02029         *dbx_lookup_type (typenums, objfile) = type;
02030       break;
02031 
02032     default:
02033       --*pp;                    /* Go back to the symbol in error.  */
02034       /* Particularly important if it was \0!  */
02035       return error_type (pp, objfile);
02036     }
02037 
02038   if (type == 0)
02039     {
02040       warning (_("GDB internal error, type is NULL in stabsread.c."));
02041       return error_type (pp, objfile);
02042     }
02043 
02044   /* Size specified in a type attribute overrides any other size.  */
02045   if (type_size != -1)
02046     TYPE_LENGTH (type) = (type_size + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;
02047 
02048   return type;
02049 }
02050 
02051 /* RS/6000 xlc/dbx combination uses a set of builtin types, starting from -1.
02052    Return the proper type node for a given builtin type number.  */
02053 
02054 static const struct objfile_data *rs6000_builtin_type_data;
02055 
02056 static struct type *
02057 rs6000_builtin_type (int typenum, struct objfile *objfile)
02058 {
02059   struct type **negative_types = objfile_data (objfile,
02060                                                rs6000_builtin_type_data);
02061 
02062   /* We recognize types numbered from -NUMBER_RECOGNIZED to -1.  */
02063 #define NUMBER_RECOGNIZED 34
02064   struct type *rettype = NULL;
02065 
02066   if (typenum >= 0 || typenum < -NUMBER_RECOGNIZED)
02067     {
02068       complaint (&symfile_complaints, _("Unknown builtin type %d"), typenum);
02069       return objfile_type (objfile)->builtin_error;
02070     }
02071 
02072   if (!negative_types)
02073     {
02074       /* This includes an empty slot for type number -0.  */
02075       negative_types = OBSTACK_CALLOC (&objfile->objfile_obstack,
02076                                        NUMBER_RECOGNIZED + 1, struct type *);
02077       set_objfile_data (objfile, rs6000_builtin_type_data, negative_types);
02078     }
02079 
02080   if (negative_types[-typenum] != NULL)
02081     return negative_types[-typenum];
02082 
02083 #if TARGET_CHAR_BIT != 8
02084 #error This code wrong for TARGET_CHAR_BIT not 8
02085   /* These definitions all assume that TARGET_CHAR_BIT is 8.  I think
02086      that if that ever becomes not true, the correct fix will be to
02087      make the size in the struct type to be in bits, not in units of
02088      TARGET_CHAR_BIT.  */
02089 #endif
02090 
02091   switch (-typenum)
02092     {
02093     case 1:
02094       /* The size of this and all the other types are fixed, defined
02095          by the debugging format.  If there is a type called "int" which
02096          is other than 32 bits, then it should use a new negative type
02097          number (or avoid negative type numbers for that case).
02098          See stabs.texinfo.  */
02099       rettype = init_type (TYPE_CODE_INT, 4, 0, "int", objfile);
02100       break;
02101     case 2:
02102       rettype = init_type (TYPE_CODE_INT, 1, 0, "char", objfile);
02103       break;
02104     case 3:
02105       rettype = init_type (TYPE_CODE_INT, 2, 0, "short", objfile);
02106       break;
02107     case 4:
02108       rettype = init_type (TYPE_CODE_INT, 4, 0, "long", objfile);
02109       break;
02110     case 5:
02111       rettype = init_type (TYPE_CODE_INT, 1, TYPE_FLAG_UNSIGNED,
02112                            "unsigned char", objfile);
02113       break;
02114     case 6:
02115       rettype = init_type (TYPE_CODE_INT, 1, 0, "signed char", objfile);
02116       break;
02117     case 7:
02118       rettype = init_type (TYPE_CODE_INT, 2, TYPE_FLAG_UNSIGNED,
02119                            "unsigned short", objfile);
02120       break;
02121     case 8:
02122       rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED,
02123                            "unsigned int", objfile);
02124       break;
02125     case 9:
02126       rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED,
02127                            "unsigned", objfile);
02128       break;
02129     case 10:
02130       rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED,
02131                            "unsigned long", objfile);
02132       break;
02133     case 11:
02134       rettype = init_type (TYPE_CODE_VOID, 1, 0, "void", objfile);
02135       break;
02136     case 12:
02137       /* IEEE single precision (32 bit).  */
02138       rettype = init_type (TYPE_CODE_FLT, 4, 0, "float", objfile);
02139       break;
02140     case 13:
02141       /* IEEE double precision (64 bit).  */
02142       rettype = init_type (TYPE_CODE_FLT, 8, 0, "double", objfile);
02143       break;
02144     case 14:
02145       /* This is an IEEE double on the RS/6000, and different machines with
02146          different sizes for "long double" should use different negative
02147          type numbers.  See stabs.texinfo.  */
02148       rettype = init_type (TYPE_CODE_FLT, 8, 0, "long double", objfile);
02149       break;
02150     case 15:
02151       rettype = init_type (TYPE_CODE_INT, 4, 0, "integer", objfile);
02152       break;
02153     case 16:
02154       rettype = init_type (TYPE_CODE_BOOL, 4, TYPE_FLAG_UNSIGNED,
02155                            "boolean", objfile);
02156       break;
02157     case 17:
02158       rettype = init_type (TYPE_CODE_FLT, 4, 0, "short real", objfile);
02159       break;
02160     case 18:
02161       rettype = init_type (TYPE_CODE_FLT, 8, 0, "real", objfile);
02162       break;
02163     case 19:
02164       rettype = init_type (TYPE_CODE_ERROR, 0, 0, "stringptr", objfile);
02165       break;
02166     case 20:
02167       rettype = init_type (TYPE_CODE_CHAR, 1, TYPE_FLAG_UNSIGNED,
02168                            "character", objfile);
02169       break;
02170     case 21:
02171       rettype = init_type (TYPE_CODE_BOOL, 1, TYPE_FLAG_UNSIGNED,
02172                            "logical*1", objfile);
02173       break;
02174     case 22:
02175       rettype = init_type (TYPE_CODE_BOOL, 2, TYPE_FLAG_UNSIGNED,
02176                            "logical*2", objfile);
02177       break;
02178     case 23:
02179       rettype = init_type (TYPE_CODE_BOOL, 4, TYPE_FLAG_UNSIGNED,
02180                            "logical*4", objfile);
02181       break;
02182     case 24:
02183       rettype = init_type (TYPE_CODE_BOOL, 4, TYPE_FLAG_UNSIGNED,
02184                            "logical", objfile);
02185       break;
02186     case 25:
02187       /* Complex type consisting of two IEEE single precision values.  */
02188       rettype = init_type (TYPE_CODE_COMPLEX, 8, 0, "complex", objfile);
02189       TYPE_TARGET_TYPE (rettype) = init_type (TYPE_CODE_FLT, 4, 0, "float",
02190                                               objfile);
02191       break;
02192     case 26:
02193       /* Complex type consisting of two IEEE double precision values.  */
02194       rettype = init_type (TYPE_CODE_COMPLEX, 16, 0, "double complex", NULL);
02195       TYPE_TARGET_TYPE (rettype) = init_type (TYPE_CODE_FLT, 8, 0, "double",
02196                                               objfile);
02197       break;
02198     case 27:
02199       rettype = init_type (TYPE_CODE_INT, 1, 0, "integer*1", objfile);
02200       break;
02201     case 28:
02202       rettype = init_type (TYPE_CODE_INT, 2, 0, "integer*2", objfile);
02203       break;
02204     case 29:
02205       rettype = init_type (TYPE_CODE_INT, 4, 0, "integer*4", objfile);
02206       break;
02207     case 30:
02208       rettype = init_type (TYPE_CODE_CHAR, 2, 0, "wchar", objfile);
02209       break;
02210     case 31:
02211       rettype = init_type (TYPE_CODE_INT, 8, 0, "long long", objfile);
02212       break;
02213     case 32:
02214       rettype = init_type (TYPE_CODE_INT, 8, TYPE_FLAG_UNSIGNED,
02215                            "unsigned long long", objfile);
02216       break;
02217     case 33:
02218       rettype = init_type (TYPE_CODE_INT, 8, TYPE_FLAG_UNSIGNED,
02219                            "logical*8", objfile);
02220       break;
02221     case 34:
02222       rettype = init_type (TYPE_CODE_INT, 8, 0, "integer*8", objfile);
02223       break;
02224     }
02225   negative_types[-typenum] = rettype;
02226   return rettype;
02227 }
02228 
02229 /* This page contains subroutines of read_type.  */
02230 
02231 /* Wrapper around method_name_from_physname to flag a complaint
02232    if there is an error.  */
02233 
02234 static char *
02235 stabs_method_name_from_physname (const char *physname)
02236 {
02237   char *method_name;
02238 
02239   method_name = method_name_from_physname (physname);
02240 
02241   if (method_name == NULL)
02242     {
02243       complaint (&symfile_complaints,
02244                  _("Method has bad physname %s\n"), physname);
02245       return NULL;
02246     }
02247 
02248   return method_name;
02249 }
02250 
02251 /* Read member function stabs info for C++ classes.  The form of each member
02252    function data is:
02253 
02254    NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
02255 
02256    An example with two member functions is:
02257 
02258    afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
02259 
02260    For the case of overloaded operators, the format is op$::*.funcs, where
02261    $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
02262    name (such as `+=') and `.' marks the end of the operator name.
02263 
02264    Returns 1 for success, 0 for failure.  */
02265 
02266 static int
02267 read_member_functions (struct field_info *fip, char **pp, struct type *type,
02268                        struct objfile *objfile)
02269 {
02270   int nfn_fields = 0;
02271   int length = 0;
02272   int i;
02273   struct next_fnfield
02274     {
02275       struct next_fnfield *next;
02276       struct fn_field fn_field;
02277     }
02278    *sublist;
02279   struct type *look_ahead_type;
02280   struct next_fnfieldlist *new_fnlist;
02281   struct next_fnfield *new_sublist;
02282   char *main_fn_name;
02283   char *p;
02284 
02285   /* Process each list until we find something that is not a member function
02286      or find the end of the functions.  */
02287 
02288   while (**pp != ';')
02289     {
02290       /* We should be positioned at the start of the function name.
02291          Scan forward to find the first ':' and if it is not the
02292          first of a "::" delimiter, then this is not a member function.  */
02293       p = *pp;
02294       while (*p != ':')
02295         {
02296           p++;
02297         }
02298       if (p[1] != ':')
02299         {
02300           break;
02301         }
02302 
02303       sublist = NULL;
02304       look_ahead_type = NULL;
02305       length = 0;
02306 
02307       new_fnlist = (struct next_fnfieldlist *)
02308         xmalloc (sizeof (struct next_fnfieldlist));
02309       make_cleanup (xfree, new_fnlist);
02310       memset (new_fnlist, 0, sizeof (struct next_fnfieldlist));
02311 
02312       if ((*pp)[0] == 'o' && (*pp)[1] == 'p' && is_cplus_marker ((*pp)[2]))
02313         {
02314           /* This is a completely wierd case.  In order to stuff in the
02315              names that might contain colons (the usual name delimiter),
02316              Mike Tiemann defined a different name format which is
02317              signalled if the identifier is "op$".  In that case, the
02318              format is "op$::XXXX." where XXXX is the name.  This is
02319              used for names like "+" or "=".  YUUUUUUUK!  FIXME!  */
02320           /* This lets the user type "break operator+".
02321              We could just put in "+" as the name, but that wouldn't
02322              work for "*".  */
02323           static char opname[32] = "op$";
02324           char *o = opname + 3;
02325 
02326           /* Skip past '::'.  */
02327           *pp = p + 2;
02328 
02329           STABS_CONTINUE (pp, objfile);
02330           p = *pp;
02331           while (*p != '.')
02332             {
02333               *o++ = *p++;
02334             }
02335           main_fn_name = savestring (opname, o - opname);
02336           /* Skip past '.'  */
02337           *pp = p + 1;
02338         }
02339       else
02340         {
02341           main_fn_name = savestring (*pp, p - *pp);
02342           /* Skip past '::'.  */
02343           *pp = p + 2;
02344         }
02345       new_fnlist->fn_fieldlist.name = main_fn_name;
02346 
02347       do
02348         {
02349           new_sublist =
02350             (struct next_fnfield *) xmalloc (sizeof (struct next_fnfield));
02351           make_cleanup (xfree, new_sublist);
02352           memset (new_sublist, 0, sizeof (struct next_fnfield));
02353 
02354           /* Check for and handle cretinous dbx symbol name continuation!  */
02355           if (look_ahead_type == NULL)
02356             {
02357               /* Normal case.  */
02358               STABS_CONTINUE (pp, objfile);
02359 
02360               new_sublist->fn_field.type = read_type (pp, objfile);
02361               if (**pp != ':')
02362                 {
02363                   /* Invalid symtab info for member function.  */
02364                   return 0;
02365                 }
02366             }
02367           else
02368             {
02369               /* g++ version 1 kludge */
02370               new_sublist->fn_field.type = look_ahead_type;
02371               look_ahead_type = NULL;
02372             }
02373 
02374           (*pp)++;
02375           p = *pp;
02376           while (*p != ';')
02377             {
02378               p++;
02379             }
02380 
02381           /* If this is just a stub, then we don't have the real name here.  */
02382 
02383           if (TYPE_STUB (new_sublist->fn_field.type))
02384             {
02385               if (!TYPE_DOMAIN_TYPE (new_sublist->fn_field.type))
02386                 TYPE_DOMAIN_TYPE (new_sublist->fn_field.type) = type;
02387               new_sublist->fn_field.is_stub = 1;
02388             }
02389           new_sublist->fn_field.physname = savestring (*pp, p - *pp);
02390           *pp = p + 1;
02391 
02392           /* Set this member function's visibility fields.  */
02393           switch (*(*pp)++)
02394             {
02395             case VISIBILITY_PRIVATE:
02396               new_sublist->fn_field.is_private = 1;
02397               break;
02398             case VISIBILITY_PROTECTED:
02399               new_sublist->fn_field.is_protected = 1;
02400               break;
02401             }
02402 
02403           STABS_CONTINUE (pp, objfile);
02404           switch (**pp)
02405             {
02406             case 'A':           /* Normal functions.  */
02407               new_sublist->fn_field.is_const = 0;
02408               new_sublist->fn_field.is_volatile = 0;
02409               (*pp)++;
02410               break;
02411             case 'B':           /* `const' member functions.  */
02412               new_sublist->fn_field.is_const = 1;
02413               new_sublist->fn_field.is_volatile = 0;
02414               (*pp)++;
02415               break;
02416             case 'C':           /* `volatile' member function.  */
02417               new_sublist->fn_field.is_const = 0;
02418               new_sublist->fn_field.is_volatile = 1;
02419               (*pp)++;
02420               break;
02421             case 'D':           /* `const volatile' member function.  */
02422               new_sublist->fn_field.is_const = 1;
02423               new_sublist->fn_field.is_volatile = 1;
02424               (*pp)++;
02425               break;
02426             case '*':           /* File compiled with g++ version 1 --
02427                                    no info.  */
02428             case '?':
02429             case '.':
02430               break;
02431             default:
02432               complaint (&symfile_complaints,
02433                          _("const/volatile indicator missing, got '%c'"),
02434                          **pp);
02435               break;
02436             }
02437 
02438           switch (*(*pp)++)
02439             {
02440             case '*':
02441               {
02442                 int nbits;
02443                 /* virtual member function, followed by index.
02444                    The sign bit is set to distinguish pointers-to-methods
02445                    from virtual function indicies.  Since the array is
02446                    in words, the quantity must be shifted left by 1
02447                    on 16 bit machine, and by 2 on 32 bit machine, forcing
02448                    the sign bit out, and usable as a valid index into
02449                    the array.  Remove the sign bit here.  */
02450                 new_sublist->fn_field.voffset =
02451                   (0x7fffffff & read_huge_number (pp, ';', &nbits, 0)) + 2;
02452                 if (nbits != 0)
02453                   return 0;
02454 
02455                 STABS_CONTINUE (pp, objfile);
02456                 if (**pp == ';' || **pp == '\0')
02457                   {
02458                     /* Must be g++ version 1.  */
02459                     new_sublist->fn_field.fcontext = 0;
02460                   }
02461                 else
02462                   {
02463                     /* Figure out from whence this virtual function came.
02464                        It may belong to virtual function table of
02465                        one of its baseclasses.  */
02466                     look_ahead_type = read_type (pp, objfile);
02467                     if (**pp == ':')
02468                       {
02469                         /* g++ version 1 overloaded methods.  */
02470                       }
02471                     else
02472                       {
02473                         new_sublist->fn_field.fcontext = look_ahead_type;
02474                         if (**pp != ';')
02475                           {
02476                             return 0;
02477                           }
02478                         else
02479                           {
02480                             ++*pp;
02481                           }
02482                         look_ahead_type = NULL;
02483                       }
02484                   }
02485                 break;
02486               }
02487             case '?':
02488               /* static member function.  */
02489               {
02490                 int slen = strlen (main_fn_name);
02491 
02492                 new_sublist->fn_field.voffset = VOFFSET_STATIC;
02493 
02494                 /* For static member functions, we can't tell if they
02495                    are stubbed, as they are put out as functions, and not as
02496                    methods.
02497                    GCC v2 emits the fully mangled name if
02498                    dbxout.c:flag_minimal_debug is not set, so we have to
02499                    detect a fully mangled physname here and set is_stub
02500                    accordingly.  Fully mangled physnames in v2 start with
02501                    the member function name, followed by two underscores.
02502                    GCC v3 currently always emits stubbed member functions,
02503                    but with fully mangled physnames, which start with _Z.  */
02504                 if (!(strncmp (new_sublist->fn_field.physname,
02505                                main_fn_name, slen) == 0
02506                       && new_sublist->fn_field.physname[slen] == '_'
02507                       && new_sublist->fn_field.physname[slen + 1] == '_'))
02508                   {
02509                     new_sublist->fn_field.is_stub = 1;
02510                   }
02511                 break;
02512               }
02513 
02514             default:
02515               /* error */
02516               complaint (&symfile_complaints,
02517                          _("member function type missing, got '%c'"),
02518                          (*pp)[-1]);
02519               /* Fall through into normal member function.  */
02520 
02521             case '.':
02522               /* normal member function.  */
02523               new_sublist->fn_field.voffset = 0;
02524               new_sublist->fn_field.fcontext = 0;
02525               break;
02526             }
02527 
02528           new_sublist->next = sublist;
02529           sublist = new_sublist;
02530           length++;
02531           STABS_CONTINUE (pp, objfile);
02532         }
02533       while (**pp != ';' && **pp != '\0');
02534 
02535       (*pp)++;
02536       STABS_CONTINUE (pp, objfile);
02537 
02538       /* Skip GCC 3.X member functions which are duplicates of the callable
02539          constructor/destructor.  */
02540       if (strcmp_iw (main_fn_name, "__base_ctor ") == 0
02541           || strcmp_iw (main_fn_name, "__base_dtor ") == 0
02542           || strcmp (main_fn_name, "__deleting_dtor") == 0)
02543         {
02544           xfree (main_fn_name);
02545         }
02546       else
02547         {
02548           int has_stub = 0;
02549           int has_destructor = 0, has_other = 0;
02550           int is_v3 = 0;
02551           struct next_fnfield *tmp_sublist;
02552 
02553           /* Various versions of GCC emit various mostly-useless
02554              strings in the name field for special member functions.
02555 
02556              For stub methods, we need to defer correcting the name
02557              until we are ready to unstub the method, because the current
02558              name string is used by gdb_mangle_name.  The only stub methods
02559              of concern here are GNU v2 operators; other methods have their
02560              names correct (see caveat below).
02561 
02562              For non-stub methods, in GNU v3, we have a complete physname.
02563              Therefore we can safely correct the name now.  This primarily
02564              affects constructors and destructors, whose name will be
02565              __comp_ctor or __comp_dtor instead of Foo or ~Foo.  Cast
02566              operators will also have incorrect names; for instance,
02567              "operator int" will be named "operator i" (i.e. the type is
02568              mangled).
02569 
02570              For non-stub methods in GNU v2, we have no easy way to
02571              know if we have a complete physname or not.  For most
02572              methods the result depends on the platform (if CPLUS_MARKER
02573              can be `$' or `.', it will use minimal debug information, or
02574              otherwise the full physname will be included).
02575 
02576              Rather than dealing with this, we take a different approach.
02577              For v3 mangled names, we can use the full physname; for v2,
02578              we use cplus_demangle_opname (which is actually v2 specific),
02579              because the only interesting names are all operators - once again
02580              barring the caveat below.  Skip this process if any method in the
02581              group is a stub, to prevent our fouling up the workings of
02582              gdb_mangle_name.
02583 
02584              The caveat: GCC 2.95.x (and earlier?) put constructors and
02585              destructors in the same method group.  We need to split this
02586              into two groups, because they should have different names.
02587              So for each method group we check whether it contains both
02588              routines whose physname appears to be a destructor (the physnames
02589              for and destructors are always provided, due to quirks in v2
02590              mangling) and routines whose physname does not appear to be a
02591              destructor.  If so then we break up the list into two halves.
02592              Even if the constructors and destructors aren't in the same group
02593              the destructor will still lack the leading tilde, so that also
02594              needs to be fixed.
02595 
02596              So, to summarize what we expect and handle here:
02597 
02598                 Given         Given          Real         Real       Action
02599              method name     physname      physname   method name
02600 
02601              __opi            [none]     __opi__3Foo  operator int    opname
02602                                                                  [now or later]
02603              Foo              _._3Foo       _._3Foo      ~Foo      separate and
02604                                                                        rename
02605              operator i     _ZN3FoocviEv _ZN3FoocviEv operator int    demangle
02606              __comp_ctor  _ZN3FooC1ERKS_ _ZN3FooC1ERKS_   Foo         demangle
02607           */
02608 
02609           tmp_sublist = sublist;
02610           while (tmp_sublist != NULL)
02611             {
02612               if (tmp_sublist->fn_field.is_stub)
02613                 has_stub = 1;
02614               if (tmp_sublist->fn_field.physname[0] == '_'
02615                   && tmp_sublist->fn_field.physname[1] == 'Z')
02616                 is_v3 = 1;
02617 
02618               if (is_destructor_name (tmp_sublist->fn_field.physname))
02619                 has_destructor++;
02620               else
02621                 has_other++;
02622 
02623               tmp_sublist = tmp_sublist->next;
02624             }
02625 
02626           if (has_destructor && has_other)
02627             {
02628               struct next_fnfieldlist *destr_fnlist;
02629               struct next_fnfield *last_sublist;
02630 
02631               /* Create a new fn_fieldlist for the destructors.  */
02632 
02633               destr_fnlist = (struct next_fnfieldlist *)
02634                 xmalloc (sizeof (struct next_fnfieldlist));
02635               make_cleanup (xfree, destr_fnlist);
02636               memset (destr_fnlist, 0, sizeof (struct next_fnfieldlist));
02637               destr_fnlist->fn_fieldlist.name
02638                 = obconcat (&objfile->objfile_obstack, "~",
02639                             new_fnlist->fn_fieldlist.name, (char *) NULL);
02640 
02641               destr_fnlist->fn_fieldlist.fn_fields = (struct fn_field *)
02642                 obstack_alloc (&objfile->objfile_obstack,
02643                                sizeof (struct fn_field) * has_destructor);
02644               memset (destr_fnlist->fn_fieldlist.fn_fields, 0,
02645                   sizeof (struct fn_field) * has_destructor);
02646               tmp_sublist = sublist;
02647               last_sublist = NULL;
02648               i = 0;
02649               while (tmp_sublist != NULL)
02650                 {
02651                   if (!is_destructor_name (tmp_sublist->fn_field.physname))
02652                     {
02653                       tmp_sublist = tmp_sublist->next;
02654                       continue;
02655                     }
02656                   
02657                   destr_fnlist->fn_fieldlist.fn_fields[i++]
02658                     = tmp_sublist->fn_field;
02659                   if (last_sublist)
02660                     last_sublist->next = tmp_sublist->next;
02661                   else
02662                     sublist = tmp_sublist->next;
02663                   last_sublist = tmp_sublist;
02664                   tmp_sublist = tmp_sublist->next;
02665                 }
02666 
02667               destr_fnlist->fn_fieldlist.length = has_destructor;
02668               destr_fnlist->next = fip->fnlist;
02669               fip->fnlist = destr_fnlist;
02670               nfn_fields++;
02671               length -= has_destructor;
02672             }
02673           else if (is_v3)
02674             {
02675               /* v3 mangling prevents the use of abbreviated physnames,
02676                  so we can do this here.  There are stubbed methods in v3
02677                  only:
02678                  - in -gstabs instead of -gstabs+
02679                  - or for static methods, which are output as a function type
02680                    instead of a method type.  */
02681               char *new_method_name =
02682                 stabs_method_name_from_physname (sublist->fn_field.physname);
02683 
02684               if (new_method_name != NULL
02685                   && strcmp (new_method_name,
02686                              new_fnlist->fn_fieldlist.name) != 0)
02687                 {
02688                   new_fnlist->fn_fieldlist.name = new_method_name;
02689                   xfree (main_fn_name);
02690                 }
02691               else
02692                 xfree (new_method_name);
02693             }
02694           else if (has_destructor && new_fnlist->fn_fieldlist.name[0] != '~')
02695             {
02696               new_fnlist->fn_fieldlist.name =
02697                 obconcat (&objfile->objfile_obstack,
02698                           "~", main_fn_name, (char *)NULL);
02699               xfree (main_fn_name);
02700             }
02701           else if (!has_stub)
02702             {
02703               char dem_opname[256];
02704               int ret;
02705 
02706               ret = cplus_demangle_opname (new_fnlist->fn_fieldlist.name,
02707                                               dem_opname, DMGL_ANSI);
02708               if (!ret)
02709                 ret = cplus_demangle_opname (new_fnlist->fn_fieldlist.name,
02710                                              dem_opname, 0);
02711               if (ret)
02712                 new_fnlist->fn_fieldlist.name
02713                   = obstack_copy0 (&objfile->objfile_obstack,
02714                                    dem_opname, strlen (dem_opname));
02715               xfree (main_fn_name);
02716             }
02717 
02718           new_fnlist->fn_fieldlist.fn_fields = (struct fn_field *)
02719             obstack_alloc (&objfile->objfile_obstack,
02720                            sizeof (struct fn_field) * length);
02721           memset (new_fnlist->fn_fieldlist.fn_fields, 0,
02722                   sizeof (struct fn_field) * length);
02723           for (i = length; (i--, sublist); sublist = sublist->next)
02724             {
02725               new_fnlist->fn_fieldlist.fn_fields[i] = sublist->fn_field;
02726             }
02727 
02728           new_fnlist->fn_fieldlist.length = length;
02729           new_fnlist->next = fip->fnlist;
02730           fip->fnlist = new_fnlist;
02731           nfn_fields++;
02732         }
02733     }
02734 
02735   if (nfn_fields)
02736     {
02737       ALLOCATE_CPLUS_STRUCT_TYPE (type);
02738       TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
02739         TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * nfn_fields);
02740       memset (TYPE_FN_FIELDLISTS (type), 0,
02741               sizeof (struct fn_fieldlist) * nfn_fields);
02742       TYPE_NFN_FIELDS (type) = nfn_fields;
02743     }
02744 
02745   return 1;
02746 }
02747 
02748 /* Special GNU C++ name.
02749 
02750    Returns 1 for success, 0 for failure.  "failure" means that we can't
02751    keep parsing and it's time for error_type().  */
02752 
02753 static int
02754 read_cpp_abbrev (struct field_info *fip, char **pp, struct type *type,
02755                  struct objfile *objfile)
02756 {
02757   char *p;
02758   const char *name;
02759   char cpp_abbrev;
02760   struct type *context;
02761 
02762   p = *pp;
02763   if (*++p == 'v')
02764     {
02765       name = NULL;
02766       cpp_abbrev = *++p;
02767 
02768       *pp = p + 1;
02769 
02770       /* At this point, *pp points to something like "22:23=*22...",
02771          where the type number before the ':' is the "context" and
02772          everything after is a regular type definition.  Lookup the
02773          type, find it's name, and construct the field name.  */
02774 
02775       context = read_type (pp, objfile);
02776 
02777       switch (cpp_abbrev)
02778         {
02779         case 'f':               /* $vf -- a virtual function table pointer */
02780           name = type_name_no_tag (context);
02781           if (name == NULL)
02782             {
02783               name = "";
02784             }
02785           fip->list->field.name = obconcat (&objfile->objfile_obstack,
02786                                             vptr_name, name, (char *) NULL);
02787           break;
02788 
02789         case 'b':               /* $vb -- a virtual bsomethingorother */
02790           name = type_name_no_tag (context);
02791           if (name == NULL)
02792             {
02793               complaint (&symfile_complaints,
02794                          _("C++ abbreviated type name "
02795                            "unknown at symtab pos %d"),
02796                          symnum);
02797               name = "FOO";
02798             }
02799           fip->list->field.name = obconcat (&objfile->objfile_obstack, vb_name,
02800                                             name, (char *) NULL);
02801           break;
02802 
02803         default:
02804           invalid_cpp_abbrev_complaint (*pp);
02805           fip->list->field.name = obconcat (&objfile->objfile_obstack,
02806                                             "INVALID_CPLUSPLUS_ABBREV",
02807                                             (char *) NULL);
02808           break;
02809         }
02810 
02811       /* At this point, *pp points to the ':'.  Skip it and read the
02812          field type.  */
02813 
02814       p = ++(*pp);
02815       if (p[-1] != ':')
02816         {
02817           invalid_cpp_abbrev_complaint (*pp);
02818           return 0;
02819         }
02820       fip->list->field.type = read_type (pp, objfile);
02821       if (**pp == ',')
02822         (*pp)++;                /* Skip the comma.  */
02823       else
02824         return 0;
02825 
02826       {
02827         int nbits;
02828 
02829         SET_FIELD_BITPOS (fip->list->field,
02830                           read_huge_number (pp, ';', &nbits, 0));
02831         if (nbits != 0)
02832           return 0;
02833       }
02834       /* This field is unpacked.  */
02835       FIELD_BITSIZE (fip->list->field) = 0;
02836       fip->list->visibility = VISIBILITY_PRIVATE;
02837     }
02838   else
02839     {
02840       invalid_cpp_abbrev_complaint (*pp);
02841       /* We have no idea what syntax an unrecognized abbrev would have, so
02842          better return 0.  If we returned 1, we would need to at least advance
02843          *pp to avoid an infinite loop.  */
02844       return 0;
02845     }
02846   return 1;
02847 }
02848 
02849 static void
02850 read_one_struct_field (struct field_info *fip, char **pp, char *p,
02851                        struct type *type, struct objfile *objfile)
02852 {
02853   struct gdbarch *gdbarch = get_objfile_arch (objfile);
02854 
02855   fip->list->field.name =
02856     obstack_copy0 (&objfile->objfile_obstack, *pp, p - *pp);
02857   *pp = p + 1;
02858 
02859   /* This means we have a visibility for a field coming.  */
02860   if (**pp == '/')
02861     {
02862       (*pp)++;
02863       fip->list->visibility = *(*pp)++;
02864     }
02865   else
02866     {
02867       /* normal dbx-style format, no explicit visibility */
02868       fip->list->visibility = VISIBILITY_PUBLIC;
02869     }
02870 
02871   fip->list->field.type = read_type (pp, objfile);
02872   if (**pp == ':')
02873     {
02874       p = ++(*pp);
02875 #if 0
02876       /* Possible future hook for nested types.  */
02877       if (**pp == '!')
02878         {
02879           fip->list->field.bitpos = (long) -2;  /* nested type */
02880           p = ++(*pp);
02881         }
02882       else
02883         ...;
02884 #endif
02885       while (*p != ';')
02886         {
02887           p++;
02888         }
02889       /* Static class member.  */
02890       SET_FIELD_PHYSNAME (fip->list->field, savestring (*pp, p - *pp));
02891       *pp = p + 1;
02892       return;
02893     }
02894   else if (**pp != ',')
02895     {
02896       /* Bad structure-type format.  */
02897       stabs_general_complaint ("bad structure-type format");
02898       return;
02899     }
02900 
02901   (*pp)++;                      /* Skip the comma.  */
02902 
02903   {
02904     int nbits;
02905 
02906     SET_FIELD_BITPOS (fip->list->field,
02907                       read_huge_number (pp, ',', &nbits, 0));
02908     if (nbits != 0)
02909       {
02910         stabs_general_complaint ("bad structure-type format");
02911         return;
02912       }
02913     FIELD_BITSIZE (fip->list->field) = read_huge_number (pp, ';', &nbits, 0);
02914     if (nbits != 0)
02915       {
02916         stabs_general_complaint ("bad structure-type format");
02917         return;
02918       }
02919   }
02920 
02921   if (FIELD_BITPOS (fip->list->field) == 0
02922       && FIELD_BITSIZE (fip->list->field) == 0)
02923     {
02924       /* This can happen in two cases: (1) at least for gcc 2.4.5 or so,
02925          it is a field which has been optimized out.  The correct stab for
02926          this case is to use VISIBILITY_IGNORE, but that is a recent
02927          invention.  (2) It is a 0-size array.  For example
02928          union { int num; char str[0]; } foo.  Printing _("<no value>" for
02929          str in "p foo" is OK, since foo.str (and thus foo.str[3])
02930          will continue to work, and a 0-size array as a whole doesn't
02931          have any contents to print.
02932 
02933          I suspect this probably could also happen with gcc -gstabs (not
02934          -gstabs+) for static fields, and perhaps other C++ extensions.
02935          Hopefully few people use -gstabs with gdb, since it is intended
02936          for dbx compatibility.  */
02937 
02938       /* Ignore this field.  */
02939       fip->list->visibility = VISIBILITY_IGNORE;
02940     }
02941   else
02942     {
02943       /* Detect an unpacked field and mark it as such.
02944          dbx gives a bit size for all fields.
02945          Note that forward refs cannot be packed,
02946          and treat enums as if they had the width of ints.  */
02947 
02948       struct type *field_type = check_typedef (FIELD_TYPE (fip->list->field));
02949 
02950       if (TYPE_CODE (field_type) != TYPE_CODE_INT
02951           && TYPE_CODE (field_type) != TYPE_CODE_RANGE
02952           && TYPE_CODE (field_type) != TYPE_CODE_BOOL
02953           && TYPE_CODE (field_type) != TYPE_CODE_ENUM)
02954         {
02955           FIELD_BITSIZE (fip->list->field) = 0;
02956         }
02957       if ((FIELD_BITSIZE (fip->list->field)
02958            == TARGET_CHAR_BIT * TYPE_LENGTH (field_type)
02959            || (TYPE_CODE (field_type) == TYPE_CODE_ENUM
02960                && FIELD_BITSIZE (fip->list->field)
02961                   == gdbarch_int_bit (gdbarch))
02962           )
02963           &&
02964           FIELD_BITPOS (fip->list->field) % 8 == 0)
02965         {
02966           FIELD_BITSIZE (fip->list->field) = 0;
02967         }
02968     }
02969 }
02970 
02971 
02972 /* Read struct or class data fields.  They have the form:
02973 
02974    NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
02975 
02976    At the end, we see a semicolon instead of a field.
02977 
02978    In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
02979    a static field.
02980 
02981    The optional VISIBILITY is one of:
02982 
02983    '/0' (VISIBILITY_PRIVATE)
02984    '/1' (VISIBILITY_PROTECTED)
02985    '/2' (VISIBILITY_PUBLIC)
02986    '/9' (VISIBILITY_IGNORE)
02987 
02988    or nothing, for C style fields with public visibility.
02989 
02990    Returns 1 for success, 0 for failure.  */
02991 
02992 static int
02993 read_struct_fields (struct field_info *fip, char **pp, struct type *type,
02994                     struct objfile *objfile)
02995 {
02996   char *p;
02997   struct nextfield *new;
02998 
02999   /* We better set p right now, in case there are no fields at all...    */
03000 
03001   p = *pp;
03002 
03003   /* Read each data member type until we find the terminating ';' at the end of
03004      the data member list, or break for some other reason such as finding the
03005      start of the member function list.  */
03006   /* Stab string for structure/union does not end with two ';' in
03007      SUN C compiler 5.3 i.e. F6U2, hence check for end of string.  */
03008 
03009   while (**pp != ';' && **pp != '\0')
03010     {
03011       STABS_CONTINUE (pp, objfile);
03012       /* Get space to record the next field's data.  */
03013       new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
03014       make_cleanup (xfree, new);
03015       memset (new, 0, sizeof (struct nextfield));
03016       new->next = fip->list;
03017       fip->list = new;
03018 
03019       /* Get the field name.  */
03020       p = *pp;
03021 
03022       /* If is starts with CPLUS_MARKER it is a special abbreviation,
03023          unless the CPLUS_MARKER is followed by an underscore, in
03024          which case it is just the name of an anonymous type, which we
03025          should handle like any other type name.  */
03026 
03027       if (is_cplus_marker (p[0]) && p[1] != '_')
03028         {
03029           if (!read_cpp_abbrev (fip, pp, type, objfile))
03030             return 0;
03031           continue;
03032         }
03033 
03034       /* Look for the ':' that separates the field name from the field
03035          values.  Data members are delimited by a single ':', while member
03036          functions are delimited by a pair of ':'s.  When we hit the member
03037          functions (if any), terminate scan loop and return.  */
03038 
03039       while (*p != ':' && *p != '\0')
03040         {
03041           p++;
03042         }
03043       if (*p == '\0')
03044         return 0;
03045 
03046       /* Check to see if we have hit the member functions yet.  */
03047       if (p[1] == ':')
03048         {
03049           break;
03050         }
03051       read_one_struct_field (fip, pp, p, type, objfile);
03052     }
03053   if (p[0] == ':' && p[1] == ':')
03054     {
03055       /* (the deleted) chill the list of fields: the last entry (at
03056          the head) is a partially constructed entry which we now
03057          scrub.  */
03058       fip->list = fip->list->next;
03059     }
03060   return 1;
03061 }
03062 /* *INDENT-OFF* */
03063 /* The stabs for C++ derived classes contain baseclass information which
03064    is marked by a '!' character after the total size.  This function is
03065    called when we encounter the baseclass marker, and slurps up all the
03066    baseclass information.
03067 
03068    Immediately following the '!' marker is the number of base classes that
03069    the class is derived from, followed by information for each base class.
03070    For each base class, there are two visibility specifiers, a bit offset
03071    to the base class information within the derived class, a reference to
03072    the type for the base class, and a terminating semicolon.
03073 
03074    A typical example, with two base classes, would be "!2,020,19;0264,21;".
03075                                                        ^^ ^ ^ ^  ^ ^  ^
03076         Baseclass information marker __________________|| | | |  | |  |
03077         Number of baseclasses __________________________| | | |  | |  |
03078         Visibility specifiers (2) ________________________| | |  | |  |
03079         Offset in bits from start of class _________________| |  | |  |
03080         Type number for base class ___________________________|  | |  |
03081         Visibility specifiers (2) _______________________________| |  |
03082         Offset in bits from start of class ________________________|  |
03083         Type number of base class ____________________________________|
03084 
03085   Return 1 for success, 0 for (error-type-inducing) failure.  */
03086 /* *INDENT-ON* */
03087 
03088 
03089 
03090 static int
03091 read_baseclasses (struct field_info *fip, char **pp, struct type *type,
03092                   struct objfile *objfile)
03093 {
03094   int i;
03095   struct nextfield *new;
03096 
03097   if (**pp != '!')
03098     {
03099       return 1;
03100     }
03101   else
03102     {
03103       /* Skip the '!' baseclass information marker.  */
03104       (*pp)++;
03105     }
03106 
03107   ALLOCATE_CPLUS_STRUCT_TYPE (type);
03108   {
03109     int nbits;
03110 
03111     TYPE_N_BASECLASSES (type) = read_huge_number (pp, ',', &nbits, 0);
03112     if (nbits != 0)
03113       return 0;
03114   }
03115 
03116 #if 0
03117   /* Some stupid compilers have trouble with the following, so break
03118      it up into simpler expressions.  */
03119   TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *)
03120     TYPE_ALLOC (type, B_BYTES (TYPE_N_BASECLASSES (type)));
03121 #else
03122   {
03123     int num_bytes = B_BYTES (TYPE_N_BASECLASSES (type));
03124     char *pointer;
03125 
03126     pointer = (char *) TYPE_ALLOC (type, num_bytes);
03127     TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) pointer;
03128   }
03129 #endif /* 0 */
03130 
03131   B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), TYPE_N_BASECLASSES (type));
03132 
03133   for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
03134     {
03135       new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
03136       make_cleanup (xfree, new);
03137       memset (new, 0, sizeof (struct nextfield));
03138       new->next = fip->list;
03139       fip->list = new;
03140       FIELD_BITSIZE (new->field) = 0;   /* This should be an unpacked
03141                                            field!  */
03142 
03143       STABS_CONTINUE (pp, objfile);
03144       switch (**pp)
03145         {
03146         case '0':
03147           /* Nothing to do.  */
03148           break;
03149         case '1':
03150           SET_TYPE_FIELD_VIRTUAL (type, i);
03151           break;
03152         default:
03153           /* Unknown character.  Complain and treat it as non-virtual.  */
03154           {
03155             complaint (&symfile_complaints,
03156                        _("Unknown virtual character `%c' for baseclass"),
03157                        **pp);
03158           }
03159         }
03160       ++(*pp);
03161 
03162       new->visibility = *(*pp)++;
03163       switch (new->visibility)
03164         {
03165         case VISIBILITY_PRIVATE:
03166         case VISIBILITY_PROTECTED:
03167         case VISIBILITY_PUBLIC:
03168           break;
03169         default:
03170           /* Bad visibility format.  Complain and treat it as
03171              public.  */
03172           {
03173             complaint (&symfile_complaints,
03174                        _("Unknown visibility `%c' for baseclass"),
03175                        new->visibility);
03176             new->visibility = VISIBILITY_PUBLIC;
03177           }
03178         }
03179 
03180       {
03181         int nbits;
03182 
03183         /* The remaining value is the bit offset of the portion of the object
03184            corresponding to this baseclass.  Always zero in the absence of
03185            multiple inheritance.  */
03186 
03187         SET_FIELD_BITPOS (new->field, read_huge_number (pp, ',', &nbits, 0));
03188         if (nbits != 0)
03189           return 0;
03190       }
03191 
03192       /* The last piece of baseclass information is the type of the
03193          base class.  Read it, and remember it's type name as this
03194          field's name.  */
03195 
03196       new->field.type = read_type (pp, objfile);
03197       new->field.name = type_name_no_tag (new->field.type);
03198 
03199       /* Skip trailing ';' and bump count of number of fields seen.  */
03200       if (**pp == ';')
03201         (*pp)++;
03202       else
03203         return 0;
03204     }
03205   return 1;
03206 }
03207 
03208 /* The tail end of stabs for C++ classes that contain a virtual function
03209    pointer contains a tilde, a %, and a type number.
03210    The type number refers to the base class (possibly this class itself) which
03211    contains the vtable pointer for the current class.
03212 
03213    This function is called when we have parsed all the method declarations,
03214    so we can look for the vptr base class info.  */
03215 
03216 static int
03217 read_tilde_fields (struct field_info *fip, char **pp, struct type *type,
03218                    struct objfile *objfile)
03219 {
03220   char *p;
03221 
03222   STABS_CONTINUE (pp, objfile);
03223 
03224   /* If we are positioned at a ';', then skip it.  */
03225   if (**pp == ';')
03226     {
03227       (*pp)++;
03228     }
03229 
03230   if (**pp == '~')
03231     {
03232       (*pp)++;
03233 
03234       if (**pp == '=' || **pp == '+' || **pp == '-')
03235         {
03236           /* Obsolete flags that used to indicate the presence
03237              of constructors and/or destructors.  */
03238           (*pp)++;
03239         }
03240 
03241       /* Read either a '%' or the final ';'.  */
03242       if (*(*pp)++ == '%')
03243         {
03244           /* The next number is the type number of the base class
03245              (possibly our own class) which supplies the vtable for
03246              this class.  Parse it out, and search that class to find
03247              its vtable pointer, and install those into TYPE_VPTR_BASETYPE
03248              and TYPE_VPTR_FIELDNO.  */
03249 
03250           struct type *t;
03251           int i;
03252 
03253           t = read_type (pp, objfile);
03254           p = (*pp)++;
03255           while (*p != '\0' && *p != ';')
03256             {
03257               p++;
03258             }
03259           if (*p == '\0')
03260             {
03261               /* Premature end of symbol.  */
03262               return 0;
03263             }
03264 
03265           TYPE_VPTR_BASETYPE (type) = t;
03266           if (type == t)        /* Our own class provides vtbl ptr.  */
03267             {
03268               for (i = TYPE_NFIELDS (t) - 1;
03269                    i >= TYPE_N_BASECLASSES (t);
03270                    --i)
03271                 {
03272                   const char *name = TYPE_FIELD_NAME (t, i);
03273 
03274                   if (!strncmp (name, vptr_name, sizeof (vptr_name) - 2)
03275                       && is_cplus_marker (name[sizeof (vptr_name) - 2]))
03276                     {
03277                       TYPE_VPTR_FIELDNO (type) = i;
03278                       goto gotit;
03279                     }
03280                 }
03281               /* Virtual function table field not found.  */
03282               complaint (&symfile_complaints,
03283                          _("virtual function table pointer "
03284                            "not found when defining class `%s'"),
03285                          TYPE_NAME (type));
03286               return 0;
03287             }
03288           else
03289             {
03290               TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
03291             }
03292 
03293         gotit:
03294           *pp = p + 1;
03295         }
03296     }
03297   return 1;
03298 }
03299 
03300 static int
03301 attach_fn_fields_to_type (struct field_info *fip, struct type *type)
03302 {
03303   int n;
03304 
03305   for (n = TYPE_NFN_FIELDS (type);
03306        fip->fnlist != NULL;
03307        fip->fnlist = fip->fnlist->next)
03308     {
03309       --n;                      /* Circumvent Sun3 compiler bug.  */
03310       TYPE_FN_FIELDLISTS (type)[n] = fip->fnlist->fn_fieldlist;
03311     }
03312   return 1;
03313 }
03314 
03315 /* Create the vector of fields, and record how big it is.
03316    We need this info to record proper virtual function table information
03317    for this class's virtual functions.  */
03318 
03319 static int
03320 attach_fields_to_type (struct field_info *fip, struct type *type,
03321                        struct objfile *objfile)
03322 {
03323   int nfields = 0;
03324   int non_public_fields = 0;
03325   struct nextfield *scan;
03326 
03327   /* Count up the number of fields that we have, as well as taking note of
03328      whether or not there are any non-public fields, which requires us to
03329      allocate and build the private_field_bits and protected_field_bits
03330      bitfields.  */
03331 
03332   for (scan = fip->list; scan != NULL; scan = scan->next)
03333     {
03334       nfields++;
03335       if (scan->visibility != VISIBILITY_PUBLIC)
03336         {
03337           non_public_fields++;
03338         }
03339     }
03340 
03341   /* Now we know how many fields there are, and whether or not there are any
03342      non-public fields.  Record the field count, allocate space for the
03343      array of fields, and create blank visibility bitfields if necessary.  */
03344 
03345   TYPE_NFIELDS (type) = nfields;
03346   TYPE_FIELDS (type) = (struct field *)
03347     TYPE_ALLOC (type, sizeof (struct field) * nfields);
03348   memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
03349 
03350   if (non_public_fields)
03351     {
03352       ALLOCATE_CPLUS_STRUCT_TYPE (type);
03353 
03354       TYPE_FIELD_PRIVATE_BITS (type) =
03355         (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
03356       B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
03357 
03358       TYPE_FIELD_PROTECTED_BITS (type) =
03359         (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
03360       B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
03361 
03362       TYPE_FIELD_IGNORE_BITS (type) =
03363         (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
03364       B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields);
03365     }
03366 
03367   /* Copy the saved-up fields into the field vector.  Start from the
03368      head of the list, adding to the tail of the field array, so that
03369      they end up in the same order in the array in which they were
03370      added to the list.  */
03371 
03372   while (nfields-- > 0)
03373     {
03374       TYPE_FIELD (type, nfields) = fip->list->field;
03375       switch (fip->list->visibility)
03376         {
03377         case VISIBILITY_PRIVATE:
03378           SET_TYPE_FIELD_PRIVATE (type, nfields);
03379           break;
03380 
03381         case VISIBILITY_PROTECTED:
03382           SET_TYPE_FIELD_PROTECTED (type, nfields);
03383           break;
03384 
03385         case VISIBILITY_IGNORE:
03386           SET_TYPE_FIELD_IGNORE (type, nfields);
03387           break;
03388 
03389         case VISIBILITY_PUBLIC:
03390           break;
03391 
03392         default:
03393           /* Unknown visibility.  Complain and treat it as public.  */
03394           {
03395             complaint (&symfile_complaints,
03396                        _("Unknown visibility `%c' for field"),
03397                        fip->list->visibility);
03398           }
03399           break;
03400         }
03401       fip->list = fip->list->next;
03402     }
03403   return 1;
03404 }
03405 
03406 
03407 /* Complain that the compiler has emitted more than one definition for the
03408    structure type TYPE.  */
03409 static void 
03410 complain_about_struct_wipeout (struct type *type)
03411 {
03412   const char *name = "";
03413   const char *kind = "";
03414 
03415   if (TYPE_TAG_NAME (type))
03416     {
03417       name = TYPE_TAG_NAME (type);
03418       switch (TYPE_CODE (type))
03419         {
03420         case TYPE_CODE_STRUCT: kind = "struct "; break;
03421         case TYPE_CODE_UNION:  kind = "union ";  break;
03422         case TYPE_CODE_ENUM:   kind = "enum ";   break;
03423         default: kind = "";
03424         }
03425     }
03426   else if (TYPE_NAME (type))
03427     {
03428       name = TYPE_NAME (type);
03429       kind = "";
03430     }
03431   else
03432     {
03433       name = "<unknown>";
03434       kind = "";
03435     }
03436 
03437   complaint (&symfile_complaints,
03438              _("struct/union type gets multiply defined: %s%s"), kind, name);
03439 }
03440 
03441 /* Set the length for all variants of a same main_type, which are
03442    connected in the closed chain.
03443    
03444    This is something that needs to be done when a type is defined *after*
03445    some cross references to this type have already been read.  Consider
03446    for instance the following scenario where we have the following two
03447    stabs entries:
03448 
03449         .stabs  "t:p(0,21)=*(0,22)=k(0,23)=xsdummy:",160,0,28,-24
03450         .stabs  "dummy:T(0,23)=s16x:(0,1),0,3[...]"
03451 
03452    A stubbed version of type dummy is created while processing the first
03453    stabs entry.  The length of that type is initially set to zero, since
03454    it is unknown at this point.  Also, a "constant" variation of type
03455    "dummy" is created as well (this is the "(0,22)=k(0,23)" section of
03456    the stabs line).
03457 
03458    The second stabs entry allows us to replace the stubbed definition
03459    with the real definition.  However, we still need to adjust the length
03460    of the "constant" variation of that type, as its length was left
03461    untouched during the main type replacement...  */
03462 
03463 static void
03464 set_length_in_type_chain (struct type *type)
03465 {
03466   struct type *ntype = TYPE_CHAIN (type);
03467 
03468   while (ntype != type)
03469     {
03470       if (TYPE_LENGTH(ntype) == 0)
03471         TYPE_LENGTH (ntype) = TYPE_LENGTH (type);
03472       else
03473         complain_about_struct_wipeout (ntype);
03474       ntype = TYPE_CHAIN (ntype);
03475     }
03476 }
03477 
03478 /* Read the description of a structure (or union type) and return an object
03479    describing the type.
03480 
03481    PP points to a character pointer that points to the next unconsumed token
03482    in the stabs string.  For example, given stabs "A:T4=s4a:1,0,32;;",
03483    *PP will point to "4a:1,0,32;;".
03484 
03485    TYPE points to an incomplete type that needs to be filled in.
03486 
03487    OBJFILE points to the current objfile from which the stabs information is
03488    being read.  (Note that it is redundant in that TYPE also contains a pointer
03489    to this same objfile, so it might be a good idea to eliminate it.  FIXME). 
03490  */
03491 
03492 static struct type *
03493 read_struct_type (char **pp, struct type *type, enum type_code type_code,
03494                   struct objfile *objfile)
03495 {
03496   struct cleanup *back_to;
03497   struct field_info fi;
03498 
03499   fi.list = NULL;
03500   fi.fnlist = NULL;
03501 
03502   /* When describing struct/union/class types in stabs, G++ always drops
03503      all qualifications from the name.  So if you've got:
03504        struct A { ... struct B { ... }; ... };
03505      then G++ will emit stabs for `struct A::B' that call it simply
03506      `struct B'.  Obviously, if you've got a real top-level definition for
03507      `struct B', or other nested definitions, this is going to cause
03508      problems.
03509 
03510      Obviously, GDB can't fix this by itself, but it can at least avoid
03511      scribbling on existing structure type objects when new definitions
03512      appear.  */
03513   if (! (TYPE_CODE (type) == TYPE_CODE_UNDEF
03514          || TYPE_STUB (type)))
03515     {
03516       complain_about_struct_wipeout (type);
03517 
03518       /* It's probably best to return the type unchanged.  */
03519       return type;
03520     }
03521 
03522   back_to = make_cleanup (null_cleanup, 0);
03523 
03524   INIT_CPLUS_SPECIFIC (type);
03525   TYPE_CODE (type) = type_code;
03526   TYPE_STUB (type) = 0;
03527 
03528   /* First comes the total size in bytes.  */
03529 
03530   {
03531     int nbits;
03532 
03533     TYPE_LENGTH (type) = read_huge_number (pp, 0, &nbits, 0);
03534     if (nbits != 0)
03535       {
03536         do_cleanups (back_to);
03537         return error_type (pp, objfile);
03538       }
03539     set_length_in_type_chain (type);
03540   }
03541 
03542   /* Now read the baseclasses, if any, read the regular C struct or C++
03543      class member fields, attach the fields to the type, read the C++
03544      member functions, attach them to the type, and then read any tilde
03545      field (baseclass specifier for the class holding the main vtable).  */
03546 
03547   if (!read_baseclasses (&fi, pp, type, objfile)
03548       || !read_struct_fields (&fi, pp, type, objfile)
03549       || !attach_fields_to_type (&fi, type, objfile)
03550       || !read_member_functions (&fi, pp, type, objfile)
03551       || !attach_fn_fields_to_type (&fi, type)
03552       || !read_tilde_fields (&fi, pp, type, objfile))
03553     {
03554       type = error_type (pp, objfile);
03555     }
03556 
03557   do_cleanups (back_to);
03558   return (type);
03559 }
03560 
03561 /* Read a definition of an array type,
03562    and create and return a suitable type object.
03563    Also creates a range type which represents the bounds of that
03564    array.  */
03565 
03566 static struct type *
03567 read_array_type (char **pp, struct type *type,
03568                  struct objfile *objfile)
03569 {
03570   struct type *index_type, *element_type, *range_type;
03571   int lower, upper;
03572   int adjustable = 0;
03573   int nbits;
03574 
03575   /* Format of an array type:
03576      "ar<index type>;lower;upper;<array_contents_type>".
03577      OS9000: "arlower,upper;<array_contents_type>".
03578 
03579      Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
03580      for these, produce a type like float[][].  */
03581 
03582     {
03583       index_type = read_type (pp, objfile);
03584       if (**pp != ';')
03585         /* Improper format of array type decl.  */
03586         return error_type (pp, objfile);
03587       ++*pp;
03588     }
03589 
03590   if (!(**pp >= '0' && **pp <= '9') && **pp != '-')
03591     {
03592       (*pp)++;
03593       adjustable = 1;
03594     }
03595   lower = read_huge_number (pp, ';', &nbits, 0);
03596 
03597   if (nbits != 0)
03598     return error_type (pp, objfile);
03599 
03600   if (!(**pp >= '0' && **pp <= '9') && **pp != '-')
03601     {
03602       (*pp)++;
03603       adjustable = 1;
03604     }
03605   upper = read_huge_number (pp, ';', &nbits, 0);
03606   if (nbits != 0)
03607     return error_type (pp, objfile);
03608 
03609   element_type = read_type (pp, objfile);
03610 
03611   if (adjustable)
03612     {
03613       lower = 0;
03614       upper = -1;
03615     }
03616 
03617   range_type =
03618     create_range_type ((struct type *) NULL, index_type, lower, upper);
03619   type = create_array_type (type, element_type, range_type);
03620 
03621   return type;
03622 }
03623 
03624 
03625 /* Read a definition of an enumeration type,
03626    and create and return a suitable type object.
03627    Also defines the symbols that represent the values of the type.  */
03628 
03629 static struct type *
03630 read_enum_type (char **pp, struct type *type,
03631                 struct objfile *objfile)
03632 {
03633   struct gdbarch *gdbarch = get_objfile_arch (objfile);
03634   char *p;
03635   char *name;
03636   long n;
03637   struct symbol *sym;
03638   int nsyms = 0;
03639   struct pending **symlist;
03640   struct pending *osyms, *syms;
03641   int o_nsyms;
03642   int nbits;
03643   int unsigned_enum = 1;
03644 
03645 #if 0
03646   /* FIXME!  The stabs produced by Sun CC merrily define things that ought
03647      to be file-scope, between N_FN entries, using N_LSYM.  What's a mother
03648      to do?  For now, force all enum values to file scope.  */
03649   if (within_function)
03650     symlist = &local_symbols;
03651   else
03652 #endif
03653     symlist = &file_symbols;
03654   osyms = *symlist;
03655   o_nsyms = osyms ? osyms->nsyms : 0;
03656 
03657   /* The aix4 compiler emits an extra field before the enum members;
03658      my guess is it's a type of some sort.  Just ignore it.  */
03659   if (**pp == '-')
03660     {
03661       /* Skip over the type.  */
03662       while (**pp != ':')
03663         (*pp)++;
03664 
03665       /* Skip over the colon.  */
03666       (*pp)++;
03667     }
03668 
03669   /* Read the value-names and their values.
03670      The input syntax is NAME:VALUE,NAME:VALUE, and so on.
03671      A semicolon or comma instead of a NAME means the end.  */
03672   while (**pp && **pp != ';' && **pp != ',')
03673     {
03674       STABS_CONTINUE (pp, objfile);
03675       p = *pp;
03676       while (*p != ':')
03677         p++;
03678       name = obstack_copy0 (&objfile->objfile_obstack, *pp, p - *pp);
03679       *pp = p + 1;
03680       n = read_huge_number (pp, ',', &nbits, 0);
03681       if (nbits != 0)
03682         return error_type (pp, objfile);
03683 
03684       sym = allocate_symbol (objfile);
03685       SYMBOL_SET_LINKAGE_NAME (sym, name);
03686       SYMBOL_SET_LANGUAGE (sym, current_subfile->language,
03687                            &objfile->objfile_obstack);
03688       SYMBOL_ACLASS_INDEX (sym) = LOC_CONST;
03689       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
03690       SYMBOL_VALUE (sym) = n;
03691       if (n < 0)
03692         unsigned_enum = 0;
03693       add_symbol_to_list (sym, symlist);
03694       nsyms++;
03695     }
03696 
03697   if (**pp == ';')
03698     (*pp)++;                    /* Skip the semicolon.  */
03699 
03700   /* Now fill in the fields of the type-structure.  */
03701 
03702   TYPE_LENGTH (type) = gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT;
03703   set_length_in_type_chain (type);
03704   TYPE_CODE (type) = TYPE_CODE_ENUM;
03705   TYPE_STUB (type) = 0;
03706   if (unsigned_enum)
03707     TYPE_UNSIGNED (type) = 1;
03708   TYPE_NFIELDS (type) = nsyms;
03709   TYPE_FIELDS (type) = (struct field *)
03710     TYPE_ALLOC (type, sizeof (struct field) * nsyms);
03711   memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nsyms);
03712 
03713   /* Find the symbols for the values and put them into the type.
03714      The symbols can be found in the symlist that we put them on
03715      to cause them to be defined.  osyms contains the old value
03716      of that symlist; everything up to there was defined by us.  */
03717   /* Note that we preserve the order of the enum constants, so
03718      that in something like "enum {FOO, LAST_THING=FOO}" we print
03719      FOO, not LAST_THING.  */
03720 
03721   for (syms = *symlist, n = nsyms - 1; syms; syms = syms->next)
03722     {
03723       int last = syms == osyms ? o_nsyms : 0;
03724       int j = syms->nsyms;
03725 
03726       for (; --j >= last; --n)
03727         {
03728           struct symbol *xsym = syms->symbol[j];
03729 
03730           SYMBOL_TYPE (xsym) = type;
03731           TYPE_FIELD_NAME (type, n) = SYMBOL_LINKAGE_NAME (xsym);
03732           SET_FIELD_ENUMVAL (TYPE_FIELD (type, n), SYMBOL_VALUE (xsym));
03733           TYPE_FIELD_BITSIZE (type, n) = 0;
03734         }
03735       if (syms == osyms)
03736         break;
03737     }
03738 
03739   return type;
03740 }
03741 
03742 /* Sun's ACC uses a somewhat saner method for specifying the builtin
03743    typedefs in every file (for int, long, etc):
03744 
03745    type = b <signed> <width> <format type>; <offset>; <nbits>
03746    signed = u or s.
03747    optional format type = c or b for char or boolean.
03748    offset = offset from high order bit to start bit of type.
03749    width is # bytes in object of this type, nbits is # bits in type.
03750 
03751    The width/offset stuff appears to be for small objects stored in
03752    larger ones (e.g. `shorts' in `int' registers).  We ignore it for now,
03753    FIXME.  */
03754 
03755 static struct type *
03756 read_sun_builtin_type (char **pp, int typenums[2], struct objfile *objfile)
03757 {
03758   int type_bits;
03759   int nbits;
03760   int signed_type;
03761   enum type_code code = TYPE_CODE_INT;
03762 
03763   switch (**pp)
03764     {
03765     case 's':
03766       signed_type = 1;
03767       break;
03768     case 'u':
03769       signed_type = 0;
03770       break;
03771     default:
03772       return error_type (pp, objfile);
03773     }
03774   (*pp)++;
03775 
03776   /* For some odd reason, all forms of char put a c here.  This is strange
03777      because no other type has this honor.  We can safely ignore this because
03778      we actually determine 'char'acterness by the number of bits specified in
03779      the descriptor.
03780      Boolean forms, e.g Fortran logical*X, put a b here.  */
03781 
03782   if (**pp == 'c')
03783     (*pp)++;
03784   else if (**pp == 'b')
03785     {
03786       code = TYPE_CODE_BOOL;
03787       (*pp)++;
03788     }
03789 
03790   /* The first number appears to be the number of bytes occupied
03791      by this type, except that unsigned short is 4 instead of 2.
03792      Since this information is redundant with the third number,
03793      we will ignore it.  */
03794   read_huge_number (pp, ';', &nbits, 0);
03795   if (nbits != 0)
03796     return error_type (pp, objfile);
03797 
03798   /* The second number is always 0, so ignore it too.  */
03799   read_huge_number (pp, ';', &nbits, 0);
03800   if (nbits != 0)
03801     return error_type (pp, objfile);
03802 
03803   /* The third number is the number of bits for this type.  */
03804   type_bits = read_huge_number (pp, 0, &nbits, 0);
03805   if (nbits != 0)
03806     return error_type (pp, objfile);
03807   /* The type *should* end with a semicolon.  If it are embedded
03808      in a larger type the semicolon may be the only way to know where
03809      the type ends.  If this type is at the end of the stabstring we
03810      can deal with the omitted semicolon (but we don't have to like
03811      it).  Don't bother to complain(), Sun's compiler omits the semicolon
03812      for "void".  */
03813   if (**pp == ';')
03814     ++(*pp);
03815 
03816   if (type_bits == 0)
03817     return init_type (TYPE_CODE_VOID, 1,
03818                       signed_type ? 0 : TYPE_FLAG_UNSIGNED, (char *) NULL,
03819                       objfile);
03820   else
03821     return init_type (code,
03822                       type_bits / TARGET_CHAR_BIT,
03823                       signed_type ? 0 : TYPE_FLAG_UNSIGNED, (char *) NULL,
03824                       objfile);
03825 }
03826 
03827 static struct type *
03828 read_sun_floating_type (char **pp, int typenums[2], struct objfile *objfile)
03829 {
03830   int nbits;
03831   int details;
03832   int nbytes;
03833   struct type *rettype;
03834 
03835   /* The first number has more details about the type, for example
03836      FN_COMPLEX.  */
03837   details = read_huge_number (pp, ';', &nbits, 0);
03838   if (nbits != 0)
03839     return error_type (pp, objfile);
03840 
03841   /* The second number is the number of bytes occupied by this type.  */
03842   nbytes = read_huge_number (pp, ';', &nbits, 0);
03843   if (nbits != 0)
03844     return error_type (pp, objfile);
03845 
03846   if (details == NF_COMPLEX || details == NF_COMPLEX16
03847       || details == NF_COMPLEX32)
03848     {
03849       rettype = init_type (TYPE_CODE_COMPLEX, nbytes, 0, NULL, objfile);
03850       TYPE_TARGET_TYPE (rettype)
03851         = init_type (TYPE_CODE_FLT, nbytes / 2, 0, NULL, objfile);
03852       return rettype;
03853     }
03854 
03855   return init_type (TYPE_CODE_FLT, nbytes, 0, NULL, objfile);
03856 }
03857 
03858 /* Read a number from the string pointed to by *PP.
03859    The value of *PP is advanced over the number.
03860    If END is nonzero, the character that ends the
03861    number must match END, or an error happens;
03862    and that character is skipped if it does match.
03863    If END is zero, *PP is left pointing to that character.
03864 
03865    If TWOS_COMPLEMENT_BITS is set to a strictly positive value and if
03866    the number is represented in an octal representation, assume that
03867    it is represented in a 2's complement representation with a size of
03868    TWOS_COMPLEMENT_BITS.
03869 
03870    If the number fits in a long, set *BITS to 0 and return the value.
03871    If not, set *BITS to be the number of bits in the number and return 0.
03872 
03873    If encounter garbage, set *BITS to -1 and return 0.  */
03874 
03875 static long
03876 read_huge_number (char **pp, int end, int *bits, int twos_complement_bits)
03877 {
03878   char *p = *pp;
03879   int sign = 1;
03880   int sign_bit = 0;
03881   long n = 0;
03882   int radix = 10;
03883   char overflow = 0;
03884   int nbits = 0;
03885   int c;
03886   long upper_limit;
03887   int twos_complement_representation = 0;
03888 
03889   if (*p == '-')
03890     {
03891       sign = -1;
03892       p++;
03893     }
03894 
03895   /* Leading zero means octal.  GCC uses this to output values larger
03896      than an int (because that would be hard in decimal).  */
03897   if (*p == '0')
03898     {
03899       radix = 8;
03900       p++;
03901     }
03902 
03903   /* Skip extra zeros.  */
03904   while (*p == '0')
03905     p++;
03906 
03907   if (sign > 0 && radix == 8 && twos_complement_bits > 0)
03908     {
03909       /* Octal, possibly signed.  Check if we have enough chars for a
03910          negative number.  */
03911 
03912       size_t len;
03913       char *p1 = p;
03914 
03915       while ((c = *p1) >= '0' && c < '8')
03916         p1++;
03917 
03918       len = p1 - p;
03919       if (len > twos_complement_bits / 3
03920           || (twos_complement_bits % 3 == 0
03921               && len == twos_complement_bits / 3))
03922         {
03923           /* Ok, we have enough characters for a signed value, check
03924              for signness by testing if the sign bit is set.  */
03925           sign_bit = (twos_complement_bits % 3 + 2) % 3;
03926           c = *p - '0';
03927           if (c & (1 << sign_bit))
03928             {
03929               /* Definitely signed.  */
03930               twos_complement_representation = 1;
03931               sign = -1;
03932             }
03933         }
03934     }
03935 
03936   upper_limit = LONG_MAX / radix;
03937 
03938   while ((c = *p++) >= '0' && c < ('0' + radix))
03939     {
03940       if (n <= upper_limit)
03941         {
03942           if (twos_complement_representation)
03943             {
03944               /* Octal, signed, twos complement representation.  In
03945                  this case, n is the corresponding absolute value.  */
03946               if (n == 0)
03947                 {
03948                   long sn = c - '0' - ((2 * (c - '0')) | (2 << sign_bit));
03949 
03950                   n = -sn;
03951                 }
03952               else
03953                 {
03954                   n *= radix;
03955                   n -= c - '0';
03956                 }
03957             }
03958           else
03959             {
03960               /* unsigned representation */
03961               n *= radix;
03962               n += c - '0';             /* FIXME this overflows anyway.  */
03963             }
03964         }
03965       else
03966         overflow = 1;
03967 
03968       /* This depends on large values being output in octal, which is
03969          what GCC does.  */
03970       if (radix == 8)
03971         {
03972           if (nbits == 0)
03973             {
03974               if (c == '0')
03975                 /* Ignore leading zeroes.  */
03976                 ;
03977               else if (c == '1')
03978                 nbits = 1;
03979               else if (c == '2' || c == '3')
03980                 nbits = 2;
03981               else
03982                 nbits = 3;
03983             }
03984           else
03985             nbits += 3;
03986         }
03987     }
03988   if (end)
03989     {
03990       if (c && c != end)
03991         {
03992           if (bits != NULL)
03993             *bits = -1;
03994           return 0;
03995         }
03996     }
03997   else
03998     --p;
03999 
04000   if (radix == 8 && twos_complement_bits > 0 && nbits > twos_complement_bits)
04001     {
04002       /* We were supposed to parse a number with maximum
04003          TWOS_COMPLEMENT_BITS bits, but something went wrong.  */
04004       if (bits != NULL)
04005         *bits = -1;
04006       return 0;
04007     }
04008 
04009   *pp = p;
04010   if (overflow)
04011     {
04012       if (nbits == 0)
04013         {
04014           /* Large decimal constants are an error (because it is hard to
04015              count how many bits are in them).  */
04016           if (bits != NULL)
04017             *bits = -1;
04018           return 0;
04019         }
04020 
04021       /* -0x7f is the same as 0x80.  So deal with it by adding one to
04022          the number of bits.  Two's complement represention octals
04023          can't have a '-' in front.  */
04024       if (sign == -1 && !twos_complement_representation)
04025         ++nbits;
04026       if (bits)
04027         *bits = nbits;
04028     }
04029   else
04030     {
04031       if (bits)
04032         *bits = 0;
04033       return n * sign;
04034     }
04035   /* It's *BITS which has the interesting information.  */
04036   return 0;
04037 }
04038 
04039 static struct type *
04040 read_range_type (char **pp, int typenums[2], int type_size,
04041                  struct objfile *objfile)
04042 {
04043   struct gdbarch *gdbarch = get_objfile_arch (objfile);
04044   char *orig_pp = *pp;
04045   int rangenums[2];
04046   long n2, n3;
04047   int n2bits, n3bits;
04048   int self_subrange;
04049   struct type *result_type;
04050   struct type *index_type = NULL;
04051 
04052   /* First comes a type we are a subrange of.
04053      In C it is usually 0, 1 or the type being defined.  */
04054   if (read_type_number (pp, rangenums) != 0)
04055     return error_type (pp, objfile);
04056   self_subrange = (rangenums[0] == typenums[0] &&
04057                    rangenums[1] == typenums[1]);
04058 
04059   if (**pp == '=')
04060     {
04061       *pp = orig_pp;
04062       index_type = read_type (pp, objfile);
04063     }
04064 
04065   /* A semicolon should now follow; skip it.  */
04066   if (**pp == ';')
04067     (*pp)++;
04068 
04069   /* The remaining two operands are usually lower and upper bounds
04070      of the range.  But in some special cases they mean something else.  */
04071   n2 = read_huge_number (pp, ';', &n2bits, type_size);
04072   n3 = read_huge_number (pp, ';', &n3bits, type_size);
04073 
04074   if (n2bits == -1 || n3bits == -1)
04075     return error_type (pp, objfile);
04076 
04077   if (index_type)
04078     goto handle_true_range;
04079 
04080   /* If limits are huge, must be large integral type.  */
04081   if (n2bits != 0 || n3bits != 0)
04082     {
04083       char got_signed = 0;
04084       char got_unsigned = 0;
04085       /* Number of bits in the type.  */
04086       int nbits = 0;
04087 
04088       /* If a type size attribute has been specified, the bounds of
04089          the range should fit in this size.  If the lower bounds needs
04090          more bits than the upper bound, then the type is signed.  */
04091       if (n2bits <= type_size && n3bits <= type_size)
04092         {
04093           if (n2bits == type_size && n2bits > n3bits)
04094             got_signed = 1;
04095           else
04096             got_unsigned = 1;
04097           nbits = type_size;
04098         }
04099       /* Range from 0 to <large number> is an unsigned large integral type.  */
04100       else if ((n2bits == 0 && n2 == 0) && n3bits != 0)
04101         {
04102           got_unsigned = 1;
04103           nbits = n3bits;
04104         }
04105       /* Range from <large number> to <large number>-1 is a large signed
04106          integral type.  Take care of the case where <large number> doesn't
04107          fit in a long but <large number>-1 does.  */
04108       else if ((n2bits != 0 && n3bits != 0 && n2bits == n3bits + 1)
04109                || (n2bits != 0 && n3bits == 0
04110                    && (n2bits == sizeof (long) * HOST_CHAR_BIT)
04111                    && n3 == LONG_MAX))
04112         {
04113           got_signed = 1;
04114           nbits = n2bits;
04115         }
04116 
04117       if (got_signed || got_unsigned)
04118         {
04119           return init_type (TYPE_CODE_INT, nbits / TARGET_CHAR_BIT,
04120                             got_unsigned ? TYPE_FLAG_UNSIGNED : 0, NULL,
04121                             objfile);
04122         }
04123       else
04124         return error_type (pp, objfile);
04125     }
04126 
04127   /* A type defined as a subrange of itself, with bounds both 0, is void.  */
04128   if (self_subrange && n2 == 0 && n3 == 0)
04129     return init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile);
04130 
04131   /* If n3 is zero and n2 is positive, we want a floating type, and n2
04132      is the width in bytes.
04133 
04134      Fortran programs appear to use this for complex types also.  To
04135      distinguish between floats and complex, g77 (and others?)  seem
04136      to use self-subranges for the complexes, and subranges of int for
04137      the floats.
04138 
04139      Also note that for complexes, g77 sets n2 to the size of one of
04140      the member floats, not the whole complex beast.  My guess is that
04141      this was to work well with pre-COMPLEX versions of gdb.  */
04142 
04143   if (n3 == 0 && n2 > 0)
04144     {
04145       struct type *float_type
04146         = init_type (TYPE_CODE_FLT, n2, 0, NULL, objfile);
04147 
04148       if (self_subrange)
04149         {
04150           struct type *complex_type = 
04151             init_type (TYPE_CODE_COMPLEX, 2 * n2, 0, NULL, objfile);
04152 
04153           TYPE_TARGET_TYPE (complex_type) = float_type;
04154           return complex_type;
04155         }
04156       else
04157         return float_type;
04158     }
04159 
04160   /* If the upper bound is -1, it must really be an unsigned integral.  */
04161 
04162   else if (n2 == 0 && n3 == -1)
04163     {
04164       int bits = type_size;
04165 
04166       if (bits <= 0)
04167         {
04168           /* We don't know its size.  It is unsigned int or unsigned
04169              long.  GCC 2.3.3 uses this for long long too, but that is
04170              just a GDB 3.5 compatibility hack.  */
04171           bits = gdbarch_int_bit (gdbarch);
04172         }
04173 
04174       return init_type (TYPE_CODE_INT, bits / TARGET_CHAR_BIT,
04175                         TYPE_FLAG_UNSIGNED, NULL, objfile);
04176     }
04177 
04178   /* Special case: char is defined (Who knows why) as a subrange of
04179      itself with range 0-127.  */
04180   else if (self_subrange && n2 == 0 && n3 == 127)
04181     return init_type (TYPE_CODE_INT, 1, TYPE_FLAG_NOSIGN, NULL, objfile);
04182 
04183   /* We used to do this only for subrange of self or subrange of int.  */
04184   else if (n2 == 0)
04185     {
04186       /* -1 is used for the upper bound of (4 byte) "unsigned int" and
04187          "unsigned long", and we already checked for that,
04188          so don't need to test for it here.  */
04189 
04190       if (n3 < 0)
04191         /* n3 actually gives the size.  */
04192         return init_type (TYPE_CODE_INT, -n3, TYPE_FLAG_UNSIGNED,
04193                           NULL, objfile);
04194 
04195       /* Is n3 == 2**(8n)-1 for some integer n?  Then it's an
04196          unsigned n-byte integer.  But do require n to be a power of
04197          two; we don't want 3- and 5-byte integers flying around.  */
04198       {
04199         int bytes;
04200         unsigned long bits;
04201 
04202         bits = n3;
04203         for (bytes = 0; (bits & 0xff) == 0xff; bytes++)
04204           bits >>= 8;
04205         if (bits == 0
04206             && ((bytes - 1) & bytes) == 0) /* "bytes is a power of two" */
04207           return init_type (TYPE_CODE_INT, bytes, TYPE_FLAG_UNSIGNED, NULL,
04208                             objfile);
04209       }
04210     }
04211   /* I think this is for Convex "long long".  Since I don't know whether
04212      Convex sets self_subrange, I also accept that particular size regardless
04213      of self_subrange.  */
04214   else if (n3 == 0 && n2 < 0
04215            && (self_subrange
04216                || n2 == -gdbarch_long_long_bit
04217                           (gdbarch) / TARGET_CHAR_BIT))
04218     return init_type (TYPE_CODE_INT, -n2, 0, NULL, objfile);
04219   else if (n2 == -n3 - 1)
04220     {
04221       if (n3 == 0x7f)
04222         return init_type (TYPE_CODE_INT, 1, 0, NULL, objfile);
04223       if (n3 == 0x7fff)
04224         return init_type (TYPE_CODE_INT, 2, 0, NULL, objfile);
04225       if (n3 == 0x7fffffff)
04226         return init_type (TYPE_CODE_INT, 4, 0, NULL, objfile);
04227     }
04228 
04229   /* We have a real range type on our hands.  Allocate space and
04230      return a real pointer.  */
04231 handle_true_range:
04232 
04233   if (self_subrange)
04234     index_type = objfile_type (objfile)->builtin_int;
04235   else
04236     index_type = *dbx_lookup_type (rangenums, objfile);
04237   if (index_type == NULL)
04238     {
04239       /* Does this actually ever happen?  Is that why we are worrying
04240          about dealing with it rather than just calling error_type?  */
04241 
04242       complaint (&symfile_complaints,
04243                  _("base type %d of range type is not defined"), rangenums[1]);
04244 
04245       index_type = objfile_type (objfile)->builtin_int;
04246     }
04247 
04248   result_type = create_range_type ((struct type *) NULL, index_type, n2, n3);
04249   return (result_type);
04250 }
04251 
04252 /* Read in an argument list.  This is a list of types, separated by commas
04253    and terminated with END.  Return the list of types read in, or NULL
04254    if there is an error.  */
04255 
04256 static struct field *
04257 read_args (char **pp, int end, struct objfile *objfile, int *nargsp,
04258            int *varargsp)
04259 {
04260   /* FIXME!  Remove this arbitrary limit!  */
04261   struct type *types[1024];     /* Allow for fns of 1023 parameters.  */
04262   int n = 0, i;
04263   struct field *rval;
04264 
04265   while (**pp != end)
04266     {
04267       if (**pp != ',')
04268         /* Invalid argument list: no ','.  */
04269         return NULL;
04270       (*pp)++;
04271       STABS_CONTINUE (pp, objfile);
04272       types[n++] = read_type (pp, objfile);
04273     }
04274   (*pp)++;                      /* get past `end' (the ':' character).  */
04275 
04276   if (n == 0)
04277     {
04278       /* We should read at least the THIS parameter here.  Some broken stabs
04279          output contained `(0,41),(0,42)=@s8;-16;,(0,43),(0,1);' where should
04280          have been present ";-16,(0,43)" reference instead.  This way the
04281          excessive ";" marker prematurely stops the parameters parsing.  */
04282 
04283       complaint (&symfile_complaints, _("Invalid (empty) method arguments"));
04284       *varargsp = 0;
04285     }
04286   else if (TYPE_CODE (types[n - 1]) != TYPE_CODE_VOID)
04287     *varargsp = 1;
04288   else
04289     {
04290       n--;
04291       *varargsp = 0;
04292     }
04293 
04294   rval = (struct field *) xmalloc (n * sizeof (struct field));
04295   memset (rval, 0, n * sizeof (struct field));
04296   for (i = 0; i < n; i++)
04297     rval[i].type = types[i];
04298   *nargsp = n;
04299   return rval;
04300 }
04301 
04302 /* Common block handling.  */
04303 
04304 /* List of symbols declared since the last BCOMM.  This list is a tail
04305    of local_symbols.  When ECOMM is seen, the symbols on the list
04306    are noted so their proper addresses can be filled in later,
04307    using the common block base address gotten from the assembler
04308    stabs.  */
04309 
04310 static struct pending *common_block;
04311 static int common_block_i;
04312 
04313 /* Name of the current common block.  We get it from the BCOMM instead of the
04314    ECOMM to match IBM documentation (even though IBM puts the name both places
04315    like everyone else).  */
04316 static char *common_block_name;
04317 
04318 /* Process a N_BCOMM symbol.  The storage for NAME is not guaranteed
04319    to remain after this function returns.  */
04320 
04321 void
04322 common_block_start (char *name, struct objfile *objfile)
04323 {
04324   if (common_block_name != NULL)
04325     {
04326       complaint (&symfile_complaints,
04327                  _("Invalid symbol data: common block within common block"));
04328     }
04329   common_block = local_symbols;
04330   common_block_i = local_symbols ? local_symbols->nsyms : 0;
04331   common_block_name = obstack_copy0 (&objfile->objfile_obstack,
04332                                      name, strlen (name));
04333 }
04334 
04335 /* Process a N_ECOMM symbol.  */
04336 
04337 void
04338 common_block_end (struct objfile *objfile)
04339 {
04340   /* Symbols declared since the BCOMM are to have the common block
04341      start address added in when we know it.  common_block and
04342      common_block_i point to the first symbol after the BCOMM in
04343      the local_symbols list; copy the list and hang it off the
04344      symbol for the common block name for later fixup.  */
04345   int i;
04346   struct symbol *sym;
04347   struct pending *new = 0;
04348   struct pending *next;
04349   int j;
04350 
04351   if (common_block_name == NULL)
04352     {
04353       complaint (&symfile_complaints, _("ECOMM symbol unmatched by BCOMM"));
04354       return;
04355     }
04356 
04357   sym = allocate_symbol (objfile);
04358   /* Note: common_block_name already saved on objfile_obstack.  */
04359   SYMBOL_SET_LINKAGE_NAME (sym, common_block_name);
04360   SYMBOL_ACLASS_INDEX (sym) = LOC_BLOCK;
04361 
04362   /* Now we copy all the symbols which have been defined since the BCOMM.  */
04363 
04364   /* Copy all the struct pendings before common_block.  */
04365   for (next = local_symbols;
04366        next != NULL && next != common_block;
04367        next = next->next)
04368     {
04369       for (j = 0; j < next->nsyms; j++)
04370         add_symbol_to_list (next->symbol[j], &new);
04371     }
04372 
04373   /* Copy however much of COMMON_BLOCK we need.  If COMMON_BLOCK is
04374      NULL, it means copy all the local symbols (which we already did
04375      above).  */
04376 
04377   if (common_block != NULL)
04378     for (j = common_block_i; j < common_block->nsyms; j++)
04379       add_symbol_to_list (common_block->symbol[j], &new);
04380 
04381   SYMBOL_TYPE (sym) = (struct type *) new;
04382 
04383   /* Should we be putting local_symbols back to what it was?
04384      Does it matter?  */
04385 
04386   i = hashname (SYMBOL_LINKAGE_NAME (sym));
04387   SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i];
04388   global_sym_chain[i] = sym;
04389   common_block_name = NULL;
04390 }
04391 
04392 /* Add a common block's start address to the offset of each symbol
04393    declared to be in it (by being between a BCOMM/ECOMM pair that uses
04394    the common block name).  */
04395 
04396 static void
04397 fix_common_block (struct symbol *sym, CORE_ADDR valu)
04398 {
04399   struct pending *next = (struct pending *) SYMBOL_TYPE (sym);
04400 
04401   for (; next; next = next->next)
04402     {
04403       int j;
04404 
04405       for (j = next->nsyms - 1; j >= 0; j--)
04406         SYMBOL_VALUE_ADDRESS (next->symbol[j]) += valu;
04407     }
04408 }
04409 
04410 
04411 
04412 /* Add {TYPE, TYPENUMS} to the NONAME_UNDEFS vector.
04413    See add_undefined_type for more details.  */
04414 
04415 static void
04416 add_undefined_type_noname (struct type *type, int typenums[2])
04417 {
04418   struct nat nat;
04419 
04420   nat.typenums[0] = typenums [0];
04421   nat.typenums[1] = typenums [1];
04422   nat.type = type;
04423 
04424   if (noname_undefs_length == noname_undefs_allocated)
04425     {
04426       noname_undefs_allocated *= 2;
04427       noname_undefs = (struct nat *)
04428         xrealloc ((char *) noname_undefs,
04429                   noname_undefs_allocated * sizeof (struct nat));
04430     }
04431   noname_undefs[noname_undefs_length++] = nat;
04432 }
04433 
04434 /* Add TYPE to the UNDEF_TYPES vector.
04435    See add_undefined_type for more details.  */
04436 
04437 static void
04438 add_undefined_type_1 (struct type *type)
04439 {
04440   if (undef_types_length == undef_types_allocated)
04441     {
04442       undef_types_allocated *= 2;
04443       undef_types = (struct type **)
04444         xrealloc ((char *) undef_types,
04445                   undef_types_allocated * sizeof (struct type *));
04446     }
04447   undef_types[undef_types_length++] = type;
04448 }
04449 
04450 /* What about types defined as forward references inside of a small lexical
04451    scope?  */
04452 /* Add a type to the list of undefined types to be checked through
04453    once this file has been read in.
04454    
04455    In practice, we actually maintain two such lists: The first list
04456    (UNDEF_TYPES) is used for types whose name has been provided, and
04457    concerns forward references (eg 'xs' or 'xu' forward references);
04458    the second list (NONAME_UNDEFS) is used for types whose name is
04459    unknown at creation time, because they were referenced through
04460    their type number before the actual type was declared.
04461    This function actually adds the given type to the proper list.  */
04462 
04463 static void
04464 add_undefined_type (struct type *type, int typenums[2])
04465 {
04466   if (TYPE_TAG_NAME (type) == NULL)
04467     add_undefined_type_noname (type, typenums);
04468   else
04469     add_undefined_type_1 (type);
04470 }
04471 
04472 /* Try to fix all undefined types pushed on the UNDEF_TYPES vector.  */
04473 
04474 static void
04475 cleanup_undefined_types_noname (struct objfile *objfile)
04476 {
04477   int i;
04478 
04479   for (i = 0; i < noname_undefs_length; i++)
04480     {
04481       struct nat nat = noname_undefs[i];
04482       struct type **type;
04483 
04484       type = dbx_lookup_type (nat.typenums, objfile);
04485       if (nat.type != *type && TYPE_CODE (*type) != TYPE_CODE_UNDEF)
04486         {
04487           /* The instance flags of the undefined type are still unset,
04488              and needs to be copied over from the reference type.
04489              Since replace_type expects them to be identical, we need
04490              to set these flags manually before hand.  */
04491           TYPE_INSTANCE_FLAGS (nat.type) = TYPE_INSTANCE_FLAGS (*type);
04492           replace_type (nat.type, *type);
04493         }
04494     }
04495 
04496   noname_undefs_length = 0;
04497 }
04498 
04499 /* Go through each undefined type, see if it's still undefined, and fix it
04500    up if possible.  We have two kinds of undefined types:
04501 
04502    TYPE_CODE_ARRAY:  Array whose target type wasn't defined yet.
04503    Fix:  update array length using the element bounds
04504    and the target type's length.
04505    TYPE_CODE_STRUCT, TYPE_CODE_UNION:  Structure whose fields were not
04506    yet defined at the time a pointer to it was made.
04507    Fix:  Do a full lookup on the struct/union tag.  */
04508 
04509 static void
04510 cleanup_undefined_types_1 (void)
04511 {
04512   struct type **type;
04513 
04514   /* Iterate over every undefined type, and look for a symbol whose type
04515      matches our undefined type.  The symbol matches if:
04516        1. It is a typedef in the STRUCT domain;
04517        2. It has the same name, and same type code;
04518        3. The instance flags are identical.
04519      
04520      It is important to check the instance flags, because we have seen
04521      examples where the debug info contained definitions such as:
04522 
04523          "foo_t:t30=B31=xefoo_t:"
04524 
04525      In this case, we have created an undefined type named "foo_t" whose
04526      instance flags is null (when processing "xefoo_t"), and then created
04527      another type with the same name, but with different instance flags
04528      ('B' means volatile).  I think that the definition above is wrong,
04529      since the same type cannot be volatile and non-volatile at the same
04530      time, but we need to be able to cope with it when it happens.  The
04531      approach taken here is to treat these two types as different.  */
04532 
04533   for (type = undef_types; type < undef_types + undef_types_length; type++)
04534     {
04535       switch (TYPE_CODE (*type))
04536         {
04537 
04538         case TYPE_CODE_STRUCT:
04539         case TYPE_CODE_UNION:
04540         case TYPE_CODE_ENUM:
04541           {
04542             /* Check if it has been defined since.  Need to do this here
04543                as well as in check_typedef to deal with the (legitimate in
04544                C though not C++) case of several types with the same name
04545                in different source files.  */
04546             if (TYPE_STUB (*type))
04547               {
04548                 struct pending *ppt;
04549                 int i;
04550                 /* Name of the type, without "struct" or "union".  */
04551                 const char *typename = TYPE_TAG_NAME (*type);
04552 
04553                 if (typename == NULL)
04554                   {
04555                     complaint (&symfile_complaints, _("need a type name"));
04556                     break;
04557                   }
04558                 for (ppt = file_symbols; ppt; ppt = ppt->next)
04559                   {
04560                     for (i = 0; i < ppt->nsyms; i++)
04561                       {
04562                         struct symbol *sym = ppt->symbol[i];
04563 
04564                         if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
04565                             && SYMBOL_DOMAIN (sym) == STRUCT_DOMAIN
04566                             && (TYPE_CODE (SYMBOL_TYPE (sym)) ==
04567                                 TYPE_CODE (*type))
04568                             && (TYPE_INSTANCE_FLAGS (*type) ==
04569                                 TYPE_INSTANCE_FLAGS (SYMBOL_TYPE (sym)))
04570                             && strcmp (SYMBOL_LINKAGE_NAME (sym),
04571                                        typename) == 0)
04572                           replace_type (*type, SYMBOL_TYPE (sym));
04573                       }
04574                   }
04575               }
04576           }
04577           break;
04578 
04579         default:
04580           {
04581             complaint (&symfile_complaints,
04582                        _("forward-referenced types left unresolved, "
04583                        "type code %d."),
04584                        TYPE_CODE (*type));
04585           }
04586           break;
04587         }
04588     }
04589 
04590   undef_types_length = 0;
04591 }
04592 
04593 /* Try to fix all the undefined types we ecountered while processing
04594    this unit.  */
04595 
04596 void
04597 cleanup_undefined_stabs_types (struct objfile *objfile)
04598 {
04599   cleanup_undefined_types_1 ();
04600   cleanup_undefined_types_noname (objfile);
04601 }
04602 
04603 /* Scan through all of the global symbols defined in the object file,
04604    assigning values to the debugging symbols that need to be assigned
04605    to.  Get these symbols from the minimal symbol table.  */
04606 
04607 void
04608 scan_file_globals (struct objfile *objfile)
04609 {
04610   int hash;
04611   struct minimal_symbol *msymbol;
04612   struct symbol *sym, *prev;
04613   struct objfile *resolve_objfile;
04614 
04615   /* SVR4 based linkers copy referenced global symbols from shared
04616      libraries to the main executable.
04617      If we are scanning the symbols for a shared library, try to resolve
04618      them from the minimal symbols of the main executable first.  */
04619 
04620   if (symfile_objfile && objfile != symfile_objfile)
04621     resolve_objfile = symfile_objfile;
04622   else
04623     resolve_objfile = objfile;
04624 
04625   while (1)
04626     {
04627       /* Avoid expensive loop through all minimal symbols if there are
04628          no unresolved symbols.  */
04629       for (hash = 0; hash < HASHSIZE; hash++)
04630         {
04631           if (global_sym_chain[hash])
04632             break;
04633         }
04634       if (hash >= HASHSIZE)
04635         return;
04636 
04637       ALL_OBJFILE_MSYMBOLS (resolve_objfile, msymbol)
04638         {
04639           QUIT;
04640 
04641           /* Skip static symbols.  */
04642           switch (MSYMBOL_TYPE (msymbol))
04643             {
04644             case mst_file_text:
04645             case mst_file_data:
04646             case mst_file_bss:
04647               continue;
04648             default:
04649               break;
04650             }
04651 
04652           prev = NULL;
04653 
04654           /* Get the hash index and check all the symbols
04655              under that hash index.  */
04656 
04657           hash = hashname (SYMBOL_LINKAGE_NAME (msymbol));
04658 
04659           for (sym = global_sym_chain[hash]; sym;)
04660             {
04661               if (strcmp (SYMBOL_LINKAGE_NAME (msymbol),
04662                           SYMBOL_LINKAGE_NAME (sym)) == 0)
04663                 {
04664                   /* Splice this symbol out of the hash chain and
04665                      assign the value we have to it.  */
04666                   if (prev)
04667                     {
04668                       SYMBOL_VALUE_CHAIN (prev) = SYMBOL_VALUE_CHAIN (sym);
04669                     }
04670                   else
04671                     {
04672                       global_sym_chain[hash] = SYMBOL_VALUE_CHAIN (sym);
04673                     }
04674 
04675                   /* Check to see whether we need to fix up a common block.  */
04676                   /* Note: this code might be executed several times for
04677                      the same symbol if there are multiple references.  */
04678                   if (sym)
04679                     {
04680                       if (SYMBOL_CLASS (sym) == LOC_BLOCK)
04681                         {
04682                           fix_common_block (sym,
04683                                             SYMBOL_VALUE_ADDRESS (msymbol));
04684                         }
04685                       else
04686                         {
04687                           SYMBOL_VALUE_ADDRESS (sym)
04688                             = SYMBOL_VALUE_ADDRESS (msymbol);
04689                         }
04690                       SYMBOL_SECTION (sym) = SYMBOL_SECTION (msymbol);
04691                     }
04692 
04693                   if (prev)
04694                     {
04695                       sym = SYMBOL_VALUE_CHAIN (prev);
04696                     }
04697                   else
04698                     {
04699                       sym = global_sym_chain[hash];
04700                     }
04701                 }
04702               else
04703                 {
04704                   prev = sym;
04705                   sym = SYMBOL_VALUE_CHAIN (sym);
04706                 }
04707             }
04708         }
04709       if (resolve_objfile == objfile)
04710         break;
04711       resolve_objfile = objfile;
04712     }
04713 
04714   /* Change the storage class of any remaining unresolved globals to
04715      LOC_UNRESOLVED and remove them from the chain.  */
04716   for (hash = 0; hash < HASHSIZE; hash++)
04717     {
04718       sym = global_sym_chain[hash];
04719       while (sym)
04720         {
04721           prev = sym;
04722           sym = SYMBOL_VALUE_CHAIN (sym);
04723 
04724           /* Change the symbol address from the misleading chain value
04725              to address zero.  */
04726           SYMBOL_VALUE_ADDRESS (prev) = 0;
04727 
04728           /* Complain about unresolved common block symbols.  */
04729           if (SYMBOL_CLASS (prev) == LOC_STATIC)
04730             SYMBOL_ACLASS_INDEX (prev) = LOC_UNRESOLVED;
04731           else
04732             complaint (&symfile_complaints,
04733                        _("%s: common block `%s' from "
04734                          "global_sym_chain unresolved"),
04735                        objfile_name (objfile), SYMBOL_PRINT_NAME (prev));
04736         }
04737     }
04738   memset (global_sym_chain, 0, sizeof (global_sym_chain));
04739 }
04740 
04741 /* Initialize anything that needs initializing when starting to read
04742    a fresh piece of a symbol file, e.g. reading in the stuff corresponding
04743    to a psymtab.  */
04744 
04745 void
04746 stabsread_init (void)
04747 {
04748 }
04749 
04750 /* Initialize anything that needs initializing when a completely new
04751    symbol file is specified (not just adding some symbols from another
04752    file, e.g. a shared library).  */
04753 
04754 void
04755 stabsread_new_init (void)
04756 {
04757   /* Empty the hash table of global syms looking for values.  */
04758   memset (global_sym_chain, 0, sizeof (global_sym_chain));
04759 }
04760 
04761 /* Initialize anything that needs initializing at the same time as
04762    start_symtab() is called.  */
04763 
04764 void
04765 start_stabs (void)
04766 {
04767   global_stabs = NULL;          /* AIX COFF */
04768   /* Leave FILENUM of 0 free for builtin types and this file's types.  */
04769   n_this_object_header_files = 1;
04770   type_vector_length = 0;
04771   type_vector = (struct type **) 0;
04772 
04773   /* FIXME: If common_block_name is not already NULL, we should complain().  */
04774   common_block_name = NULL;
04775 }
04776 
04777 /* Call after end_symtab().  */
04778 
04779 void
04780 end_stabs (void)
04781 {
04782   if (type_vector)
04783     {
04784       xfree (type_vector);
04785     }
04786   type_vector = 0;
04787   type_vector_length = 0;
04788   previous_stab_code = 0;
04789 }
04790 
04791 void
04792 finish_global_stabs (struct objfile *objfile)
04793 {
04794   if (global_stabs)
04795     {
04796       patch_block_stabs (global_symbols, global_stabs, objfile);
04797       xfree (global_stabs);
04798       global_stabs = NULL;
04799     }
04800 }
04801 
04802 /* Find the end of the name, delimited by a ':', but don't match
04803    ObjC symbols which look like -[Foo bar::]:bla.  */
04804 static char *
04805 find_name_end (char *name)
04806 {
04807   char *s = name;
04808 
04809   if (s[0] == '-' || *s == '+')
04810     {
04811       /* Must be an ObjC method symbol.  */
04812       if (s[1] != '[')
04813         {
04814           error (_("invalid symbol name \"%s\""), name);
04815         }
04816       s = strchr (s, ']');
04817       if (s == NULL)
04818         {
04819           error (_("invalid symbol name \"%s\""), name);
04820         }
04821       return strchr (s, ':');
04822     }
04823   else
04824     {
04825       return strchr (s, ':');
04826     }
04827 }
04828 
04829 /* Initializer for this module.  */
04830 
04831 void
04832 _initialize_stabsread (void)
04833 {
04834   rs6000_builtin_type_data = register_objfile_data ();
04835 
04836   undef_types_allocated = 20;
04837   undef_types_length = 0;
04838   undef_types = (struct type **)
04839     xmalloc (undef_types_allocated * sizeof (struct type *));
04840 
04841   noname_undefs_allocated = 20;
04842   noname_undefs_length = 0;
04843   noname_undefs = (struct nat *)
04844     xmalloc (noname_undefs_allocated * sizeof (struct nat));
04845 
04846   stab_register_index = register_symbol_register_impl (LOC_REGISTER,
04847                                                        &stab_register_funcs);
04848   stab_regparm_index = register_symbol_register_impl (LOC_REGPARM_ADDR,
04849                                                       &stab_register_funcs);
04850 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines