diff options
author | Joel Brobecker <brobecker@adacore.com> | 2018-09-08 16:49:10 -0500 |
---|---|---|
committer | Joel Brobecker <brobecker@adacore.com> | 2018-09-08 17:49:10 -0400 |
commit | 16b9eb7bfa56f060d183aa44165bf75cb3c414d8 (patch) | |
tree | efc56918db8c0036b95af9e8c5173bd415e63c79 | |
parent | d8ce91275e421dfe57aa4e79bb9a58824c155e96 (diff) | |
download | binutils-16b9eb7bfa56f060d183aa44165bf75cb3c414d8.zip binutils-16b9eb7bfa56f060d183aa44165bf75cb3c414d8.tar.gz binutils-16b9eb7bfa56f060d183aa44165bf75cb3c414d8.tar.bz2 |
(Ada) slightly incorrect bounds for type of array indexed by enum
Consider the following code:
type Enumerated is (Enum_A, Enum_B, Enum_C, Enum_Last);
type Table is array (Enumerated) of Integer;
-- Declare a variable of type Table to make sure the compiler
-- does emit the debugging information for that type.
V : Table := (others => 1);
Trying to print the type description of type Table, or of variable V
yields:
(gdb) ptype v
type = array (0 .. 3) of integer
(gdb) ptype example.table
type = array (0 .. 3) of integer
The compiler generates an XA type for the bounds...
<1><cf6>: Abbrev Number: 13 (DW_TAG_structure_type)
<cf7> DW_AT_name : example__table___XA
... whose member is described as being as:
<2><cfe>: Abbrev Number: 14 (DW_TAG_member)
<cff> DW_AT_name : example__enumerated
<d05> DW_AT_type : <0xc69>
This leads us to DIE 0xc69, which is our enumeration type:
<2><c69>: Abbrev Number: 4 (DW_TAG_enumeration_type)
<c6a> DW_AT_name : example__enumerated
Normally, for arrays, we expect a range type, rather than an enumerated
type. However, for a situation like this, where the range of the array
index is the full enumeration type, it seems like a waste to require
an extra range layer.
Instead, looking at print_range, we see that we print the bounds
of our range using the target type:
target_type = TYPE_TARGET_TYPE (type);
if (target_type == NULL)
target_type = type;
[...]
ada_print_scalar (target_type, lo, stream);
fprintf_filtered (stream, " .. ");
ada_print_scalar (target_type, hi, stream);
In this case, this causes us to use the enumerated type's subtype,
which is a plain integer type, hence the output we get. However,
there is no reason for using the target type, even in the TYPE_CODE_RANGE
situation. So this patch fixes the issue by simply printing the bounds
using the type being given, instead of its target type.
gdb/ChangeLog:
* ada-typeprint.c (print_range): Print the bounds using TYPE
rather than its TYPE_TARGET_TYPE.
A new test for this isn't necessary, as existing tests will demonstrate
this issue once a change in the compiler triggering the generation of
this type of debugging info gets pushed.
-rw-r--r-- | gdb/ChangeLog | 5 | ||||
-rw-r--r-- | gdb/ada-typeprint.c | 9 |
2 files changed, 7 insertions, 7 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 7869bc1..0f73a3e 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,10 @@ 2018-09-08 Joel Brobecker <brobecker@adacore.com> + * ada-typeprint.c (print_range): Print the bounds using TYPE + rather than its TYPE_TARGET_TYPE. + +2018-09-08 Joel Brobecker <brobecker@adacore.com> + * ada-lang.c (ada_to_fixed_value): Minor reformatting in call to ada_to_fixed_value_create. diff --git a/gdb/ada-typeprint.c b/gdb/ada-typeprint.c index 47ce897..b78654d 100644 --- a/gdb/ada-typeprint.c +++ b/gdb/ada-typeprint.c @@ -159,14 +159,9 @@ print_range (struct type *type, struct ui_file *stream, case TYPE_CODE_RANGE: case TYPE_CODE_ENUM: { - struct type *target_type; LONGEST lo = 0, hi = 0; /* init for gcc -Wall */ int got_error = 0; - target_type = TYPE_TARGET_TYPE (type); - if (target_type == NULL) - target_type = type; - TRY { lo = ada_discrete_type_low_bound (type); @@ -186,9 +181,9 @@ print_range (struct type *type, struct ui_file *stream, if (!got_error) { - ada_print_scalar (target_type, lo, stream); + ada_print_scalar (type, lo, stream); fprintf_filtered (stream, " .. "); - ada_print_scalar (target_type, hi, stream); + ada_print_scalar (type, hi, stream); } } break; |