From d230848a85a922260b7ad6984f2dd19222c125a6 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Tue, 18 Jan 2022 16:37:30 -0800 Subject: [PATCH] [lldb] Print an error message when we're reading libobjc.A.dylib from memory Use libobjc.A.dylib as a sentinel to detect situations where we're reading libraries from process memory instead of the shared cache. Differential revision: https://reviews.llvm.org/D117623 --- .../AppleObjCRuntime/AppleObjCRuntimeV2.cpp | 28 ++++++++++++++++++- .../AppleObjCRuntime/AppleObjCRuntimeV2.h | 1 + 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp index bd6b6335ca8c..f2cf25f93eb2 100644 --- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp +++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp @@ -671,7 +671,7 @@ AppleObjCRuntimeV2::AppleObjCRuntimeV2(Process *process, static const ConstString g_objc_copyRealizedClassList( "_ZL33objc_copyRealizedClassList_nolockPj"); m_has_objc_copyRealizedClassList = HasSymbol(g_objc_copyRealizedClassList); - + WarnIfNoExpandedSharedCache(); RegisterObjCExceptionRecognizer(process); } @@ -2355,6 +2355,32 @@ void AppleObjCRuntimeV2::WarnIfNoClassesCached( } } +void AppleObjCRuntimeV2::WarnIfNoExpandedSharedCache() { + if (!m_objc_module_sp) + return; + + ObjectFile *object_file = m_objc_module_sp->GetObjectFile(); + if (!object_file) + return; + + if (!object_file->IsInMemory()) + return; + + Target &target = GetProcess()->GetTarget(); + Debugger &debugger = target.GetDebugger(); + if (auto stream = debugger.GetAsyncOutputStream()) { + const char *msg = "read from the shared cache"; + if (PlatformSP platform_sp = target.GetPlatform()) + msg = platform_sp->IsHost() + ? "read from the host's in-memory shared cache" + : "find the on-disk shared cache for this device"; + stream->Printf("warning: libobjc.A.dylib is being read from process " + "memory. This indicates that LLDB could not %s. This will " + "likely reduce debugging performance.\n", + msg); + } +} + DeclVendor *AppleObjCRuntimeV2::GetDeclVendor() { if (!m_decl_vendor_up) m_decl_vendor_up = std::make_unique(*this); diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h index 6266634e64c5..e1a6b7cde48a 100644 --- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h +++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h @@ -399,6 +399,7 @@ private: }; void WarnIfNoClassesCached(SharedCacheWarningReason reason); + void WarnIfNoExpandedSharedCache(); lldb::addr_t GetSharedCacheReadOnlyAddress(); lldb::addr_t GetSharedCacheBaseAddress();