From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4405 invoked by alias); 15 Aug 2011 14:30:29 -0000 Received: (qmail 4395 invoked by uid 22791); 15 Aug 2011 14:30:28 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (38.113.113.100) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 15 Aug 2011 14:30:12 +0000 Received: (qmail 14765 invoked from network); 15 Aug 2011 14:30:11 -0000 Received: from unknown (HELO scottsdale.localnet) (pedro@127.0.0.2) by mail.codesourcery.com with ESMTPA; 15 Aug 2011 14:30:11 -0000 From: Pedro Alves To: gdb@sourceware.org Subject: Re: Python API - nested pretty printers MI implications Date: Mon, 15 Aug 2011 14:30:00 -0000 User-Agent: KMail/1.13.6 (Linux/2.6.38-10-generic; KDE/4.7.0; x86_64; ; ) Cc: Andrew Oakley References: <20110814171023.19db4f49@ado-gentoo> <201108151357.50298.pedro@codesourcery.com> <4E4927D2.2050903@ado.is-a-geek.net> In-Reply-To: <4E4927D2.2050903@ado.is-a-geek.net> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Message-Id: <201108151530.08237.pedro@codesourcery.com> 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: 2011-08/txt/msg00046.txt.bz2 On Monday 15 August 2011 15:06:10, Andrew Oakley wrote: > On 15/08/11 13:57, Pedro Alves wrote: > > On Sunday 14 August 2011 17:10:23, Andrew Oakley wrote: > >> def children(self): > >> yield ("normal variable", "some value") > >> yield ("phony group 1", inner_pretty_printer(...)) > >> yield ("phony group 2", inner_pretty_printer(...)) > >> > >> This seems to work well but I'm not quite sure how to handle the for M= I. > >> > >> As far as I can tell I need to create "fake" varobj structures with no > >> underlying value or type (because I don't have one).=20 > >=20 > > I'm not very familiar with the pretty printing stuff, but, > > doesn't something like this work nowadays? >=20 > [snip] >=20 > > That is, create a specialized Value class and install the pretty > > printer for that _value_. >=20 > This didn't come up when I asked about this previously. >=20 > I assume the idea is to create a gdb.Value (with some data it doesn't > really matter what) and then detect that it is that particular gdb.Value > when the pretty printers list is searched? Perhaps you could do > something like this: >=20 > def fake_value_printer(val): > if hasattr(val, "prettyprinter"): > return val.prettyprinter > else: > return None >=20 > gdb.pretty_printers.insert(0, fake_value_printer) >=20 > Then you could just return any old gdb.Value and as long as it had a > prettyprinter attribute then that would be called instead of the > "normal" version. >=20 > Is this what you were thinking of? I was actually thinking more like: gdb.pretty_printers.insert(0, fake_value_printer) def fake_value_printer(val): isinstance(o, MyFakeValue) return FakeValuePrinter(val, or whatever args needed) else: return None instead of duck typing, but yes, that sounds similar. > That's quite a nice trick but I'm not sure its a good long-term > solution. It relies on the same python gdb.Value being passed back to > the pretty printer selection function=20 I don't understand. > and probably causes exactly the same problems for the MI. There'd be no NULL values this way. Wasn't that the problem? > Back to my initial question I guess for MI this is also creating a > "dummy" varobj with some type and value chosen by the python script. Do > you know if this works in practice with MI frontends? I'm not sure what you mean. You'd always need a "dummy" varobj for each of the "fake values", wouldn't you? (I'm not sure you've seen my reply to Andr=E9 though). --=20 Pedro Alves