GDB errors on macOS Mojave
Asked Answered
A

2

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?

Aldaaldan answered 17/2, 2019 at 19:19 Comment(2)
You might want to look at this issue. 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.Hayton
That tip helped, @SimonWright. I got a slightly later archive of the gdb sources at sourceware.org/pub/gdb/snapshots/current/…. 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!Aldaaldan
A
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.

Aldaaldan answered 18/2, 2019 at 17:10 Comment(3)
I too encountered the problems with darwin-nat.c. I looked at the warnings and decided they weren’t harmful, so configured with --disable-werror.Hayton
Hi @Simon, what's the exact command line you used for configuring?Price
Here, see gdb.sh (and common.sh)Hayton
C
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.

Cammiecammy answered 22/8, 2020 at 9:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.