blob: 29cc15c5cf8c373e9cdbc143b4c805fc0d17c0ac [file] [log] [blame]
Jim Cownie5e8470a2013-09-27 10:38:44 +00001/*
2 * kmp_debug.h -- debug / assertion code for Assure library
Jim Cownie5e8470a2013-09-27 10:38:44 +00003 */
4
Jim Cownie5e8470a2013-09-27 10:38:44 +00005//===----------------------------------------------------------------------===//
6//
7// The LLVM Compiler Infrastructure
8//
9// This file is dual licensed under the MIT and the University of Illinois Open
10// Source Licenses. See LICENSE.txt for details.
11//
12//===----------------------------------------------------------------------===//
13
Jim Cownie5e8470a2013-09-27 10:38:44 +000014#ifndef KMP_DEBUG_H
15#define KMP_DEBUG_H
16
17#include <stdarg.h>
18
19#ifdef __cplusplus
Jonathan Peyton30419822017-05-12 18:01:32 +000020extern "C" {
Jim Cownie5e8470a2013-09-27 10:38:44 +000021#endif // __cplusplus
22
Jonathan Peyton30419822017-05-12 18:01:32 +000023// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +000024// Build-time assertion.
Jim Cownie5e8470a2013-09-27 10:38:44 +000025
Jonathan Peyton3692fcf2017-01-18 07:49:30 +000026// New C++11 style build assert
Jonathan Peyton30419822017-05-12 18:01:32 +000027#define KMP_BUILD_ASSERT(expr) static_assert(expr, "Build condition error")
Jim Cownie5e8470a2013-09-27 10:38:44 +000028
Jonathan Peyton30419822017-05-12 18:01:32 +000029// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +000030// Run-time assertions.
Jim Cownie5e8470a2013-09-27 10:38:44 +000031
Jonathan Peyton30419822017-05-12 18:01:32 +000032extern void __kmp_dump_debug_buffer(void);
Jim Cownie5e8470a2013-09-27 10:38:44 +000033
34#ifdef KMP_USE_ASSERT
Jonathan Peyton30419822017-05-12 18:01:32 +000035extern int __kmp_debug_assert(char const *expr, char const *file, int line);
36#ifdef KMP_DEBUG
37#define KMP_ASSERT(cond) \
Jonathan Peytonbaad3f62018-08-09 22:04:30 +000038 if (!(cond)) { \
39 __kmp_debug_assert(#cond, __FILE__, __LINE__); \
40 }
Jonathan Peyton30419822017-05-12 18:01:32 +000041#define KMP_ASSERT2(cond, msg) \
Jonathan Peytonbaad3f62018-08-09 22:04:30 +000042 if (!(cond)) { \
43 __kmp_debug_assert((msg), __FILE__, __LINE__); \
44 }
Jonathan Peyton30419822017-05-12 18:01:32 +000045#define KMP_DEBUG_ASSERT(cond) KMP_ASSERT(cond)
46#define KMP_DEBUG_ASSERT2(cond, msg) KMP_ASSERT2(cond, msg)
Jonathan Peytonbaad3f62018-08-09 22:04:30 +000047#define KMP_DEBUG_USE_VAR(x) /* Nothing (it is used!) */
Jim Cownie5e8470a2013-09-27 10:38:44 +000048#else
Jonathan Peyton30419822017-05-12 18:01:32 +000049// Do not expose condition in release build. Use "assertion failure".
50#define KMP_ASSERT(cond) \
Jonathan Peytonbaad3f62018-08-09 22:04:30 +000051 if (!(cond)) { \
52 __kmp_debug_assert("assertion failure", __FILE__, __LINE__); \
53 }
Jonathan Peyton30419822017-05-12 18:01:32 +000054#define KMP_ASSERT2(cond, msg) KMP_ASSERT(cond)
Jonathan Peytonbaad3f62018-08-09 22:04:30 +000055#define KMP_DEBUG_ASSERT(cond) /* Nothing */
56#define KMP_DEBUG_ASSERT2(cond, msg) /* Nothing */
57#define KMP_DEBUG_USE_VAR(x) ((void)(x))
Jonathan Peyton30419822017-05-12 18:01:32 +000058#endif // KMP_DEBUG
59#else
Jonathan Peytonbaad3f62018-08-09 22:04:30 +000060#define KMP_ASSERT(cond) /* Nothing */
61#define KMP_ASSERT2(cond, msg) /* Nothing */
62#define KMP_DEBUG_ASSERT(cond) /* Nothing */
63#define KMP_DEBUG_ASSERT2(cond, msg) /* Nothing */
64#define KMP_DEBUG_USE_VAR(x) ((void)(x))
Jim Cownie5e8470a2013-09-27 10:38:44 +000065#endif // KMP_USE_ASSERT
66
67#ifdef KMP_DEBUG
Jonathan Peyton30419822017-05-12 18:01:32 +000068extern void __kmp_debug_printf_stdout(char const *format, ...);
Jim Cownie5e8470a2013-09-27 10:38:44 +000069#endif
Jonathan Peyton30419822017-05-12 18:01:32 +000070extern void __kmp_debug_printf(char const *format, ...);
Jim Cownie5e8470a2013-09-27 10:38:44 +000071
72#ifdef KMP_DEBUG
73
Jonathan Peyton30419822017-05-12 18:01:32 +000074extern int kmp_a_debug;
75extern int kmp_b_debug;
76extern int kmp_c_debug;
77extern int kmp_d_debug;
78extern int kmp_e_debug;
79extern int kmp_f_debug;
80extern int kmp_diag;
Jim Cownie5e8470a2013-09-27 10:38:44 +000081
Jonathan Peyton30419822017-05-12 18:01:32 +000082#define KA_TRACE(d, x) \
83 if (kmp_a_debug >= d) { \
84 __kmp_debug_printf x; \
85 }
86#define KB_TRACE(d, x) \
87 if (kmp_b_debug >= d) { \
88 __kmp_debug_printf x; \
89 }
90#define KC_TRACE(d, x) \
91 if (kmp_c_debug >= d) { \
92 __kmp_debug_printf x; \
93 }
94#define KD_TRACE(d, x) \
95 if (kmp_d_debug >= d) { \
96 __kmp_debug_printf x; \
97 }
98#define KE_TRACE(d, x) \
99 if (kmp_e_debug >= d) { \
100 __kmp_debug_printf x; \
101 }
102#define KF_TRACE(d, x) \
103 if (kmp_f_debug >= d) { \
104 __kmp_debug_printf x; \
105 }
106#define K_DIAG(d, x) \
107 { \
108 if (kmp_diag == d) { \
109 __kmp_debug_printf_stdout x; \
110 } \
111 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000112
Jonathan Peyton30419822017-05-12 18:01:32 +0000113#define KA_DUMP(d, x) \
114 if (kmp_a_debug >= d) { \
115 int ks; \
116 __kmp_disable(&ks); \
117 (x); \
118 __kmp_enable(ks); \
119 }
120#define KB_DUMP(d, x) \
121 if (kmp_b_debug >= d) { \
122 int ks; \
123 __kmp_disable(&ks); \
124 (x); \
125 __kmp_enable(ks); \
126 }
127#define KC_DUMP(d, x) \
128 if (kmp_c_debug >= d) { \
129 int ks; \
130 __kmp_disable(&ks); \
131 (x); \
132 __kmp_enable(ks); \
133 }
134#define KD_DUMP(d, x) \
135 if (kmp_d_debug >= d) { \
136 int ks; \
137 __kmp_disable(&ks); \
138 (x); \
139 __kmp_enable(ks); \
140 }
141#define KE_DUMP(d, x) \
142 if (kmp_e_debug >= d) { \
143 int ks; \
144 __kmp_disable(&ks); \
145 (x); \
146 __kmp_enable(ks); \
147 }
148#define KF_DUMP(d, x) \
149 if (kmp_f_debug >= d) { \
150 int ks; \
151 __kmp_disable(&ks); \
152 (x); \
153 __kmp_enable(ks); \
154 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000155
156#else
157
Jonathan Peyton30419822017-05-12 18:01:32 +0000158#define KA_TRACE(d, x) /* nothing to do */
159#define KB_TRACE(d, x) /* nothing to do */
160#define KC_TRACE(d, x) /* nothing to do */
161#define KD_TRACE(d, x) /* nothing to do */
162#define KE_TRACE(d, x) /* nothing to do */
163#define KF_TRACE(d, x) /* nothing to do */
164#define K_DIAG(d, x) \
165 {} /* nothing to do */
Jim Cownie5e8470a2013-09-27 10:38:44 +0000166
Jonathan Peyton30419822017-05-12 18:01:32 +0000167#define KA_DUMP(d, x) /* nothing to do */
168#define KB_DUMP(d, x) /* nothing to do */
169#define KC_DUMP(d, x) /* nothing to do */
170#define KD_DUMP(d, x) /* nothing to do */
171#define KE_DUMP(d, x) /* nothing to do */
172#define KF_DUMP(d, x) /* nothing to do */
Jim Cownie5e8470a2013-09-27 10:38:44 +0000173
174#endif // KMP_DEBUG
175
176#ifdef __cplusplus
Jonathan Peyton30419822017-05-12 18:01:32 +0000177} // extern "C"
Jim Cownie5e8470a2013-09-27 10:38:44 +0000178#endif // __cplusplus
179
180#endif /* KMP_DEBUG_H */