return type;
}
+/* See gdbtypes.h. */
+
+unsigned int
+type_length_units (struct type *type)
+{
+ struct gdbarch *arch = get_type_arch (type);
+ int unit_size = gdbarch_addressable_memory_unit_size (arch);
+
+ return TYPE_LENGTH (type) / unit_size;
+}
+
/* Alloc a new type instance structure, fill it with some defaults,
and point it at OLDTYPE. Allocate the new type instance from the
same place as OLDTYPE. */
int
get_discrete_bounds (struct type *type, LONGEST *lowp, LONGEST *highp)
{
- CHECK_TYPEDEF (type);
+ type = check_typedef (type);
switch (TYPE_CODE (type))
{
case TYPE_CODE_RANGE:
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.
if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
low_bound = high_bound = 0;
- CHECK_TYPEDEF (element_type);
+ element_type = check_typedef (element_type);
/* 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. */
const char *name;
struct objfile *objfile;
- CHECK_TYPEDEF (type);
+ type = check_typedef (type);
name = type_name_no_tag (type);
if (name != NULL)
for (;;)
{
- CHECK_TYPEDEF (type);
+ type = check_typedef (type);
if (TYPE_CODE (type) != TYPE_CODE_PTR
&& TYPE_CODE (type) != TYPE_CODE_REF)
break;
{
unsigned int n;
- CHECK_TYPEDEF (type);
+ type = check_typedef (type);
gdb_assert (TYPE_CODE (type) == TYPE_CODE_INT && TYPE_UNSIGNED (type));
gdb_assert (TYPE_LENGTH (type) <= sizeof (ULONGEST));
{
unsigned int n;
- CHECK_TYPEDEF (type);
+ type = check_typedef (type);
gdb_assert (TYPE_CODE (type) == TYPE_CODE_INT && !TYPE_UNSIGNED (type));
gdb_assert (TYPE_LENGTH (type) <= sizeof (LONGEST));
int
internal_type_vptr_fieldno (struct type *type)
{
- CHECK_TYPEDEF (type);
+ type = check_typedef (type);
gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT
|| TYPE_CODE (type) == TYPE_CODE_UNION);
if (!HAVE_CPLUS_STRUCT (type))
void
set_type_vptr_fieldno (struct type *type, int fieldno)
{
- CHECK_TYPEDEF (type);
+ type = check_typedef (type);
gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT
|| TYPE_CODE (type) == TYPE_CODE_UNION);
if (!HAVE_CPLUS_STRUCT (type))
struct type *
internal_type_vptr_basetype (struct type *type)
{
- CHECK_TYPEDEF (type);
+ type = check_typedef (type);
gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT
|| TYPE_CODE (type) == TYPE_CODE_UNION);
gdb_assert (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_CPLUS_STUFF);
void
set_type_vptr_basetype (struct type *type, struct type *basetype)
{
- CHECK_TYPEDEF (type);
+ type = check_typedef (type);
gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT
|| TYPE_CODE (type) == TYPE_CODE_UNION);
if (!HAVE_CPLUS_STRUCT (type))
int
get_vptr_fieldno (struct type *type, struct type **basetypep)
{
- CHECK_TYPEDEF (type);
+ type = check_typedef (type);
if (TYPE_VPTR_FIELDNO (type) < 0)
{
/* 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);
ary_dim = check_typedef (TYPE_TARGET_TYPE (elt_type));
if (ary_dim != NULL && TYPE_CODE (ary_dim) == TYPE_CODE_ARRAY)
- elt_type = resolve_dynamic_array (TYPE_TARGET_TYPE (type), addr_stack);
+ elt_type = resolve_dynamic_array (ary_dim, addr_stack);
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 */
{
/* FIXME: Should we return true for references as well as
pointers? */
- CHECK_TYPEDEF (t);
+ t = check_typedef (t);
return
(t != NULL
&& TYPE_CODE (t) == TYPE_CODE_PTR
int
is_integral_type (struct type *t)
{
- CHECK_TYPEDEF (t);
+ t = check_typedef (t);
return
((t != NULL)
&& ((TYPE_CODE (t) == TYPE_CODE_INT)
static int
is_scalar_type (struct type *type)
{
- CHECK_TYPEDEF (type);
+ type = check_typedef (type);
switch (TYPE_CODE (type))
{
int
is_scalar_type_recursive (struct type *t)
{
- CHECK_TYPEDEF (t);
+ t = check_typedef (t);
if (is_scalar_type (t))
return 1;
int i;
int d;
- CHECK_TYPEDEF (base);
- CHECK_TYPEDEF (dclass);
+ base = check_typedef (base);
+ dclass = check_typedef (dclass);
if (class_types_same_p (base, dclass))
return 0;
{
int i, count = 0;
- CHECK_TYPEDEF (base);
- CHECK_TYPEDEF (dclass);
+ base = check_typedef (base);
+ dclass = check_typedef (dclass);
for (i = 0; i < TYPE_N_BASECLASSES (dclass) && count < 2; ++i)
{
check_types_equal (struct type *type1, struct type *type2,
VEC (type_equality_entry_d) **worklist)
{
- CHECK_TYPEDEF (type1);
- CHECK_TYPEDEF (type2);
+ type1 = check_typedef (type1);
+ type2 = check_typedef (type2);
if (type1 == type2)
return 1;
{
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;