diff options
author | Oxore <oxore@protonmail.com> | 2025-01-03 17:07:00 +0300 |
---|---|---|
committer | Oxore <oxore@protonmail.com> | 2025-01-07 14:39:01 +0300 |
commit | cb96278e25140cfcc1afc22df2102bcf3b6ae38c (patch) | |
tree | 9e93bd8a5fb4d5fbc177924b6b25ca8cd04e7fd7 /src/debug.h | |
parent | 810dc87cd5173f8cfc81c774fd49cf8f928a9ae8 (diff) |
Impl extended trace table format parser
Diffstat (limited to 'src/debug.h')
-rw-r--r-- | src/debug.h | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/debug.h b/src/debug.h new file mode 100644 index 0000000..4cd1b58 --- /dev/null +++ b/src/debug.h @@ -0,0 +1,45 @@ +#pragma once + +/* SPDX-License-Identifier: Unlicense + */ + +#ifdef NDEBUG +#define __DEBUG 0 +#else +#define __DEBUG 1 +#endif + +#ifndef __TRACE +#define __TRACE 0 +#endif + +#define TRACE(format, ...) \ + if (__TRACE) fprintf(stderr, "%s:%d %s: " format "\n", \ + __FILE__, __LINE__, __func__ __VA_OPT__(,) __VA_ARGS__) + +#if defined(__SANITIZE_ADDRESS__) || defined(__SANITIZE_THREAD__) +#define __SANITIZER_PRINT_STACK_TRACE() __sanitizer_print_stack_trace() +#include <sanitizer/common_interface_defs.h> +#else +#define __SANITIZER_PRINT_STACK_TRACE() +#endif + +#if __DEBUG +#define ASSERT(x) ((x) ? (void)(x) : (__SANITIZER_PRINT_STACK_TRACE(), assert(x))) +#define ASSERT_CONSUME(x) ASSERT(x) +#define UNREACHABLE_BODY() (ASSERT(!"unreachable code reached"), abort()) +#else +#define ASSERT(x) ((void)0) +#define ASSERT_CONSUME(x) ((void)(x)) +#define UNREACHABLE_BODY() ((void)0) +#endif + +#include <cassert> + +#ifdef __GNUC__ +#define BUILTIN_UNREACHABLE() __builtin_unreachable() +#else +#define BUILTIN_UNREACHABLE() ((void)0) +#endif + +#define UNREACHABLE() (UNREACHABLE_BODY(), BUILTIN_UNREACHABLE()) |