[Lldb-commits] [lldb] r159884 - in /lldb/trunk: include/lldb/Target/SectionLoadList.h source/API/SBTarget.cpp source/Commands/CommandObjectTarget.cpp source/Core/Module.cpp source/Core/Section.cpp source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp source/Plugins/DynamicLoader/Static/DynamicLoaderStatic.cpp source/Target/SectionLoadList.cpp

Greg Clayton gclayton at apple.com
Fri Jul 6 18:24:12 PDT 2012


Author: gclayton
Date: Fri Jul  6 20:24:12 2012
New Revision: 159884

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

Fixed a crasher where the section load list was not thread safe.


Modified:
    lldb/trunk/include/lldb/Target/SectionLoadList.h
    lldb/trunk/source/API/SBTarget.cpp
    lldb/trunk/source/Commands/CommandObjectTarget.cpp
    lldb/trunk/source/Core/Module.cpp
    lldb/trunk/source/Core/Section.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/Target/SectionLoadList.cpp

Modified: lldb/trunk/include/lldb/Target/SectionLoadList.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/SectionLoadList.h?rev=159884&r1=159883&r2=159884&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/SectionLoadList.h (original)
+++ lldb/trunk/include/lldb/Target/SectionLoadList.h Fri Jul  6 20:24:12 2012
@@ -47,31 +47,31 @@
     Clear ();
 
     lldb::addr_t
-    GetSectionLoadAddress (const Section *section) const;
+    GetSectionLoadAddress (const lldb::SectionSP &section_sp) const;
 
     bool
     ResolveLoadAddress (lldb::addr_t load_addr, Address &so_addr) const;
 
     bool
-    SetSectionLoadAddress (const Section *section, lldb::addr_t load_addr, bool warn_multiple = false);
+    SetSectionLoadAddress (const lldb::SectionSP &section_sp, lldb::addr_t load_addr, bool warn_multiple = false);
 
     // The old load address should be specified when unloading to ensure we get
     // the correct instance of the section as a shared library could be loaded
     // at more than one location.
     bool
-    SetSectionUnloaded (const Section *section, lldb::addr_t load_addr);
+    SetSectionUnloaded (const lldb::SectionSP &section_sp, lldb::addr_t load_addr);
 
     // Unload all instances of a section. This function can be used on systems
     // that don't support multiple copies of the same shared library to be
     // loaded at the same time.
     size_t
-    SetSectionUnloaded (const Section *section);
+    SetSectionUnloaded (const lldb::SectionSP &section_sp);
 
     void
     Dump (Stream &s, Target *target);
 
 protected:
-    typedef std::map<lldb::addr_t, const Section *> addr_to_sect_collection;
+    typedef std::map<lldb::addr_t, lldb::SectionSP> addr_to_sect_collection;
     typedef llvm::DenseMap<const Section *, lldb::addr_t> sect_to_addr_collection;
     addr_to_sect_collection m_addr_to_sect;
     sect_to_addr_collection m_sect_to_addr;

Modified: lldb/trunk/source/API/SBTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBTarget.cpp?rev=159884&r1=159883&r2=159884&view=diff
==============================================================================
--- lldb/trunk/source/API/SBTarget.cpp (original)
+++ lldb/trunk/source/API/SBTarget.cpp Fri Jul  6 20:24:12 2012
@@ -2137,7 +2137,7 @@
                 }
                 else
                 {
-                    target_sp->GetSectionLoadList().SetSectionLoadAddress (section_sp.get(), section_base_addr);
+                    target_sp->GetSectionLoadList().SetSectionLoadAddress (section_sp, section_base_addr);
                 }
             }
         }
@@ -2163,7 +2163,7 @@
         }
         else
         {
-            target_sp->GetSectionLoadList().SetSectionUnloaded (section.GetSP().get());
+            target_sp->GetSectionLoadList().SetSectionUnloaded (section.GetSP());
         }
     }
     else
@@ -2233,7 +2233,7 @@
                     {
                         SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx));
                         if (section_sp)
