理論文章
crash分析攻略:https://mp.weixin.qq.com/s/hVj-j61Br3dox37SN79fDQ
常見崩潰原因分析
分享一些常見的崩潰原因
總覽
可以通過Exception Information和Backtrace迅速判斷出大致崩潰原因挣输。
有些常見的崩潰都有額外的診斷信息须蜗,這些信息能夠幫助我們進一步排查出問題订讼。
Swift Runtime Error
Swift通過內(nèi)存安全技術來提前捕獲代碼問題雏逾。Swift Runtime Error會有比較鮮明的特征
Exception Type: EXC_BREAKPOINT (SIGTRAP)
...
Termination Signal: Trace/BPT trap: 5
Termination Reason: Namespace SIGNAL, Code 0x5
在英特爾處理器上,崩潰信如下
Exception Type: EXC_BAD_INSTRUCTION (SIGILL)
...
Exception Note: EXC_CORPSE_NOTIFY
Termination Signal: Illegal instruction: 4
Termination Reason: Namespace SIGNAL, Code 0x4
在堆棧區(qū)域也有相關信息
Thread 0 Crashed:
0 MyCoolApp 0x0000000100a71a88 @objc ViewController.viewDidLoad() (in MyCoolApp) (ViewController.swift:18)
Language Exception(OC崩潰)
Apple的系統(tǒng)框架在發(fā)生runtime錯誤的時候會拋出Language Exception狮惜,比如數(shù)組越界等赃承。會有如下特征:
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
同時此類崩潰還有Last Exception Backtrace
Last Exception Backtrace:
0 CoreFoundation 0x19aae2a48 __exceptionPreprocess + 220
1 libobjc.A.dylib 0x19a809fa4 objc_exception_throw + 55
watch dog強殺
被watchdog強殺一般崩潰類型是SIGKILL痒谴,同時Termination Reason里面的Code固定為0x8badf00d。
Exception Type: EXC_CRASH (SIGKILL)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Termination Reason: Namespace SPRINGBOARD, Code 0x8badf00d
如果watchdog強殺是因為app長時間沒有響應箱叁,則可能會有額外信息墅垮。
Termination Description: SPRINGBOARD,
scene-create watchdog transgression: application<com.example.MyCoolApp>:667
exhausted real (wall clock) time allowance of 19.97 seconds
| ProcessVisibility: Foreground
| ProcessState: Running
| WatchdogEvent: scene-create
| WatchdogVisibility: Foreground
| WatchdogCPUStatistics: (
| "Elapsed total CPU time (seconds): 15.290 (user 15.290, system 0.000), 28% CPU",
| "Elapsed application CPU time (seconds): 0.367, 1% CPU"
| )
訪問僵尸對象導致的崩潰
訪問僵尸對象的,意思是說給已經(jīng)dealloc的對象發(fā)送消息耕漱。給已經(jīng)析構的對象發(fā)送消息會發(fā)生 objc_msgSend, objc_retain, or objc_release類似這種崩潰算色。
Thread 0 Crashed:
0 libobjc.A.dylib 0x00000001a186d190 objc_msgSend + 16
1 Foundation 0x00000001a1f31238 __NSThreadPerformPerform + 232
2 CoreFoundation 0x00000001a1ac67e0 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
另外一種情況也可能代表是訪問了僵尸對象,這時候會有Last Exception Backtrace信息
Last Exception Backtrace:
0 CoreFoundation 0x1bf596a48 __exceptionPreprocess + 220
1 libobjc.A.dylib 0x1bf2bdfa4 objc_exception_throw + 55
2 CoreFoundation 0x1bf49a5a8 -[NSObject+ 193960 (NSObject) doesNotRecognizeSelector:] + 139
Memory Access野指針問題
野指針異常類型一般是EXC_BAD_ACCESS螟够,同時還就會有VM Region Info信息灾梦。
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x0000000000000000
VM Region Info: 0 is not in any region. Bytes before following region: 4307009536
REGION TYPE START - END [ VSIZE] PRT/MAX SHRMOD REGION DETAIL
UNUSED SPACE AT START
--->
__TEXT 0000000100b7c000-0000000100b84000 [ 32K] r-x/r-x SM=COW ...pp/MyGreatApp
Framework丟失
如果app運行時發(fā)現(xiàn)缺少framework,會拋出 EXC_CRASH (SIGABRT)異常錯誤碼妓笙,而且你也會收到Termination Description中斷描述若河。
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Termination Description: DYLD, dependent dylib '@rpath/MyFramework.framework/MyFramework'
not found for '<path>/MyCoolApp.app/MyCoolApp', tried but didn't find:
'/usr/lib/swift/MyFramework.framework/MyFramework'
'<path>/MyCoolApp.app/Frameworks/MyFramework.framework/MyFramework'
'@rpath/MyFramework.framework/MyFramework'
'/System/Library/Frameworks/MyFramework.framework/MyFramework'