From patchwork Tue May 9 17:46:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Arnez X-Patchwork-Id: 20346 Received: (qmail 116723 invoked by alias); 9 May 2017 17:53:51 -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 116710 invoked by uid 89); 9 May 2017 17:53:50 -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=Mirror 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:53:49 +0000 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v49Hrf3x041375 for ; Tue, 9 May 2017 13:53:50 -0400 Received: from e06smtp12.uk.ibm.com (e06smtp12.uk.ibm.com [195.75.94.108]) by mx0a-001b2d01.pphosted.com with ESMTP id 2aavru0tsh-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 09 May 2017 13:53:50 -0400 Received: from localhost by e06smtp12.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 9 May 2017 18:53:48 +0100 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp12.uk.ibm.com (192.168.101.142) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 9 May 2017 18:53:47 +0100 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v49HrkDD15991106 for ; Tue, 9 May 2017 17:53:47 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AE45852043 for ; Tue, 9 May 2017 17:51:10 +0100 (BST) Received: from oc1027705133.ibm.com (unknown [9.152.212.109]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id 94AB152041 for ; Tue, 9 May 2017 17:51:10 +0100 (BST) From: Andreas Arnez To: gdb-patches@sourceware.org Subject: [PATCH v2 10/19] write_pieced_value: Transfer least significant bits into bit-field Date: Tue, 9 May 2017 19:46:06 +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-0008-0000-0000-000004418951 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17050917-0009-0000-0000-00001D99A851 Message-Id: <1494352015-10465-11-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 On big-endian targets, when targeting a bit-field, write_pieced_value currently transfers the source value's *most* significant bits to the target value, instead of its least significant bits. This is fixed. In particular the fix adjusts the initial value of 'offset', which can now potentially be nonzero. Thus the variable 'type_len' is renamed to 'max_offset', to avoid confusion. And for consistency, the affected logic that was mirrored in read_pieced_value is changed there in the same way. gdb/ChangeLog: * dwarf2loc.c (write_pieced_value): When writing to a bit-field, transfer the source value's least significant bits, instead of its lowest-addressed ones. Rename type_len to max_offset. (read_pieced_value): Mirror above changes to write_pieced_value as applicable. --- gdb/dwarf2loc.c | 70 +++++++++++++++++++++++++-------------------------------- 1 file changed, 31 insertions(+), 39 deletions(-) diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c index e1e1562..da0e8c3 100644 --- a/gdb/dwarf2loc.c +++ b/gdb/dwarf2loc.c @@ -1756,12 +1756,11 @@ static void read_pieced_value (struct value *v) { int i; - long offset = 0; + LONGEST offset = 0, max_offset; ULONGEST bits_to_skip; gdb_byte *contents; struct piece_closure *c = (struct piece_closure *) value_computed_closure (v); - size_t type_len; size_t buffer_size = 0; std::vector buffer; int bits_big_endian @@ -1778,12 +1777,12 @@ read_pieced_value (struct value *v) { bits_to_skip += (8 * value_offset (value_parent (v)) + value_bitpos (v)); - type_len = value_bitsize (v); + max_offset = value_bitsize (v); } else - type_len = 8 * TYPE_LENGTH (value_type (v)); + max_offset = 8 * TYPE_LENGTH (value_type (v)); - for (i = 0; i < c->n_pieces && offset < type_len; i++) + for (i = 0; i < c->n_pieces && offset < max_offset; i++) { struct dwarf_expr_piece *p = &c->pieces[i]; size_t this_size, this_size_bits; @@ -1798,20 +1797,13 @@ read_pieced_value (struct value *v) bits_to_skip -= this_size_bits; continue; } - if (bits_to_skip > 0) - { - dest_offset_bits = 0; - source_offset_bits = bits_to_skip; - this_size_bits -= bits_to_skip; - bits_to_skip = 0; - } - else - { - dest_offset_bits = offset; - source_offset_bits = 0; - } - if (this_size_bits > type_len - offset) - this_size_bits = type_len - offset; + source_offset_bits = bits_to_skip; + this_size_bits -= bits_to_skip; + bits_to_skip = 0; + dest_offset_bits = offset; + + if (this_size_bits > max_offset - offset) + this_size_bits = max_offset - offset; this_size = (this_size_bits + source_offset_bits % 8 + 7) / 8; source_offset = source_offset_bits / 8; @@ -1932,12 +1924,11 @@ static void write_pieced_value (struct value *to, struct value *from) { int i; - long offset = 0; ULONGEST bits_to_skip; + LONGEST offset = 0, max_offset; const gdb_byte *contents; struct piece_closure *c = (struct piece_closure *) value_computed_closure (to); - size_t type_len; size_t buffer_size = 0; std::vector buffer; int bits_big_endian @@ -1949,12 +1940,20 @@ write_pieced_value (struct value *to, struct value *from) { bits_to_skip += (8 * value_offset (value_parent (to)) + value_bitpos (to)); - type_len = value_bitsize (to); - } + /* Use the least significant bits of FROM. */ + if (gdbarch_byte_order (get_type_arch (value_type (from))) + == BFD_ENDIAN_BIG) + { + max_offset = 8 * TYPE_LENGTH (value_type (from)); + offset = max_offset - value_bitsize (to); + } + else + max_offset = value_bitsize (to); + } else - type_len = 8 * TYPE_LENGTH (value_type (to)); + max_offset = 8 * TYPE_LENGTH (value_type (to)); - for (i = 0; i < c->n_pieces && offset < type_len; i++) + for (i = 0; i < c->n_pieces && offset < max_offset; i++) { struct dwarf_expr_piece *p = &c->pieces[i]; size_t this_size_bits, this_size; @@ -1968,20 +1967,13 @@ write_pieced_value (struct value *to, struct value *from) bits_to_skip -= this_size_bits; continue; } - if (bits_to_skip > 0) - { - dest_offset_bits = bits_to_skip; - source_offset_bits = 0; - this_size_bits -= bits_to_skip; - bits_to_skip = 0; - } - else - { - dest_offset_bits = 0; - source_offset_bits = offset; - } - if (this_size_bits > type_len - offset) - this_size_bits = type_len - offset; + dest_offset_bits = bits_to_skip; + this_size_bits -= bits_to_skip; + bits_to_skip = 0; + source_offset_bits = offset; + + if (this_size_bits > max_offset - offset) + this_size_bits = max_offset - offset; this_size = (this_size_bits + dest_offset_bits % 8 + 7) / 8; source_offset = source_offset_bits / 8;