iOS_Xcode_LLDB调试常用命令

文章目录

结构

命令结构:

llvm 复制代码
// 命令结构:
<command> [<subcommand> [<subcommand>...]] <action> [-options [optionvalue]] [argument [argument...]]
命令 子命令 命令操作 命令选项 命令参数

常用命令:

llvm 复制代码
expression:表达式
thread backtrace:堆栈
thread:线程
frame:栈帧
breakpoint:符号断点
watchpoint:内存断点
image:镜像
register:寄存器
memory:内存

continue:继续
next:下一步
step:跳进
finish:跳出

call:执行方法

查看帮助:help <command> [<subcommand>]

查看命令具体帮助:apropos <command>


流程控制:

1、流程控制:

  • 源码级别 source level:
llvm 复制代码
// 单步运行
thread step-in / step / s // 会进入函数内部
thread step-over / next / n // 不会进入函数内部
  • 指令级别 instruction level:

需要设置:Debug → Debug workflow → Always Show Disassembly

llvm 复制代码
// 在汇编页面
thread step-inst / stepi / si  // 会进入函数内部
thread step-inst-over / ni  // 不会进入函数内部
  • 继续、退出
llvm 复制代码
// 从一个函数跳出(若没有执行s/si, 会跳到汇编指令bl的下一条位置)
thread step-out / finish / f
// 要从嵌套的 step-out 中退出,可执行 c 跳转到下一个断点
process continue / continue / c

2、常用命令

llvm 复制代码
// 执行表达式
expression / expr / p

// 打印1:print = p
p person
(Person *) $0 = 0x000000010053b7f0

// 打印2:expression -o / expr -o / po 
po person
<Person: 0x10053b7f0>
// 若接受到的对象是一个指针,会调用它的 description 方法打印
// 若接受到的对象是 CoreFoundation 对象,会调用它的 CFShow 方法打印
// 其他情况同 p

// 修改背景色
expr tableView.backgroundColor = UIColor.red

// 查看变量类型结构
fr v -R a
(Swift.Int) a = {
  _value = 10
}

3、进程信息:

llvm 复制代码
thread list # 线程列表
// 堆栈
thread backtrace all # 所有线程堆栈
thread backtrace # 当前线程堆栈
thread backtrace 2 # 线程2堆栈

// 跳出当前执行的方法(后面的不执行)
thread return
thread return 20

// 栈帧
frame info // 栈帧信息
frame variable // 帧变量列表
frame select 0 // 选择帧
// 移动帧:up:序号+1 down:序号-1

4、寄存器:register

llvm 复制代码
register read
register write rax 123

5、镜像:image

llvm 复制代码
// 依赖库列表
image list
// 查找模块
image lookup -type class // 查看class所有属性和成员变量
image lookup -name '方法名' // 查找方法来源
image lookup -address 地址 // 查找崩溃位置

6、内存:memory

llvm 复制代码
memory read/数量+格式+字节数 内存地址
// 格式:x为16进制,f位浮点数,d为10进制
// 字节数:b为1个字节,h为2个字节,w为4个字节,g为8个字节

// 例:
x/4xg 0x00006000001600b0
memory read 0x00006000001600b0
memory read/3xg 0x00006000001600b0
memory read/8xg 0x00006000001600b0
memory read/8xw 0x00006000001600b0
memory read/3dw 0x00006000001600b0
memory read/3fw 0x00006000001600b0

// 写内存
memory write 内存地址 述职

7、符号断点:breakpoint

llvm 复制代码
// 列出所有断点
breakpoint list
// 设置断点
breakpoint set -address 0x000000 // 函数地址
breakpoint set -name "viewDidLoad" // 函数名

breakpoint disable 断点编号 // 禁用断点
breakpoint enable 断点编号 // 启用断点
breakpoint delete 断点编号 // 删除断点

8、内存断点:watchpoint

llvm 复制代码
watchpoint set variable 变量
watchpoint set expression 地址
watchpoint list
watchpoint diable 断点编号
watchpoint enable 断点编号
watchpoint delete 断点编号
watchpoint command add 断点编号
watchpoint command list 断点编号
watchpoint command delete 断点编号

9、Tips:

反引号:a,会用表达式解析器运行该值的文本,将值替换为该文本

memory read -c len 0x12345

当参数以-开头,前面需要用- -隔开:

process launch --stop-at-entry -- -program_arg value


参考:

官网:https://lldb.llvm.org/

官方教程:https://lldb.llvm.org/use/tutorial.html

lldb常用命令与调试技巧

iOS开发之LLDB常用命令

相关推荐
游戏开发爱好者82 小时前
日常开发与测试的 App 测试方法、查看设备状态、实时日志、应用数据
android·ios·小程序·https·uni-app·iphone·webview
黑码哥3 小时前
ViewHolder设计模式深度剖析:iOS开发者掌握Android列表性能优化的实战指南
android·ios·性能优化·跨平台开发·viewholder
2501_915106324 小时前
app 上架过程,安装包准备、证书与描述文件管理、安装测试、上传
android·ios·小程序·https·uni-app·iphone·webview
2501_915106324 小时前
使用 Sniffmaster TCP 抓包和 Wireshark 网络分析
网络协议·tcp/ip·ios·小程序·uni-app·wireshark·iphone
熊猫钓鱼>_>5 小时前
移动端开发技术选型报告:三足鼎立时代的开发者指南(2026年2月)
android·人工智能·ios·app·鸿蒙·cpu·移动端
徐同保1 天前
通过ip访问nginx的服务时,被第一个server重定向了,通过设置default_server解决这个问题
ios·iphone
皮卡车厘子1 天前
Mac 挂载目录
macos
良逍Ai出海1 天前
在 Windows & macOS 上安装 Claude Code,并使用第三方 Key 的完整教程
windows·macos
热爱生活的五柒1 天前
linux/mac/wsl如何使用claude code,并配置免费的硅基流动API?(官方的需要付费订阅)
linux·运维·macos
2501_915918411 天前
在 iOS 环境下查看 App 详细信息与文件目录
android·ios·小程序·https·uni-app·iphone·webview