Skip to content

Commit 22bbd7d

Browse files
committed
FuncUnwinders: Add a new "SymbolFile" unwind plan
Summary: some unwind formats are specific to a single symbol file and so it does not make sense for their parsing code live in the general Symbol library (as is the case with eh_frame for instance). This is the case for the unwind information in breakpad files, but the same will probably be true for PDB unwind info (once we are able to parse that). This patch adds the ability to fetch an unwind plan provided by a symbol file plugin, as discussed in the RFC at <http://lists.llvm.org/pipermail/lldb-dev/2019-February/014703.html>. I've kept the set of changes to a minimum, as there is no way to test them until we have a symbol file which implements this API -- that is comming in a follow-up patch, which will also implicitly test this change. The interesting part here is the introduction of the "RegisterInfoResolver" interface. The reason for this is that breakpad needs to be able to resolve register names (which are present as strings in the file) into register enums so that it can construct the unwind plan. This is normally done via the RegisterContext class, handing this over to the SymbolFile plugin would mean that it has full access to the debugged process, which is not something we want it to have. So instead, I create a facade, which only provides the ability to query register names, and hide the RegisterContext behind the facade. Also note that this only adds the ability to dump the unwind plan created by the symbol file plugin -- the plan is not used for unwinding yet -- this will be added in a third patch, which will add additional tests which makes sure the unwinding works as a whole. Reviewers: jasonmolenda, clayborg Subscribers: markmentovai, amccarth, lldb-commits Differential Revision: https://reviews.llvm.org/D61732 llvm-svn: 360409
1 parent c4f1201 commit 22bbd7d

File tree

7 files changed

+71
-3
lines changed

7 files changed

+71
-3
lines changed

