diff --git a/lldb/include/lldb/Target/LanguageRuntime.h b/lldb/include/lldb/Target/LanguageRuntime.h index dac96659ec7a..289bdf518ca6 100644 --- a/lldb/include/lldb/Target/LanguageRuntime.h +++ b/lldb/include/lldb/Target/LanguageRuntime.h @@ -119,6 +119,12 @@ public: return false; } + virtual void + ModulesDidLoad (const ModuleList &module_list) + { + return; + } + protected: //------------------------------------------------------------------ // Classes that inherit from LanguageRuntime can see and modify these diff --git a/lldb/include/lldb/Target/ObjCLanguageRuntime.h b/lldb/include/lldb/Target/ObjCLanguageRuntime.h index 42a391478e3e..1cb88ed58c89 100644 --- a/lldb/include/lldb/Target/ObjCLanguageRuntime.h +++ b/lldb/include/lldb/Target/ObjCLanguageRuntime.h @@ -313,8 +313,8 @@ public: virtual ~ObjCLanguageRuntime(); - virtual lldb::LanguageType - GetLanguageType () const + lldb::LanguageType + GetLanguageType () const override { return lldb::eLanguageTypeObjC; } @@ -515,10 +515,10 @@ public: m_negative_complete_class_cache.clear(); } - virtual bool + bool GetTypeBitSize (const ClangASTType& clang_type, - uint64_t &size); - + uint64_t &size) override; + protected: //------------------------------------------------------------------ // Classes that inherit from ObjCLanguageRuntime can see and modify these @@ -645,6 +645,9 @@ protected: ISAToDescriptorIterator GetDescriptorIterator (const ConstString &name); + void + ReadObjCLibraryIfNeeded (const ModuleList &module_list); + DISALLOW_COPY_AND_ASSIGN (ObjCLanguageRuntime); }; diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp index ba1ccb17985f..258df3f16423 100644 --- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp +++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp @@ -39,6 +39,15 @@ using namespace lldb_private; #define PO_FUNCTION_TIMEOUT_USEC 15*1000*1000 +AppleObjCRuntime::AppleObjCRuntime(Process *process) : + ObjCLanguageRuntime (process), + m_read_objc_library (false), + m_objc_trampoline_handler_ap (), + m_Foundation_major() +{ + ReadObjCLibraryIfNeeded (process->GetTarget().GetImages()); +} + bool AppleObjCRuntime::GetObjectDescription (Stream &str, ValueObject &valobj) { @@ -443,3 +452,29 @@ AppleObjCRuntime::CreateExceptionSearchFilter () } } +void +AppleObjCRuntime::ReadObjCLibraryIfNeeded (const ModuleList &module_list) +{ + if (!HasReadObjCLibrary ()) + { + Mutex::Locker locker (module_list.GetMutex ()); + + size_t num_modules = module_list.GetSize(); + for (size_t i = 0; i < num_modules; i++) + { + auto mod = module_list.GetModuleAtIndex (i); + if (IsModuleObjCLibrary (mod)) + { + ReadObjCLibrary (mod); + break; + } + } + } +} + +void +AppleObjCRuntime::ModulesDidLoad (const ModuleList &module_list) +{ + ReadObjCLibraryIfNeeded (module_list); +} + diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.h b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.h index f9e00540cb7f..f8f73bae865d 100644 --- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.h +++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.h @@ -34,37 +34,37 @@ public: virtual ~AppleObjCRuntime() { } // These are generic runtime functions: - virtual bool - GetObjectDescription (Stream &str, Value &value, ExecutionContextScope *exe_scope); + bool + GetObjectDescription (Stream &str, Value &value, ExecutionContextScope *exe_scope) override; - virtual bool - GetObjectDescription (Stream &str, ValueObject &object); + bool + GetObjectDescription (Stream &str, ValueObject &object) override; - virtual bool - CouldHaveDynamicValue (ValueObject &in_value); + bool + CouldHaveDynamicValue (ValueObject &in_value) override; - virtual bool + bool GetDynamicTypeAndAddress (ValueObject &in_value, lldb::DynamicValueType use_dynamic, TypeAndOrName &class_type_or_name, - Address &address); + Address &address) override; // These are the ObjC specific functions. - virtual bool - IsModuleObjCLibrary (const lldb::ModuleSP &module_sp); + bool + IsModuleObjCLibrary (const lldb::ModuleSP &module_sp) override; - virtual bool - ReadObjCLibrary (const lldb::ModuleSP &module_sp); + bool + ReadObjCLibrary (const lldb::ModuleSP &module_sp) override; - virtual bool - HasReadObjCLibrary () + bool + HasReadObjCLibrary () override { return m_read_objc_library; } - virtual lldb::ThreadPlanSP - GetStepThroughTrampolinePlan (Thread &thread, bool stop_others); + lldb::ThreadPlanSP + GetStepThroughTrampolinePlan (Thread &thread, bool stop_others) override; // Get the "libobjc.A.dylib" module from the current target if we can find // it, also cache it once it is found to ensure quick lookups. @@ -76,10 +76,16 @@ public: //------------------------------------------------------------------ // Note there is no CreateInstance, Initialize & Terminate functions here, because // you can't make an instance of this generic runtime. - + + + // Sync up with the target + + void + ModulesDidLoad (const ModuleList &module_list) override; + protected: - virtual bool - CalculateHasNewLiteralsAndIndexing(); + bool + CalculateHasNewLiteralsAndIndexing() override; static bool AppleIsModuleObjCLibrary (const lldb::ModuleSP &module_sp); @@ -87,24 +93,27 @@ protected: static enum ObjCRuntimeVersions GetObjCVersion (Process *process, lldb::ModuleSP &objc_module_sp); + void + ReadObjCLibraryIfNeeded (const ModuleList &module_list); + //------------------------------------------------------------------ // PluginInterface protocol //------------------------------------------------------------------ public: - virtual void - SetExceptionBreakpoints(); + void + SetExceptionBreakpoints() override; - virtual void - ClearExceptionBreakpoints (); + void + ClearExceptionBreakpoints () override; - virtual bool - ExceptionBreakpointsAreSet (); + bool + ExceptionBreakpointsAreSet () override; - virtual bool - ExceptionBreakpointsExplainStop (lldb::StopInfoSP stop_reason); + bool + ExceptionBreakpointsExplainStop (lldb::StopInfoSP stop_reason) override; - virtual lldb::SearchFilterSP - CreateExceptionSearchFilter (); + lldb::SearchFilterSP + CreateExceptionSearchFilter () override; uint32_t GetFoundationVersion (); @@ -121,14 +130,8 @@ protected: llvm::Optional m_Foundation_major; - AppleObjCRuntime(Process *process) : - lldb_private::ObjCLanguageRuntime(process), - m_read_objc_library (false), - m_objc_trampoline_handler_ap (), - m_Foundation_major() - { - // Call CreateInstance instead. - } + // Call CreateInstance instead. + AppleObjCRuntime(Process *process); }; } // namespace lldb_private diff --git a/lldb/source/Target/ObjCLanguageRuntime.cpp b/lldb/source/Target/ObjCLanguageRuntime.cpp index 9ed2f26f7861..8dd43c76ea79 100644 --- a/lldb/source/Target/ObjCLanguageRuntime.cpp +++ b/lldb/source/Target/ObjCLanguageRuntime.cpp @@ -44,7 +44,6 @@ ObjCLanguageRuntime::ObjCLanguageRuntime (Process *process) : m_complete_class_cache(), m_negative_complete_class_cache() { - } bool diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp index abf214b2bde7..606c2c0b2ff2 100644 --- a/lldb/source/Target/Process.cpp +++ b/lldb/source/Target/Process.cpp @@ -6469,13 +6469,29 @@ Process::ModulesDidLoad (ModuleList &module_list) runtime->ModulesDidLoad(module_list); } + // Let any language runtimes we have already created know + // about the modules that loaded. + + // Iterate over a copy of this language runtime list in case + // the language runtime ModulesDidLoad somehow causes the language + // riuntime to be unloaded. + LanguageRuntimeCollection language_runtimes(m_language_runtimes); + for (const auto &pair: language_runtimes) + { + // We must check language_runtime_sp to make sure it is not + // NULL as we might cache the fact that we didn't have a + // language runtime for a language. + LanguageRuntimeSP language_runtime_sp = pair.second; + if (language_runtime_sp) + language_runtime_sp->ModulesDidLoad(module_list); + } } ThreadCollectionSP Process::GetHistoryThreads(lldb::addr_t addr) { ThreadCollectionSP threads; - + const MemoryHistorySP &memory_history = MemoryHistory::FindPlugin(shared_from_this()); if (! memory_history.get()) { diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp index bbee4051c7e2..193d62d4fd00 100644 --- a/lldb/source/Target/Target.cpp +++ b/lldb/source/Target/Target.cpp @@ -1259,24 +1259,6 @@ Target::ModulesDidLoad (ModuleList &module_list) if (m_process_sp) { m_process_sp->ModulesDidLoad (module_list); - - // This assumes there can only be one libobjc loaded. - ObjCLanguageRuntime *objc_runtime = m_process_sp->GetObjCLanguageRuntime (); - if (objc_runtime && !objc_runtime->HasReadObjCLibrary ()) - { - Mutex::Locker locker (module_list.GetMutex ()); - - size_t num_modules = module_list.GetSize(); - for (size_t i = 0; i < num_modules; i++) - { - auto mod = module_list.GetModuleAtIndex (i); - if (objc_runtime->IsModuleObjCLibrary (mod)) - { - objc_runtime->ReadObjCLibrary (mod); - break; - } - } - } } BroadcastEvent (eBroadcastBitModulesLoaded, new TargetEventData (this->shared_from_this(), module_list)); }