LLDB集合

LLDB斷點(diǎn)調(diào)試命令叛赚,在一些情況下還是很好用的俐填,畢竟有時(shí)候你需要知道某個(gè)或者多個(gè)屬性是否有值的時(shí)候寓娩,讓你去寫一個(gè)NSLog或者多個(gè)NSLog還是比較煩的她渴,除非需要連續(xù)打印某串值的時(shí)候NSLog才比較好用抡医《阋颍或者你覺得我直接斷點(diǎn)早敬,然后鼠標(biāo)移過去查看相應(yīng)的屬性不就行了?使用self.調(diào)用的還是沒法直接獲取到的...
廢話就不扯了大脉,下面講點(diǎn)干貨搞监,當(dāng)然也是個(gè)整理,畢竟這種文章的帖子百度一堆哈镰矿。

LLDB使用

LLDB 在xcode4.3或者之后的版本里面默認(rèn)的調(diào)試器,在這之前用的就是GDB琐驴。
具體的操作:需要lldb命令調(diào)試的地方斷點(diǎn) ——>lldb命令調(diào)試


lldb命令調(diào)試.png

常用LLDB命令

po命令

"point object"(打印對(duì)象昙读,且會(huì)調(diào)用description方法)侥蒙〗饭Γ可以在調(diào)試時(shí)動(dòng)態(tài)執(zhí)行指定的表達(dá)式余赢,并將結(jié)果打印出來障般,是個(gè)很有用的命令汗茄。


po命令.png

p命令

輸出值+值類型+引用名+內(nèi)存地址


p命令.png

exp命令

expression的簡(jiǎn)寫炊苫,可以打印值肃叶、修改值怖现。

exp命令.png

call命令

在斷點(diǎn)調(diào)用某個(gè)方法茁帽,并輸出此方法的返回值。


call命令.png

Thread系列

堆棧打印 thread backtrace

如果嫌堆棧打印太長(zhǎng)屈嗤,可以加一個(gè)值限制潘拨,如bt 10,只打印

(lldb) bt 10
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 3.1
 * frame #0: 0x0000000100d28da8 ztjyyd_test`-[ZTGNoticeViewController setupViews](self=0x0000000117267900, _cmd="setupViews") at ZTGNoticeViewController.m:36
frame #1: 0x000000010199263c ztjyyd_test`-[SZYViewController viewDidLoad](self=0x0000000117267900, _cmd="viewDidLoad") at SZYViewController.m:26
frame #2: 0x000000018f85aee0 UIKit`-[UIViewController loadViewIfRequired] + 1020
frame #3: 0x000000018f85aacc UIKit`-[UIViewController view] + 28
frame #4: 0x0000000100f4736c ztjyyd_test`-[RDVSZYTabBarController setSelectedIndex:](self=0x000000010f2738c0, _cmd="setSelectedIndex:", selectedIndex=0) at RDVSZYTabBarController.m:136
frame #5: 0x0000000100f46e04 ztjyyd_test`-[RDVSZYTabBarController viewWillAppear:](self=0x000000010f2738c0, _cmd="viewWillAppear:", animated=YES) at RDVSZYTabBarController.m:56
frame #6: 0x000000018f8da6d8 UIKit`-[UIViewController _setViewAppearState:isAnimating:] + 616
frame #7: 0x000000018f8da448 UIKit`-[UIViewController __viewWillAppear:] + 140
frame #8: 0x000000018fb9846c UIKit`-[UINavigationController _startCustomTransition:] + 1312
frame #9: 0x000000018f907ac8 UIKit`-[UINavigationController _startDeferredTransitionIfNeeded:] + 708
thread return跳出當(dāng)前方法的執(zhí)行

Debug的時(shí)候饶号,也許會(huì)因?yàn)楦鞣N原因铁追,我們不想讓代碼執(zhí)行某個(gè)方法,或者要直接返回一個(gè)想要的值茫船。這時(shí)候就該thread return上場(chǎng)了琅束。
有返回值的方法里,如:numberOfSectionsInTableView:算谈,直接thread return 10涩禀,就可以直接跳過方法執(zhí)行,返回10.

//跳出方法
(lldb) thread return
//讓帶有返回int值的方法直接跳出然眼,并返回值10
(lldb) thread return 10

流程控制

繼續(xù):continue, c
下一步:next, n
進(jìn)入:step, s
跳出:finish, f

當(dāng)然艾船,使用xcode自帶的可視化工具來控制“繼續(xù)”“暫停”“下一步”“進(jìn)入”“跳出”更簡(jiǎn)便

Image系列

image lookup -address 查找崩潰位置

當(dāng)你遇見數(shù)組崩潰高每,你又沒有找到崩潰的位置屿岂,只扔給你一堆報(bào)錯(cuò)信息,這時(shí)候image lookup來幫助你鲸匿。如下

0   CoreFoundation                      0x0000000103209b0b __exceptionPreprocess + 171
1   libobjc.A.dylib                     0x00000001079db141 objc_exception_throw + 48
2   CoreFoundation                      0x000000010313effb -[__NSArrayM objectAtIndex:] + 203
3   DiDi                                0x00000001009a9f3a -[FW_MyHomeTableView tableView:cellForRowAtIndexPath:] + 1322
4   UIKit                               0x00000001055a2ab2 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 750
5   UIKit                               0x00000001055a2cf8 -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 74
6   UIKit                               0x0000000105577639 -[UITableView _updateVisibleCellsNow:isRecursive:] + 2845
7   UIKit                               0x00000001055abccc -[UITableView _performWithCachedTraitCollection:] + 111
8   UIKit                               0x0000000105592e7a -[UITableView layoutSubviews] + 233
9   UIKit                               0x00000001054f955b -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1268
10  QuartzCore                          0x0000000105114904 -[CALayer layoutSublayers] + 146

尋找自己項(xiàng)目的標(biāo)識(shí)爷怀,看到frame3位置带欢,你只需這樣查找位置:

image lookup -a 0x00000001009a9f3a
      Address: DiDi[0x0000000100609f3a] (DiDi.__TEXT.__text + 6323194)
      Summary: DiDi`-[FW_MyHomeTableView tableView:cellForRowAtIndexPath:] + 1322 at FW_MyHomeTableView.m:243

image lookup -name 查找方法來源

此命令可以用來查找方法的來源运授。包括在第三方SDK中的方法烤惊,也能被查到。
例:查找transformOtherModelToSuit:

(lldb) image lookup -n transformOtherModelToSuit:
1 match found in /Users/xxx/Library/Developer/Xcode/DerivedData/DiDi-cwpbvvyvqmeijmcjnneothzuthsy/Build/Products/Debug-iphonesimulator/DiDi.app/DiDi:
        Address: DiDi[0x0000000100293d60] (DiDi.__TEXT.__text + 2693664)
        Summary: DiDi`+[FW_BetFunction transformOtherModelToSuit:] at FW_BetFunction.m:107

image lookup –type 查看成員

查看某個(gè)class的所有屬性和成員變量徒坡。不過貌似frameWork庫(kù)中文件不能查看撕氧。

(lldb) image lookup -t MatchEvent
1 match found in /Users/xxxx/Library/Developer/Xcode/DerivedData/DiDi-cwpbvvyvqmeijmcjnneothzuthsy/Build/Products/Debug-iphonesimulator/DiDi.app/DiDi:
id = {0x00433d32}, name = "MatchEvent", byte-size = 48, decl = MatchEvent.h:11, compiler_type = "@interface MatchEvent : NSObject{
    BOOL _isHome;
    NSString * _playerName;
    NSString * _timePoint;
    NSString * _eventType;
    NSString * _eventDesc;
}
@property ( getter = isHome,setter = setIsHome:,assign,readwrite,nonatomic ) BOOL isHome;
@property ( getter = playerName,setter = setPlayerName:,readwrite,copy,nonatomic ) NSString * playerName;
@property ( getter = timePoint,setter = setTimePoint:,readwrite,copy,nonatomic ) NSString * timePoint;
@property ( getter = eventType,setter = setEventType:,readwrite,copy,nonatomic ) NSString * eventType;
@property ( getter = eventDesc,setter = setEventDesc:,readwrite,copy,nonatomic ) NSString * eventDesc;
@end"

help命令

上面講解一下比較常用的命令,如果還需要使用或者了解其他命令可以使用help命令來查看

(lldb) help
Debugger commands:
  apropos           -- List debugger commands related to a word or subject.
  breakpoint        -- Commands for operating on breakpoints (see 'help b' for
                       shorthand.)
  bugreport         -- Commands for creating domain-specific bug reports.
  command           -- Commands for managing custom LLDB commands.
  disassemble       -- Disassemble specified instructions in the current
                       target.  Defaults to the current function for the
                       current thread and stack frame.
  expression        -- Evaluate an expression on the current thread.  Displays
                       any returned value with LLDB's default formatting.
  frame             -- Commands for selecting and examing the current thread's
                       stack frames.
  gdb-remote        -- Connect to a process via remote GDB server.  If no host
                       is specifed, localhost is assumed.
  gui               -- Switch into the curses based GUI mode.
  help              -- Show a list of all debugger commands, or give details
                       about a specific command.
