IOS收集崩溃日志,查找崩溃代码行

来源:互联网 发布:谢晋影视艺术学院 知乎 编辑:程序博客网 时间:2024/05/29 17:16

1.崩溃时候存储错误堆栈

2.系统再次启动时,向服务器发送错误信息。

3.从服务器记录中获取错误信息列表

4.根据内存找到错误代码行



1) 错误堆栈存储到文件中

 appDelegate.m  在@interface -@end 之后增加全局方法


NSUncaughtExceptionHandler * uncaughtExceptionHandler =nil;

void UncaughExceptionHandler(NSException * exception) {

   NSLog(@"CRASH: %@",exception);

    NSLog(@"Stack Trace: %@",[exceptioncallStackSymbols]);

    //异常出现时的版本信息

    NSString *version = [[[NSBundlemainBundle]infoDictionary]objectForKey:@"CFBundleVersion"];

    //异常的堆栈信息

   NSArray * stackArray = [exceptioncallStackSymbols];

    //出现异常的原因

   NSString * reason = [exceptionreason];

    //异常名称

   NSString * name = [exceptionname];

    NSString * errorReason = [NSStringstringWithFormat:@"Error Detail:<br>version:%@<br>------<br>%@<br>-----------<br>%@<br>-----------<br>%@",version,name,reason,[stackArraycomponentsJoinedByString:@"<br>"]];

    NSString * filePath = [NSHomeDirectory()stringByAppendingPathComponent:@"Documents/stackError.txt"];

    [errorReason writeToFile:filePathatomically:YESencoding:NSUTF8StringEncodingerror:nil];

   return ;

}


2)注册异常方法

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{

   //系统再次启动后把异常文件取出来,传给服务器

   NSString * filePath = [NSHomeDirectory()stringByAppendingPathComponent:@"Documents/stackError.txt"]];

  //这里写传给服务器的请求代码 略。。

  //保存系统处理异常的Handler

    uncaughtExceptionHandler =NSGetUncaughtExceptionHandler();

    //设置处理异常的handler

    NSSetUncaughtExceptionHandler(&UncaughExceptionHandler);


}


3. 服务器获取到的传上来的错误信息是这个样子的,目测只能看出来是数组越界了,但是根本不知道是哪一行.找到自己应用名称后的内存地址。  0x001ff421 

Error Detail:<br>version:2.30<br>------<br>NSRangeException<br>-----------<br>*** -[__NSArrayM objectAtIndex:]: index 5 beyond bounds [0 .. 4]<br>-----------<br>0 CoreFoundation 0x2df93f9b <redacted> + 154<br>1 libobjc.A.dylib 0x38717ccf objc_exception_throw + 38<br>2 CoreFoundation 0x2deca7cb <redacted> + 230<br>3 ingage 0x001ff421 ingage + 1229857<br>4 ingage 0x00200b09 ingage + 1235721<br>5 UIKit 0x308cf03f <redacted> + 1078<br>6 UIKit 0x30981357 <redacted> + 214<br>7 UIKit 0x308306d5 <redacted> + 316<br>8 UIKit 0x307a953b <redacted> + 430<br>9 CoreFoundation 0x2df5f255 <redacted> + 20<br>10 CoreFoundation 0x2df5cbf9 <redacted> + 284<br>11 CoreFoundation 0x2df5cf3b <redacted> + 730<br>12 CoreFoundation 0x2dec7ebf CFRunLoopRunSpecific + 522<br>13 CoreFoundation 0x2dec7ca3 CFRunLoopRunInMode + 106<br>14 GraphicsServices 0x32dcd663 GSEventRunModal + 138<br>15 UIKit 0x3081414d UIApplicationMain + 1136<br>16 ingage 0x000e6b21 ingage + 80673<br>17 ingage 0x000d9518 ingage + 25880


4.打开xcode-window-organizer-archives  ,找到发布时候的包,右键 show in finder,文件名格式是 应用名+发布时间.xcarchive格式的,右键-显示简介,找到路径,用terminal工具进入,

一直用cd命令进入到 xxx.xcarchive/dSYMs/ingage.app.dSYM/Contents/Resources/DWARF 


执行命令 

 atos -arch armv7  -o ingage  0x001ff421  ,出现错误的代码行就出来了。






0 0
原创粉丝点击