From patchwork Wed Sep 10 13:39:07 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Brobecker X-Patchwork-Id: 2749 Received: (qmail 17698 invoked by alias); 10 Sep 2014 13:39:19 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 17628 invoked by uid 89); 10 Sep 2014 13:39:19 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.0 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Wed, 10 Sep 2014 13:39:17 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 5AB1A11644A for ; Wed, 10 Sep 2014 09:39:15 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id MFyTqvx9hluV for ; Wed, 10 Sep 2014 09:39:15 -0400 (EDT) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id 2546E116445 for ; Wed, 10 Sep 2014 09:39:15 -0400 (EDT) Received: by joel.gnat.com (Postfix, from userid 1000) id 71B3D477FF; Wed, 10 Sep 2014 06:39:17 -0700 (PDT) From: Joel Brobecker To: gdb-patches@sourceware.org Subject: [pushed/Ada 2/4] Ada subscripting of pointer to array with dynamic bounds Date: Wed, 10 Sep 2014 06:39:07 -0700 Message-Id: <1410356349-5661-3-git-send-email-brobecker@adacore.com> In-Reply-To: <1410356349-5661-1-git-send-email-brobecker@adacore.com> References: <1410356349-5661-1-git-send-email-brobecker@adacore.com> 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/ChangeLog | 8 +++ gdb/ada-lang.c | 17 +++--- gdb/testsuite/ChangeLog | 4 ++ gdb/testsuite/gdb.dwarf2/dynarr-ptr.exp | 104 ++++++++++++++++++++++++++++++++ 4 files changed, 125 insertions(+), 8 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 82e3622..67f631d 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,13 @@ 2014-09-10 Joel Brobecker + * 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. + +2014-09-10 Joel Brobecker + * ada-valprint.c (ada_value_print): Use VAL's enclosing type instead of VAL's type. diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 28999c7..4c6d039 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -2715,15 +2715,16 @@ ada_value_subscript (struct value *arr, int arity, struct value **ind) return elt; } -/* Assuming ARR is a pointer to a standard GDB array of type TYPE, the - value of the element of *ARR at the ARITY indices given in - IND. Does not read the entire array into memory. */ +/* Assuming ARR is a pointer to a GDB array, the value of the element + of *ARR at the ARITY indices given in IND. + Does not read the entire array into memory. */ static struct value * -ada_value_ptr_subscript (struct value *arr, struct type *type, int arity, - struct value **ind) +ada_value_ptr_subscript (struct value *arr, int arity, struct value **ind) { int k; + struct type *type + = check_typedef (value_enclosing_type (ada_value_ind (arr))); for (k = 0; k < arity; k += 1) { @@ -10323,9 +10324,9 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp, (ada_coerce_to_simple_array (argvec[0]), nargs, argvec + 1)); case TYPE_CODE_PTR: /* Pointer to array */ - type = to_fixed_array_type (TYPE_TARGET_TYPE (type), NULL, 1); if (noside == EVAL_AVOID_SIDE_EFFECTS) { + type = to_fixed_array_type (TYPE_TARGET_TYPE (type), NULL, 1); type = ada_array_element_type (type, nargs); if (type == NULL) error (_("element type of array unknown")); @@ -10333,8 +10334,8 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp, return value_zero (ada_aligned_type (type), lval_memory); } return - unwrap_value (ada_value_ptr_subscript (argvec[0], type, - nargs, argvec + 1)); + unwrap_value (ada_value_ptr_subscript (argvec[0], + nargs, argvec + 1)); default: error (_("Attempt to index or call something other than an " diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index e7bba77..ebb7e6a 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,5 +1,9 @@ 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. * gdb.dwarf2/dynarr-ptr.exp: New file. diff --git a/gdb/testsuite/gdb.dwarf2/dynarr-ptr.exp b/gdb/testsuite/gdb.dwarf2/dynarr-ptr.exp index 501f129..1df5e3c 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"