[v2] break gdb build on 32-bit host with ADI support
Commit Message
The problem of failing to build with arm-linux-gnueabihf-g++-4.8 was
that type CORE_ADDR is of "unsigned long" on a 64-bit machine so it's
OK to use %lx but is of type "unsigned long long" on a 32 bit system.
Fixed the problem in three places - (1) use a temp variable of type CORE_ADDR
as argument 3 when calling target_auxv_search() then assign its value to
"blksize" and "nbits" in 2 calls; (2) redo adi_normalize_address() using
masks and xor operators to calculate normalized address; (3) call paddress()
to print CORE_ADDR in either printf_filtered() or error(). Thank you, Pedro,
for all your suggestions.
---
gdb/sparc64-tdep.c | 29 +++++++++++++++++------------
1 files changed, 17 insertions(+), 12 deletions(-)
Comments
$subject should be "unbreak", I hope. :-)
On 08/25/2017 02:33 AM, Weimin Pan wrote:
> @@ -240,7 +242,7 @@ adi_normalize_address (CORE_ADDR addr)
> adi_stat_t ast = get_adi_info (ptid_get_pid (inferior_ptid));
>
> if (ast.nbits)
> - return ((CORE_ADDR)(((long)addr << ast.nbits) >> ast.nbits));
> + return (addr & ((1 << ast.nbits) - 1)) ^ (addr & (-1 >> ast.nbits));
How did you test this? Doesn't look right to me.
Also, "-1 >>" is still an implementation-defined signed
right shift.
I _think_ this is what you want:
/* Clear upper bits. */
addr &= ((uint64_t) -1) >> ast.nbits;
/* Sign extend. */
CORE_ADDR signbit = (uint64_t) 1 << (64 - ast.nbits - 1);
return (addr ^ signbit) - signbit;
I.e., with ast.nbits == 4:
before: ffffffffffffffff
after: ffffffffffffffff
before: f7ffffffffffffff
after: 07ffffffffffffff
Thanks,
Pedro Alves
On 2017-08-25 12:18, Pedro Alves wrote:
> $subject should be "unbreak", I hope. :-)
>
> On 08/25/2017 02:33 AM, Weimin Pan wrote:
>
>> @@ -240,7 +242,7 @@ adi_normalize_address (CORE_ADDR addr)
>> adi_stat_t ast = get_adi_info (ptid_get_pid (inferior_ptid));
>>
>> if (ast.nbits)
>> - return ((CORE_ADDR)(((long)addr << ast.nbits) >> ast.nbits));
>> + return (addr & ((1 << ast.nbits) - 1)) ^ (addr & (-1 >>
>> ast.nbits));
>
> How did you test this? Doesn't look right to me.
> Also, "-1 >>" is still an implementation-defined signed
> right shift.
>
> I _think_ this is what you want:
>
> /* Clear upper bits. */
> addr &= ((uint64_t) -1) >> ast.nbits;
>
> /* Sign extend. */
> CORE_ADDR signbit = (uint64_t) 1 << (64 - ast.nbits - 1);
> return (addr ^ signbit) - signbit;
>
> I.e., with ast.nbits == 4:
>
> before: ffffffffffffffff
> after: ffffffffffffffff
>
> before: f7ffffffffffffff
> after: 07ffffffffffffff
Since it's not trivial, I would suggest putting this operation in its
own function and adding a unit-test for it.
Simon
On 08/25/2017 11:33 AM, Simon Marchi wrote:
> Since it's not trivial, I would suggest putting this operation in its
> own function and adding a unit-test for it.
Definitely agreed with a unit-test. I suggest splitting the
sign extension fix to a follow up patch, so that we can
restore --enable-targets=all builds/bots quickly.
The rest of the patch LGTM, though we're missing a ChangeLog entry.
Thanks,
Pedro Alves
On 8/25/2017 3:18 AM, Pedro Alves wrote:
> $subject should be "unbreak", I hope. :-)
>
> On 08/25/2017 02:33 AM, Weimin Pan wrote:
>
>> @@ -240,7 +242,7 @@ adi_normalize_address (CORE_ADDR addr)
>> adi_stat_t ast = get_adi_info (ptid_get_pid (inferior_ptid));
>>
>> if (ast.nbits)
>> - return ((CORE_ADDR)(((long)addr << ast.nbits) >> ast.nbits));
>> + return (addr & ((1 << ast.nbits) - 1)) ^ (addr & (-1 >> ast.nbits));
> How did you test this? Doesn't look right to me.
> Also, "-1 >>" is still an implementation-defined signed
> right shift.
>
> I _think_ this is what you want:
>
> /* Clear upper bits. */
> addr &= ((uint64_t) -1) >> ast.nbits;
>
> /* Sign extend. */
> CORE_ADDR signbit = (uint64_t) 1 << (64 - ast.nbits - 1);
> return (addr ^ signbit) - signbit;
>
> I.e., with ast.nbits == 4:
>
> before: ffffffffffffffff
> after: ffffffffffffffff
>
> before: f7ffffffffffffff
> after: 07ffffffffffffff
>
> Thanks,
> Pedro Alves
>
Yes, below is running the ADI test case, which Yao requested in one of
these patches,
with your code:
% make check TESTS="gdb.arch/sparc64-adi.exp"
make[1]: Entering directory
`/home/wepan/work/new3/binutils-gdb/gdb/testsuite'
Nothing to be done for all...
make check-single
make[2]: Entering directory
`/home/wepan/work/new3/binutils-gdb/gdb/testsuite'
rootme=`pwd`; export rootme; srcdir=. ; export srcdir ; EXPECT=`if [
"${READ1}"
!= "" ] ; then echo ${rootme}/expect-read1; elif [ -f
${rootme}/../../expect/exp
ect ] ; then echo ${rootme}/../../expect/expect ; else echo expect ; fi`
; expor
t EXPECT ; EXEEXT= ; export EXEEXT ;
LD_LIBRARY_PATH=$rootme/../../expect:$rootm
e/../../libstdc++:$rootme/../../tk/unix:$rootme/../../tcl/unix:$rootme/../../bfd
:$rootme/../../opcodes:$LD_LIBRARY_PATH; export LD_LIBRARY_PATH; if [ -f
${rootm
e}/../../expect/expect ] ; then TCL_LIBRARY=${srcdir}/../../tcl/library
; export
TCL_LIBRARY ; fi ; runtest --status gdb.arch/sparc64-adi.exp
WARNING: Couldn't find the global config file.
Test Run By wepan on Fri Aug 25 12:21:07 2017
Native configuration is sparc64-unknown-linux-gnu
=== gdb tests ===
Schedule of variations:
unix
Running target unix
Using /usr/share/dejagnu/baseboards/unix.exp as board description file
for target.
Using /usr/share/dejagnu/config/unix.exp as generic interface file for
target.
Using /home/wepan/work/new3/binutils-gdb/gdb/testsuite/config/unix.exp
as tool-a
nd-target-specific interface file.
Running
/home/wepan/work/new3/binutils-gdb/gdb/testsuite/gdb.arch/sparc64-adi.exp
...
=== gdb Summary ===
# of expected passes 7
/home/wepan/work/new3/binutils-gdb/gdb/testsuite/../../gdb/gdb version
8.0.50.2
0170823-git -nw -nx -data-directory
/home/wepan/work/new3/binutils-gdb/gdb/tests
uite/../data-directory
Thanks much.
@@ -93,8 +93,8 @@ typedef struct
unsigned long blksize;
/* Number of bits used for an ADI version tag which can be
- * used together with the shift value for an ADI version tag
- * to encode or extract the ADI version value in a pointer. */
+ used together with the shift value for an ADI version tag
+ to encode or extract the ADI version value in a pointer. */
unsigned long nbits;
/* The maximum ADI version tag value supported. */
@@ -217,15 +217,17 @@ adi_available (void)
{
pid_t pid = ptid_get_pid (inferior_ptid);
sparc64_adi_info *proc = get_adi_info_proc (pid);
+ CORE_ADDR value;
if (proc->stat.checked_avail)
return proc->stat.is_avail;
proc->stat.checked_avail = true;
- if (target_auxv_search (¤t_target, AT_ADI_BLKSZ,
- &proc->stat.blksize) <= 0)
- return false;
- target_auxv_search (¤t_target, AT_ADI_NBITS, &proc->stat.nbits);
+ if (target_auxv_search (¤t_target, AT_ADI_BLKSZ, &value) <= 0)
+ return false;
+ proc->stat.blksize = value;
+ target_auxv_search (¤t_target, AT_ADI_NBITS, &value);
+ proc->stat.nbits = value;
proc->stat.max_version = (1 << proc->stat.nbits) - 2;
proc->stat.is_avail = true;
@@ -240,7 +242,7 @@ adi_normalize_address (CORE_ADDR addr)
adi_stat_t ast = get_adi_info (ptid_get_pid (inferior_ptid));
if (ast.nbits)
- return ((CORE_ADDR)(((long)addr << ast.nbits) >> ast.nbits));
+ return (addr & ((1 << ast.nbits) - 1)) ^ (addr & (-1 >> ast.nbits));
return addr;
}
@@ -346,7 +348,8 @@ adi_read_versions (CORE_ADDR vaddr, size_t size, unsigned char *tags)
if (!adi_is_addr_mapped (vaddr, size))
{
adi_stat_t ast = get_adi_info (ptid_get_pid (inferior_ptid));
- error(_("Address at 0x%lx is not in ADI maps"), vaddr*ast.blksize);
+ error(_("Address at %s is not in ADI maps"),
+ paddress (target_gdbarch (), vaddr * ast.blksize));
}
int target_errno;
@@ -366,7 +369,8 @@ adi_write_versions (CORE_ADDR vaddr, size_t size, unsigned char *tags)
if (!adi_is_addr_mapped (vaddr, size))
{
adi_stat_t ast = get_adi_info (ptid_get_pid (inferior_ptid));
- error(_("Address at 0x%lx is not in ADI maps"), vaddr*ast.blksize);
+ error(_("Address at %s is not in ADI maps"),
+ paddress (target_gdbarch (), vaddr * ast.blksize));
}
int target_errno;
@@ -387,7 +391,8 @@ adi_print_versions (CORE_ADDR vaddr, size_t cnt, unsigned char *tags)
while (cnt > 0)
{
QUIT;
- printf_filtered ("0x%016lx:\t", vaddr * adi_stat.blksize);
+ printf_filtered ("%s:\t",
+ paddress (target_gdbarch (), vaddr * adi_stat.blksize));
for (int i = maxelts; i > 0 && cnt > 0; i--, cnt--)
{
if (tags[v_idx] == 0xff) /* no version tag */
@@ -418,7 +423,7 @@ do_examine (CORE_ADDR start, int bcnt)
if (read_cnt == -1)
error (_("No ADI information"));
else if (read_cnt < cnt)
- error(_("No ADI information at 0x%lx"), vaddr);
+ error(_("No ADI information at %s"), paddress (target_gdbarch (), vaddr));
adi_print_versions (vstart, cnt, buf);
@@ -438,7 +443,7 @@ do_assign (CORE_ADDR start, size_t bcnt, int version)
if (set_cnt == -1)
error (_("No ADI information"));
else if (set_cnt < cnt)
- error(_("No ADI information at 0x%lx"), vaddr);
+ error(_("No ADI information at %s"), paddress (target_gdbarch (), vaddr));
}