From patchwork Tue May 9 17:46:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Arnez X-Patchwork-Id: 20352 Received: (qmail 124920 invoked by alias); 9 May 2017 17:58:00 -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 124890 invoked by uid 89); 9 May 2017 17:58:00 -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:58 +0000 Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v49Hrp50013352 for ; Tue, 9 May 2017 13:57:59 -0400 Received: from e06smtp11.uk.ibm.com (e06smtp11.uk.ibm.com [195.75.94.107]) by mx0a-001b2d01.pphosted.com with ESMTP id 2abhb9k26r-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 09 May 2017 13:57:59 -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:56 +0100 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) 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:54 +0100 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v49Hvs1s33423478 for ; Tue, 9 May 2017 17:57:54 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6B6C052043 for ; Tue, 9 May 2017 17:55:17 +0100 (BST) Received: from oc1027705133.ibm.com (unknown [9.152.212.109]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id 518CC52041 for ; Tue, 9 May 2017 17:55:17 +0100 (BST) From: Andreas Arnez To: gdb-patches@sourceware.org Subject: [PATCH v2 16/19] read/write_pieced_value: Remove unnecessary variable copies Date: Tue, 9 May 2017 19:46:12 +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-000003A3C595 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17050917-0041-0000-0000-0000200C99B9 Message-Id: <1494352015-10465-17-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 In read_pieced_value's main loop, the variables `dest_offset_bits' and `source_offset_bits' are basically just copies of `offset' and `bits_to_skip', respectively. In write_pieced_value the copies are reversed. This is not very helpful when trying to keep the logic between these functions in sync. Since the copies are unnecessary, this patch just removes them. gdb/ChangeLog: * dwarf2loc.c (read_pieced_value): Remove unnecessary variables dest_offset_bits and source_offset_bits. (write_pieced_value): Likewise. --- gdb/dwarf2loc.c | 120 ++++++++++++++++++++++++-------------------------------- 1 file changed, 52 insertions(+), 68 deletions(-) diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c index 23901f0e7..ed5b29c 100644 --- a/gdb/dwarf2loc.c +++ b/gdb/dwarf2loc.c @@ -1790,25 +1790,16 @@ read_pieced_value (struct value *v) else max_offset = 8 * TYPE_LENGTH (value_type (v)); - for (i = 0; i < c->n_pieces && offset < max_offset; i++) + /* Advance to the first non-skipped piece. */ + for (i = 0; i < c->n_pieces && bits_to_skip >= c->pieces[i].size; i++) + bits_to_skip -= c->pieces[i].size; + + for (; i < c->n_pieces && offset < max_offset; i++) { struct dwarf_expr_piece *p = &c->pieces[i]; size_t this_size, this_size_bits; - long dest_offset_bits, source_offset_bits; - - /* Compute size, source, and destination offsets for copying, in - bits. */ - this_size_bits = p->size; - if (bits_to_skip > 0 && bits_to_skip >= this_size_bits) - { - bits_to_skip -= this_size_bits; - continue; - } - source_offset_bits = bits_to_skip; - this_size_bits -= bits_to_skip; - bits_to_skip = 0; - dest_offset_bits = offset; + this_size_bits = p->size - bits_to_skip; if (this_size_bits > max_offset - offset) this_size_bits = max_offset - offset; @@ -1827,16 +1818,16 @@ read_pieced_value (struct value *v) && p->offset + p->size < reg_bits) { /* Big-endian, and we want less than full size. */ - source_offset_bits += reg_bits - (p->offset + p->size); + bits_to_skip += reg_bits - (p->offset + p->size); } else - source_offset_bits += p->offset; + bits_to_skip += p->offset; - this_size = bits_to_bytes (source_offset_bits, this_size_bits); + this_size = bits_to_bytes (bits_to_skip, this_size_bits); buffer.reserve (this_size); if (!get_frame_register_bytes (frame, gdb_regnum, - source_offset_bits / 8, + bits_to_skip / 8, this_size, buffer.data (), &optim, &unavail)) { @@ -1846,24 +1837,23 @@ read_pieced_value (struct value *v) mark_value_bits_unavailable (v, offset, this_size_bits); break; } - - copy_bitwise (contents, dest_offset_bits, - buffer.data (), source_offset_bits % 8, + copy_bitwise (contents, offset, + buffer.data (), bits_to_skip % 8, this_size_bits, bits_big_endian); } break; case DWARF_VALUE_MEMORY: - source_offset_bits += p->offset; - this_size = bits_to_bytes (source_offset_bits, this_size_bits); + bits_to_skip += p->offset; + this_size = bits_to_bytes (bits_to_skip, this_size_bits); buffer.reserve (this_size); read_value_memory (v, offset, p->v.mem.in_stack_memory, - p->v.mem.addr + source_offset_bits / 8, + p->v.mem.addr + bits_to_skip / 8, buffer.data (), this_size); - copy_bitwise (contents, dest_offset_bits, - buffer.data (), source_offset_bits % 8, + copy_bitwise (contents, offset, + buffer.data (), bits_to_skip % 8, this_size_bits, bits_big_endian); break; @@ -1880,14 +1870,13 @@ read_pieced_value (struct value *v) /* 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->offset - p->size); + bits_to_skip += stack_value_size_bits - p->offset - p->size; else - source_offset_bits += p->offset; + bits_to_skip += p->offset; - copy_bitwise (contents, dest_offset_bits, + copy_bitwise (contents, offset, value_contents_all (p->v.value), - source_offset_bits, + bits_to_skip, this_size_bits, bits_big_endian); } break; @@ -1898,14 +1887,14 @@ 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) + bits_to_skip += p->offset; + if (bits_to_skip >= literal_size_bits) break; - if (n > literal_size_bits - source_offset_bits) - n = literal_size_bits - source_offset_bits; + if (n > literal_size_bits - bits_to_skip) + n = literal_size_bits - bits_to_skip; - copy_bitwise (contents, dest_offset_bits, - p->v.literal.data, source_offset_bits, + copy_bitwise (contents, offset, + p->v.literal.data, bits_to_skip, n, bits_big_endian); } break; @@ -1924,6 +1913,7 @@ read_pieced_value (struct value *v) } offset += this_size_bits; + bits_to_skip = 0; } } @@ -1959,23 +1949,16 @@ write_pieced_value (struct value *to, struct value *from) else max_offset = 8 * TYPE_LENGTH (value_type (to)); - for (i = 0; i < c->n_pieces && offset < max_offset; i++) + /* Advance to the first non-skipped piece. */ + for (i = 0; i < c->n_pieces && bits_to_skip >= c->pieces[i].size; i++) + bits_to_skip -= c->pieces[i].size; + + for (; i < c->n_pieces && offset < max_offset; i++) { struct dwarf_expr_piece *p = &c->pieces[i]; size_t this_size_bits, this_size; - long dest_offset_bits, source_offset_bits; - - this_size_bits = p->size; - if (bits_to_skip > 0 && bits_to_skip >= this_size_bits) - { - bits_to_skip -= this_size_bits; - continue; - } - dest_offset_bits = bits_to_skip; - this_size_bits -= bits_to_skip; - bits_to_skip = 0; - source_offset_bits = offset; + this_size_bits = p->size - bits_to_skip; if (this_size_bits > max_offset - offset) this_size_bits = max_offset - offset; @@ -1992,22 +1975,22 @@ write_pieced_value (struct value *to, struct value *from) && p->offset + p->size < reg_bits) { /* Big-endian, and we want less than full size. */ - dest_offset_bits += reg_bits - (p->offset + p->size); + bits_to_skip += reg_bits - (p->offset + p->size); } else - dest_offset_bits += p->offset; + bits_to_skip += p->offset; - this_size = bits_to_bytes (dest_offset_bits, this_size_bits); + this_size = bits_to_bytes (bits_to_skip, this_size_bits); buffer.reserve (this_size); - if (dest_offset_bits % 8 != 0 || this_size_bits % 8 != 0) + if (bits_to_skip % 8 != 0 || this_size_bits % 8 != 0) { /* Data is copied non-byte-aligned into the register. Need some bits from original register value. */ int optim, unavail; if (!get_frame_register_bytes (frame, gdb_regnum, - dest_offset_bits / 8, + bits_to_skip / 8, this_size, buffer.data (), &optim, &unavail)) { @@ -2024,34 +2007,34 @@ write_pieced_value (struct value *to, struct value *from) } } - copy_bitwise (buffer.data (), dest_offset_bits % 8, - contents, source_offset_bits, + copy_bitwise (buffer.data (), bits_to_skip % 8, + contents, offset, this_size_bits, bits_big_endian); put_frame_register_bytes (frame, gdb_regnum, - dest_offset_bits / 8, + bits_to_skip / 8, this_size, buffer.data ()); } break; case DWARF_VALUE_MEMORY: { - dest_offset_bits += p->offset; + bits_to_skip += p->offset; - CORE_ADDR start_addr = p->v.mem.addr + dest_offset_bits / 8; + CORE_ADDR start_addr = p->v.mem.addr + bits_to_skip / 8; - if (dest_offset_bits % 8 == 0 && this_size_bits % 8 == 0 - && source_offset_bits % 8 == 0) + if (bits_to_skip % 8 == 0 && this_size_bits % 8 == 0 + && offset % 8 == 0) { /* Everything is byte-aligned; no buffer needed. */ write_memory (start_addr, - contents + source_offset_bits / 8, + contents + offset / 8, this_size_bits / 8); break; } - this_size = bits_to_bytes (dest_offset_bits, this_size_bits); + this_size = bits_to_bytes (bits_to_skip, this_size_bits); buffer.reserve (this_size); - if (dest_offset_bits % 8 != 0 || this_size_bits % 8 != 0) + if (bits_to_skip % 8 != 0 || this_size_bits % 8 != 0) { if (this_size <= 8) { @@ -2068,8 +2051,8 @@ write_pieced_value (struct value *to, struct value *from) } } - copy_bitwise (buffer.data (), dest_offset_bits % 8, - contents, source_offset_bits, + copy_bitwise (buffer.data (), bits_to_skip % 8, + contents, offset, this_size_bits, bits_big_endian); write_memory (start_addr, buffer.data (), this_size); } @@ -2079,6 +2062,7 @@ write_pieced_value (struct value *to, struct value *from) break; } offset += this_size_bits; + bits_to_skip = 0; } }