Unable to debug vscode+ cortex-debug, though servertype": "external" works ok

#1247 · open · 5 comments

View on GitHub ↗

andre538-0

Hello guys, I'm trying to debug with vscode (1.131) + cortex-debug (1.13.0-pre9) +nuclei studio toolchain riscv64-unknown-elf (202510). Windows 10 pro as a host system, jtag probe connected with USB. Debug console has a lot of output, terminal console is _empty_ except "PS C:\1\gh\pnfm>" line. So there is no sense in "Please check TERMINAL tab (gdb-server) for output" message. Last line of debug console is ~~~ "Failed to launch jlink GDB Server: Error: connect ETIMEDOUT 127.0.0.1:55878" ~~~ Checked with netstat -aon | findstr ":55878" - there is a vscode process on this port, respawns in case of end task from task manager. ~~~ `Cortex-Debug: VSCode debugger extension version 1.13.0-pre9 git(d793ce2). Usage info: https://github.com/Marus/cortex-debug#usage INFO: A log of gdb-servers, gdb, debug adapter start/stop/pid info can be found in 'C:\Users\***\AppData\Local\Temp\cortex-debug-server.log'. "configuration": { "name": "Debug JLink", "type": "cortex-debug", "request": "launch", "cwd": "C:\\1\\gh\\pnfm", "executable": "C:/1/gh/pnfm/build/src/firmware_meter.elf", "serverpath": "C:\\Program Files\\SEGGER\\JLink_V762c\\JLinkGDBServerCL.exe", "runToEntryPoint": "main", "showDevDebugOutput": "raw", "servertype": "jlink", "interface": "jtag", "device": "CM32M4xxR", "gdbTarget": "127.0.0.1:50000", "serverArgs": [ "-log", "C:\\1\\gh\\pnfm/jlink_gdb_server.log" ], "toolchainPrefix": "riscv64-unknown-elf", "svdFile": "C:\\1\\gh\\pnfm/firmware/CM32M4xxR.svd", "preLaunchTask": "Build", "liveWatch": { "enabled": true, "samplesPerSecond": 5 }, "__configurationTarget": 6, "gdbServerConsolePort": 55878, "pvtAvoidPorts": [], "chainedConfigurations": { "enabled": false }, "debuggerArgs": [], "swoConfig": { "enabled": false, "decoders": [], "cpuFrequency": 0, "swoFrequency": 0, "source": "probe" }, "rttConfig": { "enabled": false, "decoders": [] }, "graphConfig": [], "preLaunchCommands": [], "postLaunchCommands": [], "preAttachCommands": [], "postAttachCommands": [], "preResetCommands": [], "postResetCommands": [], "overridePreEndSessionCommands": null, "postResetSessionCommands": null, "pvtAdapterDebugOptions": {}, "gdbPath": "C:/NucleiStudio/toolchain/gcc/bin/riscv64-unknown-elf-gdb.exe", "extensionPath": "c:/Users/***/.vscode/extensions/marus25.cortex-debug-1.13.0-pre9", "registerUseNaturalFormat": true, "variableUseNaturalFormat": true, "pvtVersion": "1.13.0-pre9", "__sessionId": "1f01b17c-2ed9-4038-ae4f-cf63cbaabfa0", "pvtShowDevDebugOutput": "raw" } Reading symbols from c:/nucleistudio/toolchain/gcc/bin/riscv64-unknown-elf-objdump.exe --syms -C -h -w C:/1/gh/pnfm/build/src/firmware_meter.elf Reading symbols from c:/nucleistudio/toolchain/gcc/bin/riscv64-unknown-elf-nm.exe --defined-only -S -l -C -p C:/1/gh/pnfm/build/src/firmware_meter.elf Launching GDB: "C:/NucleiStudio/toolchain/gcc/bin/riscv64-unknown-elf-gdb.exe" -q --interpreter=mi2 1-gdb-version Launching gdb-server: "C:\\Program Files\\SEGGER\\JLink_V762c\\JLinkGDBServerCL.exe" -singlerun -nogui -if jtag -port 50000 -swoport 50001 -telnetport 50002 -device CM32M4xxR -log "C:\\1\\gh\\pnfm/jlink_gdb_server.log" Please check TERMINAL tab (gdb-server) for output from C:\Program Files\SEGGER\JLink_V762c\JLinkGDBServerCL.exe Finished reading symbols from objdump: Time: 198 ms. File: C:/1/gh/pnfm/build/src/firmware_meter.elf -> =thread-group-added,id="i1" Finished reading symbols from nm: Time: 207 ms. File: C:/1/gh/pnfm/build/src/firmware_meter.elf -> ~"GNU gdb (GDB) 16.2.90.20250210-git\n" -> ~"Copyright (C) 2024 Free Software Foundation, Inc.\n" -> ~"License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\nThis is free software: you are free to change and redistribute it.\nThere is NO WARRANTY, to the extent permitted by law." -> ~"\nType \"" -> ~"show copying\" and \"show warranty\" for details.\n" -> ~"This GDB was configured as \"--host=x86_64-w64-mingw32 --target=riscv64-unknown-elf\".\n" -> ~"Type \"show configuration\" for configuration details.\n" -> ~"For bug reporting instructions, please see:\n" -> ~"<https://www.gnu.org/software/gdb/bugs/>.\n" -> ~"Find the GDB manual and other documentation resources online at:\n <" -> ~"http://www.gnu.org/software/gdb/documentation/>.\n\n" -> ~"For help, type \"help\".\n" -> ~"Type \"apropos word\" to search for commands related to \"word\".\n" -> 1^done 2-gdb-set mi-async on -> 2^done 3-interpreter-exec console "set print demangle on" -> 3^done 4-interpreter-exec console "set print asm-demangle on" -> =cmd-param-changed,param="print asm-demangle",value="on" -> 4^done 5-enable-pretty-printing -> 5^done 6-interpreter-exec console "source c:/Users/***/.vscode/extensions/marus25.cortex-debug-1.13.0-pre9/support/gdbsupport.init" -> =cmd-param-changed,param="language",value="c" -> =cmd-param-changed,param="language",value="auto" -> 6^done 7-interpreter-exec console "source c:/Users/***/.vscode/extensions/marus25.cortex-debug-1.13.0-pre9/support/gdb-swo.init" -> 7^done 8-interpreter-exec console "set output-radix 0xa" -> ~"Output radix now set to decimal 10, hex a, octal 12.\n" Output radix now set to decimal 10, hex a, octal 12. -> 8^done 9-interpreter-exec console "set input-radix 0xa" -> ~"Input radix now set to decimal 10, hex a, octal 12.\n" Input radix now set to decimal 10, hex a, octal 12. -> 9^done 10-file-exec-and-symbols "C:/1/gh/pnfm/build/src/firmware_meter.elf" -> 10^done Failed to launch jlink GDB Server: Error: connect ETIMEDOUT 127.0.0.1:55878 ~~~ At the same time starting manual launch as written in "Launching gdb-server: "C:\\Program Files\\SEGGER\\JLink_V762c\\JLinkGDBServerCL.exe" -singlerun -nogui -if jtag -port 50000 -swoport 50001 -telnetport 50002 -device CM32M4xxR -log " combined with "servertype": "external" works ok. Disabling Auto forwards Ports make no help for me. JLinkGDBServerCL.exe runs ok from command line. cortex-debug-server.log contains a lot of strings like ~~~ [2026-07-24T12:56:55.395Z] ppid=33652 pid=33652 Debug JLink: ******* Starting new session request type="launch" [2026-07-24T12:56:55.434Z] ppid=33652 pid=30028 GDB started ppid=33652 pid=30028 [2026-07-24T12:56:55.758Z] ppid=33652 pid=30028 GDBServer: Could not connect to console: Error: connect ETIMEDOUT 127.0.0.1:55878 [2026-07-24T12:56:55.771Z] ppid=33652 pid=30028 GDBServer(34940): forcing an exit with kill() [2026-07-24T12:56:55.777Z] ppid=33652 pid=30028 Debug JLink: Begin disconnectRequest [2026-07-24T12:56:55.788Z] ppid=33652 pid=30028 GDBServer(34940): exited code=null signal=SIGTERM [2026-07-24T12:56:57.855Z] ppid=33652 pid=30028 GDB: exited [2026-07-24T12:56:57.856Z] ppid=33652 pid=30028 Debug JLink: disconnectRequest sendResponse 1 [2026-07-24T12:56:57.867Z] ppid=33652 pid=30028 Debug JLink: quitEvent: sending VSCode TerminatedEvent [2026-07-24T12:57:39.719Z] ppid=33464 pid=33464 Debug JLink: ******* Starting new session request type="launch" [2026-07-24T12:57:39.758Z] ppid=33464 pid=29152 GDB started ppid=33464 pid=29152 [2026-07-24T12:57:40.076Z] ppid=33464 pid=29152 GDBServer: Could not connect to console: Error: connect ETIMEDOUT 127.0.0.1:55878 [2026-07-24T12:57:40.087Z] ppid=33464 pid=29152 GDBServer(33952): forcing an exit with kill() ~~~ Please help! Best regards, Andre

