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.
/* 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;
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:
/* 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:
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;
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
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);
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
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);
" (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);
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;
}
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
{
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;
/* 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 */
{
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;