blob: 1756035726f401fa62fac0ad6f10f32f1d2ca1b8 [file] [log] [blame]
Sam Leffler7a773c52022-10-05 14:58:42 +00001#!/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 Leffler3346fb52021-06-15 13:57:00 -070016
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
22if [[ -z "${ROOTDIR}" ]]; then
23 echo "Source build/setup.sh first"
24 exit 1
25fi
26
Sam Leffler81b6c922022-02-14 10:57:23 -080027TARGET=riscv32-unknown-elf
28GDB="${ROOTDIR}"/cache/toolchain/bin/${TARGET}-gdb
Sam Leffler3b480332023-11-22 16:02:54 -080029PROGRAM=out/matcha/hw/boot_rom.elf
Sam Leffler3346fb52021-06-15 13:57:00 -070030REMOTE=localhost:3333
31
Sam Lefflere6be9322023-07-28 16:37:25 -070032CANTRIP_OUT=out/cantrip/${PLATFORM}/debug
Sam Leffler81b6c922022-02-14 10:57:23 -080033MATCHA_OUT=out/matcha/riscv32imc-unknown-none-elf/debug
Sam Leffler1bba8e52021-06-25 10:16:12 -070034
June Tate-Gansa531a3a2022-07-20 10:34:04 -050035USE_SEL4_EXTENSIONS="true"
36USE_SEL4_SYMBOL_AUTOSWITCHING="false"
37
Matthew Wilson45a04192023-11-21 12:30:45 -080038export PYTHONPATH=${PYTHON_SHODAN_ENV}/lib/python3.11/site-packages/:${PYTHONPATH}
June Tate-Gans548dde62022-11-22 11:06:31 -060039export SOURCE_DIR=${ROOTDIR}/cantrip
40export BUILD_DIR=$CANTRIP_OUT
Marcin Witkowski6ae4b4b2022-04-14 17:27:08 +020041
June Tate-Gansa531a3a2022-07-20 10:34:04 -050042function 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
77function main {
78 local -a gdbargs=(
79 -ex "set pagination off"
Sam Leffler3b480332023-11-22 16:02:54 -080080 -ex "directory sw/tock hw/matcha"
June Tate-Gansa531a3a2022-07-20 10:34:04 -050081 -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
107main "$@"