今天在微博上看到小笨狼分享的一片文章,其中比较详细的介绍了LLDB的使用,顿时感觉原来LLDB控制体可以做那么多事情,下面是我挑选的几个,开发中比较常用的命令
1、基本语法
首先还是先看一下最近本的语法,这会让我们会更容易的去理解和记住下面的命令
1 |
|
breakpoint set - n main
1 |
|
breakpoint set -n main
br s -n main
1 |
|
expression
1 |
|
expression – self.view.backgroundColor = [UIColor redColor]
1 |
|
(lldb) expression – self.view
(UIView *) $1 = 0x00007fe322c18a10
1 |
|
(lldb) expression – self.view
(UIView *) $5 = 0x00007fb2a40344a0
(lldb) p self.view
(UIView *) $6 = 0x00007fb2a40344a0
(lldb) print self.view
(UIView *) $7 = 0x00007fb2a40344a0
(lldb) call self.view
(UIView *) $8 = 0x00007fb2a40344a0
(lldb) e self.view
(UIView *) $9 = 0x00007fb2a40344a0
1 |
|
expression – self.view
(UIView *) $13 = 0x00007fb2a40344a0
1 |
|
(lldb) expression -O – self.view
<UIView: 0x7fb2a40344a0; frame = (0 0; 375 667); autoresize = W+H; layer = <CALayer: 0x7fb2a4018c80>>
1 |
|
(lldb) po self.view
<UIView: 0x7fb2a40344a0; frame = (0 0; 375 667); autoresize = W+H; layer = <CALayer: 0x7fb2a4018c80>>
1 |
|
thread backtrace [-c
1 |
|
(lldb) thread backtrace
- thread #1: tid = 0xdd42, 0x000000010afb380b libobjc.A.dylib
objc_msgSend + 11, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=EXC_I386_GPFLT) frame #0: 0x000000010afb380b libobjc.A.dylib
objc_msgSend + 11- frame #1: 0x000000010aa9f75e TLLDB
-[ViewController viewDidLoad](self=0x00007fa270e1f440, _cmd="viewDidLoad") + 174 at ViewController.m:23 frame #2: 0x000000010ba67f98 UIKit
-[UIViewController loadViewIfRequired] + 1198
frame #3: 0x000000010ba682e7 UIKit-[UIViewController view] + 27 frame #4: 0x000000010b93eab0 UIKit
-[UIWindow addRootViewControllerViewIfPossible] + 61
frame #5: 0x000000010b93f199 UIKit-[UIWindow _setHidden:forced:] + 282 frame #6: 0x000000010b950c2e UIKit
-[UIWindow makeKeyAndVisible] + 42
- frame #1: 0x000000010aa9f75e TLLDB
1 |
|
(lldb) thread return NO
1 |
|
这个方法的功能比较强大,可以根据方法名设置断点,可以给指定文件中的指定方法设置断点(方法不存在,无法设置断点),给指定文件的某一行设置断点、设置条件断点、设置单次执行断点。由于这些在实际的开发中用的比较少,所以在这里不再详细说明(需要看的可以在本文最后查看引用的文章)
1 |
|
2015-12-17 14:51:06.301 TLLDB[25086:246169] * Terminating app due to uncaught exception ‘NSRangeException’, reason: ‘* -[__NSArray0 objectAtIndex:]: index 1 beyond bounds for empty NSArray’
*** First throw call stack:
(
0 CoreFoundation 0x000000010accde65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010a746deb objc_exception_throw + 48
2 CoreFoundation 0x000000010ac7c395 -[__NSArray0 objectAtIndex:] + 101
3 TLLDB 0x000000010a1c3e36 -[ViewController viewDidLoad] + 86
4 UIKit 0x000000010b210f98 -[UIViewController loadViewIfRequired] + 1198
5 UIKit 0x000000010b2112e7 -[UIViewController view] + 27
1 |
|
(lldb) image lookup -a 0x000000010a1c3e36
Address: TLLDB[0x0000000100000e36] (TLLDB.__TEXT.__text + 246)
Summary: TLLDB`-[ViewController viewDidLoad] + 86 at ViewController.m:32
1 |
|
某个第三方SDK用了一个我们项目里原有的第三方库,库里面对NSDictionary添加了category。也就是有2个class对NSDictionary添加了名字相同的category,项目中调用自己的category的地方实际走到了第三方SDK里面去了。最大的问题是,这2个同名category方法行为并不一致,导致出现bug
现在问题来了,怎么寻找到底是哪个第三方SDK?方法完全包在.a里面
1 |
|
(lldb) image lookup -n dictionaryWithXMLString:
2 matches found in /Users/jiangliancheng/Library/Developer/Xcode/DerivedData/VideoIphone-aivsnqmlwjhxapdlvmdmrubbdxpq/Build/Products/Debug-iphoneos/BaiduIphoneVideo.app/BaiduIphoneVideo:
Address: BaiduIphoneVideo[0x00533a7c] (BaiduIphoneVideo.__TEXT.__text + 5414908)
Summary: BaiduIphoneVideo+[NSDictionary(SAPIXmlDictionary) dictionaryWithXMLString:] at XmlDictionary.m Module: file = "/Users/jiangliancheng/Library/Developer/Xcode/DerivedData/VideoIphone-aivsnqmlwjhxapdlvmdmrubbdxpq/Build/Products/Debug-iphoneos/BaiduIphoneVideo.app/BaiduIphoneVideo", arch = "armv7" CompileUnit: id = {0x00000000}, file = "/Users/jiangliancheng/Development/Work/iOS_ShareLib/SharedLib/Srvcs/BDPassport4iOS/BDPassport4iOS/SAPI/Extensive/ThirdParty/XMLDictionary/XmlDictionary.m", language = "Objective-C" Function: id = {0x23500000756}, name = "+[NSDictionary(SAPIXmlDictionary) dictionaryWithXMLString:]", range = [0x005a6a7c-0x005a6b02) FuncType: id = {0x23500000756}, decl = XmlDictionary.m:189, clang_type = "NSDictionary *(NSString *)" Blocks: id = {0x23500000756}, range = [0x005a6a7c-0x005a6b02) LineEntry: [0x005a6a7c-0x005a6a98): /Users/jiangliancheng/Development/Work/iOS_ShareLib/SharedLib/Srvcs/BDPassport4iOS/BDPassport4iOS/SAPI/Extensive/ThirdParty/XMLDictionary/XmlDictionary.m Symbol: id = {0x0000f2d5}, range = [0x005a6a7c-0x005a6b04), name="+[NSDictionary(SAPIXmlDictionary) dictionaryWithXMLString:]" Variable: id = {0x23500000771}, name = "self", type = "Class", location = [sp+32], decl = Variable: id = {0x2350000077e}, name = "_cmd", type = "SEL", location = [sp+28], decl = Variable: id = {0x2350000078b}, name = "string", type = "NSString *", location = [sp+24], decl = XmlDictionary.m:189 Variable: id = {0x23500000799}, name = "data", type = "NSData *", location = [sp+20], decl = XmlDictionary.m:192 Address: BaiduIphoneVideo[0x012ee160] (BaiduIphoneVideo.__TEXT.__text + 19810016) Summary: BaiduIphoneVideo
+[NSDictionary(XMLDictionary) dictionaryWithXMLString:] at XMLDictionary.m
Module: file = “/Users/jiangliancheng/Library/Developer/Xcode/DerivedData/VideoIphone-aivsnqmlwjhxapdlvmdmrubbdxpq/Build/Products/Debug-iphoneos/BaiduIphoneVideo.app/BaiduIphoneVideo”, arch = “armv7”
CompileUnit: id = {0x00000000}, file = “/Users/wingle/Workspace/qqlive4iphone/iphone_4.0_fabu_20150601/Common_Proj/mobileTAD/VIDEO/Library/Third Party/XMLDictionary/XMLDictionary.m”, language = “Objective-C”
Function: id = {0x79900000b02}, name = “+[NSDictionary(XMLDictionary) dictionaryWithXMLString:]”, range = [0x01361160-0x0136119a)
FuncType: id = {0x79900000b02}, decl = XMLDictionary.m:325, clang_type = “NSDictionary *(NSString *)”
Blocks: id = {0x79900000b02}, range = [0x01361160-0x0136119a)
LineEntry: [0x01361160-0x01361164): /Users/wingle/Workspace/qqlive4iphone/iphone_4.0_fabu_20150601/Common_Proj/mobileTAD/VIDEO/Library/Third Party/XMLDictionary/XMLDictionary.m
Symbol: id = {0x0003a1e9}, range = [0x01361160-0x0136119c), name=”+[NSDictionary(XMLDictionary) dictionaryWithXMLString:]”
Variable: id = {0x79900000b1e}, name = “self”, type = “Class”, location = r0, decl =
Variable: id = {0x79900000b2c}, name = “_cmd”, type = “SEL”, location = r1, decl =
Variable: id = {0x79900000b3a}, name = “string”, type = “NSString *”, location = r2, decl = XMLDictionary.m:325
Variable: id = {0x79900000b4a}, name = “data”, type = “NSData *”, location = r2, decl = XMLDictionary.m:327
1 |
|
CompileUnit: id = {0x00000000}, file = “/Users/jiangliancheng/Development/Work/iOS_ShareLib/SharedLib/Srvcs/BDPassport4iOS/BDPassport4iOS/SAPI/Extensive/ThirdParty/XMLDictionary/XmlDictionary.m”, language = “Objective-C”
CompileUnit: id = {0x00000000}, file = “/Users/wingle/Workspace/qqlive4iphone/iphone_4.0_fabu_20150601/Common_Proj/mobileTAD/VIDEO/Library/Third Party/XMLDictionary/XMLDictionary.m”, language = “Objective-C”
1 |
|
(lldb) image lookup -t Model
Best match found in /Users/jiangliancheng/Library/Developer/Xcode/DerivedData/TLLDB-beqoowskwzbttrejseahdoaivpgq/Build/Products/Debug-iphonesimulator/TLLDB.app/TLLDB:
id = {0x30000002f}, name = “Model”, byte-size = 32, decl = Modek.h:11, clang_type = “@interface Model : NSObject{
NSString * _bb;
NSString * _cc;
NSString * _name;
}
@property ( getter = name,setter = setName:,readwrite,nonatomic ) NSString * name;
@end
“
4、其他不常用的方法,这里不再多说
### tips:
help & apropos
LLDB的命令其实还有很多,很多命令我也没玩过。就算玩过的命令,我们也非常容易忘记,下次可能就不记得是怎么用的了。还好LLDB给我们提供了2个查找命令的命令:help & apropos
参考文章:
[小笨狼与LLDB的故事](http://www.jianshu.com/p/e89af3e9a8d7)