查看iOS應用crash日誌

基本操做:html

一、電腦安裝好Xcode,鏈接好手機設備ios

二、打開Xcode,點擊Window-Devices and Simulatorsswift

三、選中手機設備,點擊View Device Logs,便可查看手機crash日誌app

Incident Identifier: F04CE61A-F2E4-4AC8-8293-5AE959DE1842
CrashReporter Key:   29d37eab6d7de1b3f24295a26734d0c45dacdb9c
Hardware Model:      iPhone9,1
Process:             MyCamera [1899]
Path:                /private/var/containers/Bundle/Application/33958860-F333-4713-853A-E4E359FC4DA2/MyCamera.app/MyCamera
Identifier:          com.ios.devetest
Version:             1 (1.0)
Code Type:           ARM-64 (Native)
Role:                Foreground
Parent Process:      launchd [1]
Coalition:           com.ios.devetest [1803]
Date/Time:           2019-03-30 15:26:19.5775 +0800
Launch Time:         2019-03-30 15:26:11.1932 +0800
OS Version:          iPhone OS 11.3.1 (15E302)
Baseband Version:    3.66.00
Report Version:      104

Exception Type:  EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000001, 0x0000000104198b8c
Termination Signal: Trace/BPT trap: 5
Termination Reason: Namespace SIGNAL, Code 0x5
Terminating Process: exc handler [0]
Triggered by Thread:  0
 
Filtered syslog:
None found

Thread 0 name:  Dispatch queue: com.apple.main-thread

Thread 0 Crashed:

0   libswiftCore.dylib            0x0000000104198b8c 0x103fa8000 + 2034572
1   libswiftCore.dylib            0x0000000104198b8c 0x103fa8000 + 2034572
2   libswiftCore.dylib            0x0000000104001fc0 0x103fa8000 + 368576
3   MyCamera                      0x00000001031113d4 0x102eb8000 + 2462676

 

接下來長長姿式。。。。ide

 

首先要知道一點,之因此在View Device Logs面板能夠看到crash日誌,主要的功臣就是一個叫symbolicatecrash的可執行文件。集成在Xcode中的symbolicatecrash有點相似於集成在Android Studio中的adb工具包同樣,而且二者都是能夠單獨拿出來使用的。函數

 

首先,找到symbolicatecrash文件的位置:find /Applications/Xcode.app -name symbolicatecrash -type f工具

/Applications/Xcode.app/Contents/Developer/Platforms/WatchSimulator.platform/Developer/Library/PrivateFrameworks/DVTFoundation.framework/symbolicatecrash

/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVSimulator.platform/Developer/Library/PrivateFrameworks/DVTFoundation.framework/symbolicatecrash

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Library/PrivateFrameworks/DVTFoundation.framework/symbolicatecrash

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

這裏我用的是手機真機,因此使用的是最後一個,能夠把它拷貝出來。ui

 

這裏有個問題,咱們打印出來的crash日誌裏面,有代碼的函數名,但有些卻只有函數地址。spa

0   libswiftCore.dylib            0x0000000104198b8c 0x103fa8000 + 2034572
1   libswiftCore.dylib            0x0000000104198b8c 0x103fa8000 + 2034572
2   libswiftCore.dylib            0x0000000104001fc0 0x103fa8000 + 368576

緣由就在於我安裝到手機上的app並非由我當前這臺電腦編譯打包出來的,沒有**.app和**.app.dSYM兩個文件,因此根本沒有辦法把地址同步解析出來。線程

處理方法:

一、在桌面建立一個Crash文件夾,而後去編譯打包的機器上打開Xcode-Window-Organizer,在Archives找到App,右鍵Show in Finder

二、複製**.app和**.app.dSYM到Crash文件夾

三、把前面找到的symbolicatecrash文件以及待解析的MyApp.crash文件也一併複製到Crash目錄下

四、執行命令:./symbolicatecrash MyApp.crash **.app.dSYM > MyApp_symbol.crash

若是解析成功了,就會有函數名了,像下面這樣

Thread 0 Crashed:

0   libobjc.A.dylib                   0x300c87ec objc_msgSend + 20
1   MobileLines                       0x00006434 -[BoardView setSelectedPiece:] (BoardView.m:321)
2   MobileLines                       0x000064c2 -[BoardView touchesBegan:withEvent:] (BoardView.m:349)
3   UIKit                             0x30a740ac -[UIWindow sendEvent:] + 264
4   UIKit                             0x30a66110 -[UIApplication sendEvent:] + 248

 

假如查看crash log中的崩潰線程是這樣的:

Thread 0 Crashed:
0   libobjc.A.dylib               0x00003ec0 objc_msgSend + 24
1   MyApp               0x000036d2 0×1000 + 9938

咱們獲得了用戶發生崩潰狀況的內存地址:0x000036d2

而後回到咱們應用程序的build目錄,目錄下必定要包含**.app和**.app.dSYM兩個文件。在控制檯使用dwarfdump命令,就能解析出內存地址,如:

dwarfdump –lookup 0x000036d2 –arch armv6 MyApp.app.dSYM

相關文章
相關標籤/搜索