lldb命令详解

前言

新博客

lldb命令的格式如下 :

<noun> <verb> [-options [option-value]] [argument [argument..]]

断点管理

  • 简单地通过文件和行号进行断点 :
breakpoint set --file foo.c --line 12
breakpoint set -f foo.c -l 12
  • 通过函数的名称来设置断点 :
breakpoint set --name foo
breakpoint set -n foo
  • 可以同时使用 -n来设置多个函数的断点:

`breakpoint set -n foo -n bar

  • `要为C++函数设置断点,使用method :
breakpoint set --method foo
breakpoint set -M foo
  • 设置 OC里面selector的断点 :
breakpoint set --seletor alignLeftEdges:
breakpoint set -S alignLeftEdges:
  • 也可以针对可执行的image设置断点 :
breakpoint set --shlib foo.dylib --name foo
breakpoint set -s foo.dylib -n foo

可以重复使用 --shlib来标记多个公共库。

  • breakpoint简写为br :
breakpoint set -n "-[SKTGraphicView alignLeftEdges:]"
br s -n "-[SKTGraphicView alignLeftEdges:]"
(lldb) br list
No breakpoints currently set.
(lldb) br li 
No breakpoints currently set.

使用 breakpoint delete id 删除断点,简写 br del, 使用breakpoint enable id 和 breakpoint disable id 来启用或禁用断点,

自定义alias

我们可以设置alias :

`command alias bfl breakpoint set -f %1 -l %2
`
`bfl foo.c 12
`用户可以修改~/.lldbinit文件,以存储自己的快捷键。

流程控制

process continue 取消暂停,继续执行函数 ,别名是 continue,简写是 c.

thread step-over : 执行当前函数中的一行代码,但是不跳进函数。简写是 next ,n 。

thread step-in : 跳进函数中, 简写 step,s 。

thread step-out : 跳出函数,简写是 finish 。

thread list : 列出线程列表

thread backtrace : 列出线程堆栈。可以通过thread select 2切换线程。 thread backtrace all 输出所有线程堆栈

thread return <RETURN EXPRESSION> : 直接返回当前函数, 可以设置返回值。

查看当前的断点的函数信息。

(lldb) frame info 
frame #0: 0x0000000114ab4e76 libsystem_kernel.dylib`mach_msg_trap + 10

可以通过help命令查看帮助, 如help frame ,help thread , help process 。

调试的时候,我们经常需要打印界面的层次,使用以下命令:

po [[UIApp keyWindow] recursiveDescription]

recursiveDescription是一个私有函数。会打印出view的所有层次信息。

lldb高级

初始化程序,目的是从程序入口就开始进行附着,这样我们就可以在一些安全防护代码执行之前,进行破解。 最常用的就是跳过ptrace

  • 添加Action以在断点时,执行自定义事件
(lldb) breakpoint set -n isEven
Breakpoint 1: where = DebuggerDance`isEven + 16 at main.m:4, address = 0x00000001083b5d00
(lldb) breakpoint modify -c 'i == 99' 1
(lldb) breakpoint command add 1
Enter your debugger command(s).  Type 'DONE' to end.
> p i
> DONE
 breakpoint modify -c 'i == 99' 1 指添加action的触发条件。

ps:hopper中最常用的操作(直接修改汇编代码 ,在菜单Modify - Assemble Instruction 进行汇编代码的修改。)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值