blob: b3a745abfde332b0de3f20cb23cb714716beb1dd [file] [log] [blame]
Sam Leffler3346fb52021-06-15 13:57:00 -07001#! /bin/bash
2
3# Launch gdb talking to a simulator or similar at localhost:3333
4#
5# ROOTDIR must be set to the top of the shodan development tree
6# (as done by build/setup.sh).
7
8if [[ -z "${ROOTDIR}" ]]; then
9 echo "Source build/setup.sh first"
10 exit 1
11fi
12
Sam Leffler81b6c922022-02-14 10:57:23 -080013TARGET=riscv32-unknown-elf
14GDB="${ROOTDIR}"/cache/toolchain/bin/${TARGET}-gdb
Sam Lefflerd2ed7f02022-07-17 14:40:53 -070015PROGRAM=out/shodan_boot_rom/multihart_boot_rom/multihart_boot_rom.elf
Sam Leffler3346fb52021-06-15 13:57:00 -070016REMOTE=localhost:3333
17
Sam Leffler81b6c922022-02-14 10:57:23 -080018KATA_OUT=out/kata/${TARGET}/debug
19MATCHA_OUT=out/matcha/riscv32imc-unknown-none-elf/debug
Sam Leffler1bba8e52021-06-25 10:16:12 -070020
June Tate-Gansa531a3a2022-07-20 10:34:04 -050021USE_SEL4_EXTENSIONS="true"
22USE_SEL4_SYMBOL_AUTOSWITCHING="false"
23
Marcin Witkowski6ae4b4b2022-04-14 17:27:08 +020024export SOURCE_DIR=${ROOTDIR}/kata
25export BUILD_DIR=$KATA_OUT
26
June Tate-Gansa531a3a2022-07-20 10:34:04 -050027function parseargv {
28 local usage="Usage: kgdb.sh [-h|--help] [-S|--no-sel4-extensions] [-a|--sel4-symbol-autoswitching]"
29 local args=$(getopt -o hSa --long no-sel4-extensions,symbol-autoswitching,help -n kgdb.sh -- "$@")
30
31 set -- $args
32
33 for i; do
34 case "$1" in
35 -S|--no-sel4-extensions)
36 echo "*** Disabling sel4 extensions"
37 USE_SEL4_EXTENSIONS="false"
38 shift
39 ;;
40
41 -a|--symbol-autoswitching)
42 echo "*** Enabling sel4 symbol autoswitching"
43 echo "*** Warning: this can cause unexpected behaviors."
44 USE_SEL4_EXTENSIONS="true"
45 USE_SEL4_SYMBOL_AUTOSWITCHING="true"
46 shift
47 ;;
48
49 --)
50 shift
51 break
52 ;;
53
54 -h|--help|*)
55 echo "$usage" >/dev/stderr
56 exit 1
57 ;;
58 esac
59 done
60}
61
62function main {
63 local -a gdbargs=(
64 -ex "set pagination off"
65 -ex "directory sw/tock"
66 -ex "file ${PROGRAM}"
67 -ex "set confirm off"
68 -ex "add-symbol-file ${PROGRAM}"
69 -ex "add-symbol-file ${MATCHA_OUT}/matcha_platform"
70 -ex "add-symbol-file ${MATCHA_OUT}/matcha_app"
71 -ex "set pagination on"
72 -ex "target remote ${REMOTE}"
73 -ex "monitor cpu0 IsHalted false"
74 )
75
76 parseargv "$@"
77
78 if [[ "${USE_SEL4_EXTENSIONS}" == "true" ]]; then
79 gdbargs+=(
80 -ex "monitor cpu1 CreateSeL4 0xffffffee"
81 -ex "source sim/renode/tools/sel4_extensions/gdbscript.py"
82 -ex "sel4 symbol-autoswitching ${USE_SEL4_SYMBOL_AUTOSWITCHING}"
83 )
84 fi
85
86
87 # NB: -q suppresses the banner to workaround the banner msg triggering the pager
88 # NB: auto-start cpu0 & cpu1 but leave cpu2 (VC) halted
89 exec "${GDB}" -q -cd "${ROOTDIR}" "${gdbargs[@]}"
90}
91
92main "$@"