Skip to content

Instantly share code, notes, and snippets.

@dk949
Last active September 1, 2025 13:54
Show Gist options
  • Save dk949/e36f1a7ecc9a8aff296ee6e76a06ba68 to your computer and use it in GitHub Desktop.
Save dk949/e36f1a7ecc9a8aff296ee6e76a06ba68 to your computer and use it in GitHub Desktop.
Portable(ish) breakpoint macros
#ifndef UT_BREAKPOINT_HPP
#define UT_BREAKPOINT_HPP
#ifndef __has_builtin
# define UT_DETAIL_HAS_BUILTIN(x) 0
#else
# define UT_DETAIL_HAS_BUILTIN(x) __has_builtin(x)
#endif
#if defined(__GNUC__)
# if UT_DETAIL_HAS_BUILTIN(__builtin_debugtrap)
# define UT_BREAKPOINT() \
do { \
__builtin_debugtrap(); \
} while (false)
# elif defined(__i386__) || defined(__x86_64__)
# define UT_BREAKPOINT() \
do { \
asm volatile("int3"); \
} while (false)
# endif
#elif defined(_MSC_VER)
# include <intrin.h>
# define UT_BREAKPOINT() \
do { \
__debugbreak(); \
} while (false)
#endif
#ifndef UT_BREAKPOINT
# include <csignal>
# define UT_BREAKPOINT() \
do { \
std::raise(SIGTRAP); \
} while (false)
#endif
#endif // UT_BREAKPOINT_HPP
Portable(ish) breakpoint macros
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment