【LLDB】高級運用與深入理解

摘要

如何在調(diào)試中高級運用調(diào)試方法,減少重新運行

LLDB獲取幫助

調(diào)用help命令來列出LLDB所有的頂層命令

LLDB高級運用

(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無法判定某一步的計算結(jié)果是什么數(shù)據(jù)類型

(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 //查看調(diào)用棧狀態(tài)

(lldb) thread return //命令需要一個參數(shù)來指明函數(shù)強制返回時的返回值。

//檢查幀參數(shù)和本地變量的最簡便的方式是使用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 //如果想查看具體類型

自定義執(zhí)行

執(zhí)行任意代碼

(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的顏色、尺寸、甚至創(chuàng)建controller來push。

打印cgframe

(lldb) po self.view.frameerror: unsupported expressionwithunknowntypeerror: unsupported expressionwithunknowntypeerror:2errors parsing expression

(lldb) p (CGRect)[self.view frame](CGRect) $0= origin=(x=0, y=0) size=(width=320, height=480)

觀察watchpoint

watchpoint可以在某個變量被寫入/讀取時暫停程序運行

(lldb) watchpointsetexpression-- (int*)&_abc4Watchpoint created: Watchpoint7: addr =0x15e36d3csize=4state = enabledtype= wnewvalue:0x00000000(lldb) watchpointsetv -wread_abc4Watchpoint created: Watchpoint8: addr =0x15e36d3csize=4state = enabledtype= r ? ?watchpoint spec ='_abc4'newvalue:0(lldb) watchpointsetv -w read_write _abc3Watchpoint created: Watchpoint9: addr =0x15e36d38size=4state = enabledtype= rw ? ?watchpoint spec ='_abc3'newvalue:0

刷新UI

(lldb) po [[[UIApplication sharedApplication] keyWindow] recursiveDescription]|(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]

查找按鈕的 target

(lldb) po [$myButtonallTargets]{( ? ?)}

(lldb) po [$myButtonactionsForTarget:(id)0x7fb58bd2e240forControlEvent:0](_handleTap:)

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容