Skip to content

Instantly share code, notes, and snippets.

@levihuayuzhang
Created December 31, 2022 23:47
Show Gist options
  • Save levihuayuzhang/ea821f903913c438049e223e04e6f18d to your computer and use it in GitHub Desktop.
Save levihuayuzhang/ea821f903913c438049e223e04e6f18d to your computer and use it in GitHub Desktop.
MacOS VS Code Debug using CMake extension (Pressing F5)

When I want to use CMake extention of VS Code in MacOS to debug program using LLDB, it requre some set up to use F5 button.

  1. Install VS Code, LLVM, CMAKE and C/C++ extensions.
  1. tasks.json:
{
   "version": "2.0.0",
   "tasks": [
       {
           "label": "build",
           "type": "shell",
           "command": "{cmake.debugTarget}",
           "options": {
               "cwd": "${workspaceFolder}/build"
           },
           "group": {
               "kind": "build",
               "isDefault": true
           }
       }
   ]
}
  1. launch.json:
{
   "version": "0.2.0",
   "configurations": [
       {
           "name": "MacOS Cmake LLDB",
           "type": "cppdbg",
           "request": "launch",
           "preLaunchTask": "build",
           "args": [],
           "stopAtEntry": false,
           "program": "${command:cmake.launchTargetPath}",
           "MIMode": "lldb",
           "miDebuggerPath": "/usr/local/bin/lldb-mi",
           "cwd": "${workspaceFolder}/build"
       }
   ]
}
  1. settings.json:
{
   "C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools"
}

References:

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