Skip to content

Instantly share code, notes, and snippets.

@felixpie
Forked from gravitylow/codesign_gdb.md
Last active April 22, 2018 17:36
Show Gist options
  • Save felixpie/d3b11b344e931410fd0e3c0b6b247dbd to your computer and use it in GitHub Desktop.
Save felixpie/d3b11b344e931410fd0e3c0b6b247dbd 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.

When you still get problems (e.g. process gets terminated) try to downgrade to gdb version 8.0.1 $brew uninstall --force gdb $brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/c3128a5c335bd2fa75ffba9d721e9910134e4644/Formula/gdb.rb

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