[python] Pretty-printers and addressprint
Paul Koning
Paul_Koning@Dell.com
Tue Nov 10 18:49:00 GMT 2009
repr() is a Python builtin function that returns the "representation" of
an object -- a string that matches the representation of that object in
Python. Contrast that with str() which prints it the user-friendly way
which may be less complete.
For example:
python
Python 2.5.1 (r251:54863, Feb 6 2009, 19:02:12)
>>> foo="abc\1"
>>> print foo
abc
>>> print repr(foo)
'abc\x01'
>>> print str(foo)
abc
>>>
Note that "repr" puts quotes around the string, and escapes the
non-printable characters. It also escapes quotes, which simply wrapping
a quote around the raw string won't cover.
If in gdb repr() doesn't work as in standard Python that would be a
problem...
paul
> -----Original Message-----
> From: Paul Pluzhnikov [mailto:ppluzhnikov@google.com]
> Sent: Tuesday, November 10, 2009 10:45 AM
> To: Paul Koning
> Cc: Elmenthaler, Jens; gdb@sourceware.org; archer@sourceware.org;
> dje@google.com
> Subject: Re: [python] Pretty-printers and addressprint
>
> On Tue, Nov 10, 2009 at 3:53 AM, Paul Koning <Paul_Koning@dell.com>
> wrote:
>
> >> Unfortunately I frequently deal with non-ascii strings, and the
> >> problem just wouldn't go away :-(
> >
> > My test (without gdb, I don't have that installed yet) is
> inconclusive
> > but I think using repr() will cure that too.
>
> AFAICT, in GDB repr(value) is a no-op, and the end result of returning
> repr(value) from the pretty-printer is exactly the same as that of
> returning the value itself:
>
> $4 = 0x4007e0 "this is x\201\202\203\204"
>
> Should repr(value) do something different?
>
> Thanks,
> --
> Paul Pluzhnikov
More information about the Gdb
mailing list