[Lldb-commits] [lldb] r158188 - in /lldb/trunk: include/lldb/Core/Section.h source/Core/Section.cpp source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp source/Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.cpp

Sean Callanan scallanan at apple.com
Thu Jun 7 19:16:09 PDT 2012


Author: spyffe
Date: Thu Jun  7 21:16:08 2012
New Revision: 158188

URL: http://llvm.org/viewvc/llvm-project?rev=158188&view=rev
Log:
Committed a change to the SectionList that introduces
a cache of address ranges for child sections,
accelerating lookups.  This cache is built during
object file loading, and is then set in stone once
the object files are done loading.  (In Debug builds,
we ensure that the cache is never invalidated after
that.)

Modified:
    lldb/trunk/include/lldb/Core/Section.h
    lldb/trunk/source/Core/Section.cpp
    lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
    lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
    lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
    lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
    lldb/trunk/source/Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.cpp

Modified: lldb/trunk/include/lldb/Core/Section.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Section.h?rev=158188&r1=158187&r2=158188&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/Section.h (original)
+++ lldb/trunk/include/lldb/Core/Section.h Thu Jun  7 21:16:08 2012
@@ -15,6 +15,7 @@
 #include "lldb/Core/Flags.h"
 #include "lldb/Core/ModuleChild.h"
 #include "lldb/Core/ConstString.h"
+#include "lldb/Core/RangeMap.h"
 #include "lldb/Core/UserID.h"
 #include "lldb/Core/VMRange.h"
 #include <limits.h>
@@ -85,9 +86,23 @@
 
     size_t
     Slide (lldb::addr_t slide_amount, bool slide_children);
+    
+    // Update all section lookup caches
+    void
+    Finalize ();
 
 protected:
     collection  m_sections;
+
+    typedef RangeDataArray<uint64_t, uint64_t, collection::size_type, 1> SectionRangeCache;
+    mutable SectionRangeCache   m_range_cache;
+#ifdef LLDB_CONFIGURATION_DEBUG
+    mutable bool                m_finalized;
+#endif
+    
+    void BuildRangeCache() const;
+    
+    void InvalidateRangeCache() const;
 };
 
 
@@ -273,6 +288,13 @@
     {
         m_thread_specific = b;
     }
+    
+    // Update all section lookup caches
+    void
+    Finalize ()
+    {
+        m_children.Finalize();
+    }
 
 protected:
 

Modified: lldb/trunk/source/Core/Section.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Section.cpp?rev=158188&r1=158187&r2=158188&view=diff
==============================================================================
--- lldb/trunk/source/Core/Section.cpp (original)
+++ lldb/trunk/source/Core/Section.cpp Thu Jun  7 21:16:08 2012
@@ -379,6 +379,9 @@
 
 SectionList::SectionList () :
     m_sections()
+#ifdef LLDB_CONFIGURATION_DEBUG
+    , m_finalized(false)
+#endif
 {
 }
 
@@ -393,6 +396,7 @@
     assert (section_sp.get());
     uint32_t section_index = m_sections.size();
     m_sections.push_back(section_sp);
+    InvalidateRangeCache();
     return section_index;
 }
 
@@ -432,6 +436,7 @@
         if ((*sect_iter)->GetID() == sect_id)
         {
             *sect_iter = sect_sp;
+            InvalidateRangeCache();
             return true;
         }
         else if (depth > 0)
@@ -565,26 +570,69 @@
     return sect_sp;
 }
 
