From 6ad9cf1ec7191bbd5cdec35f578439f3a9dcaab9 Mon Sep 17 00:00:00 2001 From: Marian Buschsieweke Date: Sun, 9 Nov 2025 15:57:13 +0100 Subject: [PATCH] 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. --- dist/tools/jlink/jlink.sh | 39 +++++++++++---------------------------- 1 file changed, 11 insertions(+), 28 deletions(-) diff --git a/dist/tools/jlink/jlink.sh b/dist/tools/jlink/jlink.sh index 2a41d13497..a6dfbf9f30 100755 --- a/dist/tools/jlink/jlink.sh +++ b/dist/tools/jlink/jlink.sh @@ -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 \