LLDB断点调试命令,在一些情况下还是很好用的,毕竟有时候你需要知道某个或者多个属性是否有值的时候,让你去写一个NSLog或者多个NSLog还是比较烦的,除非需要连续打印某串值的时候NSLog才比较好用。或者你觉得我直接断点,然后鼠标移过去查看相应的属性不就行了?使用self.
调用的还是没法直接获取到的...
废话就不扯了,下面讲点干货,当然也是个整理,毕竟这种文章的帖子百度一堆哈。
LLDB使用
LLDB 在xcode4.3或者之后的版本里面默认的调试器,在这之前用的就是GDB。
具体的操作:需要lldb命令调试的地方断点 ——>lldb命令调试
lldb命令调试.png
常用LLDB命令
po命令
"point object"(打印对象,且会调用description方法)。可以在调试时动态执行指定的表达式,并将结果打印出来,是个很有用的命令。
po命令.png
p命令
输出值+值类型+引用名+内存地址
p命令.png
exp命令
expression的简写,可以打印值、修改值。
call命令
在断点调用某个方法,并输出此方法的返回值。
call命令.png
Thread系列
堆栈打印 thread backtrace
如果嫌堆栈打印太长,可以加一个值限制,如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跳出当前方法的执行
Debug的时候,也许会因为各种原因,我们不想让代码执行某个方法,或者要直接返回一个想要的值。这时候就该thread return上场了。
有返回值的方法里,如:numberOfSectionsInTableView:,直接thread return 10,就可以直接跳过方法执行,返回10.
//跳出方法
(lldb) thread return
//让带有返回int值的方法直接跳出,并返回值10
(lldb) thread return 10
流程控制
继续:continue, c
下一步:next, n
进入:step, s
跳出:finish, f
当然,使用xcode自带的可视化工具来控制“继续”“暂停”“下一步”“进入”“跳出”更简便
Image系列
image lookup -address 查找崩溃位置
当你遇见数组崩溃,你又没有找到崩溃的位置,只扔给你一堆报错信息,这时候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
寻找自己项目的标识,看到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 查看成员
查看某个class的所有属性和成员变量。不过貌似frameWork库中文件不能查看。
(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.
...
总结
先介绍这些吧,后面会接着更新补充另外一些常用的命令,当然也可以参考别人的帖子,顺便附上本文参考帖子。
相关文章:
iOS之LLDB常用命令
iOS_LLDB 调试命令
Xcode高级调试技巧(1)
网友评论