40

I am looking for a solid tutorial on creating a custom printer.

There are a few sparse pages on the GDB page however they are far from complete and leave much to the imagination!

For instance, I'd love to be able to create a PrettyPrinter for our custom shared pointer class.

Toon Krijthe
  • 52,876
  • 38
  • 145
  • 202
Setheron
  • 3,520
  • 3
  • 34
  • 52
  • 1
    You mean these http://sourceware.org/gdb/current/onlinedocs/gdb/Writing-a-Pretty_002dPrinter.html#Writing-a-Pretty_002dPrinter? – Nikolai Fetissov Sep 25 '12 at 02:49
  • 4
    yes those leave much up to the imagination of implementing pretty printers for complex structures for instance. – Setheron Sep 26 '12 at 21:14

2 Answers2

40

Check out Tom Tromey's pretty printing tutorials part 1 and part 2. There is also the libstdc++-v6 pretty printer implementation to look at, which is what I used myself as a template when I started out. A somewhat simpler example (as of this writing) is the Boost pretty printer by Rüdiger Sonderfeld.

js.
  • 1,787
  • 19
  • 22
David Holm
  • 17,522
  • 8
  • 47
  • 47
15

This one looks interesting for starters: Python Pretty-Printers from redhat

From this simple tutorial, you can proceed to more advanced ones. Here is a good example:Pretty-printers for libstc++