崩溃信息解析

崩溃信息解析

Posted by JT on January 23, 2019

崩溃检查

参考

苹果官方崩溃文件解释

崩溃文件

解决办法

苹果xcode为我们提供了一个工具“symbolicatecrash”,通过这个工具可以帮助我们解决问题。

  1. “/Applications/Xcode.app/Contents/SharedFrameworks/DVTFoundation.framework/Versions/A/Resources/symbolicatecrash”下找到“symbolicatecrash”工具;将其拷贝到新建文件夹中:例“crash”;
  2. 将审核被拒返回的txt文档下载下来,复制,粘贴到这个新建文件夹“crash”中,名称例如“applecrash.txt”;
  3. 找到对应的dSYM文件,例如“EasyWords.app.dSYM”;
  4. 执行”./symbolicatecrash ./applecrash.txt ./EasyWords.app.dSYM > crash.log”,“crash.log”为输出文件
  5. 如果遇到“Error: “DEVELOPER_DIR” is not defined at ./symbolicatecrash line 69. ”,则执行“export DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer”,可以通过“echo $DEVELOPER_DIR”查看是否设置成功 6.再去执行4,就可以拿到log

dSYM文件

iOS平台中,dSYM文件是指具有调试信息的目标文件,文件名通常为:xxx.app.dSYM

符号表

符号表是通过工具从dSYM文件中提取出来的

符号表是内存地址与函数名、文件名、行号的映射表。符号表元素如下所示:

<起始地址> <结束地址> <函数> [<文件名:行号>]

File:	/Users/li/Downloads/buglySymboliOS3.0.0/EasyWords.app.dSYM/Contents/Resources/DWARF/EasyWords
Format:	Mach-O/64-Bit
Arch:	arm64
Symbols:	236144
Tool Version:	3.0.0
File Version:	1.4
UUID:	1a7a3927fc173ce3887cdec76bd045ad
Built Time:	2020-12-23 08:40:27
Symbol table:
4ed0	4ee8	-[ZFPortraitControlView initWithFrame:]	ZFPortraitControlView.m:54
4ee8	4f08	-[ZFPortraitControlView initWithFrame:]	ZFPortraitControlView.m:55
4f08	4f0c	-[ZFPortraitControlView initWithFrame:]	ZFPortraitControlView.m:55
4f0c	4f20	-[ZFPortraitControlView initWithFrame:]	ZFPortraitControlView.m:57
4f20	4f24	-[ZFPortraitControlView initWithFrame:]	ZFPortraitControlView.m:0
4f24	4f2c	-[ZFPortraitControlView initWithFrame:]	ZFPortraitControlView.m:57
4f2c	4f4c	-[ZFPortraitControlView initWithFrame:]	ZFPortraitControlView.m:57
4f4c	4f60	-[ZFPortraitControlView initWithFrame:]	ZFPortraitControlView.m:58
4f60	4f64	-[ZFPortraitControlView initWithFrame:]	ZFPortraitControlView.m:0
4f64	4f6c	-[ZFPortraitControlView initWithFrame:]	ZFPortraitControlView.m:58
4f6c	4f84	-[ZFPortraitControlView initWithFrame:]	ZFPortraitControlView.m:58
4f84	4f94	-[ZFPortraitControlView initWithFrame:]	ZFPortraitControlView.m:59
4f94	4f98	-[ZFPortraitControlView initWithFrame:]	ZFPortraitControlView.m:0

崩溃详解

崩溃收集

  • 模拟器崩溃log位置:~/Library/Logs/DiagnosticReports/;例如:文件
  • 第三方工具:友盟等
  • 自己在应用内实现收集,上报服务端
  • XCode-Window-Organizer-Crashes产看线上崩溃
  • Xcode-Devices中直接查看某个设备的崩溃信息。

收集方法

ios c函数 NSSetUncaughtExceptionHandler

+ (void)registerHandler {
    // Backup original handler
    previousUncaughtExceptionHandler = NSGetUncaughtExceptionHandler();
    
    NSSetUncaughtExceptionHandler(&DoraemonUncaughtExceptionHandler);
}

#pragma mark - Private

// 崩溃时的回调函数
static void DoraemonUncaughtExceptionHandler(NSException * exception) {
    // 异常的堆栈信息
    NSArray * stackArray = [exception callStackSymbols];
    // 出现异常的原因
    NSString * reason = [exception reason];
    // 异常名称
    NSString * name = [exception name];
    
    NSString * exceptionInfo = [NSString stringWithFormat:@"========uncaughtException异常错误报告========\nname:%@\nreason:\n%@\ncallStackSymbols:\n%@", name, reason, [stackArray componentsJoinedByString:@"\n"]];
    
    // 保存崩溃日志到沙盒cache目录
    [DoraemonCrashTool saveCrashLog:exceptionInfo fileName:@"Crash(Uncaught)"];
    
    // 调用之前崩溃的回调函数
    if (previousUncaughtExceptionHandler) {
        previousUncaughtExceptionHandler(exception);
    }
    
    // 杀掉程序,这样可以防止同时抛出的SIGABRT被SignalException捕获
    kill(getpid(), SIGKILL);
}