/* 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, 2008, 2009 Free Software Foundation, Inc.
+ 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+ Free Software Foundation, Inc.
Contributed by Cygnus Support, using pieces from other GDB modules.
/* FIXME! Assume the machine has only one representation for
pointers! */
- TYPE_LENGTH (ntype) =
- gdbarch_ptr_bit (current_gdbarch) / TARGET_CHAR_BIT;
+ TYPE_LENGTH (ntype)
+ = gdbarch_ptr_bit (get_type_arch (type)) / TARGET_CHAR_BIT;
TYPE_CODE (ntype) = TYPE_CODE_PTR;
/* Mark pointers as unsigned. The target converts between pointers
references, and that it matches the (only) representation for
pointers! */
- TYPE_LENGTH (ntype) = gdbarch_ptr_bit (current_gdbarch) / TARGET_CHAR_BIT;
+ TYPE_LENGTH (ntype) =
+ gdbarch_ptr_bit (get_type_arch (type)) / TARGET_CHAR_BIT;
TYPE_CODE (ntype) = TYPE_CODE_REF;
if (!TYPE_REFERENCE_TYPE (type)) /* Remember it, if don't have one. */
/* Identify address space identifier by name --
return the integer flag defined in gdbtypes.h. */
extern int
-address_space_name_to_int (char *space_identifier)
+address_space_name_to_int (struct gdbarch *gdbarch, char *space_identifier)
{
- struct gdbarch *gdbarch = current_gdbarch;
int type_flags;
/* Check for known address space delimiters. */
if (!strcmp (space_identifier, "code"))
gdbtypes.h -- return the string version of the adress space name. */
const char *
-address_space_int_to_name (int space_flag)
+address_space_int_to_name (struct gdbarch *gdbarch, int space_flag)
{
- struct gdbarch *gdbarch = current_gdbarch;
if (space_flag & TYPE_INSTANCE_FLAG_CODE_SPACE)
return "code";
else if (space_flag & TYPE_INSTANCE_FLAG_DATA_SPACE)
struct type *
create_range_type (struct type *result_type, struct type *index_type,
- int low_bound, int high_bound)
+ LONGEST low_bound, LONGEST high_bound)
{
if (result_type == NULL)
result_type = alloc_type_copy (index_type);
TYPE_TARGET_STUB (result_type) = 1;
else
TYPE_LENGTH (result_type) = TYPE_LENGTH (check_typedef (index_type));
- TYPE_NFIELDS (result_type) = 2;
- TYPE_FIELDS (result_type) = TYPE_ZALLOC (result_type,
- TYPE_NFIELDS (result_type)
- * sizeof (struct field));
+ TYPE_RANGE_DATA (result_type) = (struct range_bounds *)
+ TYPE_ZALLOC (result_type, sizeof (struct range_bounds));
TYPE_LOW_BOUND (result_type) = low_bound;
TYPE_HIGH_BOUND (result_type) = high_bound;
lookup_array_range_type (struct type *element_type,
int low_bound, int high_bound)
{
- struct gdbarch *gdbarch = current_gdbarch;
+ struct gdbarch *gdbarch = get_type_arch (element_type);
struct type *index_type = builtin_type (gdbarch)->builtin_int;
struct type *range_type
= create_range_type (NULL, index_type, low_bound, high_bound);
TYPE_DOMAIN_TYPE (type) = domain;
/* Assume that a data member pointer is the same size as a normal
pointer. */
- TYPE_LENGTH (type) = gdbarch_ptr_bit (current_gdbarch) / TARGET_CHAR_BIT;
+ TYPE_LENGTH (type)
+ = gdbarch_ptr_bit (get_type_arch (to_type)) / TARGET_CHAR_BIT;
TYPE_CODE (type) = TYPE_CODE_MEMBERPTR;
}
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
+ debugging a .o file, or the compiler uses DWARF-2 and is not GCC),
+ 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 or incomplete. */
symbols which contain a full definition for the type.
This used to be coded as a macro, but I don't think it is called
- often enough to merit such treatment. */
+ often enough to merit such treatment.
-/* Find the real type of TYPE. This function returns the real type,
+ Find the real type of TYPE. This function returns the real type,
after removing all layers of typedefs and completing opaque or stub
types. Completion changes the TYPE argument, but stripping of
- typedefs does not. */
+ typedefs does not.
+
+ If TYPE is a TYPE_CODE_TYPEDEF, its length is (also) set to the length of
+ the target type instead of zero. However, in the case of TYPE_CODE_TYPEDEF
+ check_typedef can still return different type than the original TYPE
+ pointer. */
struct type *
check_typedef (struct type *type)
/* Now recompute the length of the array type, based on its
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_LOW_BOUND (range_type);
- const int high_bound = TYPE_HIGH_BOUND (range_type);
- int nb_elements;
-
+ is smaller than the low bound. */
+ const LONGEST low_bound = TYPE_LOW_BOUND (range_type);
+ const LONGEST high_bound = TYPE_HIGH_BOUND (range_type);
+ ULONGEST len;
+
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);
+ len = 0;
+ else {
+ /* For now, we conservatively take the array length to be 0
+ if its length exceeds UINT_MAX. The code below assumes
+ that for x < 0, (ULONGEST) x == -x + ULONGEST_MAX + 1,
+ which is technically not guaranteed by C, but is usually true
+ (because it would be true if x were unsigned with its
+ high-order bit on). It uses the fact that
+ high_bound-low_bound is always representable in
+ ULONGEST and that if high_bound-low_bound+1 overflows,
+ it overflows to 0. We must change these tests if we
+ decide to increase the representation of TYPE_LENGTH
+ from unsigned int to ULONGEST. */
+ ULONGEST ulow = low_bound, uhigh = high_bound;
+ ULONGEST tlen = TYPE_LENGTH (target_type);
+
+ len = tlen * (uhigh - ulow + 1);
+ if (tlen == 0 || (len / tlen - 1 + ulow) != uhigh
+ || len > UINT_MAX)
+ len = 0;
+ }
+ TYPE_LENGTH (type) = len;
TYPE_TARGET_STUB (type) = 0;
}
else if (TYPE_CODE (type) == TYPE_CODE_RANGE)
static void
check_stub_method (struct type *type, int method_id, int signature_id)
{
- struct gdbarch *gdbarch = current_gdbarch;
+ struct gdbarch *gdbarch = get_type_arch (type);
struct fn_field *f;
char *mangled_name = gdb_mangle_name (type, method_id, signature_id);
char *demangled_name = cplus_demangle (mangled_name,
switch (TYPE_CODE (arg))
{
case TYPE_CODE_PTR:
- if (TYPE_CODE (TYPE_TARGET_TYPE (parm)) == TYPE_CODE_VOID)
+ if (TYPE_CODE (TYPE_TARGET_TYPE (parm)) == TYPE_CODE_VOID
+ && TYPE_CODE (TYPE_TARGET_TYPE (arg)) != TYPE_CODE_VOID)
return VOID_PTR_CONVERSION_BADNESS;
else
return rank_one_type (TYPE_TARGET_TYPE (parm),
recursive_dump_type (TYPE_FIELD_TYPE (type, idx), spaces + 4);
}
}
+ if (TYPE_CODE (type) == TYPE_CODE_RANGE)
+ {
+ printfi_filtered (spaces, "low %s%s high %s%s\n",
+ plongest (TYPE_LOW_BOUND (type)),
+ TYPE_LOW_BOUND_UNDEFINED (type) ? " (undefined)" : "",
+ plongest (TYPE_HIGH_BOUND (type)),
+ TYPE_HIGH_BOUND_UNDEFINED (type) ? " (undefined)" : "");
+ }
printfi_filtered (spaces, "vptr_basetype ");
gdb_print_host_address (TYPE_VPTR_BASETYPE (type), gdb_stdout);
puts_filtered ("\n");
}
}
+ /* For range types, copy the bounds information. */
+ if (TYPE_CODE (type) == TYPE_CODE_RANGE)
+ {
+ TYPE_RANGE_DATA (new_type) = xmalloc (sizeof (struct range_bounds));
+ *TYPE_RANGE_DATA (new_type) = *TYPE_RANGE_DATA (type);
+ }
+
/* Copy pointers to other types. */
if (TYPE_TARGET_TYPE (type))
TYPE_TARGET_TYPE (new_type) =