mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-12-25 23:13:39 +00:00
[common] debug: add DEBUG_ASSERT macro
This, unlike the standard assert macro, is guaranteed to print the failed assertion to our log file, and tests the assertion even with NDEBUG defined so we can more easily catch failures in production binaries without crashing the program. The motivation of this is how MinGW handles assertion failures: it creates a dialog window that the headless user will not be able to see, and blocks the program from being restarted by the service. Since the failed assertion is displayed in the dialog, it doesn't print anything to the log, making it impossible to diagnose issues.
This commit is contained in:
parent
10ee6cd031
commit
be1306f91a
@ -97,6 +97,23 @@ void printBacktrace(void);
|
||||
abort(); \
|
||||
} while(0)
|
||||
|
||||
#define DEBUG_ASSERT_PRINT(...) DEBUG_ERROR("Assertion failed: %s", #__VA_ARGS__)
|
||||
|
||||
#ifdef NDEBUG
|
||||
#define DEBUG_ASSERT(...) do { \
|
||||
if (!(__VA_ARGS__)) \
|
||||
DEBUG_ASSERT_PRINT(__VA_ARGS__); \
|
||||
} while (0)
|
||||
#else
|
||||
#define DEBUG_ASSERT(...) do { \
|
||||
if (!(__VA_ARGS__)) \
|
||||
{ \
|
||||
DEBUG_ASSERT_PRINT(__VA_ARGS__); \
|
||||
abort(); \
|
||||
} \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
#if defined(DEBUG_SPICE) | defined(DEBUG_IVSHMEM)
|
||||
#define DEBUG_PROTO(fmt, args...) DEBUG_PRINT("[P]", fmt, ##args)
|
||||
#else
|
||||
|
Loading…
Reference in New Issue
Block a user