[llvm-dev] GDB pretty printers for LLVM ADTs

David Blaikie via llvm-dev
2016-12-16T22:05:54Z

I've added a few LLVM GDB pretty printers a while back (& just added
llvm::Optional earlier today) & thought people might be interested in how
to use them, etc.

I use them by adding the following to my .gdbinit:

  source /path/to/llvm/src/utils/gdb-scripts/prettyprinters.py

Also, I can suggest adding:

  set print pretty on

there too, it helps a lot when printing complex nested data structures.

Once you have that, you can get pretty output like this:

(gdb) p Abbrev->AbbrDeclSets
$1 = std::map with 1 elements = {
  [0] = {
    Offset = 0,
    FirstAbbrCode = 1,
    Decls = std::vector of length 1, capacity 1 = {{
        Code = 1,
        Tag = llvm::dwarf::Tag::DW_TAG_compile_unit,
        CodeByteSize = 1 '\001',
        HasChildren = false,
        AttributeSpecs = llvm::SmallVector of length 8, capacity 8 = {{
            Attr = llvm::dwarf::Attribute::DW_AT_low_pc,
            Form = llvm::dwarf::Form::DW_FORM_addr,
            ByteSize = llvm::Optional is not initialized
          }, {
            Attr = llvm::dwarf::Attribute::DW_AT_high_pc,
            Form = llvm::dwarf::Form::DW_FORM_data8,
            ByteSize = llvm::Optional is initialized = {
              value = 8 '\b'
            }

Here you can see the pretty printers for SmallVector and Optional, but
there's also support for StringRef, SmallString, and ArrayRef.

I've tried doing a DenseMap pretty printer, but haven't quite figured it
out yet (having trouble calling member functions to do some of teh more
complicated parts of DenseMap iteration - may end up printing it with the
tombstone/empty values present, but not sure how easy that'll be to read,
etc). Happy to take requests or talk people through adding more pretty
printers anyone wants to add :)

Enjoy!
- Dave
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20161216/32476e74/attachment.html>