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

Greg Clayton gclayton at apple.com
Sun Dec 12 13:03:32 PST 2010


Author: gclayton
Date: Sun Dec 12 15:03:32 2010
New Revision: 121641

URL: http://llvm.org/viewvc/llvm-project?rev=121641&view=rev
Log:
Fixed an issue where the macosx dynamic loader, on the first shared library loaded notification, wasn't properly removing shared libraries from the target that didn't get loaded. This usually happens when a different shared library is loaded in place of another due to DYLD_LIBRARY_PATH or DYLD_FRAMEWORK_PATH environment variables. We now properly remove any images that didn't make it into the executable.

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

Modified: lldb/trunk/include/lldb/Core/ModuleList.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ModuleList.h?rev=121641&r1=121640&r2=121641&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/ModuleList.h (original)
+++ lldb/trunk/include/lldb/Core/ModuleList.h Sun Dec 12 15:03:32 2010
@@ -76,7 +76,7 @@
     Append (lldb::ModuleSP &module_sp);
 
     bool
-    AppendInNeeded (lldb::ModuleSP &module_sp);
+    AppendIfNeeded (lldb::ModuleSP &module_sp);
 
     //------------------------------------------------------------------
     /// Clear the object's state.

Modified: lldb/trunk/source/Breakpoint/Breakpoint.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Breakpoint/Breakpoint.cpp?rev=121641&r1=121640&r2=121641&view=diff
==============================================================================
--- lldb/trunk/source/Breakpoint/Breakpoint.cpp (original)
+++ lldb/trunk/source/Breakpoint/Breakpoint.cpp Sun Dec 12 15:03:32 2010
@@ -313,7 +313,7 @@
             }
 
             if (!seen)
-                new_modules.AppendInNeeded (module_sp);
+                new_modules.AppendIfNeeded (module_sp);
 
         }
         if (new_modules.GetSize() > 0)

Modified: lldb/trunk/source/Core/ModuleList.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ModuleList.cpp?rev=121641&r1=121640&r2=121641&view=diff
==============================================================================
--- lldb/trunk/source/Core/ModuleList.cpp (original)
+++ lldb/trunk/source/Core/ModuleList.cpp Sun Dec 12 15:03:32 2010
@@ -67,7 +67,7 @@
 }
 
 bool
