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)
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

index 67f631d2be493ddfa712762849526078e952c186..4601ae7eb609c3b9822ac84d97dbe0d61050a9c2 100644 (file)
@@ -1,3 +1,10 @@
+2014-09-10  Joel Brobecker  <brobecker@adacore.com>
+
+       * 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.
+
 2014-09-10  Joel Brobecker  <brobecker@adacore.com>
 
        * ada-lang.c (ada_value_ptr_subscript): Remove parameter "type".
index 4c6d03933a61ed06562e38c7c302988dc12d0e41..c7e50e285dd195c3f212a22066bdbc7e4bce49cd 100644 (file)
@@ -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);
index ebb7e6a917d38caa261543f4d84d27dc08271073..66b50a94992b5da7df185b1acc2fbaa333764a81 100644 (file)
@@ -1,3 +1,7 @@
+2014-09-10  Joel Brobecker  <brobecker@adacore.com>
+
+       * gdb.dwarf2/dynarr-ptr.exp: Add 'first, 'last and 'length tests.
+
 2014-09-10  Joel Brobecker  <brobecker@adacore.com>
 
        * gdb.dwarf2/dynarr-ptr.exp: Add subscripting tests.
index 1df5e3c018d230799c6170326e8765083740f9b2..696c76519fc2f3968d2264b481e07ffe776cc6bb 100644 (file)
@@ -146,6 +146,15 @@ gdb_test "print foo.three_ptr.all(2)" \
 gdb_test "print foo.three_ptr.all(3)" \
          " = 3"
 
+gdb_test "print foo.three_ptr.all'first" \
+         " = 1"
+
+gdb_test "print foo.three_ptr.all'last" \
+         " = 3"
+
+gdb_test "print foo.three_ptr.all'length" \
+         " = 3"
+
 # foo.three_ptr
 
 gdb_test "print foo.three_ptr(1)" \
@@ -157,6 +166,15 @@ gdb_test "print foo.three_ptr(2)" \
 gdb_test "print foo.three_ptr(3)" \
          " = 3"
 
+gdb_test "print foo.three_ptr'first" \
+         " = 1"
+
+gdb_test "print foo.three_ptr'last" \
+         " = 3"
+
+gdb_test "print foo.three_ptr'length" \
+         " = 3"
+
 # foo.three_ptr_tdef.all
 
 gdb_test "print foo.three_ptr_tdef.all" \
@@ -171,6 +189,15 @@ gdb_test "print foo.three_ptr_tdef.all(2)" \
 gdb_test "print foo.three_ptr_tdef.all(3)" \
          " = 3"
 
+gdb_test "print foo.three_ptr_tdef.all'first" \
+         " = 1"
+
+gdb_test "print foo.three_ptr_tdef.all'last" \
+         " = 3"
+
+gdb_test "print foo.three_ptr_tdef.all'length" \
+         " = 3"
+
 # foo.three_ptr_tdef
 
 gdb_test "print foo.three_ptr_tdef(1)" \
@@ -182,6 +209,15 @@ gdb_test "print foo.three_ptr_tdef(2)" \
 gdb_test "print foo.three_ptr_tdef(3)" \
          " = 3"
 
+gdb_test "print foo.three_ptr_tdef'first" \
+         " = 1"
+
+gdb_test "print foo.three_ptr_tdef'last" \
+         " = 3"
+
+gdb_test "print foo.three_ptr_tdef'length" \
+         " = 3"
+
 # foo.five_ptr.all
 
 gdb_test "print foo.five_ptr.all" \
@@ -202,6 +238,15 @@ gdb_test "print foo.five_ptr.all(5)" \
 gdb_test "print foo.five_ptr.all(6)" \
          " = 34"
 
+gdb_test "print foo.five_ptr.all'first" \
+         " = 2"
+
+gdb_test "print foo.five_ptr.all'last" \
+         " = 6"
+
+gdb_test "print foo.five_ptr.all'length" \
+         " = 5"
+
 # foo.five_ptr
 
 gdb_test "print foo.five_ptr(2)" \
@@ -219,6 +264,15 @@ gdb_test "print foo.five_ptr(5)" \
 gdb_test "print foo.five_ptr(6)" \
          " = 34"
 
+gdb_test "print foo.five_ptr'first" \
+         " = 2"
+
+gdb_test "print foo.five_ptr'last" \
+         " = 6"
+
+gdb_test "print foo.five_ptr'length" \
+         " = 5"
+
 # foo.five_ptr_tdef.all
 
 gdb_test "print foo.five_ptr_tdef.all" \
@@ -239,6 +293,15 @@ gdb_test "print foo.five_ptr_tdef.all(5)" \
 gdb_test "print foo.five_ptr_tdef.all(6)" \
          " = 34"
 
+gdb_test "print foo.five_ptr_tdef.all'first" \
+         " = 2"
+
+gdb_test "print foo.five_ptr_tdef.all'last" \
+         " = 6"
+
+gdb_test "print foo.five_ptr_tdef.all'length" \
+         " = 5"
+
 # foo.five_ptr_tdef
 
 gdb_test "print foo.five_ptr_tdef(2)" \
@@ -255,3 +318,12 @@ gdb_test "print foo.five_ptr_tdef(5)" \
 
 gdb_test "print foo.five_ptr_tdef(6)" \
          " = 34"
+
+gdb_test "print foo.five_ptr_tdef'first" \
+         " = 2"
+
+gdb_test "print foo.five_ptr_tdef'last" \
+         " = 6"
+
+gdb_test "print foo.five_ptr_tdef'length" \
+         " = 5"
This page took 0.043157 seconds and 4 git commands to generate.