JLinkGDBServer graceful shutdown?

Hi,

Debugging a NRF52 target using PIO Unified Debugger and a JLink V9 / EDU probe on Linux. Starting a debug session works great the first time, but I click the “Stop Debugging” button the JLinkGDBServer is killed and the JLink HW probe is left in a “bad” state. Any future attempts to start a debug session will fail with this error:

Connecting to target…ERROR: Communication timed out: Requested 8 bytes, received 0 bytes !
ERROR: Could not transfer JTAG data.
ERROR: Could not connect to target.
Target connection failed. GDBServer will be closed…
.pioinit:11: Error in sourced command file:
Remote communication error. Target disconnected.: Connection reset by peer.

The only way to recover is to power cycle the JLink. This has been reported before here: [SOLVED] J-Link is low on memory - J-Link/Flasher related - SEGGER - Forum

As a workaround, I use “pkill JLinkGDBServer” outside of PIO before clicking the “Stop Debugging” button. Then the JLink hardware is de-initialized properly and it is possible to start a new debug session.

Please advice.

Thank you so much that reported this issue. I don’t have J-Link but would be glad if you help to resolve this issue. Could you run this command before pressing “Stop”? Please open “DEBUG CONSOLE” in VSCode and type at the bottom input

monitor q

Now, press stop. You can play with J-Link commands via monitor xxx, see a list here https://www.segger.com/downloads/jlink/UM08001

Output in Debug Console:

monitor q
Target does not support this command. (from interpreter-exec console “monitor q”)
WARNING: Unsupported remote command “q”
Target does not support this command.
monitor
{“token”:2822,“outOfBandRecord”:,“resultRecords”:{“resultClass”:“done”,“results”:}}
SEGGER J-Link GDB Server V6.34h

Available remote commands are:

cp15 clrbp ci clrwp
cd device flash device endian
ExcludeFlashCacheRange flash breakpoints flash cpuclock flash download
getargs go halt IsHalted
interface if jtagconf loadbin
rtos MemU16 WriteU16 MemU32
WriteU32 mww long MemU8
WriteU8 reg regs remoteport
port reset STRACE Config STRACE Read
STRACE Start STRACE Stop SWO DisableTarget SWO EnableTarget
SWO GetMaxSpeed SWO GetSpeedInfo SWOSpeed SWO Start
SWO Stop select semihosting ARMSWI semihosting disable
semihosting enable semihosting IOClient semihosting BreakOnError semihosting ThumbSWI
setargs setbp bi WriteDP
WriteAP ReadDP ReadAP bdh
bd bdb sleep speed
step si waithalt wh
wice rmib

Could you try to type just quit?

quit
Canceled
A debugging session is active.
Inferior 1 [Remote target] will be killed.
Quit anyway?
(y or n) [answered Y; input not from terminal]
GDB closed TCP/IP connection

Yes. Quit works properly, thank you! Please let me know how to make the change so that clicking the “Stop Debugging” button sends a “quit” command instead of killing the GDBServer.

Could you try this beta version of our debugging frontend?

  1. Download and unzip https://www.dropbox.com/s/77panjmzrswl2i0/platformio-ide-1.4.2-beta.1.vsix.zip?dl=1
  2. VSCode > View > Command Palette > Install from VSIX
  3. Restart VSCode after installation.

Does it work better now?

Nope. Same problem.
Getting this when clicking Stop Debugging:

pio_reset_target
Warning! Undefined pio_reset_target command
Cannot execute this command while the target is running.
Use the “interrupt” command to stop the target
and then try again.
Cannot execute this command while the target is running.
Use the “interrupt” command to stop the target
and then try again.
Cannot execute this command while the target is running.
Use the “interrupt” command to stop the target
and then try again.

Followed by:

Connecting to target…ERROR: Could not connect to target.
Target connection failed. GDBServer will be closed…
.pioinit:11: Error in sourced command file:
Remote communication error. Target disconnected.: Connection reset by peer.

When trying to debug again. Power cycle JLink is required.

Please file an issue here Issues · platformio/platformio-vscode-ide · GitHub

We will investigate this issue in details ASAP.