iOS开发 通过分析UMeng的错误详情解决crash问题
在项目中获取崩溃信息很重要。在iOS开发调试以及上线之后,程序经常会出现Crash问题。比较常见的第三方crash分析工具是使用友盟、百度、crashlytics等。第三方crash分析工具,甚至还带了符号化crash日志的功能。比较常用的有Crashlytics,Flurry等。
##找出出现crash的代码所在的位置
友盟统计中Crash有时候很难看出出现crash的地方。所以我们需要找出出现crash的代码所在的位置。
例如-[NSNull length]: unrecognized selector sent to instance 0x3a675a60
-[NSNull length]: unrecognized selector sent to instance 0x3a675a60
(null)
(0 CoreFoundation 0x2f70fee3 <redacted> + 1541 libobjc.A.dylib 0x39eaace7 objc_exception_throw + 382 CoreFoundation 0x2f7137f7 <redacted> + 2023 CoreFoundation 0x2f7120f7 <redacted> + 7064 CoreFoundation 0x2f661058 _CF_forwarding_prep_0 + 245 Views 0x3f55e3 Views + 41343716 Views 0xce63f Views + 8289917 UIKit 0x31f766a7 <redacted> + 908 UIKit 0x320dd56d <redacted> + 1209 UIKit 0x31f766a7 <redacted> + 9010 UIKit 0x31f76643 <redacted> + 3811 UIKit 0x31f76613 <redacted> + 4612 UIKit 0x31f61d5b <redacted> + 37413 UIKit 0x31f7605b <redacted> + 59414 UIKit 0x31f75d2d <redacted> + 52815 UIKit 0x31f70c87 <redacted> + 75816 UIKit 0x31f45e55 <redacted> + 19617 UIKit 0x31f44521 <redacted> + 712018 CoreFoundation 0x2f6dafaf <redacted> + 1419 CoreFoundation 0x2f6da477 <redacted> + 20620 CoreFoundation 0x2f6d8c67 <redacted> + 63021 CoreFoundation 0x2f643729 CFRunLoopRunSpecific + 52422 CoreFoundation 0x2f64350b CFRunLoopRunInMode + 10623 GraphicsServices 0x345b26d3 GSEventRunModal + 13824 UIKit 0x31fa4871 UIApplicationMain + 113625 Views 0x277f77 Views + 257215126 libdyld.dylib 0x3a3a8ab7 <redacted> + 2
)dSYM UUID: DF56542E-9A22-323A-AB92-66DDB8217241
CPU Type: armv7
Slide Address: 0x00004000
Binary Image: Views
Base Address: 0x000f5000
在以上的出现crash的log中,我们可以看到无法直接定位crash的代码行。
##下面我们就通过命令找出问题所在
- 1、找到当时打包应用发布时的归档文件 *.xcarchive。找到 dSYMs 文件夹里面的 *.dSYM 文件,将其复制出来。
- 2、打开终端,通过cd,*.dSYM 文件所在的文件夹。
- 3、通过命令dwarfdump --uuid appname.app.dSYM 找出对应的响应的uuid
1deMac-mini-2:dysm a1$ dwarfdump --uuid 4.0.3_Views.app.dSYM
UUID: DF56542E-9A22-323A-AB92-66DDB8217241 (armv7) 4.0.3_Views.app.dSYM/Contents/Resources/DWARF/Views
UUID: 1D53917F-B39C-3FBB-BDD4-3802F7372CD1 (arm64) 4.0.3_Views.app.dSYM/Contents/Resources/DWARF/Views
- 4、找出among中crash的错误详情中的dSYM UUID: DF56542E-9A22-323A-AB92-66DDB8217241 如下图所示
- 5、比对uuid是否一致,如果一致即说明包和crash时匹配的。
- 6、通过命令dwarfdump --arch=armv7 --lookup 0x3f55e3 4.0.3_Views.app.dSYM 可以看出问题所在
1deMac-mini-2:dysm a1$ dwarfdump --arch=armv7 --lookup 0x3f55e3 4.0.3_Views.app.dSYM
----------------------------------------------------------------------File: 4.0.3_Views.app.dSYM/Contents/Resources/DWARF/Views (armv7)
----------------------------------------------------------------------
Looking up address: 0x00000000003f55e3 in .debug_info... found!0x0038a04b: Compile Unit: length = 0x0000065e version = 0x0002 abbr_offset = 0x00000000 addr_size = 0x04 (next CU at 0x0038a6ad)0x0038a056: TAG_compile_unit [106] *AT_producer( "Apple LLVM version 8.0.0 (clang-800.0.38)" )AT_language( DW_LANG_ObjC )AT_name( "/Users/a1/Desktop/ios/ios/Views/Views/Controllers/Browser/BrowserViewController+Ex.m" )AT_stmt_list( 0x001f699f )AT_comp_dir( "/Users/a1/Desktop/ios/ios/Views" )AT_APPLE_optimized( 0x01 )AT_APPLE_major_runtime_vers( 0x02 )AT_low_pc( 0x003f52b0 )AT_high_pc( 0x003f5850 )0x0038a40d: TAG_subprogram [117] *AT_low_pc( 0x003f53e2 )AT_high_pc( 0x003f581c )AT_frame_base( r7 )AT_object_pointer( {0x0038a429} )AT_name( "-[BrowserViewController(Ex) getShareModel:]" )AT_decl_file( "/Users/a1/Desktop/ios/ios/Views/Views/Controllers/Browser/BrowserViewController+Ex.m" )AT_decl_line( 17 )AT_prototyped( 0x01 )AT_type( {0x0038a53f} ( ShareModel* ) )AT_APPLE_optimized( 0x01 )AT_APPLE_isa( 0x01 )
Line table dir : '/Users/a1/Desktop/ios/ios/Views/Views/Controllers/Browser'
Line table file: 'BrowserViewController+Ex.m' line 29, column 55 with start address 0x00000000003f55d0Looking up address: 0x00000000003f55e3 in .debug_frame... found!0x00067490: FDElength: 0x0000000cCIE_pointer: 0x00000000start_addr: 0x003f53e2 -[BrowserViewController(Ex) getShareModel:]range_size: 0x0000043a (end_addr = 0x003f581c)Instructions: 0x003f53e2: CFA=sp 1deMac-mini-2:dysm a1$
从上面的log中,我们可以看到问题所在,crash出现在BrowserViewController+Ex.m的29行。以及可以从start_addr: 0x003f53e2 -[BrowserViewController(Ex) getShareModel:]看出crash问题所在的方法。
如下图所示:
本文为学习记录,如果有不对的地方,还请您留言。