fixup position of #ifdef BFD64 for powerpc delta recently applied.
[deliverable/binutils-gdb.git] / gdb / stabsread.c
index ec59cf36bd08f22464cf40f6e0d90bb2210c195b..47502141547b23ae6487db4c34d2fd570294f6b8 100644 (file)
@@ -1,5 +1,6 @@
 /* Support routines for decoding "stabs" debugging information format.
-   Copyright 1986, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 1998
+   Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
+   1996, 1997, 1998, 1999, 2000, 2001, 2002
    Free Software Foundation, Inc.
 
    This file is part of GDB.
@@ -42,6 +43,7 @@
 #include "complaints.h"
 #include "demangle.h"
 #include "language.h"
+#include "doublest.h"
 
 #include <ctype.h>
 
@@ -51,7 +53,7 @@
 #include "stabsread.h"         /* Our own declarations */
 #undef EXTERN
 
-extern void _initialize_stabsread PARAMS ((void));
+extern void _initialize_stabsread (void);
 
 /* The routines that read and process a complete stabs for a C struct or 
    C++ class pass lists of data member fields and lists of member function
@@ -82,117 +84,104 @@ struct field_info
   };
 
 static void
-read_one_struct_field PARAMS ((struct field_info *, char **, char *,
-                              struct type *, struct objfile *));
+read_one_struct_field (struct field_info *, char **, char *,
+                      struct type *, struct objfile *);
 
-static char *
-  get_substring PARAMS ((char **, int));
+static char *get_substring (char **, int);
 
-static struct type *
-  dbx_alloc_type PARAMS ((int[2], struct objfile *));
+static struct type *dbx_alloc_type (int[2], struct objfile *);
 
-static long read_huge_number PARAMS ((char **, int, int *));
+static long read_huge_number (char **, int, int *);
 
-static struct type *error_type PARAMS ((char **, struct objfile *));
+static struct type *error_type (char **, struct objfile *);
 
 static void
-patch_block_stabs PARAMS ((struct pending *, struct pending_stabs *,
-                          struct objfile *));
+patch_block_stabs (struct pending *, struct pending_stabs *,
+                  struct objfile *);
 
-static void
-fix_common_block PARAMS ((struct symbol *, int));
+static void fix_common_block (struct symbol *, int);
 
-static int
-read_type_number PARAMS ((char **, int *));
+static int read_type_number (char **, int *);
 
-static struct type *
-  read_range_type PARAMS ((char **, int[2], struct objfile *));
+static struct type *read_range_type (char **, int[2], struct objfile *);
 
-static struct type *
-  read_sun_builtin_type PARAMS ((char **, int[2], struct objfile *));
+static struct type *read_sun_builtin_type (char **, int[2], struct objfile *);
 
-static struct type *
-  read_sun_floating_type PARAMS ((char **, int[2], struct objfile *));
+static struct type *read_sun_floating_type (char **, int[2],
+                                           struct objfile *);
 
-static struct type *
-  read_enum_type PARAMS ((char **, struct type *, struct objfile *));
+static struct type *read_enum_type (char **, struct type *, struct objfile *);
 
-static struct type *
-  rs6000_builtin_type PARAMS ((int));
+static struct type *rs6000_builtin_type (int);
 
 static int
-read_member_functions PARAMS ((struct field_info *, char **, struct type *,
-                              struct objfile *));
+read_member_functions (struct field_info *, char **, struct type *,
+                      struct objfile *);
 
 static int
-read_struct_fields PARAMS ((struct field_info *, char **, struct type *,
-                           struct objfile *));
+read_struct_fields (struct field_info *, char **, struct type *,
+                   struct objfile *);
 
 static int
-read_baseclasses PARAMS ((struct field_info *, char **, struct type *,
-                         struct objfile *));
+read_baseclasses (struct field_info *, char **, struct type *,
+                 struct objfile *);
 
 static int
-read_tilde_fields PARAMS ((struct field_info *, char **, struct type *,
-                          struct objfile *));
+read_tilde_fields (struct field_info *, char **, struct type *,
+                  struct objfile *);
 
-static int
-attach_fn_fields_to_type PARAMS ((struct field_info *, struct type *));
+static int attach_fn_fields_to_type (struct field_info *, struct type *);
 
 static int
-attach_fields_to_type PARAMS ((struct field_info *, struct type *,
-                              struct objfile *));
+attach_fields_to_type (struct field_info *, struct type *, struct objfile *);
 
-static struct type *
-  read_struct_type PARAMS ((char **, struct type *, struct objfile *));
+static struct type *read_struct_type (char **, struct type *,
+                                      enum type_code,
+                                     struct objfile *);
 
-static struct type *
-  read_array_type PARAMS ((char **, struct type *, struct objfile *));
+static struct type *read_array_type (char **, struct type *,
+                                    struct objfile *);
 
-static struct type **
-  read_args PARAMS ((char **, int, struct objfile *));
+static struct field *read_args (char **, int, struct objfile *, int *, int *);
 
 static int
-read_cpp_abbrev PARAMS ((struct field_info *, char **, struct type *,
-                        struct objfile *));
+read_cpp_abbrev (struct field_info *, char **, struct type *,
+                struct objfile *);
 
 /* new functions added for cfront support */
 
 static int
-copy_cfront_struct_fields PARAMS ((struct field_info *, struct type *,
-                                  struct objfile *));
+copy_cfront_struct_fields (struct field_info *, struct type *,
+                          struct objfile *);
 
-static char *
-  get_cfront_method_physname PARAMS ((char *));
+static char *get_cfront_method_physname (char *);
 
 static int
-read_cfront_baseclasses PARAMS ((struct field_info *, char **,
-                                struct type *, struct objfile *));
+read_cfront_baseclasses (struct field_info *, char **,
+                        struct type *, struct objfile *);
 
 static int
-read_cfront_static_fields PARAMS ((struct field_info *, char **,
-                                  struct type *, struct objfile *));
+read_cfront_static_fields (struct field_info *, char **,
+                          struct type *, struct objfile *);
 static int
-read_cfront_member_functions PARAMS ((struct field_info *, char **,
-                                     struct type *, struct objfile *));
+read_cfront_member_functions (struct field_info *, char **,
+                             struct type *, struct objfile *);
 
 /* end new functions added for cfront support */
 
 static void
-add_live_range PARAMS ((struct objfile *, struct symbol *,
-                       CORE_ADDR, CORE_ADDR));
+add_live_range (struct objfile *, struct symbol *, CORE_ADDR, CORE_ADDR);
 
-static int
-resolve_live_range PARAMS ((struct objfile *, struct symbol *, char *));
+static int resolve_live_range (struct objfile *, struct symbol *, char *);
 
-static int
-process_reference PARAMS ((char **string));
+static int process_reference (char **string);
 
-static CORE_ADDR
-  ref_search_value PARAMS ((int refnum));
+static CORE_ADDR ref_search_value (int refnum);
 
 static int
-resolve_symbol_reference PARAMS ((struct objfile *, struct symbol *, char *));
+resolve_symbol_reference (struct objfile *, struct symbol *, char *);
+
+void stabsread_clear_cache (void);
 
 static const char vptr_name[] =
 {'_', 'v', 'p', 't', 'r', CPLUS_MARKER, '\0'};
@@ -224,7 +213,7 @@ static struct complaint const_vol_complaint =
 {"const/volatile indicator missing, got '%c'", 0, 0};
 
 static struct complaint error_type_complaint =
-{"debug info mismatch between compiler and debugger", 0, 0};
+{"couldn't parse type; debugger out of date?", 0, 0};
 
 static struct complaint invalid_member_complaint =
 {"invalid (minimal) member type data format at symtab pos %d.", 0, 0};
@@ -286,13 +275,12 @@ static struct type **os9k_type_vector[] =
   &builtin_type_long_double
 };
 
-static void os9k_init_type_vector PARAMS ((struct type **));
+static void os9k_init_type_vector (struct type **);
 
 static void
