Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dist/tools/openocd: start debug-server in background and wait #19737

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)" &
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the background wait needed?
Does it keep the script (and trap) alive for the cleanup?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tested it without the ampersand in L437 and I think what happens then is that the shell waits for the openocd process to finish, while it is running obviously. So the script does not get to the while read until something on the remote side kills openocd


while read -r line; do
echo "Exit with Ctrl+D"
done
}

do_reset() {
Expand Down