From 3f6b3866810619b51f5fac92fb4c9b44f163dc92 Mon Sep 17 00:00:00 2001 From: Svyatoslav Scherbina Date: Mon, 16 May 2022 13:15:15 +0300 Subject: [PATCH] Native: make debug interface handle uninitialized threads Generally, debug interface is not called from uninitialized threads, but let's be on the safe side here. --- kotlin-native/runtime/src/debug/cpp/KDebug.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/kotlin-native/runtime/src/debug/cpp/KDebug.cpp b/kotlin-native/runtime/src/debug/cpp/KDebug.cpp index 86b4c668c6c..a4ceb765d50 100644 --- a/kotlin-native/runtime/src/debug/cpp/KDebug.cpp +++ b/kotlin-native/runtime/src/debug/cpp/KDebug.cpp @@ -112,7 +112,9 @@ int Konan_DebugBufferSizeWithObjectImpl(KRef obj) { int32_t Konan_DebugObjectToUtf8ArrayImpl(KRef obj, char* buffer, int32_t bufferSize) { // We need the runnable thread state to call the Kotlin function 'KonanObjectToUtf8Array' and operate with it's result. // But the current thread can be in any state when this function is called by the debugger. So we use the reentrant state switch. - kotlin::ThreadStateGuard guard(kotlin::ThreadState::kRunnable, /* reentrant */ true); + // Finally, let's be on the safe side and assume that current thread might be uninitialized, + // so use CalledFromNativeGuard instead of ThreadStateGuard. + kotlin::CalledFromNativeGuard guard(/* reentrant */ true); ObjHolder stringHolder; // Kotlin call. ArrayHeader* data = KonanObjectToUtf8Array(obj, stringHolder.slot())->array();