diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2021-01-20 16:47:05 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2021-01-20 16:47:05 +0000 |
| commit | c5031be4899ea516635ef7c65a6f82b3b45860b9 (patch) | |
| tree | 10948eb4aface28e80d6a075fecf11fad3075618 /debug.h | |
| parent | Merge branch 'decset-1047-and-1048' (diff) | |
| parent | debug: rename assert() to xassert(), to avoid clashing with <assert.h> (diff) | |
Merge branch 'stacktrace'
Diffstat (limited to 'debug.h')
| -rw-r--r-- | debug.h | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/debug.h b/debug.h new file mode 100644 index 00000000..fcc09830 --- /dev/null +++ b/debug.h @@ -0,0 +1,30 @@ +#pragma once + +#include "macros.h" + +#ifdef NDEBUG + #define BUG(...) UNREACHABLE() +#else + #define BUG(...) bug(__FILE__, __LINE__, __func__, __VA_ARGS__) +#endif + +#define xassert(x) do { \ + IGNORE_WARNING("-Wtautological-compare") \ + if (unlikely(!(x))) { \ + BUG("assertion failed: '%s'", #x); \ + } \ + UNIGNORE_WARNINGS \ +} while (0) + +#ifndef static_assert + #if __STDC_VERSION__ >= 201112L + #define static_assert(x, msg) _Static_assert((x), msg) + #elif GNUC_AT_LEAST(4, 6) || HAS_EXTENSION(c_static_assert) + #define static_assert(x, msg) __extension__ _Static_assert((x), msg) + #else + #define static_assert(x, msg) + #endif +#endif + +noreturn void fatal_error(const char *msg, int err) COLD; +noreturn void bug(const char *file, int line, const char *func, const char *fmt, ...) PRINTF(4) COLD; |
