Skip to content

Instantly share code, notes, and snippets.

@neilsong
Last active September 12, 2023 19:37
Show Gist options
  • Select an option

  • Save neilsong/25c07cdeff247c2381c2910a3be96264 to your computer and use it in GitHub Desktop.

Select an option

Save neilsong/25c07cdeff247c2381c2910a3be96264 to your computer and use it in GitHub Desktop.
VSCode Integrated C Build + Debug (with Makefile)

Goal

Build and debug a Make project in VSCode's integrated debugger with the press of a single button.

Procedure

  1. Create folder .vscode.
  2. Create files launch.json and tasks.json as defined in this gist.
  3. Make sure your Makefile is properly configured (change build targets by changing "command" in tasks.json).
  4. Replace [EXECUTABLE_NAME] in launch.json with your output executable.
  5. Define any executable arguments inside args.
  6. Press F5 to begin building and debugging.
{
// 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": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceRoot}/[EXECUTABLE_NAME]",
"args": [
"[ARG1]",
"[ARG2]"
],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
],
"preLaunchTask": "Build",
}
]
}
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Build",
"type": "shell",
"command": "make",
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": {
"owner": "c",
"fileLocation": [
"relative",
"${workspaceFolder}"
],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment