在 Eclipse 中进行 C++ 调试的 macOS 10.15 Catalina gdb 问题

macOS 10.15 Catalina gdb problem for C++ Debugging in Eclipse

我正在使用 macOS 10.15.2 Catalina 并尝试在 Eclipse 中调试 Hello World C++ 程序。 我已经通过从 Homebrew 安装 gdb 调试器并按照下面 link.

中的过程签署证书来设置它

https://www.thomasvitale.com/how-to-setup-gdb-and-eclipse-to-debug-c-files-on-macos-sierra/

调试器没有启动。

我已经在 Eclipse 中设置了 gdb 设置,如下面的屏幕截图所示。

当我调试项目时,出现错误:Configuring GDB Aborting configuring GDB(下面也提供了它的截图)。

您使用的是哪个版本的 gdb 和 Eclipse?

我将尝试提及我过去遇到问题的一些方面。

  1. 如果您使用 Homebrew 安装 gdb,请尝试将 "GDB debugger" 字段设置为实际路径,例如 /usr/local/Cellar/gdb/8.3/bin/gdb 而不是 link /usr/local/bin/gdb.

  2. 您的 .gdbinit 文件位于何处?在本教程中,它位于用户主文件夹中,因此在 Eclipse 调试配置中,GDB 命令文件设置为 ~/.gdbinit。您屏幕截图中的值未指定绝对路径,它可能在错误的位置查找它。

  3. 您的 gdb 证书是系统钥匙串(而不是登录钥匙串)的一部分吗?在签名期间,您是否将权利文件作为参数传递?

我遇到了类似的问题,我不得不执行两个步骤来解决它。我不确定是否需要它们:

  1. 确保您的调试配置具有指向 .gdbinit 的绝对路径。您的用户文件夹中需要有一个包含以下内容的 .gdbinit 文件:
set startup-with-shell off

我在 eclipse 中的调试配置指向这个文件,但直到我将路径更改为绝对路径后它才读取它。

  1. 使用本指南中的额外权利设置权限:https://www.thomasvitale.com/how-to-setup-gdb-and-eclipse-to-debug-c-files-on-macos-sierra/

创建一个包含以下内容的 gdb-entitlement.xml 文件:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
    "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
        <key>com.apple.security.cs.allow-jit</key>
        <true/>
        <key>com.apple.security.cs.allow-unsigned-executable-memory</key>
        <true/>
        <key>com.apple.security.cs.allow-dyld-environment-variables</key>
        <true/>
        <key>com.apple.security.cs.disable-library-validation</key>
        <true/>
        <key>com.apple.security.cs.disable-executable-page-protection</key>
        <true/>
        <key>com.apple.security.cs.debugger</key>
        <true/>
        <key>com.apple.security.get-task-allow</key>
        <true/>
    </dict>
    </plist>

然后,打开终端提示符,转到保存 xml 文件的目录,然后 运行:

codesign --entitlements gdb-entitlement.xml -fs gdb-cert $(which gdb)

其中 "gdb-cert" 是您之前为代码签名创建的证书。 在完成这些步骤并在 Eclipse 上正确设置 GDB 路径后,调试再次成功。