###LLDB獲取幫助python
調用help命令來列出LLDB全部的頂層命令
###LLDB高級運用c++
(lldb) e int $a = 2 (lldb) p $a * 19 38 (lldb) e NSArray *$array = @[ @"Saturday", @"Sunday", @"Monday" ] (lldb) p [$array count] 3 (lldb) po [[$array objectAtIndex:0] uppercaseString] SATURDAY (lldb) p [[$array objectAtIndex:$a] characterAtIndex:0] error: no known method '-characterAtIndex:'; cast the message send to the method's return type error: 1 errors parsing expression //lldb沒法斷定某一步的計算結果是什麼數據類型 (lldb) p (char)[[$array objectAtIndex:$a] characterAtIndex:0] 'M' (lldb) p/d (char)[[$array objectAtIndex:$a] characterAtIndex:0] 77 (lldb) thread step-in // The same as "step" or "s" in GDB. (lldb) thread step-over // The same as "next" or "n" in GDB. (lldb) thread step-out // The same as "finish" or "f" in GDB. (lldb) thread step-inst // The same as "stepi" / "si" in GDB. (lldb) thread step-over-inst // The same as "nexti" / "ni" in GDB. (lldb) thread list (lldb) thread backtrace (lldb) thread backtrace all //查看調用棧狀態 (lldb) thread return //命令須要一個參數來指明函數強制返回時的返回值。 //檢查幀參數和本地變量的最簡便的方式是使用frame variable命令 (lldb) frame variable self = (SKTGraphicView *) 0x0000000100208b40 _cmd = (struct objc_selector *) 0x000000010001bae1 sender = (id) 0x00000001001264e0 selection = (NSArray *) 0x00000001001264e0 i = (NSUInteger) 0x00000001001264e0 c = (NSUInteger) 0x00000001001253b0 (lldb) frame variable self (SKTGraphicView *) self = 0x0000000100208b40 (lldb) frame variable *self (SKTGraphicView *) self = 0x0000000100208b40 (NSView) NSView = { (NSResponder) NSResponder = { ... (lldb) frame select 9 frame #9: 0x0000000100015ae3 //查看工程中使用的庫 lldb) image list [ 0] 432A6EBF-B9D2-3850-BCB2-821B9E62B1E0 0x0000000100000000 /Users/**/Library/Developer/Xcode/ (lldb) image lookup --address 0x0000000100000de0//具體哪一行 (lldb) image lookup --type NSURL //若是想查看具體類型
###自定義執行express
執行任意代碼 (lldb) e char *$str = (char *)malloc(128) (lldb) e (void)strcpy($str, "wxrld of warcraft") (lldb) e $str[1] = 'o' (char) $0 = 'o' (lldb) p $str (char *) $str = 0x00007fd04a900040 "world of warcraft" (lldb) e (void)free($str) 在debugger中能夠修改view的顏色、尺寸、甚至建立controller來push。
###打印cgframeiview
(lldb) po self.view.frame error: unsupported expression with unknown type error: unsupported expression with unknown type error: 2 errors parsing expression (lldb) p (CGRect)[self.view frame] (CGRect) $0 = origin=(x=0, y=0) size=(width=320, height=480)
###觀察watchpoint函數
watchpoint能夠在某個變量被寫入/讀取時暫停程序運行 (lldb) watchpoint set expression -- (int*)&_abc4 Watchpoint created: Watchpoint 7: addr = 0x15e36d3c size = 4 state = enabled type = w new value: 0x00000000 (lldb) watchpoint set v -w read _abc4 Watchpoint created: Watchpoint 8: addr = 0x15e36d3c size = 4 state = enabled type = r watchpoint spec = '_abc4' new value: 0 (lldb) watchpoint set v -w read_write _abc3 Watchpoint created: Watchpoint 9: addr = 0x15e36d38 size = 4 state = enabled type = rw watchpoint spec = '_abc3' new value: 0
###刷新UIui
(lldb) po [[[UIApplication sharedApplication] keyWindow] recursiveDescription]<uiwindow: 0x7f82b1fa8140; frame = (0 0; 320 568); gesturerecognizers = ; layer = > | <uiview: 0x7f82b1d01fd0; frame = (0 0; 320 568); autoresize = w+h; layer = ></uiview: 0x7f82b1d01fd0; frame = (0 0; 320 568); autoresize = w+h; layer = ></uiwindow: 0x7f82b1fa8140; frame = (0 0; 320 568); gesturerecognizers = ; layer = > (lldb) e id $myView = (id)0x7f82b1d01fd0 (lldb) e (void)[$myView setBackgroundColor:[UIColor blueColor]] (lldb) e (void)[CATransaction flush]//必須加 (lldb) e id $nvc = [[[UIApplication sharedApplication] keyWindow] rootViewController] (lldb) e id $vc = [UIViewController new] (lldb) e (void)[[$vc view] setBackgroundColor:[UIColor yellowColor]] (lldb) e (void)[$vc setTitle:@"Yay!"] (lldb) e (void)[$nvc pushViewContoller:$vc animated:YES] (lldb) e (void)[CATransaction flush]
###查找按鈕的 targetdebug
(lldb) po [$myButton allTargets] {( )} (lldb) po [$myButton actionsForTarget:(id)0x7fb58bd2e240 forControlEvent:0]( _handleTap: )
###高級frame調試調試
// Object-C po [[[UIWindow keyWindow] rootViewController] _printHierarchy] // Swift expr -l objc++ -O -- [[UIWindow keyWindow] recursiveDescription] fr v -R self // obj print expr -l objc++ -O -- [0x7f8d81c3c8b0 _printHierarchy] expr -l objc++ -O -- [[[UIWindow keyWindow] rootViewController] _printHierarchy]
###LLDB 和 Python LLDB 有內建的,完整的 Python 支持。在LLDB中輸入 script,會打開一個 Python REPL。你也能夠輸入一行 python 語句做爲 script 命令 的參數,這能夠運行 python 語句而不進入REPL:code
(lldb) script import os (lldb) script os.system("open http://www.objc.io/")
這樣就容許你創造各類酷的命令。把下面的語句放到文件 ~/myCommands.py 中:ip
def caflushCommand(debugger, command, result, internal_dict): debugger.HandleCommand("e (void)[CATransaction flush]")
command script import ~/myCommands.py