1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-24 22:13:52 +01:00

dist/tools/jlink: refactor script

- Do not provide defaults for `${DBG}`, `${TUI}`, `${GDB_PORT}`,
  `${TELNET_PORT}` with special shell functions, but use canonical
  syntax for that
- Add `${DBG_EXTRA_FLAGS}` and pass them to GDB, as we do in OpenOCD
- Run `${DBG}` with `sh -c "..."` just like done in `openocd.sh` to
  allow passing flags to GDB in the same way independent of whether
  JLink or OpenOCD is used.
This commit is contained in:
Marian Buschsieweke 2025-11-09 15:57:13 +01:00 committed by Marian Buschsieweke
parent 370bb0e449
commit 6ad9cf1ec7
No known key found for this signature in database
GPG Key ID: 758BD52517F79C41

View File

@ -68,10 +68,18 @@
# The setsid command is needed so that Ctrl+C in GDB doesn't kill OpenOCD
: ${SETSID:=setsid}
# GDB command, usually a separate command for each platform (e.g. arm-none-eabi-gdb)
: ${GDB:=gdb}
# Debugger client command, can be used to wrap GDB in a front-end
: ${DBG:=${GDB}}
# Start with tui by default
: ${TUI:=-tui}
# Extra debugger flags, added by the user
: ${DBG_EXTRA_FLAGS:=}
# default GDB port
_GDB_PORT=3333
: ${GDB_PORT:=3333}
# default telnet port
_TELNET_PORT=4444
: ${TELNET_PORT:=4444}
# default J-Link command names, interface and speed
_JLINK=JLinkExe
_JLINK_SERVER=JLinkGDBServer
@ -115,15 +123,6 @@ test_binfile() {
fi
}
test_ports() {
if [ -z "${GDB_PORT}" ]; then
GDB_PORT=${_GDB_PORT}
fi
if [ -z "${TELNET_PORT}" ]; then
TELNET_PORT=${_TELNET_PORT}
fi
}
test_elffile() {
if [ ! -f "${ELFFILE}" ]; then
echo "Error: Unable to locate ELFFILE"
@ -132,12 +131,6 @@ test_elffile() {
fi
}
test_tui() {
if [ -n "${TUI}" ]; then
TUI=-tui
fi
}
test_serial() {
if [ -n "${JLINK_SERIAL}" ]; then
JLINK_SERIAL_SERVER="-select usb='${JLINK_SERIAL}'"
@ -145,12 +138,6 @@ test_serial() {
fi
}
test_dbg() {
if [ -z "${DBG}" ]; then
DBG="${GDB}"
fi
}
test_term() {
if [ -z "${JLINK_TERMPROG}" ]; then
JLINK_TERMPROG="${_JLINK_TERMPROG}"
@ -246,9 +233,6 @@ do_debug() {
test_serial
test_version
test_elffile
test_ports
test_tui
test_dbg
# start the J-Link GDB server
${SETSID} sh -c "${JLINK_SERVER} ${JLINK_SERIAL_SERVER} \
-nogui \
@ -261,7 +245,7 @@ do_debug() {
# save PID for terminating the server afterwards
DBG_PID=$!
# connect to the GDB server
${DBG} -q ${TUI} -ex "tar ext :${GDB_PORT}" ${ELFFILE}
sh -c "${DBG} -q ${TUI} -ex \"tar ext :${GDB_PORT}\" ${DBG_EXTRA_FLAGS} \"${ELFFILE}\""
# clean up
kill ${DBG_PID}
}
@ -270,7 +254,6 @@ do_debugserver() {
test_config
test_serial
test_version
test_ports
# start the J-Link GDB server
sh -c "${JLINK_SERVER} ${JLINK_SERIAL_SERVER} \
-nogui \