Last active
September 1, 2025 13:54
-
-
Save dk949/e36f1a7ecc9a8aff296ee6e76a06ba68 to your computer and use it in GitHub Desktop.
Portable(ish) breakpoint macros
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Portable(ish) breakpoint macros |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment