From 99b1c762c990c8488c70ad537412f1209b5610bd Mon Sep 17 00:00:00 2001 From: Joel Brobecker Date: Wed, 29 Feb 2012 19:34:40 +0000 Subject: [Ada] print packed arrays indexed by enumerated type Consider the following declarations (a packed array indexed by an enumerated type): type Color is (Black, Red, Green, Blue, White); type Full_Table is array (Color) of Boolean; pragma Pack (Full_Table); Full : Full_Table := (False, True, False, True, False); GDB is unable to print the index values correctly. It prints the enumeration's underlying value instead of the enumeration name: (gdb) p full $1 = (0 => false, true, false, true, false) (gdb) p full'first $2 = 0 And yet, it is capable of printing the correct type description: (gdb) ptype full type = array (black .. white) of boolean To get to the real index type, one has to follow the parallel XA type. We already do this for normal arrays. We can do it for this packed array as well. gdb/ChangeLog: * ada-lang.c (constrained_packed_array_type): If there is a parallel XA type, use it to determine the array index type. gdb/testsuite/ChangeLog: * gdb.ada/arrayidx.exp: Adjust expected output for p_one_two_three. * gdb.ada/enum_idx_packed: New testcase. --- gdb/ada-lang.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'gdb/ada-lang.c') diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 7243ab8..b1dbe32 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -2006,22 +2006,30 @@ constrained_packed_array_type (struct type *type, long *elt_bits) { struct type *new_elt_type; struct type *new_type; + struct type *index_type_desc; + struct type *index_type; LONGEST low_bound, high_bound; type = ada_check_typedef (type); if (TYPE_CODE (type) != TYPE_CODE_ARRAY) return type; + index_type_desc = ada_find_parallel_type (type, "___XA"); + if (index_type_desc) + index_type = to_fixed_range_type (TYPE_FIELD_TYPE (index_type_desc, 0), + NULL); + else + index_type = TYPE_INDEX_TYPE (type); + new_type = alloc_type_copy (type); new_elt_type = constrained_packed_array_type (ada_check_typedef (TYPE_TARGET_TYPE (type)), elt_bits); - create_array_type (new_type, new_elt_type, TYPE_INDEX_TYPE (type)); + create_array_type (new_type, new_elt_type, index_type); TYPE_FIELD_BITSIZE (new_type, 0) = *elt_bits; TYPE_NAME (new_type) = ada_type_name (type); - if (get_discrete_bounds (TYPE_INDEX_TYPE (type), - &low_bound, &high_bound) < 0) + if (get_discrete_bounds (index_type, &low_bound, &high_bound) < 0) low_bound = high_bound = 0; if (high_bound < low_bound) *elt_bits = TYPE_LENGTH (new_type) = 0; -- cgit v1.1