Forked and modifed from hlissner’s post.

If you are getting this in gdb on OSX 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
    • (Optional)Extend the expiration date
  4. Continue until “specify a location for…”
  5. Keychain = System
  6. Close. Find certificate in System keychains.
  7. Get Info
  8. Expand Trust, set Code signing to always trust
  9. sudo killall taskgated
  10. sudo codesign -fs gdbc /usr/local/bin/gdb
  11. Disable root account

Done!

Appendix.