Add set/show debug dwarf-line.
[deliverable/binutils-gdb.git] / gdb / gdbtypes.c
index 4aec5ec526c37a21cdb34ba5e743e2f0f8165dab..ca86fbd3c21a7ff2d038f8b7880ac0489b1ed159 100644 (file)
@@ -1004,6 +1004,45 @@ get_array_bounds (struct type *type, LONGEST *low_bound, LONGEST *high_bound)
   return 1;
 }
 
+/* Assuming that TYPE is a discrete type and VAL is a valid integer
+   representation of a value of this type, save the corresponding
+   position number in POS.
+
+   Its differs from VAL only in the case of enumeration types.  In
+   this case, the position number of the value of the first listed
+   enumeration literal is zero; the position number of the value of
+   each subsequent enumeration literal is one more than that of its
+   predecessor in the list.
+
+   Return 1 if the operation was successful.  Return zero otherwise,
+   in which case the value of POS is unmodified.
+*/
+
+int
+discrete_position (struct type *type, LONGEST val, LONGEST *pos)
+{
+  if (TYPE_CODE (type) == TYPE_CODE_ENUM)
+    {
+      int i;
+
+      for (i = 0; i < TYPE_NFIELDS (type); i += 1)
+        {
+          if (val == TYPE_FIELD_ENUMVAL (type, i))
+           {
+             *pos = i;
+             return 1;
+           }
+        }
+      /* Invalid enumeration value.  */
+      return 0;
+    }
+  else
+    {
+      *pos = val;
+      return 1;
+    }
+}
+
 /* Create an array type using either a blank type supplied in
    RESULT_TYPE, or creating a new type, inheriting the objfile from
    RANGE_TYPE.
@@ -1748,10 +1787,14 @@ stub_noname_complaint (void)
 /* Worker for is_dynamic_type.  */
 
 static int
-is_dynamic_type_internal (struct type *type)
+is_dynamic_type_internal (struct type *type, int top_level)
 {
   type = check_typedef (type);
 
+  /* We only want to recognize references at the outermost level.  */
+  if (top_level && TYPE_CODE (type) == TYPE_CODE_REF)
+    type = check_typedef (TYPE_TARGET_TYPE (type));
+
   /* Types that have a dynamic TYPE_DATA_LOCATION are considered
      dynamic, even if the type itself is statically defined.
      From a user's point of view, this may appear counter-intuitive;
@@ -1773,7 +1816,7 @@ is_dynamic_type_internal (struct type *type)
           of the range type are static.  It allows us to assume that
           the subtype of a static range type is also static.  */
        return (!has_static_range (TYPE_RANGE_DATA (type))
-               || is_dynamic_type_internal (TYPE_TARGET_TYPE (type)));
+               || is_dynamic_type_internal (TYPE_TARGET_TYPE (type), 0));
       }
 
     case TYPE_CODE_ARRAY:
@@ -1782,9 +1825,9 @@ is_dynamic_type_internal (struct type *type)
 
        /* The array is dynamic if either the bounds are dynamic,
           or the elements it contains have a dynamic contents.  */
-       if (is_dynamic_type_internal (TYPE_INDEX_TYPE (type)))
+       if (is_dynamic_type_internal (TYPE_INDEX_TYPE (type), 0))
          return 1;
-       return is_dynamic_type_internal (TYPE_TARGET_TYPE (type));
+       return is_dynamic_type_internal (TYPE_TARGET_TYPE (type), 0);
       }
 
     case TYPE_CODE_STRUCT:
@@ -1794,7 +1837,7 @@ is_dynamic_type_internal (struct type *type)
 
        for (i = 0; i < TYPE_NFIELDS (type); ++i)
          if (!field_is_static (&TYPE_FIELD (type, i))
-             && is_dynamic_type_internal (TYPE_FIELD_TYPE (type, i)))
+             && is_dynamic_type_internal (TYPE_FIELD_TYPE (type, i), 0))
            return 1;
       }
       break;
@@ -1808,11 +1851,11 @@ is_dynamic_type_internal (struct type *type)
 int
 is_dynamic_type (struct type *type)
 {
-  return is_dynamic_type_internal (type);
+  return is_dynamic_type_internal (type, 1);
 }
 
 static struct type *resolve_dynamic_type_internal
-  (struct type *type, struct property_addr_info *addr_stack);
+  (struct type *type, struct property_addr_info *addr_stack, int top_level);
 
 /* Given a dynamic range type (dyn_range_type) and a stack of
    struct property_addr_info elements, return a static version
@@ -1860,7 +1903,7 @@ resolve_dynamic_range (struct type *dyn_range_type,
 
   static_target_type
     = resolve_dynamic_type_internal (TYPE_TARGET_TYPE (dyn_range_type),
-                                    addr_stack);
+                                    addr_stack, 0);
   static_range_type = create_range_type (copy_type (dyn_range_type),
                                         static_target_type,
                                         &low_bound, &high_bound);
@@ -1894,9 +1937,9 @@ resolve_dynamic_array (struct type *type,
   else
     elt_type = TYPE_TARGET_TYPE (type);
 
-  return create_array_type (copy_type (type),
-                           elt_type,
-                           range_type);
+  return create_array_type_with_stride (copy_type (type),
+                                       elt_type, range_type,
+                                       TYPE_FIELD_BITSIZE (type, 0));
 }
 
 /* Resolve dynamic bounds of members of the union TYPE to static
@@ -1928,7 +1971,7 @@ resolve_dynamic_union (struct type *type,
        continue;
 
       t = resolve_dynamic_type_internal (TYPE_FIELD_TYPE (resolved_type, i),
-                                        addr_stack);
+                                        addr_stack, 0);
       TYPE_FIELD_TYPE (resolved_type, i) = t;
       if (TYPE_LENGTH (t) > max_len)
        max_len = TYPE_LENGTH (t);
@@ -1980,12 +2023,13 @@ resolve_dynamic_struct (struct type *type,
                 " (invalid location kind)"));
 
       pinfo.type = check_typedef (TYPE_FIELD_TYPE (type, i));
+      pinfo.valaddr = addr_stack->valaddr;
       pinfo.addr = addr_stack->addr;
       pinfo.next = addr_stack;
 
       TYPE_FIELD_TYPE (resolved_type, i)
        = resolve_dynamic_type_internal (TYPE_FIELD_TYPE (resolved_type, i),
-                                        &pinfo);
+                                        &pinfo, 0);
       gdb_assert (TYPE_FIELD_LOC_KIND (resolved_type, i)
                  == FIELD_LOC_KIND_BITPOS);
 
@@ -2009,6 +2053,10 @@ resolve_dynamic_struct (struct type *type,
   TYPE_LENGTH (resolved_type)
     = (resolved_type_bit_length + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;
 
+  /* The Ada language uses this field as a cache for static fixed types: reset
+     it as RESOLVED_TYPE must have its own static fixed type.  */
+  TYPE_TARGET_TYPE (resolved_type) = NULL;
+
   return resolved_type;
 }
 
@@ -2016,21 +2064,23 @@ resolve_dynamic_struct (struct type *type,
 
 static struct type *
 resolve_dynamic_type_internal (struct type *type,
-                              struct property_addr_info *addr_stack)
+                              struct property_addr_info *addr_stack,
+                              int top_level)
 {
   struct type *real_type = check_typedef (type);
   struct type *resolved_type = type;
   struct dynamic_prop *prop;
   CORE_ADDR value;
 
-  if (!is_dynamic_type_internal (real_type))
+  if (!is_dynamic_type_internal (real_type, top_level))
     return type;
 
   if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
     {
       resolved_type = copy_type (type);
       TYPE_TARGET_TYPE (resolved_type)
-       = resolve_dynamic_type_internal (TYPE_TARGET_TYPE (type), addr_stack);
+       = resolve_dynamic_type_internal (TYPE_TARGET_TYPE (type), addr_stack,
+                                        top_level);
     }
   else 
     {
@@ -2039,6 +2089,25 @@ resolve_dynamic_type_internal (struct type *type,
 
       switch (TYPE_CODE (type))
        {
+       case TYPE_CODE_REF:
+         {
+           struct property_addr_info pinfo;
+
+           pinfo.type = check_typedef (TYPE_TARGET_TYPE (type));
+           pinfo.valaddr = NULL;
+           if (addr_stack->valaddr != NULL)
+             pinfo.addr = extract_typed_address (addr_stack->valaddr, type);
+           else
+             pinfo.addr = read_memory_typed_address (addr_stack->addr, type);
+           pinfo.next = addr_stack;
+
+           resolved_type = copy_type (type);
+           TYPE_TARGET_TYPE (resolved_type)
+             = resolve_dynamic_type_internal (TYPE_TARGET_TYPE (type),
+                                              &pinfo, top_level);
+           break;
+         }
+
        case TYPE_CODE_ARRAY:
          resolved_type = resolve_dynamic_array (type, addr_stack);
          break;
@@ -2071,11 +2140,13 @@ resolve_dynamic_type_internal (struct type *type,
 /* See gdbtypes.h  */
 
 struct type *
-resolve_dynamic_type (struct type *type, CORE_ADDR addr)
+resolve_dynamic_type (struct type *type, const gdb_byte *valaddr,
+                     CORE_ADDR addr)
 {
-  struct property_addr_info pinfo = {check_typedef (type), addr, NULL};
+  struct property_addr_info pinfo
+    = {check_typedef (type), valaddr, addr, NULL};
 
-  return resolve_dynamic_type_internal (type, &pinfo);
+  return resolve_dynamic_type_internal (type, &pinfo, 1);
 }
 
 /* See gdbtypes.h  */
@@ -3867,7 +3938,13 @@ print_gnat_stuff (struct type *type, int spaces)
 {
   struct type *descriptive_type = TYPE_DESCRIPTIVE_TYPE (type);
 
-  recursive_dump_type (descriptive_type, spaces + 2);
+  if (descriptive_type == NULL)
+    printfi_filtered (spaces + 2, "no descriptive type\n");
+  else
+    {
+      printfi_filtered (spaces + 2, "descriptive type\n");
+      recursive_dump_type (descriptive_type, spaces + 4);
+    }
 }
 
 static struct obstack dont_print_type_obstack;
This page took 0.027608 seconds and 4 git commands to generate.