lldb命令详解

发布时间:2019-08-06 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了lldb命令详解脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

前言

新博客@H_512_4@

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 进行汇编代码的修改。)

脚本宝典总结

以上是脚本宝典为你收集整理的lldb命令详解全部内容,希望文章能够帮你解决lldb命令详解所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。