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


Andrew Cagney wrote:
> 
> "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).
>
I agree as well.  "a" stands for address -- it is always better to show it in a consistent size.

 
> >
> > 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.
> 

I am not the maintainer of printcmd.c, but as it is remotely related to the command line user interface I would at least
vote in favor of it (with the addition of the comment suggested by Andrew).


-- 
Fernando Nasser
Red Hat - Toronto                       E-Mail:  fnasser@cygnus.com
2323 Yonge Street, Suite #300           Tel:  416-482-2661 ext. 311
Toronto, Ontario   M4P 2C9              Fax:  416-482-6299

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