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常用命令

相关推荐
Anhty4 小时前
2026九月最新变声器测评:iOS安卓双端适配,低延迟运行更稳定
android·人工智能·功能测试·ios·智能手机
黄一一9112435 小时前
跨平台视频图片压缩互转!离线视频压缩工具!Github开源轻松无损压缩视频!Win/Mac/Linux三端通用开源工具
windows·macos·音视频·开源软件
_瑞13 小时前
APM_OOMDetector
ios
秋雨梧桐叶落莳13 小时前
【iOS】从源码深入理解RunLoop机制
macos·ios·objective-c·cocoa·cocoapods·uikit
烂蜻蜓14 小时前
Flask入门教程(二十七):Session Interface API——自定义Session存储后端
网络·ios·flask
用户380341658829714 小时前
VideoToolbox 硬编解码的十个坑:为什么它几乎从不报错
ios
别走!万哥爱你14 小时前
Mac访达中不显示iPad或iPhone怎么办?
macos·iphone·ipad
bcbnb15 小时前
Flutter-Notebook代码混淆:Android与iOS平台安全配置
后端·ios
ACP广源盛1392462567315 小时前
M6/M5 Pro Mac mini 端侧 AI 爆发@ACP#YLB3118 存储扩展芯片在本地 AI 服务中的机会与落地场景
大数据·网络·数据库·人工智能·嵌入式硬件·macos
2501_9151063216 小时前
第一次开发 iPhone App,可能碰到的问题,解决办法
ide·vscode·ios·objective-c·个人开发·swift·敏捷流程