美文网首页iOS开发专题iOSiOS Developer
崩溃日志分析和实战[附命令行]

崩溃日志分析和实战[附命令行]

作者: wg689 | 来源:发表于2016-12-14 18:09 被阅读852次

    1)找到symbolicatecrash,准备好文件

    如果jekens集成的话,记得从邮件中进入的链接UUID才可能和ips文件中的UUID一致

    第一次或者升级xcode 时候需要 找到symbolicatecrash的目录在终端输入以下命令

    find /Applications/Xcode.app -name symbolicatecrash -type f
    

    等一会才出现结果

    /Applications/Xcode.app/Contents/SharedFrameworks/DVTFoundation.framework/Versions/A/Resources/symbolicatecrash
    

    用命令将symbolicatecrash拷贝到桌面的crash文件夹里面,与.app和.app.dSYM放一起(手动找到symbolicatecrash,拷贝出来也行)

    cp /Applications/Xcode.app/Contents/SharedFrameworks/DVTFoundation.framework/Versions/A/Resources/symbolicatecrash /Users/wanggang/Desktop/crash
    

    将Crash文件也拷到当前文件夹里面(*.crash文件导出,参考最下面)

    2) 解析崩溃日志

    2.1获得3个解析文件.dSYM 和 ipa symbolicatecrash

    如何获取这些文件参考 使用Xcode自带工具symbolicatecrash解析iOS Crash文件

    2.2 UUID检查是否一致

    不从jekens邮件进入,会被覆盖
    每一个 xx.app 和 xx.app.dSYM 文件都有对应的 UUID,crash 文件也有自己的 UUID,只要这三个文件的 UUID 一致,我们就可以通过他们解析出正确的错误函数信息了。

    1.查看 xx.app 文件的 UUID,terminal 中输入命令 :

    dwarfdump --uuid DYZB.app/DYZB
    

    2.查看 xx.app.dSYM 文件的 UUID ,在 terminal 中输入命令:

    dwarfdump --uuid DYZB.app.dSYM 
    

    3.crash 文件内第一行 Incident Identifier 就是该 crash 文件的 UUID。
    检查发现不一致,crash文件解析不彻底

    slice_uuid

    dysm 的UUID 和上图片中的uuid 一致 可以完全解析

    wanggangdeiMac:crash wanggang$ dwarfdump --uuid DYZB680.app/DYZB
    UUID: 1D0097B7-C33A-3E7C-8BAF-913055829F15 (armv7) DYZB680.app/DYZB
    UUID: 91AAADFA-BD3A-3591-AA1E-EBC12967BE04 (arm64) DYZB680.app/DYZB
    wanggangdeiMac:crash wanggang$ dwarfdump --uuid DYZB.app.dSYM
    UUID: 8AB76108-8BC7-3A6D-933D-CDEE7FBE94B5 (armv7) DYZB.app.dSYM/Contents/Resources/DWARF/DYZB
    UUID: 1254221D-B4BA-39C7-B244-0DFAA33069C2 (arm64) DYZB.app.dSYM/Contents/Resources/DWARF/DYZB
    wanggangdeiMac:crash wanggang$ 
    
    wanggangdeiMac:crash wanggang$ dwarfdump --uuid DYZB.app/DYZB
    2016-12-16 14:04:30.462 xcodebuild[11001:1702581] [MT] DVTPlugInManager: Required plug-in compatibility UUID E0A62D1F-3C18-4D74-BFE5-A4167D643966 for KSImageNamed.ideplugin (com.ksuther.KSImageNamed) not present
    2016-12-16 14:04:30.533 xcodebuild[11001:1702581] [MT] PluginLoading: Required plug-in compatibility UUID E0A62D1F-3C18-4D74-BFE5-A4167D643966 for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/VVDocumenter-Xcode.xcplugin' not present in DVTPlugInCompatibilityUUIDs
    UUID: 2A3AFC4F-D379-358B-8B86-F5020594F3A8 (armv7) DYZB.app/DYZB
    UUID: 78D5EFDF-0D4A-3F40-9431-FF557B1C6ADA (arm64) DYZB.app/DYZB
    wanggangdeiMac:crash wanggang$ dwarfdump --uuid DYZB.app.dSYM
    UUID: 2A3AFC4F-D379-358B-8B86-F5020594F3A8 (armv7) DYZB.app.dSYM/Contents/Resources/DWARF/DYZB
    UUID: 78D5EFDF-0D4A-3F40-9431-FF557B1C6ADA (arm64) DYZB.app.dSYM/Contents/Resources/DWARF/DYZB
    wanggangdeiMac:crash wanggang$ 68320921-8205-4B4C-972F-8BE1C45A83EE
    

    .dSYM .app 里面的UUID 一致

    wanggangdeiMac:crash wanggang$ dwarfdump --uuid DYZB.app-680.dSYM
    UUID: 1D0097B7-C33A-3E7C-8BAF-913055829F15 (armv7) DYZB.app-680.dSYM/Contents/Resources/DWARF/DYZB //一致
    UUID: 91AAADFA-BD3A-3591-AA1E-EBC12967BE04 (arm64) DYZB.app-680.dSYM/Contents/Resources/DWARF/DYZB
    wanggangdeiMac:crash wanggang$ dwarfdump --uuid DYZB680.app/DYZB680 
    error: unable to open 'DYZB680.app/DYZB680': No such file or directory
    wanggangdeiMac:crash wanggang$ dwarfdump --uuid DYZB680.app/DYZB680 
    error: unable to open 'DYZB680.app/DYZB680': No such file or directory
    wanggangdeiMac:crash wanggang$ dwarfdump --uuid DYZB680.app/DYZB
    UUID: 1D0097B7-C33A-3E7C-8BAF-913055829F15 (armv7) DYZB680.app/DYZB //一致
    UUID: 91AAADFA-BD3A-3591-AA1E-EBC12967BE04 (arm64) DYZB680.app/DYZB
    

    2)将三个解析文件(crash文件,DSYM文件, symbolicatecrash文件)放到 一个文件夹下

    3) 执行如下命令(3步2分钟搞定)

    DYZB-2016-12-14-005657.crash 是crash 文件的名

    cd /Users/wanggang/Desktop/crash
    
    ./symbolicatecrash /Users/wanggang/Desktop/crash/DYZB-2016-12-14-005657.crash /Users/wanggang/Desktop/crash/DYZB.app.dSYM > Control_symbol.crash
    

    这时候终端有可能会出现:Error: "DEVELOPER_DIR" is not defined at ./symbolicatecrash line 60.

    输入命令:

    export DEVELOPER_DIR="/Applications/XCode.app/Contents/Developer"
    

    再执行

    ./symbolicatecrash /Users/wanggang/Desktop/crash/DYZB-2016-12-14-005657.crash /Users/wanggang/Desktop/crash/DYZB.app.dSYM > Control_symbol.crash
    

    更牛逼的命令

    //命令行进入CrashReport目录
    cd Desktop/crash/
    //配置环境变量
    export DEVELOPER_DIR=/Applications/XCode.app/Contents/Developer
    //解析.crash文件
    ./symbolicatecrash ./*.crash ./*.app.dSYM > symbol.crash
    

    那么多线程知道被那个触发的

    image.png

    最后成功就可成功

    解析不完全和解析完全的示例

    上述三个地方的UUID 一致才能正确解析,否则只能解析一部分
    样例部分解析

    Thread 0 name:  Dispatch queue: com.apple.main-thread
    Thread 0 Crashed:
    0   libsystem_kernel.dylib          0x0000000192e36014 __pthread_kill + 8
    1   libsystem_pthread.dylib         0x0000000192efe450 pthread_kill + 112
    2   libsystem_c.dylib               0x0000000192daa47c __abort + 144
    3   libsystem_c.dylib               0x0000000192daa3ec __abort + 0
    4   libsystem_malloc.dylib          0x0000000192e7aa38 _nano_vet_and_size_of_live + 0
    5   libsystem_malloc.dylib          0x0000000192e7bdb8 nano_free + 220
    6   CoreFoundation                  0x0000000193e15e8c _CFRelease + 1264
    7   CoreText                        0x0000000196ac467c TLine::DetachRun(long) + 104
    8   CoreText                        0x0000000196ac3f84 TLine::DetachRuns() + 80
    9   CoreText                        0x0000000196ac3e8c TLine::UpdateWidth() + 28
    10  CoreText                        0x0000000196aa4d2c TTypesetter::FinishLineFill(std::__1::tuple<TLine const*, TCharStream const*, void const* (*)(__CTRun const*, __CFString const*, void*), void*, std::__1::shared_ptr<TBidiLevelsProvider>*, unsigned int, unsigned char> const&, TLine&, double, double) + 72
    11  CoreText                        0x0000000196ac9e84 TFramesetter::FrameInRect(TFrame&, CFRange, double&, std::__1::tuple<double, double, double, double, double, double>&) const + 1084
    12  CoreText                        0x0000000196ac9978 TFramesetter::CreateFrame(CFRange, CGPath const*, __CFDictionary const*, double&, std::__1::tuple<double, double, double, double, double, double>&) const + 156
    13  CoreText                        0x0000000196ac9130 CTFramesetterSuggestFrameSizeWithConstraints + 216
    14  DYZB                            0x000000010006ddbc 0x10003c000 + 204220
    15  DYZB                            0x000000010006dc90 0x10003c000 + 203920
    16  DYZB                            0x0000000100070dbc 0x10003c000 + 216508
    17  DYZB                            0x000000010006f15c 0x10003c000 + 209244
    18  DYZB                            0x000000010004c238 0x10003c000 + 66104
    19  DYZB                            0x0000000100250168 0x10003c000 + 2179432
    20  DYZB                            0x000000010021a3fc 0x10003c000 + 1958908
    21  libdispatch.dylib               0x0000000192cf1200 _dispatch_call_block_and_release + 24
    22  libdispatch.dylib               0x0000000192cf11c0 _dispatch_client_callout + 16
    23  libdispatch.dylib               0x0000000192cf5d6c _dispatch_main_queue_callback_4CF + 1000
    24  CoreFoundation                  0x0000000193e13f2c __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12
    25  CoreFoundation                  0x0000000193e11b18 __CFRunLoopRun + 1660
    26  CoreFoundation                  0x0000000193d40048 CFRunLoopRunSpecific + 444
    27  GraphicsServices                0x00000001957c6198 GSEventRunModal + 180
    28  UIKit                           0x0000000199d2c2fc -[UIApplication _run] + 684
    29  UIKit                           0x0000000199d27034 UIApplicationMain + 208
    30  DYZB                            0x000000010052ecf4 0x10003c000 + 5188852
    31  libdyld.dylib                   0x0000000192d245b8 start + 4
    

    完全解析

    0   libsystem_kernel.dylib          0x0000000192e36014 __pthread_kill + 8
    1   libsystem_pthread.dylib         0x0000000192efe450 pthread_kill + 112
    2   libsystem_c.dylib               0x0000000192daa47c __abort + 144
    3   libsystem_c.dylib               0x0000000192daa3ec __abort + 0
    4   libsystem_malloc.dylib          0x0000000192e7aa38 _nano_vet_and_size_of_live + 0
    5   libsystem_malloc.dylib          0x0000000192e7bdb8 nano_free + 220
    6   CoreFoundation                  0x0000000193e15e8c _CFRelease + 1264
    7   CoreText                        0x0000000196ac467c TLine::DetachRun(long) + 104
    8   CoreText                        0x0000000196ac3f84 TLine::DetachRuns() + 80
    9   CoreText                        0x0000000196ac3e8c TLine::UpdateWidth() + 28
    10  CoreText                        0x0000000196aa4d2c TTypesetter::FinishLineFill(std::__1::tuple<TLine const*, TCharStream const*, void const* (*)(__CTRun const*, __CFString const*, void*), void*, std::__1::shared_ptr<TBidiLevelsProvider>*, unsigned int, unsigned char> const&, TLine&, double, double) + 72
    11  CoreText                        0x0000000196ac9e84 TFramesetter::FrameInRect(TFrame&, CFRange, double&, std::__1::tuple<double, double, double, double, double, double>&) const + 1084
    12  CoreText                        0x0000000196ac9978 TFramesetter::CreateFrame(CFRange, CGPath const*, __CFDictionary const*, double&, std::__1::tuple<double, double, double, double, double, double>&) const + 156
    13  CoreText                        0x0000000196ac9130 CTFramesetterSuggestFrameSizeWithConstraints + 216
    14  DYZB                            0x000000010006ddbc +[CTFrameParser parseAttributedContent:config:] (CTFrameParser.m:261)
    15  DYZB                            0x000000010006dc90 +[CTFrameParser parseAttributedFromDataArray:config:] (CTFrameParser.m:238)
    16  DYZB                            0x0000000100070dbc +[CTFrameParser parseMessageChatModel:config:] (CTFrameParser.m:694)
    17  DYZB                            0x000000010006f15c +[CTFrameParser parseDanMuModel:config:] (CTFrameParser.m:434)
    18  DYZB                            0x000000010004c238 -[DYChatView refreshChatTable:] (DYChatView.m:506)
    19  DYZB                            0x0000000100250168 -[DYNewPlayerViewController(DYSocketDelegate) socketDanmuDidRead:] (DYNewPlayerViewController+DYSocketDelegate.m:201)
    20  DYZB                            0x000000010021a3fc __56-[DYSocketManager(Live) receiveMessageWithType:message:]_block_invoke (DYSocketManager+Live.m:579)
    21  libdispatch.dylib               0x0000000192cf1200 _dispatch_call_block_and_release + 24
    22  libdispatch.dylib               0x0000000192cf11c0 _dispatch_client_callout + 16
    23  libdispatch.dylib               0x0000000192cf5d6c _dispatch_main_queue_callback_4CF + 1000
    24  CoreFoundation                  0x0000000193e13f2c __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12
    25  CoreFoundation                  0x0000000193e11b18 __CFRunLoopRun + 1660
    26  CoreFoundation                  0x0000000193d40048 CFRunLoopRunSpecific + 444
    27  GraphicsServices                0x00000001957c6198 GSEventRunModal + 180
    28  UIKit                           0x0000000199d2c2fc -[UIApplication _run] + 684
    29  UIKit                           0x0000000199d27034 UIApplicationMain + 208
    30  DYZB                            0x000000010052ecf4 main (main.m:14)
    31  libdyld.dylib                   0x0000000192d245b8 start + 4
    
    

    4)分析理解崩溃日志

    Date/Time:           2016-12-14 00:56:57.0262 +0800
    Launch Time:         2016-12-14 00:32:01.6074 +0800
    OS Version:          iPhone OS 10.1.1 (14B100)
    Report Version:      104
    
    Exception Type:  EXC_CRASH (SIGABRT)
    Exception Codes: 0x0000000000000000, 0x0000000000000000
    Exception Note:  EXC_CORPSE_NOTIFY
    Triggered by Thread:  0
    

    上文的常见的Exception Type & Exception Code

    异常类型Exception Type

    1)EXC_BAD_ACCESS

    此类型的Excpetion是我们最长碰到的Crash,通常用于访问了不该访问的内存导致。一般EXC_BAD_ACCESS后面的"()"还会带有补充信息。
    SIGSEGV: 通常由于重复释放对象导致,这种类型在切换了ARC以后应该已经很少见到了。
    SIGABRT: 收到Abort信号退出,通常Foundation库中的容器为了保护状态正常会做一些检测,例如插入nil到数组中等会遇到此类错误。
    SEGV:(Segmentation Violation),代表无效内存地址,比如空指针,未初始化指针,栈溢出等;

    SIGBUS:总线错误,与 SIGSEGV 不同的是,SIGSEGV 访问的是无效地址,而 SIGBUS 访问的是有效地址,但总线访问异常(如地址对齐问题)
    SIGILL:尝试执行非法的指令,可能不被识别或者没有权限

    2)EXC_BAD_INSTRUCTION

    此类异常通常由于线程执行非法指令导致

    3)EXC_ARITHMETIC

    除零错误会抛出此类异常

    5)分析实战

    Exception Type:  EXC_CRASH (SIGABRT)
    Exception Codes: 0x0000000000000000, 0x0000000000000000
    Exception Note:  EXC_CORPSE_NOTIFY
    Triggered by Thread:  0
    
    Application Specific Information:
    abort() called
    
    Filtered syslog:
    None found
    
    Thread 0 name:  Dispatch queue: com.apple.main-thread
    Thread 0 Crashed:
    0   libsystem_kernel.dylib          0x0000000192e36014 __pthread_kill + 8
    1   libsystem_pthread.dylib         0x0000000192efe450 pthread_kill + 112
    2   libsystem_c.dylib               0x0000000192daa47c __abort + 144
    3   libsystem_c.dylib               0x0000000192daa3ec __abort + 0
    4   libsystem_malloc.dylib          0x0000000192e7aa38 _nano_vet_and_size_of_live + 0
    5   libsystem_malloc.dylib          0x0000000192e7bdb8 nano_free + 220
    6   CoreFoundation                  0x0000000193e15e8c _CFRelease + 1264
    7   CoreText                        0x0000000196ac467c TLine::DetachRun(long) + 104
    8   CoreText                        0x0000000196ac3f84 TLine::DetachRuns() + 80
    9   CoreText                        0x0000000196ac3e8c TLine::UpdateWidth() + 28
    10  CoreText                        0x0000000196aa4d2c TTypesetter::FinishLineFill(std::__1::tuple<TLine const*, TCharStream const*, void const* (*)(__CTRun const*, __CFString const*, void*), void*, std::__1::shared_ptr<TBidiLevelsProvider>*, unsigned int, unsigned char> const&, TLine&, double, double) + 72
    11  CoreText                        0x0000000196ac9e84 TFramesetter::FrameInRect(TFrame&, CFRange, double&, std::__1::tuple<double, double, double, double, double, double>&) const + 1084
    12  CoreText                        0x0000000196ac9978 TFramesetter::CreateFrame(CFRange, CGPath const*, __CFDictionary const*, double&, std::__1::tuple<double, double, double, double, double, double>&) const + 156
    13  CoreText                        0x0000000196ac9130 CTFramesetterSuggestFrameSizeWithConstraints + 216
    14  DYZB                            0x000000010006ddbc 0x10003c000 + 204220
    15  DYZB                            0x000000010006dc90 0x10003c000 + 203920
    16  DYZB                            0x0000000100070dbc 0x10003c000 + 216508
    17  DYZB                            0x000000010006f15c 0x10003c000 + 209244
    18  DYZB                            0x000000010004c238 0x10003c000 + 66104
    19  DYZB                            0x0000000100250168 0x10003c000 + 2179432
    20  DYZB                            0x000000010021a3fc 0x10003c000 + 1958908
    21  libdispatch.dylib               0x0000000192cf1200 _dispatch_call_block_and_release + 24
    22  libdispatch.dylib               0x0000000192cf11c0 _dispatch_client_callout + 16
    23  libdispatch.dylib               0x0000000192cf5d6c _dispatch_main_queue_callback_4CF + 1000
    24  CoreFoundation                  0x0000000193e13f2c __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12
    25  CoreFoundation                  0x0000000193e11b18 __CFRunLoopRun + 1660
    26  CoreFoundation                  0x0000000193d40048 CFRunLoopRunSpecific + 444
    27  GraphicsServices                0x00000001957c6198 GSEventRunModal + 180
    28  UIKit                           0x0000000199d2c2fc -[UIApplication _run] + 684
    29  UIKit                           0x0000000199d27034 UIApplicationMain + 208
    30  DYZB                            0x000000010052ecf4 0x10003c000 + 5188852
    31  libdyld.dylib                   0x0000000192d245b8 start + 4
    

    崩溃类型 EXC_CRASH (SIGABRT)
    一搬是nil 值造成的

    上述崩溃中出现 了函数名的没有几个地方,问题出现在coreText,出现了函数:CTFramesetterSuggestFrameSizeWithConstraints 全工程中搜索结合解释反馈,初步怀疑 传入nil 值造成. 加一个判断防止nil作为一个参数 传入此函数```

    6)使用 atos解析crash logs

    atos 只是解析单条指令,小米加步枪式的
    经网上搜索解析crash logs的三种,由于未经测试,所以没有记录下,详见可以:http://www.cocoachina.com/industry/20140514/8418.html
    经测试可用的方法为atos -o XXX.app.dSYM/Contents/Resources/DWARF/XXX -l address0 targetAddress
    其中:
    a、XXX是appname
    b、address0是当前进程在内存中加载的起始地址,至于为什么需要这个,那就有必要去了解下ASLR
    获取地址参下图:


    binary Images后面第一个即为基地址(内存中加载的起始地址)
    c、targetAddress就是你想要符号化的地址 ,此处一般选取如下
            3 appName 0x000f462a 0x4000 + 984618
            4 appName 0x00352aee 0x4000 + 3468014
    

    参考:ios开发之crash日志收集,以及分析
    教你如何对ios崩溃(crash)日志做符号化


    相关文章

      网友评论

        本文标题:崩溃日志分析和实战[附命令行]

        本文链接:https://www.haomeiwen.com/subject/dzaimttx.html