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

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.

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

Which approach would would be best?

Thanks for your advice,
Andrew


  reply	other threads:[~2013-12-09 21:04 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 [this message]
2013-12-10 11:32       ` Pedro Alves
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=52A63067.8050702@broadcom.com \
    --to=aburgess@broadcom.com \
    --cc=gdb-patches@sourceware.org \
    --cc=palves@redhat.com \
    /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