2010-06-09 00:52:24 +08:00
|
|
|
//===-- Section.cpp ---------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/Core/Section.h"
|
|
|
|
#include "lldb/Core/Module.h"
|
|
|
|
#include "lldb/Symbol/ObjectFile.h"
|
2013-12-06 09:12:00 +08:00
|
|
|
#include "lldb/Target/SectionLoadList.h"
|
2010-09-15 07:36:40 +08:00
|
|
|
#include "lldb/Target/Target.h"
|
2015-03-19 05:31:45 +08:00
|
|
|
#include "lldb/Utility/ConvertEnum.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2014-05-15 00:15:43 +08:00
|
|
|
#include <limits>
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2012-02-24 09:59:29 +08:00
|
|
|
Section::Section (const ModuleSP &module_sp,
|
2013-07-02 03:45:50 +08:00
|
|
|
ObjectFile *obj_file,
|
2012-02-24 09:59:29 +08:00
|
|
|
user_id_t sect_id,
|
|
|
|
const ConstString &name,
|
|
|
|
SectionType sect_type,
|
|
|
|
addr_t file_addr,
|
|
|
|
addr_t byte_size,
|
2013-03-05 05:46:16 +08:00
|
|
|
lldb::offset_t file_offset,
|
|
|
|
lldb::offset_t file_size,
|
2014-06-25 06:22:43 +08:00
|
|
|
uint32_t log2align,
|
2014-09-29 16:02:24 +08:00
|
|
|
uint32_t flags,
|
|
|
|
uint32_t target_byte_size/*=1*/) :
|
2012-02-24 09:59:29 +08:00
|
|
|
ModuleChild (module_sp),
|
2010-06-09 00:52:24 +08:00
|
|
|
UserID (sect_id),
|
|
|
|
Flags (flags),
|
2013-07-02 03:45:50 +08:00
|
|
|
m_obj_file (obj_file),
|
2013-06-20 05:50:28 +08:00
|
|
|
m_type (sect_type),
|
2012-02-24 09:59:29 +08:00
|
|
|
m_parent_wp (),
|
2010-06-09 00:52:24 +08:00
|
|
|
m_name (name),
|
|
|
|
m_file_addr (file_addr),
|
|
|
|
m_byte_size (byte_size),
|
|
|
|
m_file_offset (file_offset),
|
|
|
|
m_file_size (file_size),
|
2014-06-25 06:22:43 +08:00
|
|
|
m_log2align (log2align),
|
2010-06-09 00:52:24 +08:00
|
|
|
m_children (),
|
|
|
|
m_fake (false),
|
2012-03-28 05:10:07 +08:00
|
|
|
m_encrypted (false),
|
2014-09-29 16:02:24 +08:00
|
|
|
m_thread_specific (false),
|
|
|
|
m_target_byte_size(target_byte_size)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2012-11-30 05:49:15 +08:00
|
|
|
// 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",
|
2012-02-24 09:59:29 +08:00
|
|
|
// this, module_sp.get(), sect_id, file_addr, file_addr + byte_size, file_offset, file_offset + file_size, flags, name.GetCString());
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2012-02-24 09:59:29 +08:00
|
|
|
Section::Section (const lldb::SectionSP &parent_section_sp,
|
|
|
|
const ModuleSP &module_sp,
|
2013-07-02 03:45:50 +08:00
|
|
|
ObjectFile *obj_file,
|
2012-02-24 09:59:29 +08:00
|
|
|
user_id_t sect_id,
|
|
|
|
const ConstString &name,
|
|
|
|
SectionType sect_type,
|
|
|
|
addr_t file_addr,
|
|
|
|
addr_t byte_size,
|
2013-03-05 05:46:16 +08:00
|
|
|
lldb::offset_t file_offset,
|
|
|
|
lldb::offset_t file_size,
|
2014-06-25 06:22:43 +08:00
|
|
|
uint32_t log2align,
|
2014-09-29 16:02:24 +08:00
|
|
|
uint32_t flags,
|
|
|
|
uint32_t target_byte_size/*=1*/) :
|
2012-02-24 09:59:29 +08:00
|
|
|
ModuleChild (module_sp),
|
|
|
|
UserID (sect_id),
|
|
|
|
Flags (flags),
|
2013-07-02 03:45:50 +08:00
|
|
|
m_obj_file (obj_file),
|
2013-06-20 05:50:28 +08:00
|
|
|
m_type (sect_type),
|
2012-02-24 09:59:29 +08:00
|
|
|
m_parent_wp (),
|
|
|
|
m_name (name),
|
|
|
|
m_file_addr (file_addr),
|
|
|
|
m_byte_size (byte_size),
|
|
|
|
m_file_offset (file_offset),
|
|
|
|
m_file_size (file_size),
|
2014-06-25 06:22:43 +08:00
|
|
|
m_log2align (log2align),
|
2012-02-24 09:59:29 +08:00
|
|
|
m_children (),
|
|
|
|
m_fake (false),
|
2012-03-28 05:10:07 +08:00
|
|
|
m_encrypted (false),
|
2014-09-29 16:02:24 +08:00
|
|
|
m_thread_specific (false),
|
|
|
|
m_target_byte_size(target_byte_size)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2012-11-30 05:49:15 +08:00
|
|
|
// 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",
|
2012-02-24 09:59:29 +08:00
|
|
|
// 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());
|
|
|
|
if (parent_section_sp)
|
|
|
|
m_parent_wp = parent_section_sp;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2012-02-24 09:59:29 +08:00
|
|
|
Section::~Section()
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2012-02-24 09:59:29 +08:00
|
|
|
// printf ("Section::~Section(%p)\n", this);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
addr_t
|
|
|
|
Section::GetFileAddress () const
|
|
|
|
{
|
2012-02-24 09:59:29 +08:00
|
|
|
SectionSP parent_sp (GetParent ());
|
|
|
|
if (parent_sp)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
// This section has a parent which means m_file_addr is an offset into
|
|
|
|
// the parent section, so the file address for this section is the file
|
|
|
|
// address of the parent plus the offset
|
2012-02-24 09:59:29 +08:00
|
|
|
return parent_sp->GetFileAddress() + m_file_addr;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
// This section has no parent, so m_file_addr is the file base address
|
|
|
|
return m_file_addr;
|
|
|
|
}
|
|
|
|
|
2013-08-16 11:20:42 +08:00
|
|
|
bool
|
|
|
|
Section::SetFileAddress (lldb::addr_t file_addr)
|
|
|
|
{
|
|
|
|
SectionSP parent_sp (GetParent ());
|
|
|
|
if (parent_sp)
|
|
|
|
{
|
|
|
|
if (m_file_addr >= file_addr)
|
|
|
|
return parent_sp->SetFileAddress (m_file_addr - file_addr);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// This section has no parent, so m_file_addr is the file base address
|
|
|
|
m_file_addr = file_addr;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-24 09:59:29 +08:00
|
|
|
lldb::addr_t
|
|
|
|
Section::GetOffset () const
|
|
|
|
{
|
|
|
|
// This section has a parent which means m_file_addr is an offset.
|
|
|
|
SectionSP parent_sp (GetParent ());
|
|
|
|
if (parent_sp)
|
|
|
|
return m_file_addr;
|
|
|
|
|
|
|
|
// This section has no parent, so there is no offset to be had
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
addr_t
|
2010-09-15 07:36:40 +08:00
|
|
|
Section::GetLoadBaseAddress (Target *target) const
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
addr_t load_base_addr = LLDB_INVALID_ADDRESS;
|
2013-03-05 05:46:16 +08:00
|
|
|
SectionSP parent_sp (GetParent ());
|
|
|
|
if (parent_sp)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2013-03-05 05:46:16 +08:00
|
|
|
load_base_addr = parent_sp->GetLoadBaseAddress (target);
|
2011-08-22 10:49:39 +08:00
|
|
|
if (load_base_addr != LLDB_INVALID_ADDRESS)
|
2013-03-05 05:46:16 +08:00
|
|
|
load_base_addr += GetOffset();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2014-06-25 06:22:43 +08:00
|
|
|
if (load_base_addr == LLDB_INVALID_ADDRESS)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2013-03-05 05:46:16 +08:00
|
|
|
load_base_addr = target->GetSectionLoadList().GetSectionLoadAddress (const_cast<Section *>(this)->shared_from_this());
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
return load_base_addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Section::ResolveContainedAddress (addr_t offset, Address &so_addr) const
|
|
|
|
{
|
2013-01-26 02:06:21 +08:00
|
|
|
const size_t num_children = m_children.GetSize();
|
2010-06-09 00:52:24 +08:00
|
|
|
if (num_children > 0)
|
|
|
|
{
|
2013-01-26 02:06:21 +08:00
|
|
|
for (size_t i=0; i<num_children; i++)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
Section* child_section = m_children.GetSectionAtIndex (i).get();
|
|
|
|
|
|
|
|
addr_t child_offset = child_section->GetOffset();
|
|
|
|
if (child_offset <= offset && offset - child_offset < child_section->GetByteSize())
|
|
|
|
return child_section->ResolveContainedAddress (offset - child_offset, so_addr);
|
|
|
|
}
|
|
|
|
}
|
2013-03-05 05:46:16 +08:00
|
|
|
so_addr.SetOffset(offset);
|
|
|
|
so_addr.SetSection(const_cast<Section *>(this)->shared_from_this());
|
|
|
|
|
2012-07-13 04:44:21 +08:00
|
|
|
#ifdef LLDB_CONFIGURATION_DEBUG
|
2013-03-05 05:46:16 +08:00
|
|
|
// For debug builds, ensure that there are no orphaned (i.e., moduleless) sections.
|
|
|
|
assert(GetModule().get());
|
2012-07-13 04:44:21 +08:00
|
|
|
#endif
|
2010-06-09 00:52:24 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Section::ContainsFileAddress (addr_t vm_addr) const
|
|
|
|
{
|
|
|
|
const addr_t file_addr = GetFileAddress();
|
|
|
|
if (file_addr != LLDB_INVALID_ADDRESS)
|
|
|
|
{
|
|
|
|
if (file_addr <= vm_addr)
|
|
|
|
{
|
2014-09-29 16:02:24 +08:00
|
|
|
const addr_t offset = (vm_addr - file_addr) * m_target_byte_size;
|
2010-06-09 00:52:24 +08:00
|
|
|
return offset < GetByteSize();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
Section::Compare (const Section& a, const Section& b)
|
|
|
|
{
|
|
|
|
if (&a == &b)
|
|
|
|
return 0;
|
|
|
|
|
2012-02-24 09:59:29 +08:00
|
|
|
const ModuleSP a_module_sp = a.GetModule();
|
|
|
|
const ModuleSP b_module_sp = b.GetModule();
|
|
|
|
if (a_module_sp == b_module_sp)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
user_id_t a_sect_uid = a.GetID();
|
|
|
|
user_id_t b_sect_uid = b.GetID();
|
|
|
|
if (a_sect_uid < b_sect_uid)
|
|
|
|
return -1;
|
|
|
|
if (a_sect_uid > b_sect_uid)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// The modules are different, just compare the module pointers
|
2012-02-24 09:59:29 +08:00
|
|
|
if (a_module_sp.get() < b_module_sp.get())
|
2010-06-09 00:52:24 +08:00
|
|
|
return -1;
|
|
|
|
else
|
|
|
|
return 1; // We already know the modules aren't equal
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2010-12-08 13:08:21 +08:00
|
|
|
Section::Dump (Stream *s, Target *target, uint32_t depth) const
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-10-08 08:21:05 +08:00
|
|
|
// s->Printf("%.*p: ", (int)sizeof(void*) * 2, this);
|
2010-06-09 00:52:24 +08:00
|
|
|
s->Indent();
|
2012-11-30 05:49:15 +08:00
|
|
|
s->Printf("0x%8.8" PRIx64 " %-16s ", GetID(), GetSectionTypeAsCString (m_type));
|
2010-06-09 00:52:24 +08:00
|
|
|
bool resolved = true;
|
|
|
|
addr_t addr = LLDB_INVALID_ADDRESS;
|
|
|
|
|
|
|
|
if (GetByteSize() == 0)
|
|
|
|
s->Printf("%39s", "");
|
|
|
|
else
|
|
|
|
{
|
2013-03-05 05:46:16 +08:00
|
|
|
if (target)
|
2010-09-15 07:36:40 +08:00
|
|
|
addr = GetLoadBaseAddress (target);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
if (addr == LLDB_INVALID_ADDRESS)
|
|
|
|
{
|
2010-09-15 07:36:40 +08:00
|
|
|
if (target)
|
2010-06-09 00:52:24 +08:00
|
|
|
resolved = false;
|
|
|
|
addr = GetFileAddress();
|
|
|
|
}
|
|
|
|
|
|
|
|
VMRange range(addr, addr + m_byte_size);
|
|
|
|
range.Dump (s, 0);
|
|
|
|
}
|
|
|
|
|
2012-11-30 05:49:15 +08:00
|
|
|
s->Printf("%c 0x%8.8" PRIx64 " 0x%8.8" PRIx64 " 0x%8.8x ", resolved ? ' ' : '*', m_file_offset, m_file_size, Get());
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
DumpName (s);
|
|
|
|
|
|
|
|
s->EOL();
|
|
|
|
|
2010-12-08 13:08:21 +08:00
|
|
|
if (depth > 0)
|
|
|
|
m_children.Dump(s, target, false, depth - 1);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Section::DumpName (Stream *s) const
|
|
|
|
{
|
2012-02-24 09:59:29 +08:00
|
|
|
SectionSP parent_sp (GetParent ());
|
|
|
|
if (parent_sp)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2012-02-24 09:59:29 +08:00
|
|
|
parent_sp->DumpName (s);
|
|
|
|
s->PutChar('.');
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-02-24 09:59:29 +08:00
|
|
|
// The top most section prints the module basename
|
2013-07-02 03:45:50 +08:00
|
|
|
const char * name = NULL;
|
2012-02-24 09:59:29 +08:00
|
|
|
ModuleSP module_sp (GetModule());
|
2013-07-02 03:45:50 +08:00
|
|
|
const FileSpec &file_spec = m_obj_file->GetFileSpec();
|
|
|
|
|
|
|
|
if (m_obj_file)
|
|
|
|
name = file_spec.GetFilename().AsCString();
|
|
|
|
if ((!name || !name[0]) && module_sp)
|
|
|
|
name = module_sp->GetFileSpec().GetFilename().AsCString();
|
|
|
|
if (name && name[0])
|
|
|
|
s->Printf("%s.", name);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
m_name.Dump(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Section::IsDescendant (const Section *section)
|
|
|
|
{
|
|
|
|
if (this == section)
|
|
|
|
return true;
|
2012-02-24 09:59:29 +08:00
|
|
|
SectionSP parent_sp (GetParent ());
|
|
|
|
if (parent_sp)
|
|
|
|
return parent_sp->IsDescendant (section);
|
2010-06-09 00:52:24 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Section::Slide (addr_t slide_amount, bool slide_children)
|
|
|
|
{
|
|
|
|
if (m_file_addr != LLDB_INVALID_ADDRESS)
|
|
|
|
{
|
|
|
|
if (slide_amount == 0)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
m_file_addr += slide_amount;
|
|
|
|
|
|
|
|
if (slide_children)
|
|
|
|
m_children.Slide (slide_amount, slide_children);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark SectionList
|
|
|
|
|
|
|
|
SectionList::SectionList () :
|
|
|
|
m_sections()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SectionList::~SectionList ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-07-10 09:23:25 +08:00
|
|
|
SectionList &
|
|
|
|
SectionList::operator = (const SectionList& rhs)
|
2013-07-02 03:45:50 +08:00
|
|
|
{
|
2013-07-10 09:23:25 +08:00
|
|
|
if (this != &rhs)
|
|
|
|
m_sections = rhs.m_sections;
|
|
|
|
return *this;
|
2013-07-02 03:45:50 +08:00
|
|
|
}
|
|
|
|
|
2013-01-26 02:06:21 +08:00
|
|
|
size_t
|
2012-02-24 09:59:29 +08:00
|
|
|
SectionList::AddSection (const lldb::SectionSP& section_sp)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2014-05-14 09:12:09 +08:00
|
|
|
if (section_sp)
|
|
|
|
{
|
|
|
|
size_t section_index = m_sections.size();
|
|
|
|
m_sections.push_back(section_sp);
|
|
|
|
return section_index;
|
|
|
|
}
|
2014-05-15 00:15:43 +08:00
|
|
|
|
|
|
|
return std::numeric_limits<size_t>::max ();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2013-07-02 03:45:50 +08:00
|
|
|
// Warning, this can be slow as it's removing items from a std::vector.
|
|
|
|
bool
|
|
|
|
SectionList::DeleteSection (size_t idx)
|
|
|
|
{
|
|
|
|
if (idx < m_sections.size())
|
|
|
|
{
|
|
|
|
m_sections.erase (m_sections.begin() + idx);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-01-26 02:06:21 +08:00
|
|
|
size_t
|
2010-06-09 00:52:24 +08:00
|
|
|
SectionList::FindSectionIndex (const Section* sect)
|
|
|
|
{
|
|
|
|
iterator sect_iter;
|
|
|
|
iterator begin = m_sections.begin();
|
|
|
|
iterator end = m_sections.end();
|
|
|
|
for (sect_iter = begin; sect_iter != end; ++sect_iter)
|
|
|
|
{
|
|
|
|
if (sect_iter->get() == sect)
|
|
|
|
{
|
|
|
|
// The secton was already in this section list
|
|
|
|
return std::distance (begin, sect_iter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return UINT32_MAX;
|
|
|
|
}
|
|
|
|
|
2013-01-26 02:06:21 +08:00
|
|
|
size_t
|
2012-02-24 09:59:29 +08:00
|
|
|
SectionList::AddUniqueSection (const lldb::SectionSP& sect_sp)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2013-01-26 02:06:21 +08:00
|
|
|
size_t sect_idx = FindSectionIndex (sect_sp.get());
|
2010-06-09 00:52:24 +08:00
|
|
|
if (sect_idx == UINT32_MAX)
|
2013-07-02 03:45:50 +08:00
|
|
|
{
|
2010-06-09 00:52:24 +08:00
|
|
|
sect_idx = AddSection (sect_sp);
|
2013-07-02 03:45:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
return sect_idx;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-02-24 09:59:29 +08:00
|
|
|
SectionList::ReplaceSection (user_id_t sect_id, const lldb::SectionSP& sect_sp, uint32_t depth)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
iterator sect_iter, end = m_sections.end();
|
|
|
|
for (sect_iter = m_sections.begin(); sect_iter != end; ++sect_iter)
|
|
|
|
{
|
|
|
|
if ((*sect_iter)->GetID() == sect_id)
|
|
|
|
{
|
|
|
|
*sect_iter = sect_sp;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (depth > 0)
|
|
|
|
{
|
|
|
|
if ((*sect_iter)->GetChildren().ReplaceSection(sect_id, sect_sp, depth - 1))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
SectionList::GetNumSections (uint32_t depth) const
|
|
|
|
{
|
|
|
|
size_t count = m_sections.size();
|
|
|
|
if (depth > 0)
|
|
|
|
{
|
|
|
|
const_iterator sect_iter, end = m_sections.end();
|
|
|
|
for (sect_iter = m_sections.begin(); sect_iter != end; ++sect_iter)
|
|
|
|
{
|
|
|
|
count += (*sect_iter)->GetChildren().GetNumSections(depth - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
SectionSP
|
2013-01-26 02:06:21 +08:00
|
|
|
SectionList::GetSectionAtIndex (size_t idx) const
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
SectionSP sect_sp;
|
|
|
|
if (idx < m_sections.size())
|
|
|
|
sect_sp = m_sections[idx];
|
|
|
|
return sect_sp;
|
|
|
|
}
|
|
|
|
|
|
|
|
SectionSP
|
|
|
|
SectionList::FindSectionByName (const ConstString §ion_dstr) const
|
|
|
|
{
|
|
|
|
SectionSP sect_sp;
|
|
|
|
// Check if we have a valid section string
|
2012-02-24 09:59:29 +08:00
|
|
|
if (section_dstr && !m_sections.empty())
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
2012-02-24 09:59:29 +08:00
|
|
|
Section *child_section = sect_iter->get();
|
2014-05-14 09:12:09 +08:00
|
|
|
if (child_section)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2014-05-14 09:12:09 +08:00
|
|
|
if (child_section->GetName() == section_dstr)
|
|
|
|
{
|
|
|
|
sect_sp = *sect_iter;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sect_sp = child_section->GetChildren().FindSectionByName(section_dstr);
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return sect_sp;
|
|
|
|
}
|
|
|
|
|
|
|
|
SectionSP
|
|
|
|
SectionList::FindSectionByID (user_id_t sect_id) const
|
|
|
|
{
|
|
|
|
SectionSP sect_sp;
|
|
|
|
if (sect_id)
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
if ((*sect_iter)->GetID() == sect_id)
|
|
|
|
{
|
|
|
|
sect_sp = *sect_iter;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sect_sp = (*sect_iter)->GetChildren().FindSectionByID (sect_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return sect_sp;
|
|
|
|
}
|
|
|
|
|
2010-07-22 05:49:46 +08:00
|
|
|
|
|
|
|
SectionSP
|
2013-01-26 02:06:21 +08:00
|
|
|
SectionList::FindSectionByType (SectionType sect_type, bool check_children, size_t start_idx) const
|
2010-07-22 05:49:46 +08:00
|
|
|
{
|
|
|
|
SectionSP sect_sp;
|
2013-01-26 02:06:21 +08:00
|
|
|
size_t num_sections = m_sections.size();
|
|
|
|
for (size_t idx = start_idx; idx < num_sections; ++idx)
|
2010-07-22 05:49:46 +08:00
|
|
|
{
|
|
|
|
if (m_sections[idx]->GetType() == sect_type)
|
|
|
|
{
|
|
|
|
sect_sp = m_sections[idx];
|
|
|
|
break;
|
|
|
|
}
|
2010-07-22 06:54:26 +08:00
|
|
|
else if (check_children)
|
|
|
|
{
|
|
|
|
sect_sp = m_sections[idx]->GetChildren().FindSectionByType (sect_type, check_children, 0);
|
|
|
|
if (sect_sp)
|
|
|
|
break;
|
|
|
|
}
|
2010-07-22 05:49:46 +08:00
|
|
|
}
|
|
|
|
return sect_sp;
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
SectionSP
|
|
|
|
SectionList::FindSectionContainingFileAddress (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->ContainsFileAddress (vm_addr))
|
|
|
|
{
|
|
|
|
// The file address is in this section. We need to make sure one of our child
|
|
|
|
// sections doesn't contain this address as well as obeying the depth limit
|
|
|
|
// that was passed in.
|
|
|
|
if (depth > 0)
|
|
|
|
sect_sp = sect->GetChildren().FindSectionContainingFileAddress(vm_addr, depth - 1);
|
|
|
|
|
|
|
|
if (sect_sp.get() == NULL && !sect->IsFake())
|
|
|
|
sect_sp = *sect_iter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return sect_sp;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SectionList::ContainsSection(user_id_t sect_id) const
|
|
|
|
{
|
|
|
|
return FindSectionByID (sect_id).get() != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-12-08 13:08:21 +08:00
|
|
|
SectionList::Dump (Stream *s, Target *target, bool show_header, uint32_t depth) const
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-12-08 02:05:22 +08:00
|
|
|
bool target_has_loaded_sections = target && !target->GetSectionLoadList().IsEmpty();
|
2010-06-09 00:52:24 +08:00
|
|
|
if (show_header && !m_sections.empty())
|
|
|
|
{
|
|
|
|
s->Indent();
|
2012-01-12 13:25:17 +08:00
|
|
|
s->Printf( "SectID Type %s Address File Off. File Size Flags Section Name\n", target_has_loaded_sections ? "Load" : "File");
|
2010-06-09 00:52:24 +08:00
|
|
|
s->Indent();
|
2012-01-12 13:25:17 +08:00
|
|
|
s->PutCString("---------- ---------------- --------------------------------------- ---------- ---------- ---------- ----------------------------\n");
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const_iterator sect_iter;
|
|
|
|
const_iterator end = m_sections.end();
|
|
|
|
for (sect_iter = m_sections.begin(); sect_iter != end; ++sect_iter)
|
|
|
|
{
|
2010-12-08 13:08:21 +08:00
|
|
|
(*sect_iter)->Dump(s, target_has_loaded_sections ? target : NULL, depth);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (show_header && !m_sections.empty())
|
|
|
|
s->IndentLess();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
SectionList::Slide (addr_t slide_amount, bool slide_children)
|
|
|
|
{
|
|
|
|
size_t count = 0;
|
|
|
|
const_iterator pos, end = m_sections.end();
|
|
|
|
for (pos = m_sections.begin(); pos != end; ++pos)
|
|
|
|
{
|
|
|
|
if ((*pos)->Slide(slide_amount, slide_children))
|
|
|
|
++count;
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|