2 * kmp_debug.cpp -- debug utilities for the Guide library
5 //===----------------------------------------------------------------------===//
7 // The LLVM Compiler Infrastructure
9 // This file is dual licensed under the MIT and the University of Illinois Open
10 // Source Licenses. See LICENSE.txt for details.
12 //===----------------------------------------------------------------------===//
15 #include "kmp_debug.h" /* really necessary? */
20 void __kmp_debug_printf_stdout(char const *format, ...) {
24 __kmp_vprintf(kmp_out, format, ap);
30 void __kmp_debug_printf(char const *format, ...) {
34 __kmp_vprintf(kmp_err, format, ap);
40 int __kmp_debug_assert(char const *msg, char const *file, int line) {
43 file = KMP_I18N_STR(UnknownFile);
45 // Remove directories from path, leave only file name. File name is enough,
46 // there is no need in bothering developers and customers with full paths.
47 char const *slash = strrchr(file, '/');
54 __kmp_acquire_bootstrap_lock(&__kmp_stdio_lock);
55 __kmp_debug_printf("Assertion failure at %s(%d): %s.\n", file, line, msg);
56 __kmp_release_bootstrap_lock(&__kmp_stdio_lock);
57 #ifdef USE_ASSERT_BREAK
61 #endif // USE_ASSERT_BREAK
62 #ifdef USE_ASSERT_STALL
63 /* __kmp_infinite_loop(); */
66 #endif // USE_ASSERT_STALL
69 int volatile *ZERO = (int *)0;
72 #endif // USE_ASSERT_SEG
75 __kmp_fatal(KMP_MSG(AssertionFailure, file, line), KMP_HNT(SubmitBugReport),
80 } // __kmp_debug_assert
82 #endif // KMP_USE_ASSERT
84 /* Dump debugging buffer to stderr */
85 void __kmp_dump_debug_buffer(void) {
86 if (__kmp_debug_buffer != NULL) {
88 int dc = __kmp_debug_count;
89 char *db = &__kmp_debug_buffer[(dc % __kmp_debug_buf_lines) *
90 __kmp_debug_buf_chars];
92 &__kmp_debug_buffer[__kmp_debug_buf_lines * __kmp_debug_buf_chars];
95 __kmp_acquire_bootstrap_lock(&__kmp_stdio_lock);
96 __kmp_printf_no_lock("\nStart dump of debugging buffer (entry=%d):\n",
97 dc % __kmp_debug_buf_lines);
99 for (i = 0; i < __kmp_debug_buf_lines; i++) {
102 /* Fix up where no carriage return before string termination char */
103 for (db2 = db + 1; db2 < db + __kmp_debug_buf_chars - 1; db2++) {
105 if (*(db2 - 1) != '\n') {
112 /* Handle case at end by shortening the printed message by one char if
114 if (db2 == db + __kmp_debug_buf_chars - 1 && *db2 == '\0' &&
115 *(db2 - 1) != '\n') {
119 __kmp_printf_no_lock("%4d: %.*s", i, __kmp_debug_buf_chars, db);
120 *db = '\0'; /* only let it print once! */
123 db += __kmp_debug_buf_chars;
125 db = __kmp_debug_buffer;
128 __kmp_printf_no_lock("End dump of debugging buffer (entry=%d).\n\n",
129 (dc + i - 1) % __kmp_debug_buf_lines);
130 __kmp_release_bootstrap_lock(&__kmp_stdio_lock);