Debug C
- Install VS Code
- Enable C/C++ extensions
- Copy
launch.json
,task.json
to.vscode
directory - Run debug for
giftcardreader.c
Install VS Code
Please download and install VS Code from https://code.visualstudio.com/download
Enable C/C++ extensions
C/C++ default installed in VS Code, please cross check if extension enabled
launch.json
, task.json
to .vscode
directory
Copy - Create
.vscode
in source code directory - Copy
launch.json
,task.json
to.vscode
launch.json
- Define run debug for active file
- Update args (arguments) in your case
{
// 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": "gcc - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": ["1", "examplefile.gft"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb",
"preLaunchTask": "C/C++: gcc build active file"
}
]
}
task.json
- Define how to build with gcc
{
"tasks": [
{
"type": "shell",
"label": "C/C++: gcc build active file",
"command": "/usr/bin/gcc",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
],
"version": "2.0.0"
}
Files copied in .vscode
directory
Run debug for giftcardreader.c
- Open file:
giftcardreader.c
- Set breaking point at line
- Press
Ctrl+Shift+P
to show all command - Type
debug
to search for C debug - Choose
C/C++ Build and Debug active file
- Choose compiler
gcc
- Press Enter to start debug