2 * kmp_debug.cpp -- debug utilities for the Guide library
5 //===----------------------------------------------------------------------===//
7 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
8 // See https://llvm.org/LICENSE.txt for license information.
9 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
11 //===----------------------------------------------------------------------===//
14 #include "kmp_debug.h" /* really necessary? */
19 void __kmp_debug_printf_stdout(char const *format, ...) {
23 __kmp_vprintf(kmp_out, format, ap);
29 void __kmp_debug_printf(char const *format, ...) {
33 __kmp_vprintf(kmp_err, format, ap);
39 int __kmp_debug_assert(char const *msg, char const *file, int line) {
42 file = KMP_I18N_STR(UnknownFile);
44 // Remove directories from path, leave only file name. File name is enough,
45 // there is no need in bothering developers and customers with full paths.
46 char const *slash = strrchr(file, '/');
53 __kmp_acquire_bootstrap_lock(&__kmp_stdio_lock);
54 __kmp_debug_printf("Assertion failure at %s(%d): %s.\n", file, line, msg);
55 __kmp_release_bootstrap_lock(&__kmp_stdio_lock);
56 #ifdef USE_ASSERT_BREAK
60 #endif // USE_ASSERT_BREAK
61 #ifdef USE_ASSERT_STALL
62 /* __kmp_infinite_loop(); */
65 #endif // USE_ASSERT_STALL
68 int volatile *ZERO = (int *)0;
71 #endif // USE_ASSERT_SEG
74 __kmp_fatal(KMP_MSG(AssertionFailure, file, line), KMP_HNT(SubmitBugReport),
79 } // __kmp_debug_assert
81 #endif // KMP_USE_ASSERT
83 /* Dump debugging buffer to stderr */
84 void __kmp_dump_debug_buffer(void) {
85 if (__kmp_debug_buffer != NULL) {
87 int dc = __kmp_debug_count;
88 char *db = &__kmp_debug_buffer[(dc % __kmp_debug_buf_lines) *
89 __kmp_debug_buf_chars];
91 &__kmp_debug_buffer[__kmp_debug_buf_lines * __kmp_debug_buf_chars];
94 __kmp_acquire_bootstrap_lock(&__kmp_stdio_lock);
95 __kmp_printf_no_lock("\nStart dump of debugging buffer (entry=%d):\n",
96 dc % __kmp_debug_buf_lines);
98 for (i = 0; i < __kmp_debug_buf_lines; i++) {
101 /* Fix up where no carriage return before string termination char */
102 for (db2 = db + 1; db2 < db + __kmp_debug_buf_chars - 1; db2++) {
104 if (*(db2 - 1) != '\n') {
111 /* Handle case at end by shortening the printed message by one char if
113 if (db2 == db + __kmp_debug_buf_chars - 1 && *db2 == '\0' &&
114 *(db2 - 1) != '\n') {
118 __kmp_printf_no_lock("%4d: %.*s", i, __kmp_debug_buf_chars, db);
119 *db = '\0'; /* only let it print once! */
122 db += __kmp_debug_buf_chars;
124 db = __kmp_debug_buffer;
127 __kmp_printf_no_lock("End dump of debugging buffer (entry=%d).\n\n",
128 (dc + i - 1) % __kmp_debug_buf_lines);
129 __kmp_release_bootstrap_lock(&__kmp_stdio_lock);