LLDB 调试
最编程
2024-03-01 22:26:17
...
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 失效/生效。
参考文章
与调试器共舞 - LLDB 的华尔兹
dSYM详细资料
iOS中framework的联调
上一篇: iOS 开发 LLDB 通用命令
推荐阅读
-
Linux MIPI DSI 驱动程序调试说明 - LCD 时序参数配置 (III)
-
Java 调试接口 (JDI) 的深度 Java 调试系统
-
使用 Eclipse 构建 Raspberry Pi 远程调试环境
-
飞思卡尔的工具 freemaster 可与 powerpc 调试器配合使用
-
Plankton Embedded:用于飞思卡尔 Kinetis 开发板的 OpenSDA 调试器(第 1 部分)--背景和架构
-
stm32 HardFault_Handler 调试和问题查找方法 - Freescale
-
基于飞思卡尔 i.MX 6Quad Sabrelite 开发板的触摸屏调试
-
飞思卡尔硬件调试概要
-
逐步学习 FRDM-KE02Z (I):IAR 调试平台构建和 OpenSDA 两种工作模式设置
-
Win10 蓝牙调试工具 Bluetooth LE Explorer 简单易用