By Michael Hahsler
You need to have gdb
(GNU Project Debugger) installed.
- You may have to configure CMake for debugging by clicking in the status bar on
CMake: [Debug]
and selectDebug
. - Set a breakpoint (red dot) to the left of a line number in the source code.
- Click the debug symbol in the status bar which starts a frontend for
gdb
. - Use the navigation panel (appearing on the top of VS Code) and inspect and watch variables.
If you want to debug your program with the VS Code run button and command line arguments, then you can set the command line arguments in VS Code and CMake:
CTRL-SHIFT+P
typesettings.json
and choosePreferences: Open Work Space Settings
. This creates settings.json in the .vscode folder.- Add the following lines:
{ "cmake.debugConfig": { "args": [ "argument_1", "argument_2" ] } }
- Find the compiled executable (in VS Code it is in the build directory)
- Start
gdb executable
. - Set a breakpoint with
b
and userun
. See the GDB QUICK REFERENCE for available commands.
All code and documents in this repository are provided under Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) License.