(Ada) Fix printing of access to unconstrained arrays
authorXavier Roirand <roirand@adacore.com>
Mon, 10 Sep 2018 15:34:59 +0000 (10:34 -0500)
committerJoel Brobecker <brobecker@adacore.com>
Mon, 10 Sep 2018 15:34:59 +0000 (11:34 -0400)
commitcc330e39bc938cefd4cfc581639177ef4c6bcbe3
tree641ae04ebbc20a33e606918ee96eeeb83cf53837
parentb9c50e9a9ac48662b2132583c52d46976efb3512
(Ada) Fix printing of access to unconstrained arrays

Using this Ada code:

    type String_Access is access String;
    type Array_Of_String is array (1 .. 2) of String_Access;
    Aos : Array_Of_String := (new String'("ab"), new String'("cd"));

When debugging with GDB, printing each Aos element displays:

    (gdb) print Aos(1)
    $2 = "ab"
    (gdb) print Aos(2)
    $3 = "cd"

Whereas it should display:

    (gdb) print Aos(1)
    $2 = (foo_r118_024.string_access) 0x635018
    (gdb) print Aos(2)
    $3 = (foo_r118_024.string_access) 0x635038

Notice that printing the entire array works:

(gdb) print Aos
$1 = (0x635018, 0x635038)

The problem was located in ada_value_print function and due to the fact
that the value_type used in this function was based on
value_enclosing_type rather than value_type itself.
In our example, the difference between the value_type and the
value_enclosing_type of the value is that the value_type contains an
additional typedef layer which is not present in the value_enclosing_type.
This typedef layer is GNAT's way to specify that the element is, at the
source level, an access to the unconstrained array, rather than the
unconstrained array.
Moreover, the value_enclosing_type is not really needed in that case and
the value_type can be used instead in this function, and this patch fixes
this.

gdb/ChangeLog:

    * ada-valprint.c (ada_value_print): Use type instead of
    enclosing type.

testsuite/ChangeLog:

    * gdb.ada/access_to_unbounded_array.exp: New testcase.
    * gdb.ada/access_to_unbounded_array/foo.adb: New file.
    * gdb.ada/access_to_unbounded_array/pack.adb: New file.
    * gdb.ada/access_to_unbounded_array/pack.ads: New file.

Tested: x86_64-linux
gdb/ChangeLog
gdb/ada-valprint.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.ada/access_to_unbounded_array.exp [new file with mode: 0644]
gdb/testsuite/gdb.ada/access_to_unbounded_array/foo.adb [new file with mode: 0644]
gdb/testsuite/gdb.ada/access_to_unbounded_array/pack.adb [new file with mode: 0644]
gdb/testsuite/gdb.ada/access_to_unbounded_array/pack.ads [new file with mode: 0644]