iOS_SN_LLDB常用命令
有一次因为封装一个控件,UI能正常显示就是不能点击,一点击就崩溃,而且异常断点也无法捕捉,把Xcode的僵尸对象打开,每次崩溃就打印一个地址,最后就必须根据地址寻找对象,可以使用frame variable命令检查帧参数和本地变量。当时用此命令打印出self的地址和崩溃地址一样,一下就缩小了检查范围,最后是因为按钮添加方法时target的参数把自己当做属性传过去了,其实只要把它自己传过去就行。
现在就说一说常用命令:
p 用于输出基本类型,
po 用于输出 Objective-C 对象,
print 与p命令相似 他们的具体打印信息如下:
(lldb) print mouthLable (UILabel *) $3 = 0x09c77070 (lldb) p mouthLable (UILabel *) $4 = 0x09c77070 (lldb) po mouthLable <UILabel: 0x9c77070; frame = (0 0; 50 40); userInteractionEnabled = NO; layer = <_UILabelLayer: 0x52eec90>>
上图显示了在控制台的左边有一个可以直接选择打印的对象,打印出来的结果如下:
Printing description of mouthLable: <UILabel: 0x9c77070; frame = (0 0; 50 40); userInteractionEnabled = NO; layer = <_UILabelLayer: 0x52eec90>>
这些都是常用的输出方法,如果用这些输出方法输出带有宏定义的则输出不了,必须把宏定义的内容还原才行,用PO还可以输出方法,可以使输出的值强转。如下:
(lldb) po bigLable <UILabel: 0xb3bcf70; frame = (0 0; 100 40); userInteractionEnabled = NO; layer = <_UILabelLayer: 0xb3bd050>> (lldb) po [bigLable subviews] <__NSArrayM 0xb3bf710>( <UILabel: 0xb3beaa0; frame = (0 0; 50 40); text = '03月'; userInteractionEnabled = NO; layer = <_UILabelLayer: 0xb3acc90>> ) (lldb) po (int)[[bigLable subviews] count] 1 (lldb)
线程状态
thread list:显示线程数
(lldb) thread list Process 4198 stopped * thread #1: tid = 0xfc64c, 0x00800b42 iSchool`-[YXHomeTViewController viewDidLoad](self=0x0b3b92d0, _cmd="viewDidLoad") + 1686 at YXHomeTViewController.m:138, queue = 'com.apple.main-thread', stop reason = breakpoint 5.1 thread #5: tid = 0xfc690, 0x37d70224 libsystem_kernel.dylib`kevent64 + 24, queue = 'com.apple.libdispatch-manager' thread #6: tid = 0xfc694, 0x37d84190 libsystem_kernel.dylib`__semwait_signal + 24, name = 'gputools.smt_poll.0x22485c0' thread #11: tid = 0xfc6c7, 0x37d70474 libsystem_kernel.dylib`mach_msg_trap + 20, name = 'AFNetworking' thread #12: tid = 0xfc6cd, 0x37d70474 libsystem_kernel.dylib`mach_msg_trap + 20, name = 'com.apple.NSURLConnectionLoader' thread #15: tid = 0xfc6d0, 0x37d84080 libsystem_kernel.dylib`__select + 20, name = 'com.apple.CFSocket.private' thread #30: tid = 0xfc777, 0x37d70474 libsystem_kernel.dylib`mach_msg_trap + 20, name = 'EMGCDAsyncSocket-CFStream' thread #46: tid = 0xfdaf8, 0x37d849c0 libsystem_kernel.dylib`__workq_kernreturn + 8
星号(*)表示thread #1为当前线程。为了获取线程的跟踪栈,可以使用以下命令:
(lldb) thread backtrace * thread #1: tid = 0xfc64c, 0x00800b42 iSchool`-[YXHomeTViewController viewDidLoad](self=0x0b3b92d0, _cmd="viewDidLoad") + 1686 at YXHomeTViewController.m:138, queue = 'com.apple.main-thread', stop reason = breakpoint 5.1 frame #0: 0x00800b42 iSchool`-[YXHomeTViewController viewDidLoad](self=0x0b3b92d0, _cmd="viewDidLoad") + 1686 at YXHomeTViewController.m:138 frame #1: 0x2c6c59ae UIKit`-[UIViewController loadViewIfRequired] + 602 frame #2: 0x2c6c571c UIKit`-[UIViewController view] + 24 * frame #3: 0x000dc80a iSchool`-[BaseViewControllerT showLoading](self=0x0b3b92d0, _cmd="showLoading") + 38 at BaseViewControllerT.m:72 frame #4: 0x007ff70c iSchool`-[YXHomeTViewController TestHttp](self=0x0b3b92d0, _cmd="TestHttp") + 60 at YXHomeTViewController.m:56 frame #5: 0x007ff6b4 iSchool`-[YXHomeTViewController init](self=0x0b3b92d0, _cmd="init") + 128 at YXHomeTViewController.m:49 frame #6: 0x00747b36 iSchool`-[MobileCampusController didselCellZhengshi:](self=0x022e7fd0, _cmd="didselCellZhengshi:", indexPath=0x09ca75b0) + 1014 at MobileCampusController.m:304
如果要查看所有线程调用栈则可以使用
thread backtrace all
检查帧参数和本地变量的最简便的方式是使用frame variable命令
(lldb) frame variable (YXHomeTViewController *) self = 0x0b3b92d0 (SEL) _cmd = "showLoading"
可以查看相关对象和地址。
image list可以用它来查看工程中使用的库。
(lldb) image list [ 0] B4BF0C10-3B1A-3FE5-9CCB-E65743E82B77 0x00004000 /Users/traceboard/Library/Developer/Xcode/DerivedData/iSchool-fujsfonczhafjxcmkgfofjbzpfwk/Build/Products/Debug-iphoneos/iSchool.app/iSchool /Users/traceboard/Library/Developer/Xcode/DerivedData/iSchool-fujsfonczhafjxcmkgfofjbzpfwk/Build/Products/Debug-iphoneos/iSchool.app.dSYM/Contents/Resources/DWARF/iSchool [ 1] 6CF411B5-99E9-3791-B3F4-0CED325786DD 0x1fe0b000 /Users/traceboard/Library/Developer/Xcode/iOS DeviceSupport/8.4.1 (12H321)/Symbols/usr/lib/dyld [ 2] 8574AF16-8793-3D1C-AEE7-FC2A51F04E4F 0x371ad000 /Users/traceboard/Library/Developer/Xcode/iOS DeviceSupport/8.4.1 (12H321)/Symbols/usr/lib/libicucore.A.dylib [ 3] 2E1A648A-1C0A-3A65-9BAF-221C2719C5C4 0x28d04000 /Users/traceboard/Library/Developer/Xcode/iOS DeviceSupport/8.4.1 (12H321)/Symbols/System/Library/Frameworks/CoreBluetooth.framework/CoreBluetooth [ 4] E9633AB3-EDDC-3032-8604-7203C343F2B8 0x296ff000 /Users/traceboard/Library/Developer/Xcode/iOS DeviceSupport/8.4.1 (12H321)/Symbols/System/Library/Frameworks/CoreLocation.framework/CoreLocation [ 5] 92F64E66-D354-3D04-BAED-AE41A6291C31 0x37a17000 /Users/traceboard/Library/Developer/Xcode/iOS DeviceSupport/8.4.1 (12H321)/Symbols/usr/lib/libsqlite3.dylib [ 6] 65E6D41B-25C1-306E-BE96-DF64D33C03AB 0x37c22000 /Users/traceboard/Library/Developer/Xcode/iOS DeviceSupport/8.4.1 (12H321)/Symbols/usr/lib/libz.1.dylib
还有可以设置断点:breakpoint set等命令,因为设置断点可以用图形界面更快更直观的设置,还有可以设置程序运行的步骤thread step等命令,都可以使用图形界面进行控制,而用的不多,个人感觉最有用的要属寻找对象地址,打印对象信息。