debugbreak icon indicating copy to clipboard operation
debugbreak copied to clipboard

__builtin_debugtrap detection is wrong

Open jwakely opened this issue 3 years ago • 3 comments

You use defined(__APPLE__) to decide whether to use __builtin_debugtrap but that's wrong, because only Clang supports that built-in, but GCC defines __APPLE__ too.

The minimal fix would be to just check defined(__clang__) instead of defined(__APPLE__).

I don't see any reason to restrict the use of __builtin_debugtrap() to aarch64 on macOS, you could use it on all platforms when compiling with Clang. For x86 it expands to int 3 which is what your own code does. For ARM it expands to .inst 0xe7f001f0 which is the same as your code again.

To use __builtin_debugtrap() whenever the compiler supports it, you can do something like:

#ifdef __has_builtin
# if __has_builtin(__builtin_debugtrap)
#  define DEBUG_BREAK_IMPL DEBUG_BREAK_USE_BUILTIN_DEBUGTRAP
# endif
#endif

#ifndef DEBUG_BREAK_IMPL
// ... existing code ...
#endif

jwakely avatar Jan 04 '22 14:01 jwakely

@jwakely do you have a fork with these fixes?

ericoporto avatar May 02 '23 01:05 ericoporto

No, maybe I'll create one tomorrow though

jwakely avatar May 02 '23 07:05 jwakely