public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Andreas Arnez <arnez@linux.vnet.ibm.com>
To: gdb-patches@sourceware.org
Subject: [PATCH v2 03/19] PR gdb/21226: Take DWARF stack value pieces from LSB end
Date: Tue, 09 May 2017 17:49:00 -0000	[thread overview]
Message-ID: <1494352015-10465-4-git-send-email-arnez@linux.vnet.ibm.com> (raw)
In-Reply-To: <1494352015-10465-1-git-send-email-arnez@linux.vnet.ibm.com>

When taking a DW_OP_piece or DW_OP_bit_piece from a DW_OP_stack_value, the
existing logic always takes the piece from the lowest-addressed end, which
is wrong on big-endian targets.  The DWARF standard states that the
"DW_OP_bit_piece operation describes a sequence of bits using the least
significant bits of that value", and this also matches the current logic
in GCC.  For instance, the GCC guality test case pr54970.c fails on s390x
because of this.

This fix adjusts the piece accordingly on big-endian targets.  It is
assumed that:

* DW_OP_piece shall take the piece from the LSB end as well;

* pieces reaching outside the stack value bits are considered undefined,
  and a zero value can be used instead.

gdb/ChangeLog:

	PR gdb/21226
	* dwarf2loc.c (read_pieced_value): Anchor stack value pieces at
	the LSB end, independent of endianness.

gdb/testsuite/ChangeLog:

	PR gdb/21226
	* gdb.dwarf2/nonvar-access.exp: Add checks for verifying that
	stack value pieces are taken from the LSB end.
---
 gdb/dwarf2loc.c                            | 46 +++++++++++++++++-------------
 gdb/testsuite/gdb.dwarf2/nonvar-access.exp | 21 ++++++++++++--
 2 files changed, 44 insertions(+), 23 deletions(-)

diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c
index 2a45a79..061ec6d 100644
--- a/gdb/dwarf2loc.c
+++ b/gdb/dwarf2loc.c
@@ -1858,6 +1858,10 @@ read_pieced_value (struct value *v)
 		if (unavail)
 		  mark_value_bits_unavailable (v, offset, this_size_bits);
 	      }
+
+	    copy_bitwise (contents, dest_offset_bits,
+			  intermediate_buffer, source_offset_bits % 8,
+			  this_size_bits, bits_big_endian);
 	  }
 	  break;
 
@@ -1866,26 +1870,30 @@ read_pieced_value (struct value *v)
 			     p->v.mem.in_stack_memory,
 			     p->v.mem.addr + source_offset,
 			     buffer.data (), this_size);
+	  copy_bitwise (contents, dest_offset_bits,
+			intermediate_buffer, source_offset_bits % 8,
+			this_size_bits, bits_big_endian);
 	  break;
 
 	case DWARF_VALUE_STACK:
 	  {
-	    size_t n = this_size;
+	    struct objfile *objfile = dwarf2_per_cu_objfile (c->per_cu);
+	    struct gdbarch *objfile_gdbarch = get_objfile_arch (objfile);
+	    ULONGEST stack_value_size_bits
+	      = 8 * TYPE_LENGTH (value_type (p->v.value));
 
-	    if (n > c->addr_size - source_offset)
-	      n = (c->addr_size >= source_offset
-		   ? c->addr_size - source_offset
-		   : 0);
-	    if (n == 0)
-	      {
-		/* Nothing.  */
-	      }
-	    else
-	      {
-		const gdb_byte *val_bytes = value_contents_all (p->v.value);
+	    /* Use zeroes if piece reaches beyond stack value.  */
+	    if (p->size > stack_value_size_bits)
+	      break;
 
-		intermediate_buffer = val_bytes + source_offset;
-	      }
+	    /* 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->size;
+
+	    copy_bitwise (contents, dest_offset_bits,
+			  value_contents_all (p->v.value),
+			  source_offset_bits,
+			  this_size_bits, bits_big_endian);
 	  }
 	  break;
 
@@ -1899,6 +1907,10 @@ read_pieced_value (struct value *v)
 		   : 0);
 	    if (n != 0)
 	      intermediate_buffer = p->v.literal.data + source_offset;
+
+	    copy_bitwise (contents, dest_offset_bits,
+			  intermediate_buffer, source_offset_bits % 8,
+			  this_size_bits, bits_big_endian);
 	  }
 	  break;
 
@@ -1915,12 +1927,6 @@ read_pieced_value (struct value *v)
 	  internal_error (__FILE__, __LINE__, _("invalid location type"));
 	}
 
-      if (p->location != DWARF_VALUE_OPTIMIZED_OUT
-	  && p->location != DWARF_VALUE_IMPLICIT_POINTER)
-	copy_bitwise (contents, dest_offset_bits,
-		      intermediate_buffer, source_offset_bits % 8,
-		      this_size_bits, bits_big_endian);
-
       offset += this_size_bits;
     }
 }
diff --git a/gdb/testsuite/gdb.dwarf2/nonvar-access.exp b/gdb/testsuite/gdb.dwarf2/nonvar-access.exp
index 99f63cc..5406029 100644
--- a/gdb/testsuite/gdb.dwarf2/nonvar-access.exp
+++ b/gdb/testsuite/gdb.dwarf2/nonvar-access.exp
@@ -128,14 +128,26 @@ Dwarf::assemble $asm_file {
 		    {name def_t}
 		    {type :$struct_t_label}
 		    {location {
-			const1u 0
+			const2s -184
 			stack_value
 			bit_piece 9 0
-			const1s -1
+			const4u 1752286
 			stack_value
 			bit_piece 23 0
 		    } SPECIAL_expr}
 		}
+		# Composite location with some empty pieces.
+		DW_TAG_variable {
+		    {name part_def_a}
+		    {type :$array_a9_label}
+		    {location {
+			piece 3
+			const4u 0xf1927314
+			stack_value
+			piece 4
+			piece 2
+		    } SPECIAL_expr}
+		}
 		# Implicit location: immediate value.
 		DW_TAG_variable {
 		    {name def_implicit_s}
@@ -221,9 +233,12 @@ gdb_test "print/x *implicit_b_ptr" " = $val"
 
 # Byte-aligned fields, pieced together from DWARF stack values.
 gdb_test "print def_s" " = \\{a = 0, b = -1\\}"
+switch $endian { big {set val 0x92} little {set val 0x73} }
+gdb_test "print/x part_def_a\[4\]" " = $val"
+gdb_test "print/x part_def_a\[8\]" " = <optimized out>"
 
 # Non-byte-aligned fields, pieced together from DWARF stack values.
-gdb_test "print def_t" " = \\{a = 0, b = -1\\}"
+gdb_test "print def_t" " = \\{a = -184, b = 1752286\\}"
 
 # Simple variable without location.
 gdb_test "print undef_int" " = <optimized out>"
-- 
2.5.0

  parent reply	other threads:[~2017-05-09 17:49 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 ` Andreas Arnez [this message]
2017-05-15  9:32   ` [PATCH v2 03/19] PR gdb/21226: Take DWARF stack value pieces from LSB end 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 ` [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:53 ` [PATCH v2 10/19] write_pieced_value: Transfer least significant bits into bit-field Andreas Arnez
2017-05-16  9:14   ` 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 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: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: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 16/19] read/write_pieced_value: Remove unnecessary variable copies Andreas Arnez
2017-06-12 13:50   ` 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: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-4-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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).