From 51781c481efc56dd06cbfe75c356b3aae600f0bc Mon Sep 17 00:00:00 2001 From: WormHeamer Date: Sat, 27 Dec 2025 22:24:53 -0500 Subject: better TRAP() implementation --- wrmr.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/wrmr.h b/wrmr.h index 2a86040..67523ec 100644 --- a/wrmr.h +++ b/wrmr.h @@ -31,9 +31,12 @@ typedef uintptr_t uptr; #define HAS_BUILTIN(x) 0 #endif -#if HAS_BUILTIN(__builtin_debugtrap) +#if defined(__i368__) || defined(__x86_64__) +/* nop so gdb will break on the trap, not the line after */ +# define TRAP() __asm__ volatile ("int3; nop") +#elif HAS_BUILTIN(__builtin_debugtrap) # define TRAP() __builtin_debugtrap() -#elif HAS_BUILTIN(__builtin_trap) +#elif HAS_BUILTIN(__builtin_trap) && defined(__STDC_HOSTED__) && (__STDC_HOSTED__ == 0) # define TRAP() __builtin_trap() #elif defined(_MSC_VER) # define TRAP() __debugbreak() @@ -62,7 +65,7 @@ typedef uintptr_t uptr; #else # if __STDC_VERSION__ >= 202311L # define UNREACHABLE_MSG(msg) (unreachable()) -# elif HAVE_BUILTIN(__builtin_unreachable) +# elif HAS_BUILTIN(__builtin_unreachable) # define UNREACHABLE_MSG(msg) (__builtin_unreachable()) # elif defined(_MSC_VER) # define UNREACHABLE_MSG(msg) (__assume(0)) @@ -76,7 +79,7 @@ typedef uintptr_t uptr; #ifdef NDEBUG # if defined(_MSC_VER) # define ASSUME(...) (__assume(__VA_ARGS__)) -# elif HAVE_BUILTIN(__builtin_assume) +# elif HAS_BUILTIN(__builtin_assume) # define ASSUME(...) (__builtin_assume(__VA_ARGS__)) # endif #else -- cgit v1.2.3