* emultempl/armelf.em (elf32_arm_add_stub_section): Use
[deliverable/binutils-gdb.git] / gdb / gdbtypes.c
index e42c2f4166ad712b37d4583e19a878d662eb6ac6..939a1dcee1e5898795306477d6f1551bcc253c56 100644 (file)
@@ -1,7 +1,7 @@
 /* Support routines for manipulating internal types for GDB.
 
-   Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
-   2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
+   Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002,
+   2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
 
    Contributed by Cygnus Support, using pieces from other GDB modules.
 
@@ -811,8 +811,14 @@ create_array_type (struct type *result_type,
   if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
     low_bound = high_bound = 0;
   CHECK_TYPEDEF (element_type);
-  TYPE_LENGTH (result_type) =
-    TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);
+  /* Be careful when setting the array length.  Ada arrays can be
+     empty arrays with the high_bound being smaller than the low_bound.
+     In such cases, the array length should be zero.  */
+  if (high_bound < low_bound)
+    TYPE_LENGTH (result_type) = 0;
+  else
+    TYPE_LENGTH (result_type) =
+      TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);
   TYPE_NFIELDS (result_type) = 1;
   TYPE_FIELDS (result_type) =
     (struct field *) TYPE_ALLOC (result_type, sizeof (struct field));
@@ -1039,8 +1045,7 @@ lookup_typename (char *name, struct block *block, int noerr)
   struct symbol *sym;
   struct type *tmp;
 
-  sym = lookup_symbol (name, block, VAR_DOMAIN, 0, 
-                      (struct symtab **) NULL);
+  sym = lookup_symbol (name, block, VAR_DOMAIN, 0);
   if (sym == NULL || SYMBOL_CLASS (sym) != LOC_TYPEDEF)
     {
       tmp = language_lookup_primitive_type_by_name (current_language,
@@ -1095,8 +1100,7 @@ lookup_struct (char *name, struct block *block)
 {
   struct symbol *sym;
 
-  sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0,
-                      (struct symtab **) NULL);
+  sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0);
 
   if (sym == NULL)
     {
@@ -1119,8 +1123,7 @@ lookup_union (char *name, struct block *block)
   struct symbol *sym;
   struct type *t;
 
-  sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0,
-                      (struct symtab **) NULL);
+  sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0);
 
   if (sym == NULL)
     error (_("No union type named %s."), name);
