VSCode Debugger
C++ Debugging (Apple Silicon)
Required extensions:
ms-vscode.cpptools
vadimcn.vscode-lldb
Wiil be using lldb debugger.
In your .vscode directory, ultimately three files will be created:
c_cpp_properties.json # Compiler path, etc.
launch.json # CLI arguments, etc.
tasks.json # Pre-build and post-build tasks go here
Compiler Configuration
Open Command Palette and search for C/C++: Edit Configurations (JSON). Default settings will be created in c_cpp_properties.json.
Some things you often want to change:
compilerPath: Default is/usr/bin/clang, but you could change it to/usr/bin/g++, etc.cppStandard: Default isc++17, but you could change it toc++11, etc.
Example `c_cpp_properties.json`
{
"configurations": [
{
"name": "Mac",
"includePath": ["${workspaceFolder}/**"],
"defines": [],
"macFrameworkPath": [
"/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"
],
"compilerPath": "/usr/bin/g++",
"cStandard": "c17",
"cppStandard": "c++11",
"intelliSenseMode": "macos-clang-arm64"
}
],
"version": 4
}
Debug Configuration
Open Command Palette and search for C/C++: Add Debug Configuration.
Select whichever compiler you are using, and the basic prebuild tasks and launch configurations will be created.
Tasks
In tasks.json, you can add pre-build and post-build tasks.
Some things you often want to change:
label: Task name, if you’re adding multiple tasks- This value is referenced in
launch.json
- This value is referenced in
args: Compiler argumentsRemoving
${file}and replace with${fileDirname}/*.cpp, so that all.cppfiles in the directory are compiled (useful for debugging)If you do not remove
${file}, the compiler will complain about multiple definitions.Adding
-std=c++11, etc. to enforce a specific C++ standard
Example `tasks.json`
{
"tasks": [
{
"type": "cppbuild",
"label": "Build all files in directory",
"command": "/usr/bin/g++",
"args": [
"-fdiagnostics-color=always",
"-g",
"${fileDirname}/*.cpp",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
"-std=c++11",
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
Launch
You need to set the debugger type to lldb in launch.json.
{
...
"type": "lldb",
...
}
With lldb, remove the unsupported options:
These unsupported options will be highlighted yellow.
stopAtEntryenvironmentexternalConsoleMIMode
Some things you often want to change:
name: To remind yourself what this configuration is fortype:lldbprogram: Path to the binary fileIf you modified the output binary name in
tasks.json, you need to change theprograminlaunch.jsonto match.preLaunchTask: The task name intasks.jsonIf you modified the
labelintasks.json, you need to change thepreLaunchTaskinlaunch.jsonto match.
Example `launch.json`
{
"configurations": [
{
"name": "Lets' Debug!",
"type": "lldb",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"cwd": "${fileDirname}",
"preLaunchTask": "Build all files in directory",
}
],
"version": "2.0.0"
}
References: