Skip to content

Commit

Permalink
openocd: support target debug-client
Browse files Browse the repository at this point in the history
  • Loading branch information
fabian18 committed Jun 9, 2023
1 parent 4e1ac37 commit c76a192
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
35 changes: 25 additions & 10 deletions dist/tools/openocd/openocd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
# TELNET_PORT: port opened for telnet connections
# DBG: debugger client command, default: 'gdb -q'
# TUI: if TUI!=null, the -tui option will be used
# debug-client: debug-client <elffile>
# connects to a running debug-server
# GDB_PORT: port opened for GDB connections
# DBG: debugger client command, default: 'gdb -q'
# TUI: if TUI!=null, the -tui option will be used
#
# debugr: debug <elfile>
# debug given file on the target but flash it first directly
Expand Down Expand Up @@ -344,6 +349,21 @@ do_flash() {
echo 'Done flashing'
}

do_debugclient() {
ELFFILE=$1
test_elffile
# Export to be able to access these from the sh -c command lines, may be
# useful when using a frontend for GDB
export ELFFILE
export GDB
export GDB_PORT
export DBG_FLAGS
export DBG_DEFAULT_FLAGS
export DBG_EXTRA_FLAGS
# Start the debugger and connect to the GDB server
sh -c "${DBG} ${DBG_FLAGS} ${ELFFILE}"
}

do_debug() {
ELFFILE=$1
test_config
Expand Down Expand Up @@ -375,16 +395,7 @@ do_debug() {
${OPENOCD_DBG_START_CMD} \
-l /dev/null & \
echo \$! > $OCD_PIDFILE" &
# Export to be able to access these from the sh -c command lines, may be
# useful when using a frontend for GDB
export ELFFILE
export GDB
export GDB_PORT
export DBG_FLAGS
export DBG_DEFAULT_FLAGS
export DBG_EXTRA_FLAGS
# Start the debugger and connect to the GDB server
sh -c "${DBG} ${DBG_FLAGS} ${ELFFILE}"
do_debugclient ${ELFFILE}
}

do_debugserver() {
Expand Down Expand Up @@ -485,6 +496,10 @@ case "${ACTION}" in
echo "### Starting Debugging ###"
do_debug "$@"
;;
debug-client)
echo "### Attaching to GDB Server ###"
do_debugclient "$@"
;;
debug-server)
echo "### Starting GDB Server ###"
do_debugserver
Expand Down
4 changes: 3 additions & 1 deletion makefiles/tools/openocd.inc.mk
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
FLASHER ?= $(RIOTTOOLS)/openocd/openocd.sh
DEBUGGER ?= $(RIOTTOOLS)/openocd/openocd.sh
DEBUGSERVER ?= $(RIOTTOOLS)/openocd/openocd.sh
DEBUGCLIENT ?= $(RIOTTOOLS)/openocd/openocd.sh
RESET ?= $(RIOTTOOLS)/openocd/openocd.sh

FLASHFILE ?= $(ELFFILE)
FFLAGS ?= flash $(FLASHFILE)
DEBUGGER_FLAGS ?= debug $(DEBUG_ELFFILE)
DEBUGSERVER_FLAGS ?= debug-server
DEBUGCLIENT_FLAGS ?= debug-client $(DEBUG_ELFFILE)
RESET_FLAGS ?= reset

ifneq (,$(OPENOCD_DEBUG_ADAPTER))
Expand Down Expand Up @@ -44,7 +46,7 @@ ifneq (,$(OPENOCD_CMD_RESET_HALT))
$(call target-export-variables,flash-only,OPENOCD_CMD_RESET_HALT)
endif

OPENOCD_DEBUG_TARGETS = debug debugr debug-server
OPENOCD_DEBUG_TARGETS = debug debugr debug-server debug-client

ifneq (,$(OPENOCD_DBG_EXTRA_CMD))
# Export OPENOCD_DBG_EXTRA_CMD only to the flash/flash-only target
Expand Down

0 comments on commit c76a192

Please sign in to comment.