Blame SOURCES/gdb-rhbz1420304-s390x-23of35.patch

e1d87d
commit 65d84b76164dc8ec1a1f0f0e0fd41667065ffd4e
e1d87d
Author: Andreas Arnez <arnez@linux.vnet.ibm.com>
e1d87d
Date:   Tue Jun 13 15:20:31 2017 +0200
e1d87d
e1d87d
    Respect piece offset for DW_OP_bit_piece
e1d87d
    
e1d87d
    So far GDB ignores the piece offset of all kinds of DWARF bit
e1d87d
    pieces (DW_OP_bit_piece) and treats such pieces as if the offset was zero.
e1d87d
    
e1d87d
    This is fixed, and an appropriate test is added.
e1d87d
    
e1d87d
    gdb/ChangeLog:
e1d87d
    
e1d87d
            * dwarf2loc.c (read_pieced_value): Respect the piece offset, as
e1d87d
            given by DW_OP_bit_piece.
e1d87d
            (write_pieced_value): Likewise.
e1d87d
    
e1d87d
      Andreas Arnez  <arnez@linux.vnet.ibm.com>
e1d87d
    
e1d87d
            * gdb.dwarf2/var-access.exp: Add test for composite location with
e1d87d
            nonzero piece offsets.
e1d87d
e1d87d
### a/gdb/ChangeLog
e1d87d
### b/gdb/ChangeLog
e1d87d
## -1,5 +1,11 @@
e1d87d
 2017-06-13  Andreas Arnez  <arnez@linux.vnet.ibm.com>
e1d87d
 
e1d87d
+	* dwarf2loc.c (read_pieced_value): Respect the piece offset, as
e1d87d
+	given by DW_OP_bit_piece.
e1d87d
+	(write_pieced_value): Likewise.
e1d87d
+
e1d87d
+2017-06-13  Andreas Arnez  <arnez@linux.vnet.ibm.com>
e1d87d
+
e1d87d
 	* dwarf2loc.c (read_pieced_value): Move the buffer allocation and
e1d87d
 	some other preparations to the places where sufficient information
e1d87d
 	is available.
e1d87d
--- a/gdb/dwarf2loc.c
e1d87d
+++ b/gdb/dwarf2loc.c
e1d87d
@@ -1824,11 +1824,14 @@ read_pieced_value (struct value *v)
e1d87d
 	    int optim, unavail;
e1d87d
 
e1d87d
 	    if (gdbarch_byte_order (arch) == BFD_ENDIAN_BIG
e1d87d
-		&& p->size < reg_bits)
e1d87d
+		&& p->offset + p->size < reg_bits)
e1d87d
 	      {
e1d87d
 		/* Big-endian, and we want less than full size.  */
e1d87d
-		source_offset_bits += reg_bits - p->size;
e1d87d
+		source_offset_bits += reg_bits - (p->offset + p->size);
e1d87d
 	      }
e1d87d
+	    else
e1d87d
+	      source_offset_bits += p->offset;
e1d87d
+
e1d87d
 	    this_size = bits_to_bytes (source_offset_bits, this_size_bits);
e1d87d
 	    buffer.reserve (this_size);
e1d87d
 
e1d87d
@@ -1851,6 +1854,7 @@ read_pieced_value (struct value *v)
e1d87d
 	  break;
e1d87d
 
e1d87d
 	case DWARF_VALUE_MEMORY:
e1d87d
+	  source_offset_bits += p->offset;
e1d87d
 	  this_size = bits_to_bytes (source_offset_bits, this_size_bits);
e1d87d
 	  buffer.reserve (this_size);
e1d87d
 
e1d87d
@@ -1871,12 +1875,15 @@ read_pieced_value (struct value *v)
e1d87d
 	      = 8 * TYPE_LENGTH (value_type (p->v.value));
e1d87d
 
e1d87d
 	    /* Use zeroes if piece reaches beyond stack value.  */
e1d87d
-	    if (p->size > stack_value_size_bits)
e1d87d
+	    if (p->offset + p->size > stack_value_size_bits)
e1d87d
 	      break;
e1d87d
 
e1d87d
 	    /* Piece is anchored at least significant bit end.  */
e1d87d
 	    if (gdbarch_byte_order (objfile_gdbarch) == BFD_ENDIAN_BIG)
e1d87d
-	      source_offset_bits += stack_value_size_bits - p->size;
e1d87d
+	      source_offset_bits += (stack_value_size_bits
e1d87d
+				     - p->offset - p->size);
e1d87d
+	    else
e1d87d
+	      source_offset_bits += p->offset;
e1d87d
 
