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))
- Open Keychain Access
- In menu, open Keychain Access > Certificate Assistant > Create a certificate
- Give it a name (e.g.
gdbc
)
- Identity type: Self Signed Root
- Certificate type: Code Signing
- Check: let me override defaults
- Continue until "specify a location for..."
- Set Keychain location to System
- Create certificate and close Certificate Assistant.
- Find certificate in System keychain.
- Double click certificate
- Expand Trust, set Code signing to
always trust
- Restart taskgated in terminal:
sudo killall taskgated
- 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>
- 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. - GDB should now work as expected.
I'm getting two errors: