Today, when I install GDB in OS X EI Capitan 10.11.6, I have a lot of problems. I write this article so that I can remind myself in the future.

The solution

1. Install GDB

$ brew install gdb
$ gdb --versionThe GNU GDB 8.2.1 (GDB)Copy the code

2, We tried to run GDB, the following error:

Unable to find Mach task port for process-id 28885: (os/kern) failure (0x5).
(please check gdb is codesigned - see taskgated(8))
Copy the code

3, Create certificate execution menu keystring access -> Certificate Assistant -> Create certificate information

  • Certificate name: gdb-cert
  • Identity type: self-signed root certificate
  • Certificate type: code signature
  • Check: Let me override these defaults

Then click continue until the step of specifying the location of the certificate, select the key string to save the location is system click Create, enter the system password, create complete. (It is highly likely that the creation will fail. In this case, you can select login to save the key string, export the certificate, and then import the certificate to the system.) Open the introduction interface of the certificate, click Trust -> Code Signature, and change it to Always Trust

  1. Restart the system refresh the system certificate and code signature data

  2. For GDB signature

    $ sudo killall taskgated
    $ codesign -fs gdb-cert "$(which gdb)"    # -f overwrites the signature if it already exists
    Copy the code
  3. Add the ~/.gdbinit file

    $ echo "set startup-with-shell off" >> ~/.gdbinit
    Copy the code
  4. Finally, the following error occurs

    $ sudo gdb test.out
    (gdb) r
    Starting program: /Users/apple/Desktop/code/test.out
    [New Thread 0x1103 of process 843]
    [New Thread 0xe03 of process 843]
    
    During startup program terminated with signal SIGTRAP, Trace/breakpoint trap.
    Copy the code

4. At this time, we only need to replace GDB V8.1 to GDB V8.0.1 with the following code:

$ brew uninstall gdb
$ brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/c3128a5c335bd2fa75ffba9d721e9910134e4644/Formula/gdb.rb
Copy the code

The test success is as follows:

reference

  • Panks. Me/posts / 2013 /…
  • Andresabino.com/2015/04/14/…
  • Sourceware.org/gdb/wiki/Bu…
  • Stackoverflow.com/questions/4…