-ModuleList::AppendInNeeded (ModuleSP &module_sp)
+ModuleList::AppendIfNeeded (ModuleSP &module_sp)
 {
     Mutex::Locker locker(m_modules_mutex);
     collection::iterator pos, end = m_modules.end();

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=121641&r1=121640&r2=121641&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp (original)
+++ lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp Sun Dec 12 15:03:32 2010
@@ -40,6 +40,23 @@
 /// I am putting it here so I can invoke it in the Trampoline code here, but
 /// it should be moved to the ObjC Runtime support when it is set up.
 
+
+DynamicLoaderMacOSXDYLD::DYLDImageInfo *
+DynamicLoaderMacOSXDYLD::GetImageInfo (const FileSpec &file_spec, const UUID &uuid)
+{
+    DYLDImageInfo::collection::iterator pos, end = m_dyld_image_infos.end();
+    for (pos = m_dyld_image_infos.begin(); pos != end; ++pos)
+    {
+        if (pos->uuid == uuid && pos->file_spec == file_spec)
+            return &(*pos);
+    }
+    
+    if (m_dyld.uuid == uuid && m_dyld.file_spec == file_spec)
+        return &m_dyld;
+
+    return NULL;
+}
+
 //----------------------------------------------------------------------
 // Create an instance of this class. This function is filled into
 // the plugin info class that gets handed out by the plugin factory and
@@ -226,7 +243,7 @@
             // it again (since Target::SetExecutableModule() will clear the
             // images). So append the dyld module back to the list if it is
             /// unique!
-            if (m_process->GetTarget().GetImages().AppendInNeeded (dyld_module_sp))
+            if (m_process->GetTarget().GetImages().AppendIfNeeded (dyld_module_sp))
                 UpdateImageLoadAddress(dyld_module_sp.get(), m_dyld);
 
             return true;
@@ -589,36 +606,57 @@
 
         // If our new list is smaller than our old list, we have unloaded
         // some shared libraries
-        if (m_dyld_image_infos.size() < old_dyld_all_image_infos.size())
+        if (m_dyld_image_infos.size() != old_dyld_all_image_infos.size())
         {
             ModuleList unloaded_module_list;
-            uint32_t old_idx;
-            for (idx = 0; idx < old_dyld_all_image_infos.size(); ++idx)
+            if (old_dyld_all_image_infos.size() == 0)
+            {
+                // This is the first time we are loading shared libraries,
+                // we need to make sure to trim anything that isn't in the
+                // m_dyld_image_infos out of the target module list since
+                // we might have shared libraries that got loaded from
+                // elsewhere due to DYLD_FRAMEWORK_PATH, or DYLD_LIBRARY_PATH
+                // environment variables...
+                ModuleList& images = m_process->GetTarget().GetImages();
+                const size_t num_images = images.GetSize();
+                for (idx = 0; idx < num_images; ++idx)
+                {
+                    ModuleSP module_sp (images.GetModuleAtIndex (idx));
+                    
+                    if (GetImageInfo (module_sp->GetFileSpec(), module_sp->GetUUID()) == NULL)
+                        unloaded_module_list.AppendIfNeeded (module_sp);
+                }
+            }
+            else
             {
-                for (old_idx = idx; old_idx < old_dyld_all_image_infos.size(); ++old_idx)
+                uint32_t old_idx;
+                for (idx = 0; idx < old_dyld_all_image_infos.size(); ++idx)
                 {
-                    if (m_dyld_image_infos[idx].file_spec == old_dyld_all_image_infos[old_idx].file_spec)
+                    for (old_idx = idx; old_idx < old_dyld_all_image_infos.size(); ++old_idx)
                     {
-                        old_dyld_all_image_infos[old_idx].address = LLDB_INVALID_ADDRESS;
-                        break;
+                        if (m_dyld_image_infos[idx].file_spec == old_dyld_all_image_infos[old_idx].file_spec)
+                        {
+                            old_dyld_all_image_infos[old_idx].address = LLDB_INVALID_ADDRESS;
+                            break;
+                        }
                     }
                 }
-            }
 
-            if (log)
-                log->PutCString("Unloaded:");
+                if (log)
+                    log->PutCString("Unloaded:");
 
-            for (old_idx = 0; old_idx < old_dyld_all_image_infos.size(); ++old_idx)
-            {
-                if (old_dyld_all_image_infos[old_idx].address != LLDB_INVALID_ADDRESS)
+                for (old_idx = 0; old_idx < old_dyld_all_image_infos.size(); ++old_idx)
                 {
-                    if (log)
-                        old_dyld_all_image_infos[old_idx].PutToLog (log.get());
-                    ModuleSP unload_image_module_sp(m_process->GetTarget().GetImages().FindFirstModuleForFileSpec (old_dyld_all_image_infos[old_idx].file_spec));
-                    if (unload_image_module_sp.get())
+                    if (old_dyld_all_image_infos[old_idx].address != LLDB_INVALID_ADDRESS)
                     {
-                        if (UnloadImageLoadAddress (unload_image_module_sp.get(), old_dyld_all_image_infos[old_idx]))
-                            unloaded_module_list.AppendInNeeded (unload_image_module_sp);
+                        if (log)
+                            old_dyld_all_image_infos[old_idx].PutToLog (log.get());
+                        ModuleSP unload_image_module_sp(m_process->GetTarget().GetImages().FindFirstModuleForFileSpec (old_dyld_all_image_infos[old_idx].file_spec));
+                        if (unload_image_module_sp.get())
+                        {
+                            if (UnloadImageLoadAddress (unload_image_module_sp.get(), old_dyld_all_image_infos[old_idx]))
+                                unloaded_module_list.AppendIfNeeded (unload_image_module_sp);
+                        }
                     }
                 }
             }
@@ -690,7 +728,7 @@
                 // shared libraries each time.
                 if (UpdateImageLoadAddress (image_module_sp.get(), m_dyld_image_infos[idx]))
                 {
-                    loaded_module_list.AppendInNeeded (image_module_sp);
+                    loaded_module_list.AppendIfNeeded (image_module_sp);
                 }
             }
         }

Modified: lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h?rev=121641&r1=121640&r2=121641&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h (original)
+++ lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h Sun Dec 12 15:03:32 2010
@@ -202,13 +202,13 @@
 
     struct DYLDImageInfo
     {
-        lldb::addr_t address;           // Address of mach header for this dylib
-        lldb::addr_t slide;             // The amount to slide all segments by if there is a global slide.
-        lldb::addr_t mod_date;          // Modification date for this dylib
-        lldb_private::FileSpec file_spec;       // Resolved path for this dylib
-        lldb_private::UUID uuid;                // UUID for this dylib if it has one, else all zeros
-        llvm::MachO::mach_header header;      // The mach header for this image
-        std::vector<Segment> segments;  // All segment vmaddr and vmsize pairs for this executable (from memory of inferior)
+        lldb::addr_t address;               // Address of mach header for this dylib
+        lldb::addr_t slide;                 // The amount to slide all segments by if there is a global slide.
+        lldb::addr_t mod_date;              // Modification date for this dylib
+        lldb_private::FileSpec file_spec;   // Resolved path for this dylib
+        lldb_private::UUID uuid;            // UUID for this dylib if it has one, else all zeros
+        llvm::MachO::mach_header header;    // The mach header for this image
+        std::vector<Segment> segments;      // All segment vmaddr and vmsize pairs for this executable (from memory of inferior)
 
         DYLDImageInfo() :
             address(LLDB_INVALID_ADDRESS),
@@ -359,6 +359,10 @@
     UnloadImageLoadAddress (lldb_private::Module *module,
                             struct DYLDImageInfo& info);
 
+    DYLDImageInfo *
+    GetImageInfo (const lldb_private::FileSpec &file_spec, 
+                  const lldb_private::UUID &uuid);
+
     bool
     NeedToLocateDYLD () const;
 





More information about the lldb-commits mailing list