This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
RE: Python pretty printers and dynamic cast
- From: "Elmenthaler, Jens" <jens dot elmenthaler at verigy dot com>
- To: <tromey at redhat dot com>
- Cc: <gdb at sourceware dot org>
- Date: Tue, 22 Dec 2009 02:14:26 -0600
- Subject: RE: Python pretty printers and dynamic cast
Tom> There is nothing built-in yet. We've had a few requests for this,
Tom> though, and there was a patch posted to the archer list. If you give it
Tom> a try, let us know how it turns out.
I gave it a try. Unfortunately, the patch only provided the C++ style casts on the gdb command line, not the python API. I got stuck figuring out how to get the gdb command line called from within python.
Nevertheless, another patch from the Archer mailing list made me really happy (and this applies to the python pretty printing facility in general!): http://sourceware.org/ml/archer/2009-q4/msg00013.html.
This patch adds a rtti_type method to gdb.Value.
In my case, I have a smart-pointer like class, i.e. it has just one member, which is a pointer to some base interface. We have many derived interfaces of that base interface, and we have at least one implementation of each of those derived interfaces.
I realized to find out the real implementation type of this pointer member is the real value for debugging our code. The "set print object on" has no effect on the MI interface, and thus out Eclipse CDT frontend does not show the implementation type members when expanding this pointer member.
I ended up having just one pretty printer with a children method figuring out the implementation type of the pointer member via the rtti_type method. I then use the normal cast method of the python API to (static) cast the value to its implementation type and return this value. This isn't clean, but didn't fail so far.
So, my vote as a user looks something like this:
Prio 1: commit this patch for the rtti_type method (I applied it to the current gdb 7.0 sources and was happy with it). ]
Prio 2: also add the C++ style casts to improve gdb command line experience for C++.
Prio 3: provide the C++ style casts in the Python API to make pretty printers like the one described above clean.
To those of you who celebrate Christmas - merry Christmas and enjoy your holidays. Jens.
-----Original Message-----
From: Tom Tromey [mailto:tromey@redhat.com]
Sent: Freitag, 30. Oktober 2009 18:25
To: Elmenthaler, Jens
Cc: gdb@sourceware.org
Subject: Re: Python pretty printers and dynamic cast
>>>>> "Jens" == Elmenthaler, Jens <jens.elmenthaler@verigy.com> writes:
Jens> Is there any way for a python pretty printer to do (or 'mimic') a
Jens> dynamic cast, such that I can show the members of the
Jens> implementation type where ever I have the interface type?
There is nothing built-in yet. We've had a few requests for this,
though, and there was a patch posted to the archer list. If you give it
a try, let us know how it turns out.
Tom