Skip to content

Instantly share code, notes, and snippets.

@zbyhoo
Last active January 12, 2018 03:01
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save zbyhoo/09b08f371e7a8971ece8 to your computer and use it in GitHub Desktop.
Save zbyhoo/09b08f371e7a8971ece8 to your computer and use it in GitHub Desktop.
#!/bin/bash
function usage()
{
echo ""
echo "Usage:"
echo "$0 <archive> <app_name> <crashlog> [<output_file>]"
echo "or"
echo "$0 <archive> <app_name> <crashlog_dir> [<output_dir>]"
echo ""
}
function symbolicate()
{
crash_log_local=$1
output_file_local=$2
if [ -e "${output_file_local}" ]; then
echo "already symbolicated: ${crash_log_local}"
return
fi
echo "processing crash log: ${crash_log_local}"
exec 2<&-
unnamed_functions=$(${symbolicatecrash_app} "${crash_log_local}" "${dsym}")
load_address_line=$(echo -e "${unnamed_functions}" | grep -A1 "Binary Images:" | grep -v "Binary Images:")
load_address=$(echo $load_address_line | awk '{print $1;}')
slide_output=$(otool -arch ${architecture} -l "${app}" | grep -B 3 -A 8 -m 2 "__TEXT" | grep vmaddr)
search_string="* ${app_name} *"
all_lines=$(cat "${crash_log_local}" | wc -l | sed -e 's/^ *//' -e 's/ *$//')
counter=0
echo -n "" > ${output_file_local}
symbolicated_string=""
while read -r line
do
counter=$((counter + 1))
pct=$(bc <<< "scale=2; (100*$counter/$all_lines)")
echo -ne \\r"processing line: ${counter}/${all_lines} (${pct}%)"
if [[ "$line" == $search_string ]]
then
IFS=', ' read -a array <<< "$line"
IFS=', ' read -a slide_array <<< "$slide_output"
slide=${slide_array[1]}
stack_address=${array[2]}
let symbol_address="${slide}+${stack_address}-${load_address}"
final=$(printf "%x\n" ${symbol_address})
named_function=$(atos -arch ${architecture} -o "${app}" ${final} | tail -1)
new_line=$(fill_spaces "${array[0]}" 4)
new_line="${new_line}"$(fill_spaces "${array[1]}" 30)
new_line="${new_line}"$(printf \\t)
new_line="${new_line}"$(fill_spaces "$stack_address" 11)
symbolicated_string="${new_line}"" ${named_function}"
else
symbolicated_string="${line}"
fi
echo "$symbolicated_string" >> "${output_file_local}"
done < <(echo -e "$unnamed_functions")
echo ""
exec 2>&1
}
if [ "$#" -ne 4 ] && [ "$#" -ne 3 ]; then
usage
exit 0
fi
function fill_spaces()
{
word=$1
max_length=$2
word_length=${#word}
let spaces_count="${max_length}-${word_length}"
printf ${word}
awk "BEGIN{for(c=0;c<${spaces_count};c++) printf \" \";}"
}
export -f fill_spaces
export DEVELOPER_DIR=$(xcode-select -print-path)
export symbolicatecrash_app=$(find $DEVELOPER_DIR -name symbolicatecrash -type f)
export architecture="armv7"
output_postfix="_symbolicated.txt"
if [ "$#" -eq 4 ]; then
archive="${1}"
app_name="${2}"
crash_log="${3}"
output_file="${4}"
elif [ "$#" -eq 3 ]; then
archive="${1}"
app_name="${2}"
crash_log="${3}"
if [ -d "$crash_log" ]; then
output_file="${3}"
elif [ -f "$crash_log" ]; then
output_file="${3}${output_postfix}"
fi
fi
app="${archive}/Products/Applications/${app_name}.app/${app_name}"
dsym="${archive}/dSYMs/${app_name}.app.dSYM"
if [ -d "$crash_log" ] && [ -d "$output_file" ]; then
for i in $crash_log/*.crash; do
if [ -f "$i" ]; then
symbolicate "$i" "${i}${output_postfix}"
fi
done
elif [ -f "$crash_log" ]; then
symbolicate "$crash_log" "$output_file"
else
usage
exit 0
fi
echo "Done"
@laktak
Copy link

laktak commented Apr 9, 2014

With the following change it works perfectly for monotouch apps as well, thanks!

app="${archive}/${app_name}.app/${app_name}"
dsym="${archive}/${app_name}.app.dSYM"

@sfreeland
Copy link

Line 69: done < <(echo -e "$unnamed_functions")

What redirection syntax is that? The version of bash I have installed (3.2.53) doesn't like it at all...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment