8

There are tons and tons of post and blogs discussing this topic, but nothing seems to work...

From across the internet, here is the common consensus regarding the procedure required to install and run gdb.

  1. Install gdb

    brew install gdb
    

    Homebrew "successfully" installs gdb v8.1

  2. Codesign gdb

    Codesign gdb by following the codesigning procedure (as detailed in a separate SO post).

  3. Update ~/.gdbinit

    echo "set startup-with-shell off" >> ~/.gdbinit
    

After completing all the steps, when I attempt to debug a simple "hello world" program, I get the following startup error resulting from SIGTRAP being throw.

(gdb) start
Temporary breakpoint 1 at 0x100000e66: file test.cpp, line 5.
Starting program: /Users/zfields/Documents/Development/test/a.out
[New Thread 0x1703 of process 67971]
[New Thread 0x1903 of process 67971]
During startup program terminated with signal SIGTRAP, Trace/breakpoint trap.

What am I missing?

Zak
  • 12,213
  • 21
  • 59
  • 105

3 Answers3

14

After hours and hours of searching, I finally found an obscure gist identifying the issue and detailing the solution.

TL;DR The GNU Debugger requires a patch before it can work with MacOS. gdb v8.0.1 is the last known good version of GDB for MacOS.

  1. Uninstall the latest version of gdb (i.e. v8.1)

    brew uninstall --force gdb
    
  2. Force Homebrew to install a version of gdb with the patch for MacOS.

    brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/c3128a5c335bd2fa75ffba9d721e9910134e4644/Formula/gdb.rb
    
  3. Use the existing certificate to codesign the new install of gdb

    codesign -f -s  "<GNU GDB Certificate>" $(which gdb)
    

Now, gdb works as expected!

Special thanks to https://github.com/marcoparente and https://github.com/lokoum for their gist comments!

Zak
  • 12,213
  • 21
  • 59
  • 105
  • 1
    This solution was not working for me until I exported the certificate and both keys, private and public, from the Login keychain to the System Keychain. Now It worked. Thanks a lot. – aaguirre Mar 13 '18 at 23:43
  • 2
    Why Apple is making this so hard. I've made the whole thing work. A system upgrade makes me search everywhere again. – lkahtz Oct 03 '18 at 11:13
  • Note: this doesn't work in latest OSX (Mojave); downgrading gdb doesn't fix https://stackoverflow.com/questions/52529838/gdb-8-2-cant-recognized-executable-file-on-macos-mojave-10-14 – timotheecour Dec 02 '18 at 23:22
  • 2
    I will soon ditch this MacBook and go to pure Linux ... so user unfriendly. – Xofo Dec 11 '18 at 02:24
0

I got gdb working on Mojave yesterday by:

a) getting the latest gdb source archive (at time of writing, ftp://sourceware.org/pub/gdb/snapshots/current/gdb-weekly-8.2.50.20190212.tar.xz

b) build gdb. I got errors for variable shadowing in darwin-nat.c so I edited the file and rebuilt.

c) follow steps in https://forward-in-code.blogspot.com/2018/11/mojave-vs-gdb.html

Voila!

(source: GDB on Mac/Mojave: During startup program terminated with signal ?, Unknown signal)

Joubert Nel
  • 3,154
  • 3
  • 26
  • 24
0

Maybe a bit of unrelated:

Mac OS Sierra 10.13.6 gdb 8.0.1

had the same error as topic-starter.

https://gist.github.com/gravitylow/fb595186ce6068537a6e9da6d8b5b96d

I discovered that I already had gdbcert1 in my System. Followed everything from 7. Works!

Sergej Fomin
  • 1,822
  • 3
  • 24
  • 42