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

相关推荐
AGoodrMe8 小时前
swift基础之async/await
前端·ios
hhb_6189 小时前
Swift核心技术难点与实战案例解析
开发语言·ios·swift
人月神话-Lee9 小时前
【图像处理】饱和度——颜色的浓淡与灰度化
图像处理·人工智能·ios·ai编程·swift
人月神话-Lee13 小时前
【图像处理】卷积原理与卷积核——图像处理的核心引擎
图像处理·深度学习·ios·ai编程·swift
2501_9151063214 小时前
深入解析无源码iOS加固原理与方案,保护应用安全
android·安全·ios·小程序·uni-app·cocoa·iphone
Daniel_Coder16 小时前
iOS Widget 开发-15:Widget 性能优化指南
ios·swift·widget·widgetcenter
大熊猫侯佩16 小时前
升级到 macOS26.5 后看视频会自动息屏的解决
macos·操作系统
磊 子18 小时前
C++ IO 流
macos·objective-c·cocoa
库奇噜啦呼18 小时前
【iOS】源码学习-dyld加载
学习·ios·cocoa
Daniel_Coder18 小时前
iOS Widget 开发-16:Widget 网络数据加载策略
ios·swift·widget·widgetcenter