首先,此文是在参考Xcode4时,对CrashReport的解析方法,而整理来的。感谢如下文章作者
http://www.cnblogs.com/ydhliphonedev/archive/2012/12/07/2806866.html
http://www.haogongju.net/art/1349569
最近半年忙于项目开发,很久没有更新博客了。言归正传,开始吧
在Xcode5下,每次发布Archive,都会生成一个对应本次发布的文件夹。路径如下:
/Users/[XXX]/Library/Developer/Xcode/Archives
其下会按照日期进行分类。而每个日期下对应不同的发布批次会有不同的xcarchive文件
[app名称] 13-11-24 下午1.41.xcarchive
个人推荐,最好保留每次发布的xcarchive文件。否则无法对真机CrashReport进行分析
在XCode5下,此步骤足够简单。可以通过苹果的iTunes Conencts中获取。
如果有真机,可以通过Xcode中
当然,注意到的同学已经能看到,在右侧可以看到经过初步解析的错误日志。这是因为此App是由我打包发布的,我本地有存储第一步中的Archive结果
- 第三步 :提取Xcode中自带的CrashReport解析器 symbolicatecrash
跟Xcode4时不同,在Xcode5中,此解析器工具的路径发生了变化。全路径如下
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/PrivateFrameworks/DTDeviceKitBase.framework/Versions/A/Resources/symbolicatecrash
其中DTDeviceKitBase.framework需要右键打开。
*因symbolicatecrash可以独立执行,而且为了方便我们下一步针对.app操作,可以选择将其拷贝到合适的目录下。
dSYM符号文件是Xcode在编译代码时生成的匹配文件,与当时发布的.app文件一一对应。如果没有此文件,就不能解析Crash文件。
dSYM文件,存在第一步中保留的xcarchive中。选择右键显示包内容,可以dSYMs文件夹。
将第二步、第三步、第四步获取的三个文件,放到同一文件夹下。执行如下命令
symbolicatecrash
crashReport.crash
AppName.app.dSYM
因系统设置不同,可能会报错:
Error: "DEVELOPER_DIR" is not defined at ./symbolicatecrash line 60.
这是因为缺少上下文。通过设置如下上下文可解决此错误
export DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer
此时,我们已经能初步解析CrashReport了,而获得的结果与Xcode的结果相同。而不难发现,作为调试最关键的,非系统代码,却未能识别出来。这无疑让CrashReport的作用大打折扣。
Code: |
Date/Time: 2013-11-24 14:19:24.466 +0800 OS Version: iOS 6.1 (10B144) Report Version: 104 Exception Type: EXC_BAD_ACCESS (SIGSEGV) Exception Codes: KERN_INVALID_ADDRESS at 0x915f34e3 Crashed Thread: 0 Thread 0 name: Dispatch queue: com.apple.main-thread Thread 0 Crashed: 0 libobjc.A.dylib 0x3b564522 objc_retain + 2 1 baiduHi_enterprise 0x0022bfbc 0xea000 + 1318844 2 baiduHi_enterprise 0x0022bfe4 0xea000 + 1318884 3 baiduHi_enterprise 0x001cb0c6 0xea000 + 921798 4 UIKit 0x357f2d84 _UIGestureRecognizerSendActions + 124 5 UIKit 0x357ba3f0 -[UIGestureRecognizer _updateGestureWithEvent:] + 388 6 UIKit 0x359a7a34 ___UIGestureRecognizerUpdate_block_invoke_0543 + 44 7 UIKit 0x356de82c _UIGestureRecognizerRemoveObjectsFromArrayAndApplyBlocks + 216 8 UIKit 0x356dd28e _UIGestureRecognizerUpdate + 1270 9 UIKit 0x356e81e2 -[UIWindow _sendGesturesForEvent:] + 762 10 UIKit 0x356e7dae -[UIWindow sendEvent:] + 86 |
其实,想做到这一点很简单,但很多文章中都没有涉及到。只需要在第一步中保留的Archive中,从xcarchive中,获取Products/Applications/AppName.app 对象,并将其拷贝到第五步中的目录里。再重新运行
symbolicatecrash命令即可。
Code: |
Date/Time: 2013-11-24 14:19:24.466 +0800 OS Version: iOS 6.1 (10B144) Report Version: 104 Exception Type: EXC_BAD_ACCESS (SIGSEGV) Exception Codes: KERN_INVALID_ADDRESS at 0x915f34e3 Crashed Thread: 0 Thread 0 name: Dispatch queue: com.apple.main-thread Thread 0 Crashed: 0 libobjc.A.dylib 0x3b564522 objc_retain + 2 1 baiduHi_enterprise 0x0022bfbc -[UIResponder(ActionUIResponder) dispatchUIActionEvent:] (UIActionResponder.m:21) 2 baiduHi_enterprise 0x0022bfe4 -[UIResponder(ActionUIResponder) dispatchUIActionEvent:] (UIActionResponder.m:28) 3 baiduHi_enterprise 0x001cb0c6 -[xxxxxx] (xxxxxx.m:225) 4 UIKit 0x357f2d84 _UIGestureRecognizerSendActions + 124 5 UIKit 0x357ba3f0 -[UIGestureRecognizer _updateGestureWithEvent:] + 388 6 UIKit 0x359a7a34 ___UIGestureRecognizerUpdate_block_invoke_0543 + 44 7 UIKit 0x356de82c _UIGestureRecognizerRemoveObjectsFromArrayAndApplyBlocks + 216 8 UIKit 0x356dd28e _UIGestureRecognizerUpdate + 1270 9 UIKit 0x356e81e2 -[UIWindow _sendGesturesForEvent:] + 762 10 UIKit 0x356e7dae -[UIWindow sendEvent:] + 86 11 baiduHi_enterprise 0x001544ac -[baiduHiUIWindow sendEvent:] (baiduHiUIWindow.m:26) 12 UIKit 0x356d57fc -[UIApplication sendEvent:] + 376 |
通过苹果的CrashReport,配合相应的工具。我们可以做到对异常进行代码级的跟踪。这无疑对解决问题提供了很大的帮助。
From: http://blog.sina.com.cn/s/blog_613126600101avjv.html