<rdar://problem/13338643>
DWARF with .o files now uses 40-60% less memory!
Big fixes include:
- Change line table internal representation to contain "file addresses". Since each line table is owned by a compile unit that is owned by a module, it makes address translation into lldb_private::Address easy to do when needed.
- Removed linked address members/methods from lldb_private::Section and lldb_private::Address
- lldb_private::LineTable can now relink itself using a FileRangeMap to make it easier to re-link line tables in the future
- Added ObjectFile::ClearSymtab() so that we can get rid of the object file symbol tables after we parse them once since they are not needed and kept memory allocated for no reason
- Moved the m_sections_ap (std::auto_ptr to section list) and m_symtab_ap (std::auto_ptr to the lldb_private::Symtab) out of each of the ObjectFile subclasses and put it into lldb_private::ObjectFile.
- Changed how the debug map is parsed and stored to be able to:
- Lazily parse the debug map for each object file
- not require the address map for a .o file until debug information is linked for a .o file
llvm-svn: 176454
diff --git a/lldb/source/Core/Section.cpp b/lldb/source/Core/Section.cpp
index a9481d2..0d924a3 100644
--- a/lldb/source/Core/Section.cpp
+++ b/lldb/source/Core/Section.cpp
@@ -21,8 +21,8 @@
SectionType sect_type,
addr_t file_addr,
addr_t byte_size,
- uint64_t file_offset,
- uint64_t file_size,
+ lldb::offset_t file_offset,
+ lldb::offset_t file_size,
uint32_t flags) :
ModuleChild (module_sp),
UserID (sect_id),
@@ -37,9 +37,7 @@
m_children (),
m_fake (false),
m_encrypted (false),
- m_thread_specific (false),
- m_linked_section_wp(),
- m_linked_offset (0)
+ m_thread_specific (false)
{
// printf ("Section::Section(%p): module=%p, sect_id = 0x%16.16" PRIx64 ", addr=[0x%16.16" PRIx64 " - 0x%16.16" PRIx64 "), file [0x%16.16" PRIx64 " - 0x%16.16" PRIx64 "), flags = 0x%8.8x, name = %s\n",
// this, module_sp.get(), sect_id, file_addr, file_addr + byte_size, file_offset, file_offset + file_size, flags, name.GetCString());
@@ -52,8 +50,8 @@
SectionType sect_type,
addr_t file_addr,
addr_t byte_size,
- uint64_t file_offset,
- uint64_t file_size,
+ lldb::offset_t file_offset,
+ lldb::offset_t file_size,
uint32_t flags) :
ModuleChild (module_sp),
UserID (sect_id),
@@ -68,9 +66,7 @@
m_children (),
m_fake (false),
m_encrypted (false),
- m_thread_specific (false),
- m_linked_section_wp(),
- m_linked_offset (0)
+ m_thread_specific (false)
{
// printf ("Section::Section(%p): module=%p, sect_id = 0x%16.16" PRIx64 ", addr=[0x%16.16" PRIx64 " - 0x%16.16" PRIx64 "), file [0x%16.16" PRIx64 " - 0x%16.16" PRIx64 "), flags = 0x%8.8x, name = %s.%s\n",
// this, module_sp.get(), sect_id, file_addr, file_addr + byte_size, file_offset, file_offset + file_size, flags, parent_section_sp->GetName().GetCString(), name.GetCString());
@@ -83,15 +79,6 @@
// printf ("Section::~Section(%p)\n", this);
}
-const ConstString&
-Section::GetName() const
-{
- SectionSP linked_section_sp (m_linked_section_wp.lock());
- if (linked_section_sp)
- return linked_section_sp->GetName();
- return m_name;
-}
-
addr_t
Section::GetFileAddress () const
{
@@ -119,43 +106,21 @@
return 0;
}
-
-addr_t
-Section::GetLinkedFileAddress () const
-{
- SectionSP linked_section_sp (m_linked_section_wp.lock());
- if (linked_section_sp)
- return linked_section_sp->GetFileAddress() + m_linked_offset;
- return LLDB_INVALID_ADDRESS;
-}
-
-
addr_t
Section::GetLoadBaseAddress (Target *target) const
{
addr_t load_base_addr = LLDB_INVALID_ADDRESS;
- SectionSP linked_section_sp (m_linked_section_wp.lock());
- if (linked_section_sp)
+ SectionSP parent_sp (GetParent ());
+ if (parent_sp)
{
- load_base_addr = linked_section_sp->GetLoadBaseAddress(target);
+ load_base_addr = parent_sp->GetLoadBaseAddress (target);
if (load_base_addr != LLDB_INVALID_ADDRESS)
- load_base_addr += m_linked_offset;
+ load_base_addr += GetOffset();
}
else
{
- SectionSP parent_sp (GetParent ());
- if (parent_sp)
- {
- load_base_addr = parent_sp->GetLoadBaseAddress (target);
- if (load_base_addr != LLDB_INVALID_ADDRESS)
- load_base_addr += GetOffset();
- }
- else
- {
- load_base_addr = target->GetSectionLoadList().GetSectionLoadAddress (const_cast<Section *>(this)->shared_from_this());
- }
+ load_base_addr = target->GetSectionLoadList().GetSectionLoadAddress (const_cast<Section *>(this)->shared_from_this());
}
-
return load_base_addr;
}
@@ -174,22 +139,13 @@
return child_section->ResolveContainedAddress (offset - child_offset, so_addr);
}
}
- SectionSP linked_section_sp (m_linked_section_wp.lock());
- if (linked_section_sp)
- {
- so_addr.SetOffset(m_linked_offset + offset);
- so_addr.SetSection(linked_section_sp);
- }
- else
- {
- so_addr.SetOffset(offset);
- so_addr.SetSection(const_cast<Section *>(this)->shared_from_this());
-
+ so_addr.SetOffset(offset);
+ so_addr.SetSection(const_cast<Section *>(this)->shared_from_this());
+
#ifdef LLDB_CONFIGURATION_DEBUG
- // For debug builds, ensure that there are no orphaned (i.e., moduleless) sections.
- assert(GetModule().get());
+ // For debug builds, ensure that there are no orphaned (i.e., moduleless) sections.
+ assert(GetModule().get());
#endif
- }
return true;
}
@@ -208,21 +164,6 @@
return false;
}
-bool
-Section::ContainsLinkedFileAddress (addr_t vm_addr) const
-{
- const addr_t linked_file_addr = GetLinkedFileAddress();
- if (linked_file_addr != LLDB_INVALID_ADDRESS)
- {
- if (linked_file_addr <= vm_addr)
- {
- const addr_t offset = vm_addr - linked_file_addr;
- return offset < GetByteSize();
- }
- }
- return false;
-}
-
int
Section::Compare (const Section& a, const Section& b)
{
@@ -261,12 +202,11 @@
bool resolved = true;
addr_t addr = LLDB_INVALID_ADDRESS;
- SectionSP linked_section_sp (m_linked_section_wp.lock());
if (GetByteSize() == 0)
s->Printf("%39s", "");
else
{
- if (target && linked_section_sp.get() == NULL)
+ if (target)
addr = GetLoadBaseAddress (target);
if (addr == LLDB_INVALID_ADDRESS)
@@ -286,35 +226,6 @@
s->EOL();
- if (linked_section_sp)
- {
- addr = LLDB_INVALID_ADDRESS;
- resolved = true;
- if (target)
- {
- addr = linked_section_sp->GetLoadBaseAddress(target);
- if (addr != LLDB_INVALID_ADDRESS)
- addr += m_linked_offset;
- }
-
- if (addr == LLDB_INVALID_ADDRESS)
- {
- if (target)
- resolved = false;
- addr = linked_section_sp->GetFileAddress() + m_linked_offset;
- }
-
- int indent = 28 + s->GetIndentLevel();
- s->Printf("%*.*s", indent, indent, "");
- VMRange linked_range(addr, addr + m_byte_size);
- linked_range.Dump (s, 0);
- indent = 3 * (sizeof(uint32_t) * 2 + 2 + 1) + 1;
- s->Printf("%c%*.*s", resolved ? ' ' : '*', indent, indent, "");
-
- linked_section_sp->DumpName(s);
- s->Printf(" + 0x%" PRIx64 "\n", m_linked_offset);
- }
-
if (depth > 0)
m_children.Dump(s, target, false, depth - 1);
}
@@ -371,22 +282,10 @@
return false;
}
-void
-Section::SetLinkedLocation (const lldb::SectionSP &linked_section_sp, uint64_t linked_offset)
-{
- if (linked_section_sp)
- m_module_wp = linked_section_sp->GetModule();
- m_linked_section_wp = linked_section_sp;
- m_linked_offset = linked_offset;
-}
-
#pragma mark SectionList
SectionList::SectionList () :
m_sections()
-#ifdef LLDB_CONFIGURATION_DEBUG
- , m_finalized(false)
-#endif
{
}
@@ -401,7 +300,6 @@
assert (section_sp.get());
size_t section_index = m_sections.size();
m_sections.push_back(section_sp);
- InvalidateRangeCache();
return section_index;
}
@@ -441,7 +339,6 @@
if ((*sect_iter)->GetID() == sect_id)
{
*sect_iter = sect_sp;
- InvalidateRangeCache();
return true;
}
else if (depth > 0)
@@ -575,71 +472,6 @@
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
-{
- //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 SectionSP();
-}
-
bool
SectionList::ContainsSection(user_id_t sect_id) const
{
@@ -681,15 +513,12 @@
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)