Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Andreas Arnez <arnez@linux.vnet.ibm.com>
To: gdb-patches@sourceware.org
Subject: [PATCH v2 10/19] write_pieced_value: Transfer least significant bits into bit-field
Date: Tue, 09 May 2017 17:53:00 -0000	[thread overview]
Message-ID: <1494352015-10465-11-git-send-email-arnez@linux.vnet.ibm.com> (raw)
In-Reply-To: <1494352015-10465-1-git-send-email-arnez@linux.vnet.ibm.com>

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<gdb_byte> 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<gdb_byte> 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;
-- 
2.5.0


  parent reply	other threads:[~2017-05-09 17:53 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-09 17:47 [PATCH v2 00/19] Various DWARF piece fixes Andreas Arnez
2017-05-09 17:47 ` [PATCH v2 01/19] Add test for modifiable DWARF locations Andreas Arnez
2017-05-11 21:22   ` Yao Qi
2017-05-09 17:48 ` [PATCH v2 02/19] write_pieced_value: Fix size capping logic Andreas Arnez
2017-05-11 21:26   ` Yao Qi
2017-05-09 17:49 ` [PATCH v2 04/19] Remove addr_size field from struct piece_closure Andreas Arnez
2017-05-11 21:29   ` Yao Qi
2017-05-09 17:49 ` [PATCH v2 03/19] PR gdb/21226: Take DWARF stack value pieces from LSB end Andreas Arnez
2017-05-15  9:32   ` Yao Qi
2017-05-15 16:35     ` Andreas Arnez
2017-05-16  7:53       ` Yao Qi
     [not found]         ` <m34lwlf2cq.fsf@oc1027705133.ibm.com>
2017-05-16 13:50           ` Yao Qi
2017-05-09 17:50 ` [PATCH v2 05/19] gdb/testsuite: Add "get_endianness" convenience proc Andreas Arnez
2017-05-11 21:32   ` Yao Qi
2017-05-09 17:51 ` [PATCH v2 07/19] write_pieced_value: Fix copy/paste error in size calculation Andreas Arnez
2017-05-16  8:29   ` Yao Qi
2017-05-09 17:51 ` [PATCH v2 06/19] read/write_pieced_value: Respect value parent's offset Andreas Arnez
2017-05-16  8:18   ` Yao Qi
2017-05-09 17:52 ` [PATCH v2 08/19] write_pieced_value: Include transfer size in byte-wise check Andreas Arnez
2017-05-16  8:32   ` Yao Qi
2017-05-16 13:45     ` Andreas Arnez
2017-05-09 17:53 ` Andreas Arnez [this message]
2017-05-16  9:14   ` [PATCH v2 10/19] write_pieced_value: Transfer least significant bits into bit-field Yao Qi
2017-05-09 17:53 ` [PATCH v2 09/19] write_pieced_value: Fix buffer offset for memory pieces Andreas Arnez
2017-05-16  8:46   ` Yao Qi
2017-05-09 17:54 ` [PATCH v2 11/19] Add DWARF piece test cases for bit-field access Andreas Arnez
2017-05-16 13:52   ` Yao Qi
2017-05-09 17:55 ` [PATCH v2 12/19] read/write_pieced_value: Drop 'buffer_size' variable Andreas Arnez
2017-05-16 14:08   ` Yao Qi
2017-05-16 17:51     ` Andreas Arnez
2017-05-09 17:55 ` [PATCH v2 13/19] Fix handling of DWARF register pieces on big-endian targets Andreas Arnez
2017-06-12 13:12   ` Yao Qi
2017-05-09 17:56 ` [PATCH v2 14/19] read/write_pieced_value: Improve logic for buffer allocation Andreas Arnez
2017-06-12 13:28   ` Yao Qi
2017-06-12 19:40   ` Simon Marchi
2017-06-13 12:10     ` Andreas Arnez
2017-06-13 12:18       ` Pedro Alves
2017-06-13 14:41         ` Andreas Arnez
2017-05-09 17:57 ` [PATCH v2 15/19] Respect piece offset for DW_OP_bit_piece Andreas Arnez
2017-05-16 21:08   ` Yao Qi
2017-05-09 17:58 ` [PATCH v2 17/19] Fix bit-/byte-offset mismatch in parameter to read_value_memory Andreas Arnez
2017-05-30 19:59   ` Simon Marchi
2017-05-31 14:02     ` Andreas Arnez
2017-05-31 14:30       ` Simon Marchi
2017-05-09 17:58 ` [PATCH v2 16/19] read/write_pieced_value: Remove unnecessary variable copies Andreas Arnez
2017-06-12 13:50   ` Yao Qi
2017-05-09 17:59 ` [PATCH v2 18/19] write_pieced_value: Notify memory_changed observers Andreas Arnez
2017-05-16 21:12   ` Yao Qi
2017-05-09 18:00 ` [PATCH v2 19/19] read/write_pieced_value: Merge into one function Andreas Arnez
2017-06-12 13:57   ` Yao Qi
2017-06-12 14:34     ` Andreas Arnez
2017-06-13  9:17       ` Yao Qi
2017-05-30 16:42 ` [ping] [PATCH v2 00/19] Various DWARF piece fixes Andreas Arnez
2017-05-30 20:44 ` Simon Marchi
2017-05-31 14:24   ` Andreas Arnez
2017-06-12 11:38     ` Andreas Arnez

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=1494352015-10465-11-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