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"
|
2015-09-30 21:50:14 +08:00
|
|
|
#include "lldb/Symbol/ArmUnwindInfo.h"
|
2014-12-08 11:09:00 +08:00
|
|
|
#include "lldb/Symbol/CompactUnwindInfo.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;
|
|
|
|
|
2016-05-19 13:13:57 +08:00
|
|
|
UnwindTable::UnwindTable(ObjectFile &objfile)
|
|
|
|
: m_object_file(objfile),
|
|
|
|
m_unwinds(),
|
|
|
|
m_initialized(false),
|
|
|
|
m_mutex(),
|
|
|
|
m_eh_frame_up(),
|
|
|
|
m_compact_unwind_up(),
|
|
|
|
m_arm_unwind_up()
|
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;
|
|
|
|
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::mutex> guard(m_mutex);
|
2014-06-19 07:32:53 +08:00
|
|
|
|
|
|
|
if (m_initialized) // check again once we've acquired the lock
|
|
|
|
return;
|
|
|
|
|
2010-09-10 15:49:16 +08:00
|
|
|
SectionList* sl = m_object_file.GetSectionList ();
|
|
|
|
if (sl)
|
|
|
|
{
|
|
|
|
SectionSP sect = sl->FindSectionByType (eSectionTypeEHFrame, true);
|
|
|
|
if (sect.get())
|
|
|
|
{
|
2015-09-30 21:50:14 +08:00
|
|
|
m_eh_frame_up.reset(new DWARFCallFrameInfo(m_object_file, sect, eRegisterKindEHFrame, true));
|
2010-09-10 15:49:16 +08:00
|
|
|
}
|
2014-12-08 11:09:00 +08:00
|
|
|
sect = sl->FindSectionByType (eSectionTypeCompactUnwind, true);
|
|
|
|
if (sect.get())
|
|
|
|
{
|
2015-09-30 21:50:14 +08:00
|
|
|
m_compact_unwind_up.reset(new CompactUnwindInfo(m_object_file, sect));
|
|
|
|
}
|
|
|
|
sect = sl->FindSectionByType (eSectionTypeARMexidx, true);
|
|
|
|
if (sect.get())
|
|
|
|
{
|
|
|
|
SectionSP sect_extab = sl->FindSectionByType (eSectionTypeARMextab, true);
|
|
|
|
if (sect_extab.get())
|
|
|
|
{
|
|
|
|
m_arm_unwind_up.reset(new ArmUnwindInfo(m_object_file, sect, sect_extab));
|
|
|
|
}
|
2014-12-08 11:09:00 +08:00
|
|
|
}
|
2010-09-10 15:49:16 +08:00
|
|
|
}
|
|
|
|
|
2014-05-23 09:48:10 +08:00
|
|
|
m_initialized = true;
|
2010-09-10 15:49:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
UnwindTable::~UnwindTable ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::mutex> guard(m_mutex);
|
2014-06-19 07:32:53 +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?
|
2015-09-30 21:50:14 +08:00
|
|
|
if (m_eh_frame_up == nullptr || !m_eh_frame_up->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
|
|
|
|
2014-05-23 09:48:10 +08:00
|
|
|
FuncUnwindersSP func_unwinder_sp(new FuncUnwinders(*this, range));
|
2011-01-08 08:05:12 +08:00
|
|
|
m_unwinds.insert (insert_pos, std::make_pair(range.GetBaseAddress().GetFileAddress(), func_unwinder_sp));
|
2013-10-10 08:16:10 +08:00
|
|
|
// StreamFile s(stdout, false);
|
2011-01-08 08:05:12 +08:00
|
|
|
// Dump (s);
|
|
|
|
return func_unwinder_sp;
|
|
|
|
}
|
|
|
|
|
2012-07-12 08:20:07 +08:00
|
|
|
// Ignore any existing FuncUnwinders for this function, create a new one and don't add it to the
|
|
|
|
// UnwindTable. This is intended for use by target modules show-unwind where we want to create
|
|
|
|
// new UnwindPlans, not re-use existing ones.
|
|
|
|
|
|
|
|
FuncUnwindersSP
|
|
|
|
UnwindTable::GetUncachedFuncUnwindersContainingAddress (const Address& addr, SymbolContext &sc)
|
|
|
|
{
|
|
|
|
FuncUnwindersSP no_unwind_found;
|
|
|
|
Initialize();
|
|
|
|
|
|
|
|
AddressRange range;
|
|
|
|
if (!sc.GetAddressRange(eSymbolContextFunction | eSymbolContextSymbol, 0, false, range) || !range.GetBaseAddress().IsValid())
|
|
|
|
{
|
|
|
|
// Does the eh_frame unwind info has a function bounds for this addr?
|
2015-09-30 21:50:14 +08:00
|
|
|
if (m_eh_frame_up == nullptr || !m_eh_frame_up->GetAddressRange (addr, range))
|
2012-07-12 08:20:07 +08:00
|
|
|
{
|
|
|
|
return no_unwind_found;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-23 09:48:10 +08:00
|
|
|
FuncUnwindersSP func_unwinder_sp(new FuncUnwinders(*this, range));
|
2012-07-12 08:20:07 +08:00
|
|
|
return func_unwinder_sp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-08 08:05:12 +08:00
|
|
|
void
|
|
|
|
UnwindTable::Dump (Stream &s)
|
|
|
|
{
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::mutex> guard(m_mutex);
|
2013-04-30 01:25:54 +08:00
|
|
|
s.Printf("UnwindTable for '%s':\n", m_object_file.GetFileSpec().GetPath().c_str());
|
2011-01-08 08:05:12 +08:00
|
|
|
const_iterator begin = m_unwinds.begin();
|
|
|
|
const_iterator end = m_unwinds.end();
|
|
|
|
for (const_iterator pos = begin; pos != end; ++pos)
|
|
|
|
{
|
2012-11-30 05:49:15 +08:00
|
|
|
s.Printf ("[%u] 0x%16.16" PRIx64 "\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();
|
2015-09-30 21:50:14 +08:00
|
|
|
return m_eh_frame_up.get();
|
2010-09-10 15:49:16 +08:00
|
|
|
}
|
2014-05-23 09:48:10 +08:00
|
|
|
|
2014-12-08 11:09:00 +08:00
|
|
|
CompactUnwindInfo *
|
|
|
|
UnwindTable::GetCompactUnwindInfo ()
|
|
|
|
{
|
|
|
|
Initialize();
|
2015-09-30 21:50:14 +08:00
|
|
|
return m_compact_unwind_up.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
ArmUnwindInfo *
|
|
|
|
UnwindTable::GetArmUnwindInfo ()
|
|
|
|
{
|
|
|
|
Initialize();
|
|
|
|
return m_arm_unwind_up.get();
|
2014-12-08 11:09:00 +08:00
|
|
|
}
|
|
|
|
|
2014-05-23 09:48:10 +08:00
|
|
|
bool
|
|
|
|
UnwindTable::GetArchitecture (lldb_private::ArchSpec &arch)
|
|
|
|
{
|
|
|
|
return m_object_file.GetArchitecture (arch);
|
|
|
|
}
|
2016-05-04 11:09:40 +08:00
|
|
|
|
|
|
|
bool
|
|
|
|
UnwindTable::GetAllowAssemblyEmulationUnwindPlans ()
|
|
|
|
{
|
|
|
|
return m_object_file.AllowAssemblyEmulationUnwindPlans ();
|
|
|
|
}
|