From patchwork Thu May 9 22:22:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 32626 Received: (qmail 27436 invoked by alias); 9 May 2019 22:22:33 -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 27245 invoked by uid 89); 9 May 2019 22:22:31 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mail-wr1-f46.google.com Received: from mail-wr1-f46.google.com (HELO mail-wr1-f46.google.com) (209.85.221.46) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 09 May 2019 22:22:29 +0000 Received: by mail-wr1-f46.google.com with SMTP id r7so4466403wrr.13 for ; Thu, 09 May 2019 15:22:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=yW82iofFzvur2tosOvtRKEwZTUq64rFrm7FaQRmj4os=; b=a+1uMIfniF841f6SSwvnW18K4rDDA9GN8601CZHKWK9dqylOaM+bVzTAtxOXsjlawD WltZI8dowj2rq4CUJWujqryEosrWbPc/guJZpHpOiVBKEXaLBbYxHhChSzbajfsmO4zk 5ePE4ACJiS7CelK4yNrGhI6b6EPCSD1y5vo/xP8tnZI9mIKC8HwUah2Cgqp3xGQnQXSb WlnEQ0VpumKPdF+iL3oMrgZrUire5YPt1Xf2Kn72o+J+3mUc1riAIeAH25OPVO6PWVkV aucPpbtPWzFQD9InvNfHJZiUtciJyYlwpL9mhp0LkNkBMUQLlg7njJ8+DaZmOIBKI5Ly DhyA== Return-Path: Received: from localhost (host109-154-100-57.range109-154.btcentralplus.com. [109.154.100.57]) by smtp.gmail.com with ESMTPSA id s11sm9632641wrb.71.2019.05.09.15.22.26 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 09 May 2019 15:22:26 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv2 5/5] gdb: Better support for dynamic properties with negative values Date: Thu, 9 May 2019 23:22:16 +0100 Message-Id: <672dc208d6dfb9f068eb635e02bf85abb9630c74.1557439866.git.andrew.burgess@embecosm.com> In-Reply-To: References: In-Reply-To: References: X-IsSubscribed: yes When the type of a property is smaller than the CORE_ADDR in which the property value has been placed, and if the property is signed, then sign extend the property value from its actual type up to the size of CORE_ADDR. gdb/ChangeLog: * dwarf2loc.c (dwarf2_evaluate_property): Sign extend property value if its desired type is smaller than a CORE_ADDR and signed. gdb/testsuite/ChangeLog: * gdb.fortran/vla-ptype.exp: Print array with negative bounds. * gdb.fortran/vla-sizeof.exp: Print the size of an array with negative bounds. * gdb.fortran/vla-value.exp: Print elements of an array with negative bounds. * gdb.fortran/vla.f90: Setup an array with negative bounds for testing. --- gdb/ChangeLog | 5 +++++ gdb/dwarf2loc.c | 22 ++++++++++++++++++++++ gdb/testsuite/ChangeLog | 11 +++++++++++ gdb/testsuite/gdb.fortran/vla-ptype.exp | 12 ++++++++++++ gdb/testsuite/gdb.fortran/vla-sizeof.exp | 10 ++++++++++ gdb/testsuite/gdb.fortran/vla-value.exp | 27 +++++++++++++++++++++++++++ gdb/testsuite/gdb.fortran/vla.f90 | 15 +++++++++++++++ 7 files changed, 102 insertions(+) diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c index 88d34eb8660..0a25a7a64b0 100644 --- a/gdb/dwarf2loc.c +++ b/gdb/dwarf2loc.c @@ -2454,6 +2454,28 @@ dwarf2_evaluate_property (const struct dynamic_prop *prop, struct value *val = value_at (baton->property_type, *value); *value = value_as_address (val); } + else + { + gdb_assert (baton->property_type != NULL); + + struct type *type = check_typedef (baton->property_type); + if (TYPE_LENGTH (type) < sizeof (CORE_ADDR) + && !TYPE_UNSIGNED (type)) + { + /* If we have a valid return candidate and it's value + is signed, we have to sign-extend the value because + CORE_ADDR on 64bit machine has 8 bytes but address + size of an 32bit application is bytes. */ + const int addr_size + = (dwarf2_per_cu_addr_size (baton->locexpr.per_cu) + * TARGET_CHAR_BIT); + const CORE_ADDR neg_mask = ((~0) << (addr_size - 1)); + + /* Check if signed bit is set and sign-extend values. */ + if (*value & (neg_mask)) + *value |= (neg_mask ); + } + } return true; } } diff --git a/gdb/testsuite/gdb.fortran/vla-ptype.exp b/gdb/testsuite/gdb.fortran/vla-ptype.exp index 0f4abb63757..7ad7ecdea65 100644 --- a/gdb/testsuite/gdb.fortran/vla-ptype.exp +++ b/gdb/testsuite/gdb.fortran/vla-ptype.exp @@ -98,3 +98,15 @@ gdb_test "ptype vla2" "type = " "ptype vla2 not allocated" gdb_test "ptype vla2(5, 45, 20)" \ "no such vector element \\\(vector not allocated\\\)" \ "ptype vla2(5, 45, 20) not allocated" + +gdb_breakpoint [gdb_get_line_number "vla1-neg-bounds-v1"] +gdb_continue_to_breakpoint "vla1-neg-bounds-v1" +gdb_test "ptype vla1" \ + "type = $real, allocatable \\(-2:-1,-5:-2,-3:-1\\)" \ + "ptype vla1 negative bounds" + +gdb_breakpoint [gdb_get_line_number "vla1-neg-bounds-v2"] +gdb_continue_to_breakpoint "vla1-neg-bounds-v2" +gdb_test "ptype vla1" \ + "type = $real, allocatable \\(-2:1,-5:2,-3:1\\)" \ + "ptype vla1 negative lower bounds, positive upper bounds" diff --git a/gdb/testsuite/gdb.fortran/vla-sizeof.exp b/gdb/testsuite/gdb.fortran/vla-sizeof.exp index 7f74a699d76..7527e0eb0b8 100644 --- a/gdb/testsuite/gdb.fortran/vla-sizeof.exp +++ b/gdb/testsuite/gdb.fortran/vla-sizeof.exp @@ -44,3 +44,13 @@ gdb_test "print sizeof(pvla)" " = 0" "print sizeof non-associated pvla" gdb_breakpoint [gdb_get_line_number "pvla-associated"] gdb_continue_to_breakpoint "pvla-associated" gdb_test "print sizeof(pvla)" " = 4000" "print sizeof associated pvla" + +gdb_breakpoint [gdb_get_line_number "vla1-neg-bounds-v1"] +gdb_continue_to_breakpoint "vla1-neg-bounds-v1" +gdb_test "print sizeof(vla1)" " = 96" \ + "print sizeof vla1 negative bounds" + +gdb_breakpoint [gdb_get_line_number "vla1-neg-bounds-v2"] +gdb_continue_to_breakpoint "vla1-neg-bounds-v2" +gdb_test "print sizeof(vla1)" " = 640" \ + "print sizeof vla1 negative lower bounds, positive upper bounds" diff --git a/gdb/testsuite/gdb.fortran/vla-value.exp b/gdb/testsuite/gdb.fortran/vla-value.exp index be397fd95fb..3145d21c15c 100644 --- a/gdb/testsuite/gdb.fortran/vla-value.exp +++ b/gdb/testsuite/gdb.fortran/vla-value.exp @@ -161,3 +161,30 @@ gdb_breakpoint [gdb_get_line_number "pvla-deassociated"] gdb_continue_to_breakpoint "pvla-deassociated" gdb_test "print \$mypvar(1,3,8)" " = 1001" \ "print \$mypvar(1,3,8) after deallocated" + +gdb_breakpoint [gdb_get_line_number "vla1-neg-bounds-v1"] +gdb_continue_to_breakpoint "vla1-neg-bounds-v1" +with_test_prefix "negative bounds" { + gdb_test "print vla1(-2,-5,-3)" " = 1" + gdb_test "print vla1(-2,-3,-1)" " = -231" + gdb_test "print vla1(-3,-5,-3)" "no such vector element" + gdb_test "print vla1(-2,-6,-3)" "no such vector element" + gdb_test "print vla1(-2,-5,-4)" "no such vector element" + gdb_test "print vla1(0,-2,-1)" "no such vector element" + gdb_test "print vla1(-1,-1,-1)" "no such vector element" + gdb_test "print vla1(-1,-2,0)" "no such vector element" +} + +gdb_breakpoint [gdb_get_line_number "vla1-neg-bounds-v2"] +gdb_continue_to_breakpoint "vla1-neg-bounds-v2" +with_test_prefix "negative lower bounds, positive upper bounds" { + gdb_test "print vla1(-2,-5,-3)" " = 2" + gdb_test "print vla1(-2,-3,-1)" " = 2" + gdb_test "print vla1(-2,-4,-2)" " = -242" + gdb_test "print vla1(-3,-5,-3)" "no such vector element" + gdb_test "print vla1(-2,-6,-3)" "no such vector element" + gdb_test "print vla1(-2,-5,-4)" "no such vector element" + gdb_test "print vla1(2,2,1)" "no such vector element" + gdb_test "print vla1(1,3,1)" "no such vector element" + gdb_test "print vla1(1,2,2)" "no such vector element" +} diff --git a/gdb/testsuite/gdb.fortran/vla.f90 b/gdb/testsuite/gdb.fortran/vla.f90 index 5bc608744b3..0ccb5c90d93 100644 --- a/gdb/testsuite/gdb.fortran/vla.f90 +++ b/gdb/testsuite/gdb.fortran/vla.f90 @@ -54,4 +54,19 @@ program vla allocate (vla3 (2,2)) ! vla2-deallocated vla3(:,:) = 13 + + allocate (vla1 (-2:-1, -5:-2, -3:-1)) + vla1(:, :, :) = 1 + vla1(-2, -3, -1) = -231 + + deallocate (vla1) ! vla1-neg-bounds-v1 + l = allocated(vla1) + + allocate (vla1 (-2:1, -5:2, -3:1)) + vla1(:, :, :) = 2 + vla1(-2, -4, -2) = -242 + + deallocate (vla1) ! vla1-neg-bounds-v2 + l = allocated(vla1) + end program vla