From patchwork Fri Apr 7 17:38:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Arnez X-Patchwork-Id: 19903 Received: (qmail 5429 invoked by alias); 7 Apr 2017 17:45:44 -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 4811 invoked by uid 89); 7 Apr 2017 17:45:18 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.3 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; Fri, 07 Apr 2017 17:45:16 +0000 Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v37HhZWL009752 for ; Fri, 7 Apr 2017 13:45:11 -0400 Received: from e06smtp12.uk.ibm.com (e06smtp12.uk.ibm.com [195.75.94.108]) by mx0a-001b2d01.pphosted.com with ESMTP id 29pev5sc8p-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Fri, 07 Apr 2017 13:45:11 -0400 Received: from localhost by e06smtp12.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 7 Apr 2017 18:45:09 +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; Fri, 7 Apr 2017 18:45:08 +0100 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v37Hj7mv37159104 for ; Fri, 7 Apr 2017 17:45:07 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1554711C05B for ; Fri, 7 Apr 2017 18:44:29 +0100 (BST) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EA11811C04C for ; Fri, 7 Apr 2017 18:44:28 +0100 (BST) Received: from oc1027705133.ibm.com (unknown [9.152.212.162]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Fri, 7 Apr 2017 18:44:28 +0100 (BST) From: Andreas Arnez To: gdb-patches@sourceware.org Subject: [PATCH 9/9] Remove unnecessary copies of variables in read/write_pieced_value Date: Fri, 7 Apr 2017 19:38:16 +0200 In-Reply-To: <1491586736-21296-1-git-send-email-arnez@linux.vnet.ibm.com> References: <1491586736-21296-1-git-send-email-arnez@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17040717-0008-0000-0000-0000041FA1B7 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17040717-0009-0000-0000-00001D2B8AA7 Message-Id: <1491586736-21296-10-git-send-email-arnez@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-04-07_15:, , 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-1704070145 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 | 118 +++++++++++++++++++++++++------------------------------- 1 file changed, 52 insertions(+), 66 deletions(-) diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c index 045c2d3..d7bd166 100644 --- a/gdb/dwarf2loc.c +++ b/gdb/dwarf2loc.c @@ -1790,25 +1790,16 @@ read_pieced_value (struct value *v) else type_len = 8 * TYPE_LENGTH (value_type (v)); - for (i = 0; i < c->n_pieces && offset < type_len; 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 < type_len; 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 > type_len - offset) this_size_bits = type_len - offset; @@ -1827,15 +1818,15 @@ 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; - 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); if (!get_frame_register_bytes (frame, gdb_regnum, - source_offset_bits / 8, + bits_to_skip / 8, this_size, buffer.data (), &optim, &unavail)) { @@ -1845,23 +1836,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; @@ -1877,12 +1868,12 @@ 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 += obj_size - (p->offset + p->size); + bits_to_skip += obj_size - (p->offset + p->size); else - source_offset_bits += p->offset; - copy_bitwise (contents, dest_offset_bits, + bits_to_skip += p->offset; + copy_bitwise (contents, offset, value_contents_all (p->v.value), - source_offset_bits, + bits_to_skip, this_size_bits, bits_big_endian); } break; @@ -1893,14 +1884,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 >= obj_size) + bits_to_skip += p->offset; + if (bits_to_skip >= obj_size) break; - if (n > obj_size - source_offset_bits) - n = obj_size - source_offset_bits; + if (n > obj_size - bits_to_skip) + n = obj_size - 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; @@ -1919,6 +1910,7 @@ read_pieced_value (struct value *v) } offset += this_size_bits; + bits_to_skip = 0; } } @@ -1954,23 +1946,16 @@ write_pieced_value (struct value *to, struct value *from) else type_len = 8 * TYPE_LENGTH (value_type (to)); - for (i = 0; i < c->n_pieces && offset < type_len; 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 < type_len; 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 > type_len - offset) this_size_bits = type_len - offset; @@ -1987,20 +1972,20 @@ 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; - this_size = bits_to_bytes (dest_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); - if (dest_offset_bits % 8 != 0 || this_size_bits % 8 != 0) + if (bits_to_skip % 8 != 0 || this_size_bits % 8 != 0) { /* 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)) { @@ -2017,34 +2002,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) { @@ -2061,8 +2046,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); } @@ -2072,6 +2057,7 @@ write_pieced_value (struct value *to, struct value *from) break; } offset += this_size_bits; + bits_to_skip = 0; } }