Path: blob/main/contrib/llvm-project/openmp/runtime/src/kmp_debug.cpp
35258 views
/*1* kmp_debug.cpp -- debug utilities for the Guide library2*/34//===----------------------------------------------------------------------===//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-exception9//10//===----------------------------------------------------------------------===//1112#include "kmp.h"13#include "kmp_debug.h" /* really necessary? */14#include "kmp_i18n.h"15#include "kmp_io.h"1617#ifdef KMP_DEBUG18void __kmp_debug_printf_stdout(char const *format, ...) {19va_list ap;20va_start(ap, format);2122__kmp_vprintf(kmp_out, format, ap);2324va_end(ap);25}26#endif2728void __kmp_debug_printf(char const *format, ...) {29va_list ap;30va_start(ap, format);3132__kmp_vprintf(kmp_err, format, ap);3334va_end(ap);35}3637#ifdef KMP_USE_ASSERT38int __kmp_debug_assert(char const *msg, char const *file, int line) {3940if (file == NULL) {41file = KMP_I18N_STR(UnknownFile);42} else {43// Remove directories from path, leave only file name. File name is enough,44// there is no need in bothering developers and customers with full paths.45char const *slash = strrchr(file, '/');46if (slash != NULL) {47file = slash + 1;48}49}5051#ifdef KMP_DEBUG52__kmp_acquire_bootstrap_lock(&__kmp_stdio_lock);53__kmp_debug_printf("Assertion failure at %s(%d): %s.\n", file, line, msg);54__kmp_release_bootstrap_lock(&__kmp_stdio_lock);55#ifdef USE_ASSERT_BREAK56#if KMP_OS_WINDOWS57DebugBreak();58#endif59#endif // USE_ASSERT_BREAK60#ifdef USE_ASSERT_STALL61/* __kmp_infinite_loop(); */62for (;;)63;64#endif // USE_ASSERT_STALL65#ifdef USE_ASSERT_SEG66{67int volatile *ZERO = (int *)0;68++(*ZERO);69}70#endif // USE_ASSERT_SEG71#endif7273__kmp_fatal(KMP_MSG(AssertionFailure, file, line), KMP_HNT(SubmitBugReport),74__kmp_msg_null);7576return 0;7778} // __kmp_debug_assert7980#endif // KMP_USE_ASSERT8182/* Dump debugging buffer to stderr */83void __kmp_dump_debug_buffer(void) {84if (__kmp_debug_buffer != NULL) {85int i;86int dc = __kmp_debug_count;87char *db = &__kmp_debug_buffer[(dc % __kmp_debug_buf_lines) *88__kmp_debug_buf_chars];89char *db_end =90&__kmp_debug_buffer[__kmp_debug_buf_lines * __kmp_debug_buf_chars];91char *db2;9293__kmp_acquire_bootstrap_lock(&__kmp_stdio_lock);94__kmp_printf_no_lock("\nStart dump of debugging buffer (entry=%d):\n",95dc % __kmp_debug_buf_lines);9697for (i = 0; i < __kmp_debug_buf_lines; i++) {9899if (*db != '\0') {100/* Fix up where no carriage return before string termination char */101for (db2 = db + 1; db2 < db + __kmp_debug_buf_chars - 1; db2++) {102if (*db2 == '\0') {103if (*(db2 - 1) != '\n') {104*db2 = '\n';105*(db2 + 1) = '\0';106}107break;108}109}110/* Handle case at end by shortening the printed message by one char if111* necessary */112if (db2 == db + __kmp_debug_buf_chars - 1 && *db2 == '\0' &&113*(db2 - 1) != '\n') {114*(db2 - 1) = '\n';115}116117__kmp_printf_no_lock("%4d: %.*s", i, __kmp_debug_buf_chars, db);118*db = '\0'; /* only let it print once! */119}120121db += __kmp_debug_buf_chars;122if (db >= db_end)123db = __kmp_debug_buffer;124}125126__kmp_printf_no_lock("End dump of debugging buffer (entry=%d).\n\n",127(dc + i - 1) % __kmp_debug_buf_lines);128__kmp_release_bootstrap_lock(&__kmp_stdio_lock);129}130}131132133