Pretty printer for gbd or lldb

Does anyone has the pretty printer of fundamental USD types for gdb (or llldb)?

Debugging USD codes is rather awkward with the default display of USD types in gdb. If anyone has the prettry printer of gdb/lldb or other solutions to make the debugging easier, please share here. Thanks a lot!

I can share a way of doing this with LLDB, but don’t have a lot of data formatters. Here’s an example of a data formatter for SdfPaths:

First you need a python module. I’ve called it lldb_formatters.py:

print("**** Loading USD Data Formatters *****")

import lldb

def sdfPathFormat(value, unused):
    if value is None or value.IsValid() == False or value.GetLoadAddress() == 0:
        return "<invalid>"
    expr = "((pxrInternal_v0_23__pxrReserved__::SdfPath*)0x%x)->GetString()" % (value.GetLoadAddress())
    return str(value.target.EvaluateExpression(expr, lldb.SBExpressionOptions()).GetSummary())

Then you need a .lldbinit file like this:

# Import the Python summary module
command script import --relative-to-command-file lldb_formatters

type summary add pxrInternal_v0_23__pxrReserved__::SdfPath --python-function lldb_formatters.sdfPathFormat

Now you can add formatters for all the common types. Things like GfVec3f don’t need Python and you can do these like this:

type summary add --summary-string "(${var.x}, ${var.y}, ${var.z})" pxrInternal_v0_23__pxrReserved__::GfVec3f

I’ve not worked out how to avoid using the full pxr namespace there, so you have to update when changing USD versions, but if you’re using multiple USD versions, using the full namespace is the correct thing to do.

Jerry

1 Like