lldb命令详解

前言

新博客

lldb命令的格式以下 :git

<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 bargithub

  • `要为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来标记多个公共库。segmentfault

  • 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 。debug

调试的时候,咱们常常须要打印界面的层次,使用如下命令:调试

po [[UIApp keyWindow] recursiveDescription]

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

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

相关文章
相关标签/搜索