From: Tom Tromey <tom@tromey.com>
To: Andrew Burgess <andrew.burgess@embecosm.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCHv2 5/5] gdb: Better support for dynamic properties with negative values
Date: Wed, 22 May 2019 19:37:00 -0000 [thread overview]
Message-ID: <87lfyycn6i.fsf@tromey.com> (raw)
In-Reply-To: <672dc208d6dfb9f068eb635e02bf85abb9630c74.1557439866.git.andrew.burgess@embecosm.com> (Andrew Burgess's message of "Thu, 9 May 2019 23:22:16 +0100")
>>>>> "Andrew" == Andrew Burgess <andrew.burgess@embecosm.com> writes:
Andrew> When the type of a property is smaller than the CORE_ADDR in which the
Andrew> property value has been placed, and if the property is signed, then
Andrew> sign extend the property value from its actual type up to the size of
Andrew> CORE_ADDR.
I wonder whether this should be using ULONGEST rather than CORE_ADDR
now.
Andrew> + /* If we have a valid return candidate and it's value
Andrew> + is signed, we have to sign-extend the value because
Andrew> + CORE_ADDR on 64bit machine has 8 bytes but address
Andrew> + size of an 32bit application is bytes. */
Andrew> + const int addr_size
Andrew> + = (dwarf2_per_cu_addr_size (baton->locexpr.per_cu)
Andrew> + * TARGET_CHAR_BIT);
I'm somewhat surprised there isn't an existing sign_extend function
somewhere.
Andrew> + const CORE_ADDR neg_mask = ((~0) << (addr_size - 1));
I tend to think this should say ~(CORE_ADDR) 0 rather than just ~0.
Otherwise won't this do the wrong thing if sizeof(int) < sizeof(CORE_ADDR)?
Andrew> + /* Check if signed bit is set and sign-extend values. */
Andrew> + if (*value & (neg_mask))
Andrew> + *value |= (neg_mask );
Extra parens and an extra space here.
mips-tdep.c has the fun sign extension idiom:
value = inst & 0x7ff;
value = (value ^ 0x400) - 0x400; /* Sign-extend. */
(If the high bits are 0 you can skip the "&".)
This one avoids the ~0 business.
Another approach is to let the compiler handle it.
LONGEST l = *value;
l = (l << nbits) >> nbits;
However this may be relying on undefined behavior.
Yours is fine, though, I just noticed these while digging around and
wanted to point them out :-)
Tom
next prev parent reply other threads:[~2019-05-22 19:37 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-09 22:22 [PATCHv2 0/5] Improve handling of negative dynamic properties Andrew Burgess
2019-05-05 20:57 ` [PATCH 0/3] " Andrew Burgess
2019-05-05 20:57 ` [PATCH 2/3] gdb: Convert dwarf2_evaluate_property to return bool Andrew Burgess
2019-05-06 13:57 ` Tom Tromey
2019-05-05 20:57 ` [PATCH 1/3] gdb: Update type of lower bound in value_subscripted_rvalue Andrew Burgess
2019-05-06 13:57 ` Tom Tromey
2019-05-05 20:57 ` [PATCH 3/3] gdb: Handle dynamic properties with negative values Andrew Burgess
2019-05-06 14:55 ` Tom Tromey
2019-05-09 22:22 ` [PATCHv2 4/5] gdb: Carry default property type around with dynamic properties Andrew Burgess
2019-05-22 19:05 ` Tom Tromey
2019-06-10 22:29 ` Andrew Burgess
[not found] ` <20190710141321.GL23204@embecosm.com>
2019-07-10 15:06 ` Tom Tromey
2019-05-09 22:22 ` [PATCHv2 3/5] gdb/dwarf: Ensure the target type of ranges is not void Andrew Burgess
2019-05-22 18:36 ` Tom Tromey
2019-05-09 22:22 ` [PATCHv2 1/5] gdb: Update type of lower bound in value_subscripted_rvalue Andrew Burgess
2019-05-09 22:22 ` [PATCHv2 2/5] gdb: Convert dwarf2_evaluate_property to return bool Andrew Burgess
2019-05-09 22:22 ` [PATCHv2 5/5] gdb: Better support for dynamic properties with negative values Andrew Burgess
2019-05-22 19:37 ` Tom Tromey [this message]
2019-06-10 22:17 ` Andrew Burgess
2019-07-10 15:03 ` Tom Tromey
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=87lfyycn6i.fsf@tromey.com \
--to=tom@tromey.com \
--cc=andrew.burgess@embecosm.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