常用LLDB指令

/ 0评 / 0

LLDB就是iOS上面的调试指令,命令格式是

command [ [...]] [-options [optionvalue]] [argument [argument...]]

比如给test函数设置断点

breakpoint set -n test

help

玩过命令行的都应该知道这个命令,能给我们提供很多命令的帮助,而我们这里也可以使用这个指令查询帮助
比如:

help breakpoint
help breakpoint set

expression --

执行一个表达式 --表示命令选项结束符,比如

expression self.view.backgroundColor = [UIColor redColor]

expression、expression -- 和指令print、p、call的效果一样
expression -O --和指令po的效果一样

thread backtrace

打印线程堆栈信息,和指令bt的效果一样

thread return []

让函数直接返回某个值,不会执行断点后面的代码

frame variable []

打印当前帧的变量

thread continue、continue、c

程序继续运行

thread step-over、next、n

单步运行,把子函数当做整体一步执行

thread step-in、step、s

单步运行,遇到子函数会进入子函数

thread step-out、finish

直接执行完当前函数的所有代码,返回到上一个函数

thread step-inst-over、nexti、ni

thread step-inst、stepi、si

si、ni和s、n类似

s、n是源码级别
si、ni是汇编指令级别

breakpoint set

设置断点
breakpoint set -a 函数地址
breakpoint set -n 函数名
breakpoint set -r 正则表达式
breakpoint set -s 动态库 -n 函数名

breakpoint set -n test
breakpoint set -n touchesBegan:withEvent:
breakpoint set -n "-[ViewController touchesBegan:withEvent:]"

breakpoint list

列出所有的断点,每个断点都有自己的编号

breakpoint disable 断点编号

禁用断点

breakpoint enable 断点编号

启用断点

breakpoint delete 断点编号

删除断点

breakpoint command add 断点编号

给断点预先设置需要执行的命令,到触发断点时,就会按顺序执行

breakpoint command list 断点编号

查看某个断点设置的命令

breakpoint command delete 断点编号

删除某个断点设置的命令

image lookup

image lookup -t 类型:查找某个类型的信息
image lookup -a 地址:根据类型地址查找在模块中的位置
image lookup -n 符号或者函数名:查找某个符合或者函数的位置

image list

列出所加载的模块信息

image list -o -f

打印模块的偏移地址,全路径

内存断点

在内存数据发生改变时触发(用的应该不多)

watchpoint set variable 变量

watchpoint set variable self->age

watchpoint set expression 地址

watchpoint set expression &(self->_age)

watchpoint list

watchpoint disable 断点编号

watchpoint enable 断点编号

watchpoint delete 断点编号

watchpoint command add 断点编号

watchpoint command list 断点编号

watchpoint command delete 断点编号

小技巧

敲回车键,会自动执行上次的指令
绝大部分指令可以使用缩写

评论已关闭。