[Lldb-commits] [lldb] r167569 - in /lldb/trunk: include/lldb/Core/ include/lldb/Host/ include/lldb/Target/ source/Commands/ source/Core/ source/Expression/ source/Plugins/DynamicLoader/Darwin-Kernel/ source/Plugins/DynamicLoader/MacOSX-DYLD/ source/Plugins/DynamicLoader/POSIX-DYLD/ source/Plugins/DynamicLoader/Static/ source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/ source/Plugins/Platform/MacOSX/ source/Target/

Enrico Granata egranata at apple.com
Wed Nov 7 18:22:02 PST 2012


Author: enrico
Date: Wed Nov  7 20:22:02 2012
New Revision: 167569

URL: http://llvm.org/viewvc/llvm-project?rev=167569&view=rev
Log:
<rdar://problem/12586350>

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


Modified:
    lldb/trunk/include/lldb/Core/Module.h
    lldb/trunk/include/lldb/Core/ModuleList.h
    lldb/trunk/include/lldb/Host/Symbols.h
    lldb/trunk/include/lldb/Target/Platform.h
    lldb/trunk/include/lldb/Target/Target.h
    lldb/trunk/source/Commands/CommandObjectTarget.cpp
    lldb/trunk/source/Core/Module.cpp
    lldb/trunk/source/Core/ModuleList.cpp
    lldb/trunk/source/Core/SearchFilter.cpp
    lldb/trunk/source/Expression/ClangASTSource.cpp
    lldb/trunk/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
    lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
    lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
    lldb/trunk/source/Plugins/DynamicLoader/Static/DynamicLoaderStatic.cpp
    lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp
    lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
    lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp
    lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
    lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.h
    lldb/trunk/source/Target/ObjCLanguageRuntime.cpp
    lldb/trunk/source/Target/Platform.cpp
    lldb/trunk/source/Target/Process.cpp
    lldb/trunk/source/Target/Target.cpp

Modified: lldb/trunk/include/lldb/Core/Module.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Module.h?rev=167569&r1=167568&r2=167569&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/Module.h (original)
+++ lldb/trunk/include/lldb/Core/Module.h Wed Nov  7 20:22:02 2012
@@ -532,6 +532,9 @@
     bool
     IsLoadedInTarget (Target *target);
 
+    bool
+    LoadScriptingResourceInTarget (Target *target, Error& error);
+    
     //------------------------------------------------------------------
     /// Get the number of compile units for this module.
     ///

Modified: lldb/trunk/include/lldb/Core/ModuleList.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ModuleList.h?rev=167569&r1=167568&r2=167569&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/ModuleList.h (original)
+++ lldb/trunk/include/lldb/Core/ModuleList.h Wed Nov  7 20:22:02 2012
@@ -27,6 +27,25 @@
 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 @@
     ///     Another module list object.
     //------------------------------------------------------------------
     ModuleList (const ModuleList& rhs);
+    
+    ModuleList (ModuleList::Notifier* notifier);
 
     //------------------------------------------------------------------
     /// Destructor.
@@ -91,6 +112,15 @@
     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 @@
                      const char *prefix_cstr);
                      
     Mutex &
-    GetMutex ()
+    GetMutex () const
     {
         return m_modules_mutex;
     }
@@ -151,7 +181,7 @@
     /// @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 @@
     /// @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 @@
     uint32_t
     FindCompileUnits (const FileSpec &path,
                       bool append,
-                      SymbolContextList &sc_list);
+                      SymbolContextList &sc_list) const;
     
     //------------------------------------------------------------------
     /// @see Module::FindFunctions ()
@@ -237,7 +267,7 @@
                    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 @@
     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 @@
     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 @@
                  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 @@
     // 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 &regex, 
                                      lldb::SymbolType symbol_type, 
                                      SymbolContextList &sc_list,
-                                     bool append = false);
+                                     bool append = false) const;
                                      
     //------------------------------------------------------------------
     /// Find types by name.
@@ -397,7 +427,7 @@
                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 @@
 
     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 @@
     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 @@
                                      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 @@
                                      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 @@
     //------------------------------------------------------------------
     typedef std::vector<lldb::ModuleSP> 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

Modified: lldb/trunk/include/lldb/Host/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/Symbols.h?rev=167569&r1=167568&r2=167569&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/Symbols.h (original)
+++ lldb/trunk/include/lldb/Host/Symbols.h Wed Nov  7 20:22:02 2012
@@ -41,7 +41,7 @@
     //----------------------------------------------------------------------
     static FileSpec
     LocateExecutableSymbolFile (const ModuleSpec &module_spec);