-                            target_sp->GetSectionLoadList().SetSectionUnloaded (section_sp.get());
+                            target_sp->GetSectionLoadList().SetSectionUnloaded (section_sp);
                     }
                 }
                 else

Modified: lldb/trunk/source/Commands/CommandObjectTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectTarget.cpp?rev=159884&r1=159883&r2=159884&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectTarget.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectTarget.cpp Fri Jul  6 20:24:12 2012
@@ -2651,7 +2651,7 @@
                                                     }
                                                     else
                                                     {
-                                                        if (target->GetSectionLoadList().SetSectionLoadAddress (section_sp.get(), load_addr))
+                                                        if (target->GetSectionLoadList().SetSectionLoadAddress (section_sp, load_addr))
                                                             changed = true;
                                                         result.AppendMessageWithFormat("section '%s' loaded at 0x%llx\n", sect_name, load_addr);
                                                     }

Modified: lldb/trunk/source/Core/Module.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Module.cpp?rev=159884&r1=159883&r2=159884&view=diff
==============================================================================
--- lldb/trunk/source/Core/Module.cpp (original)
+++ lldb/trunk/source/Core/Module.cpp Fri Jul  6 20:24:12 2012
@@ -1135,11 +1135,11 @@
                 // Iterate through the object file sections to find the
                 // first section that starts of file offset zero and that
                 // has bytes in the file...
-                Section *section = section_list->GetSectionAtIndex (sect_idx).get();
+                SectionSP section_sp (section_list->GetSectionAtIndex (sect_idx));
                 // Only load non-thread specific sections when given a slide
-                if (section && !section->IsThreadSpecific())
+                if (section_sp && !section_sp->IsThreadSpecific())
                 {
-                    if (target.GetSectionLoadList().SetSectionLoadAddress (section, section->GetFileAddress() + offset))
+                    if (target.GetSectionLoadList().SetSectionLoadAddress (section_sp, section_sp->GetFileAddress() + offset))
                         ++num_loaded_sections;
                 }
             }

