Bug 20266 - Broken gdb with Apple's macOS 10.12 Sierra Beta - SIGTRAP
Summary: Broken gdb with Apple's macOS 10.12 Sierra Beta - SIGTRAP
Status: UNCONFIRMED
Alias: None
Product: gdb
Classification: Unclassified
Component: gdb (show other bugs)
Version: 7.11.1
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-06-16 22:42 UTC by nikolaikrill
Modified: 2016-12-25 12:16 UTC (History)
6 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description nikolaikrill 2016-06-16 22:42:06 UTC
Just tried out Apple's new beta of the next version of OS X, namely macOS 10.12 Sierra. A freshly compiled gdb 7.11.1 is not capable of debugging anything I've tried yet, it always fails with:

During startup program terminated with signal SIGTRAP, Trace/breakpoint trap.

This is an issue specific to macOS 10.12 beta, the same gdb works fine under Mac OS X 10.11. I'm not sure if this is an Apple issue or one with gdb, just thought I should let you guys know. Also, lldb is working fine on macOS 10.12, so there's that.


(gdb) run
Starting program: /Users/k/Desktop/gdb-test/test_program 
During startup program terminated with signal SIGTRAP, Trace/breakpoint trap.
(gdb)
Comment 1 antonio.luis.sarmento 2016-09-23 13:01:53 UTC
So, the official, final release of Sierra is here and I'm here (alongside another user) to confirm this problem exists and should be treated *ASAP!

Link to my recently-created thread on Reddit:
https://www.reddit.com/r/learnprogramming/comments/53zmls/gdb_itself_is_crashing_and_i_cant_seem_to_find_a/d7xs95g?context=3
Comment 2 Pedro Alves 2016-09-23 19:15:03 UTC
Unfortunately, I don't think that any active maintainer uses macOS routinely.  So this likely will only get fixed when someone contributes a fix or investigates what the problem is.
Comment 3 Pedro Alves 2016-09-23 19:19:32 UTC
Note that "During startup program terminated..." indicates that it's the shell that died.  GDB starts the program like "sh -c '$program $arg1 $arg2'".

Usually, on Unix systems, gdb will see one SIGTRAP that indicates that the shell execed the final program, and so gdb is now actually debugging the program.

Maybe the problems is that now on macOS gdb needs to expect two traps.

See the START_INFERIOR_TRAPS_EXPECTED define in gdb's sources.  Try bumping it.

But first try the "set startup-with-shell off" command.
Comment 4 nikolaikrill 2016-10-06 18:32:38 UTC
(In reply to Pedro Alves from comment #3)
> Note that "During startup program terminated..." indicates that it's the
> shell that died.  GDB starts the program like "sh -c '$program $arg1 $arg2'".
> 
> Usually, on Unix systems, gdb will see one SIGTRAP that indicates that the
> shell execed the final program, and so gdb is now actually debugging the
> program.
> 
> Maybe the problems is that now on macOS gdb needs to expect two traps.
> 
> See the START_INFERIOR_TRAPS_EXPECTED define in gdb's sources.  Try bumping
> it.
> 
> But first try the "set startup-with-shell off" command.
Thanks for your input, Pedro. I've tried both of your suggestions, but the problem still persists.

What's strange is that the problem was fixed when I tried using gdb in Apple's later betas of Sierra, but then the issue reappeared in the official public release. Now, though, the error message has changed to the following:

During startup program terminated with signal SIG113, Real-time event 113.

I've also verified that the problem exists on macOS 10.12.1 Beta 3 (Build 16B2338c). The issue appears to be affecting everybody using gdb on Sierra, and threads on the topic have started appearing on Stack Overflow and other forums, but nobody seems to have solution yet.
Comment 5 Pedro Alves 2016-10-14 16:12:47 UTC
Seems like someone found a workaround:
 https://sourceware.org/ml/gdb/2016-10/msg00009.html
Comment 6 Tom Tromey 2016-11-01 03:40:40 UTC
This seems to hold the answer:

https://sourceware.org/ml/gdb/2016-10/msg00062.html
Comment 7 Tom Tromey 2016-11-11 17:13:29 UTC
A partial fix went in:
https://sourceware.org/ml/gdb/2016-11/msg00011.html

But apparently it still needs "set startup-with-shell off"