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 失效/生效。
參考文章