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))
- Open Keychain Access
- In menu, open Keychain Access > Certificate Assistant > Create a certificate
- Give it a name (e.g.
cert-gdb
)
- Identity type: Self Signed Root
- Certificate type: Code Signing
- Check: let me override defaults
- Continue until "specify a location for..."
- Keychain = System
- Close. Find certificate in System keychains.
- Specify a Location, make sure you choose the Keychain option of System
- Get Info
- Expand Trust, set Code signing to
always trust
- With a certificate created, restart the machine. Yes there are other ways to do this, but trust me its just easier to restart and be sure everything is working.
Right with a certificate we need to apply it to the binary, first of create an entitlements file, this is an XML file that shows associated permissions you want to grant the binary.
<?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>
With the file saved (in my case as gdb.xml) then the final setup is:
codesign --entitlements gdb.xml -fs gdb-cert /usr/local/bin/gdb
Ok assuming you found this after some Googling, you might reach the end of the above steps and run gdb think everything is going fine and it hangs with a message something like:
(gdb) run
Starting program: /Users/tnash/AppProjects/password/target/debug/password
Note: this version of macOS has System Integrity Protection.
Because `startup-with-shell' is enabled, gdb has worked around this by
caching a copy of your shell. The shell used by "run" is now:
/Users/tnash/Library/Caches/gdb/bin/zsh
[New Thread 0xc03 of process 27325]
[New Thread 0xe03 of process 27325]
If this is you, then:
echo "set startup-with-shell off" >> ~/.gdbinit
Finally, Done!
Thanks that helped me!