Ada: Print bounds/length of pointer to array with dynamic bounds
authorJoel Brobecker <brobecker@adacore.com>
Fri, 29 Aug 2014 17:56:25 +0000 (19:56 +0200)
committerJoel Brobecker <brobecker@adacore.com>
Wed, 10 Sep 2014 13:32:00 +0000 (06:32 -0700)
commiteb47903935f507a11b6367d4a997b8ac95068c4c
tree05da6daeb7a4ba032a48b66c123bcc9b4706d421
parentdeede10c775af571f72a37efa5b763b45334b19e
Ada: Print bounds/length of pointer to array with dynamic bounds

Trying to print the bounds or the length of a pointer to an array
whose bounds are dynamic results in the following error:

    (gdb) p foo.three_ptr.all'first
    Location address is not set.
    (gdb) p foo.three_ptr.all'length
    Location address is not set.

This is because, after having dereferenced our array pointer, we
use the type of the resulting array value, instead of the enclosing
type.  The former is the original type where the bounds are unresolved,
whereas we need to get the actual array bounds.

Similarly, trying to apply those attributes to the array pointer
directly (without explicitly dereferencing it with the '.all'
operator) yields the same kind of error:

    (gdb) p foo.three_ptr'first
    Location address is not set.
    (gdb) p foo.three_ptr'length
    Location address is not set.

This is caused by the fact that the dereference was done implicitly
in this case, and perform at the type level only, which is not
sufficient in order to resolve the array type.

This patch fixes both issues, thus allowing us to get the expected output:

    (gdb) p foo.three_ptr.all'first
    $1 = 1
    (gdb) p foo.three_ptr.all'length
    $2 = 3
    (gdb) p foo.three_ptr'first
    $3 = 1
    (gdb) p foo.three_ptr'length
    $4 = 3

gdb/ChangeLog:

        * ada-lang.c (ada_array_bound): If ARR is a TYPE_CODE_PTR,
        dereference it first.  Use value_enclosing_type instead of
        value_type.
        (ada_array_length): Likewise.

gdb/testsuite/ChangeLog:

        * gdb.dwarf2/dynarr-ptr.exp: Add 'first, 'last and 'length tests.
gdb/ChangeLog
gdb/ada-lang.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.dwarf2/dynarr-ptr.exp
This page took 0.043127 seconds and 4 git commands to generate.