Skip to content

Instantly share code, notes, and snippets.

@rain1024
Last active May 23, 2022 09:13
Show Gist options
  • Save rain1024/7662afaca0dd77918a58b2797cf6438e to your computer and use it in GitHub Desktop.
Save rain1024/7662afaca0dd77918a58b2797cf6438e to your computer and use it in GitHub Desktop.
Debug C++ on Mac with Visual Studio Code

Debug C++ on Mac with Visual Studio Code

Requirements

Instructions

Step 1: Edit launch.json file

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "lldb launch",
      "type": "lldb",
      "request": "launch",
      "program": "${fileDirname}/${fileBasenameNoExtension}",
      "args": [],
      "preLaunchTask": "C/C++: clang++ build active file"
    }
  ]
}

Step 2: Edit tasks.json file

{
  // See https://go.microsoft.com/fwlink/?LinkId=733558
  // for the documentation about the tasks.json format
  "version": "2.0.0",
  "tasks": [
    {
      "type": "shell",
      "label": "C/C++: clang++ build active file",
      "command": "/usr/bin/clang++",
      "args": [
        "-std=c++17",
        "-stdlib=libc++",
        "-g",
        "${file}",
        "-o",
        "${fileDirname}/${fileBasenameNoExtension}"
      ],
      "options": {
        "cwd": "${workspaceFolder}"
      },
      "problemMatcher": ["$gcc"],
      "group": {
        "kind": "build",
        "isDefault": true
      },
      "detail": "Task generated by Debugger."
    }
  ]
}

References

(Deprecated) Debug C++ in Visual Studio Code

Warning: By following these steps, I still don't have vector pretty print

Step 1: Edit launch.json file

{
  // 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": "C/C++: clang++ build and debug active file",
      "type": "cppdbg",
      "request": "launch",
      "program": "${fileDirname}/${fileBasenameNoExtension}",
      "args": [],
      "stopAtEntry": true,
      "cwd": "${workspaceFolder}",
      "environment": [],
      "externalConsole": false,
      "MIMode": "lldb",
      "preLaunchTask": "C/C++: clang++ build active file"
    }
  ]
}

Step 2: Edit tasks.json file

{
  // See https://go.microsoft.com/fwlink/?LinkId=733558
  // for the documentation about the tasks.json format
  "version": "2.0.0",
  "tasks": [
    {
      "type": "shell",
      "label": "C/C++: clang++ build active file",
      "command": "/usr/bin/clang++",
      "args": [
        "-std=c++17",
        "-stdlib=libc++",
        "-g",
        "${file}",
        "-o",
        "${fileDirname}/${fileBasenameNoExtension}"
      ],
      "options": {
        "cwd": "${workspaceFolder}"
      },
      "problemMatcher": ["$gcc"],
      "group": {
        "kind": "build",
        "isDefault": true
      },
      "detail": "Task generated by Debugger."
    }
  ]
}

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment