[Lldb-commits] [lldb] r190727 - This fixes two issues with the POSIX dynamic loader:

Matt Kopec Matt.Kopec at intel.com
Fri Sep 13 15:14:50 PDT 2013


Author: mkopec
Date: Fri Sep 13 17:14:50 2013
New Revision: 190727

URL: http://llvm.org/viewvc/llvm-project?rev=190727&view=rev
Log:
This fixes two issues with the POSIX dynamic loader:
1. existing breakpoints weren't being re-resolved after the sections of a library were loaded (ie. through dlopen).
2. loaded sections weren't being removed after a shared library had been unloaded.


Modified:
    lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
    lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h

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=190727&r1=190726&r2=190727&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp (original)
+++ lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp Fri Sep 13 17:14:50 2013
@@ -211,9 +211,11 @@ DynamicLoaderPOSIXDYLD::CanLoadImage()
 void
 DynamicLoaderPOSIXDYLD::UpdateLoadedSections(ModuleSP module, addr_t base_addr)
 {
-    ObjectFile *obj_file = module->GetObjectFile();
-    SectionList *sections = obj_file->GetSectionList();
     SectionLoadList &load_list = m_process->GetTarget().GetSectionLoadList();
+    const SectionList *sections = GetSectionListFromModule(module);
+
+    assert(sections && "SectionList missing from loaded module.");
+
     const size_t num_sections = sections->GetSize();
 
     for (unsigned i = 0; i < num_sections; ++i)
@@ -234,6 +236,22 @@ DynamicLoaderPOSIXDYLD::UpdateLoadedSect
 }
 
 void
+DynamicLoaderPOSIXDYLD::UnloadSections(const ModuleSP module)
+{
+    SectionLoadList &load_list = m_process->GetTarget().GetSectionLoadList();
+    const SectionList *sections = GetSectionListFromModule(module);
+
+    assert(sections && "SectionList missing from unloaded module.");
+
+    const size_t num_sections = sections->GetSize();
+    for (auto i = 0; i < num_sections; ++i)
+    {
+        SectionSP section_sp (sections->GetSectionAtIndex(i));
+        load_list.SetSectionUnloaded(section_sp);
+    }
+}
+
+void
 DynamicLoaderPOSIXDYLD::ProbeEntry()
 {
     Breakpoint *entry_break;
@@ -321,8 +339,12 @@ DynamicLoaderPOSIXDYLD::RefreshModules()
             FileSpec file(I->path.c_str(), true);
             ModuleSP module_sp = LoadModuleAtAddress(file, I->base_addr);
             if (module_sp.get())
+            {
                 loaded_modules.AppendIfNeeded(module_sp);
+                new_modules.Append(module_sp);
+            }
         }
+        m_process->GetTarget().ModulesDidLoad(new_modules);
     }
     
     if (m_rendezvous.ModulesDidUnload())
@@ -336,10 +358,15 @@ DynamicLoaderPOSIXDYLD::RefreshModules()
             ModuleSpec module_spec (file);
             ModuleSP module_sp = 
                 loaded_modules.FindFirstModule (module_spec);
+
             if (module_sp.get())
+            {
                 old_modules.Append(module_sp);
+                UnloadSections(module_sp);
+            }
         }
         loaded_modules.Remove(old_modules);
+        m_process->GetTarget().ModulesDidUnload(old_modules);
     }
 }
 
@@ -479,3 +506,18 @@ DynamicLoaderPOSIXDYLD::GetEntryPoint()
     m_entry_point = static_cast<addr_t>(I->value);
     return m_entry_point;
 }
+
+const SectionList *
+DynamicLoaderPOSIXDYLD::GetSectionListFromModule(const ModuleSP module) const
+{
+    SectionList *sections = nullptr;
+    if (module.get())
+    {
+        ObjectFile *obj_file = module->GetObjectFile();
+        if (obj_file)
+        {
+            sections = obj_file->GetSectionList();
+        }
+    }
+    return sections;
+}

Modified: lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h?rev=190727&r1=190726&r2=190727&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h (original)
+++ lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h Fri Sep 13 17:14:50 2013
@@ -122,6 +122,12 @@ protected:
     UpdateLoadedSections(lldb::ModuleSP module, 
                          lldb::addr_t base_addr = 0);
 
+    /// Removes the loaded sections from the target in @p module.
+    ///
+    /// @param module The module to traverse.
+    void
+    UnloadSections(const lldb::ModuleSP module);
+
     /// Locates or creates a module given by @p file and updates/loads the
     /// resulting module at the virtual base address @p base_addr.
     lldb::ModuleSP
@@ -165,6 +171,9 @@ protected:
 
 private:
     DISALLOW_COPY_AND_ASSIGN(DynamicLoaderPOSIXDYLD);
+
+    const lldb_private::SectionList *
+    GetSectionListFromModule(const lldb::ModuleSP module) const;
 };
 
 #endif  // liblldb_DynamicLoaderPOSIXDYLD_H_





More information about the lldb-commits mailing list