Skip to content
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
24 changes: 18 additions & 6 deletions dist/tools/openocd/openocd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -191,22 +191,34 @@ do_debug() {
test_elffile
test_ports
test_tui
# setsid is needed so that Ctrl+C in GDB doesn't kill OpenOCD
[ -z "${SETSID}" ] && SETSID="$(which setsid)"
# temporary file that saves OpenOCD pid
OCD_PIDFILE=$(mktemp -t "openocd_pid.XXXXXXXXXX")
# cleanup after script terminates
trap "cleanup ${OCD_PIDFILE}" EXIT
# don't trap on Ctrl+C, because GDB keeps running
trap '' INT
# start OpenOCD as GDB server
sh -c "${OPENOCD} -f '${OPENOCD_CONFIG}' \
${SETSID} sh -c "${OPENOCD} -f '${OPENOCD_CONFIG}' \
${OPENOCD_EXTRA_INIT} \
-c 'tcl_port ${TCL_PORT}' \
Copy link
Member

Choose a reason for hiding this comment

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

Whoops! Good catch!

-c 'telnet_port ${TELNET_PORT}' \
-c 'gdb_port ${GDB_PORT}' \
-c 'init' \
-c 'targets' \
-c 'halt' \
-l /dev/null" &
# save PID for terminating the server afterwards
OCD_PID=$?
-l /dev/null & \
echo \$! > $OCD_PIDFILE" &
# connect to the GDB server
${DBG} ${TUI} -ex "tar ext :${GDB_PORT}" ${ELFFILE}
# clean up
kill ${OCD_PID}
# will be called by trap
cleanup() {
OCD_PID="$(cat $OCD_PIDFILE)"
kill ${OCD_PID}
rm -f "$OCD_PIDFILE"
exit 0
}
}

do_debugserver() {
Expand Down