This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
Re: print/a ... (again!)
- To: GDB Patches <gdb-patches at sourceware dot cygnus dot com>
- Subject: Re: print/a ... (again!)
- From: Andrew Cagney <ac131313 at cygnus dot com>
- Date: Tue, 11 Jul 2000 18:49:55 +1000
- References: <3961A333.54261AF3@cygnus.com>
Andrew Cagney wrote:
>
> Hello,
>
> I'm looking at a 64 bit MIPS debugging a 32 bit ISA (-mips2 -EB) and am
> seeing:
>
> (gdb) p/a main+4
> $1 = 0xa0020290
> (gdb) print main + 4
> $5 = (int (*)()) 0xffffffffa0020290 <main+4>
>
> notice how ``print/a'' doesn't know where main is. Grubbing around in
> printcmd.c I find:
>
> case 'a':
> {
> /* Truncate address to the size of a target pointer, avoiding
> shifts larger or equal than the width of a CORE_ADDR. The
> local variable PTR_BIT stops the compiler reporting a shift
> overflow when it won't occure. */
> CORE_ADDR addr = unpack_pointer (type, valaddr);
> int ptr_bit = TARGET_PTR_BIT;
> if (ptr_bit < (sizeof (CORE_ADDR) * HOST_CHAR_BIT))
> addr &= ((CORE_ADDR) 1 << ptr_bit) - 1;
> print_address (addr, stream);
> }
> break;
>
> the problem is that the mask strips off a significant part of the
> address. Commenting out that mask I get the behavour:
>
> (gdb) print main+4
> $2 = (int (*)()) 0xffffffffa0020290 <main+4>
> (gdb) print/a main+4
> $3 = 0xffffffffa0020290 <main+4>
>
> which is definitly an improvement. I'm going to have to go diging
> around in the e-mail archives. Anyone care to try to summarize the
> rationale behind the mask?
FYI,
I'm committing the attatched patch. This is definitly more correct then
the old code while retaining the old behavour.
enjoy,
Andrew
Tue Jul 11 18:32:40 2000 Andrew Cagney <cagney@b1.cygnus.com>
* printcmd.c (print_scalar_formatted): Move masking of 'a' address
from here.
(print_address_numeric): To here.
* TODO: Update.
Index: TODO
===================================================================
RCS file: /cvs/src/src/gdb/TODO,v
retrieving revision 1.40
diff -p -r1.40 TODO
*** TODO 2000/07/09 19:11:44 1.40
--- TODO 2000/07/11 08:45:19
*************** BIG_ENDIAN and LITTLE_ENDIAN.
*** 117,122 ****
--- 117,131 ----
--
+ printcmd.c (print_address_numeric):
+
+ NOTE: This assumes that the significant address information is kept in
+ the least significant bits of ADDR - the upper bits were either zero
+ or sign extended. Should ADDRESS_TO_POINTER() or some
+ ADDRESS_TO_PRINTABLE() be used to do the conversion?
+
+ --
+
Code Cleanups: General
======================
Index: printcmd.c
===================================================================
RCS file: /cvs/src/src/gdb/printcmd.c,v
retrieving revision 1.9
diff -p -r1.9 printcmd.c
*** printcmd.c 2000/05/28 01:12:29 1.9
--- printcmd.c 2000/07/11 08:45:24
***************
*** 1,6 ****
/* Print values for GNU debugger GDB.
- Copyright 1986-1991, 1993-1995, 1998, 2000 Free Software Foundation, Inc.
This file is part of GDB.
This program is free software; you can redistribute it and/or modify
--- 1,8 ----
/* Print values for GNU debugger GDB.
+ Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1993, 1994, 1995,
+ 1998, 2000 Free Software Foundation, Inc.
+
This file is part of GDB.
This program is free software; you can redistribute it and/or modify
*************** print_scalar_formatted (valaddr, type, f
*** 445,458 ****
case 'a':
{
- /* Truncate address to the size of a target pointer, avoiding
- shifts larger or equal than the width of a CORE_ADDR. The
- local variable PTR_BIT stops the compiler reporting a shift
- overflow when it won't occure. */
CORE_ADDR addr = unpack_pointer (type, valaddr);
- int ptr_bit = TARGET_PTR_BIT;
- if (ptr_bit < (sizeof (CORE_ADDR) * HOST_CHAR_BIT))
- addr &= ((CORE_ADDR) 1 << ptr_bit) - 1;
print_address (addr, stream);
}
break;
--- 447,453 ----
*************** print_address_numeric (addr, use_local,
*** 740,747 ****
int use_local;
struct ui_file *stream;
{
! /* This assumes a CORE_ADDR can fit in a LONGEST. Probably a safe
! assumption. */
print_longest (stream, 'x', use_local, (ULONGEST) addr);
}
--- 735,751 ----
int use_local;
struct ui_file *stream;
{
! /* Truncate address to the size of a target pointer, avoiding shifts
! larger or equal than the width of a CORE_ADDR. The local
! variable PTR_BIT stops the compiler reporting a shift overflow
! when it won't occure. */
! /* NOTE: This assumes that the significant address information is
! kept in the least significant bits of ADDR - the upper bits were
! either zero or sign extended. Should ADDRESS_TO_POINTER() or
! some ADDRESS_TO_PRINTABLE() be used to do the conversion? */
! int ptr_bit = TARGET_PTR_BIT;
! if (ptr_bit < (sizeof (CORE_ADDR) * HOST_CHAR_BIT))
! addr &= ((CORE_ADDR) 1 << ptr_bit) - 1;
print_longest (stream, 'x', use_local, (ULONGEST) addr);
}