[Ada] Handle reference to array descriptors
authorJoel Brobecker <brobecker@gnat.com>
Wed, 29 Feb 2012 19:33:02 +0000 (19:33 +0000)
committerJoel Brobecker <brobecker@gnat.com>
Wed, 29 Feb 2012 19:33:02 +0000 (19:33 +0000)
commit2d4a02ee9526f370ccd9bdc3f30510f03ee59d19
tree7b8bebd3cfae84ee7be07dbe758a0956444f9df1
parentc48db5caef25bc89b8f444300c7740f01405938b
[Ada] Handle reference to array descriptors

This patch is to help handle aliased array variables, such as:

   type Bounded is array (Integer range <>) of Integer;
   function New_Bounded (Low, High : Integer) return Bounded;
   BT : aliased Bounded := New_Bounded (Low => 1, High => 3);

In that case, the compiler describes variable "BT" as a reference
to a thin pointer, and GDB is unable to print its value:

    (gdb) p bt
    $1 =

The problems starts when ada_value_print deconstructs the struct
value into contents and address in order to call val_print. It
turns out in this case that "bt" is not an lval. In the debug
information, this variable's location is described as:

        .uleb128 0xd    # (DIE (0xe0) DW_TAG_variable)
        .ascii "bt\0"   # DW_AT_name
        [...]
        .byte   0x6     # DW_AT_location
        .byte   0x91    # DW_OP_fbreg
        .sleb128 -56
        .byte   0x6     # DW_OP_deref
        .byte   0x23    # DW_OP_plus_uconst
        .uleb128 0x8
        .byte   0x9f    # DW_OP_stack_value

So, when ada_value_print passes the bt's (value) address, it passes
in effect a meaningless address. The problem continues shortly after
when ada_val_print_1 re-creates the value from the contents and address.
The value has become an lval_memory, with a null address.

As a result, we trigger a memory error later on, while trying to
read the array bounds in order to transform our value into a simple
array.

To avoid the problem entirely, the fix is to coerce references before
transforming array descriptors into simple arrays.

gdb/ChangeLog:

        * ada-valprint.c (ada_val_print_1): If our value is a reference
        to an array descriptor, dereference it before converting it
        to a simple array.

gdb/testsuite/ChangeLog:

        * gdb.ada/aliased_array: New testcase.
gdb/ChangeLog
gdb/ada-valprint.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.ada/aliased_array.exp [new file with mode: 0644]
gdb/testsuite/gdb.ada/aliased_array/foo.adb [new file with mode: 0644]
gdb/testsuite/gdb.ada/aliased_array/pck.adb [new file with mode: 0644]
gdb/testsuite/gdb.ada/aliased_array/pck.ads [new file with mode: 0644]
This page took 0.027228 seconds and 4 git commands to generate.