crash日誌符號化,以分析崩潰

weixin_34320159發表於2017-08-22

為什麼需要符號化

Filtered syslog:
None found

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0:
0   ...gou.sogouinput.BaseKeyboard  0x0000000100196000 0x100030000 + 1466368
1   ...gou.sogouinput.BaseKeyboard  0x0000000100191ca4 0x100030000 + 1449124
2   ...gou.sogouinput.BaseKeyboard  0x00000001001aadd8 0x100030000 + 1551832
3   ...gou.sogouinput.BaseKeyboard  0x00000001003942b0 0x100030000 + 3556016
4   ...gou.sogouinput.BaseKeyboard  0x0000000100393b30 0x100030000 + 3554096
5   ...gou.sogouinput.BaseKeyboard  0x00000001003c7bbc 0x100030000 + 3767228
6   ...gou.sogouinput.BaseKeyboard  0x00000001003c8a48 0x100030000 + 3770952
7   ...gou.sogouinput.BaseKeyboard  0x0000000100103158 0x100030000 + 864600
8   ...gou.sogouinput.BaseKeyboard  0x0000000100391d10 0x100030000 + 3546384
9   ...gou.sogouinput.BaseKeyboard  0x00000001003912c4 0x100030000 + 3543748
10  ...gou.sogouinput.BaseKeyboard  0x00000001003b4ba4 0x100030000 + 3689380
11  ...gou.sogouinput.BaseKeyboard  0x0000000100268174 0x100030000 + 2326900
12  ...gou.sogouinput.BaseKeyboard  0x0000000100268580 0x100030000 + 2327936

上面是sogou輸入法的crash日誌。像0x100030000 + 1466368這樣的都只給出了記憶體的崩潰地址。但無法得到是哪個方法呼叫。符號化就是將這些記憶體地址轉換成對應的可讀性方法。

準備相關檔案

要對crash日誌進行符號化,需要四樣東西:

  1. 從裝置上匯出的crash 日誌
  2. .dSYM檔案
  3. .app檔案
  4. symbolicatecrash工具
crash 日誌的匯出

將裝置連線電腦,xcode->Window->devices->選擇裝置->view device log->找到對應的crash日誌->export log

生成.dSYM檔案

crash日誌的符號化主要藉助dSYM檔案。得到dSYM檔案的方法:Target -> Build Setting -> Debug Information Format -> DWARF with dSYM File。這樣就可以和.app一起生成.dSYM檔案了。

app`檔案

symbolicatecrash工具
  1. 找到symbolicatecrash
find /Applications/Xcode.app -name symbolicatecrash -type f11
  1. 稍等一會就會有路徑輸出,這個路徑就是symbolicatecrash的路徑

    路徑可能不止一個,隨意選一個

/Applications/Xcode.app/Contents/SharedFrameworks/DVTFoundation.framework/Versions/A/Resources/symbolicatecrash
  1. 用命令將symbolicatecrash拷貝到桌面的crash資料夾裡面,與.app和.app.dSYM放一起(手動找到symbolicatecrash,拷貝出來也行)

    當然,不cp也可以的。為了清楚和方便使用,copy出來放一起。

cp /Applications/Xcode.app/Contents/SharedFrameworks/DVTFoundation.framework/Versions/A/Resources/symbolicatecrash ~/Desktop
export DEVELOPER_DIR="/Applications/XCode.app/Contents/Developer"

符號化

./symbolicatecrash XXXApp.crash XXXApp.app > crash.log

結果

對比.crash和.log檔案可以發現地址被替換成方法名、程式碼行等有用資訊。

//部分內容被修改過了
Filtered syslog:
None found

Last Exception Backtrace:
0   CoreFoundation                  0x1894fafe0 __exceptionPreprocess + 124
1   libobjc.A.dylib                 0x187f5c538 objc_exception_throw + 56
2   CoreFoundation                  0x1894faca8 -[NSException raise] + 12
3   Foundation                      0x189f1068c -[NSObject(NSKeyValueCoding) setValue:forKey:] + 272
4   XXXXApp                         0x102fb5850 -[XXXXAppManager enterRooms] (XXXXAppManager.m:33)
5   XXXXApp                         0x102f6de2c +[XXXXAppSDK showChatModule] (XXXXAppSDK.m:23)
6   XXXXApp                         0x100a918d4 +[XXXXAppManager callName:selectorName:params:] (XXXXAppManager.m:28)
7   XXXXApp                         0x100278bfc -[XXXXAppTopView buttonClick:] (XXXXAppView.m:112)
8   UIKit                           0x18f661c54 -[UIApplication sendAction:to:from:forEvent:] + 96
Filtered syslog:
None found

Last Exception Backtrace:
0   CoreFoundation                  0x1894fafe0 __exceptionPreprocess + 124
1   libobjc.A.dylib                 0x187f5c538 objc_exception_throw + 56
2   CoreFoundation                  0x1894faca8 -[NSException raise] + 12
3   Foundation                      0x189f1068c -[NSObject(NSKeyValueCoding) setValue:forKey:] + 272
4   XXXXApp                         0x102fb5850 0x1000d4000 + 49158224
5   XXXXApp                         0x102f6de2c 0x1000d4000 + 48864812
6   XXXXApp                         0x100a918d4 0x1000d4000 + 10213588
7   XXXXApp                         0x100278bfc 0x1000d4000 + 1723388
8   UIKit                           0x18f661c54 -[UIApplication sendAction:to:from:forEvent:] + 96

  • debug 模式下跑的包,產生的crash日誌不需要符號化
  • 線上環境app整合了Crashlytics,上報的crash已經符號化了
  • 主要是迴歸測試階段對於部分崩潰需要這種分析方式

相關文章