如何在Mac OS X El Capitan中安装GDB(调试器)?我已经尝试过几次安装GDB,但都失败了。
我按照这个URL进行操作:http://ntraft.com/installing-gdb-on-os-x-mavericks/ ,但是MAC不允许安装MacPorts。
请问有谁能帮助我解决这个问题吗?
如何在Mac OS X El Capitan中安装GDB(调试器)?我已经尝试过几次安装GDB,但都失败了。
我按照这个URL进行操作:http://ntraft.com/installing-gdb-on-os-x-mavericks/ ,但是MAC不允许安装MacPorts。
请问有谁能帮助我解决这个问题吗?
首先安装Homebrew:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
然后运行以下命令安装:brew install gdb
请注意,本答案是针对Mac OS El Capitan编写的。对于更新版本,请注意它可能不再适用。特别地,遗留选项很可能已经过时。
这个问题有两个解决方案,在其他回答和如何在OSX 10.11 El Capitan下使用macports使gdb工作?中都提到了,但为了消除一些混淆,这里是我的总结(作为一个回答,因为它变得有点长):
我想选择哪种替代方案更安全,取决于选择信任自签名证书还是给用户更多权限之间的选择。
如果使用签名替代方案,则不需要禁用SIP以添加-p选项到taskgated
。
然而,请注意,使用此替代方案,只允许在 _developer
组中的用户进行调试。
使用codesign使用名为gdb-cert
的证书进行签名:
codesign -s gdb-cert /opt/local/bin/ggdb
(使用MacPorts标准路径,必要时采用)
有关详细的代码签名配方(包括证书创建),请参见: https://gcc.gnu.org/onlinedocs/gcc-4.8.1/gnat_ugn_unw/Codesigning-the-Debugger.html 或 https://sourceware.org/gdb/wiki/BuildingOnDarwin
请注意,在此过程中和之后,您需要重新启动钥匙串应用程序和taskgated服务(最简单的方法是重新启动)。
taskgated
中添加-p选项是一种选择。请注意,如果使用此选项,不需要签署二进制文件,它也会绕过验证作为开发工具组(_developer
)成员的对话框。restart in recovery mode, open a terminal and run csrutil disable
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>
restart in recovery mode to reenable SIP (csrutil enable
)
restart machine and add user USERNAME
to the group procmod
:
sudo dseditgroup -o edit -a USERNAME -t user procmod
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
无法找到进程ID 576的Mach任务端口:(os / kern)失败(0x5)。 (请检查gdb是否已签名-请参见taskgated(8))
。 b. 情况最终更加复杂-方法2确实在gdb方面起作用,但严重破坏了我的系统,以至于没有第三方应用程序(不包括内置的Mac OS X应用程序)可以再次启动(所有报告与代码签名相关的异常)-我找不到还原的方法,除了使用时间机器,之后我再次检查发现是方法2导致了问题-所有这些都是在MacBook Pro 10.11.3上完成的。 - Marinos Kbrew install https://raw.githubusercontent.com/Homebrew/homebrew-core/master/Formula/gdb.rb
- zed这篇博客讲得很清楚:
http://panks.me/posts/2013/11/install-gdb-on-os-x-mavericks-from-source/
我的操作步骤如下:
通过KeyChain Access创建编码签名证书:
1.1 从菜单中选择KeyChain Access > Certificate Assistant > Create a Certificate...
1.2 按照向导创建一个证书,并将其命名为gdb-cert
,身份类型为Self Signed Root,证书类型为Code Signing,并选择Let me override defaults。
1.3 点击几次Continue,直到您到达Specify a Location For The Certificate screen,然后将Keychain设置为System。
通过Homebrew安装gdb:brew install gdb
重新启动taskgated
:sudo killall taskgated && exit
重新打开终端窗口,输入sudo codesign -vfs gdb-cert /usr/local/bin/gdb
在我的Mac OS X El Capitan上,我使用homebrew来安装gdb:
brew install gdb
然后我按照这里的说明进行操作:https://sourceware.org/gdb/wiki/BuildingOnDarwin,在2.1. Mac OS X 10.5 (Leopard)及更高版本的方法部分。
一旦您安装了gdb
的MacPorts版本,您需要禁用SIP才能对/System/Library/LaunchDaemons/com.apple.taskgated.plist
进行适当的编辑。要禁用SIP,您需要在恢复模式下重新启动,并执行以下命令:
csrutil disable
然后重新启动。然后你需要像这样编辑com.apple.taskgated.plist
的底部:
<array>
<string>/usr/libexec/taskgated</string>
<string>-sp</string>
</array>
procmod
组中。 - drRobertz我花了好几天的时间在High Sierra 10.13.1上尝试使其工作。无论我尝试什么,homebrew中的gdb 8.1版本都无法正常工作。最终通过macports安装gdb 8.0.1,这神奇地起作用了(在跳过所有与codesigning等相关的必要步骤后)。
另外一个问题是,在Eclipse中,你会发现程序参数周围有多余的单引号,可以通过在.gdbinit中提供参数来解决。
看起来MacPorts现在可以在El Capitan上安装: https://www.macports.org/install.php 然后你可能可以通过你提到的链接安装gdb。
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/master/Formula/gdb.rb
- zed