From: Joel Brobecker <brobecker@adacore.com>
To: Richard Henderson <rth@redhat.com>
Cc: gdb-patches@sources.redhat.com
Subject: Re: Question: Checking register value in buffer
Date: Thu, 19 May 2005 03:33:00 -0000 [thread overview]
Message-ID: <20050519032332.GZ12565@adacore.com> (raw)
In-Reply-To: <20050519030349.GA8255@redhat.com>
> > 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
next prev parent reply other threads:[~2005-05-19 3:23 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-05-19 2:49 Joel Brobecker
2005-05-19 3:03 ` Richard Henderson
2005-05-19 3:07 ` Joel Brobecker
2005-05-19 3:23 ` Richard Henderson
2005-05-19 3:33 ` Joel Brobecker [this message]
2005-05-19 4:52 ` Richard Henderson
2005-05-19 5:37 ` Daniel Jacobowitz
2005-05-19 3:26 ` Daniel Jacobowitz
2005-05-19 16:41 ` Andrew Cagney
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=20050519032332.GZ12565@adacore.com \
--to=brobecker@adacore.com \
--cc=gdb-patches@sources.redhat.com \
--cc=rth@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