Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 1 | /* |
| 2 | * kmp_debug.h -- debug / assertion code for Assure library |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 3 | */ |
| 4 | |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 5 | //===----------------------------------------------------------------------===// |
| 6 | // |
| 7 | // The LLVM Compiler Infrastructure |
| 8 | // |
| 9 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 10 | // Source Licenses. See LICENSE.txt for details. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 14 | #ifndef KMP_DEBUG_H |
| 15 | #define KMP_DEBUG_H |
| 16 | |
| 17 | #include <stdarg.h> |
| 18 | |
| 19 | #ifdef __cplusplus |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 20 | extern "C" { |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 21 | #endif // __cplusplus |
| 22 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 23 | // ----------------------------------------------------------------------------- |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 24 | // Build-time assertion. |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 25 | |
Jonathan Peyton | 3692fcf | 2017-01-18 07:49:30 +0000 | [diff] [blame] | 26 | // New C++11 style build assert |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 27 | #define KMP_BUILD_ASSERT(expr) static_assert(expr, "Build condition error") |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 28 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 29 | // ----------------------------------------------------------------------------- |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 30 | // Run-time assertions. |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 31 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 32 | extern void __kmp_dump_debug_buffer(void); |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 33 | |
| 34 | #ifdef KMP_USE_ASSERT |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 35 | extern int __kmp_debug_assert(char const *expr, char const *file, int line); |
| 36 | #ifdef KMP_DEBUG |
| 37 | #define KMP_ASSERT(cond) \ |
Jonathan Peyton | baad3f6 | 2018-08-09 22:04:30 +0000 | [diff] [blame] | 38 | if (!(cond)) { \ |
| 39 | __kmp_debug_assert(#cond, __FILE__, __LINE__); \ |
| 40 | } |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 41 | #define KMP_ASSERT2(cond, msg) \ |
Jonathan Peyton | baad3f6 | 2018-08-09 22:04:30 +0000 | [diff] [blame] | 42 | if (!(cond)) { \ |
| 43 | __kmp_debug_assert((msg), __FILE__, __LINE__); \ |
| 44 | } |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 45 | #define KMP_DEBUG_ASSERT(cond) KMP_ASSERT(cond) |
| 46 | #define KMP_DEBUG_ASSERT2(cond, msg) KMP_ASSERT2(cond, msg) |
Jonathan Peyton | baad3f6 | 2018-08-09 22:04:30 +0000 | [diff] [blame] | 47 | #define KMP_DEBUG_USE_VAR(x) /* Nothing (it is used!) */ |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 48 | #else |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 49 | // Do not expose condition in release build. Use "assertion failure". |
| 50 | #define KMP_ASSERT(cond) \ |
Jonathan Peyton | baad3f6 | 2018-08-09 22:04:30 +0000 | [diff] [blame] | 51 | if (!(cond)) { \ |
| 52 | __kmp_debug_assert("assertion failure", __FILE__, __LINE__); \ |
| 53 | } |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 54 | #define KMP_ASSERT2(cond, msg) KMP_ASSERT(cond) |
Jonathan Peyton | baad3f6 | 2018-08-09 22:04:30 +0000 | [diff] [blame] | 55 | #define KMP_DEBUG_ASSERT(cond) /* Nothing */ |
| 56 | #define KMP_DEBUG_ASSERT2(cond, msg) /* Nothing */ |
| 57 | #define KMP_DEBUG_USE_VAR(x) ((void)(x)) |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 58 | #endif // KMP_DEBUG |
| 59 | #else |
Jonathan Peyton | baad3f6 | 2018-08-09 22:04:30 +0000 | [diff] [blame] | 60 | #define KMP_ASSERT(cond) /* Nothing */ |
| 61 | #define KMP_ASSERT2(cond, msg) /* Nothing */ |
| 62 | #define KMP_DEBUG_ASSERT(cond) /* Nothing */ |
| 63 | #define KMP_DEBUG_ASSERT2(cond, msg) /* Nothing */ |
| 64 | #define KMP_DEBUG_USE_VAR(x) ((void)(x)) |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 65 | #endif // KMP_USE_ASSERT |
| 66 | |
| 67 | #ifdef KMP_DEBUG |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 68 | extern void __kmp_debug_printf_stdout(char const *format, ...); |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 69 | #endif |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 70 | extern void __kmp_debug_printf(char const *format, ...); |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 71 | |
| 72 | #ifdef KMP_DEBUG |
| 73 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 74 | extern int kmp_a_debug; |
| 75 | extern int kmp_b_debug; |
| 76 | extern int kmp_c_debug; |
| 77 | extern int kmp_d_debug; |
| 78 | extern int kmp_e_debug; |
| 79 | extern int kmp_f_debug; |
| 80 | extern int kmp_diag; |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 81 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 82 | #define KA_TRACE(d, x) \ |
| 83 | if (kmp_a_debug >= d) { \ |
| 84 | __kmp_debug_printf x; \ |
| 85 | } |
| 86 | #define KB_TRACE(d, x) \ |
| 87 | if (kmp_b_debug >= d) { \ |
| 88 | __kmp_debug_printf x; \ |
| 89 | } |
| 90 | #define KC_TRACE(d, x) \ |
| 91 | if (kmp_c_debug >= d) { \ |
| 92 | __kmp_debug_printf x; \ |
| 93 | } |
| 94 | #define KD_TRACE(d, x) \ |
| 95 | if (kmp_d_debug >= d) { \ |
| 96 | __kmp_debug_printf x; \ |
| 97 | } |
| 98 | #define KE_TRACE(d, x) \ |
| 99 | if (kmp_e_debug >= d) { \ |
| 100 | __kmp_debug_printf x; \ |
| 101 | } |
| 102 | #define KF_TRACE(d, x) \ |
| 103 | if (kmp_f_debug >= d) { \ |
| 104 | __kmp_debug_printf x; \ |
| 105 | } |
| 106 | #define K_DIAG(d, x) \ |
| 107 | { \ |
| 108 | if (kmp_diag == d) { \ |
| 109 | __kmp_debug_printf_stdout x; \ |
| 110 | } \ |
| 111 | } |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 112 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 113 | #define KA_DUMP(d, x) \ |
| 114 | if (kmp_a_debug >= d) { \ |
| 115 | int ks; \ |
| 116 | __kmp_disable(&ks); \ |
| 117 | (x); \ |
| 118 | __kmp_enable(ks); \ |
| 119 | } |
| 120 | #define KB_DUMP(d, x) \ |
| 121 | if (kmp_b_debug >= d) { \ |
| 122 | int ks; \ |
| 123 | __kmp_disable(&ks); \ |
| 124 | (x); \ |
| 125 | __kmp_enable(ks); \ |
| 126 | } |
| 127 | #define KC_DUMP(d, x) \ |
| 128 | if (kmp_c_debug >= d) { \ |
| 129 | int ks; \ |
| 130 | __kmp_disable(&ks); \ |
| 131 | (x); \ |
| 132 | __kmp_enable(ks); \ |
| 133 | } |
| 134 | #define KD_DUMP(d, x) \ |
| 135 | if (kmp_d_debug >= d) { \ |
| 136 | int ks; \ |
| 137 | __kmp_disable(&ks); \ |
| 138 | (x); \ |
| 139 | __kmp_enable(ks); \ |
| 140 | } |
| 141 | #define KE_DUMP(d, x) \ |
| 142 | if (kmp_e_debug >= d) { \ |
| 143 | int ks; \ |
| 144 | __kmp_disable(&ks); \ |
| 145 | (x); \ |
| 146 | __kmp_enable(ks); \ |
| 147 | } |
| 148 | #define KF_DUMP(d, x) \ |
| 149 | if (kmp_f_debug >= d) { \ |
| 150 | int ks; \ |
| 151 | __kmp_disable(&ks); \ |
| 152 | (x); \ |
| 153 | __kmp_enable(ks); \ |
| 154 | } |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 155 | |
| 156 | #else |
| 157 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 158 | #define KA_TRACE(d, x) /* nothing to do */ |
| 159 | #define KB_TRACE(d, x) /* nothing to do */ |
| 160 | #define KC_TRACE(d, x) /* nothing to do */ |
| 161 | #define KD_TRACE(d, x) /* nothing to do */ |
| 162 | #define KE_TRACE(d, x) /* nothing to do */ |
| 163 | #define KF_TRACE(d, x) /* nothing to do */ |
| 164 | #define K_DIAG(d, x) \ |
| 165 | {} /* nothing to do */ |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 166 | |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 167 | #define KA_DUMP(d, x) /* nothing to do */ |
| 168 | #define KB_DUMP(d, x) /* nothing to do */ |
| 169 | #define KC_DUMP(d, x) /* nothing to do */ |
| 170 | #define KD_DUMP(d, x) /* nothing to do */ |
| 171 | #define KE_DUMP(d, x) /* nothing to do */ |
| 172 | #define KF_DUMP(d, x) /* nothing to do */ |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 173 | |
| 174 | #endif // KMP_DEBUG |
| 175 | |
| 176 | #ifdef __cplusplus |
Jonathan Peyton | 3041982 | 2017-05-12 18:01:32 +0000 | [diff] [blame] | 177 | } // extern "C" |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 178 | #endif // __cplusplus |
| 179 | |
| 180 | #endif /* KMP_DEBUG_H */ |