1

Environment: Mac/Mojave and GDB 8.2.1 (via homebrew).

I worked through instructions https://forward-in-code.blogspot.com/2018/11/mojave-vs-gdb.html i.e.:

  • latest GDB via brew, which solves the executable format issue

  • sign GDB with new entitlements

Additionally, I've also modified SIP to allow debugging (in Recovery OS terminal: csrutil enable --without debug).

However, I still can’t get gdb to work:

(gdb) file main
Reading symbols from main...done.
(gdb) run
Starting program: /Users/joubertold/code/Rhodus/obj/debug/main 
[New Thread 0x1a03 of process 5082]
[New Thread 0x2803 of process 5082]
During startup program terminated with signal ?, Unknown signal.
(gdb) 

Interestingly, lldb works for me on the same binary:

(lldb) file main
Current executable set to 'main' (x86_64).
(lldb) run
Process 5086 launched: '/Users/joubertold/code/Rhodus/obj/debug/main' (x86_64)
Rhodus
 1 is ONE
 1 is between 1 and 10
 1 is between 1 and 10
 1 is between 1 and 10
 1 is between 1 and 10
 1 is between 1 and 10
 1 is between 1 and 10
 1 is between 1 and 10
 1 is between 1 and 10
 1 is beyond
 1 is beyond
 1 is beyond
Process 5086 exited with status = 0 (0x00000000) 
(lldb) 

Any thoughts?

Joubert Nel
  • 3,154
  • 3
  • 26
  • 24
  • 1
    You might want to look at [this issue](https://github.com/Homebrew/homebrew-core/pull/35419#issuecomment-451692800). I don’t know what version brew has loaded for you, the version I uploaded and refer to in the blog post (`gdb --version`) is GNU gdb (GDB) 8.2.50.20190112-git. – Simon Wright Feb 17 '19 at 23:20
  • That tip helped, @SimonWright. I got a slightly later archive of the gdb sources at ftp://sourceware.org/pub/gdb/snapshots/current/gdb-weekly-8.2.50.20190212.tar.xz. I also had to edit darwin-nat.c to remove 3 cases of variable shadowing. I can now use gdb in GNAT Programming Studio. Thanks! – Joubert Nel Feb 18 '19 at 04:49

2 Answers2

1

I got gdb working on Mojave 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) - amongst other things, it adds handling for recognizing executables on Mac.

b) build gdb. I got errors for variable shadowing in darwin-nat.c so I edited the file and rebuilt (diff https://gist.github.com/joubertnel/267ca0fff4eaad494cc19ec3ba7953ed).

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

Voila.

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

Unfortunately, the accepted answer doesn't work for me.

For anyone in the same situation with me, I suggest using Visual Studio Code or Xcode to debug your C program instead.

Lansorian
  • 149
  • 3
  • 11