Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gdb doesn't work on macos High Sierra 10.13.3

Tags:

macos

gdb

I have installed gdb 8.1 with brew.

I have codesign gdb also and .gdbinit as below:

set startup-with-shell off.

I have disabled SIP feature:

$ csrutil status System Integrity Protection status: disabled. 

But gdb still doesn't work:

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

Compile 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 correct steps to make gdb work on macos sierra?

like image 417
lucky1928 Avatar asked Feb 27 '18 04:02

lucky1928


People also ask

How do I get gdb to work on my Mac?

As with GCC, the easiest way to install GDB is through Homebrew. In a Terminal window, run the command brew install gdb , and wait for it to complete. (As usual, it may ask for your password.) Now, we need to code-sign the GDB executable, so it will be allowed to control other processes, as necessary for a debugger.

Does gdb work on Mac?

I just installed it (gdb 8.0) following this procedure as of today, it works on Mac OS High Sierra 10.13. 2 (17C88). For the latest version "brew install gdb" is fine. However, the steps above will allow you to install older versions which is handy.

Is High Sierra still supported 2021?

With Apple's release of macOS Catalina, High Sierra will be the third oldest version and will cease to be supported next year. As a result, SCSCF will stop providing software support for all computers running macOS 10.13 High Sierra on November 30, 2020 .

Do you have to install gdb on Mac?

If you don't already have gdb on your system, then you'll need to install it. I'm going to show you how to install gdb by using Homebrew. If you have gdb on your system already, you can skip to the Generate a certificate step. If you received an error, then you'll need to install gdb using Homebrew.


2 Answers

This is caused by latest gdb 8.1, downgrade gdb to 8.0.1 could solve this problem.

How to downgrade to gdb 8.0.1

  • Unlink 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 upgrade gdb with brew pin gdb
like image 183
Hongbo Liu Avatar answered Oct 22 '22 18:10

Hongbo Liu


in my case downgrading to 8.0.1 didn't help.
but the following steps helped.

(i inserted step 12, "check if it works" because, instead of restarting i've tested gdb and it worked just fine. i didn't follow the steps 12+)


  1. Open Keychain Access
  2. In menu, open Keychain Access > Certificate Assistant > Create a certificate
  3. Give it a name (e.g. gdb-cert)
    • Identity type: Self Signed Root
    • Certificate type: Code Signing
    • Check: let me override defaults
  4. Continue until "specify a location for..."
  5. Set Keychain location to System
  6. Create certificate and close Certificate Assistant.
  7. Find certificate in System keychain.
  8. Double click the certificate
  9. Expand Trust, set Code signing to always trust
  10. Restart taskgated in terminal: killall taskgated
  11. Codesign gdb using your certificate: codesign -fs gdb-cert /usr/local/bin/gdb
  12. --- CHECK IF IT WORKS ---
  13. Shut down your mac and restart in recovery mode (hold down command-Runtil apple logo appears)
  14. Open terminal window
  15. Modify System Integrity Protection to allow debugging: csrutil enable --without debug
  16. Reboot your Mac
  17. Debugging with gdb should now work as expected.

information source:
pre Sierra: https://gist.github.com/hlissner/898b7dfc0a3b63824a70e15cd0180154
Sierra: https://gist.github.com/gravitylow/fb595186ce6068537a6e9da6d8b5b96d

like image 38
GnoStiC Avatar answered Oct 22 '22 16:10

GnoStiC