This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
Re: Question: Checking register value in buffer
> > In terms of computing the mask, I'm thinking of using something
> > like this:
> >
> > sign_mask = 1 << (sizeof (rav) * TARGET_CHAR_BIT - 1);
>
> This confuses host and target notions. You would have wanted
> the *host* CHAR_BIT, since you're using the host sizeof.
Ah yes, of course.
> > zero_mask = sign_mask ^ -1;
>
> This fails if rav is *wider* than 64-bits.
>
> > Are there better ways of computing these masks?
>
> How about just
>
> sign = (LONGEST)1 << 63
> zero = sign - 1;
Isn't this assument that LONGEST is exactly 64 bits? I think
extract_signed_integer expands the value held in the given buffer
to fit the size of LONGEST. Here is the implementation:
LONGEST
extract_signed_integer (const void *addr, int len)
{
LONGEST retval;
const unsigned char *p;
const unsigned char *startaddr = addr;
const unsigned char *endaddr = startaddr + len;
if (len > (int) sizeof (LONGEST))
error (_("\
That operation is not available on integers of more than %d bytes."),
(int) sizeof (LONGEST));
/* Start at the most significant end of the integer, and work towards
the least significant. */
if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
{
p = startaddr;
/* Do the sign extension once at the start. */
retval = ((LONGEST) * p ^ 0x80) - 0x80;
for (++p; p < endaddr; ++p)
retval = (retval << 8) | *p;
}
else
{
p = endaddr - 1;
/* Do the sign extension once at the start. */
retval = ((LONGEST) * p ^ 0x80) - 0x80;
for (--p; p >= startaddr; --p)
retval = (retval << 8) | *p;
}
return retval;
}
Using an example where we have len = 1 and sizeof LONGEST = 2, then
the extract from "0xff" would lead to "0xffff", no?
That's why I thought the little dance with sizeof and xor was necessary.
--
Joel