This is the mail archive of the
archer@sourceware.org
mailing list for the Archer project.
RE: [python] Pretty-printers and addressprint
- From: "Elmenthaler, Jens" <jens dot elmenthaler at verigy dot com>
- To: "Paul Pluzhnikov" <ppluzhnikov at google dot com>, <gdb at sourceware dot org>, <archer at sourceware dot org>
- Cc: <dje at google dot com>
- Date: Tue, 10 Nov 2009 01:25:04 -0600
- Subject: RE: [python] Pretty-printers and addressprint
Hi Paul,
The gdb.Value class has a string() method, you could try this in your to_string method:
return self.val['whybother']['contents'].string()
Greetings, Jens.
-----Original Message-----
From: gdb-owner@sourceware.org [mailto:gdb-owner@sourceware.org] On Behalf Of Paul Pluzhnikov
Sent: Dienstag, 10. November 2009 03:12
To: gdb@sourceware.org; archer@sourceware.org
Cc: dje@google.com; ppluzhnikov@google.com
Subject: [python] Pretty-printers and addressprint
Greetings,
Consider the gdb.python/py-prettyprint.exp test case.
It has:
typedef struct string_repr
{
struct whybother
{
const char *contents;
} whybother;
} string;
and a prettyprinter for it:
# Test returning a Value from a printer.
class string_print:
def __init__(self, val):
self.val = val
def to_string(self):
return self.val['whybother']['contents']
Which currently produces:
$4 = 0x4007e0 "this is x"^M
The issue I am having is there is no apparent way to get rid of the
address from python side (address is not printed when the printer
returns a python string instead of a value), whereas if the
printer really wants to print the address, it can trivally add
it back by returning appropriate python string.
Printing addresses inside of a container seems to be especially
"not wanted".
Should the decision to print addresses be deferred to the
pretty-printer? Is the patch below reasonable?
Thanks,
--
Paul Pluzhnikov
2009-11-09 Paul Pluzhnikov <ppluzhnikov@google.com>
* gdb/python/py-prettyprint.c (print_string_repr): Don't
print value address.
--- gdb/python/py-prettyprint.c#1 2009-11-09 17:58:39.000000000 -0800
+++ gdb/python/py-prettyprint.c 2009-11-09 16:51:16.862840000 -0800
@@ -209,7 +209,12 @@ print_string_repr (PyObject *printer, co
Py_DECREF (py_str);
}
else if (replacement)
- common_val_print (replacement, stream, recurse, options, language);
+ {
+ struct value_print_options opts = *options;
+
+ opts.addressprint = 0;
+ common_val_print (replacement, stream, recurse, &opts, language);
+ }
else
gdbpy_print_stack ();
}