prefer C++ compiler builtins for BREAKPOINT

Fix breakpoints on macOS to trap EXC_BREAKPOINT with correct
source location when using lldb. Old behavior with `raise(SIGTRAP)`
traps SIGTRAP and incorrect source location.

Fix breakpoints on archlinux to trap SIGILL with correct source
location when using gdb. Old behavior with `raise(SIGTRAP)`
traps SIGTRAP and (sometimes) incorrect source location with
very shallow (break in main) stack.

when building stage1:
- w/ clang, use `__builtin_debugtrap()`
- w/ gcc, use `__builtin_trap()`
- else use `raise(SIGTRAP)`
This commit is contained in:
Michael Dusan 2020-01-12 16:10:17 -05:00
parent c96131f30c
commit 25b1ae0a5f
No known key found for this signature in database
GPG Key ID: ED4C5BA849FA1B74

View File

@ -30,8 +30,6 @@
#else
#include <signal.h>
#define ATTRIBUTE_COLD __attribute__((cold))
#define ATTRIBUTE_PRINTF(a, b) __attribute__((format(printf, a, b)))
#define ATTRIBUTE_RETURNS_NOALIAS __attribute__((__malloc__))
@ -40,7 +38,12 @@
#if defined(__MINGW32__) || defined(__MINGW64__)
#define BREAKPOINT __debugbreak()
#elif defined(__clang__)
#define BREAKPOINT __builtin_debugtrap()
#elif defined(__GNUC__)
#define BREAKPOINT __builtin_trap()
#else
#include <signal.h>
#define BREAKPOINT raise(SIGTRAP)
#endif