Skip to content

Instantly share code, notes, and snippets.

@AdanJSuarez
Forked from gravitylow/codesign_gdb.md
Created February 19, 2020 14:42
Show Gist options
  • Select an option

  • Save AdanJSuarez/39e1d6daa070c5f3041958471fd72f91 to your computer and use it in GitHub Desktop.

Select an option

Save AdanJSuarez/39e1d6daa070c5f3041958471fd72f91 to your computer and use it in GitHub Desktop.
Codesign gdb on macOS

If you are getting this in gdb on macOS while trying to run a program:

Unable to find Mach task port for process-id 57573: (os/kern) failure (0x5).
 (please check gdb is codesigned - see taskgated(8))
  1. Open Keychain Access
  2. In menu, open Keychain Access > Certificate Assistant > Create a certificate
  3. Give it a name (e.g. gdbc)
  • 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
  3. Create certificate and close Certificate Assistant.
  4. Find 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. Codesign gdb using your certificate: codesign -fs gdbc /usr/local/bin/gdb
  9. Shut down your mac and restart in recovery mode (hold down command-R until apple logo appears)
  10. Open terminal window
  11. Modify System Integrity Protection to allow debugging: csrutil enable --without debug
  12. Reboot your Mac. Debugging with gdb should now work as expected.
@AdanJSuarez
Copy link
Author

Additional instructions if you get: Unknown Error = -2,147,414,007 on creating certificate with Certificate Assistant

The purpose for creating a certificate was to codesign gdb on Mac. Here are the steps for the same:-

1.- Create a certificate with all the parameters mentioned above.
2.- Instead of saving the Keychain under location System, save it under Login.
3.- Then, unlock the System Keychain by clicking on the lock icon on the top left corner and drag the certificate from Login to System.
4.- Right Click the Certificate, click on Get Info and and under Trust, set to Always Trust.
5.- Restart taskgated in terminal: killall taskgated
6.- Enable root account:

  • 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.
  • Run codesign -fs gdbc /usr/local/bin/gdb in the terminal.
    Disable Root Account again and you should be good to go.

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