如何在 Mac OSX El Capitan 中安装 gdb(调试器)? [英] How to install gdb (debugger) in Mac OSX El Capitan?

查看:12
本文介绍了如何在 Mac OSX El Capitan 中安装 gdb(调试器)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 Mac OSX El Capitan 中安装 gdb(调试器)?我曾尝试安装 gdb,但失败了几次.

How to install gdb (debugger) in Mac OSX El Capitan ? I have tried installing gdb but failed couple of time.

我关注的是这个网址:http://ntraft.com/installing-gdb-on-os-x-mavericks/ ,MAC 不允许安装 MacPorts.

I was following this URL : http://ntraft.com/installing-gdb-on-os-x-mavericks/ , MAC doesnot allow to install MacPorts.

有人可以在这方面帮助我吗?

Could anyone please help me in this regard.

推荐答案

请注意,此答案是为 Mac OS El Capitan 编写的.对于较新的版本,请注意它可能不再适用.特别是,遗留选项很可能已被弃用.

这个问题有两种解决方案,在这个问题的其他答案和 How to get gdb to work using macports under OSX 10.11 El Capitan?,但为了澄清一些困惑,这里是我的总结(作为答案,因为评论有点长):

There are two solutions to the problem, and they are both mentioned in other answers to this question and to How to get gdb to work using macports under OSX 10.11 El Capitan?, but to clear up some confusion here is my summary (as an answer since it got a bit long for a comment):

我猜哪种选择更安全,归结为 1) 信任自签名证书和 2) 为用户提供更多权限之间的选择.

Which alternative is more secure I guess boils down to the choice between 1) trusting self-signed certificates and 2) giving users more privileges.

如果使用签名替代,则不需要禁用 SIP 以将 -p 选项添加到 taskgated.

If the signature alternative is used, disabling SIP to add the -p option to taskgated is not required.

然而,请注意,使用此替代方法,调试只允许 _developer 中的用户使用.

However, note that with this alternative, debugging is only allowed for users in the _developer group.

使用 codesign 使用名为 gdb-cert 的证书进行签名:

Using codesign to sign using a cert named gdb-cert:

codesign -s gdb-cert/opt/local/bin/ggdb

(使用MacPorts标准路径,按需采用)

(using the MacPorts standard path, adopt as necessary)

有关详细的代码签名配方(包括证书创建),请参阅:https://gcc.gnu.org/onlinedocs/gcc-4.8.1/gnat_ugn_unw/Codesigning-the-Debugger.htmlhttps://sourceware.org/gdb/wiki/BuildingOnDarwin

For detailed code-signing recipes (incl cert creation), see : https://gcc.gnu.org/onlinedocs/gcc-4.8.1/gnat_ugn_unw/Codesigning-the-Debugger.html or https://sourceware.org/gdb/wiki/BuildingOnDarwin

请注意,您需要在过程期间和之后重新启动钥匙串应用程序和任务门控服务(最简单的方法是重新启动).

Note that you need to restart the keychain application and the taskgated service during and after the process (the easiest way is to reboot).

根据@user14241 的回答,禁用 SIP 并将 -p 选项添加到 taskgated 是一个选项.请注意,如果使用此选项,不需要对二进制文件进行签名,并且它还会绕过用于验证作为开发人员工具组 (_developer) 成员的对话框.

As per the answer by @user14241, disabling SIP and adding the -p option to taskgated is an option. Note that if using this option, signing the binary is not needed, and it also bypasses the dialog for authenticating as a member of the Developer Tools group (_developer).

将 -p 选项(允许组 procmod 和 procview)添加到 taskgated 后,您还需要将应允许使用 gdb 的用户添加到 procmod 组.

After adding the -p option (allow groups procmod and procview) to taskgated you also need to add the users that should be allowed to use gdb to the procmod group.

配方是:

  1. 在recovery模式下重启,打开终端运行csrutil disable

重启机器并编辑/System/Library/LaunchDaemons/com.apple.taskgated.plist,添加-p 选项:

restart machine and edit /System/Library/LaunchDaemons/com.apple.taskgated.plist, adding the -p opion:

<array>
    <string>/usr/libexec/taskgated</string>
    <string>-sp</string>
</array>

  • 在恢复模式下重启以重新启用 SIP (csrutil enable)

    重启机器并将用户USERNAME添加到组procmod:

    restart machine and add user USERNAME to the group procmod:

    sudo dseditgroup -o edit -a USERNAME -t user procmod

    不涉及将用户添加到组的替代方法制作可执行的 setgid procmod,因为这也会制作 procmod 执行 setgid 二进制文件的任何用户的有效组 ID(建议在 https://apple.stackexchange.com/a/112132)

    An alternative that does not involve adding users to groups is to make the executable setgid procmod, as that also makes procmod the effective group id of any user executing the setgid binary (suggested in https://apple.stackexchange.com/a/112132)

    sudo chgrp procmod /path/to/gdb
    sudo chmod g+s /path/to/gdb 
    

  • 这篇关于如何在 Mac OSX El Capitan 中安装 gdb(调试器)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