Setting up GDB in VSCode (Windows Example)
Configuring GDB Debugging in VSCode
In VSCode install the
C/C++
extension(CTRL+SHIFT+P
and chooseExtensions: Install Extensions
)In your project's top most directory create a folder and name it
.vscode
Create a file
launch.json
inside the.vscode
folder
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: https://go.microsoft.com/fwlink/?linkid=830387
"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}",
}
]
}
Launching GDB Debugging in VSCode with Lager
Plug device into Lager Gateway
Connect to device, e.g.
lager connect --device stm32f3x --interface stlink --transport hla_swd
Start gdb server
~ lager gdbserver
Serving GDB on localhost:3333. Press Ctrl+C to quit.
In VSCode launch debugger with
CTRL + SHIFT + D
Press
F5
to begin debugging.
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.