Skip to content

Instantly share code, notes, and snippets.

@hieplpvip
Last active April 25, 2022 03:06
Show Gist options
  • Save hieplpvip/17bf0fd0efdc71dc776f6cf349549e78 to your computer and use it in GitHub Desktop.
Save hieplpvip/17bf0fd0efdc71dc776f6cf349549e78 to your computer and use it in GitHub Desktop.
Codesign GDB on macOS Catalina

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: sudo killall taskgated
  8. Create entitlements file: Copy the text below and save it in gdb.xml in your current directory.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>com.apple.security.cs.allow-jit</key>
    <true/>
    <key>com.apple.security.cs.allow-unsigned-executable-memory</key>
    <true/>
    <key>com.apple.security.cs.allow-dyld-environment-variables</key>
    <true/>
    <key>com.apple.security.cs.disable-library-validation</key>
    <true/>
    <key>com.apple.security.cs.disable-executable-page-protection</key>
    <true/>
    <key>com.apple.security.cs.debugger</key>
    <true/>
    <key>com.apple.security.get-task-allow</key>
    <true/>
</dict>
</plist>
  1. Codesign GDB using your certificate: codesign --entitlements gdb.xml -fs gdbc <loc of gdb>
    Replace <loc of gdb> with location of GDB on your machine.
  2. GDB should now work as expected.
@okridgway
Copy link

I'm getting two errors:

gdb.xml: unrecognized blob type (accepting blindly)
gdb.xml: invalid length in entitlement blob

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