最近刚考完试,有空来回复一下博客上的评论。在回复一条关于克鲁斯卡尔最短路径算法的评论时,为了能够让回复的内容更直观,决定贴上代码的调试信息(代码是用C写的)。我的电脑是MBP,没有安装XCode,只有Visual Studio Code,于是决定使用它来获取一些调试信息,但是我按照网上的教程配置好调试环境后,一直出现调试进程无法在我打的断点处停下的情况,一闪就过去了。度娘上面搜了好久也没有结果,最后在微软的官方教程上找到的端倪,原来这是Mac OS Catalina 10.15的BUG,也就是调试进程能够认到断点的存在,但是程序就直接运行完退出了。如下图所示:
上图中红框表明能够认到断点
上图中,退出代码为0,正常退出,没有在断点处暂停。
我的设备环境是
- Mac os Catalina 10.15.2
- Visual Studio Code 1.14.1
解决的办法也很简单,在VSCode的插件中心搜索CodeLLB
的插件安装,重启VSCode即可。
Step1:按住键盘上的⌘ +⇧+P,搜索Debug: Open launch.json
或者点击左边的小虫子,选择create a launch.json file
。
Step2:选择LLDB
Step3:编写基础配置文件
{
// 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": "${workspaceFolder}/${fileBasenameNoExtension}.out",
"args": [],
"cwd": "${workspaceFolder}"
}
]
{
"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": "${default}"
}
],
"version": 4
}
{
// 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": "${workspaceFolder}/${fileBasenameNoExtension}.out",
"args": [],
"cwd": "${workspaceFolder}"
}
]
}
{
"version": "2.0.0",
"tasks": [
{
"label": "Build with Clang",
"type": "shell",
"command": "clang++",
"args": [
"-std=c++17",
"-stdlib=libc++",
"${file}",
"-o",
"${fileBasenameNoExtension}.out",
"--debug"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
- Using Clang in Visual Studio Code
- Can’t debug on macOS Catalina (LLDB) #3829
- vscode-lldb