LLDB 常用命令

作者: YxxxHao | 来源:发表于2019-08-20 21:40 被阅读8次

较常用的命令都会带 ⭐️ ⭐️ ⭐️

执行命令

LLDB
启动一个没有参数的进程(Xcode断点时相当于执行 run 相当 Com+R)
(lldb) process launch
(lldb) run
(lldb) r
启动一个带参数的进程
(lldb) process launch -- <args>
(lldb) r <args>
在当前选择的线程中执行源级单个步骤,会进入了函数里面
(lldb) thread step-in
(lldb) step
(lldb) s
⭐️ 在当前选择的线程中执行源级单步操作
(lldb) thread step-over
(lldb) next
(lldb) n
⭐️ 在当前选择的线程中执行一个指令级的单步操作,si会单步进入汇编指令的子函数内部,ni 不会
(lldb) thread step-inst
(lldb) si
⭐️ 在当前选择的线程中执行一个指令级的单步操作
(lldb) thread step-inst-over
(lldb) ni
退出当前选定的帧
(lldb) thread step-out
(lldb) finish
⭐️ 立即从当前选定的帧返回,并带有可选的返回值
(lldb) <RETURN EXPRESSION>
设置每次停止时,执行指定的操作
(lldb) target stop-hook add
Enter your stop hook command(s). Type 'DONE' to end.
> bt
> disassemble --pc
> DONE
Stop hook #1 added.
运行到当前函数的第12行,或离开当前函数为止
(lldb) thread until 12

断点命令

LLDB
在 main 方法上设置断点
(lldb) breakpoint set --name main
(lldb) br s -n main
(lldb) b main
在指定文件和指定行上设置断点
(lldb) breakpoint set --file test.c --line 12
(lldb) br s -f test.c -l 12 (lldb) b test.c:12
设置 C++ 方法的断点
(lldb) breakpoint set --method main
(lldb) br s -M main
给一个 oc 方法添加断点
(lldb) breakpoint set --name "-[NSString stringWithFormat:]"
(lldb) b -[NSString stringWithFormat:]
给一个 oc 方法添加断点
(lldb) breakpoint set --selector count
(lldb) br s -S count
通过正则表达式在函数名上设置断点
(lldb) breakpoint set --func-regex regular-expression
(lldb) br s -r regular-expression
通过指定文件和行数来设置断点
(lldb) settings set target.inline-breakpoint-strategy always
(lldb) br s -f foo.c -l 12
通过正则表达式对源文件内容设置断点
(lldb) breakpoint set --source-pattern regular-expression --file SourceFile
(lldb) br s -p regular-expression -f file
设置条件断点
(lldb) breakpoint set --name foo --condition '(int)strcmp(y,"hello") == 0'
(lldb) br s -n foo -c '(int)strcmp(y,"hello") == 0'
获取断点列表
(lldb) breakpoint list
(lldb) br l
删除一个断点
(lldb) breakpoint delete 1
(lldb) br del 1

watchpoint 命令

LLDB
⭐️ 观察一个属性的变化
(lldb) watchpoint set variable varName
(lldb) wa s v varName
⭐️ 观察一个指针
(lldb) watchpoint set expression -- my_ptr
(lldb) wa s e -- my_ptr
设置观察点的条件
(lldb) watch set var global
(lldb) watchpoint modify -c '(global==5)'
(lldb) c ...
(lldb) bt * thread #1: tid = 0x1c03, 0x0000000100000ef5 a.outmodify + 21 at main.cpp:16, stop reason = watchpoint 1 frame #0: 0x0000000100000ef5 a.outmodify + 21 at main.cpp:16 frame #1: 0x0000000100000eac a.outmain + 108 at main.cpp:25 frame #2: 0x00007fff8ac9c7e1 libdyld.dylibstart + 1
(lldb) frame var global (int32_t) global = 5
所有 watchpoint 列表
(lldb) watchpoint list
(lldb) watch l
删除一个 watchpoint
(lldb) watchpoint delete 1
(lldb) watch del 1

查看变量

