在XCODE編譯項目之後,會在app旁看見一個同名的dSYM檔案.
他是一個編譯的中轉檔案,簡單說就是debug的symbols包含在這個檔案中.
他有什麼作用? 當release的版本 crash的時候,會有一個記錄檔,包含出錯的記憶體位址, 使用symbolicatecrash工具能夠把日誌和dSYM檔案轉換成可以閱讀的log資訊,也就是將記憶體位址,轉換成程式裡的函數或變數和所屬於的 檔案名稱.
有一篇詳細的blog講了這個過程
http://www.anoshkin.net/blog/2008/09/09/iphone-crash-logs/
將類似
Thread 0 Crashed:
0 libobjc.A.dylib 0×300c87ec 0×300bb000 + 55276
1 MobileLines 0×00006434 0×1000 + 21556
2 MobileLines 0×000064c2 0×1000 + 21698
3 UIKit 0×30a740ac 0×30a54000 + 131244
的log資訊轉換成
Thread 0 Crashed:
0 libobjc.A.dylib 0×300c87ec objc_msgSend + 20
1 MobileLines 0×00006434 -[BoardView setSelectedPiece:] (BoardView.m:321)
2 MobileLines 0×000064c2 -[BoardView touchesBegan:withEvent:] (BoardView.m:349)
3 UIKit 0×30a740ac -[UIWindow sendEvent:] + 264
的有用資訊.
工具symbolicatecrash隱藏在/Developer/Platforms/iPhoneOS.platform/Developer /Library/Xcode/Plug-ins/iPhoneRemoteDevice.xcodeplugin/Contents/Resources/symbolicatecrash
所以一般複製到/usr/local/bin/ 成為命令列直接調用
$ sudo cp /Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Plug-ins/iPhoneRemoteDevice.xcodeplugin/Contents/Resources/symbolicatecrash /usr/local/bin/
這個時候運行
$ symbolicatecrash -h
就能看見協助資訊了.
這個時候,問題又來了..每次編譯後的dsym檔案都要手動儲存一次,很是麻煩.
於是有人寫了一個指令碼,自動在編譯後儲存該檔案.
請參考:
http://www.cimgf.com/2009/12/23/automatically-save-the-dsym-files/
指令碼我複製過來在下面
#!/bin/sh
if [ "$BUILD_STYLE" == "Debug" ]; then
echo “Skipping debug”
exit 0;
fi
if [ "$EFFECTIVE_PLATFORM_NAME" == "-iphonesimulator" ]; then
echo “Skipping simulator build”
exit 0;
fi
SRC_PATH=${DWARF_DSYM_FOLDER_PATH}/${DWARF_DSYM_FILE_NAME}
RELATIVE_DEST_PATH=dSYM/${EXECUTABLE_NAME}.$(date +%Y%m%d%H%M%S).app.dSYM
DEST_PATH=${PROJECT_DIR}/${RELATIVE_DEST_PATH}
echo “moving ${SRC_PATH} to ${DEST_PATH}”
mv “${SRC_PATH}” “${DEST_PATH}”
if [ -f ".git/config" ]; then
git add “${RELATIVE_DEST_PATH}”
git commit -m “Added dSYM file for ${BUILD_STYLE} build” “${RELATIVE_DEST_PATH}”
fi