How to install gdb (debugger) in Mac OSX El Capitan ? I have tried installing gdb but failed couple of time.
如何在Mac OSX El Capitan中安装gdb(调试器)?我尝试过安装gdb,但是失败了。
I was following this URL : http://ntraft.com/installing-gdb-on-os-x-mavericks/ , MAC doesnot allow to install MacPorts.
我一直在跟踪这个URL: http://ntraft.com/installing-gdb-on-os-x-mavericks/, MAC不允许安装MacPorts。
Could anyone please help me in this regard.
有人能在这方面帮助我吗?
8 个解决方案
#1
27
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):
对于这个问题,有两种解决方案,它们都在这个问题的其他答案中提到,以及如何让gdb在osx10.11 El Capitan下使用macports工作?,但为了澄清一些困惑,我的总结(作为一个回答,因为它有点长了):
Which alternative is more secure I guess boils down to the choice between 1) trusting self-signed certificates and 2) giving users more privileges.
哪种选择更安全,我想这可以归结为信任自签名证书和给予用户更多特权之间的选择。
Alternative 1: signing the binary
If the signature alternative is used, disabling SIP to add the -p option to taskgated
is not required.
如果使用了签名替代方法,则不需要禁用SIP来将-p选项添加到任务栏中。
However, note that with this alternative, debugging is only allowed for users in the _developer
group.
但是,请注意,使用这种替代方法,只允许_developer组中的用户进行调试。
Using codesign to sign using a cert named gdb-cert
:
使用codesign签名使用一个名为gdb-cert的证书:
codesign -s gdb-cert /opt/local/bin/ggdb
合作设计- s gdb-cert / opt /地方/ bin / ggdb
(using the MacPorts standard path, adopt as necessary)
(使用MacPorts标准路径,必要时采用)
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
对于详细的代码签名方案(incl cert创建),请参见:https://gcc.gnu.org/onlinedocs/gcc-4.8.1/gnat_ugn_unw/codesigndebug .html或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).
注意,您需要在过程中和之后重新启动keychain应用程序和taskgate服务(最简单的方法是重新启动)。
Alternative 2: use the legacy option for taskgated
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
).
根据@user14241的答案,禁用SIP并将-p选项添加到taskgate是一个选项。请注意,如果使用此选项,则不需要签署二进制文件,而且它还绕过了作为开发工具组(_developer)成员身份验证的对话框。
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.
在添加-p选项(允许组procmod和procview)之后,您还需要添加应该允许使用gdb到procmod组的用户。
The recipe is:
配方是:
-
restart in recovery mode, open a terminal and run
csrutil disable
重新启动恢复模式,打开终端并运行csrutil禁用。
-
restart machine and edit
/System/Library/LaunchDaemons/com.apple.taskgated.plist
, adding the-p
opion:重新启动机器并编辑/系统/库/LaunchDaemons/com.apple.taskgate。plist,添加-p opion:
<array> <string>/usr/libexec/taskgated</string> <string>-sp</string> </array>
-
restart in recovery mode to reenable SIP (
csrutil enable
)在恢复模式下重新启动,以重新启用SIP (csrutil启用)
-
restart machine and add user
USERNAME
to the groupprocmod
:重新启动机器并将用户名添加到组procmod:
sudo dseditgroup -o edit -a USERNAME -t user procmod
sudo dseditgroup -o编辑-用户名-t用户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)另一种不涉及向组添加用户的替代方法是使可执行的setgid procmod,这也使procmod成为执行setgid二进制文件的任何用户的有效组id(在https://apple.stackexchange.com/a/112132中建议)。
sudo chgrp procmod /path/to/gdb sudo chmod g+s /path/to/gdb
#2
26
Install Homebrew first :
先安装自制程序:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
/usr/bin/ruby -e“$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”
Then run this : brew install gdb
然后运行这个:brew安装gdb。
#3
11
Here's a blog post explains it very well:
这里有一篇博客文章很好地解释了这一点:
http://panks.me/posts/2013/11/install-gdb-on-os-x-mavericks-from-source/
http://panks.me/posts/2013/11/install-gdb-on-os-x-mavericks-from-source/
And the way I get it working:
我的方法是:
-
Create a coding signing certificate via KeyChain Access:
通过KeyChain访问创建编码签名证书:
1.1 From the Menu, select KeyChain Access > Certificate Assistant > Create a Certificate...
从菜单中,选择KeyChain Access >证书助理>创建一个证书…
1.2 Follow the wizard to create a certificate and let's name it
gdb.cert
, the Identity Type is Self Signed Root, and the Certificate Type is Code Signing and select the Let me override defaults.1.2使用向导创建证书,并将其命名为gdb。cert,身份类型是自签名的根,证书类型是代码签名,并选择让我重写默认值。
1.3 Click several times on Continue until you get to the Specify a Location For The Certificate screen, then set Keychain to System.
1.3单击几次继续,直到您到达指定的证书屏幕位置,然后将Keychain设置为系统。
-
Install gdb via Homebrew:
brew install gdb
通过自制程序安装gdb: brew安装gdb。
-
Restart
taskgated
:sudo killall taskgated && exit
重启任务:sudo killall taskgate &&退出。
-
Reopen a Terminal window and type
sudo codesign -vfs gdb.cert /usr/local/bin/gdb
重新打开终端窗口和类型sudo codesign -vfs gdb。cert /usr/local/bin/gdb
#4
10
This doesn't necessarily address the question but if you are using Mac OS X then you can probably use lldb
LLDB Homepage . It's very similar to gdb
and even provides a guide to using commands that you would use on gdb
.
这并不一定能解决问题,但如果你使用的是Mac OS X,那么你可能会使用lldb lldb主页。它与gdb非常类似,甚至提供了使用在gdb上使用的命令的指南。
#5
5
On my Mac OS X El Capitan, I use homebrew to install gdb:
在我的Mac OS X El Capitan上,我使用homebrew来安装gdb:
brew install gdb
Then I follow the instruction here: https://sourceware.org/gdb/wiki/BuildingOnDarwin, in the section 2.1. Method for Mac OS X 10.5 (Leopard) and later.
然后我遵循这里的指示:https://sourceware.org/gdb/wiki/BuildingOnDarwin,在第2.1节中。Mac OS X 10.5 (Leopard)和稍后的方法。
#6
2
Once you get the macports version of gdb
installed you will need to disable SIP in order to make the proper edits to /System/Library/LaunchDaemons/com.apple.taskgated.plist
. To disable SIP, you need to restart in recovery mode and execute the following command:
一旦您安装了gdb的macports版本,您就需要禁用SIP,以便对/System/Library/LaunchDaemons/ com.apple.taskgat. plist进行适当的编辑。要禁用SIP,您需要重新启动恢复模式并执行以下命令:
csrutil disable
Then restart. Then you will need to edit the bottom part of com.apple.taskgated.plist
like this:
然后重启。然后您需要编辑com.apple.taskgate的底部部分。plist是这样的:
<array>
<string>/usr/libexec/taskgated</string>
<string>-sp</string>
</array>
Then you will have to restart to have the changes take effect. Then you should reenable SIP. The gdb
command for the macports install is actually ggdb
. You will need to code sign ggdb
following the instructions here:
然后,您将不得不重新启动,以使更改生效。那么您应该重新启用SIP。macports安装的gdb命令实际上是ggdb。您将需要在这里的说明下面编码符号ggdb:
https://gcc.gnu.org/onlinedocs/gcc-4.8.1/gnat_ugn_unw/Codesigning-the-Debugger.html
https://gcc.gnu.org/onlinedocs/gcc-4.8.1/gnat_ugn_unw/Codesigning-the-Debugger.html
The only way I have been able to get the code signing to work is by running ggdb
with sudo
. Good luck!
我唯一能让代码签名工作的方法就是用sudo运行ggdb。好运!
#7
0
It seems that MacPorts could be installed in El Capitan right now: https://www.macports.org/install.php Then you probably can install gdb by link you mentioned.
似乎MacPorts现在可以安装在El Capitan中:https://www.macports.org/install.php,然后您可能可以通过您提到的链接安装gdb。
#8
0
Just spent a good few days trying to get this to work on High Sierra 10.13.1. The gdb 8.1 version from homebrew would not work no matter what I tried. Ended up installing gdb 8.0.1 via macports and this miraculously worked (after jumping through all of the other necessary hoops related to codesigning etc).
仅仅花了几天的时间,就想让这款产品在Sierra 10.13.1的高山上工作。无论我怎么尝试,从自制程序中获得的gdb 8.1版本都不会起作用。最后,通过macports安装gdb 8.0.1,这个奇迹般地工作(在完成了与codesign相关的所有其他必要的操作之后)。
One additional issue is that in Eclipse you will get extraneous single quotes around all of your program arguments which can be worked around by providing the arguments inside .gdbinit instead.
另外一个问题是,在Eclipse中,您将在您的所有程序参数周围获得额外的单引号,而这些参数可以通过在.gdbinit内提供参数来解决。
#1
27
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):
对于这个问题,有两种解决方案,它们都在这个问题的其他答案中提到,以及如何让gdb在osx10.11 El Capitan下使用macports工作?,但为了澄清一些困惑,我的总结(作为一个回答,因为它有点长了):
Which alternative is more secure I guess boils down to the choice between 1) trusting self-signed certificates and 2) giving users more privileges.
哪种选择更安全,我想这可以归结为信任自签名证书和给予用户更多特权之间的选择。
Alternative 1: signing the binary
If the signature alternative is used, disabling SIP to add the -p option to taskgated
is not required.
如果使用了签名替代方法,则不需要禁用SIP来将-p选项添加到任务栏中。
However, note that with this alternative, debugging is only allowed for users in the _developer
group.
但是,请注意,使用这种替代方法,只允许_developer组中的用户进行调试。
Using codesign to sign using a cert named gdb-cert
:
使用codesign签名使用一个名为gdb-cert的证书:
codesign -s gdb-cert /opt/local/bin/ggdb
合作设计- s gdb-cert / opt /地方/ bin / ggdb
(using the MacPorts standard path, adopt as necessary)
(使用MacPorts标准路径,必要时采用)
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
对于详细的代码签名方案(incl cert创建),请参见:https://gcc.gnu.org/onlinedocs/gcc-4.8.1/gnat_ugn_unw/codesigndebug .html或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).
注意,您需要在过程中和之后重新启动keychain应用程序和taskgate服务(最简单的方法是重新启动)。
Alternative 2: use the legacy option for taskgated
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
).
根据@user14241的答案,禁用SIP并将-p选项添加到taskgate是一个选项。请注意,如果使用此选项,则不需要签署二进制文件,而且它还绕过了作为开发工具组(_developer)成员身份验证的对话框。
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.
在添加-p选项(允许组procmod和procview)之后,您还需要添加应该允许使用gdb到procmod组的用户。
The recipe is:
配方是:
-
restart in recovery mode, open a terminal and run
csrutil disable
重新启动恢复模式,打开终端并运行csrutil禁用。
-
restart machine and edit
/System/Library/LaunchDaemons/com.apple.taskgated.plist
, adding the-p
opion:重新启动机器并编辑/系统/库/LaunchDaemons/com.apple.taskgate。plist,添加-p opion:
<array> <string>/usr/libexec/taskgated</string> <string>-sp</string> </array>
-
restart in recovery mode to reenable SIP (
csrutil enable
)在恢复模式下重新启动,以重新启用SIP (csrutil启用)
-
restart machine and add user
USERNAME
to the groupprocmod
:重新启动机器并将用户名添加到组procmod:
sudo dseditgroup -o edit -a USERNAME -t user procmod
sudo dseditgroup -o编辑-用户名-t用户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)另一种不涉及向组添加用户的替代方法是使可执行的setgid procmod,这也使procmod成为执行setgid二进制文件的任何用户的有效组id(在https://apple.stackexchange.com/a/112132中建议)。
sudo chgrp procmod /path/to/gdb sudo chmod g+s /path/to/gdb
#2
26
Install Homebrew first :
先安装自制程序:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
/usr/bin/ruby -e“$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”
Then run this : brew install gdb
然后运行这个:brew安装gdb。
#3
11
Here's a blog post explains it very well:
这里有一篇博客文章很好地解释了这一点:
http://panks.me/posts/2013/11/install-gdb-on-os-x-mavericks-from-source/
http://panks.me/posts/2013/11/install-gdb-on-os-x-mavericks-from-source/
And the way I get it working:
我的方法是:
-
Create a coding signing certificate via KeyChain Access:
通过KeyChain访问创建编码签名证书:
1.1 From the Menu, select KeyChain Access > Certificate Assistant > Create a Certificate...
从菜单中,选择KeyChain Access >证书助理>创建一个证书…
1.2 Follow the wizard to create a certificate and let's name it
gdb.cert
, the Identity Type is Self Signed Root, and the Certificate Type is Code Signing and select the Let me override defaults.1.2使用向导创建证书,并将其命名为gdb。cert,身份类型是自签名的根,证书类型是代码签名,并选择让我重写默认值。
1.3 Click several times on Continue until you get to the Specify a Location For The Certificate screen, then set Keychain to System.
1.3单击几次继续,直到您到达指定的证书屏幕位置,然后将Keychain设置为系统。
-
Install gdb via Homebrew:
brew install gdb
通过自制程序安装gdb: brew安装gdb。
-
Restart
taskgated
:sudo killall taskgated && exit
重启任务:sudo killall taskgate &&退出。
-
Reopen a Terminal window and type
sudo codesign -vfs gdb.cert /usr/local/bin/gdb
重新打开终端窗口和类型sudo codesign -vfs gdb。cert /usr/local/bin/gdb
#4
10
This doesn't necessarily address the question but if you are using Mac OS X then you can probably use lldb
LLDB Homepage . It's very similar to gdb
and even provides a guide to using commands that you would use on gdb
.
这并不一定能解决问题,但如果你使用的是Mac OS X,那么你可能会使用lldb lldb主页。它与gdb非常类似,甚至提供了使用在gdb上使用的命令的指南。
#5
5
On my Mac OS X El Capitan, I use homebrew to install gdb:
在我的Mac OS X El Capitan上,我使用homebrew来安装gdb:
brew install gdb
Then I follow the instruction here: https://sourceware.org/gdb/wiki/BuildingOnDarwin, in the section 2.1. Method for Mac OS X 10.5 (Leopard) and later.
然后我遵循这里的指示:https://sourceware.org/gdb/wiki/BuildingOnDarwin,在第2.1节中。Mac OS X 10.5 (Leopard)和稍后的方法。
#6
2
Once you get the macports version of gdb
installed you will need to disable SIP in order to make the proper edits to /System/Library/LaunchDaemons/com.apple.taskgated.plist
. To disable SIP, you need to restart in recovery mode and execute the following command:
一旦您安装了gdb的macports版本,您就需要禁用SIP,以便对/System/Library/LaunchDaemons/ com.apple.taskgat. plist进行适当的编辑。要禁用SIP,您需要重新启动恢复模式并执行以下命令:
csrutil disable
Then restart. Then you will need to edit the bottom part of com.apple.taskgated.plist
like this:
然后重启。然后您需要编辑com.apple.taskgate的底部部分。plist是这样的:
<array>
<string>/usr/libexec/taskgated</string>
<string>-sp</string>
</array>
Then you will have to restart to have the changes take effect. Then you should reenable SIP. The gdb
command for the macports install is actually ggdb
. You will need to code sign ggdb
following the instructions here:
然后,您将不得不重新启动,以使更改生效。那么您应该重新启用SIP。macports安装的gdb命令实际上是ggdb。您将需要在这里的说明下面编码符号ggdb:
https://gcc.gnu.org/onlinedocs/gcc-4.8.1/gnat_ugn_unw/Codesigning-the-Debugger.html
https://gcc.gnu.org/onlinedocs/gcc-4.8.1/gnat_ugn_unw/Codesigning-the-Debugger.html
The only way I have been able to get the code signing to work is by running ggdb
with sudo
. Good luck!
我唯一能让代码签名工作的方法就是用sudo运行ggdb。好运!
#7
0
It seems that MacPorts could be installed in El Capitan right now: https://www.macports.org/install.php Then you probably can install gdb by link you mentioned.
似乎MacPorts现在可以安装在El Capitan中:https://www.macports.org/install.php,然后您可能可以通过您提到的链接安装gdb。
#8
0
Just spent a good few days trying to get this to work on High Sierra 10.13.1. The gdb 8.1 version from homebrew would not work no matter what I tried. Ended up installing gdb 8.0.1 via macports and this miraculously worked (after jumping through all of the other necessary hoops related to codesigning etc).
仅仅花了几天的时间,就想让这款产品在Sierra 10.13.1的高山上工作。无论我怎么尝试,从自制程序中获得的gdb 8.1版本都不会起作用。最后,通过macports安装gdb 8.0.1,这个奇迹般地工作(在完成了与codesign相关的所有其他必要的操作之后)。
One additional issue is that in Eclipse you will get extraneous single quotes around all of your program arguments which can be worked around by providing the arguments inside .gdbinit instead.
另外一个问题是,在Eclipse中,您将在您的所有程序参数周围获得额外的单引号,而这些参数可以通过在.gdbinit内提供参数来解决。