From patchwork Tue May 9 17:46:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Arnez X-Patchwork-Id: 20351 Received: (qmail 123498 invoked by alias); 9 May 2017 17:57:21 -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 123472 invoked by uid 89); 9 May 2017 17:57:19 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.5 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 mx0a-001b2d01.pphosted.com (HELO mx0a-001b2d01.pphosted.com) (148.163.156.1) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 09 May 2017 17:57:17 +0000 Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v49HrdT0075679 for ; Tue, 9 May 2017 13:57:19 -0400 Received: from e06smtp11.uk.ibm.com (e06smtp11.uk.ibm.com [195.75.94.107]) by mx0a-001b2d01.pphosted.com with ESMTP id 2abcj9shcd-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 09 May 2017 13:57:18 -0400 Received: from localhost by e06smtp11.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 9 May 2017 18:57:15 +0100 Received: from b06cxnps4074.portsmouth.uk.ibm.com (9.149.109.196) by e06smtp11.uk.ibm.com (192.168.101.141) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 9 May 2017 18:57:13 +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 v49HvCad30802162 for ; Tue, 9 May 2017 17:57:12 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4DA1D5204E for ; Tue, 9 May 2017 17:54:36 +0100 (BST) Received: from oc1027705133.ibm.com (unknown [9.152.212.109]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id 332AA52043 for ; Tue, 9 May 2017 17:54:36 +0100 (BST) From: Andreas Arnez To: gdb-patches@sourceware.org Subject: [PATCH v2 15/19] Respect piece offset for DW_OP_bit_piece Date: Tue, 9 May 2017 19:46:11 +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-0040-0000-0000-000003A3C569 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17050917-0041-0000-0000-0000200C993F Message-Id: <1494352015-10465-16-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-1705090098 X-IsSubscribed: yes So far GDB ignores the piece offset of all kinds of DWARF bit pieces (DW_OP_bit_piece) and treats such pieces as if the offset was zero. This is fixed, and an appropriate test is added. gdb/ChangeLog: * dwarf2loc.c (read_pieced_value): Respect the piece offset, as given by DW_OP_bit_piece. (write_pieced_value): Likewise. Andreas Arnez * gdb.dwarf2/var-access.exp: Add test for composite location with nonzero piece offsets. --- gdb/dwarf2loc.c | 25 ++++++++++++++++----- gdb/testsuite/gdb.dwarf2/var-access.exp | 39 +++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 6 deletions(-) diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c index 3255274..23901f0e7 100644 --- a/gdb/dwarf2loc.c +++ b/gdb/dwarf2loc.c @@ -1824,11 +1824,14 @@ read_pieced_value (struct value *v) int optim, unavail; if (gdbarch_byte_order (arch) == BFD_ENDIAN_BIG - && p->size < reg_bits) + && p->offset + p->size < reg_bits) { /* Big-endian, and we want less than full size. */ - source_offset_bits += reg_bits - p->size; + source_offset_bits += reg_bits - (p->offset + p->size); } + else + source_offset_bits += p->offset; + this_size = bits_to_bytes (source_offset_bits, this_size_bits); buffer.reserve (this_size); @@ -1851,6 +1854,7 @@ read_pieced_value (struct value *v) break; case DWARF_VALUE_MEMORY: + source_offset_bits += p->offset; this_size = bits_to_bytes (source_offset_bits, this_size_bits); buffer.reserve (this_size); @@ -1871,12 +1875,15 @@ read_pieced_value (struct value *v) = 8 * TYPE_LENGTH (value_type (p->v.value)); /* Use zeroes if piece reaches beyond stack value. */ - if (p->size > stack_value_size_bits) + if (p->offset + p->size > stack_value_size_bits) break; /* Piece is anchored at least significant bit end. */ if (gdbarch_byte_order (objfile_gdbarch) == BFD_ENDIAN_BIG) - source_offset_bits += stack_value_size_bits - p->size; + source_offset_bits += (stack_value_size_bits + - p->offset - p->size); + else + source_offset_bits += p->offset; copy_bitwise (contents, dest_offset_bits, value_contents_all (p->v.value), @@ -1891,6 +1898,7 @@ read_pieced_value (struct value *v) size_t n = this_size_bits; /* Cut off at the end of the implicit value. */ + source_offset_bits += p->offset; if (source_offset_bits >= literal_size_bits) break; if (n > literal_size_bits - source_offset_bits) @@ -1981,11 +1989,14 @@ write_pieced_value (struct value *to, struct value *from) ULONGEST reg_bits = 8 * register_size (arch, gdb_regnum); if (gdbarch_byte_order (arch) == BFD_ENDIAN_BIG - && p->size <= reg_bits) + && p->offset + p->size < reg_bits) { /* Big-endian, and we want less than full size. */ - dest_offset_bits += reg_bits - p->size; + dest_offset_bits += reg_bits - (p->offset + p->size); } + else + dest_offset_bits += p->offset; + this_size = bits_to_bytes (dest_offset_bits, this_size_bits); buffer.reserve (this_size); @@ -2023,6 +2034,8 @@ write_pieced_value (struct value *to, struct value *from) break; case DWARF_VALUE_MEMORY: { + dest_offset_bits += p->offset; + CORE_ADDR start_addr = p->v.mem.addr + dest_offset_bits / 8; if (dest_offset_bits % 8 == 0 && this_size_bits % 8 == 0 diff --git a/gdb/testsuite/gdb.dwarf2/var-access.exp b/gdb/testsuite/gdb.dwarf2/var-access.exp index c533b8d..07516fc 100644 --- a/gdb/testsuite/gdb.dwarf2/var-access.exp +++ b/gdb/testsuite/gdb.dwarf2/var-access.exp @@ -228,6 +228,24 @@ Dwarf::assemble $asm_file { piece 1 } SPECIAL_expr} } + # One piece per bitfield, using piece offsets: 32 bits of + # an implicit value, 9 bits of a stack value, 13 bits of + # r0, and 10 bits of buf. + DW_TAG_variable { + {name "t3"} + {type :$struct_t_label} + {location { + implicit_value 0x12 0x34 0x56 0x78 0x9a + bit_piece 32 4 + const2s -280 + stack_value + bit_piece 9 2 + regx [lindex $dwarf_regnum 0] + bit_piece 13 14 + addr $buf_var + bit_piece 10 42 + } SPECIAL_expr} + } } } } @@ -304,3 +322,24 @@ gdb_test_no_output "set var t2.y = 2641" gdb_test_no_output "set var t2.z = -400" gdb_test_no_output "set var t2.x = 200" gdb_test "print t2.x + t2.y + t2.z" " = 2441" + +# Bitfield access through pieces with nonzero piece offsets. +gdb_test_no_output "set var \$[lindex $regname 0] = 0xa8000" \ + "init reg for t3.y" +gdb_test_no_output "set var *(char \[2\] *) (a + 5) = { 70, 82 }" \ + "init mem for t3.z" +switch $endian { + little {set val "u = -1484430527, x = -70, y = 42, z = 145"} + big {set val "u = 591751049, x = -70, y = 42, z = 101"} +} +gdb_test "print t3" " = \\{$val\\}" \ + "initialized t3 from reg and mem" +gdb_test_no_output "set var t3.y = -1" \ + "overwrite t3.y" +gdb_test "print/x \$[lindex $regname 0]" " = 0x7ffc000" \ + "verify t3.y through reg" +gdb_test_no_output "set var t3.z = -614" \ + "overwrite t3.z" +switch $endian {big {set val "0x59, 0xa2"} little {set val "0x6a, 0x56"}} +gdb_test "print/x *(char \[2\] *) (a + 5)" " = \\{$val\\}" \ + "verify t3.z through mem"