@@ -1151,8 +1154,7 @@ lookup_enum (char *name, struct block *block)
 {
   struct symbol *sym;
 
-  sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0,
-                      (struct symtab **) NULL);
+  sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0);
   if (sym == NULL)
     {
       error (_("No enum type named %s."), name);
@@ -1180,8 +1182,7 @@ lookup_template_type (char *name, struct type *type,
   strcat (nam, TYPE_NAME (type));
   strcat (nam, " >");  /* FIXME, extra space still introduced in gcc? */
 
-  sym = lookup_symbol (nam, block, VAR_DOMAIN, 0, 
-                      (struct symtab **) NULL);
+  sym = lookup_symbol (nam, block, VAR_DOMAIN, 0);
 
   if (sym == NULL)
     {
@@ -1282,15 +1283,19 @@ lookup_struct_elt_type (struct type *type, char *name, int noerr)
   return (struct type *) -1;   /* For lint */
 }
 
-/* If possible, make the vptr_fieldno and vptr_basetype fields of TYPE
-   valid.  Callers should be aware that in some cases (for example,
+/* Lookup the vptr basetype/fieldno values for TYPE.
+   If found store vptr_basetype in *BASETYPEP if non-NULL, and return
+   vptr_fieldno.  Also, if found and basetype is from the same objfile,
+   cache the results.
+   If not found, return -1 and ignore BASETYPEP.
+   Callers should be aware that in some cases (for example,
    the type or one of its baseclasses is a stub type and we are
    debugging a .o file), this function will not be able to find the
    virtual function table pointer, and vptr_fieldno will remain -1 and
-   vptr_basetype will remain NULL.  */
+   vptr_basetype will remain NULL or incomplete.  */
 
-void
-fill_in_vptr_fieldno (struct type *type)
+int
+get_vptr_fieldno (struct type *type, struct type **basetypep)
 {
   CHECK_TYPEDEF (type);
 
@@ -1302,16 +1307,34 @@ fill_in_vptr_fieldno (struct type *type)
          is virtual (and hence we cannot share the table pointer).  */
       for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
        {
-         struct type *baseclass = check_typedef (TYPE_BASECLASS (type,
-                                                                 i));
-         fill_in_vptr_fieldno (baseclass);
-         if (TYPE_VPTR_FIELDNO (baseclass) >= 0)
+         struct type *baseclass = check_typedef (TYPE_BASECLASS (type, i));
+         int fieldno;
+         struct type *basetype;
+
+         fieldno = get_vptr_fieldno (baseclass, &basetype);
+         if (fieldno >= 0)
            {
-             TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (baseclass);
-             TYPE_VPTR_BASETYPE (type) = TYPE_VPTR_BASETYPE (baseclass);
-             break;
+             /* If the type comes from a different objfile we can't cache
+                it, it may have a different lifetime. PR 2384 */
+             if (TYPE_OBJFILE (type) == TYPE_OBJFILE (baseclass))
+               {
+                 TYPE_VPTR_FIELDNO (type) = fieldno;
+                 TYPE_VPTR_BASETYPE (type) = basetype;
+               }
+             if (basetypep)
+               *basetypep = basetype;
+             return fieldno;
            }
        }
+
+      /* Not found.  */
+      return -1;
+    }
+  else
+    {
+      if (basetypep)
+       *basetypep = TYPE_VPTR_BASETYPE (type);
+      return TYPE_VPTR_FIELDNO (type);
     }
 }
 
@@ -1397,8 +1420,7 @@ check_typedef (struct type *type)
              stub_noname_complaint ();
              return type;
            }
-         sym = lookup_symbol (name, 0, STRUCT_DOMAIN, 0,
-                              (struct symtab **) NULL);
+         sym = lookup_symbol (name, 0, STRUCT_DOMAIN, 0);
          if (sym)
            TYPE_TARGET_TYPE (type) = SYMBOL_TYPE (sym);
          else                                  /* TYPE_CODE_UNDEF */
@@ -1462,8 +1484,7 @@ check_typedef (struct type *type)
          stub_noname_complaint ();
          return type;
        }
-      sym = lookup_symbol (name, 0, STRUCT_DOMAIN, 
-                          0, (struct symtab **) NULL);
+      sym = lookup_symbol (name, 0, STRUCT_DOMAIN, 0);
       if (sym)
         {
           /* Same as above for opaque types, we can replace the stub
@@ -1492,11 +1513,19 @@ check_typedef (struct type *type)
                   == TYPE_CODE_RANGE))
        {
          /* Now recompute the length of the array type, based on its
-            number of elements and the target type's length.  */
-         TYPE_LENGTH (type) =
-           ((TYPE_FIELD_BITPOS (range_type, 1)
-             - TYPE_FIELD_BITPOS (range_type, 0) + 1)
-            * TYPE_LENGTH (target_type));
+            number of elements and the target type's length.
+            Watch out for Ada null Ada arrays where the high bound
+            is smaller than the low bound.  */
+         const int low_bound = TYPE_FIELD_BITPOS (range_type, 0);
+         const int high_bound = TYPE_FIELD_BITPOS (range_type, 1);
+         int nb_elements;
+       
+         if (high_bound < low_bound)
+           nb_elements = 0;
+         else
+           nb_elements = high_bound - low_bound + 1;
+       
+         TYPE_LENGTH (type) = nb_elements * TYPE_LENGTH (target_type);
          TYPE_FLAGS (type) &= ~TYPE_FLAG_TARGET_STUB;
        }
       else if (TYPE_CODE (type) == TYPE_CODE_RANGE)
This page took 0.026696 seconds and 4 git commands to generate.