Mac VSCode CodeLLDB Debug C++配置

在macOS上配置Visual Studio 以使用Clang/LLVM编译器和调试器

一.Needed extension:

C/C++

请添加图片描述

C/C++ Extension Pack

请添加图片描述

clang

请添加图片描述

CodeLLDB

请添加图片描述CodeLLDB首次启动时自动安装codelldb-x86_64-darwin.vsix(访问外网)

请等待它安装完成,安装失败将无法调试

二.Add configuration of C++

  • 第一次运行c++程序时,C++扩展将创建tasks.json

在这里插入图片描述

tasks.json:

{
  "version": "2.0.0",
  "tasks": [
    {
      "type": "shell",
      "label": "C/C++: 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
      },
      "detail": "Task generated by Debugger."
    }
  ]
}

三.Add configuration of debug

请添加图片描述

请添加图片描述
点击调试图标后进行设置

  • 第一次点开将提示添加配置,VS Code将创建一个launch.json文件

launch.json:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "C/C++: clang++ build and debug active file",
      "type": "cppdbg",
      "request": "launch",
      "program": "${fileDirname}/${fileBasenameNoExtension}",
      "args": [],
      "stopAtEntry": true,
      "cwd": "${workspaceFolder}",
      "environment": [],
      "externalConsole": false,
      "MIMode": "lldb",
      "preLaunchTask": "C/C++: clang++ build active file"
    }
  ]
}
Visual Studio Code (VSCode) 是一款非常流行的轻量级代码编辑器,它支持广泛的编程语言,包括C语言调试。要在VSCode中调试C程序,你需要安装C/C++相关的插件如 "ms-vscode.cpptools" 或 "CodeLLDB",并按照以下步骤操作: 1. 安装插件:打开VSCode扩展市场,搜索并安装适合C/C++的调试工具插件。 2. 配置任务:在VSCode的用户目录下创建一个名为`.vscode`的文件夹,然后在其中创建`tasks.json`文件,配置编译和运行命令。 ```json { "version": "2.0.0", "tasks": [ { "label": "build-c", "type": "shell", "command": "gcc", "args": ["${file}", "-o", "${fileDirname}/${fileBasenameNoExtension}"], "problemMatcher": [] }, { "label": "run-c", "type": "shell", "command": "./${fileBasenameNoExtension}", "group": { "kind": "build", "isDefault": true } } ] } ``` 3. 设置调试配置:在`.vscode`文件夹中,添加`launch.json`文件,配置调试启动选项。这通常涉及到设置`program`, `args`等属性。 ```json { "version": "0.2.0", "configurations": [ { "name": "(gdb) Launch", "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/a.out", // 替换为你的可执行文件路径 "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "preLaunchTask": "build-c", "miDebuggerPath": "/usr/bin/gdb", // 如果你的系统是Linux,这里可能是"/usr/bin/lldb"(如果是Mac) "MIMode": "gdb", "setupCommands": [ { "description": "Enable pretty-enable-pretty-printing", "ignoreFailures": true } ], "console": "integratedTerminal" } ] } ``` 4. 调试:在源代码中设置断点,点击左上角的“Debug”图标,选择对应的配置,然后点击绿色的三角形开始调试。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值