Unable to find Mach task port
I'm trying to use this program, but I get the following error in the GUI:
Unable to find Mach task port for process-id 19311: (os/kern) failure (0x5).\n (please check gdb is codesigned - see taskgated(8))
I'm on OSX 10.11 and installed gdb through homebrew
The Darwin Kernel requires the debugger to have special permissions before it is allowed to control other processes. These permissions are granted by codesigning the GDB executable, and then running gdb (or gdbgui) as sudo. Without these permissions, the debugger will report error messages such as:
Starting program: /x/y/foo Unable to find Mach task port for process-id 28885: (os/kern) failure (0x5). (please check gdb is codesigned - see taskgated(8))
The following instructions were taken from https://gcc.gnu.org/onlinedocs/gnat_ugn/Codesigning-the-Debugger.html and slightly modified:
Codesigning requires a certificate. The following procedure explains how to create one and apply it to gdb:
- Start the Keychain Access application (in /Applications/Utilities/Keychain Access.app)
- Select the Keychain Access -> Certificate Assistant -> Create a Certificate... menu
- Then:
- Choose a name for the new certificate (this procedure will use "gdb-cert" as an example)
- Set "Identity Type" to "Self Signed Root"
- Set "Certificate Type" to "Code Signing"
- Activate the "Let me override defaults" option
- Click several times on "Continue" until the "Specify a Location For The Certificate" screen appears, then set "Keychain" to "System"
- Click on "Continue" until the certificate is created
- Finally, in the view, double-click on the new certificate, and set "When using this certificate" to "Always Trust"
- Exit the Keychain Access application and restart the computer (this is unfortunately required) Once a certificate has been created, the debugger can be codesigned as follow. In a Terminal, run the following command:
$ codesign -fs gdb-cert /path/to/gdb where "gdb-cert" should be replaced by the actual certificate name chosen above.
When run as sudo, gdb will no longer report the taskgated error.
I have followed the step by step process but am now getting the following error after I change the 'specify a location for the certificate screen' from login to 'System':
Unknown Error = -2,147,414,007
My OS is High Sierra.
Thanks for your help
Check out these links
https://apple.stackexchange.com/questions/309017/unknown-error-2-147-414-007-on-creating-certificate-with-certificate-assist
https://apple.stackexchange.com/questions/302866/keychain-access-error-when-creating-new-system-certificate
https://gist.github.com/gravitylow/fb595186ce6068537a6e9da6d8b5b96d
This solution doesn't work on my macOS Mojave. Can someone help me?
@alsydrm
I had the same problem when tried to debug my Golang code.
Described solution doesn't work for me too but I find out that I can use lldb instead of gdb.
confirm advice not working on any new/modern macos (so called operating system) apple sucks (for lack of a better word)
@ray-kim-12 I am getting the same error. It says "Unknown Error = -2,147,414,007" after the screen that changes location from login to System. Were you able to resolve it?
Whatever the root cause of this is, it affects all gdb users and is not inherently related to gdbgui. I would recommend googling around to try to find a recent workaround (or conclusive proof that gdb cannot work on Mojave).
This task has a valid workaround for previous version of macOS. I recommend creating a new issue specific to Mojave to capture this error and hopefully a workaround (if someone finds one).
To resolve the "Unknown Error = -2,147,414,007" see https://apple.stackexchange.com/questions/309017/unknown-error-2-147-414-007-on-creating-certificate-with-certificate-assist. Summary is below:
- Create a certificate with all the parameters mentioned above.
- Instead of saving the Keychain under location System, save it under Login.
- Then, unlock the System Keychain by clicking on the lock icon on the top left corner and drag the certificate from Login to System.
- Right Click the Certificate, click on Get Info and and under Trust, set to Always Trust.
- Restart taskgated in terminal: killall taskgated
- Enable root account:
- Open System Preferences.
- Go to User & Groups > Unlock.
- Login Options > "Join" (next to Network Account Server).
- Click "Open Directory Utility".
- Go up to Edit > Enable Root User.
- Run
codesign -fs gdbc /usr/local/bin/gdbin the terminal. - Disable Root Account again and you should be good to go.