This is the mail archive of the
archer@sourceware.org
mailing list for the Archer project.
Re: [patch] Fix glitches with libstdc++ pretty printers
- From: Paul Pluzhnikov <ppluzhnikov at google dot com>
- To: Tom Tromey <tromey at redhat dot com>
- Cc: archer at sourceware dot org
- Date: Thu, 18 Dec 2008 17:39:36 -0800
- Subject: Re: [patch] Fix glitches with libstdc++ pretty printers
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=google.com; s=beta;t=1229650779; bh=mZtotxnFurGaxWUl/BfGS48vfoM=;h=DomainKey-Signature:MIME-Version:In-Reply-To:References:Date: Message-ID:Subject:From:To:Cc:Content-Type: Content-Transfer-Encoding; b=IY2WQ1N3yzo91SulJ1pTDqakbsxCyEoyU6DqEZdTc2HNtsPrKNmwOgbn4i/n1dXTurkqVFL9V8JHeCIyetgIsw==
- Domainkey-signature: a=rsa-sha1; s=beta; d=google.com; c=nofws; q=dns;h=mime-version:in-reply-to:references:date:message-id:subject:from:to:cc:content-type:content-transfer-encoding;b=Hr7InFlvaUUXtdBzCNzNS1FMS4FflpEuMOMOa/om7u1wsBokD2qaK/EnfLFhDsHSsWc4f0vBvsCW41dIsepSdg==
- References: <20081015222935.0439C3A6AF5@localhost> <m3ljwpbher.fsf@fleche.redhat.com> <8ac60eac0810151624p6feca714j97d5cc8c54616b8b@mail.gmail.com> <m3vdvta080.fsf@fleche.redhat.com> <8ac60eac0810291732h44b685e1r5bebb1d954bac97a@mail.gmail.com>
On Wed, Oct 29, 2008 at 4:32 PM, Paul Pluzhnikov <ppluzhnikov@google.com> wrote:
> The approach I am considering is to put python pretty printing
> code into ".gdb_py" section in the object file which implements
> the "guts" of a container, and for GDB to automatically python-source
> this section when the object is loaded.
So, I am revisiting this ...
My use case is as follows:
- We use ProtocolBuffers (a lot!):
http://google-opensource.blogspot.com/2008/07/protocol-buffers-googles-data.html
- The classes are machine-generated, do not follow common naming
convention, but all inherit from a common ProtocolMessage ancestor,
which defines a ShortDebugString() method.
- I'd like to be able to pretty-print a vector of
SomeKindOfProtocolBuffer, and to that end I define a
pretty-printer:
class ProtocolMessagePrinter:
def __init__(self, val):
self.val = val
def to_string(self):
expr = "ProtocolMessage::ShortDebugString(%s)" % str(self.val.address())
return gdb.parse_and_eval(expr)
Now all I have to do is add lines like this:
gdb.pretty_printers['^ZooVisitor$'] = lambda val: ProtocolMessagePrinter(val)
gdb.pretty_printers['^ZooManager$'] = lambda val: ProtocolMessagePrinter(val)
gdb.pretty_printers['^ParkRanger$'] = lambda val: ProtocolMessagePrinter(val)
for each of the generated classes (of which there could be 500+).
It is easy for me to generate .gdb_py section containing above code
(just the "gdb.pretty_printers[...]" part), and then have GDB source
that section, but I don't see other reasonable way to get this info
to GDB. In particular, adding a post-link step to extract the same
info into exename-gdb.py is more difficult (our build system is
somewhat complicated, and outside of my control), and in addition
suffers from "not traveling well" (binaries get copied quite a bit,
so a binary that contains everything needed to debug it is
preferable).
Am I missing an easier way to solve this use case?
Would a patch to source ".gdb.py" section (if present) be acceptable?
Thanks,
--
Paul Pluzhnikov