iOS app exception的解决方案
最近项目中总是碰到libsystem_kernel.dylib`__pthread_kill + 8, stop reason = signal SIGABRT
类似于这样的错误,但是出现这样的错误之后总是无法定位问题具体的位置。
(lldb) bt
* thread #1: tid = 0x2403, 0x31c16350 libsystem_kernel.dylib`__pthread_kill + 8, stop reason = signal SIGABRT
frame #0: 0x31c16350 libsystem_kernel.dylib`__pthread_kill + 8
frame #1: 0x34fa5122 libsystem_c.dylib`pthread_kill + 58
frame #2: 0x34fe1972 libsystem_c.dylib`abort + 94
frame #3: 0x38101d4e libc++abi.dylib`abort_message + 74
frame #4: 0x380ff0da libc++abi.dylib`safe_handler_caller(void (*)()) + 174
frame #5: 0x380ff114 libc++abi.dylib`std::terminate() + 20
frame #6: 0x38100598 libc++abi.dylib`__cxa_rethrow + 88
frame #7: 0x33e0f9d0 libobjc.A.dylib`objc_exception_rethrow + 12
frame #8: 0x39e66f20 CoreFoundation`CFRunLoopRunSpecific + 456
frame #9: 0x39e66d48 CoreFoundation`CFRunLoopRunInMode + 104
frame #10: 0x382342ea GraphicsServices`GSEventRunModal + 74
frame #11: 0x330a62f8 UIKit`UIApplicationMain + 1120
frame #12: 0x0001174c XingVelo3`main + 152 at main.m:16
方法一
通过在Xcode的控制台里面打印具体的值
主要命令是bt 或者thread backtrace
-
If you're using gdb, use
bt
to print the backtrace -
If you're using lldb, use
thread backtrace
instead
出现错误之后把信息打印出来,然后追踪具体的位置。但是仅仅这样还不够,很多信息看不到。
方法二,设置exception breakpoint
这个方法可以直接定位到出错的位置,非常强大,也是最近才发现的。
添加exception break point的方法,下面是说明。
If you're running your app out of Xcode, add an exception breakpoint. In the breakpoint navigator (command-6) hit the '+' at the very bottom left to add. This will pause execution on the line that throws the exception and allow you to inspect the current scope, stack, etc.