~aleteoryx/muditaos

ref: 03a5cb6ab2b6efaa2529c7724ffc7fd229763e8e muditaos/tools/debug_crash_dump.sh -rwxr-xr-x 2.6 KiB
03a5cb6a — Lukasz Skrzypczak [BH-1028] Cyclic Deep Refresh 4 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/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] <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."
    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 $@