The question is “How can I install GDB on a Mac?” I’ve never tried - but if you’re using Xcode or the “command line development tools” on the Mac from Apple and want to use a command line debugger, then use “lldb” instead (llvm/clang seems to be t. Nov 30, 2020 Then run this: brew install gdb. 3: 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. 4: Here’s a blog post explains it very well. GDB: The GNU Project Debugger GDB Maintainers contributing current git documentation mailing lists Download GDB The most. Download GDB The most recent.
Then run this: brew install gdb. 3: 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. 4: Here’s a blog post explains it very well. Download Gdb Mac How to create a bootable macOS Mojave installer drive Put the macOS Mojave installer on an external USB thumb drive or hard drive and use it to install the operating system on a Mac.
Question or issue on macOS:
How to install gdb (debugger) in Mac OSX El Capitan ? I have tried installing gdb but failed couple of time.
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.
How to solve this problem?
Solution no. 1:
Please note that this answer was written for Mac OS El Capitan. For newer versions, beware that it may no longer apply. In particular, the legacy option is quite possibly deprecated.
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):
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.
However, note that with this alternative, debugging is only allowed for users in the_developer
group.
Using codesign to sign using a cert named gdb-cert
:
codesign -s gdb-cert /opt/local/bin/ggdb
(using the MacPorts standard path, adopt as necessary)
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).
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
).
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.
The recipe is:
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:restart in recovery mode to reenable SIP (
csrutil enable
)restart machine and add user
USERNAME
to the groupprocmod
: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)
Solution no. 2:
Install Homebrew first :
/usr/bin/ruby -e '$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)'
Then run this : brew install gdb
Solution no. 3:
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
.
Solution no. 4:
Here’s a blog post explains it very well:
And the way I get it working:
Create a coding signing certificate via KeyChain Access:
1.1 From the Menu, select KeyChain Access > Certificate Assistant > Create a Certificate…
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.3 Click several times on Continue until you get to the Specify a Location For The Certificate screen, then set Keychain to System.
Install gdb via Homebrew:
brew install gdb
Restart
taskgated
:sudo killall taskgated && exit
Reopen a Terminal window and type
sudo codesign -vfs gdb-cert /usr/local/bin/gdb
Solution no. 5:
On my Mac OS X El Capitan, I use homebrew to 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.
Solution no. 6:
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:
Then restart. Then you will need to edit the bottom part of com.apple.taskgated.plist
like this:
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:
The only way I have been able to get the code signing to work is by running ggdb
with sudo
. Good luck!
Solution no. 7:
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).
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.
Solution no. 8:
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.
Hope this helps!
If you work on a Mac OS X 10.9 Mavericks or later, you will run into the problem of Eclipse refusing to interactively debug problems that otherwise build and run fine: An attempt to start a debugging session by selecting Run
Debug from the menu will result in Eclipse complaining that an Error with command: gdb --version
has occurred.
The problem is caused by Apple switching away from GDB, the GNU debugger, to LLDB, the LLVM debugger, in their Xcode toolchain (along with the transition from GCC to Clang). Unfortunately, Eclipse is not capable of communicating with any debugger other than GDB (yet). Here is a step-by-step guide for installing and configuring GDB.
Installing GDB
As with GCC, the easiest way to install GDB is through Homebrew. In a Terminal window, run the command brew install gdb
, and wait for it to complete. (As usual, it may ask for your password.)
Mac Gdb Codesign
Now, we need to code-sign the GDB executable, so it will be allowed to control other processes, as necessary for a debugger. For that, we will first create a new certificate in Keychain.
Download Gdb For Mac
Creating a Certificate
Open the Keychain Access application (can be found in Applications/Utilities directory or through Spotlight). Select Certificate Assistant
Create a Certificate in the application menu (Keychain Access). An assistant window will appear for guiding you through the process.
- First, you will be asked for the name and type of the certificate. You may choose the name arbitrarily, but to simplify its future use in command line, prefer names without spaces or other fancy characters, e.g.,
gdbcert
. - Make sure that Identity Type is set to Self Signed Root, change Certificate Type to Code Signing, check the Let me override defaults checkbox, and click Continue. Click Continue again in the popup prompt warning about the certificate being self-signed.
- On the next page, leave Security Number to be 1, and set Validity Period to a large enough number of days to cover the duration of the class or more, say, 365. (Certificates cannot last forever; the maximum validity period is 20 years.)
- Then click Continue once again, and keep doing so to skip the next six screens until you see the one entitled Specify a Location For The Certificate. For the only property, Keychain, choose System from the drop-down list. Lastly, click Create, type in your password, if prompted, and click Done.
- Back in the main window, choose the System keychain in the sidebar on the left, and select the newly created certificate from the list. Open the context menu and select Get Info. In the information window that will appear, expand the Trust section and set the Code Signing property to Always Trust. Close this window (you may be asked for your password), and quit Keychain Access.
Signing GDB
Our new certificate is now ready to be used. In order to make it immediately available for signing, we need to restart the Taskgate access-control service. You can use Activity Monitor to do this (also found in Applications/Utilities). Open it and filter the list of processes by typing taskgated
in the search field in the toolbar. (If you cannot find it, make sure the menu item View
All Processes is checked.)
There should be exactly one process left in the list. Highlight it, then select View
Quit Process from the menu, and click Quit in the popup prompt. The Taskgate process will be terminated and, consequently, should disappear from the list. In a few seconds, it will be restarted by the system and should reappear in the list. Please wait for this to happen (it may take up to a minute or two, at worst).
Finally, in a Terminal window, run codesign -s gdbcert /usr/local/bin/gdb
(if you named your certificate differently, replace gdbcert
with its name here). Once again, you will be prompted for you username and password. If the command does not produce any output, then GDB is successfully signed.
Configuring Eclipse
The only thing left to do is to point Eclipse to the GDB executable. Open Eclipse
Preferences from the main menu (not to be confused with Project Preferences). In the tree of options listed in the sidebar, navigate to C/C++
Debug
GDB, and set the GDB debugger field to /usr/local/bin/gdb
.
If there is no GDB section in the C/C++
Debug subtree, close the preferences window, and try to first start a debugging session for any project that you can already run without problems. You can do it by either clicking the Debug button on the toolbar, or selecting Run
Debug from the main menu. This attempt will, of course, fail with an error message about the gdb
command, but it will force the said C/C++
Debug
GDB settings to appear in the preferences.
This will change the GDB executable for new projects; for all existing ones (that you are going to use debugging for), you will need to manually update their debug configurations. To do that, select Run
Debug Configurations from the menu. In the window that appears, one after another, select every project under the C++ Application section in the sidebar. For each of them, open the Debugger tab, set the GDB debugger field to the same path /usr/local/bin/gdb
, and click the Apply button. After repeating this change for all listed projects, click Close.
If the above steps do not solve the issue on your machine, or you encounter a problem while following them, please do not hesitate to come to one of the upcoming common labs for help.