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