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 | |
| 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 | |
Jonathan Peyton | 3692fcf | 2017-01-18 07:49:30 +0000 | [diff] [blame^] | 29 | // New C++11 style build assert |
| 30 | #define KMP_BUILD_ASSERT( expr ) static_assert(expr, "Build condition error") |
Jim Cownie | 5e8470a | 2013-09-27 10:38:44 +0000 | [diff] [blame] | 31 | |
| 32 | // ------------------------------------------------------------------------------------------------- |
| 33 | // Run-time assertions. |
| 34 | // ------------------------------------------------------------------------------------------------- |
| 35 | |
| 36 | extern void __kmp_dump_debug_buffer( void ); |
| 37 | |
| 38 | #ifdef KMP_USE_ASSERT |
| 39 | extern int __kmp_debug_assert( char const * expr, char const * file, int line ); |
| 40 | #ifdef KMP_DEBUG |
| 41 | #define KMP_ASSERT( cond ) ( (cond) ? 0 : __kmp_debug_assert( #cond, __FILE__, __LINE__ ) ) |
| 42 | #define KMP_ASSERT2( cond, msg ) ( (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 ) ( (cond) ? 0 : __kmp_debug_assert( "assertion failure", __FILE__, __LINE__ ) ) |
| 48 | #define KMP_ASSERT2( cond, msg ) KMP_ASSERT( cond ) |
| 49 | #define KMP_DEBUG_ASSERT( cond ) 0 |
| 50 | #define KMP_DEBUG_ASSERT2( cond, msg ) 0 |
| 51 | #endif // KMP_DEBUG |
| 52 | #else |
| 53 | #define KMP_ASSERT( cond ) 0 |
| 54 | #define KMP_ASSERT2( cond, msg ) 0 |
| 55 | #define KMP_DEBUG_ASSERT( cond ) 0 |
| 56 | #define KMP_DEBUG_ASSERT2( cond, msg ) 0 |
| 57 | #endif // KMP_USE_ASSERT |
| 58 | |
| 59 | #ifdef KMP_DEBUG |
| 60 | extern void __kmp_debug_printf_stdout( char const * format, ... ); |
| 61 | #endif |
| 62 | extern void __kmp_debug_printf( char const * format, ... ); |
| 63 | |
| 64 | #ifdef KMP_DEBUG |
| 65 | |
| 66 | extern int kmp_a_debug; |
| 67 | extern int kmp_b_debug; |
| 68 | extern int kmp_c_debug; |
| 69 | extern int kmp_d_debug; |
| 70 | extern int kmp_e_debug; |
| 71 | extern int kmp_f_debug; |
| 72 | extern int kmp_diag; |
| 73 | |
| 74 | #define KA_TRACE(d,x) if (kmp_a_debug >= d) { __kmp_debug_printf x ; } |
| 75 | #define KB_TRACE(d,x) if (kmp_b_debug >= d) { __kmp_debug_printf x ; } |
| 76 | #define KC_TRACE(d,x) if (kmp_c_debug >= d) { __kmp_debug_printf x ; } |
| 77 | #define KD_TRACE(d,x) if (kmp_d_debug >= d) { __kmp_debug_printf x ; } |
| 78 | #define KE_TRACE(d,x) if (kmp_e_debug >= d) { __kmp_debug_printf x ; } |
| 79 | #define KF_TRACE(d,x) if (kmp_f_debug >= d) { __kmp_debug_printf x ; } |
| 80 | #define K_DIAG(d,x) {if (kmp_diag == d) { __kmp_debug_printf_stdout x ; } } |
| 81 | |
| 82 | #define KA_DUMP(d,x) if (kmp_a_debug >= d) { int ks; __kmp_disable(&ks); (x) ; __kmp_enable(ks); } |
| 83 | #define KB_DUMP(d,x) if (kmp_b_debug >= d) { int ks; __kmp_disable(&ks); (x) ; __kmp_enable(ks); } |
| 84 | #define KC_DUMP(d,x) if (kmp_c_debug >= d) { int ks; __kmp_disable(&ks); (x) ; __kmp_enable(ks); } |
| 85 | #define KD_DUMP(d,x) if (kmp_d_debug >= d) { int ks; __kmp_disable(&ks); (x) ; __kmp_enable(ks); } |
| 86 | #define KE_DUMP(d,x) if (kmp_e_debug >= d) { int ks; __kmp_disable(&ks); (x) ; __kmp_enable(ks); } |
| 87 | #define KF_DUMP(d,x) if (kmp_f_debug >= d) { int ks; __kmp_disable(&ks); (x) ; __kmp_enable(ks); } |
| 88 | |
| 89 | #else |
| 90 | |
| 91 | #define KA_TRACE(d,x) /* nothing to do */ |
| 92 | #define KB_TRACE(d,x) /* nothing to do */ |
| 93 | #define KC_TRACE(d,x) /* nothing to do */ |
| 94 | #define KD_TRACE(d,x) /* nothing to do */ |
| 95 | #define KE_TRACE(d,x) /* nothing to do */ |
| 96 | #define KF_TRACE(d,x) /* nothing to do */ |
| 97 | #define K_DIAG(d,x) {}/* nothing to do */ |
| 98 | |
| 99 | #define KA_DUMP(d,x) /* nothing to do */ |
| 100 | #define KB_DUMP(d,x) /* nothing to do */ |
| 101 | #define KC_DUMP(d,x) /* nothing to do */ |
| 102 | #define KD_DUMP(d,x) /* nothing to do */ |
| 103 | #define KE_DUMP(d,x) /* nothing to do */ |
| 104 | #define KF_DUMP(d,x) /* nothing to do */ |
| 105 | |
| 106 | #endif // KMP_DEBUG |
| 107 | |
| 108 | #ifdef __cplusplus |
| 109 | } // extern "C" |
| 110 | #endif // __cplusplus |
| 111 | |
| 112 | #endif /* KMP_DEBUG_H */ |