From patchwork Tue May 9 17:46:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Arnez X-Patchwork-Id: 20342 Received: (qmail 68907 invoked by alias); 9 May 2017 17:51:07 -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 68885 invoked by uid 89); 9 May 2017 17:51:06 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 spammy= X-HELO: mx0a-001b2d01.pphosted.com Received: from mx0b-001b2d01.pphosted.com (HELO mx0a-001b2d01.pphosted.com) (148.163.158.5) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 09 May 2017 17:51:05 +0000 Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v49Hhbw7124979 for ; Tue, 9 May 2017 13:51:07 -0400 Received: from e06smtp14.uk.ibm.com (e06smtp14.uk.ibm.com [195.75.94.110]) by mx0b-001b2d01.pphosted.com with ESMTP id 2ab91dk59k-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 09 May 2017 13:51:06 -0400 Received: from localhost by e06smtp14.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 9 May 2017 18:51:05 +0100 Received: from b06cxnps4074.portsmouth.uk.ibm.com (9.149.109.196) by e06smtp14.uk.ibm.com (192.168.101.144) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 9 May 2017 18:51:03 +0100 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v49Hp24R40632378 for ; Tue, 9 May 2017 17:51:02 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3323A52043 for ; Tue, 9 May 2017 17:48:26 +0100 (BST) Received: from oc1027705133.ibm.com (unknown [9.152.212.109]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id 235B452049 for ; Tue, 9 May 2017 17:48:26 +0100 (BST) From: Andreas Arnez To: gdb-patches@sourceware.org Subject: [PATCH v2 06/19] read/write_pieced_value: Respect value parent's offset Date: Tue, 9 May 2017 19:46:02 +0200 In-Reply-To: <1494352015-10465-1-git-send-email-arnez@linux.vnet.ibm.com> References: <1494352015-10465-1-git-send-email-arnez@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17050917-0016-0000-0000-000004978191 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17050917-0017-0000-0000-00002796E5A5 Message-Id: <1494352015-10465-7-git-send-email-arnez@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-05-09_14:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1705090097 X-IsSubscribed: yes In the case of targeting a bit-field, read_pieced_value and write_pieced_value calculate the number of bits preceding the bit-field without considering the relative offset of the value's parent. This is relevant for a structure variable like this: struct s { uint64_t foo; struct { uint32_t bar; uint32_t bf : 10; /* <-- target bit-field */ } baz; } s; In this scenario, if 'val' is a GDB value representing s.baz.bf, val->parent represents the whole s.baz structure, and the following holds: - value_offset (val) == sizeof s.baz.bar == 4 - value_offset (val->parent) == sizeof s.foo == 8 The current logic would only use value_offset(val), resulting in the wrong offset into the target value. This is fixed. gdb/ChangeLog: * dwarf2loc.c (read_pieced_value): Respect parent value's offset when targeting a bit-field. (write_pieced_value): Likewise. --- gdb/dwarf2loc.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c index 8f99844..6ce2993 100644 --- a/gdb/dwarf2loc.c +++ b/gdb/dwarf2loc.c @@ -1776,7 +1776,8 @@ read_pieced_value (struct value *v) bits_to_skip = 8 * value_offset (v); if (value_bitsize (v)) { - bits_to_skip += value_bitpos (v); + bits_to_skip += (8 * value_offset (value_parent (v)) + + value_bitpos (v)); type_len = value_bitsize (v); } else @@ -1946,7 +1947,8 @@ write_pieced_value (struct value *to, struct value *from) bits_to_skip = 8 * value_offset (to); if (value_bitsize (to)) { - bits_to_skip += value_bitpos (to); + bits_to_skip += (8 * value_offset (value_parent (to)) + + value_bitpos (to)); type_len = value_bitsize (to); } else