首先要了解,配置文件仅仅对当前的工作区有效(工作区是一个.code_workspace的文件)
因此一般不同的语言环境的相应文件夹会存放在不同的工作区中
本次配置的debug环境 需要用到的拓展:c/c++ extension, CodeLLDB
mac安装LLDB需要用到vsic文件直接载入
配置文件:
c_cpp_properties.json
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"macFrameworkPath": [
"/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "Build with Clang",
"type": "shell",
"command": "clang++",
"args": [
"${file}",
"-std=c++11",
"-o",
"${fileDirname}/${fileBasenameNoExtension}.out",
"-g",
"--debug"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
launch.json
{
// 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": [
{
"type": "lldb",
"request": "launch",
"name": "Debug",
"program": "${fileDirname}/${fileBasenameNoExtension}.out",
"args": [],
"cwd": "${workspaceFolder}"
}
]
}
接着,就可以进行test了
以下面程序为例:
#include <iostream>
int main()
{
for(int i=0;i<5;i++){
std::cout<<"hey you"<<std::endl;
}
return 0;
}
在 for 行设置断点

如图所示
本文档详细介绍了如何在Visual Studio Code(VSCode)中配置C++的调试环境,包括安装必要的扩展如c/c++ extension和CodeLLDB,以及编辑c_cpp_properties.json、tasks.json和launch.json文件。通过配置,可以在Mac环境下使用LLDB进行调试,并针对一个简单的C++程序展示了如何设置断点并进行测试。
1023

被折叠的 条评论
为什么被折叠?