LLDB
⭐️ 显示当前帧的参数和局部变量
(lldb) frame variable
(lldb) fr v
⭐️ 显示当前帧的局部变量
(lldb) frame variable --no-args
(lldb) fr v -a
⭐️ 显示局部变量的内容
(lldb) frame variable bar
(lldb) fr v bar
(lldb) p bar
显示格式化为十六进制的局部变量的内容
(lldb) frame variable --format x bar
(lldb) fr v -f x bar
显示全局变量的内容。
(lldb) target variable varName
(lldb) ta v varName
⭐️ 显示当前源文件中定义的全局/静态变量
(lldb) target variable
(lldb) ta v
每次停止时显示变量“argc”和“argv”
(lldb) target stop-hook add --one-liner "frame variable argc argv"
(lldb) ta st a -o "fr v argc argv"
(lldb) display argc
(lldb) display argv
当在main函数断点时,显示 argc 和 argv 参数
(lldb) target stop-hook add --name main --one-liner "frame variable argc argv"
(lldb) ta st a -n main -o "fr v argc argv"
当断点停在在 C 实现的 MyClass 时,展示成变量 this
(lldb) target stop-hook add --classname MyClass --one-liner "frame variable this"
(lldb)* ta st a -c MyClass -o "fr v *this"

执行表达式

LLDB
计算当前帧中的广义表达式
(lldb) expr (int) printf ("Print nine: %d.", 4 + 5)
(lldb) print (int) printf ("Print nine: %d.", 4 + 5)
⭐️ 新增一个便捷变量并赋值
(lldb) expr unsigned int $foo = 5
⭐️ 打印对象的描述
(lldb) expr -o -- [SomeClass returnAnObject]
(lldb) po [SomeClass returnAnObject]
打印表达式结果的动态类型。
(lldb) expr -d 1 -- [SomeClass returnAnObject]
⭐️ 调用一个函数,以便可以在函数的断点处停止。
(lldb) expr -i 0 — [self xxxxx]
⭐️ 调用崩溃的函数,并在函数崩溃时停止。
(lldb) expr -u 0 — [self xxxxx]

检查线程状态