-    
+        
     static FileSpec
     FindSymbolFileInBundle (const FileSpec& dsym_bundle_fspec,
                             const lldb_private::UUID *uuid,

Modified: lldb/trunk/include/lldb/Target/Platform.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Platform.h?rev=167569&r1=167568&r2=167569&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Platform.h (original)
+++ lldb/trunk/include/lldb/Target/Platform.h Wed Nov  7 20:22:02 2012
@@ -291,6 +291,15 @@
                  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,

Modified: lldb/trunk/include/lldb/Target/Target.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Target.h?rev=167569&r1=167568&r2=167569&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Target.h (original)
+++ lldb/trunk/include/lldb/Target/Target.h Wed Nov  7 20:22:02 2012
@@ -47,7 +47,6 @@
     eInlineBreakpointsAlways
 } InlineStrategy;
 
-
 //----------------------------------------------------------------------
 // TargetProperties
 //----------------------------------------------------------------------
@@ -266,7 +265,8 @@
     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 @@
     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 @@
     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 @@
     /// @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.

Modified: lldb/trunk/source/Commands/CommandObjectTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectTarget.cpp?rev=167569&r1=167568&r2=167569&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectTarget.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectTarget.cpp Wed Nov  7 20:22:02 2012
@@ -2255,7 +2255,7 @@
             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 @@
                 {
                     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 @@
             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 @@
                 
                 // 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)

Modified: lldb/trunk/source/Core/Module.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Module.cpp?rev=167569&r1=167568&r2=167569&view=diff
==============================================================================
--- lldb/trunk/source/Core/Module.cpp (original)
+++ lldb/trunk/source/Core/Module.cpp Wed Nov  7 20:22:02 2012
@@ -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 @@
     }
     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())

Modified: lldb/trunk/source/Core/ModuleList.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ModuleList.cpp?rev=167569&r1=167568&r2=167569&view=diff
==============================================================================
--- lldb/trunk/source/Core/ModuleList.cpp (original)
+++ lldb/trunk/source/Core/ModuleList.cpp Wed Nov  7 20:22:02 2012
@@ -30,7 +30,8 @@
 //----------------------------------------------------------------------
 ModuleList::ModuleList() :
     m_modules(),
-    m_modules_mutex (Mutex::eMutexTypeRecursive)
+    m_modules_mutex (Mutex::eMutexTypeRecursive),
+    m_notifier(NULL)
 {
 }
 
@@ -44,6 +45,14 @@
     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 @@
         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 @@
 }
 
 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 @@
         {
             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 @@
                 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 @@
             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 @@
     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 @@
             {
                 if (pos->unique())
                 {
-                    pos = m_modules.erase (pos);
+                    pos = RemoveImpl(pos);
                     return true;
                 }
                 else
@@ -187,7 +250,7 @@
     {
         if (pos->unique())
         {
-            pos = m_modules.erase (pos);
+            pos = RemoveImpl(pos);
             ++remove_count;
         }
         else
@@ -213,20 +276,25 @@
 }
 
 
-
 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 @@
 }
 
 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 @@
                            bool include_symbols,
                            bool include_inlines,
                            bool append, 
-                           SymbolContextList &sc_list)
+                           SymbolContextList &sc_list) const
 {
     if (!append)
         sc_list.Clear();
@@ -284,7 +352,7 @@
 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 @@
 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 @@
 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 @@
 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 @@
 ModuleList::FindSymbolsMatchingRegExAndType (const RegularExpression &regex, 
                                              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 @@
 }
 
 ModuleSP
-ModuleList::FindModule (const Module *module_ptr)
+ModuleList::FindModule (const Module *module_ptr) const
 {
     ModuleSP module_sp;
 
@@ -407,7 +475,7 @@
 }
 
 ModuleSP
-ModuleList::FindModule (const UUID &uuid)
+ModuleList::FindModule (const UUID &uuid) const
 {
     ModuleSP module_sp;
     
@@ -430,7 +498,7 @@
 
 
 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 @@
 
 
 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 @@
 }
 
 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 @@
 }
 
 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 @@
     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();

Modified: lldb/trunk/source/Core/SearchFilter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/SearchFilter.cpp?rev=167569&r1=167568&r2=167569&view=diff
==============================================================================
--- lldb/trunk/source/Core/SearchFilter.cpp (original)
+++ lldb/trunk/source/Core/SearchFilter.cpp Wed Nov  7 20:22:02 2012
@@ -204,7 +204,7 @@
         }
         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 @@
     // 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 @@
     // 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 @@
     // 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 ();

Modified: lldb/trunk/source/Expression/ClangASTSource.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangASTSource.cpp?rev=167569&r1=167568&r2=167569&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangASTSource.cpp (original)
+++ lldb/trunk/source/Expression/ClangASTSource.cpp Wed Nov  7 20:22:02 2012
@@ -250,7 +250,7 @@
             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 @@
     }
     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 @@
     }
     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;

Modified: lldb/trunk/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp?rev=167569&r1=167568&r2=167569&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp (original)
+++ lldb/trunk/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp Wed Nov  7 20:22:02 2012
@@ -281,7 +281,7 @@
     {
         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 @@
             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;
 }
 

