iOS定位到崩溃代码行数
不知道大家是不是在代码调试过程中经常遇到项目崩溃的情况:
比如:
数组越界;
没有实现方法选择器;
野指针;
还有很多很多情况。。。。。。。昨天学到了一种可以直接定位到崩溃代码行数的一个命令,记录一下,和大家分享哟!!!
看下面我的崩溃信息:
2016-11-18 08:43:12.088 11[919:30817] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 3 beyond bounds [0 .. 2]' *** First throw call stack: ( 0 CoreFoundation 0x000000010f5be34b __exceptionPreprocess + 171 1 libobjc.A.dylib 0x000000010f01f21e objc_exception_throw + 48 2 CoreFoundation 0x000000010f4f8eeb -[__NSArrayI objectAtIndex:] + 155 3 11 0x000000010ea4c889 -[ViewController viewDidLoad] + 185 4 UIKit 0x000000010fb82c99 -[UIViewController loadViewIfRequired] + 1258 5 UIKit 0x000000010fb830cc -[UIViewController view] + 27 6 UIKit 0x000000010fa4cc51 -[UIWindow addRootViewControllerViewIfPossible] + 71 7 UIKit 0x000000010fa4d3a2 -[UIWindow _setHidden:forced:] + 293 8 UIKit 0x000000010fa60cb5 -[UIWindow makeKeyAndVisible] + 42 9 UIKit 0x000000010f9d9c89 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4818 10 UIKit 0x000000010f9dfde9 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1731 11 UIKit 0x000000010f9dcf69 -[UIApplication workspaceDidEndTransaction:] + 188 12 FrontBoardServices 0x0000000112b2f723 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 24 13 FrontBoardServices 0x0000000112b2f59c -[FBSSerialQueue _performNext] + 189 14 FrontBoardServices 0x0000000112b2f925 -[FBSSerialQueue _performNextFromRunLoopSource] + 45 15 CoreFoundation 0x000000010f563311 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17 16 CoreFoundation 0x000000010f54859c __CFRunLoopDoSources0 + 556 17 CoreFoundation 0x000000010f547a86 __CFRunLoopRun + 918 18 CoreFoundation 0x000000010f547494 CFRunLoopRunSpecific + 420 19 UIKit 0x000000010f9db7e6 -[UIApplication _run] + 434 20 UIKit 0x000000010f9e1964 UIApplicationMain + 159 21 11 0x000000010ea4cbbf main + 111 22 libdyld.dylib 0x000000011239e68d start + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException
再看我定位崩溃代码行命令以及结果显示:
(lldb) image lookup --address 0x000000010ea4c889 Address: 11[0x0000000100001889] (11.__TEXT.__text + 185) Summary: 11`-[ViewController viewDidLoad] + 185 at ViewController.m:20 Address: 11[0x0000000100001889] (11.__TEXT.__text + 185) Summary: 11`-[ViewController viewDidLoad] + 185 at ViewController.m:20 (lldb)
是不是特别方便定位到崩溃的代码行数在 ViewController.m:20。。。。第20行啦!!!
是不是很简单啊,小伙伴么!!!