Setting up GDB in VSCode (Windows Example)

Configuring GDB Debugging in VSCode

  1. In VSCode install the C/C++ extension( CTRL+SHIFT+P and choose Extensions: Install Extensions )

  2. In your project's top most directory create a folder and name it .vscode

  3. Create a file launch.json inside the .vscode folder

Image of VSCode Sidebar with Arrow Point To ".vscode".
  1. Open launch.json and add the following(replacing #...# sections with correct paths) :

    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit:
    "version": "0.2.0",
    "configurations": [
            "name": "(arm-none-eabi-gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "miDebuggerPath": #ABSOLUTLE/PATH/TO/DEBUGGER#, // e.g. "C:\\Program Files\\arm-none-eabi-gcc\\bin\\arm-none-eabi-gdb.exe"
            "targetArchitecture": "arm",
            "program": #PATH\TO\IMAGE\FILE(relative path ok)#, //e.g. "${workspaceFolder}/_build/app/app",
            "setupCommands": [
                {"text": "set remotetimeout 5"},
                {"text": "target remote localhost:3333"},
                {"text": "monitor reset halt"},
                {"text": #file ABSOLUTE\PATH\TO\IMAGE#, //e.g. "file C:\\Projects\\demo\\_build\\app\\app.elf"},
                {"text": "load"},
                {"text": "break main","ignoreFailures": true},
            "launchCompleteCommand": "None",
            "externalConsole": false,
            "cwd": "${workspaceFolder}",
Image of VSCode launch.json file.

Launching GDB Debugging in VSCode with Lager

  1. Plug device into Lager Gateway

  2. Connect to device, e.g. lager connect --device stm32f3x --interface stlink --transport hla_swd

  3. Start gdb server

~ lager gdbserver
Serving GDB on localhost:3333. Press Ctrl+C to quit.
  1. In VSCode launch debugger with CTRL + SHIFT + D

  2. Press F5 to begin debugging.

Image of VSCode + GDB Debug UI

Note: breakpoints set in the launch.json file (i.e. "text": "break main} will not be visible during debugging, but they ARE active. When one of these breakpoints is hit the Debugger will display it as "Exception has occurred." which is not an error.