Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@polymtl.ca>
To: Andreas Arnez <arnez@linux.vnet.ibm.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH 8/9] Respect piece offset for DW_OP_bit_piece
Date: Fri, 14 Apr 2017 15:07:00 -0000	[thread overview]
Message-ID: <50c411f610271ff5c5a07b4ac10e8cb6@polymtl.ca> (raw)
In-Reply-To: <1491586736-21296-9-git-send-email-arnez@linux.vnet.ibm.com>

On 2017-04-07 13:38, Andreas Arnez wrote:
> So far GDB ignores the piece offset of all kinds of DWARF bit
> pieces (DW_OP_bit_piece) and treats such pieces as if the offset was 
> zero.
> 
> This is fixed, and an appropriate test is added.
> 
> gdb/ChangeLog:
> 
> 	* dwarf2loc.c (read_pieced_value): Respect the piece offset, as
> 	given by DW_OP_bit_piece.
> 	(write_pieced_value): Likewise.
> 
>   Andreas Arnez  <arnez@linux.vnet.ibm.com>
> 
> 	* gdb.dwarf2/var-access.exp: Add test for composite location with
> 	nonzero piece offsets.
> ---
>  gdb/dwarf2loc.c                         | 22 ++++++++++++++------
>  gdb/testsuite/gdb.dwarf2/var-access.exp | 37 
> +++++++++++++++++++++++++++++++++
>  2 files changed, 53 insertions(+), 6 deletions(-)
> 
> diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c
> index 67df598..045c2d3 100644
> --- a/gdb/dwarf2loc.c
> +++ b/gdb/dwarf2loc.c
> @@ -1824,11 +1824,13 @@ read_pieced_value (struct value *v)
>  	    int optim, unavail;
> 
>  	    if (gdbarch_byte_order (arch) == BFD_ENDIAN_BIG
> -		&& p->size < reg_bits)
> +		&& p->offset + p->size < reg_bits)
>  	      {
>  		/* Big-endian, and we want less than full size.  */
> -		source_offset_bits += reg_bits - p->size;
> +		source_offset_bits += reg_bits - (p->offset + p->size);
>  	      }
> +	    else
> +	      source_offset_bits += p->offset;
>  	    this_size = bits_to_bytes (source_offset_bits, this_size_bits);
>  	    buffer.reserve (this_size);
> 
> @@ -1850,6 +1852,7 @@ read_pieced_value (struct value *v)
>  	  break;
> 
>  	case DWARF_VALUE_MEMORY:
> +	  source_offset_bits += p->offset;
>  	  this_size = bits_to_bytes (source_offset_bits, this_size_bits);
>  	  buffer.reserve (this_size);
> 
> @@ -1869,12 +1872,14 @@ read_pieced_value (struct value *v)
>  	    ULONGEST obj_size = 8 * TYPE_LENGTH (value_type (p->v.value));
> 
>  	    /* Use zeroes if piece reaches beyond stack value.  */
> -	    if (p->size > obj_size)
> +	    if (p->offset + p->size > obj_size)
>  	      break;
> 
>  	    /* Piece is anchored at least significant bit end.  */
>  	    if (gdbarch_byte_order (objfile_gdbarch) == BFD_ENDIAN_BIG)
> -	      source_offset_bits += obj_size - p->size;
> +	      source_offset_bits += obj_size - (p->offset + p->size);
> +	    else
> +	      source_offset_bits += p->offset;
>  	    copy_bitwise (contents, dest_offset_bits,
>  			  value_contents_all (p->v.value),
>  			  source_offset_bits,
> @@ -1888,6 +1893,7 @@ 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)
>  	      break;
>  	    if (n > obj_size - source_offset_bits)
> @@ -1978,11 +1984,13 @@ write_pieced_value (struct value *to, struct
> value *from)
>  	    ULONGEST reg_bits = 8 * register_size (arch, gdb_regnum);
> 
>  	    if (gdbarch_byte_order (arch) == BFD_ENDIAN_BIG
> -		&& p->size <= reg_bits)
> +		&& p->offset + p->size < reg_bits)
>  	      {
>  		/* Big-endian, and we want less than full size.  */
> -		dest_offset_bits += reg_bits - p->size;
> +		dest_offset_bits += reg_bits - (p->offset + p->size);
>  	      }
> +	    else
> +	      dest_offset_bits += p->offset;
>  	    this_size = bits_to_bytes (dest_offset_bits, this_size_bits);
>  	    buffer.reserve (this_size);
> 
> @@ -2019,6 +2027,8 @@ write_pieced_value (struct value *to, struct 
> value *from)
>  	  break;
>  	case DWARF_VALUE_MEMORY:
>  	  {
> +	    dest_offset_bits += p->offset;
> +
>  	    CORE_ADDR start_addr = p->v.mem.addr + dest_offset_bits / 8;
> 
>  	    if (dest_offset_bits % 8 == 0 && this_size_bits % 8 == 0
> diff --git a/gdb/testsuite/gdb.dwarf2/var-access.exp
> b/gdb/testsuite/gdb.dwarf2/var-access.exp
> index 4787dfb..29d61f8 100644
> --- a/gdb/testsuite/gdb.dwarf2/var-access.exp
> +++ b/gdb/testsuite/gdb.dwarf2/var-access.exp
> @@ -204,6 +204,22 @@ Dwarf::assemble $asm_file {
>  			piece 1
>  		    } SPECIAL_expr}
>  		}
> +		# One piece per bitfield.  Use piece offsets.
> +		DW_TAG_variable {
> +		    {name "t3"}
> +		    {type :$struct_t_label}
> +		    {location {
> +			implicit_value 0x12 0x34 0x56 0x78 0x9a
> +			bit_piece 32 4
> +			const2s -280
> +			stack_value
> +			bit_piece 9 2
> +			regx [lindex $dwarf_regnum 0]
> +			bit_piece 13 14
> +			addr $buf_var
> +			bit_piece 10 42
> +		    } SPECIAL_expr}
> +		}
>  	    }
>  	}
>      }
> @@ -276,3 +292,24 @@ gdb_test_no_output "set var t2.y = 2641"
>  gdb_test_no_output "set var t2.z = -400"
>  gdb_test_no_output "set var t2.x = 200"
>  gdb_test "print t2.x + t2.y + t2.z" " = 2441"
> +
> +# Bitfield access through pieces with nonzero piece offsets.
> +gdb_test_no_output "set var \$[lindex $regname 0] = 0xa8000" \
> +    "init reg for t3.y"
> +gdb_test_no_output "set var *(char \[2\] *) (a + 5) = { 70, 82 }" \
> +    "init mem for t3.z"
> +switch $endian {
> +    little {set val "u = -1484430527, x = -70, y = 42, z = 145"}
> +    big {set val "u = 591751049, x = -70, y = 42, z = 101"}
> +}

