From 1759848be00a5ab48ba5bccb70945b30c68da7f1 Mon Sep 17 00:00:00 2001 From: Enrico Granata Date: Thu, 8 Nov 2012 02:22:02 +0000 Subject: [PATCH] This commit does three things: (a) introduces a new notification model for adding/removing/changing modules to a ModuleList, and applies it to the Target's ModuleList, so that we make sure to always trigger the right set of actions whenever modules come and go in a target. Certain spots in the code still need to "manually" notify the Target for several reasons, so this is a work in progress (b) adds a new capability to the Platforms: locating a scripting resources associated to a module. A scripting resource is a Python file that can load commands, formatters, ... and any other action of interest corresponding to the loading of a module. At the moment, this is only implemented on Mac OS X and only for files inside .dSYM bundles - the next step is going to be letting the frameworks themselves hold their scripting resources. Implementors of platforms for other systems are free to implement "the right thing" for their own worlds (c) hooking up items (a) and (b) so that targets auto-load the scripting resources as the corresponding modules get loaded in a target. This has a few caveats at the moment: - the user needs to manually add the .py file to the dSYM (soon, it will also work in the framework itself) - if two modules with the same name show up during the lifetime of an LLDB session, the second one won't be able to load its scripting resource, but will otherwise work just fine llvm-svn: 167569 --- lldb/include/lldb/Core/Module.h | 3 + lldb/include/lldb/Core/ModuleList.h | 78 +++++++++--- lldb/include/lldb/Host/Symbols.h | 2 +- lldb/include/lldb/Target/Platform.h | 9 ++ lldb/include/lldb/Target/Target.h | 47 +++++--- lldb/source/Commands/CommandObjectTarget.cpp | 8 +- lldb/source/Core/Module.cpp | 47 +++++++- lldb/source/Core/ModuleList.cpp | 134 ++++++++++++++++----- lldb/source/Core/SearchFilter.cpp | 8 +- lldb/source/Expression/ClangASTSource.cpp | 6 +- .../Darwin-Kernel/DynamicLoaderDarwinKernel.cpp | 7 +- .../MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp | 14 ++- .../POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp | 7 +- .../DynamicLoader/Static/DynamicLoaderStatic.cpp | 5 +- .../ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp | 6 +- .../ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp | 2 +- .../AppleObjCTrampolineHandler.cpp | 2 +- .../Plugins/Platform/MacOSX/PlatformDarwin.cpp | 32 +++++ .../Plugins/Platform/MacOSX/PlatformDarwin.h | 3 + lldb/source/Target/ObjCLanguageRuntime.cpp | 2 +- lldb/source/Target/Platform.cpp | 6 + lldb/source/Target/Process.cpp | 2 +- lldb/source/Target/Target.cpp | 63 +++++++--- 23 files changed, 367 insertions(+), 126 deletions(-) diff --git a/lldb/include/lldb/Core/Module.h b/lldb/include/lldb/Core/Module.h index 8cd7a16..2373033 100644 --- a/lldb/include/lldb/Core/Module.h +++ b/lldb/include/lldb/Core/Module.h @@ -532,6 +532,9 @@ public: bool IsLoadedInTarget (Target *target); + bool + LoadScriptingResourceInTarget (Target *target, Error& error); + //------------------------------------------------------------------ /// Get the number of compile units for this module. /// diff --git a/lldb/include/lldb/Core/ModuleList.h b/lldb/include/lldb/Core/ModuleList.h index 38d397b..7c9f493 100644 --- a/lldb/include/lldb/Core/ModuleList.h +++ b/lldb/include/lldb/Core/ModuleList.h @@ -27,6 +27,25 @@ namespace lldb_private { class ModuleList { public: + + class Notifier + { + public: + virtual void + ModuleAdded (const lldb::ModuleSP& module_sp) = 0; + virtual void + ModuleRemoved (const lldb::ModuleSP& module_sp) = 0; + virtual void + ModuleUpdated (const lldb::ModuleSP& old_module_sp, + const lldb::ModuleSP& new_module_sp) = 0; + virtual void + WillClearList () = 0; + + virtual + ~Notifier () + {} + }; + //------------------------------------------------------------------ /// Default constructor. /// @@ -44,6 +63,8 @@ public: /// Another module list object. //------------------------------------------------------------------ ModuleList (const ModuleList& rhs); + + ModuleList (ModuleList::Notifier* notifier); //------------------------------------------------------------------ /// Destructor. @@ -91,6 +112,15 @@ public: bool AppendIfNeeded (const lldb::ModuleSP &module_sp); + void + Append (const ModuleList& module_list); + + bool + AppendIfNeeded (const ModuleList& module_list); + + bool + ReplaceModule (const lldb::ModuleSP &old_module_sp, const lldb::ModuleSP &new_module_sp); + //------------------------------------------------------------------ /// Clear the object's state. /// @@ -130,7 +160,7 @@ public: const char *prefix_cstr); Mutex & - GetMutex () + GetMutex () const { return m_modules_mutex; } @@ -151,7 +181,7 @@ public: /// @see ModuleList::GetSize() //------------------------------------------------------------------ lldb::ModuleSP - GetModuleAtIndex (uint32_t idx); + GetModuleAtIndex (uint32_t idx) const; //------------------------------------------------------------------ /// Get the module shared pointer for the module at index \a idx without @@ -168,7 +198,7 @@ public: /// @see ModuleList::GetSize() //------------------------------------------------------------------ lldb::ModuleSP - GetModuleAtIndexUnlocked (uint32_t idx); + GetModuleAtIndexUnlocked (uint32_t idx) const; //------------------------------------------------------------------ /// Get the module pointer for the module at index \a idx. @@ -226,7 +256,7 @@ public: uint32_t FindCompileUnits (const FileSpec &path, bool append, - SymbolContextList &sc_list); + SymbolContextList &sc_list) const; //------------------------------------------------------------------ /// @see Module::FindFunctions () @@ -237,7 +267,7 @@ public: bool include_symbols, bool include_inlines, bool append, - SymbolContextList &sc_list); + SymbolContextList &sc_list) const; //------------------------------------------------------------------ /// Find global and static variables by name. @@ -266,7 +296,7 @@ public: FindGlobalVariables (const ConstString &name, bool append, uint32_t max_matches, - VariableList& variable_list); + VariableList& variable_list) const; //------------------------------------------------------------------ /// Find global and static variables by regular exression. @@ -294,7 +324,7 @@ public: FindGlobalVariables (const RegularExpression& regex, bool append, uint32_t max_matches, - VariableList& variable_list); + VariableList& variable_list) const; //------------------------------------------------------------------ /// Finds the first module whose file specification matches \a @@ -332,7 +362,7 @@ public: ModuleList& matching_module_list) const; lldb::ModuleSP - FindModule (const Module *module_ptr); + FindModule (const Module *module_ptr) const; //------------------------------------------------------------------ // Find a module by UUID @@ -342,22 +372,22 @@ public: // finding modules by UUID values is very efficient and accurate. //------------------------------------------------------------------ lldb::ModuleSP - FindModule (const UUID &uuid); + FindModule (const UUID &uuid) const; lldb::ModuleSP - FindFirstModule (const ModuleSpec &module_spec); + FindFirstModule (const ModuleSpec &module_spec) const; size_t FindSymbolsWithNameAndType (const ConstString &name, lldb::SymbolType symbol_type, SymbolContextList &sc_list, - bool append = false); + bool append = false) const; size_t FindSymbolsMatchingRegExAndType (const RegularExpression ®ex, lldb::SymbolType symbol_type, SymbolContextList &sc_list, - bool append = false); + bool append = false) const; //------------------------------------------------------------------ /// Find types by name. @@ -397,7 +427,7 @@ public: const ConstString &name, bool name_is_fully_qualified, uint32_t max_matches, - TypeList& types); + TypeList& types) const; bool FindSourceFile (const FileSpec &orig_spec, FileSpec &new_spec) const; @@ -416,7 +446,7 @@ public: bool ResolveFileAddress (lldb::addr_t vm_addr, - Address& so_addr); + Address& so_addr) const; //------------------------------------------------------------------ /// @copydoc Module::ResolveSymbolContextForAddress (const Address &,uint32_t,SymbolContext&) @@ -424,7 +454,7 @@ public: uint32_t ResolveSymbolContextForAddress (const Address& so_addr, uint32_t resolve_scope, - SymbolContext& sc); + SymbolContext& sc) const; //------------------------------------------------------------------ /// @copydoc Module::ResolveSymbolContextForFilePath (const char *,uint32_t,bool,uint32_t,SymbolContextList&) @@ -434,7 +464,7 @@ public: uint32_t line, bool check_inlines, uint32_t resolve_scope, - SymbolContextList& sc_list); + SymbolContextList& sc_list) const; //------------------------------------------------------------------ /// @copydoc Module::ResolveSymbolContextsForFileSpec (const FileSpec &,uint32_t,bool,uint32_t,SymbolContextList&) @@ -444,7 +474,7 @@ public: uint32_t line, bool check_inlines, uint32_t resolve_scope, - SymbolContextList& sc_list); + SymbolContextList& sc_list) const; //------------------------------------------------------------------ /// Gets the size of the module list. @@ -485,12 +515,26 @@ protected: //------------------------------------------------------------------ typedef std::vector collection; ///< The module collection type. + void + AppendImpl (const lldb::ModuleSP &module_sp, bool use_notifier = true); + + bool + RemoveImpl (const lldb::ModuleSP &module_sp, bool use_notifier = true); + + collection::iterator + RemoveImpl (collection::iterator pos, bool use_notifier = true); + + void + ClearImpl (bool use_notifier = true); + //------------------------------------------------------------------ // Member variables. //------------------------------------------------------------------ collection m_modules; ///< The collection of modules. mutable Mutex m_modules_mutex; + Notifier* m_notifier; + }; } // namespace lldb_private diff --git a/lldb/include/lldb/Host/Symbols.h b/lldb/include/lldb/Host/Symbols.h index daba94b..9db68e1 100644 --- a/lldb/include/lldb/Host/Symbols.h +++ b/lldb/include/lldb/Host/Symbols.h @@ -41,7 +41,7 @@ public: //---------------------------------------------------------------------- static FileSpec LocateExecutableSymbolFile (const ModuleSpec &module_spec); - + static FileSpec FindSymbolFileInBundle (const FileSpec& dsym_bundle_fspec, const lldb_private::UUID *uuid, diff --git a/lldb/include/lldb/Target/Platform.h b/lldb/include/lldb/Target/Platform.h index 89f6441..2f86042 100644 --- a/lldb/include/lldb/Target/Platform.h +++ b/lldb/include/lldb/Target/Platform.h @@ -291,6 +291,15 @@ namespace lldb_private { const UUID *uuid_ptr, FileSpec &local_file); + //---------------------------------------------------------------------- + // Locate the scripting resource given a module specification. + // + // Locating the file should happen only on the local computer or using + // the current computers global settings. + //---------------------------------------------------------------------- + virtual FileSpec + LocateExecutableScriptingResource (const ModuleSpec &module_spec); + virtual Error GetSharedModule (const ModuleSpec &module_spec, lldb::ModuleSP &module_sp, diff --git a/lldb/include/lldb/Target/Target.h b/lldb/include/lldb/Target/Target.h index 65cdaa1..851ca3b 100644 --- a/lldb/include/lldb/Target/Target.h +++ b/lldb/include/lldb/Target/Target.h @@ -47,7 +47,6 @@ typedef enum InlineStrategy eInlineBreakpointsAlways } InlineStrategy; - //---------------------------------------------------------------------- // TargetProperties //---------------------------------------------------------------------- @@ -266,7 +265,8 @@ class Target : public STD_ENABLE_SHARED_FROM_THIS(Target), public TargetProperties, public Broadcaster, - public ExecutionContextScope + public ExecutionContextScope, + public ModuleList::Notifier { public: friend class TargetList; @@ -586,13 +586,6 @@ public: bool IgnoreWatchpointByID (lldb::watch_id_t watch_id, uint32_t ignore_count); - void - ModulesDidLoad (ModuleList &module_list); - - void - ModulesDidUnload (ModuleList &module_list); - - //------------------------------------------------------------------ /// Get \a load_addr as a callable code load address for this target /// @@ -623,13 +616,30 @@ public: GetOpcodeLoadAddress (lldb::addr_t load_addr, lldb::AddressClass addr_class = lldb::eAddressClassInvalid) const; protected: - void - ModuleAdded (lldb::ModuleSP &module_sp); + //------------------------------------------------------------------ + /// Implementing of ModuleList::Notifier. + //------------------------------------------------------------------ + + virtual void + ModuleAdded (const lldb::ModuleSP& module_sp); + + virtual void + ModuleRemoved (const lldb::ModuleSP& module_sp); + + virtual void + ModuleUpdated (const lldb::ModuleSP& old_module_sp, + const lldb::ModuleSP& new_module_sp); + virtual void + WillClearList (); +public: + void - ModuleUpdated (lldb::ModuleSP &old_module_sp, lldb::ModuleSP &new_module_sp); + ModulesDidLoad (ModuleList &module_list); -public: + void + ModulesDidUnload (ModuleList &module_list); + //------------------------------------------------------------------ /// Gets the module for the main executable. /// @@ -702,18 +712,17 @@ public: /// @return /// A list of Module objects in a module list. //------------------------------------------------------------------ - ModuleList& - GetImages () - { - return m_images; - } - const ModuleList& GetImages () const { return m_images; } + ModuleList& + GetImages () + { + return m_images; + } //------------------------------------------------------------------ /// Return whether this FileSpec corresponds to a module that should be considered for general searches. diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp index 679c5dd..14018a4 100644 --- a/lldb/source/Commands/CommandObjectTarget.cpp +++ b/lldb/source/Commands/CommandObjectTarget.cpp @@ -2255,7 +2255,7 @@ protected: if (command.GetArgumentCount() == 0) { // Dump all sections for all modules images - ModuleList &target_modules = target->GetImages(); + const ModuleList &target_modules = target->GetImages(); Mutex::Locker modules_locker (target_modules.GetMutex()); const uint32_t num_modules = target_modules.GetSize(); if (num_modules > 0) @@ -2368,7 +2368,7 @@ protected: { FileSpec file_spec(arg_cstr, false); - ModuleList &target_modules = target->GetImages(); + const ModuleList &target_modules = target->GetImages(); Mutex::Locker modules_locker(target_modules.GetMutex()); const uint32_t num_modules = target_modules.GetSize(); if (num_modules > 0) @@ -2940,7 +2940,7 @@ protected: Mutex::Locker locker; // This locker will be locked on the mutex in module_list_ptr if it is non-NULL. // Otherwise it will lock the AllocationModuleCollectionMutex when accessing // the global module list directly. - ModuleList *module_list_ptr = NULL; + const ModuleList *module_list_ptr = NULL; const size_t argc = command.GetArgumentCount(); if (argc == 0) { @@ -3825,7 +3825,7 @@ protected: // Dump all sections for all other modules - ModuleList &target_modules = target->GetImages(); + const ModuleList &target_modules = target->GetImages(); Mutex::Locker modules_locker(target_modules.GetMutex()); const uint32_t num_modules = target_modules.GetSize(); if (num_modules > 0) diff --git a/lldb/source/Core/Module.cpp b/lldb/source/Core/Module.cpp index 08f826e..e349d63 100644 --- a/lldb/source/Core/Module.cpp +++ b/lldb/source/Core/Module.cpp @@ -7,6 +7,7 @@ // //===----------------------------------------------------------------------===// +#include "lldb/Core/Error.h" #include "lldb/Core/Module.h" #include "lldb/Core/DataBuffer.h" #include "lldb/Core/DataBufferHeap.h" @@ -18,6 +19,9 @@ #include "lldb/Core/StreamString.h" #include "lldb/Core/Timer.h" #include "lldb/Host/Host.h" +#include "lldb/Host/Symbols.h" +#include "lldb/Interpreter/CommandInterpreter.h" +#include "lldb/Interpreter/ScriptInterpreter.h" #include "lldb/lldb-private-log.h" #include "lldb/Symbol/CompileUnit.h" #include "lldb/Symbol/ObjectFile.h" @@ -1132,7 +1136,48 @@ Module::IsLoadedInTarget (Target *target) } return false; } -bool + +bool +Module::LoadScriptingResourceInTarget (Target *target, Error& error) +{ + if (!target) + { + error.SetErrorString("invalid destination Target"); + return false; + } + + PlatformSP platform_sp(target->GetPlatform()); + + if (!platform_sp) + { + error.SetErrorString("invalid Platform"); + return false; + } + + ModuleSpec module_spec(GetFileSpec()); + FileSpec scripting_fspec = platform_sp->LocateExecutableScriptingResource(module_spec); + Debugger &debugger(target->GetDebugger()); + if (scripting_fspec && scripting_fspec.Exists()) + { + ScriptInterpreter *script_interpreter = debugger.GetCommandInterpreter().GetScriptInterpreter(); + if (script_interpreter) + { + StreamString scripting_stream; + scripting_fspec.Dump(&scripting_stream); + bool did_load = script_interpreter->LoadScriptingModule(scripting_stream.GetData(), false, true, error); + if (!did_load) + return false; + } + else + { + error.SetErrorString("invalid ScriptInterpreter"); + return false; + } + } + return true; +} + +bool Module::SetArchitecture (const ArchSpec &new_arch) { if (!m_arch.IsValid()) diff --git a/lldb/source/Core/ModuleList.cpp b/lldb/source/Core/ModuleList.cpp index 338482b..c7f7484 100644 --- a/lldb/source/Core/ModuleList.cpp +++ b/lldb/source/Core/ModuleList.cpp @@ -30,7 +30,8 @@ using namespace lldb_private; //---------------------------------------------------------------------- ModuleList::ModuleList() : m_modules(), - m_modules_mutex (Mutex::eMutexTypeRecursive) + m_modules_mutex (Mutex::eMutexTypeRecursive), + m_notifier(NULL) { } @@ -44,6 +45,14 @@ ModuleList::ModuleList(const ModuleList& rhs) : Mutex::Locker lhs_locker(m_modules_mutex); Mutex::Locker rhs_locker(rhs.m_modules_mutex); m_modules = rhs.m_modules; + m_notifier = rhs.m_notifier; +} + +ModuleList::ModuleList (ModuleList::Notifier* notifier) : + m_modules(), + m_modules_mutex (Mutex::eMutexTypeRecursive), + m_notifier(notifier) +{ } //---------------------------------------------------------------------- @@ -57,6 +66,7 @@ ModuleList::operator= (const ModuleList& rhs) Mutex::Locker lhs_locker(m_modules_mutex); Mutex::Locker rhs_locker(rhs.m_modules_mutex); m_modules = rhs.m_modules; + m_notifier = rhs.m_notifier; } return *this; } @@ -69,16 +79,24 @@ ModuleList::~ModuleList() } void -ModuleList::Append (const ModuleSP &module_sp) +ModuleList::AppendImpl (const ModuleSP &module_sp, bool use_notifier) { if (module_sp) { Mutex::Locker locker(m_modules_mutex); m_modules.push_back(module_sp); + if (use_notifier && m_notifier) + m_notifier->ModuleAdded(module_sp); } } void +ModuleList::Append (const ModuleSP &module_sp) +{ + AppendImpl (module_sp); +} + +void ModuleList::ReplaceEquivalent (const ModuleSP &module_sp) { if (module_sp) @@ -95,12 +113,12 @@ ModuleList::ReplaceEquivalent (const ModuleSP &module_sp) { ModuleSP module_sp (m_modules[idx]); if (module_sp->MatchesModuleSpec (equivalent_module_spec)) - m_modules.erase(m_modules.begin() + idx); + RemoveImpl(m_modules.begin() + idx); else ++idx; } // Now add the new module to the list - m_modules.push_back(module_sp); + Append(module_sp); } } @@ -117,14 +135,30 @@ ModuleList::AppendIfNeeded (const ModuleSP &module_sp) return false; // Already in the list } // Only push module_sp on the list if it wasn't already in there. - m_modules.push_back(module_sp); + Append(module_sp); return true; } return false; } +void +ModuleList::Append (const ModuleList& module_list) +{ + for (auto pos : module_list.m_modules) + Append(pos); +} + bool -ModuleList::Remove (const ModuleSP &module_sp) +ModuleList::AppendIfNeeded (const ModuleList& module_list) +{ + bool any_in = false; + for (auto pos : module_list.m_modules) + any_in = AppendIfNeeded(pos) | any_in; + return any_in; +} + +bool +ModuleList::RemoveImpl (const ModuleSP &module_sp, bool use_notifier) { if (module_sp) { @@ -135,6 +169,8 @@ ModuleList::Remove (const ModuleSP &module_sp) if (pos->get() == module_sp.get()) { m_modules.erase (pos); + if (use_notifier && m_notifier) + m_notifier->ModuleRemoved(module_sp); return true; } } @@ -142,6 +178,33 @@ ModuleList::Remove (const ModuleSP &module_sp) return false; } +ModuleList::collection::iterator +ModuleList::RemoveImpl (ModuleList::collection::iterator pos, bool use_notifier) +{ + ModuleSP module_sp(*pos); + collection::iterator retval = m_modules.erase(pos); + if (use_notifier && m_notifier) + m_notifier->ModuleRemoved(module_sp); + return retval; +} + +bool +ModuleList::Remove (const ModuleSP &module_sp) +{ + return RemoveImpl (module_sp); +} + +bool +ModuleList::ReplaceModule (const lldb::ModuleSP &old_module_sp, const lldb::ModuleSP &new_module_sp) +{ + if (!RemoveImpl(old_module_sp, false)) + return false; + AppendImpl (new_module_sp, false); + if (m_notifier) + m_notifier->ModuleUpdated(old_module_sp,new_module_sp); + return true; +} + bool ModuleList::RemoveIfOrphaned (const Module *module_ptr) { @@ -155,7 +218,7 @@ ModuleList::RemoveIfOrphaned (const Module *module_ptr) { if (pos->unique()) { - pos = m_modules.erase (pos); + pos = RemoveImpl(pos); return true; } else @@ -187,7 +250,7 @@ ModuleList::RemoveOrphans (bool mandatory) { if (pos->unique()) { - pos = m_modules.erase (pos); + pos = RemoveImpl(pos); ++remove_count; } else @@ -213,20 +276,25 @@ ModuleList::Remove (ModuleList &module_list) } - void ModuleList::Clear() { - Mutex::Locker locker(m_modules_mutex); - m_modules.clear(); + ClearImpl(); } void ModuleList::Destroy() { + ClearImpl(); +} + +void +ModuleList::ClearImpl (bool use_notifier) +{ Mutex::Locker locker(m_modules_mutex); - collection empty; - m_modules.swap(empty); + if (use_notifier && m_notifier) + m_notifier->WillClearList(); + m_modules.clear(); } Module* @@ -245,14 +313,14 @@ ModuleList::GetModulePointerAtIndexUnlocked (uint32_t idx) const } ModuleSP -ModuleList::GetModuleAtIndex(uint32_t idx) +ModuleList::GetModuleAtIndex(uint32_t idx) const { Mutex::Locker locker(m_modules_mutex); return GetModuleAtIndexUnlocked(idx); } ModuleSP -ModuleList::GetModuleAtIndexUnlocked(uint32_t idx) +ModuleList::GetModuleAtIndexUnlocked(uint32_t idx) const { ModuleSP module_sp; if (idx < m_modules.size()) @@ -266,7 +334,7 @@ ModuleList::FindFunctions (const ConstString &name, bool include_symbols, bool include_inlines, bool append, - SymbolContextList &sc_list) + SymbolContextList &sc_list) const { if (!append) sc_list.Clear(); @@ -284,7 +352,7 @@ ModuleList::FindFunctions (const ConstString &name, uint32_t ModuleList::FindCompileUnits (const FileSpec &path, bool append, - SymbolContextList &sc_list) + SymbolContextList &sc_list) const { if (!append) sc_list.Clear(); @@ -303,11 +371,11 @@ uint32_t ModuleList::FindGlobalVariables (const ConstString &name, bool append, uint32_t max_matches, - VariableList& variable_list) + VariableList& variable_list) const { size_t initial_size = variable_list.GetSize(); Mutex::Locker locker(m_modules_mutex); - collection::iterator pos, end = m_modules.end(); + collection::const_iterator pos, end = m_modules.end(); for (pos = m_modules.begin(); pos != end; ++pos) { (*pos)->FindGlobalVariables (name, NULL, append, max_matches, variable_list); @@ -320,11 +388,11 @@ uint32_t ModuleList::FindGlobalVariables (const RegularExpression& regex, bool append, uint32_t max_matches, - VariableList& variable_list) + VariableList& variable_list) const { size_t initial_size = variable_list.GetSize(); Mutex::Locker locker(m_modules_mutex); - collection::iterator pos, end = m_modules.end(); + collection::const_iterator pos, end = m_modules.end(); for (pos = m_modules.begin(); pos != end; ++pos) { (*pos)->FindGlobalVariables (regex, append, max_matches, variable_list); @@ -337,14 +405,14 @@ size_t ModuleList::FindSymbolsWithNameAndType (const ConstString &name, SymbolType symbol_type, SymbolContextList &sc_list, - bool append) + bool append) const { Mutex::Locker locker(m_modules_mutex); if (!append) sc_list.Clear(); size_t initial_size = sc_list.GetSize(); - collection::iterator pos, end = m_modules.end(); + collection::const_iterator pos, end = m_modules.end(); for (pos = m_modules.begin(); pos != end; ++pos) (*pos)->FindSymbolsWithNameAndType (name, symbol_type, sc_list); return sc_list.GetSize() - initial_size; @@ -354,14 +422,14 @@ size_t ModuleList::FindSymbolsMatchingRegExAndType (const RegularExpression ®ex, lldb::SymbolType symbol_type, SymbolContextList &sc_list, - bool append) + bool append) const { Mutex::Locker locker(m_modules_mutex); if (!append) sc_list.Clear(); size_t initial_size = sc_list.GetSize(); - collection::iterator pos, end = m_modules.end(); + collection::const_iterator pos, end = m_modules.end(); for (pos = m_modules.begin(); pos != end; ++pos) (*pos)->FindSymbolsMatchingRegExAndType (regex, symbol_type, sc_list); return sc_list.GetSize() - initial_size; @@ -384,7 +452,7 @@ ModuleList::FindModules (const ModuleSpec &module_spec, ModuleList& matching_mod } ModuleSP -ModuleList::FindModule (const Module *module_ptr) +ModuleList::FindModule (const Module *module_ptr) const { ModuleSP module_sp; @@ -407,7 +475,7 @@ ModuleList::FindModule (const Module *module_ptr) } ModuleSP -ModuleList::FindModule (const UUID &uuid) +ModuleList::FindModule (const UUID &uuid) const { ModuleSP module_sp; @@ -430,7 +498,7 @@ ModuleList::FindModule (const UUID &uuid) uint32_t -ModuleList::FindTypes (const SymbolContext& sc, const ConstString &name, bool name_is_fully_qualified, uint32_t max_matches, TypeList& types) +ModuleList::FindTypes (const SymbolContext& sc, const ConstString &name, bool name_is_fully_qualified, uint32_t max_matches, TypeList& types) const { Mutex::Locker locker(m_modules_mutex); @@ -487,7 +555,7 @@ ModuleList::FindSourceFile (const FileSpec &orig_spec, FileSpec &new_spec) const ModuleSP -ModuleList::FindFirstModule (const ModuleSpec &module_spec) +ModuleList::FindFirstModule (const ModuleSpec &module_spec) const { ModuleSP module_sp; Mutex::Locker locker(m_modules_mutex); @@ -554,7 +622,7 @@ ModuleList::LogUUIDAndPaths (LogSP &log_sp, const char *prefix_cstr) } bool -ModuleList::ResolveFileAddress (lldb::addr_t vm_addr, Address& so_addr) +ModuleList::ResolveFileAddress (lldb::addr_t vm_addr, Address& so_addr) const { Mutex::Locker locker(m_modules_mutex); collection::const_iterator pos, end = m_modules.end(); @@ -568,7 +636,7 @@ ModuleList::ResolveFileAddress (lldb::addr_t vm_addr, Address& so_addr) } uint32_t -ModuleList::ResolveSymbolContextForAddress (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc) +ModuleList::ResolveSymbolContextForAddress (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc) const { // The address is already section offset so it has a module uint32_t resolved_flags = 0; @@ -604,14 +672,14 @@ ModuleList::ResolveSymbolContextForFilePath bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list -) +) const { FileSpec file_spec(file_path, false); return ResolveSymbolContextsForFileSpec (file_spec, line, check_inlines, resolve_scope, sc_list); } uint32_t -ModuleList::ResolveSymbolContextsForFileSpec (const FileSpec &file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list) +ModuleList::ResolveSymbolContextsForFileSpec (const FileSpec &file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list) const { Mutex::Locker locker(m_modules_mutex); collection::const_iterator pos, end = m_modules.end(); diff --git a/lldb/source/Core/SearchFilter.cpp b/lldb/source/Core/SearchFilter.cpp index 60f7dbb..d9af19e 100644 --- a/lldb/source/Core/SearchFilter.cpp +++ b/lldb/source/Core/SearchFilter.cpp @@ -204,7 +204,7 @@ SearchFilter::DoModuleIteration (const SymbolContext &context, Searcher &searche } else { - ModuleList &target_images = m_target_sp->GetImages(); + const ModuleList &target_images = m_target_sp->GetImages(); Mutex::Locker modules_locker(target_images.GetMutex()); size_t n_modules = target_images.GetSize(); @@ -428,7 +428,7 @@ SearchFilterByModule::Search (Searcher &searcher) // filespec that passes. Otherwise, we need to go through all modules and // find the ones that match the file name. - ModuleList &target_modules = m_target_sp->GetImages(); + const ModuleList &target_modules = m_target_sp->GetImages(); Mutex::Locker modules_locker (target_modules.GetMutex()); const size_t num_modules = target_modules.GetSize (); @@ -595,7 +595,7 @@ SearchFilterByModuleList::Search (Searcher &searcher) // filespec that passes. Otherwise, we need to go through all modules and // find the ones that match the file name. - ModuleList &target_modules = m_target_sp->GetImages(); + const ModuleList &target_modules = m_target_sp->GetImages(); Mutex::Locker modules_locker (target_modules.GetMutex()); const size_t num_modules = target_modules.GetSize (); @@ -768,7 +768,7 @@ SearchFilterByModuleListAndCU::Search (Searcher &searcher) // find the ones that match the file name. ModuleList matching_modules; - ModuleList &target_images = m_target_sp->GetImages(); + const ModuleList &target_images = m_target_sp->GetImages(); Mutex::Locker modules_locker(target_images.GetMutex()); const size_t num_modules = target_images.GetSize (); diff --git a/lldb/source/Expression/ClangASTSource.cpp b/lldb/source/Expression/ClangASTSource.cpp index e238303..67fdace8 100644 --- a/lldb/source/Expression/ClangASTSource.cpp +++ b/lldb/source/Expression/ClangASTSource.cpp @@ -250,7 +250,7 @@ ClangASTSource::CompleteType (TagDecl *tag_decl) ConstString name(tag_decl->getName().str().c_str()); ClangNamespaceDecl namespace_decl; - ModuleList &module_list = m_target->GetImages(); + const ModuleList &module_list = m_target->GetImages(); bool exact_match = false; module_list.FindTypes (null_sc, name, exact_match, UINT32_MAX, types); @@ -612,7 +612,7 @@ ClangASTSource::FindExternalVisibleDecls (NameSearchContext &context, } else { - ModuleList &target_images = m_target->GetImages(); + const ModuleList &target_images = m_target->GetImages(); Mutex::Locker modules_locker (target_images.GetMutex()); for (uint32_t i = 0, e = target_images.GetSize(); @@ -1536,7 +1536,7 @@ ClangASTSource::CompleteNamespaceMap (ClangASTImporter::NamespaceMapSP &namespac } else { - ModuleList &target_images = m_target->GetImages(); + const ModuleList &target_images = m_target->GetImages(); Mutex::Locker modules_locker(target_images.GetMutex()); ClangNamespaceDecl null_namespace_decl; diff --git a/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp b/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp index 3863762..194f21e 100644 --- a/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp +++ b/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp @@ -281,7 +281,7 @@ DynamicLoaderDarwinKernel::OSKextLoadedKextSummary::LoadImageUsingMemoryModule ( { if (uuid_is_valid) { - ModuleList &target_images = target.GetImages(); + const ModuleList &target_images = target.GetImages(); module_sp = target_images.FindModule(uuid); if (!module_sp) @@ -669,10 +669,7 @@ DynamicLoaderDarwinKernel::AddModulesUsingImageInfos (OSKextLoadedKextSummary::c loaded_module_list.AppendIfNeeded (image_infos[idx].module_sp); } - if (loaded_module_list.GetSize() > 0) - { - m_process->GetTarget().ModulesDidLoad (loaded_module_list); - } + m_process->GetTarget().ModulesDidLoad (loaded_module_list); return true; } diff --git a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp index 1b9be62..4723da8 100644 --- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp +++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp @@ -287,7 +287,9 @@ DynamicLoaderMacOSXDYLD::FindTargetModuleForDYLDImageInfo (const DYLDImageInfo & { if (did_create_ptr) *did_create_ptr = false; - ModuleList &target_images = m_process->GetTarget().GetImages(); + + + const ModuleList &target_images = m_process->GetTarget().GetImages(); ModuleSpec module_spec (image_info.file_spec, image_info.GetArchitecture ()); module_spec.GetUUID() = image_info.uuid; ModuleSP module_sp (target_images.FindFirstModule (module_spec)); @@ -816,7 +818,7 @@ DynamicLoaderMacOSXDYLD::AddModulesUsingImageInfos (DYLDImageInfo::collection &i Section *commpage_section = sections->FindSectionByName(commpage_dbstr).get(); if (commpage_section) { - ModuleList& target_images = m_process->GetTarget().GetImages(); + const ModuleList& target_images = m_process->GetTarget().GetImages(); ModuleSpec module_spec (objfile->GetFileSpec(), image_infos[idx].GetArchitecture ()); module_spec.GetObjectName() = commpage_dbstr; ModuleSP commpage_image_module_sp(target_images.FindFirstModule (module_spec)); @@ -966,7 +968,7 @@ DynamicLoaderMacOSXDYLD::RemoveModulesUsingImageInfosAddress (lldb::addr_t image log->PutCString("Unloaded:"); unloaded_module_list.LogUUIDAndPaths (log, "DynamicLoaderMacOSXDYLD::ModulesDidUnload"); } - m_process->GetTarget().ModulesDidUnload (unloaded_module_list); + m_process->GetTarget().GetImages().Remove (unloaded_module_list); } m_dyld_image_infos_stop_id = m_process->GetStopID(); return true; @@ -1060,7 +1062,7 @@ DynamicLoaderMacOSXDYLD::InitializeFromAllImageInfos () // to an equivalent version. We don't want it to stay in the target's module list or it will confuse // us, so unload it here. Target &target = m_process->GetTarget(); - ModuleList &target_modules = target.GetImages(); + const ModuleList &target_modules = target.GetImages(); ModuleList not_loaded_modules; Mutex::Locker modules_locker(target_modules.GetMutex()); @@ -1082,7 +1084,7 @@ DynamicLoaderMacOSXDYLD::InitializeFromAllImageInfos () if (not_loaded_modules.GetSize() != 0) { - target.ModulesDidUnload(not_loaded_modules); + target.GetImages().Remove(not_loaded_modules); } return true; @@ -1586,7 +1588,7 @@ DynamicLoaderMacOSXDYLD::GetStepThroughTrampolinePlan (Thread &thread, bool stop { SymbolContextList target_symbols; TargetSP target_sp (thread.CalculateTarget()); - ModuleList &images = target_sp->GetImages(); + const ModuleList &images = target_sp->GetImages(); images.FindSymbolsWithNameAndType(trampoline_name, eSymbolTypeCode, target_symbols); diff --git a/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp b/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp index 251590f..1400427 100644 --- a/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp +++ b/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp @@ -271,9 +271,8 @@ DynamicLoaderPOSIXDYLD::RefreshModules() FileSpec file(I->path.c_str(), true); ModuleSP module_sp = LoadModuleAtAddress(file, I->base_addr); if (module_sp.get()) - new_modules.Append(module_sp); + loaded_modules.AppendIfNeeded(module_sp); } - m_process->GetTarget().ModulesDidLoad(new_modules); } if (m_rendezvous.ModulesDidUnload()) @@ -290,7 +289,7 @@ DynamicLoaderPOSIXDYLD::RefreshModules() if (module_sp.get()) old_modules.Append(module_sp); } - m_process->GetTarget().ModulesDidUnload(old_modules); + loaded_modules.Remove(old_modules); } } @@ -312,7 +311,7 @@ DynamicLoaderPOSIXDYLD::GetStepThroughTrampolinePlan(Thread &thread, bool stop) SymbolContextList target_symbols; Target &target = thread.GetProcess()->GetTarget(); - ModuleList &images = target.GetImages(); + const ModuleList &images = target.GetImages(); images.FindSymbolsWithNameAndType(sym_name, eSymbolTypeCode, target_symbols); size_t num_targets = target_symbols.GetSize(); diff --git a/lldb/source/Plugins/DynamicLoader/Static/DynamicLoaderStatic.cpp b/lldb/source/Plugins/DynamicLoader/Static/DynamicLoaderStatic.cpp index 9b15ea8..f27f0a1 100644 --- a/lldb/source/Plugins/DynamicLoader/Static/DynamicLoaderStatic.cpp +++ b/lldb/source/Plugins/DynamicLoader/Static/DynamicLoaderStatic.cpp @@ -95,7 +95,7 @@ DynamicLoaderStatic::DidLaunch () void DynamicLoaderStatic::LoadAllImagesAtFileAddresses () { - ModuleList &module_list = m_process->GetTarget().GetImages(); + const ModuleList &module_list = m_process->GetTarget().GetImages(); ModuleList loaded_module_list; @@ -143,8 +143,7 @@ DynamicLoaderStatic::LoadAllImagesAtFileAddresses () } } - if (loaded_module_list.GetSize()) - m_process->GetTarget().ModulesDidLoad (loaded_module_list); + m_process->GetTarget().ModulesDidLoad (loaded_module_list); } ThreadPlanSP diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp index 995a438..a49b213 100644 --- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp +++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp @@ -178,7 +178,7 @@ AppleObjCRuntime::GetObjCModule () Process *process = GetProcess(); if (process) { - ModuleList& modules = process->GetTarget().GetImages(); + const ModuleList& modules = process->GetTarget().GetImages(); for (uint32_t idx = 0; idx < modules.GetSize(); idx++) { module_sp = modules.GetModuleAtIndex(idx); @@ -197,7 +197,7 @@ AppleObjCRuntime::GetPrintForDebuggerAddr() { if (!m_PrintForDebugger_addr.get()) { - ModuleList &modules = m_process->GetTarget().GetImages(); + const ModuleList &modules = m_process->GetTarget().GetImages(); SymbolContextList contexts; SymbolContext context; @@ -289,7 +289,7 @@ AppleObjCRuntime::GetObjCVersion (Process *process, ModuleSP &objc_module_sp) return eObjC_VersionUnknown; Target &target = process->GetTarget(); - ModuleList &target_modules = target.GetImages(); + const ModuleList &target_modules = target.GetImages(); Mutex::Locker modules_locker(target_modules.GetMutex()); size_t num_images = target_modules.GetSize(); diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp index 4b13cba..5b758c8 100644 --- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp +++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp @@ -1617,7 +1617,7 @@ protected: { if (!target_sp) return eLazyBoolCalculate; - ModuleList& modules = target_sp->GetImages(); + const ModuleList& modules = target_sp->GetImages(); for (uint32_t idx = 0; idx < modules.GetSize(); idx++) { lldb::ModuleSP module_sp = modules.GetModuleAtIndex(idx); diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp index d84bccd..25a2bfa 100644 --- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp +++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp @@ -334,7 +334,7 @@ AppleObjCTrampolineHandler::AppleObjCVTables::InitializeVTableSymbols () return true; Target &target = m_process_sp->GetTarget(); - ModuleList &target_modules = target.GetImages(); + const ModuleList &target_modules = target.GetImages(); Mutex::Locker modules_locker(target_modules.GetMutex()); size_t num_modules = target_modules.GetSize(); if (!m_objc_module_sp) diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp index 7deadc0..a0d47b9 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp @@ -18,6 +18,7 @@ #include "lldb/Core/Error.h" #include "lldb/Core/Module.h" #include "lldb/Core/ModuleSpec.h" +#include "lldb/Core/Timer.h" #include "lldb/Host/Host.h" #include "lldb/Host/Symbols.h" #include "lldb/Symbol/ObjectFile.h" @@ -47,6 +48,37 @@ PlatformDarwin::~PlatformDarwin() { } +FileSpec +PlatformDarwin::LocateExecutableScriptingResource (const ModuleSpec &module_spec) +{ + const FileSpec *exec_fspec = module_spec.GetFileSpecPtr(); + const ArchSpec *arch = module_spec.GetArchitecturePtr(); + const UUID *uuid = module_spec.GetUUIDPtr(); + + Timer scoped_timer (__PRETTY_FUNCTION__, + "LocateExecutableScriptingResource (file = %s, arch = %s, uuid = %p)", + exec_fspec ? exec_fspec->GetFilename().AsCString ("") : "", + arch ? arch->GetArchitectureName() : "", + uuid); + + + FileSpec symbol_fspec (Symbols::LocateExecutableSymbolFile(module_spec)); + + FileSpec script_fspec; + + if (symbol_fspec && symbol_fspec.Exists()) + { + // for OSX we are going to be in .dSYM/Contents/Resources/DWARF/ + // let us go to .dSYM/Contents/Resources/Python/.py and see if the file exists + StreamString path_string; + path_string.Printf("%s/../Python/%s.py",symbol_fspec.GetDirectory().GetCString(),module_spec.GetFileSpec().GetFileNameStrippingExtension().GetCString()); + script_fspec.SetFile(path_string.GetData(), true); + if (!script_fspec.Exists()) + script_fspec.Clear(); + } + + return script_fspec; +} Error PlatformDarwin::ResolveExecutable (const FileSpec &exe_file, diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h index 9376a66..ddb3ead 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h @@ -38,6 +38,9 @@ public: const lldb_private::ModuleSpec &sym_spec, lldb_private::FileSpec &sym_file); + lldb_private::FileSpec + LocateExecutableScriptingResource (const lldb_private::ModuleSpec &module_spec); + virtual lldb_private::Error GetSharedModule (const lldb_private::ModuleSpec &module_spec, lldb::ModuleSP &module_sp, diff --git a/lldb/source/Target/ObjCLanguageRuntime.cpp b/lldb/source/Target/ObjCLanguageRuntime.cpp index 0be1c96..f61e5c0 100644 --- a/lldb/source/Target/ObjCLanguageRuntime.cpp +++ b/lldb/source/Target/ObjCLanguageRuntime.cpp @@ -75,7 +75,7 @@ ObjCLanguageRuntime::LookupInCompleteClassCache (ConstString &name) m_complete_class_cache.erase(name); } - ModuleList &modules = m_process->GetTarget().GetImages(); + const ModuleList &modules = m_process->GetTarget().GetImages(); SymbolContextList sc_list; const size_t matching_symbols = modules.FindSymbolsWithNameAndType (name, diff --git a/lldb/source/Target/Platform.cpp b/lldb/source/Target/Platform.cpp index 6772abf..86ef2a0 100644 --- a/lldb/source/Target/Platform.cpp +++ b/lldb/source/Target/Platform.cpp @@ -89,6 +89,12 @@ Platform::GetFile (const FileSpec &platform_file, return Error(); } +FileSpec +Platform::LocateExecutableScriptingResource (const ModuleSpec &module_spec) +{ + return FileSpec(); +} + Error Platform::GetSharedModule (const ModuleSpec &module_spec, ModuleSP &module_sp, diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp index cdbdec4..ee6fd27 100644 --- a/lldb/source/Target/Process.cpp +++ b/lldb/source/Target/Process.cpp @@ -2980,7 +2980,7 @@ Process::CompleteAttach () m_os_ap.reset (OperatingSystem::FindPlugin (this, NULL)); // Figure out which one is the executable, and set that in our target: - ModuleList &target_modules = m_target.GetImages(); + const ModuleList &target_modules = m_target.GetImages(); Mutex::Locker modules_locker(target_modules.GetMutex()); size_t num_modules = target_modules.GetSize(); ModuleSP new_executable_module_sp; diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp index fa9fb54..b961603 100644 --- a/lldb/source/Target/Target.cpp +++ b/lldb/source/Target/Target.cpp @@ -64,7 +64,7 @@ Target::Target(Debugger &debugger, const ArchSpec &target_arch, const lldb::Plat m_platform_sp (platform_sp), m_mutex (Mutex::eMutexTypeRecursive), m_arch (target_arch), - m_images (), + m_images (this), m_section_load_list (), m_breakpoint_list (false), m_internal_breakpoint_list (true), @@ -954,6 +954,18 @@ Target::GetExecutableModulePointer () return m_images.GetModulePointerAtIndex(0); } +static void +LoadScriptingResourceForModule (const ModuleSP &module_sp, Target *target) +{ + Error error; + if (module_sp && !module_sp->LoadScriptingResourceInTarget(target, error)) + { + target->GetDebugger().GetOutputStream().Printf("unable to load scripting data for module %s - error reported was %s\n", + module_sp->GetFileSpec().GetFileNameStrippingExtension().GetCString(), + error.AsCString()); + } +} + void Target::SetExecutableModule (ModuleSP& executable_sp, bool get_dependent_files) { @@ -1047,16 +1059,31 @@ Target::SetArchitecture (const ArchSpec &arch_spec) } void -Target::ModuleAdded (ModuleSP &module_sp) +Target::WillClearList () +{ +} + +void +Target::ModuleAdded (const ModuleSP &module_sp) { // A module is being added to this target for the first time ModuleList module_list; module_list.Append(module_sp); + LoadScriptingResourceForModule(module_sp, this); ModulesDidLoad (module_list); } void -Target::ModuleUpdated (ModuleSP &old_module_sp, ModuleSP &new_module_sp) +Target::ModuleRemoved (const ModuleSP &module_sp) +{ + // A module is being added to this target for the first time + ModuleList module_list; + module_list.Append(module_sp); + ModulesDidUnload (module_list); +} + +void +Target::ModuleUpdated (const ModuleSP &old_module_sp, const ModuleSP &new_module_sp) { // A module is replacing an already added module m_breakpoint_list.UpdateBreakpointsWhenModuleIsReplaced(old_module_sp, new_module_sp); @@ -1065,28 +1092,28 @@ Target::ModuleUpdated (ModuleSP &old_module_sp, ModuleSP &new_module_sp) void Target::ModulesDidLoad (ModuleList &module_list) { - m_breakpoint_list.UpdateBreakpoints (module_list, true); - // TODO: make event data that packages up the module_list - BroadcastEvent (eBroadcastBitModulesLoaded, NULL); + if (module_list.GetSize()) + { + m_breakpoint_list.UpdateBreakpoints (module_list, true); + // TODO: make event data that packages up the module_list + BroadcastEvent (eBroadcastBitModulesLoaded, NULL); + } } void Target::ModulesDidUnload (ModuleList &module_list) { - m_breakpoint_list.UpdateBreakpoints (module_list, false); - - // Remove the images from the target image list - m_images.Remove(module_list); - - // TODO: make event data that packages up the module_list - BroadcastEvent (eBroadcastBitModulesUnloaded, NULL); + if (module_list.GetSize()) + { + m_breakpoint_list.UpdateBreakpoints (module_list, false); + // TODO: make event data that packages up the module_list + BroadcastEvent (eBroadcastBitModulesUnloaded, NULL); + } } - bool Target::ModuleIsExcludedForNonModuleSpecificSearches (const FileSpec &module_file_spec) { - if (GetBreakpointsConsultPlatformAvoidList()) { ModuleList matchingModules; @@ -1456,17 +1483,15 @@ Target::GetSharedModule (const ModuleSpec &module_spec, Error *error_ptr) } } - m_images.Append (module_sp); if (old_module_sp && m_images.GetIndexForModule (old_module_sp.get()) != LLDB_INVALID_INDEX32) { - ModuleUpdated(old_module_sp, module_sp); - m_images.Remove (old_module_sp); + m_images.ReplaceModule(old_module_sp, module_sp); Module *old_module_ptr = old_module_sp.get(); old_module_sp.reset(); ModuleList::RemoveSharedModuleIfOrphaned (old_module_ptr); } else - ModuleAdded(module_sp); + m_images.Append(module_sp); } } if (error_ptr) -- 2.7.4