aboutsummaryrefslogtreecommitdiff
path: root/gdb/ada-lang.c
diff options
context:
space:
mode:
authorJoel Brobecker <brobecker@adacore.com>2014-08-29 19:56:25 +0200
committerJoel Brobecker <brobecker@adacore.com>2014-09-10 06:32:00 -0700
commiteb47903935f507a11b6367d4a997b8ac95068c4c (patch)
tree05da6daeb7a4ba032a48b66c123bcc9b4706d421 /gdb/ada-lang.c
parentdeede10c775af571f72a37efa5b763b45334b19e (diff)
downloadgdb-eb47903935f507a11b6367d4a997b8ac95068c4c.zip
gdb-eb47903935f507a11b6367d4a997b8ac95068c4c.tar.gz
gdb-eb47903935f507a11b6367d4a997b8ac95068c4c.tar.bz2
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.
Diffstat (limited to 'gdb/ada-lang.c')
-rw-r--r--gdb/ada-lang.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 4c6d039..c7e50e2 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -2942,7 +2942,11 @@ ada_array_bound_from_type (struct type *arr_type, int n, int which)
static LONGEST
ada_array_bound (struct value *arr, int n, int which)
{
- struct type *arr_type = value_type (arr);
+ struct type *arr_type;
+
+ if (TYPE_CODE (check_typedef (value_type (arr))) == TYPE_CODE_PTR)
+ arr = value_ind (arr);
+ arr_type = value_enclosing_type (arr);
if (ada_is_constrained_packed_array_type (arr_type))
return ada_array_bound (decode_constrained_packed_array (arr), n, which);
@@ -2961,7 +2965,11 @@ ada_array_bound (struct value *arr, int n, int which)
static LONGEST
ada_array_length (struct value *arr, int n)
{
- struct type *arr_type = ada_check_typedef (value_type (arr));
+ struct type *arr_type;
+
+ if (TYPE_CODE (check_typedef (value_type (arr))) == TYPE_CODE_PTR)
+ arr = value_ind (arr);
+ arr_type = value_enclosing_type (arr);
if (ada_is_constrained_packed_array_type (arr_type))
return ada_array_length (decode_constrained_packed_array (arr), n);