diff --git a/README.md b/README.md index 965092c..d0e7516 100644 --- a/README.md +++ b/README.md @@ -113,6 +113,8 @@ See table below for the behavior of **debug_break()** on other architecturs. Behavior on Different Architectures ---------------- +`__builtin_debugtrap()` is used wherever available, otherwise: + | Architecture | debug_break() | | ------------- | ------------- | | x86/x86-64 | `int3` | @@ -122,6 +124,4 @@ Behavior on Different Architectures | POWER | `.4byte 0x7d821008` | | RISC-V | `.4byte 0x00100073` | | MSVC compiler | `__debugbreak` | -| Apple compiler on AArch64 | `__builtin_trap()` | | Otherwise | `raise(SIGTRAP)` | - diff --git a/debugbreak.h b/debugbreak.h index bfb8288..36f3b79 100644 --- a/debugbreak.h +++ b/debugbreak.h @@ -37,8 +37,9 @@ extern "C" { #endif #define DEBUG_BREAK_USE_TRAP_INSTRUCTION 1 -#define DEBUG_BREAK_USE_BULTIN_TRAP 2 +#define DEBUG_BREAK_USE_BUILTIN_TRAP 2 #define DEBUG_BREAK_USE_SIGTRAP 3 +#define DEBUG_BREAK_USE_BUILTIN_DEBUGTRAP 4 #if defined(__i386__) || defined(__x86_64__) #define DEBUG_BREAK_IMPL DEBUG_BREAK_USE_TRAP_INSTRUCTION @@ -90,8 +91,6 @@ __inline__ static void trap_instruction(void) /* Known problem: * Same problem and workaround as Thumb mode */ } -#elif defined(__aarch64__) && defined(__APPLE__) - #define DEBUG_BREAK_IMPL DEBUG_BREAK_USE_BULTIN_DEBUGTRAP #elif defined(__aarch64__) #define DEBUG_BREAK_IMPL DEBUG_BREAK_USE_TRAP_INSTRUCTION __attribute__((always_inline)) @@ -133,6 +132,12 @@ __inline__ static void trap_instruction(void) #define DEBUG_BREAK_IMPL DEBUG_BREAK_USE_SIGTRAP #endif +#if defined(__has_builtin) +# if __has_builtin(__builtin_debugtrap) +# undef DEBUG_BREAK_IMPL +# define DEBUG_BREAK_IMPL DEBUG_BREAK_USE_BUILTIN_DEBUGTRAP +# endif +#endif #ifndef DEBUG_BREAK_IMPL #error "debugbreak.h is not supported on this target" @@ -142,13 +147,13 @@ __inline__ static void debug_break(void) { trap_instruction(); } -#elif DEBUG_BREAK_IMPL == DEBUG_BREAK_USE_BULTIN_DEBUGTRAP +#elif DEBUG_BREAK_IMPL == DEBUG_BREAK_USE_BUILTIN_DEBUGTRAP __attribute__((always_inline)) __inline__ static void debug_break(void) { __builtin_debugtrap(); } -#elif DEBUG_BREAK_IMPL == DEBUG_BREAK_USE_BULTIN_TRAP +#elif DEBUG_BREAK_IMPL == DEBUG_BREAK_USE_BUILTIN_TRAP __attribute__((always_inline)) __inline__ static void debug_break(void) {