LLDB
⭐️ 程序中的线程列表
(lldb) thread list
选择线程1作为后续命令的默认线程
(lldb) thread select 1
(lldb) t 1
⭐️ 显示当前线程的堆栈回溯
(lldb) thread backtrace
(lldb) bt
显示所有线程的堆栈回溯
(lldb) thread backtrace all
(lldb) bt all
回溯当前线程的前五帧
(lldb) thread backtrace -c 5
(lldb) bt 5
(lldb) bt -c 5
按索引为当前线程选择不同的堆栈帧
(lldb) frame select 12
(lldb) fr s 12
(lldb) f 12
列出当前线程中当前选定帧的相关信息
(lldb) frame info
选择当前堆栈帧的上一个堆栈帧
(lldb) up
(lldb) frame select --relative=1
选择当前堆栈帧的下一个堆栈帧
(lldb) down
(lldb) frame select --relative=-1
(lldb) fr s -r-1
使用相对偏移量选择不同的堆栈帧。
(lldb) frame select --relative 2
(lldb) fr s -r2
(lldb) frame select --relative -3
(lldb) fr s -r-3
显示当前线程的通用寄存器。
(lldb) register read
修改寄存器 rax 的值
(lldb) register write rax 123
跳过当前程序计数器(指令指针)之前的8个字节。注意,我们使用反引号来计算表达式并将标量结果插入LLDB。
(lldb) register write pc `$pc+8``
显示当前线程的通用寄存器,其格式为带符号的十进制
(lldb) register read --format i
(lldb) re r -f i
显示当前线程的所有寄存器
(lldb) register read --all
(lldb) re r -a
显示当前线程中名为“rax”、“rsp”和“rbp”的寄存器的值。
(lldb) register read rax rsp rbp
显示当前线程中名为“rax”的寄存器的值,其格式为binary
(lldb) register read --format binary rax
(lldb) re r -f b rax
从地址0xbffff3c0读取内存,并显示4个十六进制uint32_t值。
(lldb) memory read --size 4 --format x --count 4 0xbffff3c0
(lldb) me r -s4 -fx -c4 0xbffff3c0
(lldb) x -s4 -fx -c4 0xbffff3c0
从表达式“argv[0]”开始读取内存。
(lldb) memory read argv[0]
(lldb) memory read --size sizeof(int) argv[0]
从地址0xbffff3c0读取512字节的内存,并将结果保存为text的本地文件。
(lldb) memory read --outfile /tmp/mem.txt --count 512 0xbffff3c0
(lldb) me r -o/tmp/mem.txt -c512 0xbffff3c0
(lldb) x/512bx -o/tmp/mem.txt 0xbffff3c0
将从0x1000开始并以0x2000结尾的二进制内存数据保存到文件中。
(lldb) memory read --outfile /tmp/mem.bin --binary 0x1000 0x2000
(lldb) me r -o /tmp/mem.bin -b 0x1000 0x2000
获取关于特定堆分配的信息(仅在Mac OS X上可用)。
(lldb) command script import lldb.macosx.heap
(lldb) process launch --environment MallocStackLogging=1 -- [ARGS]
(lldb) malloc_info --stack-history 0x10010d680
获取有关特定堆分配的信息,并将结果转换为可推断的任何动态类型(仅在Mac OS X上可用)
(lldb) command script import lldb.macosx.heap
(lldb) malloc_info --type 0x10010d680
查找包含由表达式EXPR指定的指针的所有堆块(仅在Mac OS X上可用)。
(lldb) command script import lldb.macosx.heap
(lldb) ptr_refs EXPR
查找块中任何位置包含C字符串的所有堆块
(lldb) command script import lldb.macosx.heap
(lldb) cstr_refs CSTRING
反汇编当前断点所在函数
(lldb) disassemble --frame
(lldb) di -f
反汇编指名字的函数
(lldb) disassemble --name main
(lldb) di -n main
反汇编指定范围代码
(lldb) disassemble --start-address 0x1eb8 --end-address 0x1ec3
(lldb) di -s 0x1eb8 -e 0x1ec3
从指定地址开始反汇编
(lldb) disassemble --start-address 0x1eb8 --count 20
(lldb) di -s 0x1eb8 -c 20
当前函数的混合源和反汇编
(lldb) disassemble --frame --mixed
(lldb) di -f -m
反汇编当前函数并显示操作码字节
(lldb) disassemble --frame --bytes
(lldb) di -f -b
反编译当前行
(lldb) disassemble --line
(lldb) di -l

可执行文件和共享库查询命令

LLDB
列出主要的可执行文件和所有依赖的共享库
⭐️ (lldb) image list
⭐️ 在可执行文件或任何共享库中查找原始地址信息
(lldb) image lookup --address 0x1ec4
(lldb) im loo -a 0x1ec4
查找二进制中匹配正则表达式的函数
This one finds debug symbols:
(lldb) image lookup -r -n <FUNC_REGEX>
This one finds non-debug symbols:
(lldb) image lookup -r -s <FUNC_REGEX>
查找完整的源代码行信息
(lldb) image lookup -v --address 0x1ec4
在 a.out 找看指定地址内容
(lldb) image lookup --address 0x1ec4 a.out
(lldb) im loo -a 0x1ec4 a.out
⭐️ 根据名称查找类型“Point”的信息。
(lldb) image lookup --type Point
(lldb) im loo -t Point
转储主可执行文件和任何共享库中的所有部分。
(lldb) image dump sections
转储主可执行文件和任何共享库中的所有部分到a.out
(lldb) image dump sections a.out
从主可执行文件和任何共享库中转储所有符号
(lldb) image dump symtab
从主可执行文件和任何共享库中转储所有符号到a.outliba.so
(lldb) image dump symtab a.out liba.so

相关文章

  • lldb调试

    1. 常用命令 (lldb) thread step-over // The same as "next" or ...

  • 常用调试命令

    LLDB常用命令 LLDB是LLVM下的调试器 p 输出基本类型 po 输出objc对象 expr 断点调试时,在...

  • iOS 开发中 LLDB 常用命令整理

    iOS 开发中 LLDB 常用命令整理 expression(或者缩写expr) 表达式 expression ...

  • 六、iOS逆向之《LLDB高级用法&Cycript》

    前言 上节文章讲解了一些lldb的常用命令,这篇文章我们来讲解一些lldb的高级用法。 一、ASLR ASLR概述...

  • # LLDB调试一些常用命令和技巧

    LLDB调试一些常用命令和技巧 1.常用命令 help是帮助命令,会打印出一个command list,help ...

  • lldb

    lldb 调试实战 0x0 命令结构 其中options和argument是可选的. 0x1 常用命令 1,设置断...

  • LLDB调试-Chisel使用

    LLDB 调试器集成于 Xcode 内部并支持 C++ ,Python插件,这里解释了其工作原理。常用命令包括pr...

  • iOS逆向:动态调试

    目录一,Xcode动态调试的原理二,终端动态调试的原理三,建立连接四,LLDB常用命令五,ASLR 一,Xcode...

  • lldb常用命令

    LLDB命令的语法有其通用结构,通常是以下形式的: [ [ ...]] [-options [option...

  • LLDB常用命令

    po打印具体对象,调用变量的API,基本数据类型需要先强制类型转换,宏不能直接打印 call / p / prin...

网友评论

    本文标题:LLDB 常用命令

    本文链接:https://www.haomeiwen.com/subject/fkdpsctx.html