This is the mail archive of the
gdb-patches@sourceware.cygnus.com
mailing list for the GDB project.
Re: RFD: printcmd.c: Changing output width of p/a and x/a
- To: "Peter.Schauer" <Peter dot Schauer at regent dot e-technik dot tu-muenchen dot de>
- Subject: Re: RFD: printcmd.c: Changing output width of p/a and x/a
- From: Andrew Cagney <ac131313 at cygnus dot com>
- Date: Mon, 20 Mar 2000 20:12:14 +1100
- CC: gdb-patches at sourceware dot cygnus dot com
- Organization: Cygnus Solutions
- References: <200003072113.WAA26267@reisser.regent.e-technik.tu-muenchen.de>
"Peter.Schauer" wrote:
> Would you expect
>
> (gdb) p/a (char)-1
(I guess you mean ``(signed char) -1''
>
> to yield
>
> $1 = 0xff (truncation to length of value, will cause testsuite
> regressions, which have to be adressed by changing
> the expect patterns)
> or
>
> $1 = 0xffffffff (truncation to size of pointer)
I suspect the latter. The value is being printed as if it were being
interpreted as an address (but I'm not the CLI expert).
>
> Here is a patch to truncate to the size of a pointer, please let me know
> if you want this to be changed to truncate to the length of the value.
>
> 2000-03-07 Peter Schauer <pes@regent.e-technik.tu-muenchen.de>
>
> * printcmd.c (print_scalar_formatted): Truncate addresses to the
> size of a target pointer before passing them to print_address.
>
> *** ./printcmd.c.orig Sun Mar 5 17:35:36 2000
> --- ./printcmd.c Tue Mar 7 19:59:46 2000
> ***************
> *** 443,449 ****
> break;
>
> case 'a':
> ! print_address (unpack_pointer (type, valaddr), stream);
> break;
>
> case 'c':
> --- 443,455 ----
> break;
>
> case 'a':
> ! {
> ! /* Truncate address to the size of a target pointer. */
> ! CORE_ADDR addr = unpack_pointer (type, valaddr);
> ! if (TARGET_PTR_BIT < (sizeof (CORE_ADDR) * HOST_CHAR_BIT))
> ! addr &= ((CORE_ADDR) 1 << TARGET_PTR_BIT) - 1;
> ! print_address (addr, stream);
> ! }
> break;
I'd include a comment noteing that shifting by
sizeof(CORE_ADDR)*HOST_CHAR_BIT is dangerous.
Andrew