Skip to content

Instantly share code, notes, and snippets.

@nathan-fiscaletti
Last active July 26, 2024 17:26
Show Gist options
  • Save nathan-fiscaletti/b58b642f78a4f60274e3be703e230140 to your computer and use it in GitHub Desktop.
Save nathan-fiscaletti/b58b642f78a4f60274e3be703e230140 to your computer and use it in GitHub Desktop.
A tool for symbolicating iOS crash reports.
#!/bin/bash
CRASH=$1
APP=$2
ARCH=$3
OUTPUT=$4
# This script will fully symbolicate an iOS Crash Report
# Usage: ./symbolicate.sh mycrash.crash MyApp.app arch64 output.crash
#
# If you do not supply an output file the script will simply print the symbolicated script to STDOUT.
function main() {
if [ ! "$#" -gt 3 ]; then
echo "Usage: $0 <crash> <app> <arch> [output]"
exit
fi
if [ ! -z $OUTPUT ]; then
OUTPUT=$(pwd)/$OUTPUT
fi
pushd "$(dirname "$APP")" > /dev/null
NUMOFLINES=$(wc -l < "$CRASH")
CURLINENUM=1
if [ ! -z $OUTPUT ]; then
echo "Symbolicating to $OUTPUT..."
echo -n '' > $OUTPUT
fi
while IFS='' read -r line || [[ -n "$line" ]]; do
keys=$(echo $line | grep -oE -e '0x([a-z]|[0-9])+\s0x([a-z]|[0-9])+')
if [ ! -z "$keys" ]; then
symbolicated=$(symbolicate $keys);
fi
if [ ! -z $OUTPUT ]; then
reportProgress $CURLINENUM $NUMOFLINES
echo ${line/$keys/$symbolicated} >> $OUTPUT
else
echo ${line/$keys/$symbolicated}
fi
CURLINENUM=$(awk "BEGIN {print $CURLINENUM+1}")
done < "$CRASH"
printf "\n"
popd > /dev/null
}
function symbolicate() {
appname=$(echo $APP | grep -oE -e '([^\/.]+)\.')
echo $(xcrun atos -o "$APP/${appname/./}" -arch $ARCH -l $2 $1)
}
function reportProgress() {
PROGRESS=$(awk "BEGIN {printf \"%.0f\n\", ($1/$2)*100}")
printf '\r\033[KProgress: '
printf "$PROGRESS"
echo -n "%"
}
main $@
@nathan-fiscaletti
Copy link
Author

Thanks for this - I think line 9 should be -gt 2 not -gt 3, as the output isn't required. I couldn't get the output option to work either.

I just saw this! Can you describe what actually happens when you try to use the output option?

@diyontheweb
Copy link

Hi, I believe it's caused by the folder directory containing a space in the folder name. I would get ./symbolicate.sh: line 28: [Cut off folder directory path]: binary operator expected.

@nathan-fiscaletti
Copy link
Author

Hi, I believe it's caused by the folder directory containing a space in the folder name. I would get ./symbolicate.sh: line 28: [Cut off folder directory path]: binary operator expected.

Have you tried passing your path wrapped in quotes? Otherwise, you can try wrapping the $OUTPUT on line 28 in quotes.

@diyontheweb
Copy link

Yes, I just all files to a folder with no spaces. This was more just for your reference if you were curious. I didn't put the full file path as the output variable, instead I CD'd into the folder with the executable file and output was just a single file name in the same folder.

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