...

總結(jié)

先介紹這些吧喇完,后面會(huì)接著更新補(bǔ)充另外一些常用的命令伦泥,當(dāng)然也可以參考別人的帖子,順便附上本文參考帖子锦溪。
相關(guān)文章:
iOS之LLDB常用命令
iOS_LLDB 調(diào)試命令
Xcode高級(jí)調(diào)試技巧(1)

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末不脯,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子刻诊,更是在濱河造成了極大的恐慌防楷,老刑警劉巖,帶你破解...
    沈念sama閱讀 221,273評(píng)論 6 515
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件则涯,死亡現(xiàn)場(chǎng)離奇詭異复局,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)粟判,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,349評(píng)論 3 398
  • 文/潘曉璐 我一進(jìn)店門亿昏,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人档礁,你說我怎么就攤上這事角钩。” “怎么了呻澜?”我有些...
    開封第一講書人閱讀 167,709評(píng)論 0 360
  • 文/不壞的土叔 我叫張陵递礼,是天一觀的道長(zhǎng)。 經(jīng)常有香客問我羹幸,道長(zhǎng)脊髓,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 59,520評(píng)論 1 296
  • 正文 為了忘掉前任栅受,我火速辦了婚禮供炼,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘窘疮。我一直安慰自己,他們只是感情好冀墨,可當(dāng)我...
    茶點(diǎn)故事閱讀 68,515評(píng)論 6 397
  • 文/花漫 我一把揭開白布闸衫。 她就那樣靜靜地躺著,像睡著了一般诽嘉。 火紅的嫁衣襯著肌膚如雪蔚出。 梳的紋絲不亂的頭發(fā)上弟翘,一...
    開封第一講書人閱讀 52,158評(píng)論 1 308
  • 那天,我揣著相機(jī)與錄音骄酗,去河邊找鬼稀余。 笑死,一個(gè)胖子當(dāng)著我的面吹牛趋翻,可吹牛的內(nèi)容都是我干的睛琳。 我是一名探鬼主播,決...
    沈念sama閱讀 40,755評(píng)論 3 421
  • 文/蒼蘭香墨 我猛地睜開眼踏烙,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼师骗!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起讨惩,我...
    開封第一講書人閱讀 39,660評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤辟癌,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后荐捻,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體黍少,經(jīng)...
    沈念sama閱讀 46,203評(píng)論 1 319
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,287評(píng)論 3 340
  • 正文 我和宋清朗相戀三年处面,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了厂置。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 40,427評(píng)論 1 352
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡鸳君,死狀恐怖农渊,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情或颊,我是刑警寧澤砸紊,帶...
    沈念sama閱讀 36,122評(píng)論 5 349
  • 正文 年R本政府宣布,位于F島的核電站囱挑,受9級(jí)特大地震影響醉顽,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜平挑,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,801評(píng)論 3 333
  • 文/蒙蒙 一游添、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧通熄,春花似錦唆涝、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,272評(píng)論 0 23
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至赏枚,卻和暖如春亡驰,著一層夾襖步出監(jiān)牢的瞬間晓猛,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,393評(píng)論 1 272
  • 我被黑心中介騙來泰國(guó)打工凡辱, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留戒职,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 48,808評(píng)論 3 376
  • 正文 我出身青樓透乾,卻偏偏與公主長(zhǎng)得像洪燥,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子续徽,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,440評(píng)論 2 359

推薦閱讀更多精彩內(nèi)容

  • 轉(zhuǎn)載 與調(diào)試器共舞 - LLDB 的華爾茲: https://objccn.io/issue-19-2/ 推薦:i...
    F麥子閱讀 3,334評(píng)論 0 10
  • [轉(zhuǎn)]淺談LLDB調(diào)試器文章來源于:http://www.cocoachina.com/ios/20150126/...
    loveobjc閱讀 2,515評(píng)論 2 6
  • 隨著Xcode 5的發(fā)布蚓曼,LLDB調(diào)試器已經(jīng)取代了GDB,成為了Xcode工程中默認(rèn)的調(diào)試器钦扭。它與LLVM編譯器一...
    隨風(fēng)飄蕩的小逗逼閱讀 1,406評(píng)論 0 0
  • 你是否曾經(jīng)苦惱于理解你的代碼纫版,而去嘗試打印一個(gè)變量的值? NSLog(@"%@", whatIsInsideThi...
    木易林1閱讀 956評(píng)論 0 4
  • 與調(diào)試器共舞 - LLDB 的華爾茲 nangege 2014/12/19 你是否曾經(jīng)苦惱于理解你的代碼客情,而去嘗試...
    McDan閱讀 883評(píng)論 0 0