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 29 /* 30 Build-time assertion can do compile-time checking of data structure sizes, etc. This works by 31 declaring a negative-length array if the conditional expression evaluates to false. In that 32 case, the compiler issues a syntax error and stops the compilation. If the expression is 33 true, we get an extraneous static single character array in the scope of the macro. 34 35 Usage: 36 37 KMP_BUILD_ASSERT( sizeof( some_t ) <= 32 ); 38 KMP_BUILD_ASSERT( offsetof( some_t, field ) % 8 == 0 ); 39 40 Do not use _KMP_BUILD_ASSERT and __KMP_BUILD_ASSERT directly, it is working guts. 41 */ 42 43 #define __KMP_BUILD_ASSERT( expr, suffix ) typedef char __kmp_build_check_##suffix[ (expr) ? 1 : -1 ] 44 #define _KMP_BUILD_ASSERT( expr, suffix ) __KMP_BUILD_ASSERT( (expr), suffix ) 45 #ifdef KMP_USE_ASSERT 46 #define KMP_BUILD_ASSERT( expr ) _KMP_BUILD_ASSERT( (expr), __LINE__ ) 47 #else 48 #define KMP_BUILD_ASSERT( expr ) /* nothing to do */ 49 #endif 50 51 // ------------------------------------------------------------------------------------------------- 52 // Run-time assertions. 53 // ------------------------------------------------------------------------------------------------- 54 55 extern void __kmp_dump_debug_buffer( void ); 56 57 #ifdef KMP_USE_ASSERT 58 extern int __kmp_debug_assert( char const * expr, char const * file, int line ); 59 #ifdef KMP_DEBUG 60 #define KMP_ASSERT( cond ) ( (cond) ? 0 : __kmp_debug_assert( #cond, __FILE__, __LINE__ ) ) 61 #define KMP_ASSERT2( cond, msg ) ( (cond) ? 0 : __kmp_debug_assert( (msg), __FILE__, __LINE__ ) ) 62 #define KMP_DEBUG_ASSERT( cond ) KMP_ASSERT( cond ) 63 #define KMP_DEBUG_ASSERT2( cond, msg ) KMP_ASSERT2( cond, msg ) 64 #else 65 // Do not expose condition in release build. Use "assertion failure". 66 #define KMP_ASSERT( cond ) ( (cond) ? 0 : __kmp_debug_assert( "assertion failure", __FILE__, __LINE__ ) ) 67 #define KMP_ASSERT2( cond, msg ) KMP_ASSERT( cond ) 68 #define KMP_DEBUG_ASSERT( cond ) 0 69 #define KMP_DEBUG_ASSERT2( cond, msg ) 0 70 #endif // KMP_DEBUG 71 #else 72 #define KMP_ASSERT( cond ) 0 73 #define KMP_ASSERT2( cond, msg ) 0 74 #define KMP_DEBUG_ASSERT( cond ) 0 75 #define KMP_DEBUG_ASSERT2( cond, msg ) 0 76 #endif // KMP_USE_ASSERT 77 78 #ifdef KMP_DEBUG 79 extern void __kmp_debug_printf_stdout( char const * format, ... ); 80 #endif 81 extern void __kmp_debug_printf( char const * format, ... ); 82 83 #ifdef KMP_DEBUG 84 85 extern int kmp_a_debug; 86 extern int kmp_b_debug; 87 extern int kmp_c_debug; 88 extern int kmp_d_debug; 89 extern int kmp_e_debug; 90 extern int kmp_f_debug; 91 extern int kmp_diag; 92 93 #define KA_TRACE(d,x) if (kmp_a_debug >= d) { __kmp_debug_printf x ; } 94 #define KB_TRACE(d,x) if (kmp_b_debug >= d) { __kmp_debug_printf x ; } 95 #define KC_TRACE(d,x) if (kmp_c_debug >= d) { __kmp_debug_printf x ; } 96 #define KD_TRACE(d,x) if (kmp_d_debug >= d) { __kmp_debug_printf x ; } 97 #define KE_TRACE(d,x) if (kmp_e_debug >= d) { __kmp_debug_printf x ; } 98 #define KF_TRACE(d,x) if (kmp_f_debug >= d) { __kmp_debug_printf x ; } 99 #define K_DIAG(d,x) {if (kmp_diag == d) { __kmp_debug_printf_stdout x ; } } 100 101 #define KA_DUMP(d,x) if (kmp_a_debug >= d) { int ks; __kmp_disable(&ks); (x) ; __kmp_enable(ks); } 102 #define KB_DUMP(d,x) if (kmp_b_debug >= d) { int ks; __kmp_disable(&ks); (x) ; __kmp_enable(ks); } 103 #define KC_DUMP(d,x) if (kmp_c_debug >= d) { int ks; __kmp_disable(&ks); (x) ; __kmp_enable(ks); } 104 #define KD_DUMP(d,x) if (kmp_d_debug >= d) { int ks; __kmp_disable(&ks); (x) ; __kmp_enable(ks); } 105 #define KE_DUMP(d,x) if (kmp_e_debug >= d) { int ks; __kmp_disable(&ks); (x) ; __kmp_enable(ks); } 106 #define KF_DUMP(d,x) if (kmp_f_debug >= d) { int ks; __kmp_disable(&ks); (x) ; __kmp_enable(ks); } 107 108 #else 109 110 #define KA_TRACE(d,x) /* nothing to do */ 111 #define KB_TRACE(d,x) /* nothing to do */ 112 #define KC_TRACE(d,x) /* nothing to do */ 113 #define KD_TRACE(d,x) /* nothing to do */ 114 #define KE_TRACE(d,x) /* nothing to do */ 115 #define KF_TRACE(d,x) /* nothing to do */ 116 #define K_DIAG(d,x) {}/* nothing to do */ 117 118 #define KA_DUMP(d,x) /* nothing to do */ 119 #define KB_DUMP(d,x) /* nothing to do */ 120 #define KC_DUMP(d,x) /* nothing to do */ 121 #define KD_DUMP(d,x) /* nothing to do */ 122 #define KE_DUMP(d,x) /* nothing to do */ 123 #define KF_DUMP(d,x) /* nothing to do */ 124 125 #endif // KMP_DEBUG 126 127 #ifdef __cplusplus 128 } // extern "C" 129 #endif // __cplusplus 130 131 #endif /* KMP_DEBUG_H */ 132