From fced64fcc0c5438ed178ed13af7836b66f533c61 Mon Sep 17 00:00:00 2001 From: Vasily Levchenko Date: Wed, 8 Jan 2020 16:08:49 +0100 Subject: [PATCH] [runtime][debug] type name inspection --- runtime/src/debug/cpp/KDebug.cpp | 12 ++++++++++++ runtime/src/main/cpp/KDebug.h | 3 +++ 2 files changed, 15 insertions(+) diff --git a/runtime/src/debug/cpp/KDebug.cpp b/runtime/src/debug/cpp/KDebug.cpp index a9b669f377b..b6f47cf1460 100644 --- a/runtime/src/debug/cpp/KDebug.cpp +++ b/runtime/src/debug/cpp/KDebug.cpp @@ -19,6 +19,7 @@ #include #include "KAssert.h" +#include "KString.h" #include "Memory.h" #include "Natives.h" #include "Porting.h" @@ -176,6 +177,17 @@ RUNTIME_USED const char* Konan_DebugGetFieldName(KRef obj, int index) { return extendedTypeInfo->fieldNames_[index]; } +RUNTIME_USED const char* Konan_DebugGetTypeName(KRef obj) { + if (obj == nullptr) + return nullptr; + + auto type_info = obj->type_info(); + if (type_info == nullptr) + return ""; + + return CreateCStringFromString(type_info->relativeName_); +} + } // extern "C" #endif // !KONAN_NO_DEBUG_API diff --git a/runtime/src/main/cpp/KDebug.h b/runtime/src/main/cpp/KDebug.h index ba60740662b..30a80025208 100644 --- a/runtime/src/main/cpp/KDebug.h +++ b/runtime/src/main/cpp/KDebug.h @@ -60,6 +60,9 @@ RUNTIME_USED void* Konan_DebugGetFieldAddress(KRef obj, int index); // Compute address of field or an array element at the index, or null, if incorrect. RUNTIME_USED const char* Konan_DebugGetFieldName(KRef obj, int index); +// Returns name of type. +RUNTIME_USED const char* Konan_DebugGetTypeName(KRef obj); + #ifdef __cplusplus } #endif