Modified: lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp?rev=167569&r1=167568&r2=167569&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp (original)
+++ lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp Wed Nov  7 20:22:02 2012
@@ -287,7 +287,9 @@
 {
     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 @@
                     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 @@
             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 @@
         // 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 @@
         
         if (not_loaded_modules.GetSize() != 0)
         {
-            target.ModulesDidUnload(not_loaded_modules);
+            target.GetImages().Remove(not_loaded_modules);
         }
 
         return true;
@@ -1586,7 +1588,7 @@
             {
                 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);
 

Modified: lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp?rev=167569&r1=167568&r2=167569&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp (original)
+++ lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp Wed Nov  7 20:22:02 2012
@@ -271,9 +271,8 @@
             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 @@
             if (module_sp.get())
                 old_modules.Append(module_sp);
         }
-        m_process->GetTarget().ModulesDidUnload(old_modules);
+        loaded_modules.Remove(old_modules);
     }
 }
 
@@ -312,7 +311,7 @@
 
     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();

Modified: lldb/trunk/source/Plugins/DynamicLoader/Static/DynamicLoaderStatic.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/DynamicLoader/Static/DynamicLoaderStatic.cpp?rev=167569&r1=167568&r2=167569&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/DynamicLoader/Static/DynamicLoaderStatic.cpp (original)
+++ lldb/trunk/source/Plugins/DynamicLoader/Static/DynamicLoaderStatic.cpp Wed Nov  7 20:22:02 2012
@@ -95,7 +95,7 @@
 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 @@
         }
     }
 
-    if (loaded_module_list.GetSize())
-        m_process->GetTarget().ModulesDidLoad (loaded_module_list);
+    m_process->GetTarget().ModulesDidLoad (loaded_module_list);
 }
 
 ThreadPlanSP

Modified: lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp?rev=167569&r1=167568&r2=167569&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp (original)
+++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp Wed Nov  7 20:22:02 2012
@@ -178,7 +178,7 @@
     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 @@
 {
     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 @@
         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();

Modified: lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp?rev=167569&r1=167568&r2=167569&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp (original)
+++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp Wed Nov  7 20:22:02 2012
@@ -1617,7 +1617,7 @@
     {
         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);

Modified: lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp?rev=167569&r1=167568&r2=167569&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp (original)
+++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp Wed Nov  7 20:22:02 2012
@@ -334,7 +334,7 @@
         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)

Modified: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp?rev=167569&r1=167568&r2=167569&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp Wed Nov  7 20:22:02 2012
@@ -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 @@
 {
 }
 
+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 ("<NULL>") : "<NULL>",
+                        arch ? arch->GetArchitectureName() : "<NULL>",
+                        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/<basename>
+        // let us go to .dSYM/Contents/Resources/Python/<basename>.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,

Modified: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.h?rev=167569&r1=167568&r2=167569&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.h (original)
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.h Wed Nov  7 20:22:02 2012
@@ -38,6 +38,9 @@
                        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,

Modified: lldb/trunk/source/Target/ObjCLanguageRuntime.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/ObjCLanguageRuntime.cpp?rev=167569&r1=167568&r2=167569&view=diff
==============================================================================
--- lldb/trunk/source/Target/ObjCLanguageRuntime.cpp (original)
+++ lldb/trunk/source/Target/ObjCLanguageRuntime.cpp Wed Nov  7 20:22:02 2012
@@ -75,7 +75,7 @@
             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,

Modified: lldb/trunk/source/Target/Platform.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Platform.cpp?rev=167569&r1=167568&r2=167569&view=diff
==============================================================================
--- lldb/trunk/source/Target/Platform.cpp (original)
+++ lldb/trunk/source/Target/Platform.cpp Wed Nov  7 20:22:02 2012
@@ -89,6 +89,12 @@
     return Error();
 }
 
+FileSpec
+Platform::LocateExecutableScriptingResource (const ModuleSpec &module_spec)
+{
+    return FileSpec();
+}
+
 Error
 Platform::GetSharedModule (const ModuleSpec &module_spec,
                            ModuleSP &module_sp,

Modified: lldb/trunk/source/Target/Process.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=167569&r1=167568&r2=167569&view=diff
==============================================================================
--- lldb/trunk/source/Target/Process.cpp (original)
+++ lldb/trunk/source/Target/Process.cpp Wed Nov  7 20:22:02 2012
@@ -2980,7 +2980,7 @@
 
     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;

Modified: lldb/trunk/source/Target/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Target.cpp?rev=167569&r1=167568&r2=167569&view=diff
==============================================================================
--- lldb/trunk/source/Target/Target.cpp (original)
+++ lldb/trunk/source/Target/Target.cpp Wed Nov  7 20:22:02 2012
@@ -64,7 +64,7 @@
     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 @@
     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 @@
 }
 
 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 @@
 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 @@
                 }
             }
             
-            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)





More information about the lldb-commits mailing list