This is the mail archive of the
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: Wed, 29 Oct 2008 17:32:22 -0700
- 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=1225326746; bh=asSvo0+OiOhZwBwun7G7V+GiPS8=;h=DomainKey-Signature:Message-ID:Date:From:To:Subject:Cc: In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-Disposition:References; b=fvDyyygCwG3l+je4TKeCOdpUr5RXGGMJK6qBWAwyLZE20z2YCwoEpYw+O2xaz4j8D4NweZt7pSNUAgaCz6DCbA==
- Domainkey-signature: a=rsa-sha1; s=beta; d=google.com; c=nofws; q=dns;h=message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references;b=Jycf4j7A+h0qOjX+u/lBfvVynmfbFAG7pjbyWAGuQwHPWWAG+vt5W/odSoYUE0poBml2pxAQWPqEQnG9OncdOw==
- References: <20081015222935.0439C3A6AF5@localhost> <firstname.lastname@example.org> <email@example.com> <firstname.lastname@example.org>
On Wed, Oct 15, 2008 at 4:48 PM, Tom Tromey <email@example.com> wrote:
> Paul> The question of "who and how should maintain this" is an interesting
> Paul> one. Ideally you'd want container writers to do that, and you'd want
> Paul> this code to be somehow embedded in the binary with the rest of
> Paul> debug info, so the end user can pretty print any container and not
> Paul> worry about the pretty printer getting out of sync with container
> Paul> implementation. But I have no clue how to achieve this :(
> This already works! :-)
> When gdb opens a new objfile, it will look for a ".gdb.py" in the
> objfile's directory. If it exists, it is passed to Python.
> This setup also works fine with separate debug info.
> I'm not 100% happy with this approach. It works great if you assume
> separate debug info. But, if you have a more traditional setup, you
> only get one .gdb.py per directory -- not super.
> So, some refinement is needed. Let me know what you think.
As you pointed out, this may break if e.g. libstdc++.so.5,
libstdc++.so.6 and libfancy_container.so.1 are all in /lib, there
is no separate debuginfo, and all 3 libraries "fight" for /lib/.gdb.py.
Also, if a newer binary is installed, but the .gdb.py file isn't,
things break as well (Microsoft .PDB files have this inconvenient
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.
Obviously this only works for object file formats which are flexible
enough to have multiple named sections, such as ELF.
There is also a question of what to do about containers that are
implemented entirely in a header file.
Ignoring the 2 issues above for the moment, I expect the following
"use case" to work well here at Google:
- Developer implements SomeClass for which a pretty-printer is
- As developer debugs it, he writes SomeClass.py to pretty print it,
and loads that manually into GDB.
- Once everything looks good, developer appends something like:
#pragma embed_source(".gdb_py", "./SomeClass.py")
to SomeClass.cc, and gcc does the rest.
[This #pragma is just for convenience, so developer doesn't have
to (painfully) reformat the Python source into
__asm__ (".section .gdb_py\n"
"\t.string \"class StdListPrinter:\"\n"
Alternatively, an objcopy could be used to add .gdb_py section
When multiple objects are linked into DSO or an executable,
linker will merge all .gdb_py sections, so you get pretty printers
for all the containers actually used.