Modified: lldb/trunk/source/Core/Section.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Section.cpp?rev=159884&r1=159883&r2=159884&view=diff
==============================================================================
--- lldb/trunk/source/Core/Section.cpp (original)
+++ lldb/trunk/source/Core/Section.cpp Fri Jul  6 20:24:12 2012
@@ -152,7 +152,7 @@
         }
         else
         {
-            load_base_addr = target->GetSectionLoadList().GetSectionLoadAddress (this);
+            load_base_addr = target->GetSectionLoadList().GetSectionLoadAddress (const_cast<Section *>(this)->shared_from_this());
         }
     }
 

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=159884&r1=159883&r2=159884&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp (original)
+++ lldb/trunk/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp Fri Jul  6 20:24:12 2012
@@ -252,13 +252,13 @@
                         uint32_t num_sections_loaded = 0;
                         for (sect_idx=0; sect_idx<num_ondisk_sections; ++sect_idx)
                         {
-                            const Section *ondisk_section = ondisk_section_list->GetSectionAtIndex(sect_idx).get();
-                            if (ondisk_section)
+                            SectionSP ondisk_section_sp(ondisk_section_list->GetSectionAtIndex(sect_idx));
+                            if (ondisk_section_sp)
                             {
-                                const Section *memory_section = memory_section_list->FindSectionByName(ondisk_section->GetName()).get();
+                                const Section *memory_section = memory_section_list->FindSectionByName(ondisk_section_sp->GetName()).get();
                                 if (memory_section)
                                 {
-                                    target.GetSectionLoadList().SetSectionLoadAddress (ondisk_section, memory_section->GetFileAddress());
+                                    target.GetSectionLoadList().SetSectionLoadAddress (ondisk_section_sp, memory_section->GetFileAddress());
                                     ++num_sections_loaded;
                                 }
                             }

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=159884&r1=159883&r2=159884&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp (original)
+++ lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp Fri Jul  6 20:24:12 2012
@@ -390,15 +390,15 @@
                 uint32_t num_sections = section_list->GetSize();
                 for (uint32_t i=0; i<num_sections; ++i)
                 {
-                    Section* section = section_list->GetSectionAtIndex (i).get();
-                    if (section)
+                    SectionSP section_sp (section_list->GetSectionAtIndex (i));
+                    if (section_sp)
                     {
-                        const addr_t new_section_load_addr = section->GetFileAddress ();
-                        const addr_t old_section_load_addr = m_process->GetTarget().GetSectionLoadList().GetSectionLoadAddress (section);
+                        const addr_t new_section_load_addr = section_sp->GetFileAddress ();
+                        const addr_t old_section_load_addr = m_process->GetTarget().GetSectionLoadList().GetSectionLoadAddress (section_sp);
                         if (old_section_load_addr == LLDB_INVALID_ADDRESS ||
                             old_section_load_addr != new_section_load_addr)
                         {
-                            if (m_process->GetTarget().GetSectionLoadList().SetSectionLoadAddress (section, section->GetFileAddress ()))
+                            if (m_process->GetTarget().GetSectionLoadList().SetSectionLoadAddress (section_sp, section_sp->GetFileAddress ()))
                                 changed = true;
                         }
                     }
@@ -453,11 +453,11 @@
                             // "Section" objects, and "true" for all other sections.
                             const bool warn_multiple = section_sp->GetName() != g_section_name_LINKEDIT;
 
-                            const addr_t old_section_load_addr = m_process->GetTarget().GetSectionLoadList().GetSectionLoadAddress (section_sp.get());
+                            const addr_t old_section_load_addr = m_process->GetTarget().GetSectionLoadList().GetSectionLoadAddress (section_sp);
                             if (old_section_load_addr == LLDB_INVALID_ADDRESS ||
                                 old_section_load_addr != new_section_load_addr)
                             {
-                                if (m_process->GetTarget().GetSectionLoadList().SetSectionLoadAddress (section_sp.get(), new_section_load_addr, warn_multiple))
+                                if (m_process->GetTarget().GetSectionLoadList().SetSectionLoadAddress (section_sp, new_section_load_addr, warn_multiple))
                                     changed = true;
                             }
                         }
@@ -530,7 +530,7 @@
                     if (section_sp)
                     {
                         const addr_t old_section_load_addr = info.segments[i].vmaddr + info.slide;
-                        if (m_process->GetTarget().GetSectionLoadList().SetSectionUnloaded (section_sp.get(), old_section_load_addr))
+                        if (m_process->GetTarget().GetSectionLoadList().SetSectionUnloaded (section_sp, old_section_load_addr))
                             changed = true;
                     }
                     else

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=159884&r1=159883&r2=159884&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp (original)
+++ lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp Fri Jul  6 20:24:12 2012
@@ -172,9 +172,9 @@
 
     for (unsigned i = 0; i < num_sections; ++i)
     {
-        Section *section = sections->GetSectionAtIndex(i).get();
-        lldb::addr_t new_load_addr = section->GetFileAddress() + base_addr;
-        lldb::addr_t old_load_addr = load_list.GetSectionLoadAddress(section);
+        SectionSP section_sp (sections->GetSectionAtIndex(i));
+        lldb::addr_t new_load_addr = section_sp->GetFileAddress() + base_addr;
+        lldb::addr_t old_load_addr = load_list.GetSectionLoadAddress(section_sp);
 
         // If the file address of the section is zero then this is not an
         // allocatable/loadable section (property of ELF sh_addr).  Skip it.
@@ -183,7 +183,7 @@
 
         if (old_load_addr == LLDB_INVALID_ADDRESS ||
             old_load_addr != new_load_addr)
-            load_list.SetSectionLoadAddress(section, new_load_addr);
+            load_list.SetSectionLoadAddress(section_sp, new_load_addr);
     }
 }
 

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=159884&r1=159883&r2=159884&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/DynamicLoader/Static/DynamicLoaderStatic.cpp (original)
+++ lldb/trunk/source/Plugins/DynamicLoader/Static/DynamicLoaderStatic.cpp Fri Jul  6 20:24:12 2012
@@ -126,10 +126,10 @@
                         // Iterate through the object file sections to find the
                         // first section that starts of file offset zero and that
                         // has bytes in the file...
