Skip to content

Commit e134eb4

Browse files
committed
common: now ASSERT breaks deugger on all platforms
1 parent 8089fd7 commit e134eb4

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

libs/Common/Config.h

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,29 @@
219219
#define SAFE_RELEASE(p) { if (p!=NULL) { (p)->Release(); (p)=NULL; } }
220220

221221

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+
222245
#define PRINT_ASSERT_MSG(exp, ...)
223246

224247
#ifdef _DEBUG
@@ -232,14 +255,14 @@
232255
#define SIMPLE_ASSERT(exp) {if (!(exp) && 1 == _CrtDbgReport(_CRT_ASSERT, __FILE__, __LINE__, NULL, #exp)) _CrtDbgBreak();}
233256
#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();}}
234257
#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();}}
237260
#endif // _INC_CRTDBG
238261
#define TRACE(...) {TCHAR buffer[2048]; _sntprintf(buffer, 2048, __VA_ARGS__); OutputDebugString(buffer);}
239262
#else // _MSC_VER
240263
#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();}}
243266
#define TRACE(...)
244267
#endif // _MSC_VER
245268

0 commit comments

Comments
 (0)