GNOME Bugzilla – Bug 750807
G_BREAKPOINT doesn't work as intended on Darwin
Last modified: 2015-07-09 14:45:58 UTC
G_BREAKPOINT currently raises SIGTRAP on Apple platforms. However, SIGTRAP seems to be redirected (somehow) to the main thread, which is not very useful. Apple documentation indicates we should use __builtin_trap: https://developer.apple.com/library/mac/technotes/tn2124/_index.html#//apple_ref/doc/uid/DTS10003391-CH1-SECCONTROLLEDCRASH
Created attachment 305094 [details] [review] gbacktrace: support for Darwin (OSX, iOS) Please commit and push, since I don't have permission.
Created attachment 305095 [details] [review] gbacktrace: fix G_BREAKPOINT on Darwin (OSX, iOS) Improved commit message.
__builtin_trap() has apparently two drawbacks: 1) clang assumes all code after __builtin_trap() is dead, which might cause unwanted optimizations 2) naive attempts to resume in Xcode return to the __builtin_trap(). For that purpose, replacing __builtin_trap() with __asm__("brk #0x1") (on arm64) has the same result. Someone on Stack Overflow proposes using __asm__("svc 0"): http://stackoverflow.com/a/20713868/130066 With Xcode 6 and arm64 iOS target, this works as expected -- the breakpoint stops on the *following* instruction -- but it's a rather ugly workaround, so I'm not keen on using it.
Just to clarify, the patch is still way better than the current situation, so it should be applied.
Reviewed and committed by Patrick Griffis: https://git.gnome.org/browse/glib/commit/?id=27fae8390946e73e8343a7fd7505796f3599ee23