From deede10c775af571f72a37efa5b763b45334b19e Mon Sep 17 00:00:00 2001 From: Joel Brobecker Date: Fri, 29 Aug 2014 19:50:03 +0200 Subject: Ada subscripting of pointer to array with dynamic bounds Consider a pointer to an array which dynamic bounds, described in DWARF as follow: <1><25>: Abbrev Number: 4 (DW_TAG_array_type) <26> DW_AT_name : foo__array_type [...] <2><3b>: Abbrev Number: 5 (DW_TAG_subrange_type) [...] <40> DW_AT_lower_bound : 5 byte block: 97 38 1c 94 4 (DW_OP_push_object_address; DW_OP_lit8; DW_OP_minus; DW_OP_deref_size: 4) <46> DW_AT_upper_bound : 5 byte block: 97 34 1c 94 4 (DW_OP_push_object_address; DW_OP_lit4; DW_OP_minus; DW_OP_deref_size: 4) GDB is now able to correctly print the entire array, but not one element of the array. Eg: (gdb) p foo.three_ptr.all $1 = (1, 2, 3) (gdb) p foo.three_ptr.all(1) Cannot access memory at address 0xfffffffff4123a0c The problem occurs because we are missing a dynamic resolution of the variable's array type when subscripting the array. What the current code does is "fix"-ing the array type using the GNAT encodings, but that operation ignores any of the array's dynamic properties. This patch fixes the issue by using ada_value_ind to dereference the array pointer, which takes care of the array type resolution. It also continues to "fix" arrays described using GNAT encodings, so backwards compatibility is preserved. gdb/ChangeLog: * ada-lang.c (ada_value_ptr_subscript): Remove parameter "type". Adjust function implementation and documentation accordingly. (ada_evaluate_subexp) : Only assign "type" if NOSIDE is EVAL_AVOID_SIDE_EFFECTS. Update call to ada_value_ptr_subscript. gdb/testsuite/ChangeLog: * gdb.dwarf2/dynarr-ptr.exp: Add subscripting tests. --- gdb/testsuite/ChangeLog | 4 ++ gdb/testsuite/gdb.dwarf2/dynarr-ptr.exp | 104 ++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) (limited to 'gdb/testsuite') diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index e7bba7790f0..ebb7e6a917d 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2014-09-10 Joel Brobecker + + * gdb.dwarf2/dynarr-ptr.exp: Add subscripting tests. + 2014-09-10 Joel Brobecker * gdb.dwarf2/dynarr-ptr.c: New file. diff --git a/gdb/testsuite/gdb.dwarf2/dynarr-ptr.exp b/gdb/testsuite/gdb.dwarf2/dynarr-ptr.exp index 501f1290c3b..1df5e3c018d 100644 --- a/gdb/testsuite/gdb.dwarf2/dynarr-ptr.exp +++ b/gdb/testsuite/gdb.dwarf2/dynarr-ptr.exp @@ -137,17 +137,121 @@ gdb_test_no_output "set language ada" gdb_test "print foo.three_ptr.all" \ " = \\(1, 2, 3\\)" +gdb_test "print foo.three_ptr.all(1)" \ + " = 1" + +gdb_test "print foo.three_ptr.all(2)" \ + " = 2" + +gdb_test "print foo.three_ptr.all(3)" \ + " = 3" + +# foo.three_ptr + +gdb_test "print foo.three_ptr(1)" \ + " = 1" + +gdb_test "print foo.three_ptr(2)" \ + " = 2" + +gdb_test "print foo.three_ptr(3)" \ + " = 3" + # foo.three_ptr_tdef.all gdb_test "print foo.three_ptr_tdef.all" \ " = \\(1, 2, 3\\)" +gdb_test "print foo.three_ptr_tdef.all(1)" \ + " = 1" + +gdb_test "print foo.three_ptr_tdef.all(2)" \ + " = 2" + +gdb_test "print foo.three_ptr_tdef.all(3)" \ + " = 3" + +# foo.three_ptr_tdef + +gdb_test "print foo.three_ptr_tdef(1)" \ + " = 1" + +gdb_test "print foo.three_ptr_tdef(2)" \ + " = 2" + +gdb_test "print foo.three_ptr_tdef(3)" \ + " = 3" + # foo.five_ptr.all gdb_test "print foo.five_ptr.all" \ " = \\(2 => 5, 8, 13, 21, 34\\)" +gdb_test "print foo.five_ptr.all(2)" \ + " = 5" + +gdb_test "print foo.five_ptr.all(3)" \ + " = 8" + +gdb_test "print foo.five_ptr.all(4)" \ + " = 13" + +gdb_test "print foo.five_ptr.all(5)" \ + " = 21" + +gdb_test "print foo.five_ptr.all(6)" \ + " = 34" + +# foo.five_ptr + +gdb_test "print foo.five_ptr(2)" \ + " = 5" + +gdb_test "print foo.five_ptr(3)" \ + " = 8" + +gdb_test "print foo.five_ptr(4)" \ + " = 13" + +gdb_test "print foo.five_ptr(5)" \ + " = 21" + +gdb_test "print foo.five_ptr(6)" \ + " = 34" + # foo.five_ptr_tdef.all gdb_test "print foo.five_ptr_tdef.all" \ " = \\(2 => 5, 8, 13, 21, 34\\)" + +gdb_test "print foo.five_ptr_tdef.all(2)" \ + " = 5" + +gdb_test "print foo.five_ptr_tdef.all(3)" \ + " = 8" + +gdb_test "print foo.five_ptr_tdef.all(4)" \ + " = 13" + +gdb_test "print foo.five_ptr_tdef.all(5)" \ + " = 21" + +gdb_test "print foo.five_ptr_tdef.all(6)" \ + " = 34" + +# foo.five_ptr_tdef + +gdb_test "print foo.five_ptr_tdef(2)" \ + " = 5" + +gdb_test "print foo.five_ptr_tdef(3)" \ + " = 8" + +gdb_test "print foo.five_ptr_tdef(4)" \ + " = 13" + +gdb_test "print foo.five_ptr_tdef(5)" \ + " = 21" + +gdb_test "print foo.five_ptr_tdef(6)" \ + " = 34" -- cgit v1.2.1