From 6385c2ab8ff8304eafa822012c40934690bde124 Mon Sep 17 00:00:00 2001 From: Davide Italiano Date: Fri, 20 Mar 2020 13:42:21 -0700 Subject: [PATCH] [AppleObjCRuntimeV2] Force lazily allocated class names to be resolved. Fixes a couple of tests on new versions of the Obj-C runtime. --- .../AppleObjCRuntime/AppleObjCRuntimeV2.cpp | 34 ++++++++++++++++++- .../Shell/ExecControl/StopHook/stop-hook.test | 2 +- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp index 9fea9a217dce..4a07c792eebb 100644 --- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp +++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp @@ -1175,6 +1175,28 @@ AppleObjCRuntimeV2::GetClassDescriptorFromISA(ObjCISA isa) { return class_descriptor_sp; } +static std::pair ObjCGetClassNameRaw( + AppleObjCRuntime::ObjCISA isa, + Process *process) { + StreamString expr_string; + std::string input = std::to_string(isa); + expr_string.Printf("(const char *)objc_debug_class_getNameRaw(%s)", + input.c_str()); + + ValueObjectSP result_sp; + EvaluateExpressionOptions eval_options; + eval_options.SetLanguage(lldb::eLanguageTypeObjC); + eval_options.SetResultIsInternal(true); + eval_options.SetGenerateDebugInfo(true); + eval_options.SetTimeout(process->GetUtilityExpressionTimeout()); + auto eval_result = process->GetTarget().EvaluateExpression( + expr_string.GetData(), + process->GetThreadList().GetSelectedThread()->GetSelectedFrame().get(), + result_sp, eval_options); + ConstString type_name(result_sp->GetSummaryAsCString()); + return std::make_pair(eval_result == eExpressionCompleted, type_name); +} + ObjCLanguageRuntime::ClassDescriptorSP AppleObjCRuntimeV2::GetClassDescriptor(ValueObject &valobj) { ClassDescriptorSP objc_class_sp; @@ -1210,7 +1232,10 @@ AppleObjCRuntimeV2::GetClassDescriptor(ValueObject &valobj) { return objc_class_sp; objc_class_sp = GetClassDescriptorFromISA(isa); - if (isa && !objc_class_sp) { + + if (objc_class_sp) + return objc_class_sp; + else { Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_TYPES)); LLDB_LOGF(log, @@ -1219,6 +1244,13 @@ AppleObjCRuntimeV2::GetClassDescriptor(ValueObject &valobj) { "not in class descriptor cache 0x%" PRIx64, isa_pointer, isa); } + + ClassDescriptorSP descriptor_sp(new ClassDescriptorV2(*this, isa, nullptr)); + auto resolved = ObjCGetClassNameRaw(isa, process); + if (resolved.first == true) { + AddClass(isa, descriptor_sp, resolved.second.AsCString()); + objc_class_sp = descriptor_sp; + } return objc_class_sp; } diff --git a/lldb/test/Shell/ExecControl/StopHook/stop-hook.test b/lldb/test/Shell/ExecControl/StopHook/stop-hook.test index a06de6634ea1..7e5b37b63854 100644 --- a/lldb/test/Shell/ExecControl/StopHook/stop-hook.test +++ b/lldb/test/Shell/ExecControl/StopHook/stop-hook.test @@ -51,7 +51,7 @@ run thread step-over # Stepping inside of the stop hook range # CHECK: (lldb) thread step-over -# CHECK-NEXT: (void *) $1 = 0x +# CHECK-NEXT: (void *) $2 = 0x # CHECK: ->{{.*}} // We should stop here after stepping. process continue