简体   繁体   English

如何在 MacOS 上将 gdb 设置为 C/C++ 扩展 pf VSCode 的调试器?

[英]How to set gdb as debugger for the C/C++ extension pf VSCode on MacOS?

the C/C++ Extension of Microsoft for VSCode allows to set a launch.json file with which you can set how to debug and run your C++ code. Microsoft 的 C/C++ Extension for VSCode 允许设置launch.json文件,您可以使用该文件设置如何调试和运行 C++ 代码。 By default it has lldb as debugger for MacOS.默认情况下,它具有 lldb 作为 MacOS 的调试器。

I wonder how to set gdb as debugger instead of lldb.我想知道如何将 gdb 设置为调试器而不是 lldb。

I tried and it shows me:我试过了,它告诉我:

Unable to start debugging.无法开始调试。 GDB exited unexpectedly with exit code 134 (0x86). GDB 意外退出,退出代码为 134 (0x86)。

This is how my launch.json file looks like:这就是我的launch.json文件的样子:

 { "version": "0.2.0", "configurations": [ { "name": "g++-9 - Build and debug active file", "type": "cppdbg", "request": "launch", "program": "${fileDirname}/${fileBasenameNoExtension}", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": true, "osx": { "miDebuggerPath": "/usr/local/bin/gdb", "MIMode": "gdb" }, "preLaunchTask": "C/C++: g++-9 build active file" } ] }

Make sure you have gdb installed.确保您已安装gdb For that you can use:为此,您可以使用:

brew install gdb

Then make the gdb binary is certified.然后使gdb二进制被认证。 Because:因为:

... modern Darwin kernels restrict the capability to assume control over another process (here, for the purpose of debugging it), since that capability is a boon to malware. ...现代达尔文内核限制了控制另一个进程的能力(这里是为了调试它),因为这种能力是恶意软件的福音。 In order for said taskgated to grant access to gdb, the latter must be fitted with entitlements, which consist of digitally-signed metadata inside the gdb binary.为了让上述任务门授予对 gdb 的访问权限,后者必须配备权利,其中包括 gdb 二进制文件中的数字签名元数据。

From: https://sourceware.org/gdb/wiki/PermissionsDarwin来自: https://sourceware.org/gdb/wiki/PermissionsDarwin

To create a certification follow these instructions: https://sourceware.org/gdb/wiki/PermissionsDarwin要创建认证,请遵循以下说明: https://sourceware.org/gdb/wiki/PermissionsDarwin

After doing so, certify the binary as instructed here .完成后,按照此处的说明验证二进制文件。

Then try this for launch.json :然后试试这个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": [
        {
            "name": "g++ - Build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "preLaunchTask": "C/C++: g++ build active file"
        }
    ]
 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM