2010-09-10 15:49:16 +08:00
|
|
|
//===-- FuncUnwinders.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/Symbol/FuncUnwinders.h"
|
2016-09-07 04:57:50 +08:00
|
|
|
#include "lldb/Core/Address.h"
|
|
|
|
#include "lldb/Core/AddressRange.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"
|
2016-09-07 04:57:50 +08:00
|
|
|
#include "lldb/Symbol/DWARFCallFrameInfo.h"
|
2010-09-10 15:49:16 +08:00
|
|
|
#include "lldb/Symbol/ObjectFile.h"
|
|
|
|
#include "lldb/Symbol/UnwindPlan.h"
|
|
|
|
#include "lldb/Symbol/UnwindTable.h"
|
2011-05-12 02:39:18 +08:00
|
|
|
#include "lldb/Target/ABI.h"
|
2012-02-21 08:09:25 +08:00
|
|
|
#include "lldb/Target/ExecutionContext.h"
|
2011-05-12 02:39:18 +08:00
|
|
|
#include "lldb/Target/Process.h"
|
2017-02-15 03:06:07 +08:00
|
|
|
#include "lldb/Target/RegisterNumber.h"
|
2010-09-10 15:49:16 +08:00
|
|
|
#include "lldb/Target/Target.h"
|
2016-09-07 04:57:50 +08:00
|
|
|
#include "lldb/Target/Thread.h"
|
2011-04-26 05:14:26 +08:00
|
|
|
#include "lldb/Target/UnwindAssembly.h"
|
2010-09-10 15:49:16 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2014-12-21 18:44:54 +08:00
|
|
|
//------------------------------------------------
|
|
|
|
/// constructor
|
|
|
|
//------------------------------------------------
|
2010-09-10 15:49:16 +08:00
|
|
|
|
2016-05-18 09:59:10 +08:00
|
|
|
FuncUnwinders::FuncUnwinders(UnwindTable &unwind_table, AddressRange range)
|
2016-09-07 04:57:50 +08:00
|
|
|
: m_unwind_table(unwind_table), m_range(range), m_mutex(),
|
|
|
|
m_unwind_plan_assembly_sp(), m_unwind_plan_eh_frame_sp(),
|
|
|
|
m_unwind_plan_eh_frame_augmented_sp(), m_unwind_plan_compact_unwind(),
|
|
|
|
m_unwind_plan_arm_unwind_sp(), m_unwind_plan_fast_sp(),
|
2016-05-18 09:59:10 +08:00
|
|
|
m_unwind_plan_arch_default_sp(),
|
|
|
|
m_unwind_plan_arch_default_at_func_entry_sp(),
|
2016-09-07 04:57:50 +08:00
|
|
|
m_tried_unwind_plan_assembly(false), m_tried_unwind_plan_eh_frame(false),
|
Add debug_frame section support
Summary:
This is a beefed-up version of D33504, which adds support for dwarf 4
debug_frame section format.
The main difference here is that the decision whether to use eh_frame or
debug_frame is done on a per-function basis instead of per-object file.
This is necessary because one module can contain both sections (for
example, the start files added by the linker will typically pull in
eh_frame), but we want to be able to access both, for maximum
information.
I also add unit test for parsing various CFI formats (eh_frame,
debug_frame v3 and debug_frame v4).
Reviewers: jasonmolenda, clayborg
Subscribers: mgorny, aprantl, abidh, lldb-commits, tatyana-krasnukha
Differential Revision: https://reviews.llvm.org/D34613
llvm-svn: 306397
2017-06-27 19:16:26 +08:00
|
|
|
m_tried_unwind_plan_debug_frame(false),
|
2016-05-18 09:59:10 +08:00
|
|
|
m_tried_unwind_plan_eh_frame_augmented(false),
|
Add debug_frame section support
Summary:
This is a beefed-up version of D33504, which adds support for dwarf 4
debug_frame section format.
The main difference here is that the decision whether to use eh_frame or
debug_frame is done on a per-function basis instead of per-object file.
This is necessary because one module can contain both sections (for
example, the start files added by the linker will typically pull in
eh_frame), but we want to be able to access both, for maximum
information.
I also add unit test for parsing various CFI formats (eh_frame,
debug_frame v3 and debug_frame v4).
Reviewers: jasonmolenda, clayborg
Subscribers: mgorny, aprantl, abidh, lldb-commits, tatyana-krasnukha
Differential Revision: https://reviews.llvm.org/D34613
llvm-svn: 306397
2017-06-27 19:16:26 +08:00
|
|
|
m_tried_unwind_plan_debug_frame_augmented(false),
|
2016-05-18 09:59:10 +08:00
|
|
|
m_tried_unwind_plan_compact_unwind(false),
|
2016-09-07 04:57:50 +08:00
|
|
|
m_tried_unwind_plan_arm_unwind(false), m_tried_unwind_fast(false),
|
2016-05-18 09:59:10 +08:00
|
|
|
m_tried_unwind_arch_default(false),
|
|
|
|
m_tried_unwind_arch_default_at_func_entry(false),
|
2016-09-07 04:57:50 +08:00
|
|
|
m_first_non_prologue_insn() {}
|
2010-09-10 15:49:16 +08:00
|
|
|
|
2014-12-21 18:44:54 +08:00
|
|
|
//------------------------------------------------
|
|
|
|
/// destructor
|
|
|
|
//------------------------------------------------
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
FuncUnwinders::~FuncUnwinders() {}
|
2010-09-10 15:49:16 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
UnwindPlanSP FuncUnwinders::GetUnwindPlanAtCallSite(Target &target,
|
|
|
|
int current_offset) {
|
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2014-12-21 18:44:54 +08:00
|
|
|
|
Add debug_frame section support
Summary:
This is a beefed-up version of D33504, which adds support for dwarf 4
debug_frame section format.
The main difference here is that the decision whether to use eh_frame or
debug_frame is done on a per-function basis instead of per-object file.
This is necessary because one module can contain both sections (for
example, the start files added by the linker will typically pull in
eh_frame), but we want to be able to access both, for maximum
information.
I also add unit test for parsing various CFI formats (eh_frame,
debug_frame v3 and debug_frame v4).
Reviewers: jasonmolenda, clayborg
Subscribers: mgorny, aprantl, abidh, lldb-commits, tatyana-krasnukha
Differential Revision: https://reviews.llvm.org/D34613
llvm-svn: 306397
2017-06-27 19:16:26 +08:00
|
|
|
if (UnwindPlanSP plan_sp = GetEHFrameUnwindPlan(target, current_offset))
|
|
|
|
return plan_sp;
|
|
|
|
if (UnwindPlanSP plan_sp = GetDebugFrameUnwindPlan(target, current_offset))
|
|
|
|
return plan_sp;
|
|
|
|
if (UnwindPlanSP plan_sp = GetCompactUnwindUnwindPlan(target, current_offset))
|
|
|
|
return plan_sp;
|
|
|
|
if (UnwindPlanSP plan_sp = GetArmUnwindUnwindPlan(target, current_offset))
|
|
|
|
return plan_sp;
|
2015-09-30 21:50:14 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
return nullptr;
|
2014-12-21 18:44:54 +08:00
|
|
|
}
|
2011-01-08 08:05:12 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
UnwindPlanSP FuncUnwinders::GetCompactUnwindUnwindPlan(Target &target,
|
|
|
|
int current_offset) {
|
2017-02-24 11:35:46 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2016-09-07 04:57:50 +08:00
|
|
|
if (m_unwind_plan_compact_unwind.size() > 0)
|
|
|
|
return m_unwind_plan_compact_unwind[0]; // FIXME support multiple compact
|
|
|
|
// unwind plans for one func
|
|
|
|
if (m_tried_unwind_plan_compact_unwind)
|
2014-12-21 18:44:54 +08:00
|
|
|
return UnwindPlanSP();
|
2010-09-10 15:49:16 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
m_tried_unwind_plan_compact_unwind = true;
|
|
|
|
if (m_range.GetBaseAddress().IsValid()) {
|
|
|
|
Address current_pc(m_range.GetBaseAddress());
|
|
|
|
if (current_offset != -1)
|
|
|
|
current_pc.SetOffset(current_pc.GetOffset() + current_offset);
|
|
|
|
CompactUnwindInfo *compact_unwind = m_unwind_table.GetCompactUnwindInfo();
|
|
|
|
if (compact_unwind) {
|
|
|
|
UnwindPlanSP unwind_plan_sp(new UnwindPlan(lldb::eRegisterKindGeneric));
|
|
|
|
if (compact_unwind->GetUnwindPlan(target, current_pc, *unwind_plan_sp)) {
|
|
|
|
m_unwind_plan_compact_unwind.push_back(unwind_plan_sp);
|
|
|
|
return m_unwind_plan_compact_unwind[0]; // FIXME support multiple
|
|
|
|
// compact unwind plans for one
|
|
|
|
// func
|
|
|
|
}
|
2014-12-21 18:44:54 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
return UnwindPlanSP();
|
2014-12-21 18:44:54 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
UnwindPlanSP FuncUnwinders::GetEHFrameUnwindPlan(Target &target,
|
|
|
|
int current_offset) {
|
2017-02-24 11:35:46 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2016-09-07 04:57:50 +08:00
|
|
|
if (m_unwind_plan_eh_frame_sp.get() || m_tried_unwind_plan_eh_frame)
|
|
|
|
return m_unwind_plan_eh_frame_sp;
|
|
|
|
|
|
|
|
m_tried_unwind_plan_eh_frame = true;
|
|
|
|
if (m_range.GetBaseAddress().IsValid()) {
|
|
|
|
Address current_pc(m_range.GetBaseAddress());
|
|
|
|
if (current_offset != -1)
|
|
|
|
current_pc.SetOffset(current_pc.GetOffset() + current_offset);
|
|
|
|
DWARFCallFrameInfo *eh_frame = m_unwind_table.GetEHFrameInfo();
|
|
|
|
if (eh_frame) {
|
|
|
|
m_unwind_plan_eh_frame_sp.reset(
|
|
|
|
new UnwindPlan(lldb::eRegisterKindGeneric));
|
|
|
|
if (!eh_frame->GetUnwindPlan(current_pc, *m_unwind_plan_eh_frame_sp))
|
|
|
|
m_unwind_plan_eh_frame_sp.reset();
|
2015-09-30 21:50:14 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
return m_unwind_plan_eh_frame_sp;
|
2015-09-30 21:50:14 +08:00
|
|
|
}
|
|
|
|
|
Add debug_frame section support
Summary:
This is a beefed-up version of D33504, which adds support for dwarf 4
debug_frame section format.
The main difference here is that the decision whether to use eh_frame or
debug_frame is done on a per-function basis instead of per-object file.
This is necessary because one module can contain both sections (for
example, the start files added by the linker will typically pull in
eh_frame), but we want to be able to access both, for maximum
information.
I also add unit test for parsing various CFI formats (eh_frame,
debug_frame v3 and debug_frame v4).
Reviewers: jasonmolenda, clayborg
Subscribers: mgorny, aprantl, abidh, lldb-commits, tatyana-krasnukha
Differential Revision: https://reviews.llvm.org/D34613
llvm-svn: 306397
2017-06-27 19:16:26 +08:00
|
|
|
UnwindPlanSP FuncUnwinders::GetDebugFrameUnwindPlan(Target &target,
|
|
|
|
int current_offset) {
|
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
|
|
|
if (m_unwind_plan_debug_frame_sp || m_tried_unwind_plan_debug_frame)
|
|
|
|
return m_unwind_plan_debug_frame_sp;
|
|
|
|
|
|
|
|
m_tried_unwind_plan_debug_frame = true;
|
|
|
|
if (m_range.GetBaseAddress().IsValid()) {
|
|
|
|
Address current_pc(m_range.GetBaseAddress());
|
|
|
|
if (current_offset != -1)
|
|
|
|
current_pc.SetOffset(current_pc.GetOffset() + current_offset);
|
|
|
|
DWARFCallFrameInfo *debug_frame = m_unwind_table.GetDebugFrameInfo();
|
|
|
|
if (debug_frame) {
|
|
|
|
m_unwind_plan_debug_frame_sp.reset(
|
|
|
|
new UnwindPlan(lldb::eRegisterKindGeneric));
|
|
|
|
if (!debug_frame->GetUnwindPlan(current_pc,
|
|
|
|
*m_unwind_plan_debug_frame_sp))
|
|
|
|
m_unwind_plan_debug_frame_sp.reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return m_unwind_plan_debug_frame_sp;
|
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
UnwindPlanSP FuncUnwinders::GetArmUnwindUnwindPlan(Target &target,
|
|
|
|
int current_offset) {
|
2017-02-24 11:35:46 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2016-09-07 04:57:50 +08:00
|
|
|
if (m_unwind_plan_arm_unwind_sp.get() || m_tried_unwind_plan_arm_unwind)
|
|
|
|
return m_unwind_plan_arm_unwind_sp;
|
|
|
|
|
|
|
|
m_tried_unwind_plan_arm_unwind = true;
|
|
|
|
if (m_range.GetBaseAddress().IsValid()) {
|
|
|
|
Address current_pc(m_range.GetBaseAddress());
|
|
|
|
if (current_offset != -1)
|
|
|
|
current_pc.SetOffset(current_pc.GetOffset() + current_offset);
|
|
|
|
ArmUnwindInfo *arm_unwind_info = m_unwind_table.GetArmUnwindInfo();
|
|
|
|
if (arm_unwind_info) {
|
|
|
|
m_unwind_plan_arm_unwind_sp.reset(
|
|
|
|
new UnwindPlan(lldb::eRegisterKindGeneric));
|
|
|
|
if (!arm_unwind_info->GetUnwindPlan(target, current_pc,
|
|
|
|
*m_unwind_plan_arm_unwind_sp))
|
|
|
|
m_unwind_plan_arm_unwind_sp.reset();
|
2014-12-21 18:44:54 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
return m_unwind_plan_arm_unwind_sp;
|
|
|
|
}
|
|
|
|
|
|
|
|
UnwindPlanSP FuncUnwinders::GetEHFrameAugmentedUnwindPlan(Target &target,
|
|
|
|
Thread &thread,
|
|
|
|
int current_offset) {
|
2017-02-24 11:35:46 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2016-09-07 04:57:50 +08:00
|
|
|
if (m_unwind_plan_eh_frame_augmented_sp.get() ||
|
|
|
|
m_tried_unwind_plan_eh_frame_augmented)
|
|
|
|
return m_unwind_plan_eh_frame_augmented_sp;
|
2014-12-21 18:44:54 +08:00
|
|
|
|
2018-05-01 00:49:04 +08:00
|
|
|
// Only supported on x86 architectures where we get eh_frame from the
|
|
|
|
// compiler that describes the prologue instructions perfectly, and sometimes
|
|
|
|
// the epilogue instructions too.
|
2016-09-07 04:57:50 +08:00
|
|
|
if (target.GetArchitecture().GetCore() != ArchSpec::eCore_x86_32_i386 &&
|
|
|
|
target.GetArchitecture().GetCore() != ArchSpec::eCore_x86_64_x86_64 &&
|
|
|
|
target.GetArchitecture().GetCore() != ArchSpec::eCore_x86_64_x86_64h) {
|
2014-12-21 18:44:54 +08:00
|
|
|
m_tried_unwind_plan_eh_frame_augmented = true;
|
2016-09-07 04:57:50 +08:00
|
|
|
return m_unwind_plan_eh_frame_augmented_sp;
|
|
|
|
}
|
2014-12-21 18:44:54 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
m_tried_unwind_plan_eh_frame_augmented = true;
|
2015-05-06 23:54:48 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
UnwindPlanSP eh_frame_plan = GetEHFrameUnwindPlan(target, current_offset);
|
|
|
|
if (!eh_frame_plan)
|
|
|
|
return m_unwind_plan_eh_frame_augmented_sp;
|
2015-05-06 23:54:48 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
m_unwind_plan_eh_frame_augmented_sp.reset(new UnwindPlan(*eh_frame_plan));
|
2015-05-06 23:54:48 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
// Augment the eh_frame instructions with epilogue descriptions if necessary
|
2018-05-01 00:49:04 +08:00
|
|
|
// so the UnwindPlan can be used at any instruction in the function.
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
|
|
UnwindAssemblySP assembly_profiler_sp(GetUnwindAssemblyProfiler(target));
|
|
|
|
if (assembly_profiler_sp) {
|
|
|
|
if (!assembly_profiler_sp->AugmentUnwindPlanFromCallSite(
|
|
|
|
m_range, thread, *m_unwind_plan_eh_frame_augmented_sp)) {
|
|
|
|
m_unwind_plan_eh_frame_augmented_sp.reset();
|
2015-05-06 23:54:48 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
|
|
|
m_unwind_plan_eh_frame_augmented_sp.reset();
|
|
|
|
}
|
|
|
|
return m_unwind_plan_eh_frame_augmented_sp;
|
2014-12-21 18:44:54 +08:00
|
|
|
}
|
2014-08-26 04:29:09 +08:00
|
|
|
|
Add debug_frame section support
Summary:
This is a beefed-up version of D33504, which adds support for dwarf 4
debug_frame section format.
The main difference here is that the decision whether to use eh_frame or
debug_frame is done on a per-function basis instead of per-object file.
This is necessary because one module can contain both sections (for
example, the start files added by the linker will typically pull in
eh_frame), but we want to be able to access both, for maximum
information.
I also add unit test for parsing various CFI formats (eh_frame,
debug_frame v3 and debug_frame v4).
Reviewers: jasonmolenda, clayborg
Subscribers: mgorny, aprantl, abidh, lldb-commits, tatyana-krasnukha
Differential Revision: https://reviews.llvm.org/D34613
llvm-svn: 306397
2017-06-27 19:16:26 +08:00
|
|
|
UnwindPlanSP
|
|
|
|
FuncUnwinders::GetDebugFrameAugmentedUnwindPlan(Target &target, Thread &thread,
|
|
|
|
int current_offset) {
|
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
|
|
|
if (m_unwind_plan_debug_frame_augmented_sp.get() ||
|
|
|
|
m_tried_unwind_plan_debug_frame_augmented)
|
|
|
|
return m_unwind_plan_debug_frame_augmented_sp;
|
|
|
|
|
|
|
|
// Only supported on x86 architectures where we get debug_frame from the
|
|
|
|
// compiler that describes the prologue instructions perfectly, and sometimes
|
|
|
|
// the epilogue instructions too.
|
|
|
|
if (target.GetArchitecture().GetCore() != ArchSpec::eCore_x86_32_i386 &&
|
|
|
|
target.GetArchitecture().GetCore() != ArchSpec::eCore_x86_64_x86_64 &&
|
|
|
|
target.GetArchitecture().GetCore() != ArchSpec::eCore_x86_64_x86_64h) {
|
|
|
|
m_tried_unwind_plan_debug_frame_augmented = true;
|
|
|
|
return m_unwind_plan_debug_frame_augmented_sp;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_tried_unwind_plan_debug_frame_augmented = true;
|
|
|
|
|
|
|
|
UnwindPlanSP debug_frame_plan =
|
|
|
|
GetDebugFrameUnwindPlan(target, current_offset);
|
|
|
|
if (!debug_frame_plan)
|
|
|
|
return m_unwind_plan_debug_frame_augmented_sp;
|
|
|
|
|
|
|
|
m_unwind_plan_debug_frame_augmented_sp.reset(
|
|
|
|
new UnwindPlan(*debug_frame_plan));
|
|
|
|
|
|
|
|
// Augment the debug_frame instructions with epilogue descriptions if
|
2018-05-01 00:49:04 +08:00
|
|
|
// necessary so the UnwindPlan can be used at any instruction in the
|
|
|
|
// function.
|
Add debug_frame section support
Summary:
This is a beefed-up version of D33504, which adds support for dwarf 4
debug_frame section format.
The main difference here is that the decision whether to use eh_frame or
debug_frame is done on a per-function basis instead of per-object file.
This is necessary because one module can contain both sections (for
example, the start files added by the linker will typically pull in
eh_frame), but we want to be able to access both, for maximum
information.
I also add unit test for parsing various CFI formats (eh_frame,
debug_frame v3 and debug_frame v4).
Reviewers: jasonmolenda, clayborg
Subscribers: mgorny, aprantl, abidh, lldb-commits, tatyana-krasnukha
Differential Revision: https://reviews.llvm.org/D34613
llvm-svn: 306397
2017-06-27 19:16:26 +08:00
|
|
|
|
|
|
|
UnwindAssemblySP assembly_profiler_sp(GetUnwindAssemblyProfiler(target));
|
|
|
|
if (assembly_profiler_sp) {
|
|
|
|
if (!assembly_profiler_sp->AugmentUnwindPlanFromCallSite(
|
|
|
|
m_range, thread, *m_unwind_plan_debug_frame_augmented_sp)) {
|
|
|
|
m_unwind_plan_debug_frame_augmented_sp.reset();
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
m_unwind_plan_debug_frame_augmented_sp.reset();
|
|
|
|
return m_unwind_plan_debug_frame_augmented_sp;
|
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
UnwindPlanSP FuncUnwinders::GetAssemblyUnwindPlan(Target &target,
|
|
|
|
Thread &thread,
|
|
|
|
int current_offset) {
|
2017-02-24 11:35:46 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2016-09-07 04:57:50 +08:00
|
|
|
if (m_unwind_plan_assembly_sp.get() || m_tried_unwind_plan_assembly ||
|
|
|
|
m_unwind_table.GetAllowAssemblyEmulationUnwindPlans() == false) {
|
|
|
|
return m_unwind_plan_assembly_sp;
|
|
|
|
}
|
2014-12-21 18:44:54 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
m_tried_unwind_plan_assembly = true;
|
2014-12-21 18:44:54 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
UnwindAssemblySP assembly_profiler_sp(GetUnwindAssemblyProfiler(target));
|
|
|
|
if (assembly_profiler_sp) {
|
|
|
|
m_unwind_plan_assembly_sp.reset(new UnwindPlan(lldb::eRegisterKindGeneric));
|
|
|
|
if (!assembly_profiler_sp->GetNonCallSiteUnwindPlanFromAssembly(
|
|
|
|
m_range, thread, *m_unwind_plan_assembly_sp)) {
|
|
|
|
m_unwind_plan_assembly_sp.reset();
|
2010-10-25 19:12:07 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
return m_unwind_plan_assembly_sp;
|
2014-12-21 18:44:54 +08:00
|
|
|
}
|
|
|
|
|
2016-07-07 07:06:19 +08:00
|
|
|
// This method compares the pc unwind rule in the first row of two UnwindPlans.
|
2016-09-07 04:57:50 +08:00
|
|
|
// If they have the same way of getting the pc value (e.g. "CFA - 8" + "CFA is
|
2018-05-01 00:49:04 +08:00
|
|
|
// sp"), then it will return LazyBoolTrue.
|
2016-09-07 04:57:50 +08:00
|
|
|
LazyBool FuncUnwinders::CompareUnwindPlansForIdenticalInitialPCLocation(
|
|
|
|
Thread &thread, const UnwindPlanSP &a, const UnwindPlanSP &b) {
|
|
|
|
LazyBool plans_are_identical = eLazyBoolCalculate;
|
2014-12-21 18:44:54 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
RegisterNumber pc_reg(thread, eRegisterKindGeneric, LLDB_REGNUM_GENERIC_PC);
|
|
|
|
uint32_t pc_reg_lldb_regnum = pc_reg.GetAsKind(eRegisterKindLLDB);
|
|
|
|
|
|
|
|
if (a.get() && b.get()) {
|
|
|
|
UnwindPlan::RowSP a_first_row = a->GetRowAtIndex(0);
|
|
|
|
UnwindPlan::RowSP b_first_row = b->GetRowAtIndex(0);
|
|
|
|
|
|
|
|
if (a_first_row.get() && b_first_row.get()) {
|
|
|
|
UnwindPlan::Row::RegisterLocation a_pc_regloc;
|
|
|
|
UnwindPlan::Row::RegisterLocation b_pc_regloc;
|
|
|
|
|
|
|
|
a_first_row->GetRegisterInfo(pc_reg_lldb_regnum, a_pc_regloc);
|
|
|
|
b_first_row->GetRegisterInfo(pc_reg_lldb_regnum, b_pc_regloc);
|
2016-07-07 07:06:19 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
plans_are_identical = eLazyBoolYes;
|
|
|
|
|
|
|
|
if (a_first_row->GetCFAValue() != b_first_row->GetCFAValue()) {
|
|
|
|
plans_are_identical = eLazyBoolNo;
|
|
|
|
}
|
|
|
|
if (a_pc_regloc != b_pc_regloc) {
|
|
|
|
plans_are_identical = eLazyBoolNo;
|
|
|
|
}
|
2016-07-07 07:06:19 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
return plans_are_identical;
|
|
|
|
}
|
2016-07-07 07:06:19 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
UnwindPlanSP FuncUnwinders::GetUnwindPlanAtNonCallSite(Target &target,
|
|
|
|
Thread &thread,
|
|
|
|
int current_offset) {
|
|
|
|
UnwindPlanSP eh_frame_sp = GetEHFrameUnwindPlan(target, current_offset);
|
Add debug_frame section support
Summary:
This is a beefed-up version of D33504, which adds support for dwarf 4
debug_frame section format.
The main difference here is that the decision whether to use eh_frame or
debug_frame is done on a per-function basis instead of per-object file.
This is necessary because one module can contain both sections (for
example, the start files added by the linker will typically pull in
eh_frame), but we want to be able to access both, for maximum
information.
I also add unit test for parsing various CFI formats (eh_frame,
debug_frame v3 and debug_frame v4).
Reviewers: jasonmolenda, clayborg
Subscribers: mgorny, aprantl, abidh, lldb-commits, tatyana-krasnukha
Differential Revision: https://reviews.llvm.org/D34613
llvm-svn: 306397
2017-06-27 19:16:26 +08:00
|
|
|
if (!eh_frame_sp)
|
|
|
|
eh_frame_sp = GetDebugFrameUnwindPlan(target, current_offset);
|
2016-09-07 04:57:50 +08:00
|
|
|
UnwindPlanSP arch_default_at_entry_sp =
|
|
|
|
GetUnwindPlanArchitectureDefaultAtFunctionEntry(thread);
|
|
|
|
UnwindPlanSP arch_default_sp = GetUnwindPlanArchitectureDefault(thread);
|
|
|
|
UnwindPlanSP assembly_sp =
|
|
|
|
GetAssemblyUnwindPlan(target, thread, current_offset);
|
|
|
|
|
2018-05-01 00:49:04 +08:00
|
|
|
// This point of this code is to detect when a function is using a non-
|
|
|
|
// standard ABI, and the eh_frame correctly describes that alternate ABI.
|
Add debug_frame section support
Summary:
This is a beefed-up version of D33504, which adds support for dwarf 4
debug_frame section format.
The main difference here is that the decision whether to use eh_frame or
debug_frame is done on a per-function basis instead of per-object file.
This is necessary because one module can contain both sections (for
example, the start files added by the linker will typically pull in
eh_frame), but we want to be able to access both, for maximum
information.
I also add unit test for parsing various CFI formats (eh_frame,
debug_frame v3 and debug_frame v4).
Reviewers: jasonmolenda, clayborg
Subscribers: mgorny, aprantl, abidh, lldb-commits, tatyana-krasnukha
Differential Revision: https://reviews.llvm.org/D34613
llvm-svn: 306397
2017-06-27 19:16:26 +08:00
|
|
|
// This is addressing a specific situation on x86_64 linux systems where one
|
|
|
|
// function in a library pushes a value on the stack and jumps to another
|
2018-05-01 00:49:04 +08:00
|
|
|
// function. So using an assembly instruction based unwind will not work
|
|
|
|
// when you're in the second function - the stack has been modified in a non-
|
|
|
|
// ABI way. But we have eh_frame that correctly describes how to unwind from
|
|
|
|
// this location. So we're looking to see if the initial pc register save
|
|
|
|
// location from the eh_frame is different from the assembly unwind, the arch
|
|
|
|
// default unwind, and the arch default at initial function entry.
|
2016-09-07 04:57:50 +08:00
|
|
|
//
|
|
|
|
// We may have eh_frame that describes the entire function -- or we may have
|
Add debug_frame section support
Summary:
This is a beefed-up version of D33504, which adds support for dwarf 4
debug_frame section format.
The main difference here is that the decision whether to use eh_frame or
debug_frame is done on a per-function basis instead of per-object file.
This is necessary because one module can contain both sections (for
example, the start files added by the linker will typically pull in
eh_frame), but we want to be able to access both, for maximum
information.
I also add unit test for parsing various CFI formats (eh_frame,
debug_frame v3 and debug_frame v4).
Reviewers: jasonmolenda, clayborg
Subscribers: mgorny, aprantl, abidh, lldb-commits, tatyana-krasnukha
Differential Revision: https://reviews.llvm.org/D34613
llvm-svn: 306397
2017-06-27 19:16:26 +08:00
|
|
|
// eh_frame that only describes the unwind after the prologue has executed --
|
|
|
|
// so we need to check both the arch default (once the prologue has executed)
|
2018-05-01 00:49:04 +08:00
|
|
|
// and the arch default at initial function entry. And we may be running on
|
|
|
|
// a target where we have only some of the assembly/arch default unwind plans
|
Add debug_frame section support
Summary:
This is a beefed-up version of D33504, which adds support for dwarf 4
debug_frame section format.
The main difference here is that the decision whether to use eh_frame or
debug_frame is done on a per-function basis instead of per-object file.
This is necessary because one module can contain both sections (for
example, the start files added by the linker will typically pull in
eh_frame), but we want to be able to access both, for maximum
information.
I also add unit test for parsing various CFI formats (eh_frame,
debug_frame v3 and debug_frame v4).
Reviewers: jasonmolenda, clayborg
Subscribers: mgorny, aprantl, abidh, lldb-commits, tatyana-krasnukha
Differential Revision: https://reviews.llvm.org/D34613
llvm-svn: 306397
2017-06-27 19:16:26 +08:00
|
|
|
// available.
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
|
|
if (CompareUnwindPlansForIdenticalInitialPCLocation(
|
|
|
|
thread, eh_frame_sp, arch_default_at_entry_sp) == eLazyBoolNo &&
|
|
|
|
CompareUnwindPlansForIdenticalInitialPCLocation(
|
|
|
|
thread, eh_frame_sp, arch_default_sp) == eLazyBoolNo &&
|
|
|
|
CompareUnwindPlansForIdenticalInitialPCLocation(
|
|
|
|
thread, assembly_sp, arch_default_sp) == eLazyBoolNo) {
|
|
|
|
return eh_frame_sp;
|
|
|
|
}
|
|
|
|
|
Add debug_frame section support
Summary:
This is a beefed-up version of D33504, which adds support for dwarf 4
debug_frame section format.
The main difference here is that the decision whether to use eh_frame or
debug_frame is done on a per-function basis instead of per-object file.
This is necessary because one module can contain both sections (for
example, the start files added by the linker will typically pull in
eh_frame), but we want to be able to access both, for maximum
information.
I also add unit test for parsing various CFI formats (eh_frame,
debug_frame v3 and debug_frame v4).
Reviewers: jasonmolenda, clayborg
Subscribers: mgorny, aprantl, abidh, lldb-commits, tatyana-krasnukha
Differential Revision: https://reviews.llvm.org/D34613
llvm-svn: 306397
2017-06-27 19:16:26 +08:00
|
|
|
if (UnwindPlanSP plan_sp =
|
|
|
|
GetEHFrameAugmentedUnwindPlan(target, thread, current_offset))
|
|
|
|
return plan_sp;
|
|
|
|
if (UnwindPlanSP plan_sp =
|
|
|
|
GetDebugFrameAugmentedUnwindPlan(target, thread, current_offset))
|
|
|
|
return plan_sp;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
|
|
return assembly_sp;
|
2010-09-10 15:49:16 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
UnwindPlanSP FuncUnwinders::GetUnwindPlanFastUnwind(Target &target,
|
|
|
|
Thread &thread) {
|
2017-02-24 11:35:46 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2016-09-07 04:57:50 +08:00
|
|
|
if (m_unwind_plan_fast_sp.get() || m_tried_unwind_fast)
|
2011-02-15 08:19:15 +08:00
|
|
|
return m_unwind_plan_fast_sp;
|
2010-09-10 15:49:16 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
m_tried_unwind_fast = true;
|
|
|
|
|
|
|
|
UnwindAssemblySP assembly_profiler_sp(GetUnwindAssemblyProfiler(target));
|
|
|
|
if (assembly_profiler_sp) {
|
|
|
|
m_unwind_plan_fast_sp.reset(new UnwindPlan(lldb::eRegisterKindGeneric));
|
|
|
|
if (!assembly_profiler_sp->GetFastUnwindPlan(m_range, thread,
|
|
|
|
*m_unwind_plan_fast_sp)) {
|
|
|
|
m_unwind_plan_fast_sp.reset();
|
2010-09-10 15:49:16 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
return m_unwind_plan_fast_sp;
|
|
|
|
}
|
2010-09-10 15:49:16 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
UnwindPlanSP FuncUnwinders::GetUnwindPlanArchitectureDefault(Thread &thread) {
|
2017-02-24 11:35:46 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2016-09-07 04:57:50 +08:00
|
|
|
if (m_unwind_plan_arch_default_sp.get() || m_tried_unwind_arch_default)
|
2011-02-15 08:19:15 +08:00
|
|
|
return m_unwind_plan_arch_default_sp;
|
2010-09-10 15:49:16 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
m_tried_unwind_arch_default = true;
|
|
|
|
|
|
|
|
Address current_pc;
|
|
|
|
ProcessSP process_sp(thread.CalculateProcess());
|
|
|
|
if (process_sp) {
|
|
|
|
ABI *abi = process_sp->GetABI().get();
|
|
|
|
if (abi) {
|
|
|
|
m_unwind_plan_arch_default_sp.reset(
|
|
|
|
new UnwindPlan(lldb::eRegisterKindGeneric));
|
|
|
|
if (!abi->CreateDefaultUnwindPlan(*m_unwind_plan_arch_default_sp)) {
|
|
|
|
m_unwind_plan_arch_default_sp.reset();
|
|
|
|
}
|
2011-09-15 08:44:34 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2011-09-15 08:44:34 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
return m_unwind_plan_arch_default_sp;
|
2011-09-15 08:44:34 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
UnwindPlanSP
|
|
|
|
FuncUnwinders::GetUnwindPlanArchitectureDefaultAtFunctionEntry(Thread &thread) {
|
2017-02-24 11:35:46 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2016-09-07 04:57:50 +08:00
|
|
|
if (m_unwind_plan_arch_default_at_func_entry_sp.get() ||
|
|
|
|
m_tried_unwind_arch_default_at_func_entry)
|
|
|
|
return m_unwind_plan_arch_default_at_func_entry_sp;
|
|
|
|
|
|
|
|
m_tried_unwind_arch_default_at_func_entry = true;
|
|
|
|
|
|
|
|
Address current_pc;
|
|
|
|
ProcessSP process_sp(thread.CalculateProcess());
|
|
|
|
if (process_sp) {
|
|
|
|
ABI *abi = process_sp->GetABI().get();
|
|
|
|
if (abi) {
|
|
|
|
m_unwind_plan_arch_default_at_func_entry_sp.reset(
|
|
|
|
new UnwindPlan(lldb::eRegisterKindGeneric));
|
|
|
|
if (!abi->CreateFunctionEntryUnwindPlan(
|
|
|
|
*m_unwind_plan_arch_default_at_func_entry_sp)) {
|
|
|
|
m_unwind_plan_arch_default_at_func_entry_sp.reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-09-15 08:44:34 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
return m_unwind_plan_arch_default_at_func_entry_sp;
|
|
|
|
}
|
2014-12-21 18:44:54 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
Address &FuncUnwinders::GetFirstNonPrologueInsn(Target &target) {
|
2017-02-24 11:35:46 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2016-09-07 04:57:50 +08:00
|
|
|
if (m_first_non_prologue_insn.IsValid())
|
2010-09-10 15:49:16 +08:00
|
|
|
return m_first_non_prologue_insn;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
|
|
ExecutionContext exe_ctx(target.shared_from_this(), false);
|
|
|
|
UnwindAssemblySP assembly_profiler_sp(GetUnwindAssemblyProfiler(target));
|
|
|
|
if (assembly_profiler_sp)
|
|
|
|
assembly_profiler_sp->FirstNonPrologueInsn(m_range, exe_ctx,
|
|
|
|
m_first_non_prologue_insn);
|
|
|
|
return m_first_non_prologue_insn;
|
2010-09-10 15:49:16 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
const Address &FuncUnwinders::GetFunctionStartAddress() const {
|
|
|
|
return m_range.GetBaseAddress();
|
2010-09-10 15:49:16 +08:00
|
|
|
}
|
|
|
|
|
2014-05-23 09:48:10 +08:00
|
|
|
lldb::UnwindAssemblySP
|
2016-09-07 04:57:50 +08:00
|
|
|
FuncUnwinders::GetUnwindAssemblyProfiler(Target &target) {
|
|
|
|
UnwindAssemblySP assembly_profiler_sp;
|
|
|
|
ArchSpec arch;
|
|
|
|
if (m_unwind_table.GetArchitecture(arch)) {
|
|
|
|
arch.MergeFrom(target.GetArchitecture());
|
|
|
|
assembly_profiler_sp = UnwindAssembly::FindPlugin(arch);
|
|
|
|
}
|
|
|
|
return assembly_profiler_sp;
|
2014-05-23 09:48:10 +08:00
|
|
|
}
|
2014-11-18 10:27:42 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
Address FuncUnwinders::GetLSDAAddress(Target &target) {
|
|
|
|
Address lsda_addr;
|
|
|
|
|
|
|
|
UnwindPlanSP unwind_plan_sp = GetEHFrameUnwindPlan(target, -1);
|
|
|
|
if (unwind_plan_sp.get() == nullptr) {
|
|
|
|
unwind_plan_sp = GetCompactUnwindUnwindPlan(target, -1);
|
|
|
|
}
|
|
|
|
if (unwind_plan_sp.get() && unwind_plan_sp->GetLSDAAddress().IsValid()) {
|
|
|
|
lsda_addr = unwind_plan_sp->GetLSDAAddress();
|
|
|
|
}
|
|
|
|
return lsda_addr;
|
2014-11-18 10:27:42 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
Address FuncUnwinders::GetPersonalityRoutinePtrAddress(Target &target) {
|
|
|
|
Address personality_addr;
|
2014-11-18 10:27:42 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
UnwindPlanSP unwind_plan_sp = GetEHFrameUnwindPlan(target, -1);
|
|
|
|
if (unwind_plan_sp.get() == nullptr) {
|
|
|
|
unwind_plan_sp = GetCompactUnwindUnwindPlan(target, -1);
|
|
|
|
}
|
|
|
|
if (unwind_plan_sp.get() &&
|
|
|
|
unwind_plan_sp->GetPersonalityFunctionPtr().IsValid()) {
|
|
|
|
personality_addr = unwind_plan_sp->GetPersonalityFunctionPtr();
|
|
|
|
}
|
2014-11-18 10:27:42 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
return personality_addr;
|
2014-11-18 10:27:42 +08:00
|
|
|
}
|