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