From c76a192eb8edb4d4c874c91dbeecfb73240c4048 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20H=C3=BC=C3=9Fler?= Date: Sat, 10 Jun 2023 00:05:35 +0200 Subject: [PATCH] openocd: support target debug-client --- dist/tools/openocd/openocd.sh | 35 ++++++++++++++++++++++++---------- makefiles/tools/openocd.inc.mk | 4 +++- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/dist/tools/openocd/openocd.sh b/dist/tools/openocd/openocd.sh index 1bd5d09a3e..6660004a3d 100755 --- a/dist/tools/openocd/openocd.sh +++ b/dist/tools/openocd/openocd.sh @@ -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 +# 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 # debug given file on the target but flash it first directly @@ -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 @@ -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() { @@ -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 diff --git a/makefiles/tools/openocd.inc.mk b/makefiles/tools/openocd.inc.mk index b5d3e36244..4a7a3aa8bc 100644 --- a/makefiles/tools/openocd.inc.mk +++ b/makefiles/tools/openocd.inc.mk @@ -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)) @@ -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