[Ada] Fix the evaluation of access to packed array subscript
authorPierre-Marie de Rodat <derodat@adacore.com>
Fri, 4 Sep 2015 11:09:00 +0000 (13:09 +0200)
committerPierre-Marie de Rodat <derodat@adacore.com>
Mon, 14 Sep 2015 14:28:23 +0000 (16:28 +0200)
commit919e6dbe9b61a27e8f7f89121ba182907df461a3
treed32eab262f69f68bcd264539830f600ed774b3df
parentb027a8fa7dc4854e72ddada0b495b52166be2974
[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.
gdb/ChangeLog
gdb/ada-lang.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.ada/access_to_packed_array.exp [new file with mode: 0644]
gdb/testsuite/gdb.ada/access_to_packed_array/foo.adb [new file with mode: 0644]
gdb/testsuite/gdb.ada/access_to_packed_array/pack.adb [new file with mode: 0644]
gdb/testsuite/gdb.ada/access_to_packed_array/pack.ads [new file with mode: 0644]