blob: 1f457d08f9a09275abfc0ae51bb6905a625f1a46 [file] [log] [blame]
#!/bin/bash
#
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Launch gdb talking to a simulator or similar at localhost:3333
#
# ROOTDIR must be set to the top of the shodan development tree
# (as done by build/setup.sh).
if [[ -z "${ROOTDIR}" ]]; then
echo "Source build/setup.sh first"
exit 1
fi
TARGET=riscv32-unknown-elf
GDB="${ROOTDIR}"/cache/toolchain/bin/${TARGET}-gdb
PROGRAM=out/shodan_boot_rom/multihart_boot_rom.elf
REMOTE=localhost:3333
CANTRIP_OUT=out/cantrip/${PLATFORM}/debug
MATCHA_OUT=out/matcha/riscv32imc-unknown-none-elf/debug
USE_SEL4_EXTENSIONS="true"
USE_SEL4_SYMBOL_AUTOSWITCHING="false"
export PYTHONPATH=${ROOTDIR}/cache/python-venv/lib/python3.11/site-packages/:${PYTHONPATH}
export SOURCE_DIR=${ROOTDIR}/cantrip
export BUILD_DIR=$CANTRIP_OUT
function parseargv {
local usage="Usage: kgdb.sh [-h|--help] [-S|--no-sel4-extensions] [-a|--sel4-symbol-autoswitching]"
local args=$(getopt -o hSa --long no-sel4-extensions,symbol-autoswitching,help -n kgdb.sh -- "$@")
set -- $args
for i; do
case "$1" in
-S|--no-sel4-extensions)
echo "*** Disabling sel4 extensions"
USE_SEL4_EXTENSIONS="false"
shift
;;
-a|--symbol-autoswitching)
echo "*** Enabling sel4 symbol autoswitching"
echo "*** Warning: this can cause unexpected behaviors."
USE_SEL4_EXTENSIONS="true"
USE_SEL4_SYMBOL_AUTOSWITCHING="true"
shift
;;
--)
shift
break
;;
-h|--help|*)
echo "$usage" >/dev/stderr
exit 1
;;
esac
done
}
function main {
local -a gdbargs=(
-ex "set pagination off"
-ex "directory sw/tock"
-ex "file ${PROGRAM}"
-ex "set confirm off"
-ex "add-symbol-file ${PROGRAM}"
-ex "add-symbol-file ${MATCHA_OUT}/matcha_platform"
-ex "add-symbol-file ${MATCHA_OUT}/matcha_app"
-ex "set pagination on"
-ex "target remote ${REMOTE}"
-ex "monitor cpu0 IsHalted false"
)
parseargv "$@"
if [[ "${USE_SEL4_EXTENSIONS}" == "true" ]]; then
gdbargs+=(
-ex "monitor cpu1 CreateSeL4 0xffffffee"
-ex "source sim/renode/tools/sel4_extensions/gdbscript.py"
-ex "sel4 symbol-autoswitching ${USE_SEL4_SYMBOL_AUTOSWITCHING}"
)
fi
# NB: -q suppresses the banner to workaround the banner msg triggering the pager
# NB: auto-start cpu0 & cpu1 but leave cpu2 (VC) halted
exec "${GDB}" -q -cd "${ROOTDIR}" "${gdbargs[@]}"
}
main "$@"