查看模块基址

1
2
(lldb) image list |grep prl_vm_app
[ 0] 08F2E3D7-D9F0-38E9-BA1F-0CA1E42095DE 0x000000010ca07000 /Applications/Parallels Desktop.app/Contents/MacOS/Parallels VM.app/Contents/MacOS/prl_vm_app

下断点

1
2
3
4
5
6
7
br set -a 0xXXXXXXXX 对地址下断点
br set -f filename -l line
br set -n viewDidLoad
br set -n "[类名 方法名]"
br list 列出断点
br disa 禁用所有
br en 3 启用断点3

如果需要添加条件, 在最后添加-c "width > 68", 条件为width > 68.

断点命令

1
2
3
4
5
(lldb) br com add 1
Enter your debugger command(s). Type 'DONE' to end.
> p i
> bt
> DONE

条件断点

1
2
3
w s e -- 0x123456
w s e -s 2 -- 0x123456
w s e -w read/write -s 2 -- 0x123456

查看寄存器

reg read, reg read rax

反汇编

显示指定地址的汇编

(lldb) dis -s $pc

也可以用x/i

通过(lldb) help arch获取支持的架构, 然后(lldb) dis -A arm -s $pc

单步

si, ni, fin等

设置变量

expr long $test = 12

p $test=123

读取和修改内存

x/10gx addr, ‘c, b, w, d, g’

memory write -s 2 'bytes' 1 2 3 4

自定义命令

1.别名(alias),使用简单,但是这个只能用来实现没有输入的命令
2.正则命令(command regex),可以通过正则表达式来捕获输入,并且将其应用到命令中.但是这个在执行多行命令的时候非常不方便,并且,这个只能有一个输入参数.
3.桥接脚本(script bridging) 基于python,这个很好的权衡了方便和复杂性.并且可以做任何LLDB能做的事情.

针对第三种:

在命令行直接运行:

1
2
script import sys
script print (sys.version)

在文件test.py中创建:

1
2
3
4
5
6
def findclass(debugger,command,result,internal_dict):
print("hello lldb")
# command 为输入

def __lldb_init_module(debugger, internal_dict):
debugger.HandleCommand('command script add -f findclass.findclass testcmd')

然后在lldb中引用command script import ~/test.py

调试

参考Remote Debugging

远程调试

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
./lldb-server platform --listen "*:1234" --server

进入lldb client端
(lldb) platform status # 查看平台状态
(lldb) platform list
(lldb) platform select remote-freebsd
Platform: remote-freebsd
Connected: no
(lldb) platform connect connect://192.168.1.8:1234
Platform: remote-freebsd
Triple: arm-unknown-linux-unknown
OS Version: 5.10.93 (5.10.93)
Hostname: localhost
Connected: yes
WorkingDir: /
Kernel: #1 SMP Wed Dec 7 15:20:41 CST 2022
(lldb)

更改workingdir

1
(lldb) platform settings -w /usr/local/bin

将本地文件推送到目的机器运行

1
2
(lldb) file a.out
(lldb) run

attach

1
2
3
file  [target_binary] # 指定将要调试的二进制文件,注意是相对于WorkingDir的路径
platform process list # 查看一直远端的进程, 找到目标进程pid, 或者名称
attach 9053

将本地文件推到目的机器指定目录

1
2
3
4
5
(lldb) file a.out
(lldb) script lldb.target.module['a.out'].SetPlatformFileSpec("/bin/a.out")
# 如果要包含模块
(lldb) target module add /local/build/libfoo.so # 本地地址
(lldb) script lldb.target.module['libfoo.so'].SetPlatformFileSpec("/usr/lib/libfoo.so")