* [RFA] 64-bit range types in GDB
@ 2009-12-04 8:13 Paul Hilfinger
2009-12-04 18:35 ` Tom Tromey
0 siblings, 1 reply; 8+ messages in thread
From: Paul Hilfinger @ 2009-12-04 8:13 UTC (permalink / raw)
To: gdb-patches
AdaCore has been using the following patch for some months now to extend
the representation of types in GDB so as to allow 64-bit values in range
types. It required doing some violence to struct main_type, unfortunately,
but as a side effect, the representation of range types is a bit less of an
abuse of abstraction (IMHO, anyway). I apologize to those of you who will
have to modify your type-manipulation routines in .gdbinit files.
Tested on Linux and Sparc Solaris 10 without regressions.
Paul Hilfinger
Consultant, AdaCore, Inc.
ChangeLog:
2009-12-04 Paul N. Hilfinger <hilfinger@adacore.com>
* dwarf2read.c (struct attribute): Increase sizes of unsnd and snd
fields to allow larger integer sizes.
(read_subrange_type): Increase size of bound values.
Add logic to determine signedness based on base-type size, signedness.
(read_attribute_value): Change format for bad byte size in message.
(read_8_bytes): Increase size of result type.
(dump_die_shallow): Change format for value.
(dwarf2_get_attr_constant_value): Increase size of return type.
Correct comment.
(fixup_range_type_hack): New function.
* gdbtypes.c (create_range_type): Change API to increase size of
bounds. struct field -> union field.
Always take signedness from base type.
(check_typedef): Use new API for TYPE_LOW_BOUND, TYPE_HIGH_BOUND.
(recursive_dump_type, copy_type_recursive): Adjust to new
representation of range types.
* gdbtypes.h (fields_or_bounds): New union containing struct field and
new struct range_bounds, used for range types.
(TYPE_RANGE_DATA): New macro to access range_bounds member.
(TYPE_LOW_BOUND, TYPE_HIGH_BOUND): Represent with new TYPE_RANGE_DATA.
(TYPE_LOW_BOUND_UNDEFINED, TYPE_HIGH_BOUND_UNDEFINED): New macros,
taking over the job of TYPE_FIELD_ARTIFICIAL for range bounds.
(SET_TYPE_LOW_BOUND, SET_TYPE_HIGH_BOUND, SET_TYPE_LOW_BOUND_DEFINED)
(SET_TYPE_HIGH_BOUND_DEFINED): New macros.
(TYPE_FIELDS, TYPE_BASECLASS, TYPE_BASECLASS_NAME, TYPE_FIELD)
(TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED)
(TYPE_ARRAY_LOWER_BOUND_IS_UNDEFINED, TYPE_ARRAY_UPPER_BOUND_VALUE)
(TYPE_ARRAY_LOWER_BOUND_VALUE): Adjust to new representation.
(create_range_type): Adjust API.
* ada-lang.c (ada_modulus): Use new extended bound values.
(discrete_type_low_bound): Rename to...
(ada_discrete_type_low_bound): ... and make external.
(discrete_type_high_bound): Rename to...
(ada_discrete_type_high_bound): ... and make external.
(ada_value_slice_from_ptr, ada_array_bound_from_type)
(ada_evaluate_subexp, to_fixed_range_type):
Use ada_discrete_type_low_bound, ada_discrete_type_high_bound.
* ada-typeprint.c (print_range): Use ada_discrete_type_low_bound,
ada_discrete_type_high_bound. Don't look at field count, which
is no longer meaningful. Print bounds whenever argument is a range
or enumeration.
* ada-lang.h (ada_discrete_type_low_bound,ada_discrete_type_high_bound):
Declare.
* varobj.c (c_describe_child): Adjust to render larger values.
* mdebugread.c (parse_type): Use proper abstractions for range types:
TYPE_RANGE_DATA, SET_TYPE_LOW_BOUND_DEFINED,
SET_TYPE_HIGH_BOUND_DEFINED.
* p-typeprint.c (pascal_type_print_varspec_prefix): Use larger format
for bounds.
diff -upr old/gdb/ada-lang.c new/gdb/ada-lang.c
--- old/gdb/ada-lang.c 2009-12-02 11:29:41.000000000 -0800
+++ new/gdb/ada-lang.c 2009-12-03 22:51:40.000000000 -0800
@@ -597,8 +597,8 @@ min_of_type (struct type *t)
}
/* The largest value in the domain of TYPE, a discrete type, as an integer. */
-static LONGEST
-discrete_type_high_bound (struct type *type)
+LONGEST
+ada_discrete_type_high_bound (struct type *type)
{
switch (TYPE_CODE (type))
{
@@ -612,13 +612,13 @@ discrete_type_high_bound (struct type *t
case TYPE_CODE_INT:
return max_of_type (type);
default:
- error (_("Unexpected type in discrete_type_high_bound."));
+ error (_("Unexpected type in ada_discrete_type_high_bound."));
}
}
/* The largest value in the domain of TYPE, a discrete type, as an integer. */
-static LONGEST
-discrete_type_low_bound (struct type *type)
+LONGEST
+ada_discrete_type_low_bound (struct type *type)
{
switch (TYPE_CODE (type))
{
@@ -632,7 +632,7 @@ discrete_type_low_bound (struct type *ty
case TYPE_CODE_INT:
return min_of_type (type);
default:
- error (_("Unexpected type in discrete_type_low_bound."));
+ error (_("Unexpected type in ada_discrete_type_low_bound."));
}
}
@@ -2399,7 +2399,7 @@ ada_value_slice_from_ptr (struct value *
int low, int high)
{
CORE_ADDR base = value_as_address (array_ptr)
- + ((low - TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)))
+ + ((low - ada_discrete_type_low_bound (TYPE_INDEX_TYPE (type)))
* TYPE_LENGTH (TYPE_TARGET_TYPE (type)));
struct type *index_type =
create_range_type (NULL, TYPE_TARGET_TYPE (TYPE_INDEX_TYPE (type)),
@@ -2542,7 +2542,6 @@ static LONGEST
ada_array_bound_from_type (struct type * arr_type, int n, int which)
{
struct type *type, *elt_type, *index_type_desc, *index_type;
- LONGEST retval;
int i;
gdb_assert (which == 0 || which == 1);
@@ -2569,22 +2568,10 @@ ada_array_bound_from_type (struct type *
else
index_type = TYPE_INDEX_TYPE (elt_type);
- switch (TYPE_CODE (index_type))
- {
- case TYPE_CODE_RANGE:
- retval = which == 0 ? TYPE_LOW_BOUND (index_type)
- : TYPE_HIGH_BOUND (index_type);
- break;
- case TYPE_CODE_ENUM:
- retval = which == 0 ? TYPE_FIELD_BITPOS (index_type, 0)
- : TYPE_FIELD_BITPOS (index_type,
- TYPE_NFIELDS (index_type) - 1);
- break;
- default:
- internal_error (__FILE__, __LINE__, _("invalid type code of index type"));
- }
-
- return retval;
+ return
+ (LONGEST) (which == 0
+ ? ada_discrete_type_low_bound (index_type)
+ : ada_discrete_type_high_bound (index_type));
}
/* Given that arr is an array value, returns the lower bound of the
@@ -9262,10 +9249,10 @@ ada_evaluate_subexp (struct type *expect
error (_("unexpected attribute encountered"));
case OP_ATR_FIRST:
return value_from_longest
- (range_type, discrete_type_low_bound (range_type));
+ (range_type, ada_discrete_type_low_bound (range_type));
case OP_ATR_LAST:
return value_from_longest
- (range_type, discrete_type_high_bound (range_type));
+ (range_type, ada_discrete_type_high_bound (range_type));
case OP_ATR_LENGTH:
error (_("the 'length attribute applies only to array types"));
}
@@ -9839,14 +9826,14 @@ to_fixed_range_type (char *name, struct
subtype_info = strstr (name, "___XD");
if (subtype_info == NULL)
{
- LONGEST L = discrete_type_low_bound (raw_type);
- LONGEST U = discrete_type_high_bound (raw_type);
+ LONGEST L = ada_discrete_type_low_bound (raw_type);
+ LONGEST U = ada_discrete_type_high_bound (raw_type);
if (L < INT_MIN || U > INT_MAX)
return raw_type;
else
return create_range_type (alloc_type_copy (orig_type), raw_type,
- discrete_type_low_bound (raw_type),
- discrete_type_high_bound (raw_type));
+ ada_discrete_type_low_bound (raw_type),
+ ada_discrete_type_high_bound (raw_type));
}
else
{
@@ -9972,20 +9959,7 @@ ada_modulus_from_name (struct type *type
ULONGEST
ada_modulus (struct type *type)
{
- ULONGEST modulus;
-
- /* Normally, the modulus of a modular type is equal to the value of
- its upper bound + 1. However, the upper bound is currently stored
- as an int, which is not always big enough to hold the actual bound
- value. To workaround this, try to take advantage of the encoding
- that GNAT uses with with discrete types. To avoid some unnecessary
- parsing, we do this only when the size of TYPE is greater than
- the size of the field holding the bound. */
- if (TYPE_LENGTH (type) > sizeof (TYPE_HIGH_BOUND (type))
- && ada_modulus_from_name (type, &modulus))
- return modulus;
-
- return (ULONGEST) (unsigned int) TYPE_HIGH_BOUND (type) + 1;
+ return (ULONGEST) TYPE_HIGH_BOUND (type) + 1;
}
\f
diff -upr old/gdb/ada-lang.h new/gdb/ada-lang.h
--- old/gdb/ada-lang.h 2009-11-19 14:42:48.000000000 -0800
+++ new/gdb/ada-lang.h 2009-12-03 22:51:40.000000000 -0800
@@ -199,6 +199,10 @@ extern int ada_is_array_descriptor_type
extern int ada_is_bogus_array_descriptor (struct type *);
+extern LONGEST ada_discrete_type_low_bound (struct type *);
+
+extern LONGEST ada_discrete_type_high_bound (struct type *);
+
extern char *ada_decode_symbol (const struct general_symbol_info*);
extern const char *ada_decode (const char*);
diff -upr old/gdb/ada-typeprint.c new/gdb/ada-typeprint.c
--- old/gdb/ada-typeprint.c 2009-11-19 14:42:48.000000000 -0800
+++ new/gdb/ada-typeprint.c 2009-12-03 22:51:40.000000000 -0800
@@ -114,53 +114,32 @@ decoded_type_name (struct type *type)
}
}
-/* Print range type TYPE on STREAM. */
+/* Print TYPE on STREAM, preferably as a range. */
static void
print_range (struct type *type, struct ui_file *stream)
{
- struct type *target_type;
- target_type = TYPE_TARGET_TYPE (type);
- if (target_type == NULL)
- target_type = type;
-
- switch (TYPE_CODE (target_type))
+ switch (TYPE_CODE (type))
{
case TYPE_CODE_RANGE:
- case TYPE_CODE_INT:
- case TYPE_CODE_BOOL:
- case TYPE_CODE_CHAR:
case TYPE_CODE_ENUM:
+ {
+ struct type *target_type;
+ target_type = TYPE_TARGET_TYPE (type);
+ if (target_type == NULL)
+ target_type = type;
+ ada_print_scalar (target_type, ada_discrete_type_low_bound (type),
+ stream);
+ fprintf_filtered (stream, " .. ");
+ ada_print_scalar (target_type, ada_discrete_type_high_bound (type),
+ stream);
+ }
break;
default:
- target_type = NULL;
- break;
- }
-
- if (TYPE_NFIELDS (type) < 2)
- {
- /* A range needs at least 2 bounds to be printed. If there are less
- than 2, just print the type name instead of the range itself.
- This check handles cases such as characters, for example.
-
- If the name is not defined, then we don't print anything.
- */
fprintf_filtered (stream, "%.*s",
ada_name_prefix_len (TYPE_NAME (type)),
TYPE_NAME (type));
- }
- else
- {
- /* We extract the range type bounds respectively from the first element
- and the last element of the type->fields array */
- const LONGEST lower_bound = (LONGEST) TYPE_LOW_BOUND (type);
- const LONGEST upper_bound = (TYPE_CODE (type) == TYPE_CODE_RANGE
- ? (LONGEST) TYPE_HIGH_BOUND (type)
- : (LONGEST) TYPE_FIELD_BITPOS (type, TYPE_NFIELDS (type) - 1));
-
- ada_print_scalar (target_type, lower_bound, stream);
- fprintf_filtered (stream, " .. ");
- ada_print_scalar (target_type, upper_bound, stream);
+ break;
}
}
diff -upr old/gdb/dwarf2read.c new/gdb/dwarf2read.c
--- old/gdb/dwarf2read.c 2009-12-02 03:44:35.000000000 -0800
+++ new/gdb/dwarf2read.c 2009-12-03 22:51:40.000000000 -0800
@@ -549,8 +549,8 @@ struct attribute
{
char *str;
struct dwarf_block *blk;
- unsigned long unsnd;
- long int snd;
+ ULONGEST unsnd;
+ LONGEST snd;
CORE_ADDR addr;
struct signatured_type *signatured_type;
}
@@ -1065,7 +1065,7 @@ static int is_ref_attr (struct attribute
static unsigned int dwarf2_get_ref_die_offset (struct attribute *);
-static int dwarf2_get_attr_constant_value (struct attribute *, int);
+static LONGEST dwarf2_get_attr_constant_value (struct attribute *, int);
static struct die_info *follow_die_ref_or_sig (struct die_info *,
struct attribute *,
@@ -6032,6 +6032,42 @@ read_base_type (struct die_info *die, st
return set_die_type (die, type, cu);
}
+/* Fix the RANGE_TYPE flags if we think they are incorrect.
+ This is a temporary (?) hack to work around problems with handling
+ of >32bit range types on older compilers. On pure 32-bit hosts,
+ the compiler does not always emit the bounds as expected.
+ FIXME: pnh/2009-08-05. */
+
+static void
+fixup_range_type_hack (struct type *range_type, struct die_info *die,
+ struct dwarf2_cu *cu)
+{
+ struct attribute *low_attr = dwarf2_attr (die, DW_AT_lower_bound, cu);
+ struct attribute *high_attr = dwarf2_attr (die, DW_AT_upper_bound, cu);
+
+ LONGEST low = TYPE_LOW_BOUND (range_type);
+ LONGEST high = TYPE_HIGH_BOUND (range_type);
+
+ /* If no bounds are provided, then chances are that the compiler
+ failed to emit these bounds. In this case, we can't use the
+ (default) lower bound to determine whether the range type is
+ signed or unsigned. Use the base type instead. */
+ if (low_attr == NULL && high_attr == NULL)
+ TYPE_UNSIGNED (range_type) =
+ TYPE_UNSIGNED (TYPE_TARGET_TYPE (range_type));
+
+ /* If the size of the low bound is 4 bytes, and it is significantly
+ * larger than the high bound, guess that bit 32 is the sign bit. */
+ else if (low_attr != NULL && low_attr->form == DW_FORM_data4
+ && low > high + 1)
+ {
+ TYPE_UNSIGNED (range_type) = 0;
+ TYPE_LOW_BOUND (range_type) = low - ((LONGEST) 1 << 32);
+ if (high >= ((LONGEST) 1) << 31)
+ TYPE_HIGH_BOUND (range_type) = high - ((LONGEST) 1 << 32);
+ }
+}
+
/* Read the given DW_AT_subrange DIE. */
static struct type *
@@ -6041,9 +6077,10 @@ read_subrange_type (struct die_info *die
struct type *base_type;
struct type *range_type;
struct attribute *attr;
- int low = 0;
- int high = -1;
+ LONGEST low = 0;
+ LONGEST high = -1;
char *name;
+ LONGEST negative_mask;
base_type = die_type (die, cu);
if (TYPE_CODE (base_type) == TYPE_CODE_VOID)
@@ -6090,6 +6127,13 @@ read_subrange_type (struct die_info *die
high = dwarf2_get_attr_constant_value (attr, 1);
}
+ negative_mask =
+ (LONGEST) -1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1);
+ if (!TYPE_UNSIGNED (base_type) && (low & negative_mask))
+ low |= negative_mask;
+ if (!TYPE_UNSIGNED (base_type) && (high & negative_mask))
+ high |= negative_mask;
+
range_type = create_range_type (NULL, base_type, low, high);
name = dwarf2_name (die, cu);
@@ -7127,8 +7171,8 @@ read_attribute_value (struct attribute *
{
complaint
(&symfile_complaints,
- _("Suspicious DW_AT_byte_size value treated as zero instead of 0x%lx"),
- DW_UNSND (attr));
+ _("Suspicious DW_AT_byte_size value treated as zero instead of 0x%llx"),
+ (long long) DW_UNSND (attr));
DW_UNSND (attr) = 0;
}
@@ -10107,7 +10151,8 @@ dump_die_shallow (struct ui_file *f, int
case DW_FORM_data8:
case DW_FORM_udata:
case DW_FORM_sdata:
- fprintf_unfiltered (f, "constant: %ld", DW_UNSND (&die->attrs[i]));
+ fprintf_unfiltered (f, "constant: %lld",
+ (long long) DW_UNSND (&die->attrs[i]));
break;
case DW_FORM_sig8:
if (DW_SIGNATURED_TYPE (&die->attrs[i]) != NULL)
@@ -10230,10 +10275,10 @@ dwarf2_get_ref_die_offset (struct attrib
return 0;
}
-/* Return the constant value held by the given attribute. Return -1
- if the value held by the attribute is not constant. */
+/* Return the constant value held by ATTR. Return DEFAULT_VALUE if
+ * the value held by the attribute is not constant. */
-static int
+static LONGEST
dwarf2_get_attr_constant_value (struct attribute *attr, int default_value)
{
if (attr->form == DW_FORM_sdata)
diff -upr old/gdb/gdbtypes.c new/gdb/gdbtypes.c
--- old/gdb/gdbtypes.c 2009-11-12 11:47:25.000000000 -0800
+++ new/gdb/gdbtypes.c 2009-12-03 22:51:40.000000000 -0800
@@ -711,7 +711,7 @@ allocate_stub_method (struct type *type)
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);
@@ -721,10 +721,8 @@ create_range_type (struct type *result_t
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;
@@ -1476,14 +1474,14 @@ check_typedef (struct type *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_LOW_BOUND (range_type);
- const int high_bound = TYPE_HIGH_BOUND (range_type);
+ const LONGEST low_bound = TYPE_LOW_BOUND (range_type);
+ const LONGEST high_bound = TYPE_HIGH_BOUND (range_type);
int nb_elements;
if (high_bound < low_bound)
nb_elements = 0;
else
- nb_elements = high_bound - low_bound + 1;
+ nb_elements = (int) (high_bound - low_bound + 1);
TYPE_LENGTH (type) = nb_elements * TYPE_LENGTH (target_type);
TYPE_TARGET_STUB (type) = 0;
@@ -2737,6 +2735,14 @@ recursive_dump_type (struct type *type,
recursive_dump_type (TYPE_FIELD_TYPE (type, idx), spaces + 4);
}
}
+ if (TYPE_CODE (type) == TYPE_CODE_RANGE)
+ {
+ printfi_filtered (spaces, "low %lld%s high %lld%s\n",
+ (long long) TYPE_LOW_BOUND (type),
+ TYPE_LOW_BOUND_UNDEFINED (type) ? " (undefined)" : "",
+ (long long) 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");
@@ -2925,6 +2931,13 @@ copy_type_recursive (struct objfile *obj
}
}
+ /* 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) =
diff -upr old/gdb/gdbtypes.h new/gdb/gdbtypes.h
--- old/gdb/gdbtypes.h 2009-11-12 11:47:25.000000000 -0800
+++ new/gdb/gdbtypes.h 2009-12-03 22:51:40.000000000 -0800
@@ -447,61 +447,87 @@ struct main_type
because we can allocate the space for a type before
we know what to put in it. */
- struct field
+ union
{
- union field_location
+ struct field
{
- /* Position of this field, counting in bits from start of
- containing structure.
- For gdbarch_bits_big_endian=1 targets, it is the bit offset to the MSB.
- For gdbarch_bits_big_endian=0 targets, it is the bit offset to the LSB.
- For a range bound or enum value, this is the value itself. */
+ union field_location
+ {
+ /* Position of this field, counting in bits from start of
+ containing structure.
+ For gdbarch_bits_big_endian=1 targets, it is the bit offset to the MSB.
+ For gdbarch_bits_big_endian=0 targets, it is the bit offset to the LSB.
+ For a range bound or enum value, this is the value itself. */
+
+ int bitpos;
+
+ /* For a static field, if TYPE_FIELD_STATIC_HAS_ADDR then physaddr
+ is the location (in the target) of the static field.
+ Otherwise, physname is the mangled label of the static field. */
+
+ CORE_ADDR physaddr;
+ char *physname;
+
+ /* The field location can be computed by evaluating the following DWARF
+ block. This can be used in Fortran variable-length arrays, for
+ instance. */
+
+ struct dwarf2_locexpr_baton *dwarf_block;
+ }
+ loc;
+
+ /* For a function or member type, this is 1 if the argument is marked
+ artificial. Artificial arguments should not be shown to the
+ user. For TYPE_CODE_RANGE it is set if the specific bound is not
+ defined. */
+ unsigned int artificial : 1;
+
+ /* Discriminant for union field_location. */
+ ENUM_BITFIELD(field_loc_kind) loc_kind : 2;
+
+ /* Size of this field, in bits, or zero if not packed.
+ If non-zero in an array type, indicates the element size in
+ bits (used only in Ada at the moment).
+ For an unpacked field, the field's type's length
+ says how many bytes the field occupies. */
- int bitpos;
+ unsigned int bitsize : 29;
- /* For a static field, if TYPE_FIELD_STATIC_HAS_ADDR then physaddr
- is the location (in the target) of the static field.
- Otherwise, physname is the mangled label of the static field. */
+ /* In a struct or union type, type of this field.
+ In a function or member type, type of this argument.
+ In an array type, the domain-type of the array. */
- CORE_ADDR physaddr;
- char *physname;
+ struct type *type;
- /* The field location can be computed by evaluating the following DWARF
- block. This can be used in Fortran variable-length arrays, for
- instance. */
+ /* Name of field, value or argument.
+ NULL for range bounds, array domains, and member function
+ arguments. */
- struct dwarf2_locexpr_baton *dwarf_block;
- }
- loc;
+ char *name;
+ } *fields;
- /* For a function or member type, this is 1 if the argument is marked
- artificial. Artificial arguments should not be shown to the
- user. For TYPE_CODE_RANGE it is set if the specific bound is not
- defined. */
- unsigned int artificial : 1;
+ /* Union member used for range types. */
- /* Discriminant for union field_location. */
- ENUM_BITFIELD(field_loc_kind) loc_kind : 2;
+ struct range_bounds {
- /* Size of this field, in bits, or zero if not packed.
- For an unpacked field, the field's type's length
- says how many bytes the field occupies. */
+ /* Low bound of range. */
- unsigned int bitsize : 29;
+ LONGEST low;
- /* In a struct or union type, type of this field.
- In a function or member type, type of this argument.
- In an array type, the domain-type of the array. */
+ /* High bound of range. */
- struct type *type;
+ LONGEST high;
- /* Name of field, value or argument.
- NULL for range bounds, array domains, and member function
- arguments. */
+ /* Flags indicating whether the values of low and high are
+ valid. When true, the respective range value is
+ undefined. Currently used only for FORTRAN arrays. */
+
+ char low_undefined;
+ char high_undefined;
- char *name;
+ } *bounds;
- } *fields;
+ } flds_bnds;
/* For types with virtual functions (TYPE_CODE_STRUCT), VPTR_BASETYPE
is the base class which defined the virtual function table pointer.
@@ -828,19 +854,24 @@ extern void allocate_cplus_struct_type (
type, you need to do TYPE_CODE (check_type (this_type)). */
#define TYPE_CODE(thistype) TYPE_MAIN_TYPE(thistype)->code
#define TYPE_NFIELDS(thistype) TYPE_MAIN_TYPE(thistype)->nfields
-#define TYPE_FIELDS(thistype) TYPE_MAIN_TYPE(thistype)->fields
+#define TYPE_FIELDS(thistype) TYPE_MAIN_TYPE(thistype)->flds_bnds.fields
#define TYPE_TEMPLATE_ARGS(thistype) TYPE_CPLUS_SPECIFIC(thistype)->template_args
#define TYPE_INDEX_TYPE(type) TYPE_FIELD_TYPE (type, 0)
-#define TYPE_LOW_BOUND(range_type) TYPE_FIELD_BITPOS (range_type, 0)
-#define TYPE_HIGH_BOUND(range_type) TYPE_FIELD_BITPOS (range_type, 1)
+#define TYPE_RANGE_DATA(thistype) TYPE_MAIN_TYPE(thistype)->flds_bnds.bounds
+#define TYPE_LOW_BOUND(range_type) TYPE_RANGE_DATA(range_type)->low
+#define TYPE_HIGH_BOUND(range_type) TYPE_RANGE_DATA(range_type)->high
+#define TYPE_LOW_BOUND_UNDEFINED(range_type) \
+ TYPE_RANGE_DATA(range_type)->low_undefined
+#define TYPE_HIGH_BOUND_UNDEFINED(range_type) \
+ TYPE_RANGE_DATA(range_type)->high_undefined
/* Moto-specific stuff for FORTRAN arrays */
#define TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED(arraytype) \
- (TYPE_FIELD_ARTIFICIAL(TYPE_INDEX_TYPE((arraytype)),1))
+ TYPE_HIGH_BOUND_UNDEFINED(TYPE_INDEX_TYPE(arraytype))
#define TYPE_ARRAY_LOWER_BOUND_IS_UNDEFINED(arraytype) \
- (TYPE_FIELD_ARTIFICIAL(TYPE_INDEX_TYPE((arraytype)),0))
+ TYPE_LOW_BOUND_UNDEFINED(TYPE_INDEX_TYPE(arraytype))
#define TYPE_ARRAY_UPPER_BOUND_VALUE(arraytype) \
(TYPE_HIGH_BOUND(TYPE_INDEX_TYPE((arraytype))))
@@ -862,9 +893,9 @@ extern void allocate_cplus_struct_type (
#define TYPE_CPLUS_SPECIFIC(thistype) TYPE_MAIN_TYPE(thistype)->type_specific.cplus_stuff
#define TYPE_FLOATFORMAT(thistype) TYPE_MAIN_TYPE(thistype)->type_specific.floatformat
#define TYPE_CALLING_CONVENTION(thistype) TYPE_MAIN_TYPE(thistype)->type_specific.calling_convention
-#define TYPE_BASECLASS(thistype,index) TYPE_MAIN_TYPE(thistype)->fields[index].type
+#define TYPE_BASECLASS(thistype,index) TYPE_FIELD_TYPE(thistype, index)
#define TYPE_N_BASECLASSES(thistype) TYPE_CPLUS_SPECIFIC(thistype)->n_baseclasses
-#define TYPE_BASECLASS_NAME(thistype,index) TYPE_MAIN_TYPE(thistype)->fields[index].name
+#define TYPE_BASECLASS_NAME(thistype,index) TYPE_FIELD_NAME(thistype, index)
#define TYPE_BASECLASS_BITPOS(thistype,index) TYPE_FIELD_BITPOS(thistype,index)
#define BASETYPE_VIA_PUBLIC(thistype, index) \
((!TYPE_FIELD_PRIVATE(thistype, index)) && (!TYPE_FIELD_PROTECTED(thistype, index)))
@@ -896,7 +927,7 @@ extern void allocate_cplus_struct_type (
#define FIELD_ARTIFICIAL(thisfld) ((thisfld).artificial)
#define FIELD_BITSIZE(thisfld) ((thisfld).bitsize)
-#define TYPE_FIELD(thistype, n) TYPE_MAIN_TYPE(thistype)->fields[n]
+#define TYPE_FIELD(thistype, n) TYPE_MAIN_TYPE(thistype)->flds_bnds.fields[n]
#define TYPE_FIELD_TYPE(thistype, n) FIELD_TYPE(TYPE_FIELD(thistype, n))
#define TYPE_FIELD_NAME(thistype, n) FIELD_NAME(TYPE_FIELD(thistype, n))
#define TYPE_FIELD_LOC_KIND(thistype, n) FIELD_LOC_KIND (TYPE_FIELD (thistype, n))
@@ -1227,8 +1258,8 @@ extern struct type *make_function_type (
extern struct type *lookup_function_type (struct type *);
-extern struct type *create_range_type (struct type *, struct type *, int,
- int);
+extern struct type *create_range_type (struct type *, struct type *, LONGEST,
+ LONGEST);
extern struct type *create_array_type (struct type *, struct type *,
struct type *);
diff -upr old/gdb/mdebugread.c new/gdb/mdebugread.c
--- old/gdb/mdebugread.c 2009-11-16 10:40:22.000000000 -0800
+++ new/gdb/mdebugread.c 2009-12-03 22:51:40.000000000 -0800
@@ -1743,13 +1743,12 @@ parse_type (int fd, union aux_ext *ax, u
/* Deal with range types */
if (t->bt == btRange)
{
- TYPE_NFIELDS (tp) = 2;
- TYPE_FIELDS (tp) = ((struct field *)
- TYPE_ALLOC (tp, 2 * sizeof (struct field)));
- TYPE_FIELD_NAME (tp, 0) = "Low";
+ TYPE_NFIELDS (tp) = 0;
+ TYPE_RANGE_DATA (tp) = ((struct range_bounds *)
+ TYPE_ALLOC (tp, sizeof (struct range_bounds)));
+ memset (TYPE_RANGE_DATA (tp), 0, sizeof (struct range_bounds));
TYPE_LOW_BOUND (tp) = AUX_GET_DNLOW (bigend, ax);
ax++;
- TYPE_FIELD_NAME (tp, 1) = "High";
TYPE_HIGH_BOUND (tp) = AUX_GET_DNHIGH (bigend, ax);
ax++;
}
diff -upr old/gdb/p-typeprint.c new/gdb/p-typeprint.c
--- old/gdb/p-typeprint.c 2009-07-02 05:16:56.000000000 -0700
+++ new/gdb/p-typeprint.c 2009-12-03 22:51:40.000000000 -0800
@@ -267,10 +267,9 @@ pascal_type_print_varspec_prefix (struct
fprintf_filtered (stream, "array ");
if (TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0
&& !TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type))
- fprintf_filtered (stream, "[%d..%d] ",
- TYPE_ARRAY_LOWER_BOUND_VALUE (type),
- TYPE_ARRAY_UPPER_BOUND_VALUE (type)
- );
+ fprintf_filtered (stream, "[%lld..%lld] ",
+ (long long) TYPE_ARRAY_LOWER_BOUND_VALUE (type),
+ (long long) TYPE_ARRAY_UPPER_BOUND_VALUE (type));
fprintf_filtered (stream, "of ");
break;
diff -upr old/gdb/varobj.c new/gdb/varobj.c
--- old/gdb/varobj.c 2009-11-12 11:47:25.000000000 -0800
+++ new/gdb/varobj.c 2009-12-03 22:51:40.000000000 -0800
@@ -2793,8 +2793,9 @@ c_describe_child (struct varobj *parent,
{
case TYPE_CODE_ARRAY:
if (cname)
- *cname = xstrprintf ("%d", index
- + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)));
+ *cname = xstrdup (int_string (index
+ + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)),
+ 10, 1, 0, 0));
if (cvalue && value)
{
@@ -2806,9 +2807,11 @@ c_describe_child (struct varobj *parent,
*ctype = get_target_type (type);
if (cfull_expression)
- *cfull_expression = xstrprintf ("(%s)[%d]", parent_expression,
- index
- + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)));
+ *cfull_expression =
+ xstrprintf ("(%s)[%s]", parent_expression,
+ int_string (index
+ + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)),
+ 10, 1, 0, 0));
break;
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [RFA] 64-bit range types in GDB
2009-12-04 8:13 [RFA] 64-bit range types in GDB Paul Hilfinger
@ 2009-12-04 18:35 ` Tom Tromey
2009-12-05 12:18 ` Paul Hilfinger
0 siblings, 1 reply; 8+ messages in thread
From: Tom Tromey @ 2009-12-04 18:35 UTC (permalink / raw)
To: Hilfinger; +Cc: gdb-patches
>>>>> "Paul" == Paul Hilfinger <Hilfinger@adacore.com> writes:
Paul> It required doing some violence to struct main_type,
Paul> unfortunately, but as a side effect, the representation of range
Paul> types is a bit less of an abuse of abstraction (IMHO, anyway).
I agree, I think this is better.
Overall this patch looks great. I have a couple nits to pick.
Paul> I apologize to those of you who will have to modify your
Paul> type-manipulation routines in .gdbinit files.
I'm interested in seeing this sort of thing, so if you have gdb-specific
gdbinit hacks, please email them to me :-)
Paul> +/* Fix the RANGE_TYPE flags if we think they are incorrect.
Paul> + This is a temporary (?) hack to work around problems with handling
Paul> + of >32bit range types on older compilers. On pure 32-bit hosts,
Paul> + the compiler does not always emit the bounds as expected.
Paul> + FIXME: pnh/2009-08-05. */
Paul> +
Paul> +static void
Paul> +fixup_range_type_hack (struct type *range_type, struct die_info *die,
Paul> + struct dwarf2_cu *cu)
On irc, Joel said that he thought that this was perhaps no longer
needed. Could you comment?
Paul> + _("Suspicious DW_AT_byte_size value treated as zero instead of 0x%llx"),
Paul> + (long long) DW_UNSND (attr));
Are %ll and `long long' really portable? I think you need something
else here. There are a few cases.
[check_typedef]
Paul> - const int low_bound = TYPE_LOW_BOUND (range_type);
Paul> - const int high_bound = TYPE_HIGH_BOUND (range_type);
Paul> + const LONGEST low_bound = TYPE_LOW_BOUND (range_type);
Paul> + const LONGEST high_bound = TYPE_HIGH_BOUND (range_type);
Paul> int nb_elements;
Paul> if (high_bound < low_bound)
Paul> nb_elements = 0;
Paul> else
Paul> - nb_elements = high_bound - low_bound + 1;
Paul> + nb_elements = (int) (high_bound - low_bound + 1);
Can't this overflow? There's a subsequent multiplication, too...
I don't know what would be best to do here. Changing TYPE_LENGTH to a
LONGEST seems tough to swallow, but so does throwing an error.
Also, what does this code mean if either the high or low bound is
undefined? Maybe those cases should choose the min or max of the
underlying integral type?
Paul> + struct range_bounds {
Brace on its own line.
Paul> + TYPE_RANGE_DATA (tp) = ((struct range_bounds *)
Paul> + TYPE_ALLOC (tp, sizeof (struct range_bounds)));
Paul> + memset (TYPE_RANGE_DATA (tp), 0, sizeof (struct range_bounds));
Use TYPE_ZALLOC instead.
thanks,
Tom
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [RFA] 64-bit range types in GDB
2009-12-04 18:35 ` Tom Tromey
@ 2009-12-05 12:18 ` Paul Hilfinger
2009-12-05 16:53 ` Pierre Muller
2009-12-07 20:08 ` Tom Tromey
0 siblings, 2 replies; 8+ messages in thread
From: Paul Hilfinger @ 2009-12-05 12:18 UTC (permalink / raw)
To: tromey; +Cc: brobecker, gdb-patches
Tom,
Thanks for the (blindingly) fast response. Is Joel blackmailing you or
something? I could have a word with him if so.
> Paul> +/* Fix the RANGE_TYPE flags if we think they are incorrect.
> Paul> + This is a temporary (?) hack to work around problems with handling
> Paul> + of >32bit range types on older compilers. On pure 32-bit hosts,
> Paul> + the compiler does not always emit the bounds as expected.
> Paul> + FIXME: pnh/2009-08-05. */
> Paul> +
> Paul> +static void
> Paul> +fixup_range_type_hack (struct type *range_type, struct die_info *die,
> Paul> + struct dwarf2_cu *cu)
>
> On irc, Joel said that he thought that this was perhaps no longer
> needed. Could you comment?
In fact, at one point I HAD removed this function, but then discovered to
my annoyance that it was still needed somewhere. I'll have to go back and
reconstruct (from some months back) just what the problem was and whether it
has become OBE.
> Paul> + _("Suspicious DW_AT_byte_size value treated as zero instead of 0x%llx"),
> Paul> + (long long) DW_UNSND (attr));
>
> Are %ll and `long long' really portable? I think you need something
> else here. There are a few cases.
Yeah, it seems that long long either appears in system-specific code (like
linux-nat) where one can probably assume its existence, or conditionalized
as in printcmd.c.
>
> [check_typedef]
> Paul> - const int low_bound = TYPE_LOW_BOUND (range_type);
> Paul> - const int high_bound = TYPE_HIGH_BOUND (range_type);
> Paul> + const LONGEST low_bound = TYPE_LOW_BOUND (range_type);
> Paul> + const LONGEST high_bound = TYPE_HIGH_BOUND (range_type);
> Paul> int nb_elements;
>
> Paul> if (high_bound < low_bound)
> Paul> nb_elements = 0;
> Paul> else
> Paul> - nb_elements = high_bound - low_bound + 1;
> Paul> + nb_elements = (int) (high_bound - low_bound + 1);
>
> Can't this overflow? There's a subsequent multiplication, too...
>
> I don't know what would be best to do here. Changing TYPE_LENGTH to a
> LONGEST seems tough to swallow, but so does throwing an error.
>
Hmm. Sticky. There's this comment on 'length' in struct type:
/* Length of storage for a value of this type. This is what
sizeof(type) would return; use it for address arithmetic,
memory reads and writes, etc. ....
But then the code goes on to define 'unsigned length'. However, according
to the C standard, the type should really be size_t---and technically
that should be the TARGET's size_t. I suspect this part of the representation
hasn't been updated since the days when people actually used 16-bit address
spaces. What do you suppose people would say to using size_t here at least?
In any case, you are correct that there ought to be some provision for
overflow here.
> Also, what does this code mean if either the high or low bound is
> undefined? Maybe those cases should choose the min or max of the
> underlying integral type?
That also will require some thought. Some undefined bounds seem to be
carelessness on the part of the compiler, and I suspect that returning a
null range might be safer.
> Paul> + struct range_bounds {
>
> Brace on its own line.
>
> Paul> + TYPE_RANGE_DATA (tp) = ((struct range_bounds *)
> Paul> + TYPE_ALLOC (tp, sizeof (struct range_bounds)));
> Paul> + memset (TYPE_RANGE_DATA (tp), 0, sizeof (struct range_bounds));
>
> Use TYPE_ZALLOC instead.
OK and OK.
Thanks for the input. I should be submitting a revision soon.
Paul
^ permalink raw reply [flat|nested] 8+ messages in thread
* RE: [RFA] 64-bit range types in GDB
2009-12-05 12:18 ` Paul Hilfinger
@ 2009-12-05 16:53 ` Pierre Muller
2009-12-07 20:08 ` Tom Tromey
1 sibling, 0 replies; 8+ messages in thread
From: Pierre Muller @ 2009-12-05 16:53 UTC (permalink / raw)
To: Hilfinger, tromey; +Cc: brobecker, gdb-patches
> > Paul> + _("Suspicious DW_AT_byte_size value treated as zero
> instead of 0x%llx"),
> > Paul> + (long long) DW_UNSND (attr));
> >
> > Are %ll and `long long' really portable? I think you need something
> > else here. There are a few cases.
You shouldn't use %ll
as this would degenerate ARI regressions.
Please use %s with plongest or pulongest functions
from utils.c
Otherwise, I really like the idea of your patch to
remove the 32bit limitation for ranges!
Pierre Muller
as ARI "maintainer"...
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [RFA] 64-bit range types in GDB
2009-12-05 12:18 ` Paul Hilfinger
2009-12-05 16:53 ` Pierre Muller
@ 2009-12-07 20:08 ` Tom Tromey
2009-12-11 10:03 ` Paul Hilfinger
1 sibling, 1 reply; 8+ messages in thread
From: Tom Tromey @ 2009-12-07 20:08 UTC (permalink / raw)
To: Hilfinger; +Cc: brobecker, gdb-patches
>>>>> "Paul" == Paul Hilfinger <Hilfinger@adacore.com> writes:
Paul> Hmm. Sticky. There's this comment on 'length' in struct type:
Paul> /* Length of storage for a value of this type. This is what
Paul> sizeof(type) would return; use it for address arithmetic,
Paul> memory reads and writes, etc. ....
Paul> But then the code goes on to define 'unsigned length'. However,
Paul> according to the C standard, the type should really be
Paul> size_t---and technically that should be the TARGET's size_t. I
Paul> suspect this part of the representation hasn't been updated since
Paul> the days when people actually used 16-bit address spaces. What do
Paul> you suppose people would say to using size_t here at least?
size_t won't help on 32-bit hosts. There is also ULONGEST.
struct type and struct main_type are size-critical. It would be nice
not to grow them.
I suppose it depends on how much we care about objects bigger than 4G.
An error would be cheaper :-)
I'm open to either approach, though.
Tom
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [RFA] 64-bit range types in GDB
2009-12-07 20:08 ` Tom Tromey
@ 2009-12-11 10:03 ` Paul Hilfinger
2009-12-11 19:06 ` Tom Tromey
0 siblings, 1 reply; 8+ messages in thread
From: Paul Hilfinger @ 2009-12-11 10:03 UTC (permalink / raw)
To: gdb-patches; +Cc: brobecker, tromey
Here is the 64-bit range patch, revised per Tom's suggestions. For
now, I have eliminated the fixup_range_type_hack routine until such
time if ever that I find the failing cases that required it. (Besides which,
I see that the first patch didn't (ahem) bother to call it anyway).
In check_typedef, I have handled the overflow situation by setting the
array length to 0. I decided against using UINT_MAX given the likely
consequences of having such a value actually used to allocate a value
structure.
OK to commit?
Paul Hilfinger
ChangeLog:
2009-12-11 Paul N. Hilfinger <hilfinger@adacore.com>
* dwarf2read.c (struct attribute): Increase sizes of unsnd and snd
fields to allow larger integer sizes.
(read_subrange_type): Increase size of bound values.
Add logic to determine signedness based on base-type size, signedness.
(read_attribute_value): Change format for bad byte size in message.
(read_8_bytes): Increase size of result type.
(dump_die_shallow): Change format for value.
(dwarf2_get_attr_constant_value): Increase size of return type.
Correct comment.
* gdbtypes.c (create_range_type): Change API to increase size of
bounds. struct field -> union field.
Always take signedness from base type.
(check_typedef): Use new API for TYPE_LOW_BOUND, TYPE_HIGH_BOUND.
(recursive_dump_type, copy_type_recursive): Adjust to new
representation of range types.
* gdbtypes.h (fields_or_bounds): New union containing struct field and
new struct range_bounds, used for range types.
(TYPE_RANGE_DATA): New macro to access range_bounds member.
(TYPE_LOW_BOUND, TYPE_HIGH_BOUND): Represent with new TYPE_RANGE_DATA.
(TYPE_LOW_BOUND_UNDEFINED, TYPE_HIGH_BOUND_UNDEFINED): New macros,
taking over the job of TYPE_FIELD_ARTIFICIAL for range bounds.
(SET_TYPE_LOW_BOUND, SET_TYPE_HIGH_BOUND, SET_TYPE_LOW_BOUND_DEFINED)
(SET_TYPE_HIGH_BOUND_DEFINED): New macros.
(TYPE_FIELDS, TYPE_BASECLASS, TYPE_BASECLASS_NAME, TYPE_FIELD)
(TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED)
(TYPE_ARRAY_LOWER_BOUND_IS_UNDEFINED, TYPE_ARRAY_UPPER_BOUND_VALUE)
(TYPE_ARRAY_LOWER_BOUND_VALUE): Adjust to new representation.
(create_range_type): Adjust API.
* ada-lang.c (ada_modulus): Use new extended bound values.
(discrete_type_low_bound): Rename to...
(ada_discrete_type_low_bound): ... and make external.
(discrete_type_high_bound): Rename to...
(ada_discrete_type_high_bound): ... and make external.
(ada_value_slice_from_ptr, ada_array_bound_from_type)
(ada_evaluate_subexp, to_fixed_range_type):
Use ada_discrete_type_low_bound, ada_discrete_type_high_bound.
* ada-typeprint.c (print_range): Use ada_discrete_type_low_bound,
ada_discrete_type_high_bound. Don't look at field count, which
is no longer meaningful. Print bounds whenever argument is a range
or enumeration.
* ada-lang.h (ada_discrete_type_low_bound,ada_discrete_type_high_bound):
Declare.
* varobj.c (c_describe_child): Adjust to render larger values.
* mdebugread.c (parse_type): Use proper abstractions for range types:
TYPE_RANGE_DATA, SET_TYPE_LOW_BOUND_DEFINED,
SET_TYPE_HIGH_BOUND_DEFINED.
* p-typeprint.c (pascal_type_print_varspec_prefix): Use larger format
for bounds.
diff -upr gdb.old/gdb/ada-lang.c gdb.new/gdb/ada-lang.c
--- gdb.old/gdb/ada-lang.c 2009-12-02 11:29:41.000000000 -0800
+++ gdb.new/gdb/ada-lang.c 2009-12-11 01:39:05.000000000 -0800
@@ -597,8 +597,8 @@ min_of_type (struct type *t)
}
/* The largest value in the domain of TYPE, a discrete type, as an integer. */
-static LONGEST
-discrete_type_high_bound (struct type *type)
+LONGEST
+ada_discrete_type_high_bound (struct type *type)
{
switch (TYPE_CODE (type))
{
@@ -612,13 +612,13 @@ discrete_type_high_bound (struct type *t
case TYPE_CODE_INT:
return max_of_type (type);
default:
- error (_("Unexpected type in discrete_type_high_bound."));
+ error (_("Unexpected type in ada_discrete_type_high_bound."));
}
}
/* The largest value in the domain of TYPE, a discrete type, as an integer. */
-static LONGEST
-discrete_type_low_bound (struct type *type)
+LONGEST
+ada_discrete_type_low_bound (struct type *type)
{
switch (TYPE_CODE (type))
{
@@ -632,7 +632,7 @@ discrete_type_low_bound (struct type *ty
case TYPE_CODE_INT:
return min_of_type (type);
default:
- error (_("Unexpected type in discrete_type_low_bound."));
+ error (_("Unexpected type in ada_discrete_type_low_bound."));
}
}
@@ -2399,7 +2399,7 @@ ada_value_slice_from_ptr (struct value *
int low, int high)
{
CORE_ADDR base = value_as_address (array_ptr)
- + ((low - TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)))
+ + ((low - ada_discrete_type_low_bound (TYPE_INDEX_TYPE (type)))
* TYPE_LENGTH (TYPE_TARGET_TYPE (type)));
struct type *index_type =
create_range_type (NULL, TYPE_TARGET_TYPE (TYPE_INDEX_TYPE (type)),
@@ -2542,7 +2542,6 @@ static LONGEST
ada_array_bound_from_type (struct type * arr_type, int n, int which)
{
struct type *type, *elt_type, *index_type_desc, *index_type;
- LONGEST retval;
int i;
gdb_assert (which == 0 || which == 1);
@@ -2569,22 +2568,10 @@ ada_array_bound_from_type (struct type *
else
index_type = TYPE_INDEX_TYPE (elt_type);
- switch (TYPE_CODE (index_type))
- {
- case TYPE_CODE_RANGE:
- retval = which == 0 ? TYPE_LOW_BOUND (index_type)
- : TYPE_HIGH_BOUND (index_type);
- break;
- case TYPE_CODE_ENUM:
- retval = which == 0 ? TYPE_FIELD_BITPOS (index_type, 0)
- : TYPE_FIELD_BITPOS (index_type,
- TYPE_NFIELDS (index_type) - 1);
- break;
- default:
- internal_error (__FILE__, __LINE__, _("invalid type code of index type"));
- }
-
- return retval;
+ return
+ (LONGEST) (which == 0
+ ? ada_discrete_type_low_bound (index_type)
+ : ada_discrete_type_high_bound (index_type));
}
/* Given that arr is an array value, returns the lower bound of the
@@ -9262,10 +9249,10 @@ ada_evaluate_subexp (struct type *expect
error (_("unexpected attribute encountered"));
case OP_ATR_FIRST:
return value_from_longest
- (range_type, discrete_type_low_bound (range_type));
+ (range_type, ada_discrete_type_low_bound (range_type));
case OP_ATR_LAST:
return value_from_longest
- (range_type, discrete_type_high_bound (range_type));
+ (range_type, ada_discrete_type_high_bound (range_type));
case OP_ATR_LENGTH:
error (_("the 'length attribute applies only to array types"));
}
@@ -9839,14 +9826,14 @@ to_fixed_range_type (char *name, struct
subtype_info = strstr (name, "___XD");
if (subtype_info == NULL)
{
- LONGEST L = discrete_type_low_bound (raw_type);
- LONGEST U = discrete_type_high_bound (raw_type);
+ LONGEST L = ada_discrete_type_low_bound (raw_type);
+ LONGEST U = ada_discrete_type_high_bound (raw_type);
if (L < INT_MIN || U > INT_MAX)
return raw_type;
else
return create_range_type (alloc_type_copy (orig_type), raw_type,
- discrete_type_low_bound (raw_type),
- discrete_type_high_bound (raw_type));
+ ada_discrete_type_low_bound (raw_type),
+ ada_discrete_type_high_bound (raw_type));
}
else
{
@@ -9972,20 +9959,7 @@ ada_modulus_from_name (struct type *type
ULONGEST
ada_modulus (struct type *type)
{
- ULONGEST modulus;
-
- /* Normally, the modulus of a modular type is equal to the value of
- its upper bound + 1. However, the upper bound is currently stored
- as an int, which is not always big enough to hold the actual bound
- value. To workaround this, try to take advantage of the encoding
- that GNAT uses with with discrete types. To avoid some unnecessary
- parsing, we do this only when the size of TYPE is greater than
- the size of the field holding the bound. */
- if (TYPE_LENGTH (type) > sizeof (TYPE_HIGH_BOUND (type))
- && ada_modulus_from_name (type, &modulus))
- return modulus;
-
- return (ULONGEST) (unsigned int) TYPE_HIGH_BOUND (type) + 1;
+ return (ULONGEST) TYPE_HIGH_BOUND (type) + 1;
}
\f
Only in gdb.new/gdb: ada-lang.c.orig
diff -upr gdb.old/gdb/ada-lang.h gdb.new/gdb/ada-lang.h
--- gdb.old/gdb/ada-lang.h 2009-11-19 14:42:48.000000000 -0800
+++ gdb.new/gdb/ada-lang.h 2009-12-11 01:39:05.000000000 -0800
@@ -199,6 +199,10 @@ extern int ada_is_array_descriptor_type
extern int ada_is_bogus_array_descriptor (struct type *);
+extern LONGEST ada_discrete_type_low_bound (struct type *);
+
+extern LONGEST ada_discrete_type_high_bound (struct type *);
+
extern char *ada_decode_symbol (const struct general_symbol_info*);
extern const char *ada_decode (const char*);
diff -upr gdb.old/gdb/ada-typeprint.c gdb.new/gdb/ada-typeprint.c
--- gdb.old/gdb/ada-typeprint.c 2009-11-19 14:42:48.000000000 -0800
+++ gdb.new/gdb/ada-typeprint.c 2009-12-11 01:39:05.000000000 -0800
@@ -114,53 +114,32 @@ decoded_type_name (struct type *type)
}
}
-/* Print range type TYPE on STREAM. */
+/* Print TYPE on STREAM, preferably as a range. */
static void
print_range (struct type *type, struct ui_file *stream)
{
- struct type *target_type;
- target_type = TYPE_TARGET_TYPE (type);
- if (target_type == NULL)
- target_type = type;
-
- switch (TYPE_CODE (target_type))
+ switch (TYPE_CODE (type))
{
case TYPE_CODE_RANGE:
- case TYPE_CODE_INT:
- case TYPE_CODE_BOOL:
- case TYPE_CODE_CHAR:
case TYPE_CODE_ENUM:
+ {
+ struct type *target_type;
+ target_type = TYPE_TARGET_TYPE (type);
+ if (target_type == NULL)
+ target_type = type;
+ ada_print_scalar (target_type, ada_discrete_type_low_bound (type),
+ stream);
+ fprintf_filtered (stream, " .. ");
+ ada_print_scalar (target_type, ada_discrete_type_high_bound (type),
+ stream);
+ }
break;
default:
- target_type = NULL;
- break;
- }
-
- if (TYPE_NFIELDS (type) < 2)
- {
- /* A range needs at least 2 bounds to be printed. If there are less
- than 2, just print the type name instead of the range itself.
- This check handles cases such as characters, for example.
-
- If the name is not defined, then we don't print anything.
- */
fprintf_filtered (stream, "%.*s",
ada_name_prefix_len (TYPE_NAME (type)),
TYPE_NAME (type));
- }
- else
- {
- /* We extract the range type bounds respectively from the first element
- and the last element of the type->fields array */
- const LONGEST lower_bound = (LONGEST) TYPE_LOW_BOUND (type);
- const LONGEST upper_bound = (TYPE_CODE (type) == TYPE_CODE_RANGE
- ? (LONGEST) TYPE_HIGH_BOUND (type)
- : (LONGEST) TYPE_FIELD_BITPOS (type, TYPE_NFIELDS (type) - 1));
-
- ada_print_scalar (target_type, lower_bound, stream);
- fprintf_filtered (stream, " .. ");
- ada_print_scalar (target_type, upper_bound, stream);
+ break;
}
}
2009-12-10 Michael Snyder <msnyder@vmware.com>
* i386-tdep.c (i386_record_lea_modrm_addr): Indent goto label.
Only in gdb.new/gdb: ChangeLog.orig
Only in gdb.new/gdb: ChangeLog.rej
diff -upr gdb.old/gdb/dwarf2read.c gdb.new/gdb/dwarf2read.c
--- gdb.old/gdb/dwarf2read.c 2009-12-02 03:44:35.000000000 -0800
+++ gdb.new/gdb/dwarf2read.c 2009-12-11 01:39:05.000000000 -0800
@@ -549,8 +549,8 @@ struct attribute
{
char *str;
struct dwarf_block *blk;
- unsigned long unsnd;
- long int snd;
+ ULONGEST unsnd;
+ LONGEST snd;
CORE_ADDR addr;
struct signatured_type *signatured_type;
}
@@ -1065,7 +1065,7 @@ static int is_ref_attr (struct attribute
static unsigned int dwarf2_get_ref_die_offset (struct attribute *);
-static int dwarf2_get_attr_constant_value (struct attribute *, int);
+static LONGEST dwarf2_get_attr_constant_value (struct attribute *, int);
static struct die_info *follow_die_ref_or_sig (struct die_info *,
struct attribute *,
@@ -6041,9 +6041,10 @@ read_subrange_type (struct die_info *die
struct type *base_type;
struct type *range_type;
struct attribute *attr;
- int low = 0;
- int high = -1;
+ LONGEST low = 0;
+ LONGEST high = -1;
char *name;
+ LONGEST negative_mask;
base_type = die_type (die, cu);
if (TYPE_CODE (base_type) == TYPE_CODE_VOID)
@@ -6090,6 +6091,13 @@ read_subrange_type (struct die_info *die
high = dwarf2_get_attr_constant_value (attr, 1);
}
+ negative_mask =
+ (LONGEST) -1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1);
+ if (!TYPE_UNSIGNED (base_type) && (low & negative_mask))
+ low |= negative_mask;
+ if (!TYPE_UNSIGNED (base_type) && (high & negative_mask))
+ high |= negative_mask;
+
range_type = create_range_type (NULL, base_type, low, high);
name = dwarf2_name (die, cu);
@@ -7127,8 +7135,8 @@ read_attribute_value (struct attribute *
{
complaint
(&symfile_complaints,
- _("Suspicious DW_AT_byte_size value treated as zero instead of 0x%lx"),
- DW_UNSND (attr));
+ _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
+ hex_string (DW_UNSND (attr)));
DW_UNSND (attr) = 0;
}
@@ -10107,7 +10115,8 @@ dump_die_shallow (struct ui_file *f, int
case DW_FORM_data8:
case DW_FORM_udata:
case DW_FORM_sdata:
- fprintf_unfiltered (f, "constant: %ld", DW_UNSND (&die->attrs[i]));
+ fprintf_unfiltered (f, "constant: %s",
+ pulongest (DW_UNSND (&die->attrs[i])));
break;
case DW_FORM_sig8:
if (DW_SIGNATURED_TYPE (&die->attrs[i]) != NULL)
@@ -10230,10 +10239,10 @@ dwarf2_get_ref_die_offset (struct attrib
return 0;
}
-/* Return the constant value held by the given attribute. Return -1
- if the value held by the attribute is not constant. */
+/* Return the constant value held by ATTR. Return DEFAULT_VALUE if
+ * the value held by the attribute is not constant. */
-static int
+static LONGEST
dwarf2_get_attr_constant_value (struct attribute *attr, int default_value)
{
if (attr->form == DW_FORM_sdata)
Only in gdb.new/gdb: dwarf2read.c.orig
diff -upr gdb.old/gdb/gdbtypes.c gdb.new/gdb/gdbtypes.c
--- gdb.old/gdb/gdbtypes.c 2009-11-12 11:47:25.000000000 -0800
+++ gdb.new/gdb/gdbtypes.c 2009-12-11 01:39:05.000000000 -0800
@@ -711,7 +711,7 @@ allocate_stub_method (struct type *type)
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);
@@ -721,10 +721,8 @@ create_range_type (struct type *result_t
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;
@@ -1475,17 +1473,34 @@ 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. FIXME: pnh/2009-12-07. */
+ 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)
@@ -2737,6 +2752,14 @@ recursive_dump_type (struct type *type,
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");
@@ -2925,6 +2948,13 @@ copy_type_recursive (struct objfile *obj
}
}
+ /* 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) =
diff -upr gdb.old/gdb/gdbtypes.h gdb.new/gdb/gdbtypes.h
--- gdb.old/gdb/gdbtypes.h 2009-11-12 11:47:25.000000000 -0800
+++ gdb.new/gdb/gdbtypes.h 2009-12-11 01:39:05.000000000 -0800
@@ -447,61 +447,87 @@ struct main_type
because we can allocate the space for a type before
we know what to put in it. */
- struct field
+ union
{
- union field_location
+ struct field
{
- /* Position of this field, counting in bits from start of
- containing structure.
- For gdbarch_bits_big_endian=1 targets, it is the bit offset to the MSB.
- For gdbarch_bits_big_endian=0 targets, it is the bit offset to the LSB.
- For a range bound or enum value, this is the value itself. */
+ union field_location
+ {
+ /* Position of this field, counting in bits from start of
+ containing structure.
+ For gdbarch_bits_big_endian=1 targets, it is the bit offset to the MSB.
+ For gdbarch_bits_big_endian=0 targets, it is the bit offset to the LSB.
+ For a range bound or enum value, this is the value itself. */
+
+ int bitpos;
+
+ /* For a static field, if TYPE_FIELD_STATIC_HAS_ADDR then physaddr
+ is the location (in the target) of the static field.
+ Otherwise, physname is the mangled label of the static field. */
+
+ CORE_ADDR physaddr;
+ char *physname;
+
+ /* The field location can be computed by evaluating the following DWARF
+ block. This can be used in Fortran variable-length arrays, for
+ instance. */
+
+ struct dwarf2_locexpr_baton *dwarf_block;
+ }
+ loc;
- int bitpos;
+ /* For a function or member type, this is 1 if the argument is marked
+ artificial. Artificial arguments should not be shown to the
+ user. For TYPE_CODE_RANGE it is set if the specific bound is not
+ defined. */
+ unsigned int artificial : 1;
- /* For a static field, if TYPE_FIELD_STATIC_HAS_ADDR then physaddr
- is the location (in the target) of the static field.
- Otherwise, physname is the mangled label of the static field. */
+ /* Discriminant for union field_location. */
+ ENUM_BITFIELD(field_loc_kind) loc_kind : 2;
- CORE_ADDR physaddr;
- char *physname;
+ /* Size of this field, in bits, or zero if not packed.
+ If non-zero in an array type, indicates the element size in
+ bits (used only in Ada at the moment).
+ For an unpacked field, the field's type's length
+ says how many bytes the field occupies. */
- /* The field location can be computed by evaluating the following DWARF
- block. This can be used in Fortran variable-length arrays, for
- instance. */
+ unsigned int bitsize : 29;
- struct dwarf2_locexpr_baton *dwarf_block;
- }
- loc;
+ /* In a struct or union type, type of this field.
+ In a function or member type, type of this argument.
+ In an array type, the domain-type of the array. */
- /* For a function or member type, this is 1 if the argument is marked
- artificial. Artificial arguments should not be shown to the
- user. For TYPE_CODE_RANGE it is set if the specific bound is not
- defined. */
- unsigned int artificial : 1;
+ struct type *type;
- /* Discriminant for union field_location. */
- ENUM_BITFIELD(field_loc_kind) loc_kind : 2;
+ /* Name of field, value or argument.
+ NULL for range bounds, array domains, and member function
+ arguments. */
- /* Size of this field, in bits, or zero if not packed.
- For an unpacked field, the field's type's length
- says how many bytes the field occupies. */
+ char *name;
+ } *fields;
+
+ /* Union member used for range types. */
+
+ struct range_bounds
+ {
+ /* Low bound of range. */
- unsigned int bitsize : 29;
+ LONGEST low;
- /* In a struct or union type, type of this field.
- In a function or member type, type of this argument.
- In an array type, the domain-type of the array. */
+ /* High bound of range. */
- struct type *type;
+ LONGEST high;
- /* Name of field, value or argument.
- NULL for range bounds, array domains, and member function
- arguments. */
+ /* Flags indicating whether the values of low and high are
+ valid. When true, the respective range value is
+ undefined. Currently used only for FORTRAN arrays. */
+
+ char low_undefined;
+ char high_undefined;
- char *name;
+ } *bounds;
- } *fields;
+ } flds_bnds;
/* For types with virtual functions (TYPE_CODE_STRUCT), VPTR_BASETYPE
is the base class which defined the virtual function table pointer.
@@ -828,19 +854,24 @@ extern void allocate_cplus_struct_type (
type, you need to do TYPE_CODE (check_type (this_type)). */
#define TYPE_CODE(thistype) TYPE_MAIN_TYPE(thistype)->code
#define TYPE_NFIELDS(thistype) TYPE_MAIN_TYPE(thistype)->nfields
-#define TYPE_FIELDS(thistype) TYPE_MAIN_TYPE(thistype)->fields
+#define TYPE_FIELDS(thistype) TYPE_MAIN_TYPE(thistype)->flds_bnds.fields
#define TYPE_TEMPLATE_ARGS(thistype) TYPE_CPLUS_SPECIFIC(thistype)->template_args
#define TYPE_INDEX_TYPE(type) TYPE_FIELD_TYPE (type, 0)
-#define TYPE_LOW_BOUND(range_type) TYPE_FIELD_BITPOS (range_type, 0)
-#define TYPE_HIGH_BOUND(range_type) TYPE_FIELD_BITPOS (range_type, 1)
+#define TYPE_RANGE_DATA(thistype) TYPE_MAIN_TYPE(thistype)->flds_bnds.bounds
+#define TYPE_LOW_BOUND(range_type) TYPE_RANGE_DATA(range_type)->low
+#define TYPE_HIGH_BOUND(range_type) TYPE_RANGE_DATA(range_type)->high
+#define TYPE_LOW_BOUND_UNDEFINED(range_type) \
+ TYPE_RANGE_DATA(range_type)->low_undefined
+#define TYPE_HIGH_BOUND_UNDEFINED(range_type) \
+ TYPE_RANGE_DATA(range_type)->high_undefined
/* Moto-specific stuff for FORTRAN arrays */
#define TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED(arraytype) \
- (TYPE_FIELD_ARTIFICIAL(TYPE_INDEX_TYPE((arraytype)),1))
+ TYPE_HIGH_BOUND_UNDEFINED(TYPE_INDEX_TYPE(arraytype))
#define TYPE_ARRAY_LOWER_BOUND_IS_UNDEFINED(arraytype) \
- (TYPE_FIELD_ARTIFICIAL(TYPE_INDEX_TYPE((arraytype)),0))
+ TYPE_LOW_BOUND_UNDEFINED(TYPE_INDEX_TYPE(arraytype))
#define TYPE_ARRAY_UPPER_BOUND_VALUE(arraytype) \
(TYPE_HIGH_BOUND(TYPE_INDEX_TYPE((arraytype))))
@@ -862,9 +893,9 @@ extern void allocate_cplus_struct_type (
#define TYPE_CPLUS_SPECIFIC(thistype) TYPE_MAIN_TYPE(thistype)->type_specific.cplus_stuff
#define TYPE_FLOATFORMAT(thistype) TYPE_MAIN_TYPE(thistype)->type_specific.floatformat
#define TYPE_CALLING_CONVENTION(thistype) TYPE_MAIN_TYPE(thistype)->type_specific.calling_convention
-#define TYPE_BASECLASS(thistype,index) TYPE_MAIN_TYPE(thistype)->fields[index].type
+#define TYPE_BASECLASS(thistype,index) TYPE_FIELD_TYPE(thistype, index)
#define TYPE_N_BASECLASSES(thistype) TYPE_CPLUS_SPECIFIC(thistype)->n_baseclasses
-#define TYPE_BASECLASS_NAME(thistype,index) TYPE_MAIN_TYPE(thistype)->fields[index].name
+#define TYPE_BASECLASS_NAME(thistype,index) TYPE_FIELD_NAME(thistype, index)
#define TYPE_BASECLASS_BITPOS(thistype,index) TYPE_FIELD_BITPOS(thistype,index)
#define BASETYPE_VIA_PUBLIC(thistype, index) \
((!TYPE_FIELD_PRIVATE(thistype, index)) && (!TYPE_FIELD_PROTECTED(thistype, index)))
@@ -896,7 +927,7 @@ extern void allocate_cplus_struct_type (
#define FIELD_ARTIFICIAL(thisfld) ((thisfld).artificial)
#define FIELD_BITSIZE(thisfld) ((thisfld).bitsize)
-#define TYPE_FIELD(thistype, n) TYPE_MAIN_TYPE(thistype)->fields[n]
+#define TYPE_FIELD(thistype, n) TYPE_MAIN_TYPE(thistype)->flds_bnds.fields[n]
#define TYPE_FIELD_TYPE(thistype, n) FIELD_TYPE(TYPE_FIELD(thistype, n))
#define TYPE_FIELD_NAME(thistype, n) FIELD_NAME(TYPE_FIELD(thistype, n))
#define TYPE_FIELD_LOC_KIND(thistype, n) FIELD_LOC_KIND (TYPE_FIELD (thistype, n))
@@ -1227,8 +1258,8 @@ extern struct type *make_function_type (
extern struct type *lookup_function_type (struct type *);
-extern struct type *create_range_type (struct type *, struct type *, int,
- int);
+extern struct type *create_range_type (struct type *, struct type *, LONGEST,
+ LONGEST);
extern struct type *create_array_type (struct type *, struct type *,
struct type *);
diff -upr gdb.old/gdb/mdebugread.c gdb.new/gdb/mdebugread.c
--- gdb.old/gdb/mdebugread.c 2009-11-16 10:40:22.000000000 -0800
+++ gdb.new/gdb/mdebugread.c 2009-12-11 01:39:05.000000000 -0800
@@ -1743,13 +1743,11 @@ parse_type (int fd, union aux_ext *ax, u
/* Deal with range types */
if (t->bt == btRange)
{
- TYPE_NFIELDS (tp) = 2;
- TYPE_FIELDS (tp) = ((struct field *)
- TYPE_ALLOC (tp, 2 * sizeof (struct field)));
- TYPE_FIELD_NAME (tp, 0) = "Low";
+ TYPE_NFIELDS (tp) = 0;
+ TYPE_RANGE_DATA (tp) = ((struct range_bounds *)
+ TYPE_ZALLOC (tp, sizeof (struct range_bounds)));
TYPE_LOW_BOUND (tp) = AUX_GET_DNLOW (bigend, ax);
ax++;
- TYPE_FIELD_NAME (tp, 1) = "High";
TYPE_HIGH_BOUND (tp) = AUX_GET_DNHIGH (bigend, ax);
ax++;
}
diff -upr gdb.old/gdb/p-typeprint.c gdb.new/gdb/p-typeprint.c
--- gdb.old/gdb/p-typeprint.c 2009-07-02 05:16:56.000000000 -0700
+++ gdb.new/gdb/p-typeprint.c 2009-12-11 01:39:05.000000000 -0800
@@ -267,10 +267,9 @@ pascal_type_print_varspec_prefix (struct
fprintf_filtered (stream, "array ");
if (TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0
&& !TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type))
- fprintf_filtered (stream, "[%d..%d] ",
- TYPE_ARRAY_LOWER_BOUND_VALUE (type),
- TYPE_ARRAY_UPPER_BOUND_VALUE (type)
- );
+ fprintf_filtered (stream, "[%s..%s] ",
+ plongest (TYPE_ARRAY_LOWER_BOUND_VALUE (type)),
+ plongest (TYPE_ARRAY_UPPER_BOUND_VALUE (type)));
fprintf_filtered (stream, "of ");
break;
diff -upr gdb.old/gdb/varobj.c gdb.new/gdb/varobj.c
--- gdb.old/gdb/varobj.c 2009-11-12 11:47:25.000000000 -0800
+++ gdb.new/gdb/varobj.c 2009-12-11 01:39:05.000000000 -0800
@@ -2793,8 +2793,9 @@ c_describe_child (struct varobj *parent,
{
case TYPE_CODE_ARRAY:
if (cname)
- *cname = xstrprintf ("%d", index
- + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)));
+ *cname = xstrdup (int_string (index
+ + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)),
+ 10, 1, 0, 0));
if (cvalue && value)
{
@@ -2806,9 +2807,11 @@ c_describe_child (struct varobj *parent,
*ctype = get_target_type (type);
if (cfull_expression)
- *cfull_expression = xstrprintf ("(%s)[%d]", parent_expression,
- index
- + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)));
+ *cfull_expression =
+ xstrprintf ("(%s)[%s]", parent_expression,
+ int_string (index
+ + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)),
+ 10, 1, 0, 0));
break;
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [RFA] 64-bit range types in GDB
2009-12-11 10:03 ` Paul Hilfinger
@ 2009-12-11 19:06 ` Tom Tromey
2009-12-14 6:24 ` [COMMIT] " Paul Hilfinger
0 siblings, 1 reply; 8+ messages in thread
From: Tom Tromey @ 2009-12-11 19:06 UTC (permalink / raw)
To: Hilfinger; +Cc: gdb-patches, brobecker
>>>>> "Paul" == Paul Hilfinger <Hilfinger@adacore.com> writes:
Paul> Here is the 64-bit range patch, revised per Tom's suggestions.
Paul> For now, I have eliminated the fixup_range_type_hack routine until
Paul> such time if ever that I find the failing cases that required
Paul> it. (Besides which, I see that the first patch didn't (ahem)
Paul> bother to call it anyway).
:-)
Paul> In check_typedef, I have handled the overflow situation by setting the
Paul> array length to 0. I decided against using UINT_MAX given the likely
Paul> consequences of having such a value actually used to allocate a value
Paul> structure.
Thanks.
Paul> OK to commit?
One nit...
Paul> + /* For now, we conservatively take the array length to be 0
Paul> + * if its length exceeds UINT_MAX. The code below assumes
Paul> + * that for x < 0, (ULONGEST) x == -x + ULONGEST_MAX + 1,
Paul> + * which is technically not guaranteed by C, but is usually true
Paul> + * (because it would be true if x were unsigned with its
Paul> + * high-order bit on). It uses the fact that
Paul> + * high_bound-low_bound is always representable in
Paul> + * ULONGEST and that if high_bound-low_bound+1 overflows,
Paul> + * it overflows to 0. We must change these tests if we
Paul> + * decide to increase the representation of TYPE_LENGTH
Paul> + * from unsigned int to ULONGEST. FIXME: pnh/2009-12-07. */
The GNU style is not to put a "*" at the start of each line. Also we
currently eschew new FIXME comments. I think you could just remove the
FIXME. I personally also am not in favor of putting one's initials in
comments -- gdb has several such comments where I have no clue at all
who the person might be.
Ok with that change.
Tom
^ permalink raw reply [flat|nested] 8+ messages in thread
* [COMMIT] 64-bit range types in GDB
2009-12-11 19:06 ` Tom Tromey
@ 2009-12-14 6:24 ` Paul Hilfinger
0 siblings, 0 replies; 8+ messages in thread
From: Paul Hilfinger @ 2009-12-14 6:24 UTC (permalink / raw)
To: tromey; +Cc: Hilfinger, gdb-patches, brobecker
I have made the comment changes Tom requested and committed. Thanks, Tom,
for your quick reviews.
Paul Hilfinger
AdaCore, Inc.
2009-12-13 Paul N. Hilfinger <hilfinger@adacore.com>
* dwarf2read.c (struct attribute): Increase sizes of unsnd and snd
fields to allow larger integer sizes.
(read_subrange_type): Increase size of bound values.
Add logic to determine signedness based on base-type size, signedness.
(read_attribute_value): Change format for bad byte size in message.
(read_8_bytes): Increase size of result type.
(dump_die_shallow): Change format for value.
(dwarf2_get_attr_constant_value): Increase size of return type.
Correct comment.
* gdbtypes.c (create_range_type): Change API to increase size of
bounds. struct field -> union field.
Always take signedness from base type.
(check_typedef): Use new API for TYPE_LOW_BOUND, TYPE_HIGH_BOUND.
(recursive_dump_type, copy_type_recursive): Adjust to new
representation of range types.
* gdbtypes.h (fields_or_bounds): New union containing struct field and
new struct range_bounds, used for range types.
(TYPE_RANGE_DATA): New macro to access range_bounds member.
(TYPE_LOW_BOUND, TYPE_HIGH_BOUND): Represent with new TYPE_RANGE_DATA.
(TYPE_LOW_BOUND_UNDEFINED, TYPE_HIGH_BOUND_UNDEFINED): New macros,
taking over the job of TYPE_FIELD_ARTIFICIAL for range bounds.
(SET_TYPE_LOW_BOUND, SET_TYPE_HIGH_BOUND, SET_TYPE_LOW_BOUND_DEFINED)
(SET_TYPE_HIGH_BOUND_DEFINED): New macros.
(TYPE_FIELDS, TYPE_BASECLASS, TYPE_BASECLASS_NAME, TYPE_FIELD)
(TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED)
(TYPE_ARRAY_LOWER_BOUND_IS_UNDEFINED, TYPE_ARRAY_UPPER_BOUND_VALUE)
(TYPE_ARRAY_LOWER_BOUND_VALUE): Adjust to new representation.
(create_range_type): Adjust API.
* ada-lang.c (ada_modulus): Use new extended bound values.
(discrete_type_low_bound): Rename to...
(ada_discrete_type_low_bound): ... and make external.
(discrete_type_high_bound): Rename to...
(ada_discrete_type_high_bound): ... and make external.
(ada_value_slice_from_ptr, ada_array_bound_from_type)
(ada_evaluate_subexp, to_fixed_range_type):
Use ada_discrete_type_low_bound, ada_discrete_type_high_bound.
* ada-typeprint.c (print_range): Use ada_discrete_type_low_bound,
ada_discrete_type_high_bound. Don't look at field count, which
is no longer meaningful. Print bounds whenever argument is a range
or enumeration.
* ada-lang.h (ada_discrete_type_low_bound,ada_discrete_type_high_bound):
Declare.
* varobj.c (c_describe_child): Adjust to render larger values.
* mdebugread.c (parse_type): Use proper abstractions for range types:
TYPE_RANGE_DATA, SET_TYPE_LOW_BOUND_DEFINED,
SET_TYPE_HIGH_BOUND_DEFINED.
* p-typeprint.c (pascal_type_print_varspec_prefix): Use larger format
for bounds.
diff -r -up --exclude CVS --exclude .rej gdb-curr/gdb/ada-lang.c gdb.new/gdb/ada-lang.c
--- gdb-curr/gdb/ada-lang.c 2009-12-02 11:29:41.000000000 -0800
+++ gdb.new/gdb/ada-lang.c 2009-12-13 19:59:20.000000000 -0800
@@ -597,8 +597,8 @@ min_of_type (struct type *t)
}
/* The largest value in the domain of TYPE, a discrete type, as an integer. */
-static LONGEST
-discrete_type_high_bound (struct type *type)
+LONGEST
+ada_discrete_type_high_bound (struct type *type)
{
switch (TYPE_CODE (type))
{
@@ -612,13 +612,13 @@ discrete_type_high_bound (struct type *t
case TYPE_CODE_INT:
return max_of_type (type);
default:
- error (_("Unexpected type in discrete_type_high_bound."));
+ error (_("Unexpected type in ada_discrete_type_high_bound."));
}
}
/* The largest value in the domain of TYPE, a discrete type, as an integer. */
-static LONGEST
-discrete_type_low_bound (struct type *type)
+LONGEST
+ada_discrete_type_low_bound (struct type *type)
{
switch (TYPE_CODE (type))
{
@@ -632,7 +632,7 @@ discrete_type_low_bound (struct type *ty
case TYPE_CODE_INT:
return min_of_type (type);
default:
- error (_("Unexpected type in discrete_type_low_bound."));
+ error (_("Unexpected type in ada_discrete_type_low_bound."));
}
}
@@ -2399,7 +2399,7 @@ ada_value_slice_from_ptr (struct value *
int low, int high)
{
CORE_ADDR base = value_as_address (array_ptr)
- + ((low - TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)))
+ + ((low - ada_discrete_type_low_bound (TYPE_INDEX_TYPE (type)))
* TYPE_LENGTH (TYPE_TARGET_TYPE (type)));
struct type *index_type =
create_range_type (NULL, TYPE_TARGET_TYPE (TYPE_INDEX_TYPE (type)),
@@ -2542,7 +2542,6 @@ static LONGEST
ada_array_bound_from_type (struct type * arr_type, int n, int which)
{
struct type *type, *elt_type, *index_type_desc, *index_type;
- LONGEST retval;
int i;
gdb_assert (which == 0 || which == 1);
@@ -2569,22 +2568,10 @@ ada_array_bound_from_type (struct type *
else
index_type = TYPE_INDEX_TYPE (elt_type);
- switch (TYPE_CODE (index_type))
- {
- case TYPE_CODE_RANGE:
- retval = which == 0 ? TYPE_LOW_BOUND (index_type)
- : TYPE_HIGH_BOUND (index_type);
- break;
- case TYPE_CODE_ENUM:
- retval = which == 0 ? TYPE_FIELD_BITPOS (index_type, 0)
- : TYPE_FIELD_BITPOS (index_type,
- TYPE_NFIELDS (index_type) - 1);
- break;
- default:
- internal_error (__FILE__, __LINE__, _("invalid type code of index type"));
- }
-
- return retval;
+ return
+ (LONGEST) (which == 0
+ ? ada_discrete_type_low_bound (index_type)
+ : ada_discrete_type_high_bound (index_type));
}
/* Given that arr is an array value, returns the lower bound of the
@@ -9262,10 +9249,10 @@ ada_evaluate_subexp (struct type *expect
error (_("unexpected attribute encountered"));
case OP_ATR_FIRST:
return value_from_longest
- (range_type, discrete_type_low_bound (range_type));
+ (range_type, ada_discrete_type_low_bound (range_type));
case OP_ATR_LAST:
return value_from_longest
- (range_type, discrete_type_high_bound (range_type));
+ (range_type, ada_discrete_type_high_bound (range_type));
case OP_ATR_LENGTH:
error (_("the 'length attribute applies only to array types"));
}
@@ -9839,14 +9826,14 @@ to_fixed_range_type (char *name, struct
subtype_info = strstr (name, "___XD");
if (subtype_info == NULL)
{
- LONGEST L = discrete_type_low_bound (raw_type);
- LONGEST U = discrete_type_high_bound (raw_type);
+ LONGEST L = ada_discrete_type_low_bound (raw_type);
+ LONGEST U = ada_discrete_type_high_bound (raw_type);
if (L < INT_MIN || U > INT_MAX)
return raw_type;
else
return create_range_type (alloc_type_copy (orig_type), raw_type,
- discrete_type_low_bound (raw_type),
- discrete_type_high_bound (raw_type));
+ ada_discrete_type_low_bound (raw_type),
+ ada_discrete_type_high_bound (raw_type));
}
else
{
@@ -9972,20 +9959,7 @@ ada_modulus_from_name (struct type *type
ULONGEST
ada_modulus (struct type *type)
{
- ULONGEST modulus;
-
- /* Normally, the modulus of a modular type is equal to the value of
- its upper bound + 1. However, the upper bound is currently stored
- as an int, which is not always big enough to hold the actual bound
- value. To workaround this, try to take advantage of the encoding
- that GNAT uses with with discrete types. To avoid some unnecessary
- parsing, we do this only when the size of TYPE is greater than
- the size of the field holding the bound. */
- if (TYPE_LENGTH (type) > sizeof (TYPE_HIGH_BOUND (type))
- && ada_modulus_from_name (type, &modulus))
- return modulus;
-
- return (ULONGEST) (unsigned int) TYPE_HIGH_BOUND (type) + 1;
+ return (ULONGEST) TYPE_HIGH_BOUND (type) + 1;
}
\f
Only in gdb.new/gdb: ada-lang.c.orig
diff -r -up --exclude CVS --exclude .rej gdb-curr/gdb/ada-lang.h gdb.new/gdb/ada-lang.h
--- gdb-curr/gdb/ada-lang.h 2009-11-19 14:42:48.000000000 -0800
+++ gdb.new/gdb/ada-lang.h 2009-12-13 19:59:20.000000000 -0800
@@ -199,6 +199,10 @@ extern int ada_is_array_descriptor_type
extern int ada_is_bogus_array_descriptor (struct type *);
+extern LONGEST ada_discrete_type_low_bound (struct type *);
+
+extern LONGEST ada_discrete_type_high_bound (struct type *);
+
extern char *ada_decode_symbol (const struct general_symbol_info*);
extern const char *ada_decode (const char*);
diff -r -up --exclude CVS --exclude .rej gdb-curr/gdb/ada-typeprint.c gdb.new/gdb/ada-typeprint.c
--- gdb-curr/gdb/ada-typeprint.c 2009-11-19 14:42:48.000000000 -0800
+++ gdb.new/gdb/ada-typeprint.c 2009-12-13 19:59:20.000000000 -0800
@@ -114,53 +114,32 @@ decoded_type_name (struct type *type)
}
}
-/* Print range type TYPE on STREAM. */
+/* Print TYPE on STREAM, preferably as a range. */
static void
print_range (struct type *type, struct ui_file *stream)
{
- struct type *target_type;
- target_type = TYPE_TARGET_TYPE (type);
- if (target_type == NULL)
- target_type = type;
-
- switch (TYPE_CODE (target_type))
+ switch (TYPE_CODE (type))
{
case TYPE_CODE_RANGE:
- case TYPE_CODE_INT:
- case TYPE_CODE_BOOL:
- case TYPE_CODE_CHAR:
case TYPE_CODE_ENUM:
+ {
+ struct type *target_type;
+ target_type = TYPE_TARGET_TYPE (type);
+ if (target_type == NULL)
+ target_type = type;
+ ada_print_scalar (target_type, ada_discrete_type_low_bound (type),
+ stream);
+ fprintf_filtered (stream, " .. ");
+ ada_print_scalar (target_type, ada_discrete_type_high_bound (type),
+ stream);
+ }
break;
default:
- target_type = NULL;
- break;
- }
-
- if (TYPE_NFIELDS (type) < 2)
- {
- /* A range needs at least 2 bounds to be printed. If there are less
- than 2, just print the type name instead of the range itself.
- This check handles cases such as characters, for example.
-
- If the name is not defined, then we don't print anything.
- */
fprintf_filtered (stream, "%.*s",
ada_name_prefix_len (TYPE_NAME (type)),
TYPE_NAME (type));
- }
- else
- {
- /* We extract the range type bounds respectively from the first element
- and the last element of the type->fields array */
- const LONGEST lower_bound = (LONGEST) TYPE_LOW_BOUND (type);
- const LONGEST upper_bound = (TYPE_CODE (type) == TYPE_CODE_RANGE
- ? (LONGEST) TYPE_HIGH_BOUND (type)
- : (LONGEST) TYPE_FIELD_BITPOS (type, TYPE_NFIELDS (type) - 1));
-
- ada_print_scalar (target_type, lower_bound, stream);
- fprintf_filtered (stream, " .. ");
- ada_print_scalar (target_type, upper_bound, stream);
+ break;
}
}
2009-12-11 Michael Snyder <msnyder@vmware.com>
* main.c (captured_main): Indentation.
Only in gdb.new/gdb: ChangeLog.orig
Only in gdb.new/gdb: ChangeLog.rej
diff -r -up --exclude CVS --exclude .rej gdb-curr/gdb/dwarf2read.c gdb.new/gdb/dwarf2read.c
--- gdb-curr/gdb/dwarf2read.c 2009-12-02 03:44:35.000000000 -0800
+++ gdb.new/gdb/dwarf2read.c 2009-12-13 19:59:20.000000000 -0800
@@ -549,8 +549,8 @@ struct attribute
{
char *str;
struct dwarf_block *blk;
- unsigned long unsnd;
- long int snd;
+ ULONGEST unsnd;
+ LONGEST snd;
CORE_ADDR addr;
struct signatured_type *signatured_type;
}
@@ -1065,7 +1065,7 @@ static int is_ref_attr (struct attribute
static unsigned int dwarf2_get_ref_die_offset (struct attribute *);
-static int dwarf2_get_attr_constant_value (struct attribute *, int);
+static LONGEST dwarf2_get_attr_constant_value (struct attribute *, int);
static struct die_info *follow_die_ref_or_sig (struct die_info *,
struct attribute *,
@@ -6041,9 +6041,10 @@ read_subrange_type (struct die_info *die
struct type *base_type;
struct type *range_type;
struct attribute *attr;
- int low = 0;
- int high = -1;
+ LONGEST low = 0;
+ LONGEST high = -1;
char *name;
+ LONGEST negative_mask;
base_type = die_type (die, cu);
if (TYPE_CODE (base_type) == TYPE_CODE_VOID)
@@ -6090,6 +6091,13 @@ read_subrange_type (struct die_info *die
high = dwarf2_get_attr_constant_value (attr, 1);
}
+ negative_mask =
+ (LONGEST) -1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1);
+ if (!TYPE_UNSIGNED (base_type) && (low & negative_mask))
+ low |= negative_mask;
+ if (!TYPE_UNSIGNED (base_type) && (high & negative_mask))
+ high |= negative_mask;
+
range_type = create_range_type (NULL, base_type, low, high);
name = dwarf2_name (die, cu);
@@ -7127,8 +7135,8 @@ read_attribute_value (struct attribute *
{
complaint
(&symfile_complaints,
- _("Suspicious DW_AT_byte_size value treated as zero instead of 0x%lx"),
- DW_UNSND (attr));
+ _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
+ hex_string (DW_UNSND (attr)));
DW_UNSND (attr) = 0;
}
@@ -10107,7 +10115,8 @@ dump_die_shallow (struct ui_file *f, int
case DW_FORM_data8:
case DW_FORM_udata:
case DW_FORM_sdata:
- fprintf_unfiltered (f, "constant: %ld", DW_UNSND (&die->attrs[i]));
+ fprintf_unfiltered (f, "constant: %s",
+ pulongest (DW_UNSND (&die->attrs[i])));
break;
case DW_FORM_sig8:
if (DW_SIGNATURED_TYPE (&die->attrs[i]) != NULL)
@@ -10230,10 +10239,10 @@ dwarf2_get_ref_die_offset (struct attrib
return 0;
}
-/* Return the constant value held by the given attribute. Return -1
- if the value held by the attribute is not constant. */
+/* Return the constant value held by ATTR. Return DEFAULT_VALUE if
+ * the value held by the attribute is not constant. */
-static int
+static LONGEST
dwarf2_get_attr_constant_value (struct attribute *attr, int default_value)
{
if (attr->form == DW_FORM_sdata)
Only in gdb.new/gdb: dwarf2read.c.orig
diff -r -up --exclude CVS --exclude .rej gdb-curr/gdb/gdbtypes.c gdb.new/gdb/gdbtypes.c
--- gdb-curr/gdb/gdbtypes.c 2009-11-12 11:47:25.000000000 -0800
+++ gdb.new/gdb/gdbtypes.c 2009-12-13 19:59:20.000000000 -0800
@@ -711,7 +711,7 @@ allocate_stub_method (struct type *type)
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);
@@ -721,10 +721,8 @@ create_range_type (struct type *result_t
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;
@@ -1475,17 +1473,34 @@ 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)
@@ -2737,6 +2752,14 @@ recursive_dump_type (struct type *type,
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");
@@ -2925,6 +2948,13 @@ copy_type_recursive (struct objfile *obj
}
}
+ /* 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) =
diff -r -up --exclude CVS --exclude .rej gdb-curr/gdb/gdbtypes.h gdb.new/gdb/gdbtypes.h
--- gdb-curr/gdb/gdbtypes.h 2009-11-12 11:47:25.000000000 -0800
+++ gdb.new/gdb/gdbtypes.h 2009-12-13 19:59:20.000000000 -0800
@@ -447,61 +447,87 @@ struct main_type
because we can allocate the space for a type before
we know what to put in it. */
- struct field
+ union
{
- union field_location
+ struct field
{
- /* Position of this field, counting in bits from start of
- containing structure.
- For gdbarch_bits_big_endian=1 targets, it is the bit offset to the MSB.
- For gdbarch_bits_big_endian=0 targets, it is the bit offset to the LSB.
- For a range bound or enum value, this is the value itself. */
+ union field_location
+ {
+ /* Position of this field, counting in bits from start of
+ containing structure.
+ For gdbarch_bits_big_endian=1 targets, it is the bit offset to the MSB.
+ For gdbarch_bits_big_endian=0 targets, it is the bit offset to the LSB.
+ For a range bound or enum value, this is the value itself. */
+
+ int bitpos;
+
+ /* For a static field, if TYPE_FIELD_STATIC_HAS_ADDR then physaddr
+ is the location (in the target) of the static field.
+ Otherwise, physname is the mangled label of the static field. */
+
+ CORE_ADDR physaddr;
+ char *physname;
+
+ /* The field location can be computed by evaluating the following DWARF
+ block. This can be used in Fortran variable-length arrays, for
+ instance. */
+
+ struct dwarf2_locexpr_baton *dwarf_block;
+ }
+ loc;
- int bitpos;
+ /* For a function or member type, this is 1 if the argument is marked
+ artificial. Artificial arguments should not be shown to the
+ user. For TYPE_CODE_RANGE it is set if the specific bound is not
+ defined. */
+ unsigned int artificial : 1;
- /* For a static field, if TYPE_FIELD_STATIC_HAS_ADDR then physaddr
- is the location (in the target) of the static field.
- Otherwise, physname is the mangled label of the static field. */
+ /* Discriminant for union field_location. */
+ ENUM_BITFIELD(field_loc_kind) loc_kind : 2;
- CORE_ADDR physaddr;
- char *physname;
+ /* Size of this field, in bits, or zero if not packed.
+ If non-zero in an array type, indicates the element size in
+ bits (used only in Ada at the moment).
+ For an unpacked field, the field's type's length
+ says how many bytes the field occupies. */
- /* The field location can be computed by evaluating the following DWARF
- block. This can be used in Fortran variable-length arrays, for
- instance. */
+ unsigned int bitsize : 29;
- struct dwarf2_locexpr_baton *dwarf_block;
- }
- loc;
+ /* In a struct or union type, type of this field.
+ In a function or member type, type of this argument.
+ In an array type, the domain-type of the array. */
- /* For a function or member type, this is 1 if the argument is marked
- artificial. Artificial arguments should not be shown to the
- user. For TYPE_CODE_RANGE it is set if the specific bound is not
- defined. */
- unsigned int artificial : 1;
+ struct type *type;
- /* Discriminant for union field_location. */
- ENUM_BITFIELD(field_loc_kind) loc_kind : 2;
+ /* Name of field, value or argument.
+ NULL for range bounds, array domains, and member function
+ arguments. */
- /* Size of this field, in bits, or zero if not packed.
- For an unpacked field, the field's type's length
- says how many bytes the field occupies. */
+ char *name;
+ } *fields;
+
+ /* Union member used for range types. */
+
+ struct range_bounds
+ {
+ /* Low bound of range. */
- unsigned int bitsize : 29;
+ LONGEST low;
- /* In a struct or union type, type of this field.
- In a function or member type, type of this argument.
- In an array type, the domain-type of the array. */
+ /* High bound of range. */
- struct type *type;
+ LONGEST high;
- /* Name of field, value or argument.
- NULL for range bounds, array domains, and member function
- arguments. */
+ /* Flags indicating whether the values of low and high are
+ valid. When true, the respective range value is
+ undefined. Currently used only for FORTRAN arrays. */
+
+ char low_undefined;
+ char high_undefined;
- char *name;
+ } *bounds;
- } *fields;
+ } flds_bnds;
/* For types with virtual functions (TYPE_CODE_STRUCT), VPTR_BASETYPE
is the base class which defined the virtual function table pointer.
@@ -828,19 +854,24 @@ extern void allocate_cplus_struct_type (
type, you need to do TYPE_CODE (check_type (this_type)). */
#define TYPE_CODE(thistype) TYPE_MAIN_TYPE(thistype)->code
#define TYPE_NFIELDS(thistype) TYPE_MAIN_TYPE(thistype)->nfields
-#define TYPE_FIELDS(thistype) TYPE_MAIN_TYPE(thistype)->fields
+#define TYPE_FIELDS(thistype) TYPE_MAIN_TYPE(thistype)->flds_bnds.fields
#define TYPE_TEMPLATE_ARGS(thistype) TYPE_CPLUS_SPECIFIC(thistype)->template_args
#define TYPE_INDEX_TYPE(type) TYPE_FIELD_TYPE (type, 0)
-#define TYPE_LOW_BOUND(range_type) TYPE_FIELD_BITPOS (range_type, 0)
-#define TYPE_HIGH_BOUND(range_type) TYPE_FIELD_BITPOS (range_type, 1)
+#define TYPE_RANGE_DATA(thistype) TYPE_MAIN_TYPE(thistype)->flds_bnds.bounds
+#define TYPE_LOW_BOUND(range_type) TYPE_RANGE_DATA(range_type)->low
+#define TYPE_HIGH_BOUND(range_type) TYPE_RANGE_DATA(range_type)->high
+#define TYPE_LOW_BOUND_UNDEFINED(range_type) \
+ TYPE_RANGE_DATA(range_type)->low_undefined
+#define TYPE_HIGH_BOUND_UNDEFINED(range_type) \
+ TYPE_RANGE_DATA(range_type)->high_undefined
/* Moto-specific stuff for FORTRAN arrays */
#define TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED(arraytype) \
- (TYPE_FIELD_ARTIFICIAL(TYPE_INDEX_TYPE((arraytype)),1))
+ TYPE_HIGH_BOUND_UNDEFINED(TYPE_INDEX_TYPE(arraytype))
#define TYPE_ARRAY_LOWER_BOUND_IS_UNDEFINED(arraytype) \
- (TYPE_FIELD_ARTIFICIAL(TYPE_INDEX_TYPE((arraytype)),0))
+ TYPE_LOW_BOUND_UNDEFINED(TYPE_INDEX_TYPE(arraytype))
#define TYPE_ARRAY_UPPER_BOUND_VALUE(arraytype) \
(TYPE_HIGH_BOUND(TYPE_INDEX_TYPE((arraytype))))
@@ -862,9 +893,9 @@ extern void allocate_cplus_struct_type (
#define TYPE_CPLUS_SPECIFIC(thistype) TYPE_MAIN_TYPE(thistype)->type_specific.cplus_stuff
#define TYPE_FLOATFORMAT(thistype) TYPE_MAIN_TYPE(thistype)->type_specific.floatformat
#define TYPE_CALLING_CONVENTION(thistype) TYPE_MAIN_TYPE(thistype)->type_specific.calling_convention
-#define TYPE_BASECLASS(thistype,index) TYPE_MAIN_TYPE(thistype)->fields[index].type
+#define TYPE_BASECLASS(thistype,index) TYPE_FIELD_TYPE(thistype, index)
#define TYPE_N_BASECLASSES(thistype) TYPE_CPLUS_SPECIFIC(thistype)->n_baseclasses
-#define TYPE_BASECLASS_NAME(thistype,index) TYPE_MAIN_TYPE(thistype)->fields[index].name
+#define TYPE_BASECLASS_NAME(thistype,index) TYPE_FIELD_NAME(thistype, index)
#define TYPE_BASECLASS_BITPOS(thistype,index) TYPE_FIELD_BITPOS(thistype,index)
#define BASETYPE_VIA_PUBLIC(thistype, index) \
((!TYPE_FIELD_PRIVATE(thistype, index)) && (!TYPE_FIELD_PROTECTED(thistype, index)))
@@ -896,7 +927,7 @@ extern void allocate_cplus_struct_type (
#define FIELD_ARTIFICIAL(thisfld) ((thisfld).artificial)
#define FIELD_BITSIZE(thisfld) ((thisfld).bitsize)
-#define TYPE_FIELD(thistype, n) TYPE_MAIN_TYPE(thistype)->fields[n]
+#define TYPE_FIELD(thistype, n) TYPE_MAIN_TYPE(thistype)->flds_bnds.fields[n]
#define TYPE_FIELD_TYPE(thistype, n) FIELD_TYPE(TYPE_FIELD(thistype, n))
#define TYPE_FIELD_NAME(thistype, n) FIELD_NAME(TYPE_FIELD(thistype, n))
#define TYPE_FIELD_LOC_KIND(thistype, n) FIELD_LOC_KIND (TYPE_FIELD (thistype, n))
@@ -1227,8 +1258,8 @@ extern struct type *make_function_type (
extern struct type *lookup_function_type (struct type *);
-extern struct type *create_range_type (struct type *, struct type *, int,
- int);
+extern struct type *create_range_type (struct type *, struct type *, LONGEST,
+ LONGEST);
extern struct type *create_array_type (struct type *, struct type *,
struct type *);
diff -r -up --exclude CVS --exclude .rej gdb-curr/gdb/mdebugread.c gdb.new/gdb/mdebugread.c
--- gdb-curr/gdb/mdebugread.c 2009-11-16 10:40:22.000000000 -0800
+++ gdb.new/gdb/mdebugread.c 2009-12-13 19:59:20.000000000 -0800
@@ -1743,13 +1743,11 @@ parse_type (int fd, union aux_ext *ax, u
/* Deal with range types */
if (t->bt == btRange)
{
- TYPE_NFIELDS (tp) = 2;
- TYPE_FIELDS (tp) = ((struct field *)
- TYPE_ALLOC (tp, 2 * sizeof (struct field)));
- TYPE_FIELD_NAME (tp, 0) = "Low";
+ TYPE_NFIELDS (tp) = 0;
+ TYPE_RANGE_DATA (tp) = ((struct range_bounds *)
+ TYPE_ZALLOC (tp, sizeof (struct range_bounds)));
TYPE_LOW_BOUND (tp) = AUX_GET_DNLOW (bigend, ax);
ax++;
- TYPE_FIELD_NAME (tp, 1) = "High";
TYPE_HIGH_BOUND (tp) = AUX_GET_DNHIGH (bigend, ax);
ax++;
}
diff -r -up --exclude CVS --exclude .rej gdb-curr/gdb/p-typeprint.c gdb.new/gdb/p-typeprint.c
--- gdb-curr/gdb/p-typeprint.c 2009-07-02 05:16:56.000000000 -0700
+++ gdb.new/gdb/p-typeprint.c 2009-12-13 19:59:20.000000000 -0800
@@ -267,10 +267,9 @@ pascal_type_print_varspec_prefix (struct
fprintf_filtered (stream, "array ");
if (TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0
&& !TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type))
- fprintf_filtered (stream, "[%d..%d] ",
- TYPE_ARRAY_LOWER_BOUND_VALUE (type),
- TYPE_ARRAY_UPPER_BOUND_VALUE (type)
- );
+ fprintf_filtered (stream, "[%s..%s] ",
+ plongest (TYPE_ARRAY_LOWER_BOUND_VALUE (type)),
+ plongest (TYPE_ARRAY_UPPER_BOUND_VALUE (type)));
fprintf_filtered (stream, "of ");
break;
diff -r -up --exclude CVS --exclude .rej gdb-curr/gdb/varobj.c gdb.new/gdb/varobj.c
--- gdb-curr/gdb/varobj.c 2009-11-12 11:47:25.000000000 -0800
+++ gdb.new/gdb/varobj.c 2009-12-13 19:59:20.000000000 -0800
@@ -2793,8 +2793,9 @@ c_describe_child (struct varobj *parent,
{
case TYPE_CODE_ARRAY:
if (cname)
- *cname = xstrprintf ("%d", index
- + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)));
+ *cname = xstrdup (int_string (index
+ + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)),
+ 10, 1, 0, 0));
if (cvalue && value)
{
@@ -2806,9 +2807,11 @@ c_describe_child (struct varobj *parent,
*ctype = get_target_type (type);
if (cfull_expression)
- *cfull_expression = xstrprintf ("(%s)[%d]", parent_expression,
- index
- + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)));
+ *cfull_expression =
+ xstrprintf ("(%s)[%s]", parent_expression,
+ int_string (index
+ + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)),
+ 10, 1, 0, 0));
break;
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2009-12-14 6:24 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-12-04 8:13 [RFA] 64-bit range types in GDB Paul Hilfinger
2009-12-04 18:35 ` Tom Tromey
2009-12-05 12:18 ` Paul Hilfinger
2009-12-05 16:53 ` Pierre Muller
2009-12-07 20:08 ` Tom Tromey
2009-12-11 10:03 ` Paul Hilfinger
2009-12-11 19:06 ` Tom Tromey
2009-12-14 6:24 ` [COMMIT] " Paul Hilfinger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox