安裝facebook/chisel DerekSelander/LLDB
LLDB會從默認(rèn)的~/.lldbinit加載自定義腳本
git clone https://github.com/facebook/chisel.git
git clone https://github.com/DerekSelander/LLDB.git
touch ~/.lldbinit
vim ~/.lldbinit
# ~/.lldbinit
command script import pwd/chisel/fblldb.py
command script import pwd/LLDB/lldb_commands/dslldb.py
lldb一般最常用的就是po(print object)
-
pviews
可以打印頁面結(jié)構(gòu)(報(bào)錯(cuò)需要引用UIKitexpression @import UIKit
) -
presponder 0x15feab460
可以打印響應(yīng)鏈 -
methods 0x15feab460
可以打印屬性和方法 -
search UIImageView
可以查找頁面元素 - b 可以用來打斷點(diǎn)
- po $x1 可以打印參數(shù)
- pblock 可以打印block (逆向可以查看block里面的參數(shù)了)
(lldb) b [LoginManager requestDirectLoginInController:completion:failure:]
Breakpoint 1: where = recipe`-[LoginManager requestDirectLoginInController:completion:failure:] at LoginManager.m:93, address = 0x0000000100748044
(lldb) po $x3
<__NSGlobalBlock__: 0x102fa9300>
(lldb) pblock 0x102fa9300
Imp: 0x100311768 Signature: void ^(NSDictionary *, bool, bool);
- e 可以和Cycript一樣動態(tài)的調(diào)用函數(shù)仗考、打印函數(shù)
(lldb) e UIApplication *$app = [UIApplication sharedApplication]
(lldb) e UIWindow *$keyWindow = $app.keyWindow
(lldb) e UIViewController *$root = $keyWindow.rootViewController
(lldb) po $root
<UITabBarController: 0x1148c2400>
(lldb) e UIViewController *$f = [((UITabBarController *)$root).viewControllers firstObject]
(lldb) po $f
<UINavigationController: 0x1148ca800>
(lldb) b [LoginManager requestDirectLoginInController:completion:failure:]
Breakpoint 16: where = recipe`-[LoginManager requestDirectLoginInController:completion:failure:] at LoginManager.m:93, address = 0x0000000101630984
(lldb) po $x0
<LoginManager: 0x1c4a508f0>
(lldb) c
Process 42409 resuming
e (void)[0x1c4a508f0 requestDirectLoginInController:$nvc completion:nil failure:nil]
配合MallocStackLogging環(huán)境變量 使用lldb.macosx.heap.py
位置/Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Versions/A/Resources/Python/lldb/macosx/heap.py
雖然表明OS X使用但是iOS也可以使用
- 查看一個(gè)對象分配內(nèi)存的堆棧(需要配合MallocStackLogging malloc_info -s)
- 得到內(nèi)存指定類的實(shí)例對象(objc_refs)
- 得到一個(gè)內(nèi)存地址所有被引用的地方(ptr_refs)
- 搜索內(nèi)存中指定的C字符串(cstr_refs)
(lldb) command script import ;;db.macosx.heap
"malloc_info", "ptr_refs", "cstr_refs", "find_variable", and "objc_refs" commands have been installed, use the "--help" options on these commands for detailed help.