10

I'm developing applications on a Cortex-M3 microcontroller (STM32 family). I'm trying to use Visual Studio Code as the debugger interface, with a ST-Link v2 JTAG probe. I managed to configure OpenOCD to talk to my device, and VSCode to run a local GDB and connect to OpenOCD.

Now I'd like to have VSCode start OpenOCD at the same time as GDB when I start debugging. I have the following launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Pipe Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/path/to/program.elf",
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}/gcc-arm-none-eabi",
            "environment": [],
            "externalConsole": true,
            "pipeTransport": {
                "pipeProgram": "X:\\path\\to\\openocd-0.10.0\\bin-x64\\openocd.exe",
                "pipeArgs": ["-f", "vscode.ocd"],
                "pipeCwd": "${workspaceFolder}"
            },
            "MIMode": "gdb"
        },
        { 
            "name": "(gdb) Attach",
            "type": "cppdbg",
            "request": "launch",
            "cwd": "${workspaceFolder}/gcc-arm-none-eabi",
            "program": "${workspaceFolder}/path/to/program.elf",
            "MIMode": "gdb",
            "targetArchitecture": "arm",
            "miDebuggerPath": "X:\\path\\to\\gcc-arm-none-eabi-4_8-2014q2-20140609-win32\\bin\\arm-none-eabi-gdb.exe",
            "miDebuggerServerAddress": "127.0.0.1:3333"
        }
    ]
}

And my vscode.ocd file is as follow:

source [find interface/stlink-v2.cfg]
transport select "hla_swd"
source stm32l1.cfg

stm32l1.cpu configure -event gdb-attach halt
stm32l1.cpu configure -event gdb-detach resume

gdb_port pipe
log_output openocd.log

When I start OpenOCD manually (without "gdb_port pipe") and then run the configuration "(gdb) Attach", all is fine.

But when I run the "(gdb) Pipe Launch" configuration, VSCode starts openocd.exe, and then nothing happens. When I kill the openocd.exe process, I get a popup in VSCode which says "Unable to start debugging. Unable to establish a connection to GDB. The following message was written to stderr:" followed by some OpenOCD stderr.

I can also run GDB on its own in the command line with the following .gdbinit just fine:

target remote | openocd -f path/tovscode.ocd
sym path/to/program.elf

So my question is is there a way to have VSCode talk to OpenOCD's GDB server directly? Otherwise if I need to use some local arm-none-eabi-gdb.exe file, how can I configure VSCode to have it tell GDB to use a pipe ("target remote | something") remote?

Doub
  • 1,222
  • 1
  • 8
  • 15
  • I have a similar problem. I start an emulator with a GDB interface and try to connect. VSC always tells me it couldn't connect. Did you find a solution? – Bim Apr 16 '19 at 15:10
  • No, not really. I gave up and went back to using Visual Studio for editing and Ozone for the occasional debugging. – Doub Apr 17 '19 at 17:25

0 Answers0