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命令
po命令
"point object"(打印對(duì)象昙读,且會(huì)調(diào)用description方法)侥蒙〗饭Γ可以在調(diào)試時(shí)動(dòng)態(tài)執(zhí)行指定的表達(dá)式余赢,并將結(jié)果打印出來障般,是個(gè)很有用的命令汗茄。
p命令
輸出值+值類型+引用名+內(nèi)存地址
exp命令
expression的簡(jiǎn)寫炊苫,可以打印值肃叶、修改值怖现。
call命令
在斷點(diǎn)調(diào)用某個(gè)方法茁帽,并輸出此方法的返回值。
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)