Skip to content

Instantly share code, notes, and snippets.

@hjeffrey
Last active August 29, 2015 14:02
Show Gist options
  • Save hjeffrey/0a67316fc19314a80910 to your computer and use it in GitHub Desktop.
Save hjeffrey/0a67316fc19314a80910 to your computer and use it in GitHub Desktop.
解析iOS设备的crash文件
#
# create by Jia Yuhui. at 2014-06-05
# version 1.0
#
# find /Applications/Xcode.app -name symbolicatecrash -type f
## /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/PrivateFrameworks/DTDeviceKitBase.framework/Versions/A/Resources/symbolicatecrash
# export DEVELOPER_DIR="/Applications/XCode.app/Contents/Developer"
# ./$symbolicatecrash xxx.crash xxxxx.dSYM > xxxxxxx.crash
# dwarfdump –lookup 0x000036d2 –arch armv6 xxx.app.dSYM
# NOTE: 文件结构
# |
# shell.sh
# |
# |
# Crash|(所有的 crash 文件拷贝到该文件夹)
# | xxxx.crash(分析之后附加后缀.old,该文件之后就不再做处理了)
# | |
# | xx_date| (([版本号]或其他+今天日期,所有分析出来的文件都拷贝到这个文件夹里))
# | | |
# | |
# |
# XX([版本号]或其他,每个版本分别定义自己的文件夹)
# |
env=$1
if [ ! -n "$env" ]; then
echo '!!缺少必要的 [文件夹名] 或者 [版本号] '
exit
fi
target="xxxxxx"
toolName="symbolicatecrash"
toolPath=$(find /Applications/Xcode.app -name $toolName -type f)
#echo $toolPath
currentPath="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
#echo $currentPath
newToolPath=$currentPath/$toolName
#echo $newToolPath
if [ ! -f "$newToolPath" ]; then
cp $toolPath $newToolPath
fi
cd $currentPath
export DEVELOPER_DIR="/Applications/XCode.app/Contents/Developer"
dSYM=$currentPath/${env}/${target}.app.dSYM
app=$currentPath/${env}/${target}.app
#echo $dSYM
# 存放 crash文件 的文件夹
crashFolder='Crash'
if [ ! -d "$crashFolder" ]; then
mkdir $crashFolder
echo '!!错误: 请把 crash 文件拷贝到 Crash 文件夹)'
exit 1
fi
if [[ ! -d "$app" ]]; then
echo '!!错误: 分析失败 (' $env ' 目录内不存在 '${app}' )'
exit 1
fi
if [ -d "$dSYM" ]; then
crashFiles=$(find $crashFolder -name *.crash -maxdepth 1)
if [ -z "$crashFiles" ]; then
echo "不存在 crash 文件"
exit 0
fi
echo "开始解析 crash 文件"
for item in $crashFiles; do
#echo $item
if [ -f "$item" ]; then
resultPath=$crashFolder/$env'_Crash_'$(date +%m_%d)
if [ ! -d "$resultPath" ]; then
mkdir $resultPath
fi
targetName=$resultPath/$env"_Crash_"$(date +%m_%d_%H:%M:%S)".crash"
./$toolName $item $dSYM > $targetName
mv $item $item.old
# echo $targetName
targetPath=$currentPath/$targetName
if [ -f "$targetPath" ]; then
#open $targetPath
echo '文件' $item '分析完成'
else
echo '!!错误: 文件 '$targetName ' 不存在'
fi
else
echo '!!错误: 没发现 crash 文件'
fi #if [ -f "$item" ]; then
done #for item in $crashFiles; do
echo '全部分析完成'
else #if [ -d "$dSYM" ]; then
echo '!!错误: 分析失败 (' $env ' 目录内不存在 '${dSYM}' )'
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment