*** empty log message ***
[deliverable/binutils-gdb.git] / gdb / stabsread.c
index d3d4b318fc337d097a3ec765cb725c174255e79f..410abec92a55714c36761f48af588b331bfc0dc9 100644 (file)
@@ -1,14 +1,14 @@
 /* Support routines for decoding "stabs" debugging information format.
 
-   Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
-   1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free
-   Software Foundation, Inc.
+   Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
+   1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
+   Free Software Foundation, Inc.
 
    This file is part of GDB.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
@@ -17,9 +17,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place - Suite 330,
-   Boston, MA 02111-1307, USA.  */
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 /* Support routines for reading and decoding debugging information in
    the "stabs" format.  This format is used with many systems that use
@@ -147,7 +145,7 @@ static struct type *read_array_type (char **, struct type *,
 
 static struct field *read_args (char **, int, struct objfile *, int *, int *);
 
-static void add_undefined_type (struct type *);
+static void add_undefined_type (struct type *, int[2]);
 
 static int
 read_cpp_abbrev (struct field_info *, char **, struct type *,
@@ -162,15 +160,6 @@ void stabsread_clear_cache (void);
 static const char vptr_name[] = "_vptr$";
 static const char vb_name[] = "_vb$";
 
-/* Define this as 1 if a pcc declaration of a char or short argument
-   gives the correct address.  Otherwise assume pcc gives the
-   address of the corresponding int, which is not the same on a
-   big-endian machine.  */
-
-#if !defined (BELIEVE_PCC_PROMOTION)
-#define BELIEVE_PCC_PROMOTION 0
-#endif
-
 static void
 invalid_cpp_abbrev_complaint (const char *arg1)
 {
@@ -198,6 +187,20 @@ static int undef_types_allocated;
 static int undef_types_length;
 static struct symbol *current_symbol = NULL;
 
+/* Make a list of nameless types that are undefined.
+   This happens when another type is referenced by its number
+   before this type is actually defined. For instance "t(0,1)=k(0,2)"
+   and type (0,2) is defined only later.  */
+
+struct nat
+{
+  int typenums[2];
+  struct type *type;
+};
+static struct nat *noname_undefs;
+static int noname_undefs_allocated;
+static int noname_undefs_length;
+
 /* Check for and handle cretinous stabs symbol name continuation!  */
 #define STABS_CONTINUE(pp,objfile)                             \
   do {                                                 \
@@ -278,15 +281,12 @@ dbx_lookup_type (int typenums[2])
 
       if (real_filenum >= N_HEADER_FILES (current_objfile))
        {
-         struct type *temp_type;
-         struct type **temp_type_p;
+         static struct type **temp_type_p;
 
          warning (_("GDB internal error: bad real_filenum"));
 
        error_return:
-         temp_type = init_type (TYPE_CODE_ERROR, 0, 0, NULL, NULL);
-         temp_type_p = (struct type **) xmalloc (sizeof (struct type *));
-         *temp_type_p = temp_type;
+         temp_type_p = &builtin_type_error;
          return temp_type_p;
        }
 
@@ -722,7 +722,7 @@ define_symbol (CORE_ADDR valu, char *string, int desc, int type,
        case 'r':
          {
            double d = atof (p);
-           char *dbl_valu;
+           gdb_byte *dbl_valu;
 
            /* FIXME-if-picky-about-floating-accuracy: Should be using
               target arithmetic to get the value.  real.c in GCC
@@ -737,7 +737,7 @@ define_symbol (CORE_ADDR valu, char *string, int desc, int type,
 
            SYMBOL_TYPE (sym) = lookup_fundamental_type (objfile,
                                                         FT_DBL_PREC_FLOAT);
-           dbl_valu = (char *)
+           dbl_valu =
              obstack_alloc (&objfile->objfile_obstack,
                             TYPE_LENGTH (SYMBOL_TYPE (sym)));
            store_typed_floating (dbl_valu, SYMBOL_TYPE (sym), d);
@@ -949,7 +949,7 @@ define_symbol (CORE_ADDR valu, char *string, int desc, int type,
       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
       add_symbol_to_list (sym, &local_symbols);
 
-      if (TARGET_BYTE_ORDER != BFD_ENDIAN_BIG)
+      if (gdbarch_byte_order (current_gdbarch) != BFD_ENDIAN_BIG)
        {
          /* On little-endian machines, this crud is never necessary,
             and, if the extra bytes contain garbage, is harmful.  */
@@ -957,10 +957,11 @@ define_symbol (CORE_ADDR valu, char *string, int desc, int type,
        }
 
       /* If it's gcc-compiled, if it says `short', believe it.  */
-      if (processing_gcc_compilation || BELIEVE_PCC_PROMOTION)
+      if (processing_gcc_compilation
+         || gdbarch_believe_pcc_promotion (current_gdbarch))
        break;
 
-      if (!BELIEVE_PCC_PROMOTION)
+      if (!gdbarch_believe_pcc_promotion (current_gdbarch))
        {
          /* This is the signed type which arguments get promoted to.  */
          static struct type *pcc_promotion_type;
@@ -970,12 +971,14 @@ define_symbol (CORE_ADDR valu, char *string, int desc, int type,
          /* Call it "int" because this is mainly C lossage.  */
          if (pcc_promotion_type == NULL)
            pcc_promotion_type =
-             init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
+             init_type (TYPE_CODE_INT, 
+                        gdbarch_int_bit (current_gdbarch) / TARGET_CHAR_BIT,
                         0, "int", NULL);
 
          if (pcc_unsigned_promotion_type == NULL)
            pcc_unsigned_promotion_type =
-             init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
+             init_type (TYPE_CODE_INT, 
+                        gdbarch_int_bit (current_gdbarch) / TARGET_CHAR_BIT,
                         TYPE_FLAG_UNSIGNED, "unsigned int", NULL);
 
          /* If PCC says a parameter is a short or a char, it is
@@ -1006,13 +1009,16 @@ define_symbol (CORE_ADDR valu, char *string, int desc, int type,
       /* Parameter which is in a register.  */
       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 + NUM_PSEUDO_REGS)
+      SYMBOL_VALUE (sym) = gdbarch_stab_reg_to_regnum (current_gdbarch, valu);
+      if (SYMBOL_VALUE (sym) >= gdbarch_num_regs (current_gdbarch)
+                                 + gdbarch_num_pseudo_regs (current_gdbarch))
        {
          reg_value_complaint (SYMBOL_VALUE (sym),
-                              NUM_REGS + NUM_PSEUDO_REGS,
+                              gdbarch_num_regs (current_gdbarch)
+                                + gdbarch_num_pseudo_regs (current_gdbarch),
                               SYMBOL_PRINT_NAME (sym));
-         SYMBOL_VALUE (sym) = SP_REGNUM;       /* Known safe, though useless */
+         SYMBOL_VALUE (sym) = gdbarch_sp_regnum (current_gdbarch);
+         /* Known safe, though useless */
        }
       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
       add_symbol_to_list (sym, &local_symbols);
@@ -1022,13 +1028,16 @@ define_symbol (CORE_ADDR valu, char *string, int desc, int type,
       /* Register variable (either global or local).  */
       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 + NUM_PSEUDO_REGS)
+      SYMBOL_VALUE (sym) = gdbarch_stab_reg_to_regnum (current_gdbarch, valu);
+      if (SYMBOL_VALUE (sym) >= gdbarch_num_regs (current_gdbarch)
+                               + gdbarch_num_pseudo_regs (current_gdbarch))
        {
          reg_value_complaint (SYMBOL_VALUE (sym),
-                              NUM_REGS + NUM_PSEUDO_REGS,
+                              gdbarch_num_regs (current_gdbarch)
+                                + gdbarch_num_pseudo_regs (current_gdbarch),
                               SYMBOL_PRINT_NAME (sym));
-         SYMBOL_VALUE (sym) = SP_REGNUM;       /* Known safe, though useless */
+         SYMBOL_VALUE (sym) = gdbarch_sp_regnum (current_gdbarch);
+         /* Known safe, though useless */
        }
       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
       if (within_function)
@@ -1102,6 +1111,22 @@ define_symbol (CORE_ADDR valu, char *string, int desc, int type,
       break;
 
     case 't':
+      /* In Ada, there is no distinction between typedef and non-typedef;
+         any type declaration implicitly has the equivalent of a typedef,
+         and thus 't' is in fact equivalent to 'Tt'. 
+
+         Therefore, for Ada units, we check the character immediately
+         before the 't', and if we do not find a 'T', then make sure to
+         create the associated symbol in the STRUCT_DOMAIN ('t' definitions
+         will be stored in the VAR_DOMAIN).  If the symbol was indeed
+         defined as 'Tt' then the STRUCT_DOMAIN symbol will be created
+         elsewhere, so we don't need to take care of that.
+         
+         This is important to do, because of forward references:
+         The cleanup of undefined types stored in undef_types only uses
+         STRUCT_DOMAIN symbols to perform the replacement.  */
+      synonym = (SYMBOL_LANGUAGE (sym) == language_ada && p[-2] != 'T');
+
       /* Typedef */
       SYMBOL_TYPE (sym) = read_type (&p, objfile);
 
@@ -1185,6 +1210,24 @@ define_symbol (CORE_ADDR valu, char *string, int desc, int type,
        }
 
       add_symbol_to_list (sym, &file_symbols);
+
+      if (synonym)
+        {
+          /* Create the STRUCT_DOMAIN clone.  */
+          struct symbol *struct_sym = (struct symbol *)
+            obstack_alloc (&objfile->objfile_obstack, sizeof (struct symbol));
+
+          *struct_sym = *sym;
+          SYMBOL_CLASS (struct_sym) = LOC_TYPEDEF;
+          SYMBOL_VALUE (struct_sym) = valu;
+          SYMBOL_DOMAIN (struct_sym) = STRUCT_DOMAIN;
+          if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
+            TYPE_NAME (SYMBOL_TYPE (sym))
+              = obconcat (&objfile->objfile_obstack, "", "",
+                          DEPRECATED_SYMBOL_NAME (sym));
+          add_symbol_to_list (struct_sym, &file_symbols);
+        }
+      
       break;
 
     case 'T':
@@ -1260,13 +1303,16 @@ define_symbol (CORE_ADDR valu, char *string, int desc, int type,
       /* Reference parameter which is in a register.  */
       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 + NUM_PSEUDO_REGS)
+      SYMBOL_VALUE (sym) = gdbarch_stab_reg_to_regnum (current_gdbarch, valu);
+      if (SYMBOL_VALUE (sym) >= gdbarch_num_regs (current_gdbarch)
+                               + gdbarch_num_pseudo_regs (current_gdbarch))
        {
          reg_value_complaint (SYMBOL_VALUE (sym),
-                              NUM_REGS + NUM_PSEUDO_REGS,
+                              gdbarch_num_regs (current_gdbarch)
+                                + gdbarch_num_pseudo_regs (current_gdbarch),
                               SYMBOL_PRINT_NAME (sym));
-         SYMBOL_VALUE (sym) = SP_REGNUM;       /* Known safe, though useless */
+         SYMBOL_VALUE (sym) = gdbarch_sp_regnum (current_gdbarch);
+         /* Known safe, though useless */
        }
       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
       add_symbol_to_list (sym, &local_symbols);
@@ -1413,7 +1459,7 @@ read_type (char **pp, struct objfile *objfile)
              doesn't get patched up by the time we're done
              reading.  */
           if (TYPE_CODE (type) == TYPE_CODE_UNDEF)
-            add_undefined_type (type);
+            add_undefined_type (type, typenums);
 
           return type;
         }
@@ -1539,7 +1585,7 @@ again:
        INIT_CPLUS_SPECIFIC (type);
        TYPE_FLAGS (type) |= TYPE_FLAG_STUB;
 
-       add_undefined_type (type);
+       add_undefined_type (type, typenums);
        return type;
       }
 
@@ -1731,7 +1777,7 @@ again:
 
          memtype = read_type (pp, objfile);
          type = dbx_alloc_type (typenums, objfile);
-         smash_to_member_type (type, domain, memtype);
+         smash_to_memberptr_type (type, domain, memtype);
        }
       else
        /* type attribute */
@@ -1804,6 +1850,8 @@ again:
 
          return_type = read_type (pp, objfile);
          args = read_args (pp, ';', objfile, &nargs, &varargs);
+         if (args == NULL)
+           return error_type (pp, objfile);
          type = dbx_alloc_type (typenums, objfile);
          smash_to_method_type (type, domain, return_type, args,
                                nargs, varargs);
@@ -2527,7 +2575,8 @@ read_member_functions (struct field_info *fip, char **pp, struct type *type,
            }
          else if (has_destructor && new_fnlist->fn_fieldlist.name[0] != '~')
            {
-             new_fnlist->fn_fieldlist.name = concat ("~", main_fn_name, NULL);
+             new_fnlist->fn_fieldlist.name =
+               concat ("~", main_fn_name, (char *)NULL);
              xfree (main_fn_name);
            }
          else if (!has_stub)
@@ -2783,7 +2832,8 @@ read_one_struct_field (struct field_info *fip, char **pp, char *p,
       if ((FIELD_BITSIZE (fip->list->field)
           == TARGET_CHAR_BIT * TYPE_LENGTH (field_type)
           || (TYPE_CODE (field_type) == TYPE_CODE_ENUM
-              && FIELD_BITSIZE (fip->list->field) == TARGET_INT_BIT)
+              && FIELD_BITSIZE (fip->list->field)
+                 == gdbarch_int_bit (current_gdbarch))
          )
          &&
          FIELD_BITPOS (fip->list->field) % 8 == 0)
@@ -3476,7 +3526,7 @@ read_enum_type (char **pp, struct type *type,
 
   /* Now fill in the fields of the type-structure.  */
 
-  TYPE_LENGTH (type) = TARGET_INT_BIT / HOST_CHAR_BIT;
+  TYPE_LENGTH (type) = gdbarch_int_bit (current_gdbarch) / HOST_CHAR_BIT;
   TYPE_CODE (type) = TYPE_CODE_ENUM;
   TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
   if (unsigned_enum)
@@ -3659,7 +3709,7 @@ read_huge_number (char **pp, int end, int *bits, int twos_complement_bits)
   int nbits = 0;
   int c;
   long upper_limit;
-  int twos_complement_representation = radix == 8 && twos_complement_bits > 0;
+  int twos_complement_representation;
 
   if (*p == '-')
     {
@@ -3675,6 +3725,7 @@ read_huge_number (char **pp, int end, int *bits, int twos_complement_bits)
       p++;
     }
 
+  twos_complement_representation = radix == 8 && twos_complement_bits > 0;
   upper_limit = LONG_MAX / radix;
 
   while ((c = *p++) >= '0' && c < ('0' + radix))
@@ -3901,7 +3952,8 @@ read_range_type (char **pp, int typenums[2], int type_size,
       /* It is unsigned int or unsigned long.  */
       /* GCC 2.3.3 uses this for long long too, but that is just a GDB 3.5
          compatibility hack.  */
-      return init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
+      return init_type (TYPE_CODE_INT, 
+                       gdbarch_int_bit (current_gdbarch) / TARGET_CHAR_BIT,
                        TYPE_FLAG_UNSIGNED, NULL, objfile);
     }
 
@@ -3943,7 +3995,8 @@ read_range_type (char **pp, int typenums[2], int type_size,
      of self_subrange.  */
   else if (n3 == 0 && n2 < 0
           && (self_subrange
-              || n2 == -TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT))
+              || n2 == -gdbarch_long_long_bit
+                         (current_gdbarch) / TARGET_CHAR_BIT))
     return init_type (TYPE_CODE_INT, -n2, 0, NULL, objfile);
   else if (n2 == -n3 - 1)
     {
@@ -3974,7 +4027,8 @@ handle_true_range:
                 _("base type %d of range type is not defined"), rangenums[1]);
       if (range_type_index == NULL)
        range_type_index =
-         init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
+         init_type (TYPE_CODE_INT, 
+                    gdbarch_int_bit (current_gdbarch) / TARGET_CHAR_BIT,
                     0, "range type index type", NULL);
       index_type = range_type_index;
     }
@@ -3984,8 +4038,8 @@ handle_true_range:
 }
 
 /* Read in an argument list.  This is a list of types, separated by commas
-   and terminated with END.  Return the list of types read in, or (struct type
-   **)-1 if there is an error.  */
+   and terminated with END.  Return the list of types read in, or NULL
+   if there is an error.  */
 
 static struct field *
 read_args (char **pp, int end, struct objfile *objfile, int *nargsp,
@@ -4000,7 +4054,7 @@ read_args (char **pp, int end, struct objfile *objfile, int *nargsp,
     {
       if (**pp != ',')
        /* Invalid argument list: no ','.  */
-       return (struct field *) -1;
+       return NULL;
       (*pp)++;
       STABS_CONTINUE (pp, objfile);
       types[n++] = read_type (pp, objfile);
@@ -4133,13 +4187,33 @@ fix_common_block (struct symbol *sym, int valu)
 \f
 
 
-/* What about types defined as forward references inside of a small lexical
-   scope?  */
-/* Add a type to the list of undefined types to be checked through
-   once this file has been read in.  */
+/* Add {TYPE, TYPENUMS} to the NONAME_UNDEFS vector.
+   See add_undefined_type for more details.  */
+
+static void
+add_undefined_type_noname (struct type *type, int typenums[2])
+{
+  struct nat nat;
+
+  nat.typenums[0] = typenums [0];
+  nat.typenums[1] = typenums [1];
+  nat.type = type;
+
+  if (noname_undefs_length == noname_undefs_allocated)
+    {
+      noname_undefs_allocated *= 2;
+      noname_undefs = (struct nat *)
+       xrealloc ((char *) noname_undefs,
+                 noname_undefs_allocated * sizeof (struct nat));
+    }
+  noname_undefs[noname_undefs_length++] = nat;
+}
+
+/* Add TYPE to the UNDEF_TYPES vector.
+   See add_undefined_type for more details.  */
 
 static void
-add_undefined_type (struct type *type)
+add_undefined_type_1 (struct type *type)
 {
   if (undef_types_length == undef_types_allocated)
     {
@@ -4151,6 +4225,48 @@ add_undefined_type (struct type *type)
   undef_types[undef_types_length++] = type;
 }
 
+/* What about types defined as forward references inside of a small lexical
+   scope?  */
+/* Add a type to the list of undefined types to be checked through
+   once this file has been read in.
+   
+   In practice, we actually maintain two such lists: The first list
+   (UNDEF_TYPES) is used for types whose name has been provided, and
+   concerns forward references (eg 'xs' or 'xu' forward references);
+   the second list (NONAME_UNDEFS) is used for types whose name is
+   unknown at creation time, because they were referenced through
+   their type number before the actual type was declared.
+   This function actually adds the given type to the proper list.  */
+
+static void
+add_undefined_type (struct type *type, int typenums[2])
+{
+  if (TYPE_TAG_NAME (type) == NULL)
+    add_undefined_type_noname (type, typenums);
+  else
+    add_undefined_type_1 (type);
+}
+
+/* Try to fix all undefined types pushed on the UNDEF_TYPES vector.  */
+
+void
+cleanup_undefined_types_noname (void)
+{
+  int i;
+
+  for (i = 0; i < noname_undefs_length; i++)
+    {
+      struct nat nat = noname_undefs[i];
+      struct type **type;
+
+      type = dbx_lookup_type (nat.typenums);
+      if (nat.type != *type && TYPE_CODE (*type) != TYPE_CODE_UNDEF)
+        replace_type (nat.type, *type);
+    }
+
+  noname_undefs_length = 0;
+}
+
 /* Go through each undefined type, see if it's still undefined, and fix it
    up if possible.  We have two kinds of undefined types:
 
@@ -4160,8 +4276,9 @@ add_undefined_type (struct type *type)
    TYPE_CODE_STRUCT, TYPE_CODE_UNION:  Structure whose fields were not
    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 (void)
+cleanup_undefined_types_1 (void)
 {
   struct type **type;
 
@@ -4222,6 +4339,16 @@ cleanup_undefined_types (void)
   undef_types_length = 0;
 }
 
+/* Try to fix all the undefined types we ecountered while processing
+   this unit.  */
+
+void
+cleanup_undefined_types (void)
+{
+  cleanup_undefined_types_1 ();
+  cleanup_undefined_types_noname ();
+}
+
 /* Scan through all of the global symbols defined in the object file,
    assigning values to the debugging symbols that need to be assigned
    to.  Get these symbols from the minimal symbol table.  */
@@ -4457,4 +4584,9 @@ _initialize_stabsread (void)
   undef_types_length = 0;
   undef_types = (struct type **)
     xmalloc (undef_types_allocated * sizeof (struct type *));
+
+  noname_undefs_allocated = 20;
+  noname_undefs_length = 0;
+  noname_undefs = (struct nat *)
+    xmalloc (noname_undefs_allocated * sizeof (struct nat));
 }
This page took 0.032895 seconds and 4 git commands to generate.