This is the mail archive of the archer@sourceware.org mailing list for the Archer project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch] Fix glitches with libstdc++ pretty printers


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]