-                        Section *section = section_list->GetSectionAtIndex (sect_idx).get();
-                        if (section)
+                        SectionSP section_sp (section_list->GetSectionAtIndex (sect_idx));
+                        if (section_sp)
                         {
-                            if (m_process->GetTarget().GetSectionLoadList().SetSectionLoadAddress (section, section->GetFileAddress()))
+                            if (m_process->GetTarget().GetSectionLoadList().SetSectionLoadAddress (section_sp, section_sp->GetFileAddress()))
                                 changed = true;
                         }
                     }

Modified: lldb/trunk/source/Target/SectionLoadList.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/SectionLoadList.cpp?rev=159884&r1=159883&r2=159884&view=diff
==============================================================================
--- lldb/trunk/source/Target/SectionLoadList.cpp (original)
+++ lldb/trunk/source/Target/SectionLoadList.cpp Fri Jul  6 20:24:12 2012
@@ -41,14 +41,14 @@
 }
 
 addr_t
-SectionLoadList::GetSectionLoadAddress (const Section *section) const
+SectionLoadList::GetSectionLoadAddress (const lldb::SectionSP &section) const
 {
     // TODO: add support for the same section having multiple load addresses
     addr_t section_load_addr = LLDB_INVALID_ADDRESS;
     if (section)
     {
         Mutex::Locker locker(m_mutex);
-        sect_to_addr_collection::const_iterator pos = m_sect_to_addr.find (section);
+        sect_to_addr_collection::const_iterator pos = m_sect_to_addr.find (section.get());
         
         if (pos != m_sect_to_addr.end())
             section_load_addr = pos->second;
@@ -57,7 +57,7 @@
 }
 
 bool
-SectionLoadList::SetSectionLoadAddress (const Section *section, addr_t load_addr, bool warn_multiple)
+SectionLoadList::SetSectionLoadAddress (const lldb::SectionSP &section, addr_t load_addr, bool warn_multiple)
 {
     LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_DYNAMIC_LOADER | LIBLLDB_LOG_VERBOSE));
 
@@ -66,7 +66,7 @@
         const FileSpec &module_file_spec (section->GetModule()->GetFileSpec());
         log->Printf ("SectionLoadList::%s (section = %p (%s%s%s.%s), load_addr = 0x%16.16llx)",
                      __FUNCTION__,
-                     section,
+                     section.get(),
                      module_file_spec.GetDirectory().AsCString(),
                      module_file_spec.GetDirectory() ? "/" : "",
                      module_file_spec.GetFilename().AsCString(),
@@ -79,7 +79,7 @@
 
     // Fill in the section -> load_addr map
     Mutex::Locker locker(m_mutex);
-    sect_to_addr_collection::iterator sta_pos = m_sect_to_addr.find(section);
+    sect_to_addr_collection::iterator sta_pos = m_sect_to_addr.find(section.get());
     if (sta_pos != m_sect_to_addr.end())
     {
         if (load_addr == sta_pos->second)
@@ -88,7 +88,7 @@
             sta_pos->second = load_addr;
     }
     else
-        m_sect_to_addr[section] = load_addr;
+        m_sect_to_addr[section.get()] = load_addr;
 
     // Fill in the load_addr -> section map
     addr_to_sect_collection::iterator ats_pos = m_addr_to_sect.find(load_addr);
@@ -126,59 +126,62 @@
 }
 
 size_t
-SectionLoadList::SetSectionUnloaded (const Section *section)
+SectionLoadList::SetSectionUnloaded (const lldb::SectionSP &section_sp)
 {
-    LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_DYNAMIC_LOADER | LIBLLDB_LOG_VERBOSE));
+    size_t unload_count = 0;
 
