diff --git a/kotlin-native/runtime/src/main/cpp/KAssert.cpp b/kotlin-native/runtime/src/main/cpp/KAssert.cpp index a8a77d21866..b1a8639f2e1 100644 --- a/kotlin-native/runtime/src/main/cpp/KAssert.cpp +++ b/kotlin-native/runtime/src/main/cpp/KAssert.cpp @@ -17,10 +17,27 @@ using namespace kotlin; namespace { +THREAD_LOCAL_VARIABLE bool assertionReportInProgress = false; + void PrintAssert(bool allowStacktrace, const char* location, const char* format, std::va_list args) noexcept { + if (assertionReportInProgress) { + // WARNING: avoid anything that can assert ar panic here + konan::consoleErrorf("An attempt to report an assertion lead to another failure:\n"); + // now try to print the information we have in the simplest way possible + if (location != nullptr) { + konan::consoleErrorf("%s: ", location); + } + // do not bother with format string expansion + konan::consoleErrorf("%s\n", format); + return; + } + AutoReset recursionGuard(&assertionReportInProgress, true); + std::array bufferStorage; std_support::span buffer(bufferStorage); + buffer = FormatToSpan(buffer, "[tid#%d] ", konan::currentThreadId()); + // Write the title with a source location. if (location != nullptr) { buffer = FormatToSpan(buffer, "%s: runtime assert: ", location);