From 1b93025ab1a80a87acf8ffd8ba6e2bc136823723 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20H=C3=BC=C3=9Fler?= Date: Thu, 15 Jun 2023 19:24:14 +0200 Subject: [PATCH] dist/tools/openocd: start debug-server in background and wait --- dist/tools/openocd/openocd.sh | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/dist/tools/openocd/openocd.sh b/dist/tools/openocd/openocd.sh index 32e8886bbd..07d593268c 100755 --- a/dist/tools/openocd/openocd.sh +++ b/dist/tools/openocd/openocd.sh @@ -409,6 +409,17 @@ do_debug() { do_debugserver() { test_config + # temporary file that saves OpenOCD pid + OCD_PIDFILE=$(mktemp -t "openocd_pid.XXXXXXXXXX") + # will be called by trap + cleanup() { + OCD_PID="$(cat $OCD_PIDFILE)" + kill ${OCD_PID} + rm -f "$OCD_PIDFILE" + exit 0 + } + # cleanup after script terminates + trap "cleanup ${OCD_PIDFILE}" EXIT # start OpenOCD as GDB server sh -c "${OPENOCD} \ ${OPENOCD_ADAPTER_INIT} \ @@ -421,7 +432,13 @@ do_debugserver() { -c 'init' \ ${OPENOCD_DBG_EXTRA_CMD} \ -c 'targets' \ - -c 'halt'" + -c 'halt' & \ + echo \$! > $OCD_PIDFILE ; \ + wait \$(cat $OCD_PIDFILE)" & + + while read -r line; do + echo "Exit with Ctrl+D" + done } do_reset() {