Tips for debugging SMTK

NB: This topic is a “wiki page,” which means anyone (not just the author) can edit it. Please add your own tips below.


Below are some niceties for using lldb with SMTK. There may be equivalents for gdb; if so, please add them to a new top-level section below this one.

Model entity type bits

If you deal with smtk::model::Entity objects a lot, you’ll notice that the m_entityFlags member is always a combination of values from smtk/model/EntityTypeBits.h . The enum values in the header file are hexadecimal and easier to read in a base that is some power of 2. You can have lldb print them in hexadecimal like so:

    ty fo add --format hex smtk::model::BitFlags

Adding the line above to your ~/.lldbinit file will make it the default behavior.

Inspecting UUIDs

If you use lldb, you can have it print UUIDs out compactly instead of the verbose and unhelpful unsigned char array. To do so,

  1. Create an .lldb directory in your home directory
    mkdir ~/.lldb
  1. Create a text file in ~/.lldb named with the following contents:
import lldb

def uuid_summary(value, *rest):
    """valobj: an SBValue which you want to provide a summary for
       internal_dict: an LLDB support object not to be used"""
    rawd = value.GetChildMemberWithName('data')
    s = ''.join('%02x'%i for i in
    return 'UUID(' + s[0:8] +'-' + s[8:12] + '-' + s[12:16] + '-' + s[16:20] + '-' + s[20:32] + ')'

def __lldb_init_module(debugger, *rest):
    summary = lldb.SBTypeSummary.CreateWithFunctionName('uuid.uuid_summary')
    debugger.GetDefaultCategory().AddTypeSummary(lldb.SBTypeNameSpecifier('boost::uuids::uuid', False), summary)
  1. Either add the line below to your ~/.lldbinit file or create a new file named ~/.lldbinit with the line below
command script import ~/.lldb/


If you are working with SMTK’s Qt extensions, you may be interested in these Qt5 formatters that let you inspect QString and some of Qt’s container classes.

Shared Pointers

SMTK provides some lldb python functions in utilities/lldb/ that allow you to stop execution when a particular object’s shared-pointer use-count changes. You can import these functions into your lldb function by running

  command script import /path/to/smtk/utilities/lldb/

Then, at a point where you have a pointer to some class that inherits enable_shared_from_this (like all smtk::resource::PersistentObject and smtk::operation::Operation classes), you can run the following

  useCountWatch <scoped class name> <address of class instance>
  # e.g.,
  # useCountWatch smtk::resource::Resource 0x142f240f0

to break when that object’s use count changes. Once you have a watchpoint on the use-count, there’s also a function to dump a stack trace to a file whenever the use count changes:

  useCountTrace <instance address> <filename> [<size of use-count in bytes>]
  # e.g.,
  # useCountTrace 0x142f240f0 /tmp/trace.txt 4

If calling the useCountWatch example above created watchpoint 1, then the following will add a script to the watchpoint to dump a stack trace and continue:

  wa co add 1
  > useCountTrace 0x142f240f0 /tmp/trace.txt
  > c
  > DONE 
Privacy Notice