Troubleshoot gdb prompt signature error on Mac
Please keep this link for the original Power reprint.
Installing GDB
The new Mac has GCC, g++, but no gdb
Some say there's a setup for Xcode, but I really don't.
Install via homebrew, no installation brew command is performed
Ruby-e "$ (curl-fsslk https://raw.github.com/Homebrew/homebrew/go/install)"
Then install GDB
Brew Install HTTPS://RAW.GITHUB.COM/HOMEBREW/HOMEBREW-DUPES/MASTER/GDB.RB
Or
Brew Install Homebrew/dupes/gdb
I used the latter.
Signature issues
Install GDB and write a Hello gdb!.
Hello.cpp
#include <iostream>
using namespace Std;
int main (int argc, char **argv)
{
cout << "Hello gdb!" << Endl;
return 0;
}
Compiling links
>g++-g-o Hello Hello.cpp
Start debugging
>gdb Hello
>run
Starting program:/users/username/ws/hello
Unable to find Mach task port for Process-id 358: (Os/kern) Failure (0x5).
(Please check that GDB is Codesigned-see taskgated (8))
Hint above GDB signature error.
Reason
Darwin Kernel For security reasons, GDB is not allowed to debug any program without special authorization because it can be debugged to control the process. However, if the root user does not have this problem, but who would like to use root to debug the program.
Solve
A common workaround is to give gdb the code signing right to fully trust the system to other processes.
First, you need to create a system code signing trust certificate:
- Launch the Keychain Access app (/applications/utilities/keychain Access.app)
- Open Menu: Keychain Access-"certificate Assistant-" Create Certificate ...
- Enter the name of the certificate, such as: Gdb-cert;
- Select identity type: Self-signed root certificate (identity type to signed root)
- Select certificate Type: Code signature (Certificate type to code Signing)
- TICK: Let me override these default signatures (select the Let me override defaults)
- Go all the way until you choose to store the certificate address, select: System
- The certificate is created, and the certificate custom Trust is set
- Right-click the Gdb-cert certificate you just created, select "Get info"
- Click Trust to display the trust options that can be customized
- "Code Signing" select "Always Trust" (Code Signing
Second, grant the certificate to GDB and execute the command
>codesign-s Gdb-cert/path to GdB
Note that you need to exit the Keychain Access app first, or restart the system
View/path to GDB, execute command
>which GDB
Well, the above gives GDB a code signing certificate that the system trusts, and GDB can be used normally.
Please keep this link for the original Power reprint.