π prelude
Useful C header files
Loading...
Searching...
No Matches
debug.h
Go to the documentation of this file.
1
/*
2
* π prelude - debug.h
3
* Copyright (c) 2026 Fawn <rubiefawn@gmail.com>
4
*
5
* Permission to use, copy, modify, and distribute this software for any
6
* purpose with or without fee is hereby granted, provided that the above
7
* copyright notice and this permission notice appear in all copies.
8
*
9
* THE SOFTWARE IS PROVIDED βAS ISβ AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
*/
17
20
#pragma once
21
#include "
hint.h
"
22
29
#ifdef NDEBUG
30
#include <stdlib.h>
31
#define debug_break() abort()
32
#elif defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
33
#include <signal.h>
34
#define debug_break() raise(SIGTRAP)
35
#elif defined(_WIN32)
36
#include <intrin.h>
37
#define debug_break() __debugbreak()
38
#else
39
#warning No debug break intrinsic found, debug_break() will exit instead
40
#include <stdlib.h>
41
#define debug_break() exit(EXIT_FAILURE)
42
#endif
43
53
#define debug_msg_always(FMT, ...) fprintf(stderr, __FILE__ ":%d:%s: " FMT "\n", __LINE__, __func__ __VA_OPT__(,) __VA_ARGS__)
54
56
#define panic(FMT, ...) do { debug_msg_always(FMT __VA_OPT__(,) __VA_ARGS__); debug_break(); } while (0)
57
67
#ifdef NDEBUG
68
#define debug_msg(FMT, ...)
69
#else
70
#define debug_msg(FMT, ...) debug_msg_always(FMT __VA_OPT__(,) __VA_ARGS__)
71
#endif
72
81
#ifdef NDEBUG
82
#define assert_msg(COND, FMT, ...) assume(COND)
83
#else
84
#define assert_msg(COND, FMT, ...) do { if (COND) {} else { panic(FMT __VA_OPT__(,) __VA_ARGS__); } } while (0)
85
#endif
hint.h
Compiler hints for performance.
debug.h
Generated by
1.16.1