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:
killall taskgated
- Codesign gdb using your certificate:
codesign -fs gdbc /usr/local/bin/gdb
- Shut down your mac and restart in recovery mode (hold down command-R until apple logo appears)
- Open terminal window
- Modify System Integrity Protection to allow debugging:
csrutil enable --without debug
- Reboot your Mac. Debugging with gdb should now work as expected.
Big Sur 11.4
gdb 11.1
Gdb is running sometimes other times it will hang / block after
(gdb) run
and will not let me terminate the process. I think it might be a part of this issue as described here. Might debug further later but for now switching tolldb
To get gdb running:
Used this procedure starting from the 1.1. Create a certificate in the System Keychain with the addition of
echo "set startup-with-shell off" >> ~/.gdbinit
I had previous run the
csrutil enable --without debug
in recovery mode too. It is possible that that step is necessary. Probably would recommend to try without first according it @niilz it is not needed.@gravitylow notice me senpai