Comments

haneefdm

The overall process of getting the JLink server launch failed. JLink itself did not fail. What failed is our ability to create a VSCode window connection to display messages from JLink. Not sure how this can happen because we pick a free port at or after 55878. There is brief window of a few milliseconds between the time we figure out the port is free vs some one else claiming the port. Is this reproducible? You can have multiple VSCode windows and it still should not collide. Each VSCode gets its own tcp port for talking to the gdb server. Can you try it again with a fresh VSCode session?

haneefdm

There are two parts to our debugger. The front end and the back end. The back end runs in a different process as forced by VSCode, but it has to send messages to the frontend. The 55878 is the default port used to connect the two. Nothing to do with JLink or any other gdb-server.

haneefdm

Wondering if the frontend (the GUI part) was hung and unable to respond?

andre538-0

Yes, the whole situation itself is 100% reproducible ( at least at my PC )) ). I've restarted VS Code a lot of times, no sense. Also, I've asked sysadmin to check local firewall settings, and to run VScode as admin. No GUI response problems.

haneefdm

Yes, it could be the firewall, but if it is it could be very selective. VSCode runs a Node.JS process to launch the debug adapter (backend) using its own bundled Node.JS. If VSCode is running, I don't know if a firewall setting could even affect it. The is the code that is trying to connect to the frontend...and we know the frontend already is listening on 55878 https://github.com/Marus/cortex-debug/blob/428af021de7abe5a2522829af71a7422dabc9ead/src/backend/server.ts#L201 I hate to do this but do you have GitHub Copilot? Maybe it could diagnose the issue? I have never seen this situation before.