The following steps have already been done for you in this project. You may need to do this in future projects.
How to setup VSCode to work with Makefiles and gdb.
Microsoft Documents
https://code.visualstudio.com/docs/cpp/cpp-debug
https://code.visualstudio.com/docs/cpp/launch-json-reference
Set tabs to 2:
File | Preferences | Settings Search for tabs in the search box.
Set tab size to 2
Make sure you have User selected to set this for all projects on this machine.
Make sure the C/C++ for Visual Studio Code extension from Microsoft is installed. https://github.com/microsoft/vscode-cpptools
Choose the Debug Icon (above) and select "Create a launch.json file" then "Default configuration"
Edit launch.json to contain:
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/bin/simpleCProgram", # THIS IS IMPORTANT
"args": [],
"stopAtEntry": true, # THIS IS IMPORTANT
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "runMake", # THIS IS IMPORTANT
}
]
Terminal | Configure Default Build Task | Create tasks.json from template | Others
Edit tasks.json to contain:
{
"type": "cppbuild",
"label": "runMake",
"command": "/usr/bin/make",
"args": [ ],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by me."
}
Save all .json files.
Control-Shift-B will run the Default Build Command (runMake from above!)
Run/Debugger icon: (bug, triangle) press green triangle at top "(gdb) Launch".
Hit "run to next break point" (blue triangle with line)
Ouput shows up in terminal.
Open launch.json (found in .vscode directory) Click Add Configuration (Blue Button) C/C++: (gdb) Launch
Edit to look like:
{
"name": "(gdb) Launch with args", // Change name
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/bin/simpleCProgram", // THIS IS IMPORTANT
"args": ["CS360"], // add comma separated list of args here.
"stopAtEntry": true, // THIS IS IMPORTANT
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "runMake", // THIS IS IMPORTANT
},
Run/Debugger icon: (bug, triangle) press drop down arrow near green triangle at top to select: "(gdb) Launch with args".
Press green arrow
Hit "run to next break point" (blue triangle with line)
Ouput shows up in terminal.