-    if (log)
+    if (section_sp)
     {
-        const FileSpec &module_file_spec (section->GetModule()->GetFileSpec());
-        log->Printf ("SectionLoadList::%s (section = %p (%s%s%s.%s))",
-                     __FUNCTION__,
-                     section,
-                     module_file_spec.GetDirectory().AsCString(),
-                     module_file_spec.GetDirectory() ? "/" : "",
-                     module_file_spec.GetFilename().AsCString(),
-                     section->GetName().AsCString());
-    }
+        LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_DYNAMIC_LOADER | LIBLLDB_LOG_VERBOSE));
 
-    size_t unload_count = 0;
-    Mutex::Locker locker(m_mutex);
-    
-    sect_to_addr_collection::iterator sta_pos = m_sect_to_addr.find(section);
-    if (sta_pos != m_sect_to_addr.end())
-    {
-        addr_t load_addr = sta_pos->second;
-        m_sect_to_addr.erase (sta_pos);
+        if (log)
+        {
+            const FileSpec &module_file_spec (section_sp->GetModule()->GetFileSpec());
+            log->Printf ("SectionLoadList::%s (section = %p (%s%s%s.%s))",
+                         __FUNCTION__,
+                         section_sp.get(),
+                         module_file_spec.GetDirectory().AsCString(),
+                         module_file_spec.GetDirectory() ? "/" : "",
+                         module_file_spec.GetFilename().AsCString(),
+                         section_sp->GetName().AsCString());
+        }
 
-        addr_to_sect_collection::iterator ats_pos = m_addr_to_sect.find(load_addr);
-        if (ats_pos != m_addr_to_sect.end())
-            m_addr_to_sect.erase (ats_pos);
+        Mutex::Locker locker(m_mutex);
+        
+        sect_to_addr_collection::iterator sta_pos = m_sect_to_addr.find(section_sp.get());
+        if (sta_pos != m_sect_to_addr.end())
+        {
+            addr_t load_addr = sta_pos->second;
+            m_sect_to_addr.erase (sta_pos);
+
+            addr_to_sect_collection::iterator ats_pos = m_addr_to_sect.find(load_addr);
+            if (ats_pos != m_addr_to_sect.end())
+                m_addr_to_sect.erase (ats_pos);
+        }
     }
-    
     return unload_count;
 }
 
 bool
-SectionLoadList::SetSectionUnloaded (const Section *section, addr_t load_addr)
+SectionLoadList::SetSectionUnloaded (const lldb::SectionSP &section_sp, addr_t load_addr)
 {
     LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_DYNAMIC_LOADER | LIBLLDB_LOG_VERBOSE));
 
     if (log)
     {
-        const FileSpec &module_file_spec (section->GetModule()->GetFileSpec());
+        const FileSpec &module_file_spec (section_sp->GetModule()->GetFileSpec());
         log->Printf ("SectionLoadList::%s (section = %p (%s%s%s.%s), load_addr = 0x%16.16llx)",
                      __FUNCTION__,
-                     section,
+                     section_sp.get(),
                      module_file_spec.GetDirectory().AsCString(),
                      module_file_spec.GetDirectory() ? "/" : "",
                      module_file_spec.GetFilename().AsCString(),
-                     section->GetName().AsCString(),
+                     section_sp->GetName().AsCString(),
                      load_addr);
     }
     bool erased = false;
     Mutex::Locker locker(m_mutex);
-    sect_to_addr_collection::iterator sta_pos = m_sect_to_addr.find(section);
+    sect_to_addr_collection::iterator sta_pos = m_sect_to_addr.find(section_sp.get());
     if (sta_pos != m_sect_to_addr.end())
     {
         erased = true;
@@ -247,7 +250,7 @@
     addr_to_sect_collection::const_iterator pos, end;
     for (pos = m_addr_to_sect.begin(), end = m_addr_to_sect.end(); pos != end; ++pos)
     {
-        s.Printf("addr = 0x%16.16llx, section = %p: ", pos->first, pos->second);
+        s.Printf("addr = 0x%16.16llx, section = %p: ", pos->first, pos->second.get());
         pos->second->Dump (&s, target, 0);
     }
 }





More information about the lldb-commits mailing list