From patchwork Tue Nov 27 18:31:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Basierski X-Patchwork-Id: 30323 Received: (qmail 13153 invoked by alias); 27 Nov 2018 19:40:11 -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 13058 invoked by uid 89); 27 Nov 2018 19:40:10 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_FAIL autolearn=ham version=3.3.2 spammy=prop X-HELO: mga02.intel.com Received: from mga02.intel.com (HELO mga02.intel.com) (134.134.136.20) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 27 Nov 2018 19:40:08 +0000 Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Nov 2018 11:40:05 -0800 Received: from ubuntu.imu.intel.com ([10.217.246.11]) by FMSMGA003.fm.intel.com with ESMTP; 27 Nov 2018 11:40:04 -0800 From: Sebastian Basierski To: gdb-patches@sourceware.org Subject: [PATCH 01/11] Dwarf: Fix dynamic properties with neg. value. Date: Tue, 27 Nov 2018 19:31:29 +0100 Message-Id: <20181127183139.71170-2-sbasierski@pl.sii.eu> In-Reply-To: <20181127183139.71170-1-sbasierski@pl.sii.eu> References: <20181127183139.71170-1-sbasierski@pl.sii.eu> From: Bernhard Heckel Evaluating of neg. value of 32bit inferiours running on 64bit plattform causes issues because of the missing sign bits. Bernhard Heckel gdb/Changelog * dwarf2loc.h: Declare * dwarf2loc.c (dwarf2_evaluate_property_signed): New. (dwarf2_evaluate_property): Delegate tasks to dwarf2_evaluate_property_signed. --- gdb/dwarf2loc.c | 44 +++++++++++++++++++++++++++++++++++--------- gdb/dwarf2loc.h | 7 +++++++ 2 files changed, 42 insertions(+), 9 deletions(-) diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c index ee6a8e277c..c94bdc60f2 100644 --- a/gdb/dwarf2loc.c +++ b/gdb/dwarf2loc.c @@ -2659,11 +2659,13 @@ dwarf2_locexpr_baton_eval (const struct dwarf2_locexpr_baton *dlbaton, /* See dwarf2loc.h. */ int -dwarf2_evaluate_property (const struct dynamic_prop *prop, - struct frame_info *frame, - struct property_addr_info *addr_stack, - CORE_ADDR *value) +dwarf2_evaluate_property_signed (const struct dynamic_prop *prop, + struct frame_info *frame, + struct property_addr_info *addr_stack, + CORE_ADDR *value, int is_signed) { + int rc = 0; + if (prop == NULL) return 0; @@ -2687,7 +2689,7 @@ dwarf2_evaluate_property (const struct dynamic_prop *prop, *value = value_as_address (val); } - return 1; + rc = 1; } } break; @@ -2709,7 +2711,7 @@ dwarf2_evaluate_property (const struct dynamic_prop *prop, if (!value_optimized_out (val)) { *value = value_as_address (val); - return 1; + rc = 1; } } } @@ -2717,7 +2719,8 @@ dwarf2_evaluate_property (const struct dynamic_prop *prop, case PROP_CONST: *value = prop->data.const_val; - return 1; + rc = 1; + break; case PROP_ADDR_OFFSET: { @@ -2739,11 +2742,34 @@ dwarf2_evaluate_property (const struct dynamic_prop *prop, val = value_at (baton->offset_info.type, pinfo->addr + baton->offset_info.offset); *value = value_as_address (val); - return 1; + rc = 1; } + break; } - return 0; + if (rc == 1 && is_signed == 1) + { + /* 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 4 bytes. */ + struct gdbarch * gdbarch = target_gdbarch (); + const int addr_bit = gdbarch_addr_bit (gdbarch); + const CORE_ADDR neg_mask = ((~0) << (addr_bit - 1)); + + /* Check if signed bit is set and sign-extend values. */ + if (*value & (neg_mask)) + *value |= (neg_mask ); + } + return rc; +} + +int +dwarf2_evaluate_property (const struct dynamic_prop *prop, + struct frame_info *frame, + struct property_addr_info *addr_stack, + CORE_ADDR *value) +{ + return dwarf2_evaluate_property_signed (prop, frame, addr_stack, value, 0); } /* See dwarf2loc.h. */ diff --git a/gdb/dwarf2loc.h b/gdb/dwarf2loc.h index d7a56db05d..408e1904cd 100644 --- a/gdb/dwarf2loc.h +++ b/gdb/dwarf2loc.h @@ -143,6 +143,13 @@ int dwarf2_evaluate_property (const struct dynamic_prop *prop, struct property_addr_info *addr_stack, CORE_ADDR *value); +int dwarf2_evaluate_property_signed (const struct dynamic_prop *prop, + struct frame_info *frame, + struct property_addr_info *addr_stack, + CORE_ADDR *value, + int is_signed); + + /* A helper for the compiler interface that compiles a single dynamic property to C code.