Here are the steps to installing and setting up GDB on Mac OS Sierra/High Sierra.
Run brew install gdb.
On starting gdb, you will get the following error:
Unable to find Mach task port for process-id 2133: (os/kern) failure (0x5).
(please check gdb is codesigned - see taskgated(8))To fix this error, follow the following steps:
- Open Keychain Access
- In menu, open Keychain Access > Certificate Assistant > Create a Certificate
- Give it a name (e.g.
gdbcert)
- Identity type: Self Signed Root
- Certificate type: Code Signing
- Check: Let Me Override Defaults
- Continue until "Specify a Location For"
- Set Keychain location to System. If this yields the following error:
Certificate Error: Unknown Error =-2,147,414,007Set Location to Login, Unlock System by click on the lock at the top left corner and drag and drop the certificate gdbcert to the System Keychain. - Create certificate and close Certificate Assistant.
- Find the certificate in System keychain.
- Double click certificate.
- Expand Trust, set Code signing to
Always Trust - Restart taskgated in terminal:
killall taskgated - Enable root account by following the steps given below: Open System Preferences. Go to User & Groups > Unlock. Login Options > "Join" (next to Network Account Server). Click "Open Directory Utility". Go up to Edit > Enable Root User.
- Codesign gdb using your certificate:
codesign -fs gdbc /usr/local/bin/gdb - Shut down your mac and restart in recovery mode (hold down command-R until apple logo appears)
- Open terminal window
- Modify System Integrity Protection to allow debugging:
csrutil enable --without debug - Reboot your Mac. Debugging with gdb should now work as expected.
Hello there, first of all, thanks for your methods but there are still some problems with my macbook.
I am using OS X 10.13.6 and gdb version is 8.1.1
I have successfully finished the first nine steps you gave. But during the 10th,
killall taskgatedreturnedNo matching processes belonging to you were foundso I googled it and usedsudo killall taskgatedinstead.And under the recover mode, it returns the same as I input
csrutil enable --without debug, both returnscsrutil: requesting an unsupported configuration. This is likely to break in the future and leave your machine in an unknown state. csrutil: failed to modify system integrity configuration. This tool needs to be executed from the Recovery OS.I tried use
csrutil enableand returned successfully.But the Eclipse still tells me gdb cannot be run due to unknow reason.
Would you please help me with that?