This is the mail archive of the gdb-patches@sourceware.cygnus.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: RFD: printcmd.c: Changing output width of p/a and x/a


"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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]