From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15156 invoked by alias); 10 Nov 2009 07:25:34 -0000 Received: (qmail 15129 invoked by uid 22791); 10 Nov 2009 07:25:32 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL,BAYES_00,SPF_PASS X-Spam-Check-By: sourceware.org Received: from plmler6.mail.eds.com (HELO plmler6.mail.eds.com) (199.228.142.88) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 10 Nov 2009 07:25:27 +0000 Received: from plmlir1.mail.eds.com (plmlir1-2.mail.eds.com [199.228.142.131]) by plmler6.mail.eds.com (8.14.2/8.13.8) with ESMTP id nAA7PK4L030507; Tue, 10 Nov 2009 01:25:21 -0600 Received: from plmlir1.mail.eds.com (localhost.localdomain [127.0.0.1]) by plmlir1.mail.eds.com (8.14.2/8.12.10) with ESMTP id nAA7P6L6004626; Tue, 10 Nov 2009 01:25:06 -0600 Received: from usplmvpfe001.ent.rt.verigy.net ([192.100.40.4]) by plmlir1.mail.eds.com (8.14.2/8.12.10) with ESMTP id nAA7P6JZ004621; Tue, 10 Nov 2009 01:25:06 -0600 X-EDSINT-Source-Ip: 192.100.40.4 Received: from usplmvpbe001.ent.rt.verigy.net ([10.16.58.34]) by usplmvpfe001.ent.rt.verigy.net with Microsoft SMTPSVC(6.0.3790.3959); Tue, 10 Nov 2009 01:25:05 -0600 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Subject: RE: [python] Pretty-printers and addressprint Date: Tue, 10 Nov 2009 09:24:00 -0000 Message-ID: <58596C4646708B4BB990C44839973330013A61DE@usplmvpbe001.ent.rt.verigy.net> In-Reply-To: <20091110021158.C3C2576D70@ppluzhnikov.mtv.corp.google.com> From: "Elmenthaler, Jens" To: "Paul Pluzhnikov" , , Cc: X-IsSubscribed: yes Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org X-SW-Source: 2009-11/txt/msg00109.txt.bz2 Hi Paul, The gdb.Value class has a string() method, you could try this in your to_st= ring 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 =3D val def to_string(self): return self.val['whybother']['contents'] Which currently produces: $4 =3D 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 =3D *options; + + opts.addressprint =3D 0; + common_val_print (replacement, stream, recurse, &opts, language); + } else gdbpy_print_stack (); }