aboutsummaryrefslogtreecommitdiff
path: root/gdb/ada-lang.c
diff options
context:
space:
mode:
authorJan Kratochvil <jan.kratochvil@redhat.com>2008-12-28 14:14:19 +0000
committerJan Kratochvil <jan.kratochvil@redhat.com>2008-12-28 14:14:19 +0000
commit262452ec451590e24be1f034f4fe7fad92eefa9a (patch)
tree0cf63a1f4f72343c4a185309e05ea66daf4dfdef /gdb/ada-lang.c
parent240ab0d8f5854feb6b7043487c57e31fa1ba9dbb (diff)
downloadgdb-262452ec451590e24be1f034f4fe7fad92eefa9a.zip
gdb-262452ec451590e24be1f034f4fe7fad92eefa9a.tar.gz
gdb-262452ec451590e24be1f034f4fe7fad92eefa9a.tar.bz2
Fix TYPE_HIGH_BOUND for TYPE_CODE_RANGE using arbitrary TYPE_NFIELDS in
preparation for supporting DW_AT_byte_stride. * ada-lang.c (packed_array_type, ada_index_type): Use TYPE_INDEX_TYPE. (ada_array_bound_from_type): Move `index_type' declaration to the function start. New variable `retval'. Return the bounds for TYPE_CODE_RANGE using TYPE_LOW_BOUND and TYPE_HIGH_BOUND. Abort on invalid index type codes. * ada-typeprint.c (print_range): Set `upper_bound' for TYPE_CODE_RANGE now using TYPE_HIGH_BOUND. * ada-valprint.c (val_print_packed_array_elements): Use `index_type'. * eval.c (evaluate_subexp_standard): Use TYPE_INDEX_TYPE. * gdbtypes.c (create_range_type): Use TYPE_LOW_BOUND, TYPE_HIGH_BOUND, refer to the number of fields only through TYPE_NFIELDS. (create_array_type): Use TYPE_INDEX_TYPE. (check_typedef): Use TYPE_INDEX_TYPE, TYPE_LOW_BOUND, TYPE_HIGH_BOUND. * gdbtypes.h (TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED) (TYPE_ARRAY_LOWER_BOUND_IS_UNDEFINED): Use TYPE_INDEX_TYPE. (TYPE_ARRAY_UPPER_BOUND_VALUE, TYPE_ARRAY_LOWER_BOUND_VALUE): Use TYPE_INDEX_TYPE, TYPE_LOW_BOUND, TYPE_HIGH_BOUND, * hppa-tdep.c (hppa_alignof <TYPE_CODE_ARRAY>): Use TYPE_INDEX_TYPE. * mdebugread.c (parse_type): Use TYPE_LOW_BOUND, TYPE_HIGH_BOUND, * valarith.c (value_bit_index): Use TYPE_INDEX_TYPE.
Diffstat (limited to 'gdb/ada-lang.c')
-rw-r--r--gdb/ada-lang.c60
1 files changed, 28 insertions, 32 deletions
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index bcbd709..71d99b0 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -1777,11 +1777,11 @@ packed_array_type (struct type *type, long *elt_bits)
new_type = alloc_type (TYPE_OBJFILE (type));
new_elt_type = packed_array_type (ada_check_typedef (TYPE_TARGET_TYPE (type)),
elt_bits);
- create_array_type (new_type, new_elt_type, TYPE_FIELD_TYPE (type, 0));
+ create_array_type (new_type, new_elt_type, TYPE_INDEX_TYPE (type));
TYPE_FIELD_BITSIZE (new_type, 0) = *elt_bits;
TYPE_NAME (new_type) = ada_type_name (type);
- if (get_discrete_bounds (TYPE_FIELD_TYPE (type, 0),
+ if (get_discrete_bounds (TYPE_INDEX_TYPE (type),
&low_bound, &high_bound) < 0)
low_bound = high_bound = 0;
if (high_bound < low_bound)
@@ -2468,7 +2468,7 @@ ada_index_type (struct type *type, int n)
for (i = 1; i < n; i += 1)
type = TYPE_TARGET_TYPE (type);
- result_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type, 0));
+ result_type = TYPE_TARGET_TYPE (TYPE_INDEX_TYPE (type));
/* FIXME: The stabs type r(0,0);bound;bound in an array type
has a target type of TYPE_CODE_UNDEF. We compensate here, but
perhaps stabsread.c would make more sense. */
@@ -2492,8 +2492,10 @@ static LONGEST
ada_array_bound_from_type (struct type * arr_type, int n, int which,
struct type ** typep)
{
- struct type *type;
- struct type *index_type_desc;
+ struct type *type, *index_type_desc, *index_type;
+ LONGEST retval;
+
+ gdb_assert (which == 0 || which == 1);
if (ada_is_packed_array_type (arr_type))
arr_type = decode_packed_array_type (arr_type);
@@ -2511,10 +2513,11 @@ ada_array_bound_from_type (struct type * arr_type, int n, int which,
type = arr_type;
index_type_desc = ada_find_parallel_type (type, "___XA");
- if (index_type_desc == NULL)
+ if (index_type_desc != NULL)
+ index_type = to_fixed_range_type (TYPE_FIELD_NAME (index_type_desc, n - 1),
+ NULL, TYPE_OBJFILE (arr_type));
+ else
{
- struct type *index_type;
-
while (n > 1)
{
type = TYPE_TARGET_TYPE (type);
@@ -2522,34 +2525,27 @@ ada_array_bound_from_type (struct type * arr_type, int n, int which,
}
index_type = TYPE_INDEX_TYPE (type);
- if (typep != NULL)
- *typep = index_type;
-
- /* The index type is either a range type or an enumerated type.
- For the range type, we have some macros that allow us to
- extract the value of the low and high bounds. But they
- do now work for enumerated types. The expressions used
- below work for both range and enum types. */
- return
- (LONGEST) (which == 0
- ? TYPE_FIELD_BITPOS (index_type, 0)
- : TYPE_FIELD_BITPOS (index_type,
- TYPE_NFIELDS (index_type) - 1));
}
- else
+
+ switch (TYPE_CODE (index_type))
{
- struct type *index_type =
- to_fixed_range_type (TYPE_FIELD_NAME (index_type_desc, n - 1),
- NULL, TYPE_OBJFILE (arr_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"));
+ }
- if (typep != NULL)
- *typep = index_type;
+ if (typep != NULL)
+ *typep = index_type;
- return
- (LONGEST) (which == 0
- ? TYPE_LOW_BOUND (index_type)
- : TYPE_HIGH_BOUND (index_type));
- }
+ return retval;
}
/* Given that arr is an array value, returns the lower bound of the