|
| 1 | +//----------------------------------------------------------------------- |
| 2 | +// github.com/samisalreadytaken/sqdbg |
| 3 | +//----------------------------------------------------------------------- |
| 4 | +// |
| 5 | + |
| 6 | +#ifndef SQDBG_DEBUG_H |
| 7 | +#define SQDBG_DEBUG_H |
| 8 | + |
| 9 | +#if 0 |
| 10 | + |
| 11 | +#ifdef _DEBUG |
| 12 | + #ifdef _WIN32 |
| 13 | + #include <crtdbg.h> |
| 14 | + |
| 15 | + bool __IsDebuggerPresent(); |
| 16 | + const char *GetModuleBaseName(); |
| 17 | + |
| 18 | + #define DebuggerBreak() do { if ( __IsDebuggerPresent() ) __debugbreak(); } while(0) |
| 19 | + |
| 20 | + #define Assert( x ) \ |
| 21 | + do { \ |
| 22 | + __CAT( L, __LINE__ ): \ |
| 23 | + if ( !(x) && (1 == _CrtDbgReport(_CRT_ASSERT, __FILE__, __LINE__, GetModuleBaseName(), #x)) ) \ |
| 24 | + { \ |
| 25 | + if ( !__IsDebuggerPresent() ) \ |
| 26 | + goto __CAT( L, __LINE__ ); \ |
| 27 | + __debugbreak(); \ |
| 28 | + } \ |
| 29 | + } while(0) |
| 30 | + |
| 31 | + #define AssertMsg( x, msg ) \ |
| 32 | + do { \ |
| 33 | + __CAT( L, __LINE__ ): \ |
| 34 | + if ( !(x) && (1 == _CrtDbgReport(_CRT_ASSERT, __FILE__, __LINE__, GetModuleBaseName(), msg)) ) \ |
| 35 | + { \ |
| 36 | + if ( !__IsDebuggerPresent() ) \ |
| 37 | + goto __CAT( L, __LINE__ ); \ |
| 38 | + __debugbreak(); \ |
| 39 | + } \ |
| 40 | + } while(0) |
| 41 | + |
| 42 | + #define AssertMsg1( x, msg, a1 ) \ |
| 43 | + do { \ |
| 44 | + __CAT( L, __LINE__ ): \ |
| 45 | + if ( !(x) && (1 == _CrtDbgReport(_CRT_ASSERT, __FILE__, __LINE__, GetModuleBaseName(), msg, a1)) ) \ |
| 46 | + { \ |
| 47 | + if ( !__IsDebuggerPresent() ) \ |
| 48 | + goto __CAT( L, __LINE__ ); \ |
| 49 | + __debugbreak(); \ |
| 50 | + } \ |
| 51 | + } while(0) |
| 52 | + |
| 53 | + #define AssertMsg2( x, msg, a1, a2 ) \ |
| 54 | + do { \ |
| 55 | + __CAT( L, __LINE__ ): \ |
| 56 | + if ( !(x) && (1 == _CrtDbgReport(_CRT_ASSERT, __FILE__, __LINE__, GetModuleBaseName(), msg, a1, a2)) ) \ |
| 57 | + { \ |
| 58 | + if ( !__IsDebuggerPresent() ) \ |
| 59 | + goto __CAT( L, __LINE__ ); \ |
| 60 | + __debugbreak(); \ |
| 61 | + } \ |
| 62 | + } while(0) |
| 63 | + #else |
| 64 | + extern "C" int printf(const char *, ...); |
| 65 | + |
| 66 | + #define DebuggerBreak() asm("int3") |
| 67 | + |
| 68 | + #define Assert( x ) \ |
| 69 | + do { \ |
| 70 | + if ( !(x) ) \ |
| 71 | + { \ |
| 72 | + ::printf("Assertion failed %s:%d: %s\n", __FILE__, __LINE__, #x); \ |
| 73 | + DebuggerBreak(); \ |
| 74 | + } \ |
| 75 | + } while(0) |
| 76 | + |
| 77 | + #define AssertMsg( x, msg ) \ |
| 78 | + do { \ |
| 79 | + if ( !(x) ) \ |
| 80 | + { \ |
| 81 | + ::printf("Assertion failed %s:%d: %s\n", __FILE__, __LINE__, msg); \ |
| 82 | + DebuggerBreak(); \ |
| 83 | + } \ |
| 84 | + } while(0) |
| 85 | + |
| 86 | + #define AssertMsg1( x, msg, a1 ) \ |
| 87 | + do { \ |
| 88 | + if ( !(x) ) \ |
| 89 | + { \ |
| 90 | + ::printf("Assertion failed %s:%d: ", __FILE__, __LINE__); \ |
| 91 | + ::printf(msg, a1); \ |
| 92 | + ::printf("\n"); \ |
| 93 | + DebuggerBreak(); \ |
| 94 | + } \ |
| 95 | + } while(0) |
| 96 | + |
| 97 | + #define AssertMsg2( x, msg, a1, a2 ) \ |
| 98 | + do { \ |
| 99 | + if ( !(x) ) \ |
| 100 | + { \ |
| 101 | + ::printf("Assertion failed %s:%d: ", __FILE__, __LINE__); \ |
| 102 | + ::printf(msg, a1, a2); \ |
| 103 | + ::printf("\n"); \ |
| 104 | + DebuggerBreak(); \ |
| 105 | + } \ |
| 106 | + } while(0) |
| 107 | + #endif |
| 108 | + #define Verify( x ) Assert(x) |
| 109 | +#else |
| 110 | + #define DebuggerBreak() ((void)0) |
| 111 | + #define Assert( x ) ((void)0) |
| 112 | + #define AssertMsg( x, msg ) ((void)0) |
| 113 | + #define AssertMsg1( x, msg, a1 ) ((void)0) |
| 114 | + #define AssertMsg2( x, msg, a1, a2 ) ((void)0) |
| 115 | + #define Verify( x ) x |
| 116 | +#endif // _DEBUG |
| 117 | + |
| 118 | +#endif |
| 119 | + |
| 120 | +#include <tier0/dbg.h> |
| 121 | + |
| 122 | +// Misdefined for GCC in platform.h |
| 123 | +#undef UNREACHABLE |
| 124 | + |
| 125 | +#ifdef _WIN32 |
| 126 | + #define UNREACHABLE() do { Assert(!"UNREACHABLE"); __assume(0); } while(0) |
| 127 | +#else |
| 128 | + #define UNREACHABLE() do { Assert(!"UNREACHABLE"); __builtin_unreachable(); } while(0) |
| 129 | +#endif |
| 130 | + |
| 131 | +#endif // SQDBG_DEBUG_H |
0 commit comments