Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: Andrew Burgess <aburgess@broadcom.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH [2/2] Convert the unavailable vector to be bit, not byte, based.
Date: Tue, 10 Dec 2013 11:32:00 -0000	[thread overview]
Message-ID: <52A6FBDB.5040206@redhat.com> (raw)
In-Reply-To: <52A63067.8050702@broadcom.com>

On 12/09/2013 09:04 PM, Andrew Burgess wrote:
> On 05/12/2013 4:18 PM, Pedro Alves wrote:
>> On 12/04/2013 03:26 PM, Andrew Burgess wrote:
>>
>>>  
>>>        /* Compare the _available_ contents.  */
>>> -      if (memcmp (val1->contents + offset1,
>>> -		  val2->contents + offset2,
>>> -		  l1) != 0)
>>> +      if (memcmp (val1->contents + (offset1 / TARGET_CHAR_BIT),
>>> +		  val2->contents + (offset2 / TARGET_CHAR_BIT),
>>> +		  (l1 / TARGET_CHAR_BIT)) != 0)
>>>  	return 0;
>>
>> As memcmp compares bytes, isn't this potentially comparing bits
>> at the beginning and end of the values' buffers, when it
>> should not?   That is, it looks like the
>> 'offset1 % TARGET_CHAR_BIT != 0' and
>> '(offset1 + l1) % TARGET_CHAR_BIT' cases should be considered here?
>>
> 
> Thanks for the review.  You're right, this isn't doing the correct thing
> here, I should have written something like this:
> 
> 
> +      if (memcmp (val1->contents + (offset1 / TARGET_CHAR_BIT),
> +		  val2->contents + (offset2 / TARGET_CHAR_BIT),
> +		  ((l1 + TARGET_CHAR_BIT - 1)/ TARGET_CHAR_BIT)) != 0)
> 
> That is round the start down to the nearest byte boundary, and round the
> length up to the nearest byte boundary.
> 
> I figured that as the value content buffer is always a round number of
> bytes then there will always be memory backing the access, and as the
> content buffer is zero initialized comparing the "unavailable" bits will
> not cause the compare to fail.

Yeah, given value_available_contents_eq's interface works with bytes,
not bits, we know we'll always be comparing up to byte boundaries, so
even though this iteration may compare more bits than the current
iterated range covers, it's fine, we'd compare them the next
iteration anyway.  Something like:

     bit offset:   0 1 2 3  4 5 6 7
val1's contents: [ 1 U U U  2 2 2 2 ]
val2's contents: [ 1 U U U  5 5 5 5 ]
bits to compare: [ X X X X  X X X X ]

The first time, we'll memcmp bits bits 0-7 and return false,
even though the first available range (bit 0), compares equal.

This deserves a comment though.

> Alternatively, I can update to only access the bits we'd like to compare.

Hmm.  That'd be necessary if value_available_contents_eq accepted
bit offsets instead of byte offsets.  E.g,. consider two values
with these contents:

     bit offset:   0 1 2 3  4 5 6 7
val1's contents: [ 1 U U U  5 5 5 5 ]
val2's contents: [ 0 U U U  5 5 5 5 ]
bits to compare: [       X  X X X X ]

We'd have to make sure to not compare (or mask off before
comparing) the bit at offset 0.

I wonder if it wouldn't make it for more readable code
(and less fragile, e.g., what if we want to stop zero
initializing the contents buffer) if we handled this.  That is,
rename value_available_contents_eq to something like
value_available_contents_bits_eq (and make it static), have it accept
bit offsets, and take that case into consideration.  Then,
make value_available_contents_eq a wrapper that multiplies offsets/lengths
by TARGET_CHAR_BIT.

		if (!get_frame_register_bytes (frame, gdb_regnum, reg_offset,
					       this_size, buffer,
					       &optim, &unavail))
		  {
		    /* Just so garbage doesn't ever shine through.  */
		    memset (buffer, 0, this_size);


> Which approach would would be best?

I'm fine either way, but if we go the former route, then
please add a comment mentioning the assumptions.

> 
> Thanks for your advice,
> Andrew
> 

-- 
Pedro Alves


  reply	other threads:[~2013-12-10 11:32 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-04 15:22 PATCH [0/2] Convert " Andrew Burgess
2013-12-04 15:25 ` [PATCH [1/2] Add support for DW_OP_bit_piece and DW_OP_plus_uconst to DWARF assembler Andrew Burgess
2013-12-05 16:23   ` Pedro Alves
2013-12-05 18:53     ` Tom Tromey
2013-12-06 13:30       ` Andrew Burgess
2013-12-04 15:26 ` [PATCH [0/2] Convert the unavailable vector to be bit, not byte, based Andrew Burgess
2013-12-05 16:18   ` [PATCH [2/2] " Pedro Alves
2013-12-09 21:04     ` Andrew Burgess
2013-12-10 11:32       ` Pedro Alves [this message]
2013-12-11 16:28   ` Andrew Burgess
2013-12-11 18:45     ` Pedro Alves
2013-12-17 17:30       ` Andrew Burgess
2013-12-05 16:18 ` PATCH [0/2] Convert " Pedro Alves
2013-12-05 18:14   ` Doug Evans

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=52A6FBDB.5040206@redhat.com \
    --to=palves@redhat.com \
    --cc=aburgess@broadcom.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