-os9k_init_type_vector (tv)
-     struct type **tv;
+os9k_init_type_vector (struct type **tv)
 {
-  int i;
+  unsigned int i;
   for (i = 0; i < sizeof (os9k_type_vector) / sizeof (struct type **); i++)
     tv[i] = (os9k_type_vector[i] == 0 ? 0 : *(os9k_type_vector[i]));
 }
@@ -305,8 +293,7 @@ os9k_init_type_vector (tv)
    or for associating a new type with the pair.  */
 
 struct type **
-dbx_lookup_type (typenums)
-     int typenums[2];
+dbx_lookup_type (int typenums[2])
 {
   register int filenum = typenums[0];
   register int index = typenums[1];
@@ -413,9 +400,7 @@ Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.",
    put into the type vector, and so may not be referred to by number. */
 
 static struct type *
-dbx_alloc_type (typenums, objfile)
-     int typenums[2];
-     struct objfile *objfile;
+dbx_alloc_type (int typenums[2], struct objfile *objfile)
 {
   register struct type **type_addr;
 
@@ -441,10 +426,8 @@ dbx_alloc_type (typenums, objfile)
    and fix their symbols in given symbol vector. */
 
 static void
-patch_block_stabs (symbols, stabs, objfile)
-     struct pending *symbols;
-     struct pending_stabs *stabs;
-     struct objfile *objfile;
+patch_block_stabs (struct pending *symbols, struct pending_stabs *stabs,
+                  struct objfile *objfile)
 {
   int ii;
   char *name;
@@ -531,9 +514,7 @@ patch_block_stabs (symbols, stabs, objfile)
    Returns 0 for success, -1 for error.  */
 
 static int
-read_type_number (pp, typenums)
-     register char **pp;
-     register int *typenums;
+read_type_number (register char **pp, register int *typenums)
 {
   int nbits;
   if (**pp == '(')
@@ -557,10 +538,6 @@ read_type_number (pp, typenums)
 }
 \f
 
-#if !defined (REG_STRUCT_HAS_ADDR)
-#define REG_STRUCT_HAS_ADDR(gcc_p,type) 0
-#endif
-
 #define VISIBILITY_PRIVATE     '0'     /* Stabs character for private field */
 #define VISIBILITY_PROTECTED   '1'     /* Stabs character for protected fld */
 #define VISIBILITY_PUBLIC      '2'     /* Stabs character for public field */
@@ -575,9 +552,7 @@ read_type_number (pp, typenums)
    suibstring. */
 
 static char *
-get_substring (p, c)
-     char **p;
-     int c;
+get_substring (char **p, int c)
 {
   char *str;
   str = *p;
@@ -598,8 +573,7 @@ get_substring (p, c)
    eg: for sname="a" and fname="foo__1aFPFs_i" return "FPFs_i" */
 
 static char *
-get_cfront_method_physname (fname)
-     char *fname;
+get_cfront_method_physname (char *fname)
 {
   int len = 0;
   /* FIXME would like to make this generic for g++ too, but 
@@ -635,11 +609,8 @@ get_cfront_method_physname (fname)
  */
 
 static int
-read_cfront_baseclasses (fip, pp, type, objfile)
-     struct field_info *fip;
-     struct objfile *objfile;
-     char **pp;
-     struct type *type;
+read_cfront_baseclasses (struct field_info *fip, char **pp, struct type *type,
+                        struct objfile *objfile)
 {
   static struct complaint msg_unknown =
   {"\
@@ -686,7 +657,7 @@ read_cfront_baseclasses (fip, pp, type, objfile)
   for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
     {
       new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
-      make_cleanup (free, new);
+      make_cleanup (xfree, new);
       memset (new, 0, sizeof (struct nextfield));
       new->next = fip->list;
       fip->list = new;
@@ -788,11 +759,8 @@ read_cfront_baseclasses (fip, pp, type, objfile)
  */
 
 static int
-read_cfront_member_functions (fip, pp, type, objfile)
-     struct field_info *fip;
-     char **pp;
-     struct type *type;
-     struct objfile *objfile;
+read_cfront_member_functions (struct field_info *fip, char **pp,
+                             struct type *type, struct objfile *objfile)
 {
   /* This code extracted from read_member_functions 
      so as to do the similar thing for our funcs */
@@ -849,7 +817,7 @@ read_cfront_member_functions (fip, pp, type, objfile)
 
       new_fnlist = (struct next_fnfieldlist *)
        xmalloc (sizeof (struct next_fnfieldlist));
-      make_cleanup (free, new_fnlist);
+      make_cleanup (xfree, new_fnlist);
       memset (new_fnlist, 0, sizeof (struct next_fnfieldlist));
 
       /* The following is code to work around cfront generated stabs.
@@ -892,7 +860,7 @@ read_cfront_member_functions (fip, pp, type, objfile)
 
       new_sublist =
        (struct next_fnfield *) xmalloc (sizeof (struct next_fnfield));
-      make_cleanup (free, new_sublist);
+      make_cleanup (xfree, new_sublist);
       memset (new_sublist, 0, sizeof (struct next_fnfield));
 
       /* eat 1; from :;2A.; */
@@ -902,7 +870,7 @@ read_cfront_member_functions (fip, pp, type, objfile)
       TYPE_CODE (new_sublist->fn_field.type) = TYPE_CODE_METHOD;
 
       /* If this is just a stub, then we don't have the real name here. */
-      if (TYPE_FLAGS (new_sublist->fn_field.type) & TYPE_FLAG_STUB)
+      if (TYPE_STUB (new_sublist->fn_field.type))
        {
          if (!TYPE_DOMAIN_TYPE (new_sublist->fn_field.type))
            TYPE_DOMAIN_TYPE (new_sublist->fn_field.type) = type;
@@ -996,10 +964,8 @@ read_cfront_member_functions (fip, pp, type, objfile)
    to add information such as methods to classes.
    Examples of "p": "sA;;__ct__1AFv foo__1AFv ;;;" */
 int
-resolve_cfront_continuation (objfile, sym, p)
-     struct objfile *objfile;
-     struct symbol *sym;
-     char *p;
+resolve_cfront_continuation (struct objfile *objfile, struct symbol *sym,
+                            char *p)
 {
   struct symbol *ref_sym = 0;
   char *sname;
@@ -1068,10 +1034,7 @@ resolve_cfront_continuation (objfile, sym, p)
    symbol definition.  Returns 0 on failure, non-zero on success.  */
 
 static int
-resolve_symbol_reference (objfile, sym, p)
-     struct objfile *objfile;
-     struct symbol *sym;
-     char *p;
+resolve_symbol_reference (struct objfile *objfile, struct symbol *sym, char *p)
 {
   int refnum;
   struct symbol *ref_sym = 0;
@@ -1192,16 +1155,22 @@ static int ref_count = 0;
 /* Number of chunks malloced. */
 static int ref_chunk = 0;
 
+/* This file maintains a cache of stabs aliases found in the symbol
+   table. If the symbol table changes, this cache must be cleared
+   or we are left holding onto data in invalid obstacks. */
+void
+stabsread_clear_cache (void)
+{
+  ref_count = 0;
+  ref_chunk = 0;
+}
+
 /* Create array of pointers mapping refids to symbols and stab strings.
    Add pointers to reference definition symbols and/or their values as we 
    find them, using their reference numbers as our index. 
    These will be used later when we resolve references. */
 void
-ref_add (refnum, sym, stabs, value)
-     int refnum;
-     struct symbol *sym;
-     char *stabs;
-     CORE_ADDR value;
+ref_add (int refnum, struct symbol *sym, char *stabs, CORE_ADDR value)
 {
   if (ref_count == 0)
     ref_chunk = 0;
@@ -1223,8 +1192,7 @@ ref_add (refnum, sym, stabs, value)
 
 /* Return defined sym for the reference REFNUM.  */
 struct symbol *
-ref_search (refnum)
-     int refnum;
+ref_search (int refnum)
 {
   if (refnum < 0 || refnum > ref_count)
     return 0;
@@ -1234,8 +1202,7 @@ ref_search (refnum)
 /* Return value for the reference REFNUM.  */
 
 static CORE_ADDR
-ref_search_value (refnum)
-     int refnum;
+ref_search_value (int refnum)
 {
   if (refnum < 0 || refnum > ref_count)
     return 0;
@@ -1246,8 +1213,7 @@ ref_search_value (refnum)
    reference number.  Move STRING beyond the reference id.  */
 
 static int
-process_reference (string)
-     char **string;
+process_reference (char **string)
 {
   char *p;
   int refnum = 0;
@@ -1272,8 +1238,7 @@ process_reference (string)
    definition for later use.  Return the reference number.  */
 
 int
-symbol_reference_defined (string)
-     char **string;
+symbol_reference_defined (char **string)
 {
   char *p = *string;
   int refnum = 0;
@@ -1298,12 +1263,8 @@ symbol_reference_defined (string)
 
 /* ARGSUSED */
 struct symbol *
-define_symbol (valu, string, desc, type, objfile)
-     CORE_ADDR valu;
-     char *string;
-     int desc;
-     int type;
-     struct objfile *objfile;
+define_symbol (CORE_ADDR valu, char *string, int desc, int type,
+              struct objfile *objfile)
 {
   register struct symbol *sym;
   char *p = (char *) strchr (string, ':');
@@ -1343,13 +1304,13 @@ define_symbol (valu, string, desc, type, objfile)
   switch (type & N_TYPE)
     {
     case N_TEXT:
-      SYMBOL_SECTION (sym) = SECT_OFF_TEXT;
+      SYMBOL_SECTION (sym) = SECT_OFF_TEXT (objfile);
       break;
     case N_DATA:
-      SYMBOL_SECTION (sym) = SECT_OFF_DATA;
+      SYMBOL_SECTION (sym) = SECT_OFF_DATA (objfile);
       break;
     case N_BSS:
-      SYMBOL_SECTION (sym) = SECT_OFF_BSS;
+      SYMBOL_SECTION (sym) = SECT_OFF_BSS (objfile);
       break;
     }
 
@@ -1531,7 +1492,7 @@ define_symbol (valu, string, desc, type, objfile)
            dbl_valu = (char *)
              obstack_alloc (&objfile->symbol_obstack,
                             TYPE_LENGTH (SYMBOL_TYPE (sym)));
-           store_floating (dbl_valu, TYPE_LENGTH (SYMBOL_TYPE (sym)), d);
+           store_typed_floating (dbl_valu, SYMBOL_TYPE (sym), d);
            SYMBOL_VALUE_BYTES (sym) = dbl_valu;
            SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
          }
@@ -1668,7 +1629,8 @@ define_symbol (valu, string, desc, type, objfile)
                 FIXME: Do we need a new builtin_type_promoted_int_arg ?  */
              if (TYPE_CODE (ptype) == TYPE_CODE_VOID)
                ptype = builtin_type_int;
-             TYPE_FIELD_TYPE (ftype, nparams++) = ptype;
+             TYPE_FIELD_TYPE (ftype, nparams) = ptype;
+             TYPE_FIELD_ARTIFICIAL (ftype, nparams++) = 0;
            }
          TYPE_NFIELDS (ftype) = nparams;
          TYPE_FLAGS (ftype) |= TYPE_FLAG_PROTOTYPED;
@@ -1741,7 +1703,7 @@ define_symbol (valu, string, desc, type, objfile)
       SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
       add_symbol_to_list (sym, &local_symbols);
 
-      if (TARGET_BYTE_ORDER != BIG_ENDIAN)
+      if (TARGET_BYTE_ORDER != BFD_ENDIAN_BIG)
        {
          /* On little-endian machines, this crud is never necessary,
             and, if the extra bytes contain garbage, is harmful.  */
@@ -1843,9 +1805,10 @@ define_symbol (valu, string, desc, type, objfile)
       SYMBOL_TYPE (sym) = read_type (&p, objfile);
       SYMBOL_CLASS (sym) = LOC_REGPARM;
       SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
-      if (SYMBOL_VALUE (sym) >= NUM_REGS)
+      if (SYMBOL_VALUE (sym) >= NUM_REGS + NUM_PSEUDO_REGS)
        {
-         complain (&reg_value_complaint, SYMBOL_VALUE (sym), NUM_REGS,
+         complain (&reg_value_complaint, SYMBOL_VALUE (sym),
+                   NUM_REGS + NUM_PSEUDO_REGS,
                    SYMBOL_SOURCE_NAME (sym));
          SYMBOL_VALUE (sym) = SP_REGNUM;       /* Known safe, though useless */
        }
@@ -1858,9 +1821,10 @@ define_symbol (valu, string, desc, type, objfile)
       SYMBOL_TYPE (sym) = read_type (&p, objfile);
       SYMBOL_CLASS (sym) = LOC_REGISTER;
       SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
-      if (SYMBOL_VALUE (sym) >= NUM_REGS)
+      if (SYMBOL_VALUE (sym) >= NUM_REGS + NUM_PSEUDO_REGS)
        {
-         complain (&reg_value_complaint, SYMBOL_VALUE (sym), NUM_REGS,
+         complain (&reg_value_complaint, SYMBOL_VALUE (sym),
+                   NUM_REGS + NUM_PSEUDO_REGS,
                    SYMBOL_SOURCE_NAME (sym));
          SYMBOL_VALUE (sym) = SP_REGNUM;       /* Known safe, though useless */
        }
@@ -1887,6 +1851,7 @@ define_symbol (valu, string, desc, type, objfile)
          if (local_symbols
              && local_symbols->nsyms > 0
 #ifndef USE_REGISTER_NOT_ARG
+             && REG_STRUCT_HAS_ADDR_P ()
              && REG_STRUCT_HAS_ADDR (processing_gcc_compilation,
                                      SYMBOL_TYPE (sym))
              && (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
@@ -1939,6 +1904,7 @@ define_symbol (valu, string, desc, type, objfile)
       break;
 
     case 't':
+      /* Typedef */
       SYMBOL_TYPE (sym) = read_type (&p, objfile);
 
       /* For a nameless type, we don't want a create a symbol, thus we
@@ -1994,6 +1960,27 @@ define_symbol (valu, string, desc, type, objfile)
 
                 Fortunately, this check seems not to be necessary
                 for anything except pointers or functions.  */
+              /* ezannoni: 2000-10-26. This seems to apply for
+                versions of gcc older than 2.8. This was the original
+                problem: with the following code gdb would tell that
+                the type for name1 is caddr_t, and func is char()
+                typedef char *caddr_t;
+                char *name2;
+                struct x
+                {
+                char *name1;
+                } xx;
+                char *func()
+                {
+                }
+                main () {}
+                */
+
+             /* Pascal accepts names for pointer types. */
+             if (current_subfile->language == language_pascal)
+               {
+                 TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_NAME (sym);
+               }
            }
          else
            TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_NAME (sym);
@@ -2085,9 +2072,10 @@ define_symbol (valu, string, desc, type, objfile)
       SYMBOL_TYPE (sym) = read_type (&p, objfile);
       SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR;
       SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
-      if (SYMBOL_VALUE (sym) >= NUM_REGS)
+      if (SYMBOL_VALUE (sym) >= NUM_REGS + NUM_PSEUDO_REGS)
        {
-         complain (&reg_value_complaint, SYMBOL_VALUE (sym), NUM_REGS,
+         complain (&reg_value_complaint, SYMBOL_VALUE (sym),
+                   NUM_REGS + NUM_PSEUDO_REGS,
                    SYMBOL_SOURCE_NAME (sym));
          SYMBOL_VALUE (sym) = SP_REGNUM;       /* Known safe, though useless */
        }
@@ -2144,8 +2132,9 @@ define_symbol (valu, string, desc, type, objfile)
   /* When passing structures to a function, some systems sometimes pass
      the address in a register, not the structure itself. */
 
-  if (REG_STRUCT_HAS_ADDR (processing_gcc_compilation, SYMBOL_TYPE (sym))
-    && (SYMBOL_CLASS (sym) == LOC_REGPARM || SYMBOL_CLASS (sym) == LOC_ARG))
+  if (REG_STRUCT_HAS_ADDR_P ()
+      && REG_STRUCT_HAS_ADDR (processing_gcc_compilation, SYMBOL_TYPE (sym))
+      && (SYMBOL_CLASS (sym) == LOC_REGPARM || SYMBOL_CLASS (sym) == LOC_ARG))
     {
       struct type *symbol_type = check_typedef (SYMBOL_TYPE (sym));
 
@@ -2195,10 +2184,7 @@ define_symbol (valu, string, desc, type, objfile)
    non-zero on success, zero otherwise.  */
 
 static int
-resolve_live_range (objfile, sym, p)
-     struct objfile *objfile;
-     struct symbol *sym;
-     char *p;
+resolve_live_range (struct objfile *objfile, struct symbol *sym, char *p)
 {
   int refnum;
   CORE_ADDR start, end;
@@ -2266,10 +2252,8 @@ resolve_live_range (objfile, sym, p)
    in objfile OBJFILE.  */
 
 static void
-add_live_range (objfile, sym, start, end)
-     struct objfile *objfile;
-     struct symbol *sym;
-     CORE_ADDR start, end;
+add_live_range (struct objfile *objfile, struct symbol *sym, CORE_ADDR start,
+               CORE_ADDR end)
 {
   struct range_list *r, *rs;
 
@@ -2330,9 +2314,7 @@ add_live_range (objfile, sym, start, end)
    debugger will be able to read the new symbol tables.  */
 
 static struct type *
-error_type (pp, objfile)
-     char **pp;
-     struct objfile *objfile;
+error_type (char **pp, struct objfile *objfile)
 {
   complain (&error_type_complaint);
   while (1)
@@ -2364,9 +2346,7 @@ error_type (pp, objfile)
    deciding whether to call read_type.  */
 
 struct type *
-read_type (pp, objfile)
-     register char **pp;
-     struct objfile *objfile;
+read_type (register char **pp, struct objfile *objfile)
 {
   register struct type *type = 0;
   struct type *type1;
@@ -2380,6 +2360,9 @@ read_type (pp, objfile)
   /* Used to distinguish string and bitstring from char-array and set. */
   int is_string = 0;
 
+  /* Used to distinguish vector from array. */
+  int is_vector = 0;
+
   /* Read type number if present.  The type number may be omitted.
      for instance in a two-dimensional array declared with type
      "ar1;1;10;ar1;1;10;4".  */
@@ -2553,7 +2536,30 @@ again:
          }
        else if (type_size >= 0 || is_string)
          {
-           *type = *xtype;
+           /* This is the absolute wrong way to construct types.  Every
+              other debug format has found a way around this problem and
+              the related problems with unnecessarily stubbed types;
+              someone motivated should attempt to clean up the issue
+              here as well.  Once a type pointed to has been created it
+              should not be modified.
+
+               Well, it's not *absolutely* wrong.  Constructing recursive
+               types (trees, linked lists) necessarily entails modifying
+               types after creating them.  Constructing any loop structure
+               entails side effects.  The Dwarf 2 reader does handle this
+               more gracefully (it never constructs more than once
+               instance of a type object, so it doesn't have to copy type
+               objects wholesale), but it still mutates type objects after
+               other folks have references to them.
+
+               Keep in mind that this circularity/mutation issue shows up
+               at the source language level, too: C's "incomplete types",
+               for example.  So the proper cleanup, I think, would be to
+               limit GDB's type smashing to match exactly those required
+               by the source language.  So GDB could have a
+               "complete_this_type" function, but never create unnecessary
+               copies of a type otherwise.  */
+           replace_type (type, xtype);
            TYPE_NAME (type) = NULL;
            TYPE_TAG_NAME (type) = NULL;
          }
@@ -2572,7 +2578,7 @@ again:
          forward-referenced), and we must change it to a pointer, function,
          reference, or whatever, *in-place*.  */
 
-    case '*':
+    case '*':                  /* Pointer to another type */
       type1 = read_type (pp, objfile);
       type = make_pointer_type (type1, dbx_lookup_type (typenums));
       break;
@@ -2602,6 +2608,81 @@ again:
       type = make_function_type (type1, dbx_lookup_type (typenums));
       break;
 
+    case 'g':                   /* Prototyped function.  (Sun)  */
+      {
+        /* Unresolved questions:
+
+           - According to Sun's ``STABS Interface Manual'', for 'f'
+           and 'F' symbol descriptors, a `0' in the argument type list
+           indicates a varargs function.  But it doesn't say how 'g'
+           type descriptors represent that info.  Someone with access
+           to Sun's toolchain should try it out.
+
+           - According to the comment in define_symbol (search for
+           `process_prototype_types:'), Sun emits integer arguments as
+           types which ref themselves --- like `void' types.  Do we
+           have to deal with that here, too?  Again, someone with
+           access to Sun's toolchain should try it out and let us
+           know.  */
+
+        const char *type_start = (*pp) - 1;
+        struct type *return_type = read_type (pp, objfile);
+        struct type *func_type
+          = make_function_type (return_type, dbx_lookup_type (typenums));
+        struct type_list {
+          struct type *type;
+          struct type_list *next;
+        } *arg_types = 0;
+        int num_args = 0;
+
+        while (**pp && **pp != '#')
+          {
+            struct type *arg_type = read_type (pp, objfile);
+            struct type_list *new = alloca (sizeof (*new));
+            new->type = arg_type;
+            new->next = arg_types;
+            arg_types = new;
+            num_args++;
+          }
+        if (**pp == '#')
+          ++*pp;
+        else
+          {
+            static struct complaint msg = {
+              "Prototyped function type didn't end arguments with `#':\n%s",
+              0, 0
+            };
+            complain (&msg, type_start);
+          }
+
+        /* If there is just one argument whose type is `void', then
+           that's just an empty argument list.  */
+        if (arg_types
+            && ! arg_types->next
+            && TYPE_CODE (arg_types->type) == TYPE_CODE_VOID)
+          num_args = 0;
+
+        TYPE_FIELDS (func_type)
+          = (struct field *) TYPE_ALLOC (func_type,
+                                         num_args * sizeof (struct field));
+        memset (TYPE_FIELDS (func_type), 0, num_args * sizeof (struct field));
+        {
+          int i;
+          struct type_list *t;
+
+          /* We stuck each argument type onto the front of the list
+             when we read it, so the list is reversed.  Build the
+             fields array right-to-left.  */
+          for (t = arg_types, i = num_args - 1; t; t = t->next, i--)
+            TYPE_FIELD_TYPE (func_type, i) = t->type;
+        }
+        TYPE_NFIELDS (func_type) = num_args;
+        TYPE_FLAGS (func_type) |= TYPE_FLAG_PROTOTYPED;
+
+        type = func_type;
+        break;
+      }
+
     case 'k':                  /* Const qualifier on some type (Sun) */
     case 'c':                  /* Const qualifier on some type (OS9000) */
       /* Because 'c' means other things to AIX and 'k' is perfectly good,
@@ -2609,7 +2690,8 @@ again:
       if (type_descriptor == 'c' && !os9k_stabs)
        return error_type (pp, objfile);
       type = read_type (pp, objfile);
-      /* FIXME! For now, we ignore const and volatile qualifiers.  */
+      type = make_cv_type (1, TYPE_VOLATILE (type), type,
+                          dbx_lookup_type (typenums));
       break;
 
     case 'B':                  /* Volatile qual on some type (Sun) */
@@ -2619,7 +2701,8 @@ again:
       if (type_descriptor == 'i' && !os9k_stabs)
        return error_type (pp, objfile);
       type = read_type (pp, objfile);
-      /* FIXME! For now, we ignore const and volatile qualifiers.  */
+      type = make_cv_type (TYPE_CONST (type), 1, type,
+                          dbx_lookup_type (typenums));
       break;
 
     case '@':
@@ -2653,16 +2736,22 @@ again:
 
          switch (*attr)
            {
-           case 's':
+           case 's':           /* Size attribute */
              type_size = atoi (attr + 1);
              if (type_size <= 0)
                type_size = -1;
              break;
 
-           case 'S':
+           case 'S':           /* String attribute */
+             /* FIXME: check to see if following type is array? */
              is_string = 1;
              break;
 
+           case 'V':           /* Vector attribute */
+             /* FIXME: check to see if following type is array? */
+             is_vector = 1;
+             break;
+
            default:
              /* Ignore unrecognized type attributes, so future compilers
                 can invent new ones.  */
@@ -2691,7 +2780,8 @@ again:
        {
          struct type *domain = read_type (pp, objfile);
          struct type *return_type;
-         struct type **args;
+         struct field *args;
+         int nargs, varargs;
 
          if (**pp != ',')
            /* Invalid member type data format.  */
@@ -2700,9 +2790,10 @@ again:
            ++(*pp);
 
          return_type = read_type (pp, objfile);
-         args = read_args (pp, ';', objfile);
+         args = read_args (pp, ';', objfile, &nargs, &varargs);
          type = dbx_alloc_type (typenums, objfile);
-         smash_to_method_type (type, domain, return_type, args);
+         smash_to_method_type (type, domain, return_type, args,
+                               nargs, varargs);
        }
       break;
 
@@ -2740,18 +2831,21 @@ again:
 
     case 's':                  /* Struct type */
     case 'u':                  /* Union type */
-      type = dbx_alloc_type (typenums, objfile);
-      switch (type_descriptor)
-       {
-       case 's':
-         TYPE_CODE (type) = TYPE_CODE_STRUCT;
-         break;
-       case 'u':
-         TYPE_CODE (type) = TYPE_CODE_UNION;
-         break;
-       }
-      type = read_struct_type (pp, type, objfile);
-      break;
+      {
+        enum type_code type_code = TYPE_CODE_UNDEF;
+        type = dbx_alloc_type (typenums, objfile);
+        switch (type_descriptor)
+          {
+          case 's':
+            type_code = TYPE_CODE_STRUCT;
+            break;
+          case 'u':
+            type_code = TYPE_CODE_UNION;
+            break;
+          }
+        type = read_struct_type (pp, type, type_code, objfile);
+        break;
+      }
 
     case 'a':                  /* Array type */
       if (**pp != 'r')
@@ -2762,9 +2856,11 @@ again:
       type = read_array_type (pp, type, objfile);
       if (is_string)
        TYPE_CODE (type) = TYPE_CODE_STRING;
+      if (is_vector)
+       TYPE_FLAGS (type) |= TYPE_FLAG_VECTOR;
       break;
 
-    case 'S':
+    case 'S':                  /* Set or bitstring  type */
       type1 = read_type (pp, objfile);
       type = create_set_type ((struct type *) NULL, type1);
       if (is_string)
@@ -2796,8 +2892,7 @@ again:
    Return the proper type node for a given builtin type number. */
 
 static struct type *
-rs6000_builtin_type (typenum)
-     int typenum;
+rs6000_builtin_type (int typenum)
 {
   /* We recognize types numbered from -NUMBER_RECOGNIZED to -1.  */
 #define NUMBER_RECOGNIZED 34
@@ -2918,10 +3013,14 @@ rs6000_builtin_type (typenum)
     case 25:
       /* Complex type consisting of two IEEE single precision values.  */
       rettype = init_type (TYPE_CODE_COMPLEX, 8, 0, "complex", NULL);
+      TYPE_TARGET_TYPE (rettype) = init_type (TYPE_CODE_FLT, 4, 0, "float",
+                                             NULL);
       break;
     case 26:
       /* Complex type consisting of two IEEE double precision values.  */
       rettype = init_type (TYPE_CODE_COMPLEX, 16, 0, "double complex", NULL);
+      TYPE_TARGET_TYPE (rettype) = init_type (TYPE_CODE_FLT, 8, 0, "double",
+                                             NULL);
       break;
     case 27:
       rettype = init_type (TYPE_CODE_INT, 1, 0, "integer*1", NULL);
@@ -2972,11 +3071,8 @@ rs6000_builtin_type (typenum)
    Returns 1 for success, 0 for failure.  */
 
 static int
-read_member_functions (fip, pp, type, objfile)
-     struct field_info *fip;
-     char **pp;
-     struct type *type;
-     struct objfile *objfile;
+read_member_functions (struct field_info *fip, char **pp, struct type *type,
+                      struct objfile *objfile)
 {
   int nfn_fields = 0;
   int length = 0;
@@ -3021,7 +3117,7 @@ read_member_functions (fip, pp, type, objfile)
 
       new_fnlist = (struct next_fnfieldlist *)
        xmalloc (sizeof (struct next_fnfieldlist));
-      make_cleanup (free, new_fnlist);
+      make_cleanup (xfree, new_fnlist);
       memset (new_fnlist, 0, sizeof (struct next_fnfieldlist));
 
       if ((*pp)[0] == 'o' && (*pp)[1] == 'p' && is_cplus_marker ((*pp)[2]))
@@ -3064,7 +3160,7 @@ read_member_functions (fip, pp, type, objfile)
        {
          new_sublist =
            (struct next_fnfield *) xmalloc (sizeof (struct next_fnfield));
-         make_cleanup (free, new_sublist);
+         make_cleanup (xfree, new_sublist);
          memset (new_sublist, 0, sizeof (struct next_fnfield));
 
          /* Check for and handle cretinous dbx symbol name continuation!  */
@@ -3096,7 +3192,7 @@ read_member_functions (fip, pp, type, objfile)
 
          /* If this is just a stub, then we don't have the real name here. */
 
-         if (TYPE_FLAGS (new_sublist->fn_field.type) & TYPE_FLAG_STUB)
+         if (TYPE_STUB (new_sublist->fn_field.type))
            {
              if (!TYPE_DOMAIN_TYPE (new_sublist->fn_field.type))
                TYPE_DOMAIN_TYPE (new_sublist->fn_field.type) = type;
@@ -3199,13 +3295,30 @@ read_member_functions (fip, pp, type, objfile)
              }
            case '?':
              /* static member function.  */
-             new_sublist->fn_field.voffset = VOFFSET_STATIC;
-             if (strncmp (new_sublist->fn_field.physname,
-                          main_fn_name, strlen (main_fn_name)))
-               {
-                 new_sublist->fn_field.is_stub = 1;
-               }
-             break;
+             {
+               int slen = strlen (main_fn_name);
+
+               new_sublist->fn_field.voffset = VOFFSET_STATIC;
+
+               /* For static member functions, we can't tell if they
+                  are stubbed, as they are put out as functions, and not as
+                  methods.
+                  GCC v2 emits the fully mangled name if
+                  dbxout.c:flag_minimal_debug is not set, so we have to
+                  detect a fully mangled physname here and set is_stub
+                  accordingly.  Fully mangled physnames in v2 start with
+                  the member function name, followed by two underscores.
+                  GCC v3 currently always emits stubbed member functions,
+                  but with fully mangled physnames, which start with _Z.  */
+               if (!(strncmp (new_sublist->fn_field.physname,
+                              main_fn_name, slen) == 0
+                     && new_sublist->fn_field.physname[slen] == '_'
+                     && new_sublist->fn_field.physname[slen + 1] == '_'))
+                 {
+                   new_sublist->fn_field.is_stub = 1;
+                 }
+               break;
+             }
 
            default:
              /* error */
@@ -3227,23 +3340,34 @@ read_member_functions (fip, pp, type, objfile)
       while (**pp != ';' && **pp != '\0');
 
       (*pp)++;
+      STABS_CONTINUE (pp, objfile);
 
-      new_fnlist->fn_fieldlist.fn_fields = (struct fn_field *)
-       obstack_alloc (&objfile->type_obstack,
-                      sizeof (struct fn_field) * length);
-      memset (new_fnlist->fn_fieldlist.fn_fields, 0,
-             sizeof (struct fn_field) * length);
-      for (i = length; (i--, sublist); sublist = sublist->next)
+      /* Skip GCC 3.X member functions which are duplicates of the callable
+        constructor/destructor.  */
+      if (strcmp (main_fn_name, "__base_ctor") == 0
+         || strcmp (main_fn_name, "__base_dtor") == 0
+         || strcmp (main_fn_name, "__deleting_dtor") == 0)
        {
-         new_fnlist->fn_fieldlist.fn_fields[i] = sublist->fn_field;
+         xfree (main_fn_name);
        }
+      else
+       {
+         new_fnlist->fn_fieldlist.fn_fields = (struct fn_field *)
+           obstack_alloc (&objfile->type_obstack,
+                          sizeof (struct fn_field) * length);
+         memset (new_fnlist->fn_fieldlist.fn_fields, 0,
+                 sizeof (struct fn_field) * length);
+         for (i = length; (i--, sublist); sublist = sublist->next)
+           {
+             new_fnlist->fn_fieldlist.fn_fields[i] = sublist->fn_field;
+           }
 
-      new_fnlist->fn_fieldlist.length = length;
-      new_fnlist->next = fip->fnlist;
-      fip->fnlist = new_fnlist;
-      nfn_fields++;
-      total_length += length;
-      STABS_CONTINUE (pp, objfile);
+         new_fnlist->fn_fieldlist.length = length;
+         new_fnlist->next = fip->fnlist;
+         fip->fnlist = new_fnlist;
+         nfn_fields++;
+         total_length += length;
+       }
     }
 
   if (nfn_fields)
@@ -3266,11 +3390,8 @@ read_member_functions (fip, pp, type, objfile)
    keep parsing and it's time for error_type().  */
 
 static int
-read_cpp_abbrev (fip, pp, type, objfile)
-     struct field_info *fip;
-     char **pp;
-     struct type *type;
-     struct objfile *objfile;
+read_cpp_abbrev (struct field_info *fip, char **pp, struct type *type,
+                struct objfile *objfile)
 {
   register char *p;
   char *name;
@@ -3295,8 +3416,13 @@ read_cpp_abbrev (fip, pp, type, objfile)
       switch (cpp_abbrev)
        {
        case 'f':               /* $vf -- a virtual function table pointer */
+         name = type_name_no_tag (context);
+         if (name == NULL)
+         {
+                 name = "";
+         }
          fip->list->field.name =
-           obconcat (&objfile->type_obstack, vptr_name, "", "");
+           obconcat (&objfile->type_obstack, vptr_name, name, "");
          break;
 
        case 'b':               /* $vb -- a virtual bsomethingorother */
@@ -3355,12 +3481,8 @@ read_cpp_abbrev (fip, pp, type, objfile)
 }
 
 static void
-read_one_struct_field (fip, pp, p, type, objfile)
-     struct field_info *fip;
-     char **pp;
-     char *p;
-     struct type *type;
-     struct objfile *objfile;
+read_one_struct_field (struct field_info *fip, char **pp, char *p,
+                      struct type *type, struct objfile *objfile)
 {
   /* The following is code to work around cfront generated stabs.
      The stabs contains full mangled name for each field.
@@ -3526,11 +3648,8 @@ read_one_struct_field (fip, pp, p, type, objfile)
    Returns 1 for success, 0 for failure.  */
 
 static int
-read_struct_fields (fip, pp, type, objfile)
-     struct field_info *fip;
-     char **pp;
-     struct type *type;
-     struct objfile *objfile;
+read_struct_fields (struct field_info *fip, char **pp, struct type *type,
+                   struct objfile *objfile)
 {
   register char *p;
   struct nextfield *new;
@@ -3542,15 +3661,17 @@ read_struct_fields (fip, pp, type, objfile)
   /* Read each data member type until we find the terminating ';' at the end of
      the data member list, or break for some other reason such as finding the
      start of the member function list. */
+  /* Stab string for structure/union does not end with two ';' in
+     SUN C compiler 5.3 i.e. F6U2, hence check for end of string. */
 
-  while (**pp != ';')
+  while (**pp != ';' && **pp != '\0')
     {
       if (os9k_stabs && **pp == ',')
        break;
       STABS_CONTINUE (pp, objfile);
       /* Get space to record the next field's data.  */
       new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
-      make_cleanup (free, new);
+      make_cleanup (xfree, new);
       memset (new, 0, sizeof (struct nextfield));
       new->next = fip->list;
       fip->list = new;
@@ -3626,11 +3747,8 @@ read_struct_fields (fip, pp, type, objfile)
 
 
 static int
-read_baseclasses (fip, pp, type, objfile)
-     struct field_info *fip;
-     char **pp;
-     struct type *type;
-     struct objfile *objfile;
+read_baseclasses (struct field_info *fip, char **pp, struct type *type,
+                 struct objfile *objfile)
 {
   int i;
   struct nextfield *new;
@@ -3673,7 +3791,7 @@ read_baseclasses (fip, pp, type, objfile)
   for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
     {
       new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
-      make_cleanup (free, new);
+      make_cleanup (xfree, new);
       memset (new, 0, sizeof (struct nextfield));
       new->next = fip->list;
       fip->list = new;
@@ -3712,7 +3830,8 @@ read_baseclasses (fip, pp, type, objfile)
          {
            static struct complaint msg =
            {
-             "Unknown visibility `%c' for baseclass", 0, 0};
+             "Unknown visibility `%c' for baseclass", 0, 0
+           };
            complain (&msg, new->visibility);
            new->visibility = VISIBILITY_PUBLIC;
          }
@@ -3755,11 +3874,8 @@ read_baseclasses (fip, pp, type, objfile)
    so we can look for the vptr base class info.  */
 
 static int
-read_tilde_fields (fip, pp, type, objfile)
-     struct field_info *fip;
-     char **pp;
-     struct type *type;
-     struct objfile *objfile;
+read_tilde_fields (struct field_info *fip, char **pp, struct type *type,
+                  struct objfile *objfile)
 {
   register char *p;
 
@@ -3837,9 +3953,7 @@ read_tilde_fields (fip, pp, type, objfile)
 }
 
 static int
-attach_fn_fields_to_type (fip, type)
-     struct field_info *fip;
-     register struct type *type;
+attach_fn_fields_to_type (struct field_info *fip, register struct type *type)
 {
   register int n;
 
@@ -3863,11 +3977,8 @@ attach_fn_fields_to_type (fip, type)
  */
 
 static int
-read_cfront_static_fields (fip, pp, type, objfile)
-     struct field_info *fip;
-     char **pp;
-     struct type *type;
-     struct objfile *objfile;
+read_cfront_static_fields (struct field_info *fip, char **pp, struct type *type,
+                          struct objfile *objfile)
 {
   struct nextfield *new;
   struct type *stype;
@@ -3900,7 +4011,7 @@ read_cfront_static_fields (fip, pp, type, objfile)
 
       /* allocate a new fip */
       new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
-      make_cleanup (free, new);
+      make_cleanup (xfree, new);
       memset (new, 0, sizeof (struct nextfield));
       new->next = fip->list;
       fip->list = new;
@@ -3949,10 +4060,8 @@ read_cfront_static_fields (fip, pp, type, objfile)
    once we have collected all the class members. */
 
 static int
-copy_cfront_struct_fields (fip, type, objfile)
-     struct field_info *fip;
-     struct type *type;
-     struct objfile *objfile;
+copy_cfront_struct_fields (struct field_info *fip, struct type *type,
+                          struct objfile *objfile)
 {
   int nfields = TYPE_NFIELDS (type);
   int i;
@@ -3965,7 +4074,7 @@ copy_cfront_struct_fields (fip, type, objfile)
     {
       /* allocate a new fip */
       new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
-      make_cleanup (free, new);
+      make_cleanup (xfree, new);
       memset (new, 0, sizeof (struct nextfield));
       new->next = fip->list;
       fip->list = new;
@@ -3996,10 +4105,8 @@ copy_cfront_struct_fields (fip, type, objfile)
    for this class's virtual functions.  */
 
 static int
-attach_fields_to_type (fip, type, objfile)
-     struct field_info *fip;
-     register struct type *type;
-     struct objfile *objfile;
+attach_fields_to_type (struct field_info *fip, register struct type *type,
+                      struct objfile *objfile)
 {
   register int nfields = 0;
   register int non_public_fields = 0;
@@ -4084,6 +4191,45 @@ attach_fields_to_type (fip, type, objfile)
   return 1;
 }
 
+
+static struct complaint multiply_defined_struct =
+{"struct/union type gets multiply defined: %s%s", 0, 0};
+
+
+/* Complain that the compiler has emitted more than one definition for the
+   structure type TYPE.  */
+static void 
+complain_about_struct_wipeout (struct type *type)
+{
+  char *name = "";
+  char *kind = "";
+
+  if (TYPE_TAG_NAME (type))
+    {
+      name = TYPE_TAG_NAME (type);
+      switch (TYPE_CODE (type))
+        {
+        case TYPE_CODE_STRUCT: kind = "struct "; break;
+        case TYPE_CODE_UNION:  kind = "union ";  break;
+        case TYPE_CODE_ENUM:   kind = "enum ";   break;
+        default: kind = "";
+        }
+    }
+  else if (TYPE_NAME (type))
+    {
+      name = TYPE_NAME (type);
+      kind = "";
+    }
+  else
+    {
+      name = "<unknown>";
+      kind = "";
+    }
+
+  complain (&multiply_defined_struct, kind, name);
+}
+
+
 /* Read the description of a structure (or union type) and return an object
    describing the type.
 
@@ -4099,10 +4245,8 @@ attach_fields_to_type (fip, type, objfile)
  */
 
 static struct type *
-read_struct_type (pp, type, objfile)
-     char **pp;
-     struct type *type;
-     struct objfile *objfile;
+read_struct_type (char **pp, struct type *type, enum type_code type_code,
+                  struct objfile *objfile)
 {
   struct cleanup *back_to;
   struct field_info fi;
@@ -4110,9 +4254,30 @@ read_struct_type (pp, type, objfile)
   fi.list = NULL;
   fi.fnlist = NULL;
 
+  /* When describing struct/union/class types in stabs, G++ always drops
+     all qualifications from the name.  So if you've got:
+       struct A { ... struct B { ... }; ... };
+     then G++ will emit stabs for `struct A::B' that call it simply
+     `struct B'.  Obviously, if you've got a real top-level definition for
+     `struct B', or other nested definitions, this is going to cause
+     problems.
+
+     Obviously, GDB can't fix this by itself, but it can at least avoid
+     scribbling on existing structure type objects when new definitions
+     appear.  */
+  if (! (TYPE_CODE (type) == TYPE_CODE_UNDEF
+         || TYPE_STUB (type)))
+    {
+      complain_about_struct_wipeout (type);
+
+      /* It's probably best to return the type unchanged.  */
+      return type;
+    }
+
   back_to = make_cleanup (null_cleanup, 0);
 
   INIT_CPLUS_SPECIFIC (type);
+  TYPE_CODE (type) = type_code;
   TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
 
   /* First comes the total size in bytes.  */
@@ -4149,10 +4314,8 @@ read_struct_type (pp, type, objfile)
    array.  */
 
 static struct type *
-read_array_type (pp, type, objfile)
-     register char **pp;
-     register struct type *type;
-     struct objfile *objfile;
+read_array_type (register char **pp, register struct type *type,
+                struct objfile *objfile)
 {
   struct type *index_type, *element_type, *range_type;
   int lower, upper;
@@ -4216,10 +4379,8 @@ read_array_type (pp, type, objfile)
    Also defines the symbols that represent the values of the type.  */
 
 static struct type *
-read_enum_type (pp, type, objfile)
-     register char **pp;
-     register struct type *type;
-     struct objfile *objfile;
+read_enum_type (register char **pp, register struct type *type,
+               struct objfile *objfile)
 {
   register char *p;
   char *name;
@@ -4351,10 +4512,7 @@ read_enum_type (pp, type, objfile)
    FIXME.  */
 
 static struct type *
-read_sun_builtin_type (pp, typenums, objfile)
-     char **pp;
-     int typenums[2];
-     struct objfile *objfile;
+read_sun_builtin_type (char **pp, int typenums[2], struct objfile *objfile)
 {
   int type_bits;
   int nbits;
@@ -4426,14 +4584,12 @@ read_sun_builtin_type (pp, typenums, objfile)
 }
 
 static struct type *
-read_sun_floating_type (pp, typenums, objfile)
-     char **pp;
-     int typenums[2];
-     struct objfile *objfile;
+read_sun_floating_type (char **pp, int typenums[2], struct objfile *objfile)
 {
   int nbits;
   int details;
   int nbytes;
+  struct type *rettype;
 
   /* The first number has more details about the type, for example
      FN_COMPLEX.  */
@@ -4448,9 +4604,12 @@ read_sun_floating_type (pp, typenums, objfile)
 
   if (details == NF_COMPLEX || details == NF_COMPLEX16
       || details == NF_COMPLEX32)
-    /* This is a type we can't handle, but we do know the size.
-       We also will be able to give it a name.  */
-    return init_type (TYPE_CODE_COMPLEX, nbytes, 0, NULL, objfile);
+    {
+      rettype = init_type (TYPE_CODE_COMPLEX, nbytes, 0, NULL, objfile);
+      TYPE_TARGET_TYPE (rettype)
+       = init_type (TYPE_CODE_FLT, nbytes / 2, 0, NULL, objfile);
+      return rettype;
+    }
 
   return init_type (TYPE_CODE_FLT, nbytes, 0, NULL, objfile);
 }
@@ -4468,10 +4627,7 @@ read_sun_floating_type (pp, typenums, objfile)
    If encounter garbage, set *BITS to -1 and return 0.  */
 
 static long
-read_huge_number (pp, end, bits)
-     char **pp;
-     int end;
-     int *bits;
+read_huge_number (char **pp, int end, int *bits)
 {
   char *p = *pp;
   int sign = 1;
@@ -4573,10 +4729,7 @@ read_huge_number (pp, end, bits)
 }
 
 static struct type *
-read_range_type (pp, typenums, objfile)
-     char **pp;
-     int typenums[2];
-     struct objfile *objfile;
+read_range_type (char **pp, int typenums[2], struct objfile *objfile)
 {
   char *orig_pp = *pp;
   int rangenums[2];
@@ -4668,14 +4821,18 @@ read_range_type (pp, typenums, objfile)
 
   if (n3 == 0 && n2 > 0)
     {
+      struct type *float_type
+       = init_type (TYPE_CODE_FLT, n2, 0, NULL, objfile);
+
       if (self_subrange)
        {
-         return init_type (TYPE_CODE_COMPLEX, 2 * n2, 0, NULL, objfile);
+         struct type *complex_type = 
+           init_type (TYPE_CODE_COMPLEX, 2 * n2, 0, NULL, objfile);
+         TYPE_TARGET_TYPE (complex_type) = float_type;
+         return complex_type;
        }
       else
-       {
-         return init_type (TYPE_CODE_FLT, n2, 0, NULL, objfile);
-       }
+       return float_type;
     }
 
   /* If the upper bound is -1, it must really be an unsigned int.  */
@@ -4701,18 +4858,30 @@ read_range_type (pp, typenums, objfile)
   /* We used to do this only for subrange of self or subrange of int.  */
   else if (n2 == 0)
     {
+      /* -1 is used for the upper bound of (4 byte) "unsigned int" and
+         "unsigned long", and we already checked for that,
+         so don't need to test for it here.  */
+
       if (n3 < 0)
        /* n3 actually gives the size.  */
        return init_type (TYPE_CODE_INT, -n3, TYPE_FLAG_UNSIGNED,
                          NULL, objfile);
-      if (n3 == 0xff)
-       return init_type (TYPE_CODE_INT, 1, TYPE_FLAG_UNSIGNED, NULL, objfile);
-      if (n3 == 0xffff)
-       return init_type (TYPE_CODE_INT, 2, TYPE_FLAG_UNSIGNED, NULL, objfile);
 
-      /* -1 is used for the upper bound of (4 byte) "unsigned int" and
-         "unsigned long", and we already checked for that,
-         so don't need to test for it here.  */
+      /* Is n3 == 2**(8n)-1 for some integer n?  Then it's an
+         unsigned n-byte integer.  But do require n to be a power of
+         two; we don't want 3- and 5-byte integers flying around.  */
+      {
+       int bytes;
+       unsigned long bits;
+
+       bits = n3;
+       for (bytes = 0; (bits & 0xff) == 0xff; bytes++)
+         bits >>= 8;
+       if (bits == 0
+           && ((bytes - 1) & bytes) == 0) /* "bytes is a power of two" */
+         return init_type (TYPE_CODE_INT, bytes, TYPE_FLAG_UNSIGNED, NULL,
+                           objfile);
+      }
     }
   /* I think this is for Convex "long long".  Since I don't know whether
      Convex sets self_subrange, I also accept that particular size regardless
@@ -4762,41 +4931,39 @@ handle_true_range:
    and terminated with END.  Return the list of types read in, or (struct type
    **)-1 if there is an error.  */
 
-static struct type **
-read_args (pp, end, objfile)
-     char **pp;
-     int end;
-     struct objfile *objfile;
+static struct field *
+read_args (char **pp, int end, struct objfile *objfile, int *nargsp,
+          int *varargsp)
 {
   /* FIXME!  Remove this arbitrary limit!  */
-  struct type *types[1024], **rval;    /* allow for fns of 1023 parameters */
-  int n = 0;
+  struct type *types[1024];    /* allow for fns of 1023 parameters */
+  int n = 0, i;
+  struct field *rval;
 
   while (**pp != end)
     {
       if (**pp != ',')
        /* Invalid argument list: no ','.  */
-       return (struct type **) -1;
+       return (struct field *) -1;
       (*pp)++;
       STABS_CONTINUE (pp, objfile);
       types[n++] = read_type (pp, objfile);
     }
   (*pp)++;                     /* get past `end' (the ':' character) */
 
-  if (n == 1)
-    {
-      rval = (struct type **) xmalloc (2 * sizeof (struct type *));
-    }
-  else if (TYPE_CODE (types[n - 1]) != TYPE_CODE_VOID)
-    {
-      rval = (struct type **) xmalloc ((n + 1) * sizeof (struct type *));
-      memset (rval + n, 0, sizeof (struct type *));
-    }
+  if (TYPE_CODE (types[n - 1]) != TYPE_CODE_VOID)
+    *varargsp = 1;
   else
     {
-      rval = (struct type **) xmalloc (n * sizeof (struct type *));
+      n--;
+      *varargsp = 0;
     }
-  memcpy (rval, types, n * sizeof (struct type *));
+
+  rval = (struct field *) xmalloc (n * sizeof (struct field));
+  memset (rval, 0, n * sizeof (struct field));
+  for (i = 0; i < n; i++)
+    rval[i].type = types[i];
+  *nargsp = n;
   return rval;
 }
 \f
@@ -4820,9 +4987,7 @@ static char *common_block_name;
    to remain after this function returns.  */
 
 void
-common_block_start (name, objfile)
-     char *name;
-     struct objfile *objfile;
+common_block_start (char *name, struct objfile *objfile)
 {
   if (common_block_name != NULL)
     {
@@ -4841,8 +5006,7 @@ common_block_start (name, objfile)
 /* Process a N_ECOMM symbol.  */
 
 void
-common_block_end (objfile)
-     struct objfile *objfile;
+common_block_end (struct objfile *objfile)
 {
   /* Symbols declared since the BCOMM are to have the common block
      start address added in when we know it.  common_block and
@@ -4905,9 +5069,7 @@ common_block_end (objfile)
    the common block name).  */
 
 static void
-fix_common_block (sym, valu)
-     struct symbol *sym;
-     int valu;
+fix_common_block (struct symbol *sym, int valu)
 {
   struct pending *next = (struct pending *) SYMBOL_TYPE (sym);
   for (; next; next = next->next)
@@ -4926,8 +5088,7 @@ fix_common_block (sym, valu)
    once this file has been read in.  */
 
 void
-add_undefined_type (type)
-     struct type *type;
+add_undefined_type (struct type *type)
 {
   if (undef_types_length == undef_types_allocated)
     {
@@ -4949,7 +5110,7 @@ add_undefined_type (type)
    yet defined at the time a pointer to it was made.
    Fix:  Do a full lookup on the struct/union tag.  */
 void
-cleanup_undefined_types ()
+cleanup_undefined_types (void)
 {
   struct type **type;
 
@@ -4966,7 +5127,7 @@ cleanup_undefined_types ()
               as well as in check_typedef to deal with the (legitimate in
               C though not C++) case of several types with the same name
               in different source files.  */
-           if (TYPE_FLAGS (*type) & TYPE_FLAG_STUB)
+           if (TYPE_STUB (*type))
              {
                struct pending *ppt;
                int i;
@@ -4991,10 +5152,7 @@ cleanup_undefined_types ()
                            && (TYPE_CODE (SYMBOL_TYPE (sym)) ==
                                TYPE_CODE (*type))
                            && STREQ (SYMBOL_NAME (sym), typename))
-                         {
-                           memcpy (*type, SYMBOL_TYPE (sym),
-                                   sizeof (struct type));
-                         }
+                          replace_type (*type, SYMBOL_TYPE (sym));
                      }
                  }
              }
@@ -5020,8 +5178,7 @@ GDB internal error.  cleanup_undefined_types with bad type %d.", 0, 0};
    to.  Get these symbols from the minimal symbol table.  */
 
 void
-scan_file_globals (objfile)
-     struct objfile *objfile;
+scan_file_globals (struct objfile *objfile)
 {
   int hash;
   struct minimal_symbol *msymbol;
@@ -5179,7 +5336,7 @@ scan_file_globals (objfile)
    to a psymtab.  */
 
 void
-stabsread_init ()
+stabsread_init (void)
 {
 }
 
@@ -5188,7 +5345,7 @@ stabsread_init ()
    file, e.g. a shared library).  */
 
 void
-stabsread_new_init ()
+stabsread_new_init (void)
 {
   /* Empty the hash table of global syms looking for values.  */
   memset (global_sym_chain, 0, sizeof (global_sym_chain));
@@ -5198,7 +5355,7 @@ stabsread_new_init ()
    start_symtab() is called. */
 
 void
-start_stabs ()
+start_stabs (void)
 {
   global_stabs = NULL;         /* AIX COFF */
   /* Leave FILENUM of 0 free for builtin types and this file's types.  */
@@ -5215,11 +5372,11 @@ start_stabs ()
 /* Call after end_symtab() */
 
 void
-end_stabs ()
+end_stabs (void)
 {
   if (type_vector)
     {
-      free ((char *) type_vector);
+      xfree (type_vector);
     }
   type_vector = 0;
   type_vector_length = 0;
@@ -5227,13 +5384,12 @@ end_stabs ()
 }
 
 void
-finish_global_stabs (objfile)
-     struct objfile *objfile;
+finish_global_stabs (struct objfile *objfile)
 {
   if (global_stabs)
     {
       patch_block_stabs (global_symbols, global_stabs, objfile);
-      free ((PTR) global_stabs);
+      xfree (global_stabs);
       global_stabs = NULL;
     }
 }
@@ -5241,7 +5397,7 @@ finish_global_stabs (objfile)
 /* Initializer for this module */
 
 void
-_initialize_stabsread ()
+_initialize_stabsread (void)
 {
   undef_types_allocated = 20;
   undef_types_length = 0;
This page took 0.045147 seconds and 4 git commands to generate.