kmp_debug.h 8.2 KB

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