iOS Crash 通过trace来查找问题位置

1,041 阅读2分钟

以UMeng捕获信息为例

Application received signal SIGSEGV
(null)
((
	0   CoreFoundation                      0x0000000181f7ee50 <redacted> + 148
	1   libobjc.A.dylib                     0x00000001815e3f80 objc_exception_throw + 56
	2   CoreFoundation                      0x0000000181f7ed80 <redacted> + 0
	3   MyApp                               0x1001428c0 MyApp + 1321152
	4   libsystem_platform.dylib            0x0000000181bdd93c _sigtramp + 52
	5   UIKit                               0x000000018717cf6c <redacted> + 40
	6   WebKit                              0x0000000189f2ff24 <redacted> + 228
	7   WebKit                              0x0000000189f39444 <redacted> + 240
	8   libobjc.A.dylib                     0x00000001815fdae8 <redacted> + 508
	9   CoreFoundation                      0x0000000181e5cabc _CFAutoreleasePoolPop + 28
	10  CoreFoundation                      0x0000000181f32c48 <redacted> + 1636
	11  CoreFoundation                      0x0000000181e5cd10 CFRunLoopRunSpecific + 384
	12  GraphicsServices                    0x0000000183744088 GSEventRunModal + 180
	13  UIKit                               0x0000000187131f70 UIApplicationMain + 204
	14  MyApp                               0x1000942b8 MyApp + 606904
	15  libdyld.dylib                       0x00000001819fa8b8 <redacted> + 4
)

dSYM UUID: 89A2BD78-E27F-3E77-9BFA-8D0585C5381C
CPU Type: arm64
Slide Address: 0x0000000100000000
Binary Image: MyApp
Base Address: 0x000000010008c000

找到上传ipa包时的DWARF文件,通过终端cd到文件目录下

cd  /Users/admin/Library/Developer/Xcode/Archives/2018-03-01/MyApp 2018-3-1 下午4.50.xcarchive/dSYMs/MyApp.app.dSYM/Contents/Resources/DWARF

目录下会有MyApp文件,这是编译后的二进制文件,然后执行以下命令,可以看到内存地址反编译回来的源码行

-> atos -arch arm64 -o MyApp 0x1001428c0
-[TestViewController test] (in MyApp) (TestViewController.m:51)