+void
+SectionList::BuildRangeCache() const
+{
+    m_range_cache.Clear();
+    
+    for (collection::size_type idx = 0, last_idx = m_sections.size();
+         idx < last_idx;
+         ++idx)
+    {
+        Section *sect = m_sections[idx].get();
+        
+        addr_t linked_file_address = sect->GetLinkedFileAddress();
+        
+        if (linked_file_address != LLDB_INVALID_ADDRESS)
+            m_range_cache.Append(SectionRangeCache::Entry(linked_file_address, sect->GetByteSize(), idx));
+    }
+    
+    m_range_cache.Sort();
+    
+#ifdef LLDB_CONFIGURATION_DEBUG
+    m_finalized = true;
+#endif
+}
+
+void
+SectionList::InvalidateRangeCache() const
+{
+#ifdef LLDB_CONFIGURATION_DEBUG
+    assert(!m_finalized);
+#endif
+    m_range_cache.Clear();
+}
 
 SectionSP
 SectionList::FindSectionContainingLinkedFileAddress (addr_t vm_addr, uint32_t depth) const
 {
-    SectionSP sect_sp;
-    const_iterator sect_iter;
-    const_iterator end = m_sections.end();
-    for (sect_iter = m_sections.begin(); sect_iter != end && sect_sp.get() == NULL; ++sect_iter)
-    {
-        Section *sect = sect_iter->get();
-        if (sect->ContainsLinkedFileAddress (vm_addr))
-        {
-            sect_sp = *sect_iter;
-        }
-        else if (depth > 0)
-        {
-            sect_sp = sect->GetChildren().FindSectionContainingLinkedFileAddress (vm_addr, depth - 1);
-        }
+    //if (m_range_cache.IsEmpty())
+    //    BuildRangeCache();
+#ifdef LLDB_CONFIGURATION_DEBUG
+    assert(m_finalized);
+#endif
+    
+    SectionRangeCache::Entry *entry = m_range_cache.FindEntryThatContains(vm_addr);
+    
+    if (entry)
+        return m_sections[entry->data];
+        
+    if (depth == 0)
+        return SectionSP();
+    
+    for (const_iterator si = m_sections.begin(), se = m_sections.end();
+         si != se;
+         ++si)
+    {
+        Section *sect = si->get();
+        
+        SectionSP sect_sp = sect->GetChildren().FindSectionContainingLinkedFileAddress(vm_addr, depth - 1);
+            
+        if (sect_sp)
+            return sect_sp;
     }
-    return sect_sp;
+    
+    return SectionSP();
 }
 
 bool
@@ -628,6 +676,22 @@
         if ((*pos)->Slide(slide_amount, slide_children))
             ++count;
     }
+    InvalidateRangeCache();
     return count;
 }
 
+void
+SectionList::Finalize ()
+{
+    BuildRangeCache();
+    
+    for (const_iterator si = m_sections.begin(), se = m_sections.end();
+         si != se;
+         ++si)
+    {
+        Section *sect = si->get();
+        
+        sect->GetChildren().Finalize();
+    }
+}
+

Modified: lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp?rev=158188&r1=158187&r2=158188&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp (original)
+++ lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp Thu Jun  7 21:16:08 2012
@@ -682,6 +682,8 @@
                 section_sp->SetIsThreadSpecific (is_thread_specific);
             m_sections_ap->AddSection(section_sp);
         }
+        
+        m_sections_ap->Finalize(); // Now that we're done adding sections, finalize to build fast-lookup caches
     }
 
     return m_sections_ap.get();

Modified: lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp?rev=158188&r1=158187&r2=158188&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp (original)
+++ lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp Thu Jun  7 21:16:08 2012
@@ -889,7 +889,7 @@
                                     // adjust the child section offsets for all existing children.
                                     const lldb::addr_t slide_amount = sect64_min_addr - curr_seg_min_addr;
                                     segment->Slide(slide_amount, false);
-                                    segment->GetChildren().Slide (-slide_amount, false);
+                                    segment->GetChildren().Slide(-slide_amount, false);
                                     segment->SetByteSize (curr_seg_max_addr - sect64_min_addr);
                                 }
 

Modified: lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp?rev=158188&r1=158187&r2=158188&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp (original)
+++ lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp Thu Jun  7 21:16:08 2012
@@ -648,6 +648,8 @@
 
                 m_sections_ap->AddSection(section_sp);
             }
+            
+            m_sections_ap->Finalize(); // Now that we're done adding sections, finalize to build fast-lookup caches
         }
     }
     return m_sections_ap.get();

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp?rev=158188&r1=158187&r2=158188&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp Thu Jun  7 21:16:08 2012
@@ -426,6 +426,8 @@
                         }
                     }
                 }
+                oso_objfile->GetSectionList()->Finalize(); // Now that we're done adding sections, finalize to build fast-lookup caches
+                comp_unit_info->debug_map_sections_sp->Finalize();
 #if defined(DEBUG_OSO_DMAP)
                 s << "OSO sections after:\n";
                 oso_objfile->GetSectionList()->Dump(&s, NULL, true);

Modified: lldb/trunk/source/Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.cpp?rev=158188&r1=158187&r2=158188&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.cpp Thu Jun  7 21:16:08 2012
@@ -78,6 +78,8 @@
                     dsym_section_list->AddSection(exec_sect_sp);
             }
         }
+        
+        dsym_section_list->Finalize(); // Now that we're done adding sections, finalize to build fast-lookup caches
     }
 }
 





More information about the lldb-commits mailing list