Gdb does not work on macos High Sierra 10.13.3

I installed gdb 8.1 with brew.

I also have codeign gdb and .gdbinit as shown below:

set startup-with-shell off .

I have disabled the SIP function:

 $ csrutil status System Integrity Protection status: disabled. 

But gdb still does not work:

 #include <iostream> using namespace std; int main() { cout << "hello world!" << endl; return 0; } 

Compilation command:

 g++ -g test.cpp 

Gdb output:

 GNU gdb (GDB) 8.1 Copyright (C) 2018 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-apple-darwin17.3.0". Type "show configuration" for configuration details. For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>. Find the GDB manual and other documentation resources online at: <http://www.gnu.org/software/gdb/documentation/>. For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from a.out...Reading symbols from /Users/mypc/Downloads/a.out.dSYM/Contents/Resources/DWARF/a.out...done. done. (gdb) run Starting program: /Users/mypc/Downloads/a.out [New Thread 0x2503 of process 802] [New Thread 0x2303 of process 802] During startup program terminated with signal ?, Unknown signal. (gdb) 

What are the right steps for gdb to work on macos sierra?

+36
gdb macos
source share
3 answers

This is caused by the latest version of GDB 8.1, downgrading GDB to 8.0.1 may solve this problem.

How to upgrade to GDB 8.0.1

  • Disable current gdb: brew unlink gdb
  • Install gdb 8.0.1: brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/9ec9fb27a33698fc7636afce5c1c16787e9ce3f3/Formula/gdb.rb
  • Optional: avoid updating GDB with brew pin gdb
+50
source share

in my case, a decrease to 8.0.1 did not help.
but the following steps helped.

(I inserted step 12, β€œcheck if it works,” because instead of restarting, I tested gdb and it worked just fine. I did not follow steps 12+)


  1. Keychain Open Access
  2. From the menu, go to Keychain Access> Certificate Assistant> Create Certificate
  3. Give it a name (e.g. gdb-cert )
    • Identity Type: Self-Signed Root
    • Certificate Type: Code Signature
    • Check: let me override the defaults
  4. Continue until "indicate location for ..."
  5. Set the location of the keychain in the system
  6. Create a certificate and close the Certificate Assistant.
  7. Find a certificate in the system keychain.
  8. Double click certificate
  9. Expand Trust, set code signature to always trust
  10. Restart task in terminal: killall taskgated
  11. Create gdb using your certificate: codesign -fs gdb-cert/usr/local/bin/gdb
  12. --- CHECK IF IT WORKS ---
  13. Turn off your Mac and restart in recovery mode (hold down command-R until the Apple logo appears)
  14. Open terminal window
  15. Modify system integrity protection to enable debugging: debug csrutil enable --without debug
  16. Reboot your Mac
  17. Debugging with gdb should now work as expected.

Information resource:
Pre-Sierra: https://gist.github.com/hlissner/898b7dfc0a3b63824a70e15cd0180154
Sierra: https://gist.github.com/gravitylow/fb595186ce6068537a6e9da6d8b5b96d

+1
source share

I am using macOS 10.13.6 and I had the same problem: "(please check that gdb has a code designation - see Taskgated (8))" ...

When I downgraded GDB from 8.2.1 to 8.0.1 and then created and signed gdb-cert again, it just worked ...

Remember to change the path to gdb from 8.2.1 to 8.0.1 in the eclipse debugger, restart and it will work.

0
source share

All Articles