Just a nit, I think this (at least the part about u) would be slightly 
easier to understand if the value was printed in hex, like so (for 
little endian):

   u = 0xa7856341, x = 0xffffffba, y = 0x2a, z = 0x91

since we can recognize the nibbles from the implicit_value up there.

> +gdb_test "print t3" " = \\{$val\\}" \
> +    "initialized t3 from reg and mem"
> +gdb_test_no_output "set var t3.y = -1" \
> +    "overwrite t3.y"
> +gdb_test "print/x \$[lindex $regname 0]" " = 0x7ffc000" \
> +    "verify t3.y through reg"
> +gdb_test_no_output "set var t3.z = -614" \
> +    "overwrite t3.z"
> +switch $endian {big {set val "0x59, 0xa2"} little {set val "0x6a, 
> 0x56"}}
> +gdb_test "print/x *(char \[2\] *) (a + 5)" " = \\{$val\\}" \
> +    "verify t3.z through mem"


  reply	other threads:[~2017-04-14 15:07 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 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: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: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 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: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:44 ` [PATCH 8/9] Respect piece offset for DW_OP_bit_piece Andreas Arnez
2017-04-14 15:07   ` Simon Marchi [this message]
2017-04-07 17:45 ` [PATCH 9/9] Remove unnecessary copies of variables in read/write_pieced_value Andreas Arnez
2017-04-14 15:21   ` 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=50c411f610271ff5c5a07b4ac10e8cb6@polymtl.ca \
    --to=simon.marchi@polymtl.ca \
    --cc=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