調(diào)試

斷點(diǎn)和調(diào)試器交互

help命令

  • help 列出所有命令
  • help <commond>列出某個(gè)命令更多細(xì)節(jié),例如help print</commond>

print

  • print 打印需要查看的變量,例如print totalCount
  • print 還能使用簡(jiǎn)寫(xiě)prin, pri, p
  • po(print object)可以打印對(duì)象的description方法的結(jié)果
  • 打印不同格式可以用p/x number打印十六進(jìn)制,p/t number打印二進(jìn)制,p/c char打印字符。這里是完整清單https://sourceware.org/gdb/onlinedocs/gdb/Output-Formats.html

expression

  • expression 可以改變一個(gè)值,例如expression s
  • expression可以使用e來(lái)代替
  • e -p — dataArray 也可以打印對(duì)象的description方法的結(jié)果,等同于po

流程控制

  • continue會(huì)取消暫停,繼續(xù)執(zhí)行下去到達(dá)下一個(gè)斷電,LLDB中使用process continue,別名continue,或者使用縮寫(xiě)c
  • step over會(huì)執(zhí)行當(dāng)前這個(gè)函數(shù),然后繼續(xù)。LLDB中使用thread step-over,next或者縮寫(xiě)n
  • step into指跳進(jìn)一個(gè)函數(shù)調(diào)試。LLDB中使用thread step in,step或者s
  • step out會(huì)繼續(xù)執(zhí)行到下一個(gè)返回語(yǔ)句,然后再次停止
  • thread return會(huì)在當(dāng)前斷點(diǎn)處直接返回出函數(shù),函數(shù)剩余部分不會(huì)被執(zhí)行。LLDB中使用thread return NO

斷點(diǎn)管理

  • breakpoint list可以看到所有斷點(diǎn),簡(jiǎn)寫(xiě)br li
  • breakpoint set可以創(chuàng)建斷點(diǎn),縮寫(xiě)br

在LLDB執(zhí)行C/Objective-C/C++/Swift

  • 除了創(chuàng)建函數(shù),類(lèi),block等其它的都可以做到
  • 使用e進(jìn)行操作,p進(jìn)行打印顯示結(jié)果

在調(diào)試器中直接更新UI


(lldb) e id $myView = (id)0x7f82b1d01fd0

(lldb) e (void)[$myView setBackgroundColor:[UIColor blueColor]]

(lldb) e (void)[CATransaction flush]

查找Button的target

查看按鈕按下后誰(shuí)會(huì)接收到按鈕發(fā)出的action


(lldb) po [$myButton allTargets]

{(

<MagicEventListener: 0x7fb58bd2e240>

)}

(lldb) po [$myButton actionsForTarget:(id)0x7fb58bd2e240 forControlEvent:0]

<__NSArrayM 0x7fb58bd2aa40>(

_handleTap:

)

觀察實(shí)例變量變化

想監(jiān)視vMain變量什么時(shí)候被重寫(xiě)了,監(jiān)視這個(gè)地址什么時(shí)候被寫(xiě)入


(lldb) p (ptrdiff_t)ivar_getOffset((struct Ivar *)class_getInstanceVariable([MyView class], "vMain"))

(ptrdiff_t) $0 = 8

(lldb) watchpoint set expression -- (int *)$myView + 8

Watchpoint created: Watchpoint 3: addr = 0x7fa554231340 size = 8 state = enabled type = w

new value: 0x0000000000000000

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

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

  • 一、概述 LLDB全稱 [ Low Level Debugger ], 默認(rèn)內(nèi)置于Xcode中的動(dòng)態(tài)調(diào)試工具。標(biāo)準(zhǔn)...
    Superman168閱讀 15,504評(píng)論 2 19
  • [轉(zhuǎn)]淺談LLDB調(diào)試器文章來(lái)源于:http://www.cocoachina.com/ios/20150126/...
    loveobjc閱讀 2,728評(píng)論 2 6
  • 一句話介紹LLDB:內(nèi)置在 Xcode 中的調(diào)試器。能在特定的位置暫停程序運(yùn)行,并觀察變量的值,也可以執(zhí)行自定義指...
    廚子閱讀 398評(píng)論 0 0
  • LLDB是XCode內(nèi)置的為我們開(kāi)發(fā)者提供的調(diào)試工具,可以在設(shè)置斷點(diǎn)的時(shí)候在控制臺(tái)中輸入相關(guān)的lldb命令進(jìn)行調(diào)試...
    jumpingfrog0閱讀 2,837評(píng)論 0 1
  • 你是否曾經(jīng)苦惱于理解你的代碼,而去嘗試打印一個(gè)變量的值? NSLog(@"%@", whatIsInsideThi...
    木易林1閱讀 1,033評(píng)論 0 4

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