Files
MuditaOS/debug_crash_dump.sh
Artur Śleszyński 33d652c1a1 [EGD-6156] Create crash dumps
Integrate the CrashCatcher library in order to store phone state after
a fault occurs. The dumps are stored in the CrashCatcher hex format and
can be debugged using the CrashDebug stub built for x86_64 via the
'debug_crash_dump.sh' script.
2021-04-02 14:58:42 +02:00

94 lines
2.4 KiB
Bash
Executable File

#!/bin/bash
# Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
# For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
BUILD_DIR=
CRASH_DUMP=
PURE_ELF=
GDB=${GDB:-arm-none-eabi-gdb}
function perror()
{
echo "Error:" $@ >&2
}
function print_usage()
{
echo "debug_crash_dump: This utility uses the CrashDebug stub to load the"
echo "crash dumps generated by the CrashCatcher fault handler library."
echo "The dump must be in the CrashCatcher hex dump format. This format is"
echo "different from the standard core dump file format and this utility"
echo "won't load standard core files."
echo
echo "Usage: [OPTIONS] <builddir> <crashdump>"
echo
echo "Options:"
echo " -e|--elf The elf file that generated the crash dump (full path)."
echo " '<builddir>/PurePhone.elf' by default."
echo
echo "ENV vars:"
echo " GDB The gdb executable used to load the crash dump."
echo " 'arm-none-eabi-gdb' by default."
}
function parse_args()
{
local PARAMS=""
while (( "$#" )); do
case "$1" in
-h|--help)
print_usage
exit
;;
-e|--elf)
if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
PURE_ELF="$2"
shift 2
else
perror "Argument missing for '$1'."
print_usage
exit 1
fi
;;
-*|--*=) # unsupported flags
perror "Unsupported flag: '$1'."
exit 1
;;
*) # preserve positional arguments
PARAMS="$PARAMS $1"
shift
;;
esac
done
eval set -- "$PARAMS"
if [[ $# != 2 ]]; then
perror "Bad number of arguments."
print_usage
exit 1
fi
BUILD_DIR="$1"
CRASH_DUMP="$2"
PURE_ELF="${PURE_ELF:-$BUILD_DIR/PurePhone.elf}"
}
function exec_gdb()
{
local CRASH_DEBUG="$BUILD_DIR/host-tools/crashdebug/CrashDebug"
exec "$GDB" "$PURE_ELF" \
-ex "set target-charset ASCII" \
-ex "target remote | \"$CRASH_DEBUG\" --elf \"$PURE_ELF\" --dump \"$CRASH_DUMP\""
}
function main()
{
parse_args $@
exec_gdb
}
main $@