iOS Crash常规跟踪方法及Bugly集成运用
当app出现崩溃, 研发阶段一般可以通过以下方式来跟踪crash信息
#1.模拟器运行, 查看xcode错误日志
#2.真机调试, 查看xcode错误日志
#3.真机运行, 查看device系统日志
下面举例说明, 先写一段会Crash的代码crashdemo:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self performSelector:@selector(print) withObject:nil afterDelay:5];
}
- (void)print {
NSArray *array = @[];
NSLog(@"%@", array[1]);
}
Demo#1.模拟器运行, 查看xcode错误日志
程序执行后会立即崩溃, 打开xcode系统日志可以看到以下错误信息
2016-10-29 12:13:29.015 CrashDemo[37842:7436441] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArray0 objectAtIndex:]: index 1 beyond bounds for empty NSArray'
*** First throw call stack:
(
0 CoreFoundation 0x00b7ba84 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x00642e02 objc_exception_throw + 50
2 CoreFoundation 0x00b22390 __CFArrayGetTypeID_block_invoke + 0
3 CoreFoundation 0x00ac07f8 -[NSArray objectAtIndexedSubscript:] + 40
4 CrashDemo 0x000877b7 -[ViewController print] + 87
5 Foundation 0x00250d71 __NSFireDelayedPerform + 442
6 CoreFoundation 0x00acd576 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 22
7 CoreFoundation 0x00accf72 __CFRunLoopDoTimer + 1250
8 CoreFoundation 0x00a8b25a __CFRunLoopRun + 2202
9 CoreFoundation 0x00a8a706 CFRunLoopRunSpecific + 470
10 CoreFoundation 0x00a8a51b CFRunLoopRunInMode + 123
11 GraphicsServices 0x041e4664 GSEventRunModal + 192
12 GraphicsServices 0x041e44a1 GSEventRun + 104
13 UIKit 0x00f0c1eb UIApplicationMain + 160
14 CrashDemo 0x00087bba main + 138
15 libdyld.dylib 0x03189a21 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
通过xcode日志可以看到是数组访问越界, 发生越界的方式名为print
针对这个demo我们当然很清楚是刚才列的array[1]发生越界, 但对于一个完整的程序如何查看是在哪个地方发生越界的呢?
这个时候我们可以利用xcode的Show the breakpoint navigator功能, 点加号选择add exception breakpoint
这个时候我们在执行程序, xcode执行会自动停在要发生crash的代码段
Demo#2.真机调试, 查看xcode错误日志
如果有添加exeception point, 程序会自动停到打印array[1]那一行. 如果没有添加则程序会crash, xcode会出现以下错误日志
2016-10-29 12:15:53.561 CrashDemo[1062:316582] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArray0 objectAtIndex:]: index 1 beyond bounds for empty NSArray'
*** First throw call stack:
(0x211b398b 0x2094ee17 0x211433e7 0xc5a3b 0x219d1ad5 0x211765ff 0x21176231 0x2117407d 0x210c32e9 0x210c30d5 0x226b3ac9 0x257880b9 0xc5c99 0x20d6b873)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)










