diff options
author | Joel Brobecker <brobecker@adacore.com> | 2017-11-29 18:31:18 -0500 |
---|---|---|
committer | Joel Brobecker <brobecker@adacore.com> | 2017-11-29 18:32:17 -0500 |
commit | f5a91472120952bbc40f277561626b8ccdf7b194 (patch) | |
tree | 06ff31d1d560dbdcbc83cc71a4d0f1a3ab8438ce /gdb/ada-lang.c | |
parent | bd69330db86b2367aac8aac5915f1686451c9d5d (diff) | |
download | gdb-f5a91472120952bbc40f277561626b8ccdf7b194.zip gdb-f5a91472120952bbc40f277561626b8ccdf7b194.tar.gz gdb-f5a91472120952bbc40f277561626b8ccdf7b194.tar.bz2 |
preserve type length in ada-lang.c::to_fixed_range_type
This patch fixes a potential issue which was noticed by code inspection:
ada-lang.c::to_fixed_range_type uses gdbtypes.c::create_static_range_type
to create most of the range type, which relies on create_range_type to
do most of the work. The latter has the following piece of code which
sets the length of the range type to match the length of the index_type:
if (TYPE_STUB (index_type))
TYPE_TARGET_STUB (result_type) = 1;
else
TYPE_LENGTH (result_type) = TYPE_LENGTH (check_typedef (index_type));
In Ada, it is actually possible to have a range type whose size
is smaller than its base type. For instance, with:
type Unsigned2_T is range 0 .. 2 ** 16 - 1;
for Unsigned2_T'SIZE use 16;
The compiler generates the following DWARF:
.uleb128 0x3 # (DIE (0x4e) DW_TAG_subrange_type)
.byte 0x2 # DW_AT_byte_size
.byte 0 # DW_AT_lower_bound
.value 0xffff # DW_AT_upper_bound
.long .LASF64 # DW_AT_name: "try__unsigned2_t___XDLU_0__65535"
.long 0x616 # DW_AT_type
... which points to the following base type...
.uleb128 0x1d # (DIE (0x616) DW_TAG_base_type)
.byte 0x4 # DW_AT_byte_size
.byte 0x5 # DW_AT_encoding
.long .LASF57 # DW_AT_name: "try__Tunsigned2_tB"
# DW_AT_artificial
... which has a size of 4 bytes.
With a type like this one, create_range_type returns a type whose
size is 4 bytes, instead of 2, which is not what we we would normally
expect.
Currently, this function is only used to handle array index types,
so the length of the type actually does not matter and there should
not be any user-visible consequences of the current behavior. But
it seems best to plug this latent bug now, rather than wait for it
to surface....
gdb/ChangeLog:
* ada-lang.c (to_fixed_range_type): Make sure that the size
of the range type being returned is the same as the size
of the range type being fixed.
Tested on x86_64-linux, no regression.
Diffstat (limited to 'gdb/ada-lang.c')
-rw-r--r-- | gdb/ada-lang.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 38d1ce6..8e35ee6 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -11688,6 +11688,10 @@ to_fixed_range_type (struct type *raw_type, struct value *dval) type = create_static_range_type (alloc_type_copy (raw_type), base_type, L, U); + /* create_static_range_type alters the resulting type's length + to match the size of the base_type, which is not what we want. + Set it back to the original range type's length. */ + TYPE_LENGTH (type) = TYPE_LENGTH (raw_type); TYPE_NAME (type) = name; return type; } |