Created
January 8, 2014 15:11
-
-
Save zerdliu/8318230 to your computer and use it in GitHub Desktop.
batch symbolicate iOS crash log
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
## two args from commandline, set default value | |
crash_dat_files_directory=${1:-"./dat"} | |
dSYM_directory=${2:-"./dSYM"} | |
export DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer | |
#echo ${crash_dat_files_directory} ${dSYM_directory} | |
app_name="IphoneCom.app" | |
dSYM_name="${app_name}.dSYM" | |
output_directory=./output | |
unarchive_directory=${output_directory}/unarchive | |
output_crash_directory=${output_directory}/crash | |
function get_crash_uuid { | |
local crash_file=$1 | |
local crash_uuid=$(grep --after-context=1 "Binary Images:" ${crash_file} | tail -n1|awk -F"[><]" '{print $2}' | tr '[:lower:]' '[:upper:]') | |
echo ${crash_uuid} | |
} | |
function get_app_uuid { | |
local dSYM_file=$1 | |
local app_uuid=$(dwarfdump -u "${dSYM_file}" |awk '{print $2}' | sed 's/-//g' | tr '[:lower:]' '[:upper:]') | |
echo ${app_uuid} | |
} | |
function unarchive_dat_file { | |
local gzip_magic_number="\x1f\x8b\x08\x00\x00\x00\x00\x00" | |
local dat_file=$1 | |
local crash_file=$2 | |
printf ${gzip_magic_number} |cat - ${dat_file} |gzip -dc 2>/dev/null > ${crash_file} | |
} | |
function uuid_in_app_uuids? { | |
local uuid=$1 | |
local app_uuids=$2 | |
uuid=$(echo ${uuid}) | |
app_uuids=$(echo ${app_uuids}) | |
if [ -z ${uuid} ] ; then | |
return 1 | |
fi | |
grep -q ${uuid} <(echo ${app_uuids}) | |
return $? | |
} | |
## Step 0. prepare | |
## 0.1 create directory | |
rm -rf ${output_directory} | |
mkdir -p ${output_directory} ${unarchive_directory} ${output_crash_directory} | |
## 0.2 set lists , use unify index | |
## bellow 4 array use unify index | |
dat_files=($(find "${crash_dat_files_directory}" -type f|xargs basename)) | |
crash_file_list=() | |
crash_file_uuid_list=() | |
crash_file_app_list=() | |
dat_file_number=${#dat_files[@]} | |
## 0.3 find all dSYMs & apps path | |
dSYMs=() | |
while read -r -d $'\0'; do | |
dSYMs+=("${REPLY}") | |
done < <(find "${dSYM_directory}" -name ${dSYM_name} -print0) | |
apps=() | |
while read -r -d $'\0'; do | |
apps+=("${REPLY}") | |
done < <(find "${dSYM_directory}" -name ${app_name} -print0) | |
app_num=${#apps[@]} | |
# for debug | |
#echo ${dSYMs[@]} | |
#echo ${apps[@]} | |
#echo ${app_num} | |
## 0.4 find all app uuids | |
app_uuids=() | |
for index in $(seq 0 $(( ${app_num} - 1 ))); do | |
dSYM=${dSYMs[${index}]} | |
app=${apps[${index}]} | |
app_uuid=$(get_app_uuid "${dSYM}") | |
app_uuids+=("${app_uuid}") | |
done | |
#echo ${app_uuids[@]} | |
## Step 1. unarchive dat file to txt | |
for dat_file in ${dat_files[@]} ; do | |
crash_file=${dat_file%.dat}.crash | |
## unarchive dat file to crash file | |
unarchive_dat_file ${crash_dat_files_directory}/${dat_file} ${unarchive_directory}/${crash_file} | |
done | |
## Step 2. find app from multi-apps | |
for index in $(seq 0 $(( ${dat_file_number} - 1 )) ); do | |
dat_file=${dat_files[${index}]} | |
crash_file=${dat_file%.dat}.crash | |
## make a crash file array | |
crash_file_list+=("${crash_file}") | |
crash_uuid=$(get_crash_uuid ${unarchive_directory}/${crash_file}) | |
## uuid in app_uuid ? if not , set value = NULL, convert array to string before compare | |
if uuid_in_app_uuids? "${crash_uuid}" "$(echo ${app_uuids[@]})" ; then | |
for i in $(seq 0 $(( ${app_num} -1 ))) ; do | |
app=${apps[${i}]} | |
app_uuid=${app_uuids[${i}]} | |
if [[ ${app_uuid} == ${crash_uuid} ]] ; then | |
echo $app_uuid : $crash_uuid | |
## make a crash file uuid & app array | |
crash_file_uuid_list+=("${crash_uuid}") | |
crash_file_app_list+=("${app}") | |
break | |
fi | |
done | |
else | |
if [ -z ${crash_uuid} ]; then | |
crash_uuid="NULL" | |
fi | |
crash_file_uuid_list+=("${crash_uuid}") | |
crash_file_app_list+=("NULL") | |
fi | |
done | |
## for debug | |
#for index in $(seq 0 $(( ${dat_file_number} -1 ))) ; do | |
# echo ${crash_file_list[${index}]} ${crash_file_uuid_list[${index}]} ${crash_file_app_list[${index}]} | |
#done | |
## Step 3. symbolicate crash log | |
for index in $(seq 0 $(( ${dat_file_number} - 1 )) ); do | |
crash_file=${crash_file_list[${index}]} | |
app=${crash_file_app_list[${index}]} | |
if [[ ${app} != "NULL" ]] ; then | |
symbolicatecrash ${unarchive_directory}/${crash_file} "${app}" > ${output_crash_directory}/${crash_file} | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment