#!/bin/bash # Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. # For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md SCRIPT_DIR=$(dirname "$(readlink -f "$0")") BUILD_DIR= CRASH_DUMP= PURE_ELF= GDB=${GDB:-arm-none-eabi-gdb-py} GDB_INIT=${GDB_INIT:-$SCRIPT_DIR/../.gdbinit-1051-dump} 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] " echo echo "Options:" echo " -e|--elf The elf file that generated the crash dump (full path)." echo " '/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." echo echo " GDB_INIT The gdb init script loaded at gdb startup." echo " 'SOURCE_DIR/.gdinit-1051-dump' 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/third-party/CrashDebug/bin/CrashDebug" exec "$GDB" "$PURE_ELF" \ -x "$GDB_INIT" \ -ex "target remote | \"$CRASH_DEBUG\" --elf \"$PURE_ELF\" --dump \"$CRASH_DUMP\"" } function main() { parse_args $@ exec_gdb } main $@