blob: ac706ff1ba163642b8486628dbe537f623220f32 [file] [log] [blame]
Jim Cownie5e8470a2013-09-27 10:38:44 +00001/*
2 * kmp_debug.h -- debug / assertion code for Assure library
3 * $Revision: 42061 $
4 * $Date: 2013-02-28 16:36:24 -0600 (Thu, 28 Feb 2013) $
5 */
6
7
8//===----------------------------------------------------------------------===//
9//
10// The LLVM Compiler Infrastructure
11//
12// This file is dual licensed under the MIT and the University of Illinois Open
13// Source Licenses. See LICENSE.txt for details.
14//
15//===----------------------------------------------------------------------===//
16
17
18#ifndef KMP_DEBUG_H
19#define KMP_DEBUG_H
20
21#include <stdarg.h>
22
23#ifdef __cplusplus
24 extern "C" {
25#endif // __cplusplus
26
27// -------------------------------------------------------------------------------------------------
28// Build-time assertion.
29// -------------------------------------------------------------------------------------------------
30
31/*
32 Build-time assertion can do compile-time checking of data structure sizes, etc. This works by
33 declaring a negative-length array if the conditional expression evaluates to false. In that
34 case, the compiler issues a syntax error and stops the compilation. If the expression is
35 true, we get an extraneous static single character array in the scope of the macro.
36
37 Usage:
38
39 KMP_BUILD_ASSERT( sizeof( some_t ) <= 32 );
40 KMP_BUILD_ASSERT( offsetof( some_t, field ) % 8 == 0 );
41
42 Do not use _KMP_BUILD_ASSERT and __KMP_BUILD_ASSERT directly, it is working guts.
43*/
44
45#define __KMP_BUILD_ASSERT( expr, suffix ) static char __kmp_build_check_##suffix[ (expr) ? 1 : -1 ]
46#define _KMP_BUILD_ASSERT( expr, suffix ) __KMP_BUILD_ASSERT( (expr), suffix )
47#define KMP_BUILD_ASSERT( expr ) _KMP_BUILD_ASSERT( (expr), __LINE__ )
48
49// -------------------------------------------------------------------------------------------------
50// Run-time assertions.
51// -------------------------------------------------------------------------------------------------
52
53extern void __kmp_dump_debug_buffer( void );
54
55#ifdef KMP_USE_ASSERT
56 extern int __kmp_debug_assert( char const * expr, char const * file, int line );
57 #ifdef KMP_DEBUG
58 #define KMP_ASSERT( cond ) ( (cond) ? 0 : __kmp_debug_assert( #cond, __FILE__, __LINE__ ) )
59 #define KMP_ASSERT2( cond, msg ) ( (cond) ? 0 : __kmp_debug_assert( (msg), __FILE__, __LINE__ ) )
60 #define KMP_DEBUG_ASSERT( cond ) KMP_ASSERT( cond )
61 #define KMP_DEBUG_ASSERT2( cond, msg ) KMP_ASSERT2( cond, msg )
62 #else
63 // Do not expose condition in release build. Use "assertion failure".
64 #define KMP_ASSERT( cond ) ( (cond) ? 0 : __kmp_debug_assert( "assertion failure", __FILE__, __LINE__ ) )
65 #define KMP_ASSERT2( cond, msg ) KMP_ASSERT( cond )
66 #define KMP_DEBUG_ASSERT( cond ) 0
67 #define KMP_DEBUG_ASSERT2( cond, msg ) 0
68 #endif // KMP_DEBUG
69#else
70 #define KMP_ASSERT( cond ) 0
71 #define KMP_ASSERT2( cond, msg ) 0
72 #define KMP_DEBUG_ASSERT( cond ) 0
73 #define KMP_DEBUG_ASSERT2( cond, msg ) 0
74#endif // KMP_USE_ASSERT
75
76#ifdef KMP_DEBUG
77 extern void __kmp_debug_printf_stdout( char const * format, ... );
78#endif
79extern void __kmp_debug_printf( char const * format, ... );
80
81#ifdef KMP_DEBUG
82
83 extern int kmp_a_debug;
84 extern int kmp_b_debug;
85 extern int kmp_c_debug;
86 extern int kmp_d_debug;
87 extern int kmp_e_debug;
88 extern int kmp_f_debug;
89 extern int kmp_diag;
90
91 #define KA_TRACE(d,x) if (kmp_a_debug >= d) { __kmp_debug_printf x ; }
92 #define KB_TRACE(d,x) if (kmp_b_debug >= d) { __kmp_debug_printf x ; }
93 #define KC_TRACE(d,x) if (kmp_c_debug >= d) { __kmp_debug_printf x ; }
94 #define KD_TRACE(d,x) if (kmp_d_debug >= d) { __kmp_debug_printf x ; }
95 #define KE_TRACE(d,x) if (kmp_e_debug >= d) { __kmp_debug_printf x ; }
96 #define KF_TRACE(d,x) if (kmp_f_debug >= d) { __kmp_debug_printf x ; }
97 #define K_DIAG(d,x) {if (kmp_diag == d) { __kmp_debug_printf_stdout x ; } }
98
99 #define KA_DUMP(d,x) if (kmp_a_debug >= d) { int ks; __kmp_disable(&ks); (x) ; __kmp_enable(ks); }
100 #define KB_DUMP(d,x) if (kmp_b_debug >= d) { int ks; __kmp_disable(&ks); (x) ; __kmp_enable(ks); }
101 #define KC_DUMP(d,x) if (kmp_c_debug >= d) { int ks; __kmp_disable(&ks); (x) ; __kmp_enable(ks); }
102 #define KD_DUMP(d,x) if (kmp_d_debug >= d) { int ks; __kmp_disable(&ks); (x) ; __kmp_enable(ks); }
103 #define KE_DUMP(d,x) if (kmp_e_debug >= d) { int ks; __kmp_disable(&ks); (x) ; __kmp_enable(ks); }
104 #define KF_DUMP(d,x) if (kmp_f_debug >= d) { int ks; __kmp_disable(&ks); (x) ; __kmp_enable(ks); }
105
106#else
107
108 #define KA_TRACE(d,x) /* nothing to do */
109 #define KB_TRACE(d,x) /* nothing to do */
110 #define KC_TRACE(d,x) /* nothing to do */
111 #define KD_TRACE(d,x) /* nothing to do */
112 #define KE_TRACE(d,x) /* nothing to do */
113 #define KF_TRACE(d,x) /* nothing to do */
114 #define K_DIAG(d,x) {}/* nothing to do */
115
116 #define KA_DUMP(d,x) /* nothing to do */
117 #define KB_DUMP(d,x) /* nothing to do */
118 #define KC_DUMP(d,x) /* nothing to do */
119 #define KD_DUMP(d,x) /* nothing to do */
120 #define KE_DUMP(d,x) /* nothing to do */
121 #define KF_DUMP(d,x) /* nothing to do */
122
123#endif // KMP_DEBUG
124
125#ifdef __cplusplus
126 } // extern "C"
127#endif // __cplusplus
128
129#endif /* KMP_DEBUG_H */