lldb tips

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

Breakpoints

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
> DONE

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
http://lldb.llvm.org/varformats.html
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
expression
typedef $NoOpaque {
int foo; int bar
}
($NoOpaque)Opaque

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
~/.lldbinit-Xcode

Xcode 4 无法打开 Xcode 5 DP 打开过的工程文件 解决方法

试用Xcode 5 DP打开现有工程文件后再用Xcode4打开后 Xcode 4 会进入崩溃模式
折腾了几次发现下面的方法可以让工程文件恢复

如果在Xcode5-DP中打开过xib文件需要在侧栏中修改Interface Builder Document下的Open in为Xcode 4.6, 然后Clean,关掉工程,再到DerivedData中删掉对应的文件夹

如果遇到打开xib还会崩的话可以找一个没有用Xcode5-DP打开过的xib把两个文件用文本编辑器打开,对比着把前几行的版本号修改一下

另外还可以尝试删除 .xcodeproject中的.xcworkspace 与 xcuserdata

还有打开后4下断点失效的问题,可以试试设置link-time optimization为NO