2008-08-21 Sterling Augustine <sterling@tensilica.com>
[deliverable/binutils-gdb.git] / gdb / stabsread.c
index 75bb5f0080ee0880761dbf35940a73149d89be45..e9580f948d7e34ff4feb2079dc651c7ff6ed78f0 100644 (file)
@@ -1,14 +1,14 @@
 /* Support routines for decoding "stabs" debugging information format.
 
    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.
+   1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
+   2008 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., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301, 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
@@ -47,6 +45,7 @@
 #include "doublest.h"
 #include "cp-abi.h"
 #include "cp-support.h"
+#include "gdb_assert.h"
 
 #include <ctype.h>
 
@@ -162,15 +161,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)
 {
@@ -292,15 +282,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;
        }
 
@@ -373,6 +360,7 @@ patch_block_stabs (struct pending *symbols, struct pending_stabs *stabs,
        {
          name = stabs->stab[ii];
          pp = (char *) strchr (name, ':');
+         gdb_assert (pp);      /* Must find a ':' or game's over.  */
          while (pp[1] == ':')
            {
              pp += 2;
@@ -594,6 +582,7 @@ struct symbol *
 define_symbol (CORE_ADDR valu, char *string, int desc, int type,
               struct objfile *objfile)
 {
+  struct gdbarch *gdbarch = get_objfile_arch (objfile);
   struct symbol *sym;
   char *p = (char *) find_name_end (string);
   int deftype;
@@ -676,11 +665,11 @@ define_symbol (CORE_ADDR valu, char *string, int desc, int type,
          /* This was an anonymous type that was never fixed up.  */
          goto normal;
 
-#ifdef STATIC_TRANSFORM_NAME
        case 'X':
          /* SunPRO (3.0 at least) static variable encoding.  */
-         goto normal;
-#endif
+         if (gdbarch_static_transform_name_p (gdbarch))
+           goto normal;
+         /* ... fall through ... */
 
        default:
          complaint (&symfile_complaints, _("Unknown C++ symbol name `%s'"),
@@ -737,24 +726,19 @@ define_symbol (CORE_ADDR valu, char *string, int desc, int type,
          {
            double d = atof (p);
            gdb_byte *dbl_valu;
+           struct type *dbl_type;
 
            /* FIXME-if-picky-about-floating-accuracy: Should be using
               target arithmetic to get the value.  real.c in GCC
               probably has the necessary code.  */
 
-           /* FIXME: lookup_fundamental_type is a hack.  We should be
-              creating a type especially for the type of float constants.
-              Problem is, what type should it be?
-
-              Also, what should the name of this type be?  Should we
-              be using 'S' constants (see stabs.texinfo) instead?  */
-
-           SYMBOL_TYPE (sym) = lookup_fundamental_type (objfile,
-                                                        FT_DBL_PREC_FLOAT);
+           dbl_type = builtin_type (gdbarch)->builtin_double;
            dbl_valu =
              obstack_alloc (&objfile->objfile_obstack,
-                            TYPE_LENGTH (SYMBOL_TYPE (sym)));
-           store_typed_floating (dbl_valu, SYMBOL_TYPE (sym), d);
+                            TYPE_LENGTH (dbl_type));
+           store_typed_floating (dbl_valu, dbl_type, d);
+
+           SYMBOL_TYPE (sym) = dbl_type;
            SYMBOL_VALUE_BYTES (sym) = dbl_valu;
            SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
          }
@@ -768,22 +752,7 @@ define_symbol (CORE_ADDR valu, char *string, int desc, int type,
               types; other languages probably should have at least
               unsigned as well as signed constants.  */
 
-           /* We just need one int constant type for all objfiles.
-              It doesn't depend on languages or anything (arguably its
-              name should be a language-specific name for a type of
-              that size, but I'm inclined to say that if the compiler
-              wants a nice name for the type, it can use 'e').  */
-           static struct type *int_const_type;
-
-           /* Yes, this is as long as a *host* int.  That is because we
-              use atoi.  */
-           if (int_const_type == NULL)
-             int_const_type =
-               init_type (TYPE_CODE_INT,
-                          sizeof (int) * HOST_CHAR_BIT / TARGET_CHAR_BIT, 0,
-                          "integer constant",
-                            (struct objfile *) NULL);
-           SYMBOL_TYPE (sym) = int_const_type;
+           SYMBOL_TYPE (sym) = builtin_type (gdbarch)->builtin_long;
            SYMBOL_VALUE (sym) = atoi (p);
            SYMBOL_CLASS (sym) = LOC_CONST;
          }
@@ -891,10 +860,10 @@ define_symbol (CORE_ADDR valu, char *string, int desc, int type,
                 be promoted to the width of the calling conventions, with
                 a type which references itself. This type is turned into
                 a TYPE_CODE_VOID type by read_type, and we have to turn
-                it back into builtin_type_int here.
-                FIXME: Do we need a new builtin_type_promoted_int_arg ?  */
+                it back into builtin_int here.
+                FIXME: Do we need a new builtin_promoted_int_arg ?  */
              if (TYPE_CODE (ptype) == TYPE_CODE_VOID)
-               ptype = builtin_type_int;
+               ptype = builtin_type (gdbarch)->builtin_int;
              TYPE_FIELD_TYPE (ftype, nparams) = ptype;
              TYPE_FIELD_ARTIFICIAL (ftype, nparams++) = 0;
            }
@@ -961,9 +930,10 @@ define_symbol (CORE_ADDR valu, char *string, int desc, int type,
       SYMBOL_CLASS (sym) = LOC_ARG;
       SYMBOL_VALUE (sym) = valu;
       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
+      SYMBOL_IS_ARGUMENT (sym) = 1;
       add_symbol_to_list (sym, &local_symbols);
 
-      if (gdbarch_byte_order (current_gdbarch) != BFD_ENDIAN_BIG)
+      if (gdbarch_byte_order (gdbarch) != BFD_ENDIAN_BIG)
        {
          /* On little-endian machines, this crud is never necessary,
             and, if the extra bytes contain garbage, is harmful.  */
@@ -971,38 +941,22 @@ 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 (gdbarch))
        break;
 
-      if (!BELIEVE_PCC_PROMOTION)
+      if (!gdbarch_believe_pcc_promotion (gdbarch))
        {
-         /* This is the signed type which arguments get promoted to.  */
-         static struct type *pcc_promotion_type;
-         /* This is the unsigned type which arguments get promoted to.  */
-         static struct type *pcc_unsigned_promotion_type;
-
-         /* Call it "int" because this is mainly C lossage.  */
-         if (pcc_promotion_type == NULL)
-           pcc_promotion_type =
-             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, 
-                        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
             really an int.  */
-         if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (pcc_promotion_type)
+         if (TYPE_LENGTH (SYMBOL_TYPE (sym))
+             < gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT
              && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT)
            {
              SYMBOL_TYPE (sym) =
                TYPE_UNSIGNED (SYMBOL_TYPE (sym))
-               ? pcc_unsigned_promotion_type
-               : pcc_promotion_type;
+               ? builtin_type (gdbarch)->builtin_unsigned_int
+               : builtin_type (gdbarch)->builtin_int;
            }
          break;
        }
@@ -1021,8 +975,9 @@ define_symbol (CORE_ADDR valu, char *string, int desc, int type,
     case 'R':
       /* 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);
+      SYMBOL_CLASS (sym) = LOC_REGISTER;
+      SYMBOL_IS_ARGUMENT (sym) = 1;
+      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))
        {
@@ -1030,7 +985,8 @@ define_symbol (CORE_ADDR valu, char *string, int desc, int type,
                               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);
@@ -1040,7 +996,7 @@ 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);
+      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))
        {
@@ -1048,7 +1004,8 @@ define_symbol (CORE_ADDR valu, char *string, int desc, int type,
                               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)
@@ -1075,8 +1032,7 @@ define_symbol (CORE_ADDR valu, char *string, int desc, int type,
 
          if (local_symbols
              && local_symbols->nsyms > 0
-             && gdbarch_stabs_argument_has_addr (current_gdbarch,
-                                                 SYMBOL_TYPE (sym)))
+             && gdbarch_stabs_argument_has_addr (gdbarch, SYMBOL_TYPE (sym)))
            {
              struct symbol *prev_sym;
              prev_sym = local_symbols->symbol[local_symbols->nsyms - 1];
@@ -1085,7 +1041,7 @@ define_symbol (CORE_ADDR valu, char *string, int desc, int type,
                  && strcmp (DEPRECATED_SYMBOL_NAME (prev_sym),
                             DEPRECATED_SYMBOL_NAME (sym)) == 0)
                {
-                 SYMBOL_CLASS (prev_sym) = LOC_REGPARM;
+                 SYMBOL_CLASS (prev_sym) = LOC_REGISTER;
                  /* Use the type from the LOC_REGISTER; that is the type
                     that is actually in that register.  */
                  SYMBOL_TYPE (prev_sym) = SYMBOL_TYPE (sym);
@@ -1105,18 +1061,21 @@ define_symbol (CORE_ADDR valu, char *string, int desc, int type,
       SYMBOL_TYPE (sym) = read_type (&p, objfile);
       SYMBOL_CLASS (sym) = LOC_STATIC;
       SYMBOL_VALUE_ADDRESS (sym) = valu;
-#ifdef STATIC_TRANSFORM_NAME
-      if (IS_STATIC_TRANSFORM_NAME (DEPRECATED_SYMBOL_NAME (sym)))
+      if (gdbarch_static_transform_name_p (gdbarch)
+         && gdbarch_static_transform_name (gdbarch,
+                                           DEPRECATED_SYMBOL_NAME (sym))
+            != DEPRECATED_SYMBOL_NAME (sym))
        {
          struct minimal_symbol *msym;
          msym = lookup_minimal_symbol (DEPRECATED_SYMBOL_NAME (sym), NULL, objfile);
          if (msym != NULL)
            {
-             DEPRECATED_SYMBOL_NAME (sym) = STATIC_TRANSFORM_NAME (DEPRECATED_SYMBOL_NAME (sym));
+             DEPRECATED_SYMBOL_NAME (sym) = gdbarch_static_transform_name
+                                              (gdbarch,        
+                                               DEPRECATED_SYMBOL_NAME (sym));
              SYMBOL_VALUE_ADDRESS (sym) = SYMBOL_VALUE_ADDRESS (msym);
            }
        }
-#endif
       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
       add_symbol_to_list (sym, &file_symbols);
       break;
@@ -1285,18 +1244,21 @@ define_symbol (CORE_ADDR valu, char *string, int desc, int type,
       SYMBOL_TYPE (sym) = read_type (&p, objfile);
       SYMBOL_CLASS (sym) = LOC_STATIC;
       SYMBOL_VALUE_ADDRESS (sym) = valu;
-#ifdef STATIC_TRANSFORM_NAME
-      if (IS_STATIC_TRANSFORM_NAME (DEPRECATED_SYMBOL_NAME (sym)))
+      if (gdbarch_static_transform_name_p (gdbarch)
+         && gdbarch_static_transform_name (gdbarch,
+                                           DEPRECATED_SYMBOL_NAME (sym))
+            != DEPRECATED_SYMBOL_NAME (sym))
        {
          struct minimal_symbol *msym;
          msym = lookup_minimal_symbol (DEPRECATED_SYMBOL_NAME (sym), NULL, objfile);
          if (msym != NULL)
            {
-             DEPRECATED_SYMBOL_NAME (sym) = STATIC_TRANSFORM_NAME (DEPRECATED_SYMBOL_NAME (sym));
+             DEPRECATED_SYMBOL_NAME (sym) = gdbarch_static_transform_name
+                                              (gdbarch,        
+                                               DEPRECATED_SYMBOL_NAME (sym));
              SYMBOL_VALUE_ADDRESS (sym) = SYMBOL_VALUE_ADDRESS (msym);
            }
        }
-#endif
       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
        add_symbol_to_list (sym, &local_symbols);
       break;
@@ -1305,6 +1267,7 @@ define_symbol (CORE_ADDR valu, char *string, int desc, int type,
       /* Reference parameter */
       SYMBOL_TYPE (sym) = read_type (&p, objfile);
       SYMBOL_CLASS (sym) = LOC_REF_ARG;
+      SYMBOL_IS_ARGUMENT (sym) = 1;
       SYMBOL_VALUE (sym) = valu;
       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
       add_symbol_to_list (sym, &local_symbols);
@@ -1314,7 +1277,8 @@ 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);
+      SYMBOL_IS_ARGUMENT (sym) = 1;
+      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))
        {
@@ -1322,7 +1286,8 @@ define_symbol (CORE_ADDR valu, char *string, int desc, int type,
                               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);
@@ -1353,12 +1318,12 @@ define_symbol (CORE_ADDR valu, char *string, int desc, int type,
      of by value, i.e. they will pass the address of a structure (in a
      register or on the stack) instead of the structure itself.  */
 
-  if (gdbarch_stabs_argument_has_addr (current_gdbarch, SYMBOL_TYPE (sym))
-      && (SYMBOL_CLASS (sym) == LOC_REGPARM || SYMBOL_CLASS (sym) == LOC_ARG))
+  if (gdbarch_stabs_argument_has_addr (gdbarch, SYMBOL_TYPE (sym))
+      && SYMBOL_IS_ARGUMENT (sym))
     {
-      /* We have to convert LOC_REGPARM to LOC_REGPARM_ADDR (for
+      /* We have to convert LOC_REGISTER to LOC_REGPARM_ADDR (for
          variables passed in a register).  */
-      if (SYMBOL_CLASS (sym) == LOC_REGPARM)
+      if (SYMBOL_CLASS (sym) == LOC_REGISTER)
        SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR;
       /* Likewise for converting LOC_ARG to LOC_REF_ARG (for the 7th
         and subsequent arguments on SPARC, for example).  */
@@ -1924,7 +1889,7 @@ again:
       if (is_string)
        TYPE_CODE (type) = TYPE_CODE_STRING;
       if (is_vector)
-       TYPE_FLAGS (type) |= TYPE_FLAG_VECTOR;
+       make_vector_type (type);
       break;
 
     case 'S':                  /* Set or bitstring  type */
@@ -2739,6 +2704,8 @@ static void
 read_one_struct_field (struct field_info *fip, char **pp, char *p,
                       struct type *type, struct objfile *objfile)
 {
+  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+
   fip->list->field.name =
     obsavestring (*pp, p - *pp, &objfile->objfile_obstack);
   *pp = p + 1;
@@ -2843,7 +2810,7 @@ read_one_struct_field (struct field_info *fip, char **pp, char *p,
           == TARGET_CHAR_BIT * TYPE_LENGTH (field_type)
           || (TYPE_CODE (field_type) == TYPE_CODE_ENUM
               && FIELD_BITSIZE (fip->list->field)
-                 == gdbarch_int_bit (current_gdbarch))
+                 == gdbarch_int_bit (gdbarch))
          )
          &&
          FIELD_BITPOS (fip->list->field) % 8 == 0)
@@ -3467,6 +3434,7 @@ static struct type *
 read_enum_type (char **pp, struct type *type,
                struct objfile *objfile)
 {
+  struct gdbarch *gdbarch = get_objfile_arch (objfile);
   char *p;
   char *name;
   long n;
@@ -3536,7 +3504,7 @@ read_enum_type (char **pp, struct type *type,
 
   /* Now fill in the fields of the type-structure.  */
 
-  TYPE_LENGTH (type) = gdbarch_int_bit (current_gdbarch) / HOST_CHAR_BIT;
+  TYPE_LENGTH (type) = gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT;
   TYPE_CODE (type) = TYPE_CODE_ENUM;
   TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
   if (unsigned_enum)
@@ -3711,15 +3679,14 @@ read_huge_number (char **pp, int end, int *bits, int twos_complement_bits)
 {
   char *p = *pp;
   int sign = 1;
-  int sign_bit;
+  int sign_bit = 0;
   long n = 0;
-  long sn = 0;
   int radix = 10;
   char overflow = 0;
   int nbits = 0;
   int c;
   long upper_limit;
-  int twos_complement_representation = radix == 8 && twos_complement_bits > 0;
+  int twos_complement_representation = 0;
 
   if (*p == '-')
     {
@@ -3735,6 +3702,37 @@ read_huge_number (char **pp, int end, int *bits, int twos_complement_bits)
       p++;
     }
 
+  /* Skip extra zeros.  */
+  while (*p == '0')
+    p++;
+
+  if (sign > 0 && radix == 8 && twos_complement_bits > 0)
+    {
+      /* Octal, possibly signed.  Check if we have enough chars for a
+        negative number.  */
+
+      size_t len;
+      char *p1 = p;
+      while ((c = *p1) >= '0' && c < '8')
+       p1++;
+
+      len = p1 - p;
+      if (len > twos_complement_bits / 3
+         || (twos_complement_bits % 3 == 0 && len == twos_complement_bits / 3))
+       {
+         /* Ok, we have enough characters for a signed value, check
+            for signness by testing if the sign bit is set.  */
+         sign_bit = (twos_complement_bits % 3 + 2) % 3;
+         c = *p - '0';
+         if (c & (1 << sign_bit))
+           {
+             /* Definitely signed.  */
+             twos_complement_representation = 1;
+             sign = -1;
+           }
+       }
+    }
+
   upper_limit = LONG_MAX / radix;
 
   while ((c = *p++) >= '0' && c < ('0' + radix))
@@ -3743,23 +3741,18 @@ read_huge_number (char **pp, int end, int *bits, int twos_complement_bits)
         {
           if (twos_complement_representation)
             {
-              /* Octal, signed, twos complement representation. In this case,
-                 sn is the signed value, n is the corresponding absolute
-                 value. signed_bit is the position of the sign bit in the
-                 first three bits.  */
-              if (sn == 0)
-                {
-                  sign_bit = (twos_complement_bits % 3 + 2) % 3;
-                  sn = c - '0' - ((2 * (c - '0')) | (2 << sign_bit));
-                }
+             /* Octal, signed, twos complement representation.  In
+                this case, n is the corresponding absolute value.  */
+             if (n == 0)
+               {
+                 long sn = c - '0' - ((2 * (c - '0')) | (2 << sign_bit));
+                 n = -sn;
+               }
               else
                 {
-                  sn *= radix;
-                  sn += c - '0';
+                  n *= radix;
+                  n -= c - '0';
                 }
-
-              if (sn < 0)
-                n = -sn;
             }
           else
             {
@@ -3803,6 +3796,15 @@ read_huge_number (char **pp, int end, int *bits, int twos_complement_bits)
   else
     --p;
 
+  if (radix == 8 && twos_complement_bits > 0 && nbits > twos_complement_bits)
+    {
+      /* We were supposed to parse a number with maximum
+        TWOS_COMPLEMENT_BITS bits, but something went wrong.  */
+      if (bits != NULL)
+       *bits = -1;
+      return 0;
+    }
+
   *pp = p;
   if (overflow)
     {
@@ -3816,8 +3818,9 @@ read_huge_number (char **pp, int end, int *bits, int twos_complement_bits)
        }
 
       /* -0x7f is the same as 0x80.  So deal with it by adding one to
-         the number of bits.  */
-      if (sign == -1)
+         the number of bits.  Two's complement represention octals
+         can't have a '-' in front.  */
+      if (sign == -1 && !twos_complement_representation)
        ++nbits;
       if (bits)
        *bits = nbits;
@@ -3826,10 +3829,7 @@ read_huge_number (char **pp, int end, int *bits, int twos_complement_bits)
     {
       if (bits)
        *bits = 0;
-      if (twos_complement_representation)
-        return sn;
-      else
-        return n * sign;
+      return n * sign;
     }
   /* It's *BITS which has the interesting information.  */
   return 0;
@@ -3839,6 +3839,7 @@ static struct type *
 read_range_type (char **pp, int typenums[2], int type_size,
                  struct objfile *objfile)
 {
+  struct gdbarch *gdbarch = get_objfile_arch (objfile);
   char *orig_pp = *pp;
   int rangenums[2];
   long n2, n3;
@@ -3954,15 +3955,20 @@ read_range_type (char **pp, int typenums[2], int type_size,
        return float_type;
     }
 
-  /* If the upper bound is -1, it must really be an unsigned int.  */
+  /* If the upper bound is -1, it must really be an unsigned integral.  */
 
   else if (n2 == 0 && n3 == -1)
     {
-      /* 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, 
-                       gdbarch_int_bit (current_gdbarch) / TARGET_CHAR_BIT,
+      int bits = type_size;
+      if (bits <= 0)
+       {
+         /* We don't know its 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.  */
+         bits = gdbarch_int_bit (gdbarch);
+       }
+
+      return init_type (TYPE_CODE_INT, bits / TARGET_CHAR_BIT,
                        TYPE_FLAG_UNSIGNED, NULL, objfile);
     }
 
@@ -4005,7 +4011,7 @@ read_range_type (char **pp, int typenums[2], int type_size,
   else if (n3 == 0 && n2 < 0
           && (self_subrange
               || n2 == -gdbarch_long_long_bit
-                         (current_gdbarch) / TARGET_CHAR_BIT))
+                         (gdbarch) / TARGET_CHAR_BIT))
     return init_type (TYPE_CODE_INT, -n2, 0, NULL, objfile);
   else if (n2 == -n3 - 1)
     {
@@ -4022,7 +4028,7 @@ read_range_type (char **pp, int typenums[2], int type_size,
 handle_true_range:
 
   if (self_subrange)
-    index_type = builtin_type_int;
+    index_type = builtin_type (gdbarch)->builtin_int;
   else
     index_type = *dbx_lookup_type (rangenums);
   if (index_type == NULL)
@@ -4030,16 +4036,10 @@ handle_true_range:
       /* Does this actually ever happen?  Is that why we are worrying
          about dealing with it rather than just calling error_type?  */
 
-      static struct type *range_type_index;
-
       complaint (&symfile_complaints,
                 _("base type %d of range type is not defined"), rangenums[1]);
-      if (range_type_index == NULL)
-       range_type_index =
-         init_type (TYPE_CODE_INT, 
-                    gdbarch_int_bit (current_gdbarch) / TARGET_CHAR_BIT,
-                    0, "range type index type", NULL);
-      index_type = range_type_index;
+
+      index_type = builtin_type (gdbarch)->builtin_int;
     }
 
   result_type = create_range_type ((struct type *) NULL, index_type, n2, n3);
@@ -4270,7 +4270,14 @@ cleanup_undefined_types_noname (void)
 
       type = dbx_lookup_type (nat.typenums);
       if (nat.type != *type && TYPE_CODE (*type) != TYPE_CODE_UNDEF)
-        replace_type (nat.type, *type);
+        {
+          /* The instance flags of the undefined type are still unset,
+             and needs to be copied over from the reference type.
+             Since replace_type expects them to be identical, we need
+             to set these flags manually before hand.  */
+          TYPE_INSTANCE_FLAGS (nat.type) = TYPE_INSTANCE_FLAGS (*type);
+          replace_type (nat.type, *type);
+        }
     }
 
   noname_undefs_length = 0;
@@ -4291,6 +4298,25 @@ cleanup_undefined_types_1 (void)
 {
   struct type **type;
 
+  /* Iterate over every undefined type, and look for a symbol whose type
+     matches our undefined type.  The symbol matches if:
+       1. It is a typedef in the STRUCT domain;
+       2. It has the same name, and same type code;
+       3. The instance flags are identical.
+     
+     It is important to check the instance flags, because we have seen
+     examples where the debug info contained definitions such as:
+
+         "foo_t:t30=B31=xefoo_t:"
+
+     In this case, we have created an undefined type named "foo_t" whose
+     instance flags is null (when processing "xefoo_t"), and then created
+     another type with the same name, but with different instance flags
+     ('B' means volatile).  I think that the definition above is wrong,
+     since the same type cannot be volatile and non-volatile at the same
+     time, but we need to be able to cope with it when it happens.  The
+     approach taken here is to treat these two types as different.  */
+
   for (type = undef_types; type < undef_types + undef_types_length; type++)
     {
       switch (TYPE_CODE (*type))
@@ -4326,7 +4352,10 @@ cleanup_undefined_types_1 (void)
                            && SYMBOL_DOMAIN (sym) == STRUCT_DOMAIN
                            && (TYPE_CODE (SYMBOL_TYPE (sym)) ==
                                TYPE_CODE (*type))
-                           && strcmp (DEPRECATED_SYMBOL_NAME (sym), typename) == 0)
+                           && (TYPE_INSTANCE_FLAGS (*type) ==
+                               TYPE_INSTANCE_FLAGS (SYMBOL_TYPE (sym)))
+                           && strcmp (DEPRECATED_SYMBOL_NAME (sym),
+                                      typename) == 0)
                           replace_type (*type, SYMBOL_TYPE (sym));
                      }
                  }
This page took 0.032893 seconds and 4 git commands to generate.