[Lldb-commits] [lldb] r136755 - in /lldb/trunk: include/lldb/Core/Module.h source/Core/Module.cpp source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp

Jim Ingham jingham at apple.com
Tue Aug 2 18:03:17 PDT 2011


Author: jingham
Date: Tue Aug  2 20:03:17 2011
New Revision: 136755

URL: http://llvm.org/viewvc/llvm-project?rev=136755&view=rev
Log:
Add method Module::IsLoadedInTarget, and then in the MacOS X dynamic loader, after we
have initialized our shared library state, discard all the modules that didn't make
it into the running process.

Modified:
    lldb/trunk/include/lldb/Core/Module.h
    lldb/trunk/source/Core/Module.cpp
    lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp

Modified: lldb/trunk/include/lldb/Core/Module.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Module.h?rev=136755&r1=136754&r2=136755&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/Module.h (original)
+++ lldb/trunk/include/lldb/Core/Module.h Tue Aug  2 20:03:17 2011
@@ -399,6 +399,20 @@
     //------------------------------------------------------------------
     bool
     IsExecutable ();
+    
+    //------------------------------------------------------------------
+    /// Tells whether this module has been loaded in the target passed in.
+    /// This call doesn't distinguish between whether the module is loaded
+    /// by the dynamic loader, or by a "target module add" type call.
+    ///
+    /// @param[in] target
+    ///    The target to check whether this is loaded in.
+    ///
+    /// @return
+    ///     \b true if it is, \b false otherwise.
+    //------------------------------------------------------------------
+    bool
+    IsLoadedInTarget (Target *target);
 
     //------------------------------------------------------------------
     /// Get the number of compile units for this module.

Modified: lldb/trunk/source/Core/Module.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Module.cpp?rev=136755&r1=136754&r2=136755&view=diff
==============================================================================
--- lldb/trunk/source/Core/Module.cpp (original)
+++ lldb/trunk/source/Core/Module.cpp Tue Aug  2 20:03:17 2011
@@ -690,6 +690,29 @@
         return GetObjectFile()->IsExecutable();
 }
 
+bool
+Module::IsLoadedInTarget (Target *target)
+{
+    ObjectFile *obj_file = GetObjectFile();
+    if (obj_file)
+    {
+        SectionList *sections = obj_file->GetSectionList();
+        if (sections != NULL)
+        {
+            size_t num_sections = sections->GetSize();
+            bool loaded = false;
+            for (size_t sect_idx = 0; sect_idx < num_sections; sect_idx++)
+            {
+                SectionSP section_sp = sections->GetSectionAtIndex(sect_idx);
+                if (section_sp->GetLoadBaseAddress(target) != LLDB_INVALID_ADDRESS)
+                {
+                    return true;
+                }
+            }
+        }
+    }
+    return false;
+}
 bool 
 Module::SetArchitecture (const ArchSpec &new_arch)
 {

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=136755&r1=136754&r2=136755&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp (original)
+++ lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp Tue Aug  2 20:03:17 2011
@@ -947,6 +947,36 @@
                 }
             }
         }
+        
+        // Now we have one more bit of business.  If there is a library left in the images for our target that
+        // doesn't have a load address, then it must be something that we were expecting to load (for instance we
+        // read a load command for it) but it didn't in fact load - probably because DYLD_*_PATH pointed
+        // 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->CalculateTarget();
+        ModuleList &modules = target->GetImages();
+        ModuleList not_loaded_modules;
+        size_t num_modules = modules.GetSize();
+        for (size_t i = 0; i < num_modules; i++)
+        {
+            ModuleSP module_sp = modules.GetModuleAtIndex(i);
+            if (!module_sp->IsLoadedInTarget (target))
+            {
+                if (log)
+                {
+                    StreamString s;
+                    module_sp->GetDescription (&s);
+                    log->Printf ("Unloading pre-run module: %s.", s.GetData ());
+                }
+                not_loaded_modules.Append (module_sp);
+            }
+        }
+        
+        if (not_loaded_modules.GetSize() != 0)
+        {
+            target->ModulesDidUnload(not_loaded_modules);
+        }
+        
         return true;
     }
     else





More information about the lldb-commits mailing list