thread jump:直接让程序跳到某一行。ARC 下编译器实际插入了很多 retain,release命令,跳过一些代码不执行极可能会形成对象内存混乱发生 crash。
watchpoint
观察变量或者属性
这是一个很是有用的东西,咱们常常遇到,某一个变量,不知道何时值被改掉了,就可使用这个东西去定位:
(lldb)
watchpoint set variable self->_string
不能使用点语法
watchpoint set expression (观察地址)
若是想观察某个地址,可使用 watchpoint set expression
例如:先拿到 _model 的地址,而后对地址设置一个 watchpoint
(lldb) p &_model
(Modek **) $3 = 0x00007fe0dbf23280
(lldb) watchpoint set expression 0x00007fe0dbf23280
Watchpoint created: Watchpoint 1: addr = 0x7fe0dbf23280 size = 8 state = enabled type = w
new value: 0
watchpoint command
跟 breakpoint 相似,watchpoint 也能够添加命令
watchpoint command add (添加观察点)
例如:
(lldb) watchpoint set variable xxx
Watchpoint created: Watchpoint 1: addr = 0x7fe4e1444760 size = 8 state = enabled type = w
watchpoint spec = '_string'
new value: 0x0000000000000000
watchpoint 的 id 是1.
watchpoint command add -o 'bt' 1
在 watchpoint 停下来时,打印了它的线程信息
也能够添加多条命令:
(lldb) watchpoint command add 1
Enter your debugger command(s). Type 'DONE' to end.
> bt
> continue
> DONE
watchpoint command list (某观察点全部命令)
watchpoint command list 1
列出某个 watchpoint 的全部 command
watchpoint command delete (观察点删除)
watchpoint command delete 1
删除某个 watchpoint 全部的 command
watchpoint list (观察点列表)
查看当前全部的 watchpoint,使用 watchpoint list
watchpoint disable (观察点失效)
让某个 watchpoint 失效
watchpoint enable (观察点生效)
使某个 watchpoint 生效
watchpoint delete index
删除某个 watchpoint。
不指定 index,则删除全部的 watchpoint。
target modules & image:查找地址对应的文件位置
LLDB 给 target modules 取了个别名 image。
image lookup -address
查找这个地址具体对应的文件位置。
好比:
TLLDB[25086:246169] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArray0 objectAtIndex:]: index 1 beyond bounds for empty NSArray'
*** First throw call stack:
(
0 CoreFoundation 0x000000010accde65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010a746deb objc_exception_throw + 48
2 CoreFoundation 0x000000010ac7c395 -[__NSArray0 objectAtIndex:] + 101
3 TLLDB 0x000000010a1c3e36 -[ViewController viewDidLoad] + 86
4 UIKit 0x000000010b210f98 -[UIViewController loadViewIfRequired] + 1198
5 UIKit 0x000000010b2112e7 -[UIViewController view] + 27
)
咱们能够看到数组越界了,可是
objectAtIndex: 的代码在哪呢?
使用 image lookup
(lldb) image lookup -a 0x000000010a1c3e36
Address: TLLDB[0x0000000100000e36] (TLLDB.__TEXT.__text + 246)
Summary: TLLDB`-[ViewController viewDidLoad] + 86 at ViewController.m:32
image lookup -name
查找一个方法 或者 符号的信息
例如: 第三方 SDK 有一个 Dictionary 的 catagory,和咱们本身的 catagory 冲突了,可是不知道在哪一个 .a 里面。
使用 image lookup -n dictionaryWithXMLString: 便可。
image lookup -type
查看一个类型
image lookup -t Model
全部的属性,实例变量都会打出来
target stop-hook
使用 LLDB debug,大多数时候须要让程序 stop。该命令能够在每次 stop 的时候去执行一些命令。
target stop-hook add & display
例如:每次程序 stop 时,都用命令打印当前 frame 的全部变量。能够添加一个 stop-hook
(lldb) target stop-hook add -o "frame variable"
-o:--one-liner,表示添加一条命令。
LLDB 提供了一个更简便的命令:display。下面这两条等同
(lldb) target stop-hook add -o "p self.view"
(lldb) display self.view
target stop-hook list
能够查看全部的 stop-hook
target stop-hook delete & undisplay
删除某个 stop-hook
(lldb) target stop-hook delete index
(lldb) undisplay index
target stop-hook disable/enable
使某个 stop-hook 失效/生效。
参考文章