Skip to content

Instantly share code, notes, and snippets.

@kpy3
Forked from danisfermi/setupdb.md
Created March 30, 2018 22:16
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kpy3/27014703672ad6d54c00dfc06e45f1ae to your computer and use it in GitHub Desktop.
Save kpy3/27014703672ad6d54c00dfc06e45f1ae to your computer and use it in GitHub Desktop.
Setup gdb on Mac OS Sierra/High Sierra

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:

  1. Open Keychain Access
  2. In menu, open Keychain Access > Certificate Assistant > Create a Certificate
  3. Give it a name (e.g. gdbcert)
  • Identity type: Self Signed Root
  • Certificate type: Code Signing
  • Check: Let Me Override Defaults
  1. Continue until "Specify a Location For"
  2. Set Keychain location to System. If this yields the following error: Certificate Error: Unknown Error =-2,147,414,007 Set 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.
  3. Create certificate and close Certificate Assistant.
  4. Find the certificate in System keychain.
  5. Double click certificate.
  6. Expand Trust, set Code signing to Always Trust
  7. Restart taskgated in terminal: killall taskgated
  8. 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.
  9. Codesign gdb using your certificate: codesign -fs gdbc /usr/local/bin/gdb
  10. Shut down your mac and restart in recovery mode (hold down command-R until apple logo appears)
  11. Open terminal window
  12. Modify System Integrity Protection to allow debugging: csrutil enable --without debug
  13. Reboot your Mac. Debugging with gdb should now work as expected.
@humanitiesclinic
Copy link

humanitiesclinic commented May 8, 2019

Hi, I was trying to install gdb on the Mac, and found your post. I followed your instructions, but now have an additional problem. Do you know why:
gdb can start, but it's showing:

start
Temporary breakpoint 1 at 0x100000f04
Starting program: /Users/user/Documents/codecompre_tooltest/a.out 
[New Thread 0x1703 of process 1645]
[New Thread 0x1903 of process 1645]
[New Thread 0x1a03 of process 1645]

[3]+  Stopped                 gdb a.out

@Neo-sunny
Copy link

Neo-sunny commented Jul 20, 2020

Thnx. worked for me for STEP-5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment