Sam Leffler | 7a773c5 | 2022-10-05 14:58:42 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright 2022 Google LLC |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # https://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
Sam Leffler | 3346fb5 | 2021-06-15 13:57:00 -0700 | [diff] [blame] | 16 | |
| 17 | # Launch gdb talking to a simulator or similar at localhost:3333 |
| 18 | # |
| 19 | # ROOTDIR must be set to the top of the shodan development tree |
| 20 | # (as done by build/setup.sh). |
| 21 | |
| 22 | if [[ -z "${ROOTDIR}" ]]; then |
| 23 | echo "Source build/setup.sh first" |
| 24 | exit 1 |
| 25 | fi |
| 26 | |
Sam Leffler | 81b6c92 | 2022-02-14 10:57:23 -0800 | [diff] [blame] | 27 | TARGET=riscv32-unknown-elf |
| 28 | GDB="${ROOTDIR}"/cache/toolchain/bin/${TARGET}-gdb |
Sam Leffler | 3b48033 | 2023-11-22 16:02:54 -0800 | [diff] [blame] | 29 | PROGRAM=out/matcha/hw/boot_rom.elf |
Sam Leffler | 3346fb5 | 2021-06-15 13:57:00 -0700 | [diff] [blame] | 30 | REMOTE=localhost:3333 |
| 31 | |
Sam Leffler | e6be932 | 2023-07-28 16:37:25 -0700 | [diff] [blame] | 32 | CANTRIP_OUT=out/cantrip/${PLATFORM}/debug |
Sam Leffler | 81b6c92 | 2022-02-14 10:57:23 -0800 | [diff] [blame] | 33 | MATCHA_OUT=out/matcha/riscv32imc-unknown-none-elf/debug |
Sam Leffler | 1bba8e5 | 2021-06-25 10:16:12 -0700 | [diff] [blame] | 34 | |
June Tate-Gans | a531a3a | 2022-07-20 10:34:04 -0500 | [diff] [blame] | 35 | USE_SEL4_EXTENSIONS="true" |
| 36 | USE_SEL4_SYMBOL_AUTOSWITCHING="false" |
| 37 | |
Matthew Wilson | 45a0419 | 2023-11-21 12:30:45 -0800 | [diff] [blame] | 38 | export PYTHONPATH=${PYTHON_SHODAN_ENV}/lib/python3.11/site-packages/:${PYTHONPATH} |
June Tate-Gans | 548dde6 | 2022-11-22 11:06:31 -0600 | [diff] [blame] | 39 | export SOURCE_DIR=${ROOTDIR}/cantrip |
| 40 | export BUILD_DIR=$CANTRIP_OUT |
Marcin Witkowski | 6ae4b4b | 2022-04-14 17:27:08 +0200 | [diff] [blame] | 41 | |
June Tate-Gans | a531a3a | 2022-07-20 10:34:04 -0500 | [diff] [blame] | 42 | function parseargv { |
| 43 | local usage="Usage: kgdb.sh [-h|--help] [-S|--no-sel4-extensions] [-a|--sel4-symbol-autoswitching]" |
| 44 | local args=$(getopt -o hSa --long no-sel4-extensions,symbol-autoswitching,help -n kgdb.sh -- "$@") |
| 45 | |
| 46 | set -- $args |
| 47 | |
| 48 | for i; do |
| 49 | case "$1" in |
| 50 | -S|--no-sel4-extensions) |
| 51 | echo "*** Disabling sel4 extensions" |
| 52 | USE_SEL4_EXTENSIONS="false" |
| 53 | shift |
| 54 | ;; |
| 55 | |
| 56 | -a|--symbol-autoswitching) |
| 57 | echo "*** Enabling sel4 symbol autoswitching" |
| 58 | echo "*** Warning: this can cause unexpected behaviors." |
| 59 | USE_SEL4_EXTENSIONS="true" |
| 60 | USE_SEL4_SYMBOL_AUTOSWITCHING="true" |
| 61 | shift |
| 62 | ;; |
| 63 | |
| 64 | --) |
| 65 | shift |
| 66 | break |
| 67 | ;; |
| 68 | |
| 69 | -h|--help|*) |
| 70 | echo "$usage" >/dev/stderr |
| 71 | exit 1 |
| 72 | ;; |
| 73 | esac |
| 74 | done |
| 75 | } |
| 76 | |
| 77 | function main { |
| 78 | local -a gdbargs=( |
| 79 | -ex "set pagination off" |
Sam Leffler | 3b48033 | 2023-11-22 16:02:54 -0800 | [diff] [blame] | 80 | -ex "directory sw/tock hw/matcha" |
June Tate-Gans | a531a3a | 2022-07-20 10:34:04 -0500 | [diff] [blame] | 81 | -ex "file ${PROGRAM}" |
| 82 | -ex "set confirm off" |
| 83 | -ex "add-symbol-file ${PROGRAM}" |
| 84 | -ex "add-symbol-file ${MATCHA_OUT}/matcha_platform" |
| 85 | -ex "add-symbol-file ${MATCHA_OUT}/matcha_app" |
| 86 | -ex "set pagination on" |
| 87 | -ex "target remote ${REMOTE}" |
| 88 | -ex "monitor cpu0 IsHalted false" |
| 89 | ) |
| 90 | |
| 91 | parseargv "$@" |
| 92 | |
| 93 | if [[ "${USE_SEL4_EXTENSIONS}" == "true" ]]; then |
| 94 | gdbargs+=( |
| 95 | -ex "monitor cpu1 CreateSeL4 0xffffffee" |
| 96 | -ex "source sim/renode/tools/sel4_extensions/gdbscript.py" |
| 97 | -ex "sel4 symbol-autoswitching ${USE_SEL4_SYMBOL_AUTOSWITCHING}" |
| 98 | ) |
| 99 | fi |
| 100 | |
| 101 | |
| 102 | # NB: -q suppresses the banner to workaround the banner msg triggering the pager |
| 103 | # NB: auto-start cpu0 & cpu1 but leave cpu2 (VC) halted |
| 104 | exec "${GDB}" -q -cd "${ROOTDIR}" "${gdbargs[@]}" |
| 105 | } |
| 106 | |
| 107 | main "$@" |