This is the mail archive of the gdb@sourceware.org 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]
Other format: [Raw text]

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


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