lldb tips

Commands can have three forms:
Discoverable form: expression –object-description — foo
Abbreviated from  : e -O — foo
Alias: po foo


b MyView.m: 4
breakpoint set –file MyView.m –line 4

b “-[MyViewA drawRect:]”
breakpoint set –name “-[MyViewA drawRect:]”

b drawRect:
breakpoint set –selector drawRect:

br co a / breakpoint command add  Breakpoint commands run each time a breakpoint is hit
> p rect expression rect
> bt thread backtrace
> c process continue

p id $myModel = self  expression id $myModel = self // Create a presistent variable of type id
b “-[MyModel dealloc]”
br m -c “self == $myModel” breakpoint modify –condition “self == $myModel”

Watch Points 4 on Intel, 2 on ARM
w s v self->_needsSynchronization
watchpoint set variable self->_needsSynchronization

Stepping can hit breakpoints
LLDB maintains a stack of things you are doing
When you step, LLDB puts it on the stack
If you hit a breakpoint LLDB remembers the stack
So, when hit continue, LLDB will get you back to where when you hit step

Stepping repeatedly over irrelevant code gets old quickly
th u 11
thread until 11 

Call the code using Clang
b “-[ModelDerived removeDuplicates]”
e -i false — [self removeDuplicates]
expression –ignore-breakpoints false — [self removeDuplicates]

Data Formatters
Xcode 5 can show memory summary in debug area, It has builtin DataFormatters for Foundation CoreFoundation and STL
LLDB pass SBValue to formatter

def MyAddress_Summary(value, unused):
    firstName = value.GetChildMemberWithName("_firstName")
    lastName = value.GetChildMemberWithName("_lastName")
    firstNameSummary = firstName.GetSummary()
    lastNameSummary = lastName.GetSummary()
    return firstNameSummary + " " + lastNameSummary

ty su a MyAddress -F MyAddress_Summary

Define Types in Console
typedef $NoOpaque {
int foo; int bar

Custom LLDB Commands

SB stands for Script Bridge
def MyCommand_Impl(debugger, user_input, result, unused)
co sc a foo -f foo

thread = debugger.GetSelectedTarget().GetProcess().GetSelectedThread()
for frame in thread.frames:
    if frame.function.name == "MyFunction":
        # update counters
    print >>result, "depth: " + str(depth)

~/.lldbinit loaded at debugger startup