Skip to content

Commit

Permalink
dist/tools/openocd: start debug-server in background and wait
Browse files Browse the repository at this point in the history
  • Loading branch information
fabian18 committed Jun 15, 2023
1 parent 829af7c commit 1b93025
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion dist/tools/openocd/openocd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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} \
Expand All @@ -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() {
Expand Down

0 comments on commit 1b93025

Please sign in to comment.