From patchwork Wed Mar 8 18:26:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Arnez X-Patchwork-Id: 19492 Received: (qmail 70194 invoked by alias); 8 Mar 2017 18:26:38 -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 70177 invoked by uid 89); 8 Mar 2017 18:26:38 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.1 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=respects, verifying, Hx-languages-length:4593, states 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; Wed, 08 Mar 2017 18:26:37 +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 v28IOALC093682 for ; Wed, 8 Mar 2017 13:26:36 -0500 Received: from e06smtp11.uk.ibm.com (e06smtp11.uk.ibm.com [195.75.94.107]) by mx0a-001b2d01.pphosted.com with ESMTP id 292f838q4a-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 08 Mar 2017 13:26:35 -0500 Received: from localhost by e06smtp11.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 8 Mar 2017 18:26:33 -0000 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp11.uk.ibm.com (192.168.101.141) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 8 Mar 2017 18:26:30 -0000 Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v28IQUdU13500678 for ; Wed, 8 Mar 2017 18:26:30 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C5707AE045 for ; Wed, 8 Mar 2017 18:26:20 +0000 (GMT) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AA29FAE056 for ; Wed, 8 Mar 2017 18:26:20 +0000 (GMT) Received: from oc1027705133.ibm.com (unknown [9.152.212.162]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTPS for ; Wed, 8 Mar 2017 18:26:20 +0000 (GMT) From: Andreas Arnez To: gdb-patches@sourceware.org Subject: [PATCH] PR gdb/21226: Take DWARF stack value pieces from LSB end Date: Wed, 08 Mar 2017 19:26:26 +0100 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 17030818-0040-0000-0000-0000035A3356 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17030818-0041-0000-0000-00001F2E7776 Message-Id: X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-03-08_13:, , 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-1702020001 definitions=main-1703080145 X-IsSubscribed: yes When taking a DW_OP_piece or DW_OP_bit_piece from a DW_OP_stack_value, the existing logic always takes the piece from the lowest-addressed end, which is wrong on big-endian targets. The DWARF standard states that the "DW_OP_bit_piece operation describes a sequence of bits using the least significant bits of that value", and this also matches the current logic in GCC. For instance, the GCC guality test case pr54970.c fails on s390x because of this. This fix adjusts the piece accordingly on big-endian targets. It is assumed that: * DW_OP_piece shall take the piece from the LSB end as well; * pieces reaching outside the stack value bits are considered undefined, and a zero value can be used instead. The new logic also respects the DW_OP_bit_piece offset for DW_OP_stack_values. Previously the offset was ignored. Note that it is still ignored for all other types of DWARF pieces. gdb/ChangeLog: PR gdb/21226 * dwarf2loc.c (read_pieced_value): Anchor stack value pieces at the LSB end, independent of endianness. gdb/testsuite/ChangeLog: PR gdb/21226 * gdb.dwarf2/nonvar-access.exp: Add checks for verifying that stack value pieces are taken from the LSB end. --- gdb/dwarf2loc.c | 38 +++++++++++++----------------- gdb/testsuite/gdb.dwarf2/nonvar-access.exp | 21 ++++++++++++++--- 2 files changed, 35 insertions(+), 24 deletions(-) diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c index 4393c1f..764b3fb 100644 --- a/gdb/dwarf2loc.c +++ b/gdb/dwarf2loc.c @@ -1868,22 +1868,19 @@ read_pieced_value (struct value *v) case DWARF_VALUE_STACK: { - size_t n = this_size; + ULONGEST obj_size = 8 * TYPE_LENGTH (value_type (p->v.value)); - if (n > c->addr_size - source_offset) - n = (c->addr_size >= source_offset - ? c->addr_size - source_offset - : 0); - if (n == 0) - { - /* Nothing. */ - } - else - { - const gdb_byte *val_bytes = value_contents_all (p->v.value); + /* Use zeroes if piece reaches beyond stack value. */ + if (p->offset + p->size > obj_size) + goto skip_copy; - intermediate_buffer = val_bytes + source_offset; - } + /* Piece offset is from least significant bit end. */ + if (bits_big_endian) + source_offset_bits += obj_size - (p->offset + p->size); + else + source_offset_bits += p->offset; + intermediate_buffer = value_contents_all (p->v.value); + intermediate_buffer += source_offset_bits / 8; } break; @@ -1903,22 +1900,21 @@ read_pieced_value (struct value *v) /* These bits show up as zeros -- but do not cause the value to be considered optimized-out. */ case DWARF_VALUE_IMPLICIT_POINTER: - break; + goto skip_copy; case DWARF_VALUE_OPTIMIZED_OUT: mark_value_bits_optimized_out (v, offset, this_size_bits); - break; + goto skip_copy; default: internal_error (__FILE__, __LINE__, _("invalid location type")); } - if (p->location != DWARF_VALUE_OPTIMIZED_OUT - && p->location != DWARF_VALUE_IMPLICIT_POINTER) - copy_bitwise (contents, dest_offset_bits, - intermediate_buffer, source_offset_bits % 8, - this_size_bits, bits_big_endian); + copy_bitwise (contents, dest_offset_bits, + intermediate_buffer, source_offset_bits % 8, + this_size_bits, bits_big_endian); + skip_copy: offset += this_size_bits; } } diff --git a/gdb/testsuite/gdb.dwarf2/nonvar-access.exp b/gdb/testsuite/gdb.dwarf2/nonvar-access.exp index 3cb5c49..69e01ca 100644 --- a/gdb/testsuite/gdb.dwarf2/nonvar-access.exp +++ b/gdb/testsuite/gdb.dwarf2/nonvar-access.exp @@ -128,14 +128,26 @@ Dwarf::assemble $asm_file { {name def_t} {type :$struct_t_label} {location { - const1u 0 + const2s -184 stack_value bit_piece 9 0 - const1s -1 + const4u 1752286 stack_value bit_piece 23 0 } SPECIAL_expr} } + # Composite location with some empty pieces. + DW_TAG_variable { + {name part_def_a} + {type :$array_a9_label} + {location { + piece 3 + const4u 0xf1927314 + stack_value + piece 4 + piece 2 + } SPECIAL_expr} + } # Implicit location: immediate value. DW_TAG_variable { {name def_implicit_s} @@ -197,9 +209,12 @@ gdb_test "print/x *(char (*)\[5\]) implicit_a_ptr" \ # Byte-aligned fields, pieced together from DWARF stack values. gdb_test "print def_s" " = \\{a = 0, b = -1\\}" +switch $endian { big {set val 0x92} little {set val 0x73} } +gdb_test "print/x part_def_a\[4\]" " = $val" +gdb_test "print/x part_def_a\[8\]" " = " # Non-byte-aligned fields, pieced together from DWARF stack values. -gdb_test "print def_t" " = \\{a = 0, b = -1\\}" +gdb_test "print def_t" " = \\{a = -184, b = 1752286\\}" # Simple variable without location. gdb_test "print undef_int" " = "