Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` |
Expand All @@ -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)` |

15 changes: 10 additions & 5 deletions debugbreak.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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"
Expand All @@ -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)
{
Expand Down