Skip to content

Instantly share code, notes, and snippets.

@hoanganh25991
Last active October 5, 2020 23:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hoanganh25991/9ce116867fa37694fe75cff84b87b901 to your computer and use it in GitHub Desktop.
Save hoanganh25991/9ce116867fa37694fe75cff84b87b901 to your computer and use it in GitHub Desktop.

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

Copy launch.json, task.json to .vscode directory

  • 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

{
// 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"
}
]
}
{
"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"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment