|
219 | 219 | #define SAFE_RELEASE(p) { if (p!=NULL) { (p)->Release(); (p)=NULL; } } |
220 | 220 |
|
221 | 221 |
|
| 222 | +#ifdef _MSC_VER |
| 223 | +# define DEBUG_BREAK __debugbreak |
| 224 | +#else |
| 225 | +#if defined(__has_builtin) && __has_builtin(__builtin_debugtrap) |
| 226 | +# define DEBUG_BREAK __builtin_debugtrap |
| 227 | +#else |
| 228 | +# if defined(__i386__) || defined(__x86_64__) |
| 229 | +__inline__ static void trap_instruction() { __asm__ volatile("int $3"); } |
| 230 | +# define DEBUG_BREAK trap_instruction |
| 231 | +# elif defined(__arm__) |
| 232 | +__attribute__((always_inline)) |
| 233 | +__inline__ static void trap_instruction() { __asm__ volatile("bkpt #0"); } |
| 234 | +# define DEBUG_BREAK trap_instruction |
| 235 | +# elif defined(__aarch64__) |
| 236 | +__attribute__((always_inline)) |
| 237 | +__inline__ static void trap_instruction() { __asm__ volatile("brk #0"); } |
| 238 | +# define DEBUG_BREAK trap_instruction |
| 239 | +# else |
| 240 | +# define DEBUG_BREAK __builtin_trap |
| 241 | +# endif |
| 242 | +#endif |
| 243 | +#endif |
| 244 | + |
222 | 245 | #define PRINT_ASSERT_MSG(exp, ...) |
223 | 246 |
|
224 | 247 | #ifdef _DEBUG |
|
232 | 255 | #define SIMPLE_ASSERT(exp) {if (!(exp) && 1 == _CrtDbgReport(_CRT_ASSERT, __FILE__, __LINE__, NULL, #exp)) _CrtDbgBreak();} |
233 | 256 | #define ASSERT(exp, ...) {static bool bIgnore(false); if (!bIgnore && !(exp)) {PRINT_ASSERT_MSG(exp, ##__VA_ARGS__); if (!(bIgnore = !(1 == _CrtDbgReport(_CRT_ASSERT, __FILE__, __LINE__, NULL, #exp)))) _CrtDbgBreak();}} |
234 | 257 | #else |
235 | | -#define SIMPLE_ASSERT(exp) {if (!(exp)) __debugbreak();} |
236 | | -#define ASSERT(exp, ...) {if (!(exp)) {PRINT_ASSERT_MSG(exp, ##__VA_ARGS__); __debugbreak();}} |
| 258 | +#define SIMPLE_ASSERT(exp) {if (!(exp)) DEBUG_BREAK();} |
| 259 | +#define ASSERT(exp, ...) {if (!(exp)) {PRINT_ASSERT_MSG(exp, ##__VA_ARGS__); DEBUG_BREAK();}} |
237 | 260 | #endif // _INC_CRTDBG |
238 | 261 | #define TRACE(...) {TCHAR buffer[2048]; _sntprintf(buffer, 2048, __VA_ARGS__); OutputDebugString(buffer);} |
239 | 262 | #else // _MSC_VER |
240 | 263 | #include <assert.h> |
241 | | -#define SIMPLE_ASSERT(exp) {if (!(exp)) assert(exp);} |
242 | | -#define ASSERT(exp, ...) {if (!(exp)) {PRINT_ASSERT_MSG(exp, ##__VA_ARGS__); assert(exp);}} |
| 264 | +#define SIMPLE_ASSERT(exp) {if (!(exp)) DEBUG_BREAK();} |
| 265 | +#define ASSERT(exp, ...) {if (!(exp)) {PRINT_ASSERT_MSG(exp, ##__VA_ARGS__); DEBUG_BREAK();}} |
243 | 266 | #define TRACE(...) |
244 | 267 | #endif // _MSC_VER |
245 | 268 |
|
|
0 commit comments