mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-06-01 20:12:01 +08:00
[Ada] Fix the evaluation of access to packed array subscript
This change is relevant only for standard DWARF (as opposed to the GNAT encodings extensions): at the time of writing it only makes a difference with GCC patches that are to be integrated: see in particular <https://gcc.gnu.org/ml/gcc-patches/2015-07/msg01364.html>. Given the following Ada declarations: type Small is mod 2 ** 6; type Array_Type is array (0 .. 9) of Small with Pack; type Array_Access is access all Array_Type; A : aliased Array_Type := (1, 2, 3, 4, 5, 6, 7, 8, 9, 10); AA : constant Array_Type := A'Access; Before this change, we would get the following GDB session: (gdb) print aa.all(2) $1 = 3 (gdb) print aa(2) $2 = 16 This is wrong: both expression should yield the same value: 3. The problem is simply that the routine which handles accesses to arrays lack general handling for packed arrays. After this patch, we have the expected output: (gdb) print aa.all(2) $1 = 3 (gdb) print aa(2) $2 = 3 gdb/ChangeLog: * ada-lang.c (ada_value_ptr_subscript): Update the heading comment. Handle packed arrays. gdb/testsuite/ChangeLog: * gdb.ada/access_to_packed_array.exp: New testcase. * gdb.ada/access_to_packed_array/foo.adb: New file. * gdb.ada/access_to_packed_array/pack.adb: New file. * gdb.ada/access_to_packed_array/pack.ads: New file. Tested on x86_64-linux, no regression.
This commit is contained in:
@ -2757,14 +2757,27 @@ ada_value_subscript (struct value *arr, int arity, struct value **ind)
|
||||
|
||||
/* Assuming ARR is a pointer to a GDB array, the value of the element
|
||||
of *ARR at the ARITY indices given in IND.
|
||||
Does not read the entire array into memory. */
|
||||
Does not read the entire array into memory.
|
||||
|
||||
Note: Unlike what one would expect, this function is used instead of
|
||||
ada_value_subscript for basically all non-packed array types. The reason
|
||||
for this is that a side effect of doing our own pointer arithmetics instead
|
||||
of relying on value_subscript is that there is no implicit typedef peeling.
|
||||
This is important for arrays of array accesses, where it allows us to
|
||||
preserve the fact that the array's element is an array access, where the
|
||||
access part os encoded in a typedef layer. */
|
||||
|
||||
static struct value *
|
||||
ada_value_ptr_subscript (struct value *arr, int arity, struct value **ind)
|
||||
{
|
||||
int k;
|
||||
struct value *array_ind = ada_value_ind (arr);
|
||||
struct type *type
|
||||
= check_typedef (value_enclosing_type (ada_value_ind (arr)));
|
||||
= check_typedef (value_enclosing_type (array_ind));
|
||||
|
||||
if (TYPE_CODE (type) == TYPE_CODE_ARRAY
|
||||
&& TYPE_FIELD_BITSIZE (type, 0) > 0)
|
||||
return value_subscript_packed (array_ind, arity, ind);
|
||||
|
||||
for (k = 0; k < arity; k += 1)
|
||||
{
|
||||
|
Reference in New Issue
Block a user