NexusForce 1.0.0
A Modern C++ Library with extended functionality, web components, and utility libraries
载入中...
搜索中...
未找到
breakpoint.hpp
浏览该文件的文档.
1#ifndef NEFORCE_CORE_EXCEPTION_BREAKPOINT_HPP__
2#define NEFORCE_CORE_EXCEPTION_BREAKPOINT_HPP__
3
11
13NEFORCE_BEGIN_NAMESPACE__
14
20
21#if defined(NEFORCE_STATE_DEBUG) || defined(NEXUSFORCE_ENABLE_DOXYGEN)
28# define NEFORCE_DEBUG_VERIFY(CON, MESG) \
29 { \
30 if (CON) { \
31 } else { \
32 assert(false && MESG); \
33 } \
34 }
35#else
36# define NEFORCE_DEBUG_VERIFY(CON, MESG)
37#endif
38
39#if defined(NEFORCE_STANDARD_20) || defined(NEXUSFORCE_ENABLE_DOXYGEN)
47# define NEFORCE_CONSTEXPR_ASSERT(COND) \
48 do { \
49 if (_NEFORCE is_constant_evaluated() && !bool(COND)) { \
50 _NEFORCE unreachable(); \
51 } \
52 } while (false);
53#else
54# define NEFORCE_CONSTEXPR_ASSERT(COND)
55#endif
56
57
68NEFORCE_NORETURN NEFORCE_ALWAYS_INLINE_INLINE void unreachable() noexcept {
69#ifdef NEFORCE_COMPILER_GNUC
70 __builtin_unreachable();
71#else
72 __assume(false);
73#endif
74}
75
76#if defined(NEFORCE_STANDARD_17) || defined(NEXUSFORCE_ENABLE_DOXYGEN)
83NEFORCE_NODISCARD NEFORCE_ALWAYS_INLINE_INLINE constexpr bool is_constant_evaluated() noexcept {
84 return __builtin_is_constant_evaluated();
85}
86#endif
87
92bool NEFORCE_API is_debugger_present();
93
102void NEFORCE_API debug_assert(bool condition, const char* message = nullptr);
103
109NEFORCE_ALWAYS_INLINE_INLINE void breakpoint() noexcept {
110#ifdef NEFORCE_PLATFORM_WINDOWS
111 __debugbreak();
112#else
113# ifdef NEFORCE_COMPILER_CLANG
114 __builtin_debugtrap();
115# elif defined(NEFORCE_ARCH_X86)
116 asm volatile("int3");
117# elif defined(NEFORCE_ARCH_AARCH64)
118 asm volatile(".inst 0xd4200000");
119# elif defined(NEFORCE_ARCH_ARM32)
120 asm volatile(".inst 0xe7f001f0");
121# elif defined(NEFORCE_ARCH_RISCV)
122 asm volatile("ebreak");
123# elif defined(NEFORCE_ARCH_LOONGARCH)
124 asm volatile("break 0");
125# else
126 __builtin_trap();
127# endif
128#endif
129}
130
137NEFORCE_ALWAYS_INLINE_INLINE void breakpoint_if_debugging() {
138 if (is_debugger_present()) {
139 breakpoint();
140 }
141}
142 // DebugBreakpointsAndAssertions
144
145NEFORCE_END_NAMESPACE__
146#endif // NEFORCE_CORE_EXCEPTION_BREAKPOINT_HPP__
核心配置头文件
bool NEFORCE_API is_debugger_present()
检测当前进程是否正在被调试器附加
NEFORCE_ALWAYS_INLINE_INLINE void breakpoint_if_debugging()
如果正在调试则触发断点
void NEFORCE_API debug_assert(bool condition, const char *message=nullptr)
调试断言
NEFORCE_NODISCARD NEFORCE_ALWAYS_INLINE_INLINE constexpr bool is_constant_evaluated() noexcept
检查当前上下文是否在常量求值中
NEFORCE_NORETURN NEFORCE_ALWAYS_INLINE_INLINE void unreachable() noexcept
标记不可达代码路径
NEFORCE_ALWAYS_INLINE_INLINE void breakpoint() noexcept
触发调试断点