最近发现 MacOS Catalina 的 Visual Studio Code 不能调试 C++ 了,翻遍了国内各种资料各种方法无效,不得已准备去啃官方网站的说明,发现这个

https://code.visualstudio.com/docs/cpp/launch-json-reference#_externalconsole
https://code.visualstudio.com/docs/cpp/launch-json-reference#_externalconsole
,原来 xcode 更新之后已经不提供 lldb-mi 了,所以 externalConsole 那个配置项即便为 True 也是无效的,仅仅能打开个 Terminal 但是无法执行程序,解决方法如下:安装 CodeLLDB 插件,然后使用其提供的 launch 配置文件即可。

附:tasks.json 和 launch.json

tasks.json

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "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
}
}
]
}

launch.json , 注意其中的 type 参数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
{
// 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": "clang++ - Build and debug active file",
"type": "lldb",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": ["-arg1", "-arg2"],
"cwd": "${workspaceFolder}",
"preLaunchTask": "clang++ build active file"
}
]
}