After MacOS X 10.8, the GDB debugging tool installed will prompt error when used:
Unable to find Mach task port for process-id 28885: (os/kern) failure (0x5).
(please check gdb is codesigned - see taskgated(8))
This is because the Darwin kernel will refuse to allow gdb to debug another process if you don’t have special rights, since debugging a process means having full control over that process, and that isn’t allowed by default since it would be exploitable by malware. (The kernel won’t refuse if you are root, but of course you don’t want to be root to debug.)
The most up to date method to allow gdb to control another process is to sign it with any system-trusted code signing authority. This is an easy process once you have a certificate (see the section below).
This error occurs because OSX implements a pid access policy which requires a digital signature for binaries to access other processes pids. To enable gdb access to other processes, we must first code sign the binary. This signature depends on a particular certificate, which the user must create and register with the system.
To create a code signing certificate, open the Keychain Access application. Choose menu Keychain Access -> Certificate Assistant -> Create a Certificate…
Choose a name for the certificate (e.g., gdb-cert), set Identity Type to Self Signed Root, set Certificate Type to Code Signing and select the Let me override defaults. Click several times on Continue until you get to the Specify a Location For The Certificate screen, then set Keychain to System.
Double click on the certificate, open Trust section, and set Code Signing to Always Trust. Exit Keychain Access application.
Restart the taskgated service, and sign the binary.
sudokillalltaskgated
s
u
d
o
k
i
l
l
a
l
l
t
a
s
k
g
a
t
e
d
codesign -fs gdb-cert “$(which gdb)”
source http://andresabino.com/2015/04/14/codesign-gdb-on-mac-os-x-yosemite-10-10-2/
On macOS 10.12 (Sierra) and later, you must also
Use gdb 7.12.1 or later Additionally prevent gdb from using a shell to start the program to be debugged. You can use the following command for this inside gdb:
set startup-with-shell off
You can also put this last command in a file called .gdbinit in your home directory, in which case it will be applied automatically every time you start gdb
echo “set startup-with-shell off” >> ~/.gdbinit
Read More:
- Open vs code through terminal using code command in Mac OS
- How to uninstall CUDA driver and toolkit in Mac OS X?
- About the problem of calling tools library by running Python program under Mac OS X, modulenotfoundererror: no module named ‘tools‘
- To solve the problem of “failed to load vmmr0. R0” (Verr) of VirtualBox under Mac OS X_ SUPLIB_ WORLD_ Writable) “error
- Solve geforce error code with super full solution CODE:0x0003 Problem approach
- Python – [encoding] in Python os.system Solution to Chinese garbled code when calling CMD command
- Error: Command ‘/ usr / bin / clang’ failed with exit status 1 solution for Mac OS installation
- Solution to the error code of 0x80040154 in COM / ole call
- Big hole in using OpenGL on Mac OS
- Instability of Mac OS finder
- Solution for error 7 in lineage OS brush
- Geforce experience appears something went wrong error code 0x0003 error code solution
- Solution to garbled code problem after importing project in eclipse
- Configuring OpenGL environment on Mac OS
- Installing nmap on Mac OS
- Mac OS error in make pycaffe times failure error:’python.h’file not found resolved
- Error prompt of MAPP opening PHP under Mac OS
- A problem occurred configuring project ‘:x x x‘. > java.lang.NullPointerException (no error message)
- Error installing OS X virtual machine vcu-0: verify vmcore / VM / main / physmem_ monitor.c:1123
- Solve the problem of using in tensoft 2. X tf.contrib.slim No module named appears in the package: tensorflow.contrib problem