From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8165 invoked by alias); 10 Nov 2009 02:12:11 -0000 Mailing-List: contact archer-help@sourceware.org; run by ezmlm Sender: Precedence: bulk List-Post: List-Help: List-Subscribe: List-Id: Received: (qmail 8148 invoked by uid 22791); 10 Nov 2009 02:12:10 -0000 X-SWARE-Spam-Status: No, hits=-2.2 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: sourceware.org To: gdb@sourceware.org, archer@sourceware.org Cc: dje@google.com, ppluzhnikov@google.com Subject: [python] Pretty-printers and addressprint Message-Id: <20091110021158.C3C2576D70@ppluzhnikov.mtv.corp.google.com> Date: Tue, 10 Nov 2009 02:12:00 -0000 From: ppluzhnikov@google.com (Paul Pluzhnikov) X-SW-Source: 2009-q4/txt/msg00045.txt.bz2 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 * 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 (); }