e1d87d
 	    copy_bitwise (contents, dest_offset_bits,
e1d87d
 			  value_contents_all (p->v.value),
e1d87d
@@ -1891,6 +1898,7 @@ read_pieced_value (struct value *v)
e1d87d
 	    size_t n = this_size_bits;
e1d87d
 
e1d87d
 	    /* Cut off at the end of the implicit value.  */
e1d87d
+	    source_offset_bits += p->offset;
e1d87d
 	    if (source_offset_bits >= literal_size_bits)
e1d87d
 	      break;
e1d87d
 	    if (n > literal_size_bits - source_offset_bits)
e1d87d
@@ -1981,11 +1989,14 @@ write_pieced_value (struct value *to, struct value *from)
e1d87d
 	    ULONGEST reg_bits = 8 * register_size (arch, gdb_regnum);
e1d87d
 
e1d87d
 	    if (gdbarch_byte_order (arch) == BFD_ENDIAN_BIG
e1d87d
-		&& p->size <= reg_bits)
e1d87d
+		&& p->offset + p->size < reg_bits)
e1d87d
 	      {
e1d87d
 		/* Big-endian, and we want less than full size.  */
e1d87d
-		dest_offset_bits += reg_bits - p->size;
e1d87d
+		dest_offset_bits += reg_bits - (p->offset + p->size);
e1d87d
 	      }
e1d87d
+	    else
e1d87d
+	      dest_offset_bits += p->offset;
e1d87d
+
e1d87d
 	    this_size = bits_to_bytes (dest_offset_bits, this_size_bits);
e1d87d
 	    buffer.reserve (this_size);
e1d87d
 
e1d87d
@@ -2023,6 +2034,8 @@ write_pieced_value (struct value *to, struct value *from)
e1d87d
 	  break;
e1d87d
 	case DWARF_VALUE_MEMORY:
e1d87d
 	  {
e1d87d
+	    dest_offset_bits += p->offset;
e1d87d
+
e1d87d
 	    CORE_ADDR start_addr = p->v.mem.addr + dest_offset_bits / 8;
e1d87d
 
e1d87d
 	    if (dest_offset_bits % 8 == 0 && this_size_bits % 8 == 0
e1d87d
--- a/gdb/testsuite/gdb.dwarf2/var-access.exp
e1d87d
+++ b/gdb/testsuite/gdb.dwarf2/var-access.exp
e1d87d
@@ -228,6 +228,24 @@ Dwarf::assemble $asm_file {
e1d87d
 			piece 1
e1d87d
 		    } SPECIAL_expr}
e1d87d
 		}
e1d87d
+		# One piece per bitfield, using piece offsets: 32 bits of
e1d87d
+		# an implicit value, 9 bits of a stack value, 13 bits of
e1d87d
+		# r0, and 10 bits of buf.
e1d87d
+		DW_TAG_variable {
e1d87d
+		    {name "t3"}
e1d87d
+		    {type :$struct_t_label}
e1d87d
+		    {location {
e1d87d
+			implicit_value 0x12 0x34 0x56 0x78 0x9a
e1d87d
+			bit_piece 32 4
e1d87d
+			const2s -280
e1d87d
+			stack_value
e1d87d
+			bit_piece 9 2
e1d87d
+			regx [lindex $dwarf_regnum 0]
e1d87d
+			bit_piece 13 14
e1d87d
+			addr $buf_var
e1d87d
+			bit_piece 10 42
e1d87d
+		    } SPECIAL_expr}
e1d87d
+		}
e1d87d
 	    }
e1d87d
 	}
e1d87d
     }
e1d87d
@@ -304,3 +322,24 @@ gdb_test_no_output "set var t2.y = 2641"
e1d87d
 gdb_test_no_output "set var t2.z = -400"
e1d87d
 gdb_test_no_output "set var t2.x = 200"
e1d87d
 gdb_test "print t2.x + t2.y + t2.z" " = 2441"
e1d87d
+
e1d87d
+# Bitfield access through pieces with nonzero piece offsets.
e1d87d
+gdb_test_no_output "set var \$[lindex $regname 0] = 0xa8000" \
e1d87d
+    "init reg for t3.y"
e1d87d
+gdb_test_no_output "set var *(char \[2\] *) (a + 5) = { 70, 82 }" \
e1d87d
+    "init mem for t3.z"
e1d87d
+switch $endian {
e1d87d
+    little {set val "u = -1484430527, x = -70, y = 42, z = 145"}
e1d87d
+    big {set val "u = 591751049, x = -70, y = 42, z = 101"}
e1d87d
+}
e1d87d
+gdb_test "print t3" " = \\{$val\\}" \
e1d87d
+    "initialized t3 from reg and mem"
e1d87d
+gdb_test_no_output "set var t3.y = -1" \
e1d87d
+    "overwrite t3.y"
e1d87d
+gdb_test "print/x \$[lindex $regname 0]" " = 0x7ffc000" \
e1d87d
+    "verify t3.y through reg"
e1d87d
+gdb_test_no_output "set var t3.z = -614" \
e1d87d
+    "overwrite t3.z"
e1d87d
+switch $endian {big {set val "0x59, 0xa2"} little {set val "0x6a, 0x56"}}
e1d87d
+gdb_test "print/x *(char \[2\] *) (a + 5)" " = \\{$val\\}" \
e1d87d
+    "verify t3.z through mem"