From: Andreas Arnez <arnez@linux.vnet.ibm.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 9/9] Remove unnecessary copies of variables in read/write_pieced_value
Date: Fri, 07 Apr 2017 17:45:00 -0000 [thread overview]
Message-ID: <1491586736-21296-10-git-send-email-arnez@linux.vnet.ibm.com> (raw)
In-Reply-To: <1491586736-21296-1-git-send-email-arnez@linux.vnet.ibm.com>
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;
}
}
--
2.3.0
next prev parent reply other threads:[~2017-04-07 17:45 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-07 17:39 [PATCH 0/9] Various DWARF piece fixes Andreas Arnez
2017-04-07 17:39 ` [PATCH 1/9] Add test for modifiable DWARF locations Andreas Arnez
2017-04-13 4:00 ` Simon Marchi
2017-04-13 10:52 ` Andreas Arnez
2017-04-13 8:36 ` Yao Qi
2017-04-13 11:46 ` Andreas Arnez
2017-04-07 17:40 ` [PATCH 2/9] Fix size capping in write_pieced_value Andreas Arnez
2017-04-13 8:18 ` Yao Qi
2017-04-13 16:35 ` Andreas Arnez
2017-04-19 9:15 ` Yao Qi
2017-04-19 14:36 ` Andreas Arnez
2017-04-19 15:00 ` Yao Qi
2017-04-07 17:41 ` [PATCH 3/9] PR gdb/21226: Take DWARF stack value pieces from LSB end Andreas Arnez
2017-04-14 3:36 ` Simon Marchi
2017-04-18 16:32 ` Andreas Arnez
2017-04-18 16:43 ` Simon Marchi
2017-04-07 17:41 ` [PATCH 4/9] Remove addr_size field from struct piece_closure Andreas Arnez
2017-04-13 9:10 ` Yao Qi
2017-04-14 3:39 ` Simon Marchi
2017-04-18 17:25 ` Andreas Arnez
2017-04-18 18:49 ` Simon Marchi
2017-04-07 17:42 ` [PATCH 5/9] Fix issues in write_pieced_value when targeting bit-fields Andreas Arnez
2017-04-14 5:18 ` Simon Marchi
2017-04-27 17:54 ` Andreas Arnez
2017-05-03 13:59 ` Simon Marchi
2017-04-07 17:43 ` [PATCH 6/9] Fix handling of DWARF register pieces on big-endian targets Andreas Arnez
2017-04-14 14:11 ` Simon Marchi
2017-04-19 18:03 ` Andreas Arnez
2017-04-07 17:43 ` [PATCH 7/9] Improve logic for buffer allocation in read/write_pieced_value Andreas Arnez
2017-04-14 14:51 ` Simon Marchi
2017-04-07 17:44 ` [PATCH 8/9] Respect piece offset for DW_OP_bit_piece Andreas Arnez
2017-04-14 15:07 ` Simon Marchi
2017-04-07 17:45 ` Andreas Arnez [this message]
2017-04-14 15:21 ` [PATCH 9/9] Remove unnecessary copies of variables in read/write_pieced_value Simon Marchi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1491586736-21296-10-git-send-email-arnez@linux.vnet.ibm.com \
--to=arnez@linux.vnet.ibm.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox