2011-04-26 02:36:36 +08:00
|
|
|
//===-- UnwindTable.cpp -----------------------------------------*- C++ -*-===//
|
2010-09-10 15:49:16 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-09-23 09:09:21 +08:00
|
|
|
#include "lldb/Symbol/UnwindTable.h"
|
2010-09-10 15:49:16 +08:00
|
|
|
|
2010-09-23 09:09:21 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "lldb/Core/Module.h"
|
|
|
|
#include "lldb/Core/Section.h"
|
|
|
|
#include "lldb/Symbol/ObjectFile.h"
|
2010-09-10 15:49:16 +08:00
|
|
|
#include "lldb/Symbol/FuncUnwinders.h"
|
|
|
|
#include "lldb/Symbol/SymbolContext.h"
|
|
|
|
#include "lldb/Symbol/DWARFCallFrameInfo.h"
|
2011-04-26 05:14:26 +08:00
|
|
|
#include "lldb/Target/UnwindAssembly.h"
|
2010-09-10 15:49:16 +08:00
|
|
|
|
|
|
|
// There is one UnwindTable object per ObjectFile.
|
|
|
|
// It contains a list of Unwind objects -- one per function, populated lazily -- for the ObjectFile.
|
|
|
|
// Each Unwind object has multiple UnwindPlans for different scenarios.
|
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2011-01-08 08:05:12 +08:00
|
|
|
UnwindTable::UnwindTable (ObjectFile& objfile) :
|
|
|
|
m_object_file (objfile),
|
|
|
|
m_unwinds (),
|
|
|
|
m_initialized (false),
|
2011-04-12 03:41:40 +08:00
|
|
|
m_assembly_profiler (NULL),
|
|
|
|
m_eh_frame (NULL)
|
2010-09-10 15:49:16 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// We can't do some of this initialization when the ObjectFile is running its ctor; delay doing it
|
|
|
|
// until needed for something.
|
|
|
|
|
|
|
|
void
|
2011-01-08 08:05:12 +08:00
|
|
|
UnwindTable::Initialize ()
|
2010-09-10 15:49:16 +08:00
|
|
|
{
|
|
|
|
if (m_initialized)
|
|
|
|
return;
|
|
|
|
|
|
|
|
SectionList* sl = m_object_file.GetSectionList ();
|
|
|
|
if (sl)
|
|
|
|
{
|
|
|
|
SectionSP sect = sl->FindSectionByType (eSectionTypeEHFrame, true);
|
|
|
|
if (sect.get())
|
|
|
|
{
|
|
|
|
m_eh_frame = new DWARFCallFrameInfo(m_object_file, sect, eRegisterKindGCC, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ArchSpec arch;
|
2011-02-16 05:59:32 +08:00
|
|
|
if (m_object_file.GetArchitecture (arch))
|
|
|
|
{
|
2011-04-26 05:14:26 +08:00
|
|
|
m_assembly_profiler = UnwindAssembly::FindPlugin (arch);
|
2011-02-16 05:59:32 +08:00
|
|
|
m_initialized = true;
|
|
|
|
}
|
2010-09-10 15:49:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
UnwindTable::~UnwindTable ()
|
|
|
|
{
|
|
|
|
if (m_eh_frame)
|
|
|
|
delete m_eh_frame;
|
|
|
|
}
|
|
|
|
|
|
|
|
FuncUnwindersSP
|
|
|
|
UnwindTable::GetFuncUnwindersContainingAddress (const Address& addr, SymbolContext &sc)
|
|
|
|
{
|
|
|
|
FuncUnwindersSP no_unwind_found;
|
|
|
|
|
2011-01-08 08:05:12 +08:00
|
|
|
Initialize();
|
2010-09-10 15:49:16 +08:00
|
|
|
|
2011-01-08 08:05:12 +08:00
|
|
|
// There is an UnwindTable per object file, so we can safely use file handles
|
|
|
|
addr_t file_addr = addr.GetFileAddress();
|
|
|
|
iterator end = m_unwinds.end ();
|
|
|
|
iterator insert_pos = end;
|
|
|
|
if (!m_unwinds.empty())
|
2010-09-10 15:49:16 +08:00
|
|
|
{
|
2011-01-08 08:05:12 +08:00
|
|
|
insert_pos = m_unwinds.lower_bound (file_addr);
|
|
|
|
iterator pos = insert_pos;
|
|
|
|
if ((pos == m_unwinds.end ()) || (pos != m_unwinds.begin() && pos->second->GetFunctionStartAddress() != addr))
|
|
|
|
--pos;
|
|
|
|
|
|
|
|
if (pos->second->ContainsAddress (addr))
|
|
|
|
return pos->second;
|
2010-09-10 15:49:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
AddressRange range;
|
2011-04-23 10:04:55 +08:00
|
|
|
if (!sc.GetAddressRange(eSymbolContextFunction | eSymbolContextSymbol, 0, false, range) || !range.GetBaseAddress().IsValid())
|
2010-09-10 15:49:16 +08:00
|
|
|
{
|
2010-11-04 08:53:20 +08:00
|
|
|
// Does the eh_frame unwind info has a function bounds for this addr?
|
2010-11-09 09:21:22 +08:00
|
|
|
if (m_eh_frame == NULL || !m_eh_frame->GetAddressRange (addr, range))
|
2010-09-10 15:49:16 +08:00
|
|
|
{
|
2010-11-04 08:53:20 +08:00
|
|
|
return no_unwind_found;
|
2010-09-10 15:49:16 +08:00
|
|
|
}
|
|
|
|
}
|
2010-11-04 08:53:20 +08:00
|
|
|
|
2011-01-08 08:05:12 +08:00
|
|
|
FuncUnwindersSP func_unwinder_sp(new FuncUnwinders(*this, m_assembly_profiler, range));
|
|
|
|
m_unwinds.insert (insert_pos, std::make_pair(range.GetBaseAddress().GetFileAddress(), func_unwinder_sp));
|
|
|
|
// StreamFile s(stdout);
|
|
|
|
// Dump (s);
|
|
|
|
return func_unwinder_sp;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UnwindTable::Dump (Stream &s)
|
|
|
|
{
|
|
|
|
s.Printf("UnwindTable for %s/%s:\n", m_object_file.GetFileSpec().GetDirectory().GetCString(), m_object_file.GetFileSpec().GetFilename().GetCString());
|
|
|
|
const_iterator begin = m_unwinds.begin();
|
|
|
|
const_iterator end = m_unwinds.end();
|
|
|
|
for (const_iterator pos = begin; pos != end; ++pos)
|
|
|
|
{
|
2012-03-07 06:24:44 +08:00
|
|
|
s.Printf ("[%u] 0x%16.16llx\n", (unsigned)std::distance (begin, pos), pos->first);
|
2011-01-08 08:05:12 +08:00
|
|
|
}
|
|
|
|
s.EOL();
|
2010-09-10 15:49:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DWARFCallFrameInfo *
|
|
|
|
UnwindTable::GetEHFrameInfo ()
|
|
|
|
{
|
2011-01-08 08:05:12 +08:00
|
|
|
Initialize();
|
2010-09-10 15:49:16 +08:00
|
|
|
return m_eh_frame;
|
|
|
|
}
|