public inbox for archer@sourceware.org
 help / color / mirror / Atom feed
* [python] Pretty-printers and addressprint
@ 2009-11-10  2:12 Paul Pluzhnikov
  2009-11-10  7:25 ` Elmenthaler, Jens
  2009-11-10 15:12 ` Tom Tromey
  0 siblings, 2 replies; 11+ messages in thread
From: Paul Pluzhnikov @ 2009-11-10  2:12 UTC (permalink / raw)
  To: gdb, archer; +Cc: dje, ppluzhnikov

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 ();
 }

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2009-11-10 20:49 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-11-10  2:12 [python] Pretty-printers and addressprint Paul Pluzhnikov
2009-11-10  7:25 ` Elmenthaler, Jens
2009-11-10  8:06   ` Paul Pluzhnikov
2009-11-10  8:37     ` Phil Muldoon
2009-11-10 11:53     ` Paul Koning
2009-11-10 15:45       ` Paul Pluzhnikov
2009-11-10 15:53         ` Paul Koning
2009-11-10 16:53         ` Tom Tromey
2009-11-10 17:03           ` Paul Pluzhnikov
2009-11-10 20:49             ` Tom Tromey
2009-11-10 15:12 ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).