lldb/include/lldb/Symbol/FuncUnwinders.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ class FuncUnwinders {
9090

9191
lldb::UnwindPlanSP GetArmUnwindUnwindPlan(Target &target);
9292

93+
lldb::UnwindPlanSP GetSymbolFileUnwindPlan(Thread &thread);
94+
9395
lldb::UnwindPlanSP GetArchDefaultUnwindPlan(Thread &thread);
9496

9597
lldb::UnwindPlanSP GetArchDefaultAtFuncEntryUnwindPlan(Thread &thread);
@@ -120,6 +122,7 @@ class FuncUnwinders {
120122

121123
std::vector<lldb::UnwindPlanSP> m_unwind_plan_compact_unwind;
122124
lldb::UnwindPlanSP m_unwind_plan_arm_unwind_sp;
125+
lldb::UnwindPlanSP m_unwind_plan_symbol_file_sp;
123126
lldb::UnwindPlanSP m_unwind_plan_fast_sp;
124127
lldb::UnwindPlanSP m_unwind_plan_arch_default_sp;
125128
lldb::UnwindPlanSP m_unwind_plan_arch_default_at_func_entry_sp;
@@ -131,8 +134,8 @@ class FuncUnwinders {
131134
m_tried_unwind_plan_eh_frame_augmented : 1,
132135
m_tried_unwind_plan_debug_frame_augmented : 1,
133136
m_tried_unwind_plan_compact_unwind : 1,
134-
m_tried_unwind_plan_arm_unwind : 1, m_tried_unwind_fast : 1,
135-
m_tried_unwind_arch_default : 1,
137+
m_tried_unwind_plan_arm_unwind : 1, m_tried_unwind_plan_symbol_file : 1,
138+
m_tried_unwind_fast : 1, m_tried_unwind_arch_default : 1,
136139
m_tried_unwind_arch_default_at_func_entry : 1;
137140

138141
Address m_first_non_prologue_insn;

lldb/include/lldb/Symbol/SymbolFile.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,18 @@ class SymbolFile : public PluginInterface {
223223
/// for this module have been changed.
224224
virtual void SectionFileAddressesChanged() {}
225225

226+
struct RegisterInfoResolver {
227+
virtual ~RegisterInfoResolver(); // anchor
228+
229+
virtual const RegisterInfo *ResolveName(llvm::StringRef name) const = 0;
230+
virtual const RegisterInfo *ResolveNumber(lldb::RegisterKind kind,
231+
uint32_t number) const = 0;
232+
};
233+
virtual lldb::UnwindPlanSP
234+
GetUnwindPlan(const Address &address, const RegisterInfoResolver &resolver) {
235+
return nullptr;
236+
}
237+
226238
virtual void Dump(Stream &s) {}
227239

228240
protected:

lldb/include/lldb/Symbol/UnwindTable.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class UnwindTable {
3333
lldb_private::CompactUnwindInfo *GetCompactUnwindInfo();
3434

3535
ArmUnwindInfo *GetArmUnwindInfo();
36+
SymbolFile *GetSymbolFile();
3637

3738
lldb::FuncUnwindersSP GetFuncUnwindersContainingAddress(const Address &addr,
3839
SymbolContext &sc);

lldb/source/Commands/CommandObjectTarget.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3591,6 +3591,14 @@ class CommandObjectTargetModulesShowUnwind : public CommandObjectParsed {
35913591
result.GetOutputStream().Printf("\n");
35923592
}
35933593

3594+
if (UnwindPlanSP symfile_plan_sp =
3595+
func_unwinders_sp->GetSymbolFileUnwindPlan(*thread)) {
3596+
result.GetOutputStream().Printf("Symbol file UnwindPlan:\n");
3597+
symfile_plan_sp->Dump(result.GetOutputStream(), thread.get(),
3598+
LLDB_INVALID_ADDRESS);
3599+
result.GetOutputStream().Printf("\n");
3600+
}
3601+
35943602
UnwindPlanSP compact_unwind_sp =
35953603
func_unwinders_sp->GetCompactUnwindUnwindPlan(*target);
35963604
if (compact_unwind_sp) {

lldb/source/Symbol/FuncUnwinders.cpp

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@
1313
#include "lldb/Symbol/CompactUnwindInfo.h"
1414
#include "lldb/Symbol/DWARFCallFrameInfo.h"
1515
#include "lldb/Symbol/ObjectFile.h"
16+
#include "lldb/Symbol/SymbolFile.h"
1617
#include "lldb/Symbol/UnwindPlan.h"
1718
#include "lldb/Symbol/UnwindTable.h"
1819
#include "lldb/Target/ABI.h"
1920
#include "lldb/Target/ExecutionContext.h"
2021
#include "lldb/Target/Process.h"
22+
#include "lldb/Target/RegisterContext.h"
2123
#include "lldb/Target/RegisterNumber.h"
2224
#include "lldb/Target/Target.h"
2325
#include "lldb/Target/Thread.h"
@@ -42,7 +44,8 @@ FuncUnwinders::FuncUnwinders(UnwindTable &unwind_table, AddressRange range)
4244
m_tried_unwind_plan_eh_frame_augmented(false),
4345
m_tried_unwind_plan_debug_frame_augmented(false),
4446
m_tried_unwind_plan_compact_unwind(false),
45-
m_tried_unwind_plan_arm_unwind(false), m_tried_unwind_fast(false),
47+
m_tried_unwind_plan_arm_unwind(false),
48+
m_tried_unwind_plan_symbol_file(false), m_tried_unwind_fast(false),
4649
m_tried_unwind_arch_default(false),
4750
m_tried_unwind_arch_default_at_func_entry(false),
4851
m_first_non_prologue_insn() {}
@@ -147,6 +150,38 @@ UnwindPlanSP FuncUnwinders::GetArmUnwindUnwindPlan(Target &target) {
147150
return m_unwind_plan_arm_unwind_sp;
148151
}
149152

153+
namespace {
154+
class RegisterContextToInfo: public SymbolFile::RegisterInfoResolver {
155+
public:
156+
RegisterContextToInfo(RegisterContext &ctx) : m_ctx(ctx) {}
157+
158+
const RegisterInfo *ResolveName(llvm::StringRef name) const {
159+
return m_ctx.GetRegisterInfoByName(name);
160+
}
161+
const RegisterInfo *ResolveNumber(lldb::RegisterKind kind,
162+
uint32_t number) const {
163+
return m_ctx.GetRegisterInfo(kind, number);
164+
}
165+
166+
private:
167+
RegisterContext &m_ctx;
168+
};
169+
} // namespace
170+
171+
UnwindPlanSP FuncUnwinders::GetSymbolFileUnwindPlan(Thread &thread) {
172+
std::lock_guard<std::recursive_mutex> guard(m_mutex);
173+
if (m_unwind_plan_symbol_file_sp.get() || m_tried_unwind_plan_symbol_file)
174+
return m_unwind_plan_symbol_file_sp;
175+
176+
m_tried_unwind_plan_symbol_file = true;
177+
if (SymbolFile *symfile = m_unwind_table.GetSymbolFile()) {
178+
m_unwind_plan_symbol_file_sp = symfile->GetUnwindPlan(
179+
m_range.GetBaseAddress(),
180+
RegisterContextToInfo(*thread.GetRegisterContext()));
181+
}
182+
return m_unwind_plan_symbol_file_sp;
183+
}
184+
150185
UnwindPlanSP FuncUnwinders::GetEHFrameAugmentedUnwindPlan(Target &target,
151186
Thread &thread) {
152187
std::lock_guard<std::recursive_mutex> guard(m_mutex);

lldb/source/Symbol/SymbolFile.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,5 @@ void SymbolFile::AssertModuleLock() {
168168
"Module is not locked");
169169
#endif
170170
}
171+
172+
SymbolFile::RegisterInfoResolver::~RegisterInfoResolver() = default;

lldb/source/Symbol/UnwindTable.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "lldb/Symbol/FuncUnwinders.h"
1919
#include "lldb/Symbol/ObjectFile.h"
2020
#include "lldb/Symbol/SymbolContext.h"
21+
#include "lldb/Symbol/SymbolVendor.h"
2122

2223
// There is one UnwindTable object per ObjectFile. It contains a list of Unwind
2324
// objects -- one per function, populated lazily -- for the ObjectFile. Each
@@ -181,6 +182,12 @@ ArmUnwindInfo *UnwindTable::GetArmUnwindInfo() {
181182
return m_arm_unwind_up.get();
182183
}
183184

185+
SymbolFile *UnwindTable::GetSymbolFile() {
186+
if (SymbolVendor *vendor = m_module.GetSymbolVendor())
187+
return vendor->GetSymbolFile();
188+
return nullptr;
189+
}
190+
184191
ArchSpec UnwindTable::GetArchitecture() { return m_module.GetArchitecture(); }
185192

186193
bool UnwindTable::GetAllowAssemblyEmulationUnwindPlans() {

0 commit comments

Comments
 (0)