Unfortunately, GDB doesn't work out-of-the-box on MacOS Sierra (tested on 10.12.2) as it’s not code-signed. This is unfortunate, as GDB is the de facto standard for debugging C code. After researching the issue for a while, I managed to find a solution and successfully run GDB. Upgrade your gdb to version 8.0.1 brew upgrade gdb; execute echo 'set startup-with-shell off' /.gdbinit ( I saw this command when I installed gdb by brew ) create a certificate with name gdb-cert and trust this certificate in code signing option; reboot your mac; execute sudo codesign -s gdb-cert /usr/local/bin/gdb; done!
Mac OS X 10.10.2 does not come with gdb
pre installed. It is available on homebrew:
The binary is installed on /usr/local/bin
When initializing gdb
on a program (a.out
) it will produce the following error:
This error occurs because OSX implements a pid access policy which requires a digital signature for binaries to access other processes pids. To enable gdb
access to other processes, we must first code sign the binary. This signature depends on a particular certificate, which the user must create and register with the system.
Install Gdb For Mac Sierra Download
To create a code signing certificate, open the Keychain Access application. Choose menu Keychain Access -> Certificate Assistant -> Create a Certificate...
Choose a name for the certificate (e.g., gdb-cert
), set Identity Type to Self Signed Root, set Certificate Type to Code Signing and select the Let me override defaults. Click several times on Continue until you get to the Specify a Location For The Certificate screen, then set Keychain to System.
Install Gdb For Mac Sierra Update
Double click on the certificate, open Trust section, and set Code Signing to Always Trust. Exit Keychain Access application.
Restart the taskgated service, and sign the binary.
The officially supported debugging package for Mac OS X is lldb, which is a fine debugger. However, many people including me still prefer to use gdb, the GNU debugger. In fact, I use cgdb, which provides nice color interface to gdb, and that is why I must install gdb on my Mac. Unfortunately, it is not so easy to install and enable gdb to debug on Mac. In the previous post, I presented a method to do this, but I figure now that it was quite unsafe way to do so. For more details, please take a look at the official documentation.Install Gdb Mac High Sierra
$ brew install gdb
If you are using Sierra or above, run the following as well:
$ echo 'set startup-with-shell off' >> ~/.gdbinit
Next, this is the part where we give gdb debug other processes. Open up Keychain Access application and on the menu select Keychain Access -> Certificate Assistant -> Create a certificate.
Enter gdb-cert for the name, select Self Signed Root for Identity Type, select Code Signing for Certificate Type, and check the box Let me override defaults.
Click Continue several times until you see Specify a Location For the Certificate window. Select System for the Keychain and proceed.
Once the certificate is created, double click on it, and in the Trust section locate Code Signing item. Select Always Trust and exit. You will be prompted with your admin password to make the change.
Finally, you can close Keychain Access app and type in the following in terminal:
$ sudo killall taskgated
$ codesign -fs gdb-cert $(which gdb)
That's it! You will be able to use gdb on your Mac!