1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-17 05:32:45 +01:00

makefiles/tools/renode: improve debugger management

When using the debug target, the GDB server is spawned automatically in the background. This logic is moved in a external script
This commit is contained in:
Alexandre Abadie 2020-11-21 18:12:43 +01:00
parent 4b149fa3c3
commit dcaa9eb59c
No known key found for this signature in database
GPG Key ID: 1C919A403CAE1405
2 changed files with 69 additions and 6 deletions

53
dist/tools/renode/renode-debug.sh vendored Executable file
View File

@ -0,0 +1,53 @@
#!/usr/bin/env bash
# This script wraps Renode emulator GDB server and a debugger
# client in a single command and takes 4 arguments: the board to emulate,
# the application directory of the the current application, the elffile
# containing the firmware to debug, the debugger port and custom debugger client
# arguments
# This script is supposed to be called from RIOTs make system when using the
# "debug" target.
# @author Alexandre Abadie <alexandre.abadie@inria.fr>
BOARD=$1
APPDIR=$2
ELFFILE=$3
# GDB command, usually a separate command for each platform (e.g. arm-none-eabi-gdb)
: ${GDB:=gdb-multiarch}
# Debugger client command, can be used to wrap GDB in a front-end
: ${DBG:=${GDB}}
# Default GDB port, set to 0 to disable, required != 0 for debug and debug-server targets
: ${GDB_PORT:=$4}
# Default debugger flags,
: ${DBG_DEFAULT_FLAGS:=-q -ex \"target remote :${GDB_PORT}\"}
# Custom extra debugger flags, depends on the emulator
: ${DBG_CUSTOM_FLAGS:=$5}
# Debugger flags, will be passed to sh -c, remember to escape any quotation signs.
# Use ${DBG_DEFAULT_FLAGS} to insert the default flags anywhere in the string
: ${DBG_FLAGS:=${DBG_DEFAULT_FLAGS} ${DBG_CUSTOM_FLAGS}}
# temporary file that contains the emulator pid
EMULATOR_PIDFILE=$(mktemp -t "emulator_pid.XXXXXXXXXX")
# will be called by trap
cleanup() {
kill "$(cat ${EMULATOR_PIDFILE})"
rm -f "${EMULATOR_PIDFILE}"
exit 0
}
# cleanup after script terminates
trap "cleanup ${EMULATOR_PIDFILE}" EXIT
# don't trap on Ctrl+C, because GDB keeps running
trap '' INT
# start Renode GDB server
sh -c "\
GDB_PORT=${GDB_PORT} \
EMULATOR_PIDFILE=${EMULATOR_PIDFILE} \
BOARD=${BOARD} \
make -C ${APPDIR} emulate-only debug-server & \
echo \$! > ${EMULATOR_PIDFILE}" &
# Start the debugger and connect to the GDB server
sh -c "${DBG} ${DBG_FLAGS} ${ELFFILE}"

View File

@ -1,8 +1,6 @@
RENODE ?= renode
RENODE_IMAGE_FILE ?= $(ELFFILE)
RENODE_BOARD_CONFIG ?= $(BOARDDIR)/dist/board.resc
DEBUGGER ?= gdb-multiarch
DEBUGGER_PORT ?= 3333
# Use renode interactive commands to specify the image file and board config
RENODE_CONFIG_FLAGS += -e "set image_file '$(RENODE_IMAGE_FILE)'"
@ -10,8 +8,20 @@ RENODE_CONFIG_FLAGS += -e "include @$(RENODE_BOARD_CONFIG)"
# Set emulator variables
EMULATOR_FLAGS ?= $(RENODE_CONFIG_FLAGS) -e start
EMULATOR_DEBUG_FLAGS += $(RENODE_CONFIG_FLAGS)
EMULATOR_DEBUG_FLAGS += -e "machine StartGdbServer $(DEBUGGER_PORT) true"
EMULATOR ?= $(RENODE)
DEBUGGER_FLAGS ?= $(ELFFILE) -ex "target remote :$(DEBUGGER_PORT)" -ex "monitor start"
# Configure the debugger
GDB_PORT ?= 3333
EMULATOR_PIDFILE ?=
ifneq (,$(EMULATOR_PIDFILE))
$(info Using Renode pid file $(EMULATOR_PIDFILE))
RENODE_CONFIG_FLAGS += --pid-file $(EMULATOR_PIDFILE)
endif
RENODE_DEBUG_FLAGS += $(RENODE_CONFIG_FLAGS)
RENODE_DEBUG_FLAGS += -e "machine StartGdbServer $(GDB_PORT) true"
DEBUGSERVER ?= $(EMULATOR)
DEBUGSERVER_FLAGS ?= $(RENODE_DEBUG_FLAGS)
DEBUGGER_FLAGS ?= $(BOARD) $(APPDIR) $(ELFFILE) $(GDB_PORT) "-ex \"monitor start\""
DEBUGGER ?= $(RIOTTOOLS)/renode/renode-debug.sh