解决Mac OS Catalina下Visual Studio Code对于C/C++语言不能断点调试的问题

背景

最近刚考完试,有空来回复一下博客上的评论。在回复一条关于克鲁斯卡尔最短路径算法的评论时,为了能够让回复的内容更直观,决定贴上代码的调试信息(代码是用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}"
        }
    ]

Step4 :保存配置后++B编译后即可断点调试
在这里插入图片描述

配置文件文件分享

最后分享一下我的配置文件,希望能帮助到大家

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": "${default}"
        }
    ],
    "version": 4
}

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": "${workspaceFolder}/${fileBasenameNoExtension}.out",
            "args": [],
            "cwd": "${workspaceFolder}"
        }
    ]
}

tasks.json

{
    "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
        }
      }
    ]
  }

参考资料

  • 5
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值