blob: 9080a4a9efeb63ffd708a23e98e0ef48c62cd983 [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
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
Jonathan Peyton30419822017-05-12 18:01:32 +000022extern "C" {
Jim Cownie5e8470a2013-09-27 10:38:44 +000023#endif // __cplusplus
24
Jonathan Peyton30419822017-05-12 18:01:32 +000025// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +000026// Build-time assertion.
Jim Cownie5e8470a2013-09-27 10:38:44 +000027
Jonathan Peyton3692fcf2017-01-18 07:49:30 +000028// New C++11 style build assert
Jonathan Peyton30419822017-05-12 18:01:32 +000029#define KMP_BUILD_ASSERT(expr) static_assert(expr, "Build condition error")
Jim Cownie5e8470a2013-09-27 10:38:44 +000030
Jonathan Peyton30419822017-05-12 18:01:32 +000031// -----------------------------------------------------------------------------
Jim Cownie5e8470a2013-09-27 10:38:44 +000032// Run-time assertions.
Jim Cownie5e8470a2013-09-27 10:38:44 +000033
Jonathan Peyton30419822017-05-12 18:01:32 +000034extern void __kmp_dump_debug_buffer(void);
Jim Cownie5e8470a2013-09-27 10:38:44 +000035
36#ifdef KMP_USE_ASSERT
Jonathan Peyton30419822017-05-12 18:01:32 +000037extern int __kmp_debug_assert(char const *expr, char const *file, int line);
38#ifdef KMP_DEBUG
39#define KMP_ASSERT(cond) \
40 ((cond) ? 0 : __kmp_debug_assert(#cond, __FILE__, __LINE__))
41#define KMP_ASSERT2(cond, msg) \
42 ((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)
Jim Cownie5e8470a2013-09-27 10:38:44 +000045#else
Jonathan Peyton30419822017-05-12 18:01:32 +000046// Do not expose condition in release build. Use "assertion failure".
47#define KMP_ASSERT(cond) \
48 ((cond) ? 0 : __kmp_debug_assert("assertion failure", __FILE__, __LINE__))
49#define KMP_ASSERT2(cond, msg) KMP_ASSERT(cond)
50#define KMP_DEBUG_ASSERT(cond) 0
51#define KMP_DEBUG_ASSERT2(cond, msg) 0
52#endif // KMP_DEBUG
53#else
54#define KMP_ASSERT(cond) 0
55#define KMP_ASSERT2(cond, msg) 0
56#define KMP_DEBUG_ASSERT(cond) 0
57#define KMP_DEBUG_ASSERT2(cond, msg) 0
Jim Cownie5e8470a2013-09-27 10:38:44 +000058#endif // KMP_USE_ASSERT
59
60#ifdef KMP_DEBUG
Jonathan Peyton30419822017-05-12 18:01:32 +000061extern void __kmp_debug_printf_stdout(char const *format, ...);
Jim Cownie5e8470a2013-09-27 10:38:44 +000062#endif
Jonathan Peyton30419822017-05-12 18:01:32 +000063extern void __kmp_debug_printf(char const *format, ...);
Jim Cownie5e8470a2013-09-27 10:38:44 +000064
65#ifdef KMP_DEBUG
66
Jonathan Peyton30419822017-05-12 18:01:32 +000067extern int kmp_a_debug;
68extern int kmp_b_debug;
69extern int kmp_c_debug;
70extern int kmp_d_debug;
71extern int kmp_e_debug;
72extern int kmp_f_debug;
73extern int kmp_diag;
Jim Cownie5e8470a2013-09-27 10:38:44 +000074
Jonathan Peyton30419822017-05-12 18:01:32 +000075#define KA_TRACE(d, x) \
76 if (kmp_a_debug >= d) { \
77 __kmp_debug_printf x; \
78 }
79#define KB_TRACE(d, x) \
80 if (kmp_b_debug >= d) { \
81 __kmp_debug_printf x; \
82 }
83#define KC_TRACE(d, x) \
84 if (kmp_c_debug >= d) { \
85 __kmp_debug_printf x; \
86 }
87#define KD_TRACE(d, x) \
88 if (kmp_d_debug >= d) { \
89 __kmp_debug_printf x; \
90 }
91#define KE_TRACE(d, x) \
92 if (kmp_e_debug >= d) { \
93 __kmp_debug_printf x; \
94 }
95#define KF_TRACE(d, x) \
96 if (kmp_f_debug >= d) { \
97 __kmp_debug_printf x; \
98 }
99#define K_DIAG(d, x) \
100 { \
101 if (kmp_diag == d) { \
102 __kmp_debug_printf_stdout x; \
103 } \
104 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000105
Jonathan Peyton30419822017-05-12 18:01:32 +0000106#define KA_DUMP(d, x) \
107 if (kmp_a_debug >= d) { \
108 int ks; \
109 __kmp_disable(&ks); \
110 (x); \
111 __kmp_enable(ks); \
112 }
113#define KB_DUMP(d, x) \
114 if (kmp_b_debug >= d) { \
115 int ks; \
116 __kmp_disable(&ks); \
117 (x); \
118 __kmp_enable(ks); \
119 }
120#define KC_DUMP(d, x) \
121 if (kmp_c_debug >= d) { \
122 int ks; \
123 __kmp_disable(&ks); \
124 (x); \
125 __kmp_enable(ks); \
126 }
127#define KD_DUMP(d, x) \
128 if (kmp_d_debug >= d) { \
129 int ks; \
130 __kmp_disable(&ks); \
131 (x); \
132 __kmp_enable(ks); \
133 }
134#define KE_DUMP(d, x) \
135 if (kmp_e_debug >= d) { \
136 int ks; \
137 __kmp_disable(&ks); \
138 (x); \
139 __kmp_enable(ks); \
140 }
141#define KF_DUMP(d, x) \
142 if (kmp_f_debug >= d) { \
143 int ks; \
144 __kmp_disable(&ks); \
145 (x); \
146 __kmp_enable(ks); \
147 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000148
149#else
150
Jonathan Peyton30419822017-05-12 18:01:32 +0000151#define KA_TRACE(d, x) /* nothing to do */
152#define KB_TRACE(d, x) /* nothing to do */
153#define KC_TRACE(d, x) /* nothing to do */
154#define KD_TRACE(d, x) /* nothing to do */
155#define KE_TRACE(d, x) /* nothing to do */
156#define KF_TRACE(d, x) /* nothing to do */
157#define K_DIAG(d, x) \
158 {} /* nothing to do */
Jim Cownie5e8470a2013-09-27 10:38:44 +0000159
Jonathan Peyton30419822017-05-12 18:01:32 +0000160#define KA_DUMP(d, x) /* nothing to do */
161#define KB_DUMP(d, x) /* nothing to do */
162#define KC_DUMP(d, x) /* nothing to do */
163#define KD_DUMP(d, x) /* nothing to do */
164#define KE_DUMP(d, x) /* nothing to do */
165#define KF_DUMP(d, x) /* nothing to do */
Jim Cownie5e8470a2013-09-27 10:38:44 +0000166
167#endif // KMP_DEBUG
168
169#ifdef __cplusplus
Jonathan Peyton30419822017-05-12 18:01:32 +0000170} // extern "C"
Jim Cownie5e8470a2013-09-27 10:38:44 +0000171#endif // __cplusplus
172
173#endif /* KMP_DEBUG_H */