Skip to content

Commit d7afafd

Browse files
authored
[lldb] Return *const* UnwindPlan pointers from FuncUnwinders (#133247)
These plans are cached and accessed from multiple threads. Modifying them would be a Bad Idea(tm).
1 parent f066d75 commit d7afafd

File tree

7 files changed

+247
-250
lines changed

7 files changed

+247
-250
lines changed

lldb/include/lldb/Symbol/FuncUnwinders.h

+41-37
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,19 @@ class FuncUnwinders {
3636

3737
~FuncUnwinders();
3838

39-
lldb::UnwindPlanSP GetUnwindPlanAtCallSite(Target &target, Thread &thread);
39+
std::shared_ptr<const UnwindPlan> GetUnwindPlanAtCallSite(Target &target,
40+
Thread &thread);
4041

41-
lldb::UnwindPlanSP GetUnwindPlanAtNonCallSite(Target &target,
42-
lldb_private::Thread &thread);
42+
std::shared_ptr<const UnwindPlan>
43+
GetUnwindPlanAtNonCallSite(Target &target, lldb_private::Thread &thread);
4344

44-
lldb::UnwindPlanSP GetUnwindPlanFastUnwind(Target &target,
45-
lldb_private::Thread &thread);
45+
std::shared_ptr<const UnwindPlan>
46+
GetUnwindPlanFastUnwind(Target &target, lldb_private::Thread &thread);
4647

47-
lldb::UnwindPlanSP
48+
std::shared_ptr<const UnwindPlan>
4849
GetUnwindPlanArchitectureDefault(lldb_private::Thread &thread);
4950

50-
lldb::UnwindPlanSP
51+
std::shared_ptr<const UnwindPlan>
5152
GetUnwindPlanArchitectureDefaultAtFunctionEntry(lldb_private::Thread &thread);
5253

5354
Address &GetFirstNonPrologueInsn(Target &target);
@@ -77,32 +78,34 @@ class FuncUnwinders {
7778
// used. Instead, clients should ask for the *behavior* they are looking for,
7879
// using one of the above UnwindPlan retrieval methods.
7980

80-
lldb::UnwindPlanSP GetAssemblyUnwindPlan(Target &target, Thread &thread);
81+
std::shared_ptr<const UnwindPlan> GetAssemblyUnwindPlan(Target &target,
82+
Thread &thread);
8183

82-
lldb::UnwindPlanSP GetObjectFileUnwindPlan(Target &target);
84+
std::shared_ptr<const UnwindPlan> GetObjectFileUnwindPlan(Target &target);
8385

84-
lldb::UnwindPlanSP GetObjectFileAugmentedUnwindPlan(Target &target,
85-
Thread &thread);
86+
std::shared_ptr<const UnwindPlan>
87+
GetObjectFileAugmentedUnwindPlan(Target &target, Thread &thread);
8688

87-
lldb::UnwindPlanSP GetEHFrameUnwindPlan(Target &target);
89+
std::shared_ptr<const UnwindPlan> GetEHFrameUnwindPlan(Target &target);
8890

89-
lldb::UnwindPlanSP GetEHFrameAugmentedUnwindPlan(Target &target,
90-
Thread &thread);
91+
std::shared_ptr<const UnwindPlan>
92+
GetEHFrameAugmentedUnwindPlan(Target &target, Thread &thread);
9193

92-
lldb::UnwindPlanSP GetDebugFrameUnwindPlan(Target &target);
94+
std::shared_ptr<const UnwindPlan> GetDebugFrameUnwindPlan(Target &target);
9395

94-
lldb::UnwindPlanSP GetDebugFrameAugmentedUnwindPlan(Target &target,
95-
Thread &thread);
96+
std::shared_ptr<const UnwindPlan>
97+
GetDebugFrameAugmentedUnwindPlan(Target &target, Thread &thread);
9698

97-
lldb::UnwindPlanSP GetCompactUnwindUnwindPlan(Target &target);
99+
std::shared_ptr<const UnwindPlan> GetCompactUnwindUnwindPlan(Target &target);
98100

99-
lldb::UnwindPlanSP GetArmUnwindUnwindPlan(Target &target);
101+
std::shared_ptr<const UnwindPlan> GetArmUnwindUnwindPlan(Target &target);
100102

101-
lldb::UnwindPlanSP GetSymbolFileUnwindPlan(Thread &thread);
103+
std::shared_ptr<const UnwindPlan> GetSymbolFileUnwindPlan(Thread &thread);
102104

103-
lldb::UnwindPlanSP GetArchDefaultUnwindPlan(Thread &thread);
105+
std::shared_ptr<const UnwindPlan> GetArchDefaultUnwindPlan(Thread &thread);
104106

105-
lldb::UnwindPlanSP GetArchDefaultAtFuncEntryUnwindPlan(Thread &thread);
107+
std::shared_ptr<const UnwindPlan>
108+
GetArchDefaultAtFuncEntryUnwindPlan(Thread &thread);
106109

107110
private:
108111
lldb::UnwindAssemblySP GetUnwindAssemblyProfiler(Target &target);
@@ -113,7 +116,8 @@ class FuncUnwinders {
113116
// unwind rule for the pc, and LazyBoolCalculate if it was unable to
114117
// determine this for some reason.
115118
lldb_private::LazyBool CompareUnwindPlansForIdenticalInitialPCLocation(
116-
Thread &thread, const lldb::UnwindPlanSP &a, const lldb::UnwindPlanSP &b);
119+
Thread &thread, const std::shared_ptr<const UnwindPlan> &a,
120+
const std::shared_ptr<const UnwindPlan> &b);
117121

118122
UnwindTable &m_unwind_table;
119123

@@ -129,22 +133,22 @@ class FuncUnwinders {
129133

130134
std::recursive_mutex m_mutex;
131135

132-
lldb::UnwindPlanSP m_unwind_plan_assembly_sp;
133-
lldb::UnwindPlanSP m_unwind_plan_object_file_sp;
134-
lldb::UnwindPlanSP m_unwind_plan_eh_frame_sp;
135-
lldb::UnwindPlanSP m_unwind_plan_debug_frame_sp;
136+
std::shared_ptr<const UnwindPlan> m_unwind_plan_assembly_sp;
137+
std::shared_ptr<const UnwindPlan> m_unwind_plan_object_file_sp;
138+
std::shared_ptr<const UnwindPlan> m_unwind_plan_eh_frame_sp;
139+
std::shared_ptr<const UnwindPlan> m_unwind_plan_debug_frame_sp;
136140

137141
// augmented by assembly inspection so it's valid everywhere
138-
lldb::UnwindPlanSP m_unwind_plan_object_file_augmented_sp;
139-
lldb::UnwindPlanSP m_unwind_plan_eh_frame_augmented_sp;
140-
lldb::UnwindPlanSP m_unwind_plan_debug_frame_augmented_sp;
141-
142-
std::vector<lldb::UnwindPlanSP> m_unwind_plan_compact_unwind;
143-
lldb::UnwindPlanSP m_unwind_plan_arm_unwind_sp;
144-
lldb::UnwindPlanSP m_unwind_plan_symbol_file_sp;
145-
lldb::UnwindPlanSP m_unwind_plan_fast_sp;
146-
lldb::UnwindPlanSP m_unwind_plan_arch_default_sp;
147-
lldb::UnwindPlanSP m_unwind_plan_arch_default_at_func_entry_sp;
142+
std::shared_ptr<const UnwindPlan> m_unwind_plan_object_file_augmented_sp;
143+
std::shared_ptr<const UnwindPlan> m_unwind_plan_eh_frame_augmented_sp;
144+
std::shared_ptr<const UnwindPlan> m_unwind_plan_debug_frame_augmented_sp;
145+
146+
std::vector<std::shared_ptr<const UnwindPlan>> m_unwind_plan_compact_unwind;
147+
std::shared_ptr<const UnwindPlan> m_unwind_plan_arm_unwind_sp;
148+
std::shared_ptr<const UnwindPlan> m_unwind_plan_symbol_file_sp;
149+
std::shared_ptr<const UnwindPlan> m_unwind_plan_fast_sp;
150+
std::shared_ptr<const UnwindPlan> m_unwind_plan_arch_default_sp;
151+
std::shared_ptr<const UnwindPlan> m_unwind_plan_arch_default_at_func_entry_sp;
148152

149153
// Fetching the UnwindPlans can be expensive - if we've already attempted to
150154
// get one & failed, don't try again.

lldb/include/lldb/Symbol/UnwindPlan.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ class UnwindPlan {
482482
m_return_addr_register = regnum;
483483
}
484484

485-
uint32_t GetReturnAddressRegister() { return m_return_addr_register; }
485+
uint32_t GetReturnAddressRegister() const { return m_return_addr_register; }
486486

487487
uint32_t GetInitialCFARegister() const {
488488
if (m_row_list.empty())
@@ -497,7 +497,7 @@ class UnwindPlan {
497497
m_plan_valid_ranges = std::move(ranges);
498498
}
499499

500-
bool PlanValidAtAddress(Address addr);
500+
bool PlanValidAtAddress(Address addr) const;
501501

502502
bool IsValidRowIndex(uint32_t idx) const;
503503

lldb/include/lldb/Target/RegisterContextUnwind.h

+9-7
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ class RegisterContextUnwind : public lldb_private::RegisterContext {
127127

128128
/// Check if the given unwind plan indicates a signal trap handler, and
129129
/// update frame type and symbol context if so.
130-
void PropagateTrapHandlerFlagFromUnwindPlan(lldb::UnwindPlanSP unwind_plan);
130+
void PropagateTrapHandlerFlagFromUnwindPlan(
131+
std::shared_ptr<const UnwindPlan> unwind_plan);
131132

132133
// Provide a location for where THIS function saved the CALLER's register
133134
// value
@@ -194,16 +195,17 @@ class RegisterContextUnwind : public lldb_private::RegisterContext {
194195
const UnwindPlan::Row::FAValue &fa,
195196
lldb::addr_t &address);
196197

197-
lldb::UnwindPlanSP GetFastUnwindPlanForFrame();
198+
std::shared_ptr<const UnwindPlan> GetFastUnwindPlanForFrame();
198199

199-
lldb::UnwindPlanSP GetFullUnwindPlanForFrame();
200+
std::shared_ptr<const UnwindPlan> GetFullUnwindPlanForFrame();
200201

201202
void UnwindLogMsg(const char *fmt, ...) __attribute__((format(printf, 2, 3)));
202203

203204
void UnwindLogMsgVerbose(const char *fmt, ...)
204205
__attribute__((format(printf, 2, 3)));
205206

206-
bool IsUnwindPlanValidForCurrentPC(lldb::UnwindPlanSP unwind_plan_sp);
207+
bool IsUnwindPlanValidForCurrentPC(
208+
std::shared_ptr<const UnwindPlan> unwind_plan_sp);
207209

208210
lldb::addr_t GetReturnAddressHint(int32_t plan_offset);
209211

@@ -215,9 +217,9 @@ class RegisterContextUnwind : public lldb_private::RegisterContext {
215217
// i.e. where THIS frame saved them
216218
///
217219

218-
lldb::UnwindPlanSP m_fast_unwind_plan_sp; // may be NULL
219-
lldb::UnwindPlanSP m_full_unwind_plan_sp;
220-
lldb::UnwindPlanSP m_fallback_unwind_plan_sp; // may be NULL
220+
std::shared_ptr<const UnwindPlan> m_fast_unwind_plan_sp; // may be NULL
221+
std::shared_ptr<const UnwindPlan> m_full_unwind_plan_sp;
222+
std::shared_ptr<const UnwindPlan> m_fallback_unwind_plan_sp; // may be NULL
221223

222224
bool m_all_registers_available; // Can we retrieve all regs or just
223225
// nonvolatile regs?

lldb/source/Commands/CommandObjectTarget.cpp

+49-57
Original file line numberDiff line numberDiff line change
@@ -3641,85 +3641,78 @@ class CommandObjectTargetModulesShowUnwind : public CommandObjectParsed {
36413641

36423642
result.GetOutputStream().Printf("\n");
36433643

3644-
UnwindPlanSP non_callsite_unwind_plan =
3645-
func_unwinders_sp->GetUnwindPlanAtNonCallSite(*target, *thread);
3646-
if (non_callsite_unwind_plan) {
3644+
if (std::shared_ptr<const UnwindPlan> plan_sp =
3645+
func_unwinders_sp->GetUnwindPlanAtNonCallSite(*target, *thread)) {
36473646
result.GetOutputStream().Printf(
36483647
"Asynchronous (not restricted to call-sites) UnwindPlan is '%s'\n",
3649-
non_callsite_unwind_plan->GetSourceName().AsCString());
3648+
plan_sp->GetSourceName().AsCString());
36503649
}
3651-
UnwindPlanSP callsite_unwind_plan =
3652-
func_unwinders_sp->GetUnwindPlanAtCallSite(*target, *thread);
3653-
if (callsite_unwind_plan) {
3650+
if (std::shared_ptr<const UnwindPlan> plan_sp =
3651+
func_unwinders_sp->GetUnwindPlanAtCallSite(*target, *thread)) {
36543652
result.GetOutputStream().Printf(
36553653
"Synchronous (restricted to call-sites) UnwindPlan is '%s'\n",
3656-
callsite_unwind_plan->GetSourceName().AsCString());
3654+
plan_sp->GetSourceName().AsCString());
36573655
}
3658-
UnwindPlanSP fast_unwind_plan =
3659-
func_unwinders_sp->GetUnwindPlanFastUnwind(*target, *thread);
3660-
if (fast_unwind_plan) {
3661-
result.GetOutputStream().Printf(
3662-
"Fast UnwindPlan is '%s'\n",
3663-
fast_unwind_plan->GetSourceName().AsCString());
3656+
if (std::shared_ptr<const UnwindPlan> plan_sp =
3657+
func_unwinders_sp->GetUnwindPlanFastUnwind(*target, *thread)) {
3658+
result.GetOutputStream().Printf("Fast UnwindPlan is '%s'\n",
3659+
plan_sp->GetSourceName().AsCString());
36643660
}
36653661

36663662
result.GetOutputStream().Printf("\n");
36673663

3668-
UnwindPlanSP assembly_sp =
3669-
func_unwinders_sp->GetAssemblyUnwindPlan(*target, *thread);
3670-
if (assembly_sp) {
3664+
if (std::shared_ptr<const UnwindPlan> plan_sp =
3665+
func_unwinders_sp->GetAssemblyUnwindPlan(*target, *thread)) {
36713666
result.GetOutputStream().Printf(
36723667
"Assembly language inspection UnwindPlan:\n");
3673-
assembly_sp->Dump(result.GetOutputStream(), thread.get(),
3674-
LLDB_INVALID_ADDRESS);
3668+
plan_sp->Dump(result.GetOutputStream(), thread.get(),
3669+
LLDB_INVALID_ADDRESS);
36753670
result.GetOutputStream().Printf("\n");
36763671
}
36773672

3678-
UnwindPlanSP of_unwind_sp =
3679-
func_unwinders_sp->GetObjectFileUnwindPlan(*target);
3680-
if (of_unwind_sp) {
3673+
if (std::shared_ptr<const UnwindPlan> plan_sp =
3674+
func_unwinders_sp->GetObjectFileUnwindPlan(*target)) {
36813675
result.GetOutputStream().Printf("object file UnwindPlan:\n");
3682-
of_unwind_sp->Dump(result.GetOutputStream(), thread.get(),
3683-
LLDB_INVALID_ADDRESS);
3676+
plan_sp->Dump(result.GetOutputStream(), thread.get(),
3677+
LLDB_INVALID_ADDRESS);
36843678
result.GetOutputStream().Printf("\n");
36853679
}
36863680

3687-
UnwindPlanSP of_unwind_augmented_sp =
3688-
func_unwinders_sp->GetObjectFileAugmentedUnwindPlan(*target, *thread);
3689-
if (of_unwind_augmented_sp) {
3681+
if (std::shared_ptr<const UnwindPlan> plan_sp =
3682+
func_unwinders_sp->GetObjectFileAugmentedUnwindPlan(*target,
3683+
*thread)) {
36903684
result.GetOutputStream().Printf("object file augmented UnwindPlan:\n");
3691-
of_unwind_augmented_sp->Dump(result.GetOutputStream(), thread.get(),
3692-
LLDB_INVALID_ADDRESS);
3685+
plan_sp->Dump(result.GetOutputStream(), thread.get(),
3686+
LLDB_INVALID_ADDRESS);
36933687
result.GetOutputStream().Printf("\n");
36943688
}
36953689

3696-
UnwindPlanSP ehframe_sp =
3697-
func_unwinders_sp->GetEHFrameUnwindPlan(*target);
3698-
if (ehframe_sp) {
3690+
if (std::shared_ptr<const UnwindPlan> plan_sp =
3691+
func_unwinders_sp->GetEHFrameUnwindPlan(*target)) {
36993692
result.GetOutputStream().Printf("eh_frame UnwindPlan:\n");
3700-
ehframe_sp->Dump(result.GetOutputStream(), thread.get(),
3701-
LLDB_INVALID_ADDRESS);
3693+
plan_sp->Dump(result.GetOutputStream(), thread.get(),
3694+
LLDB_INVALID_ADDRESS);
37023695
result.GetOutputStream().Printf("\n");
37033696
}
37043697

3705-
UnwindPlanSP ehframe_augmented_sp =
3706-
func_unwinders_sp->GetEHFrameAugmentedUnwindPlan(*target, *thread);
3707-
if (ehframe_augmented_sp) {
3698+
if (std::shared_ptr<const UnwindPlan> plan_sp =
3699+
func_unwinders_sp->GetEHFrameAugmentedUnwindPlan(*target,
3700+
*thread)) {
37083701
result.GetOutputStream().Printf("eh_frame augmented UnwindPlan:\n");
3709-
ehframe_augmented_sp->Dump(result.GetOutputStream(), thread.get(),
3710-
LLDB_INVALID_ADDRESS);
3702+
plan_sp->Dump(result.GetOutputStream(), thread.get(),
3703+
LLDB_INVALID_ADDRESS);
37113704
result.GetOutputStream().Printf("\n");
37123705
}
37133706

3714-
if (UnwindPlanSP plan_sp =
3707+
if (std::shared_ptr<const UnwindPlan> plan_sp =
37153708
func_unwinders_sp->GetDebugFrameUnwindPlan(*target)) {
37163709
result.GetOutputStream().Printf("debug_frame UnwindPlan:\n");
37173710
plan_sp->Dump(result.GetOutputStream(), thread.get(),
37183711
LLDB_INVALID_ADDRESS);
37193712
result.GetOutputStream().Printf("\n");
37203713
}
37213714

3722-
if (UnwindPlanSP plan_sp =
3715+
if (std::shared_ptr<const UnwindPlan> plan_sp =
37233716
func_unwinders_sp->GetDebugFrameAugmentedUnwindPlan(*target,
37243717
*thread)) {
37253718
result.GetOutputStream().Printf("debug_frame augmented UnwindPlan:\n");
@@ -3728,36 +3721,35 @@ class CommandObjectTargetModulesShowUnwind : public CommandObjectParsed {
37283721
result.GetOutputStream().Printf("\n");
37293722
}
37303723

3731-
UnwindPlanSP arm_unwind_sp =
3732-
func_unwinders_sp->GetArmUnwindUnwindPlan(*target);
3733-
if (arm_unwind_sp) {
3724+
if (std::shared_ptr<const UnwindPlan> plan_sp =
3725+
func_unwinders_sp->GetArmUnwindUnwindPlan(*target)) {
37343726
result.GetOutputStream().Printf("ARM.exidx unwind UnwindPlan:\n");
3735-
arm_unwind_sp->Dump(result.GetOutputStream(), thread.get(),
3736-
LLDB_INVALID_ADDRESS);
3727+
plan_sp->Dump(result.GetOutputStream(), thread.get(),
3728+
LLDB_INVALID_ADDRESS);
37373729
result.GetOutputStream().Printf("\n");
37383730
}
37393731

3740-
if (UnwindPlanSP symfile_plan_sp =
3732+
if (std::shared_ptr<const UnwindPlan> plan_sp =
37413733
func_unwinders_sp->GetSymbolFileUnwindPlan(*thread)) {
37423734
result.GetOutputStream().Printf("Symbol file UnwindPlan:\n");
3743-
symfile_plan_sp->Dump(result.GetOutputStream(), thread.get(),
3744-
LLDB_INVALID_ADDRESS);
3735+
plan_sp->Dump(result.GetOutputStream(), thread.get(),
3736+
LLDB_INVALID_ADDRESS);
37453737
result.GetOutputStream().Printf("\n");
37463738
}
37473739

3748-
UnwindPlanSP compact_unwind_sp =
3749-
func_unwinders_sp->GetCompactUnwindUnwindPlan(*target);
3750-
if (compact_unwind_sp) {
3740+
if (std::shared_ptr<const UnwindPlan> plan_sp =
3741+
func_unwinders_sp->GetCompactUnwindUnwindPlan(*target)) {
37513742
result.GetOutputStream().Printf("Compact unwind UnwindPlan:\n");
3752-
compact_unwind_sp->Dump(result.GetOutputStream(), thread.get(),
3753-
LLDB_INVALID_ADDRESS);
3743+
plan_sp->Dump(result.GetOutputStream(), thread.get(),
3744+
LLDB_INVALID_ADDRESS);
37543745
result.GetOutputStream().Printf("\n");
37553746
}
37563747

3757-
if (fast_unwind_plan) {
3748+
if (std::shared_ptr<const UnwindPlan> plan_sp =
3749+
func_unwinders_sp->GetUnwindPlanFastUnwind(*target, *thread)) {
37583750
result.GetOutputStream().Printf("Fast UnwindPlan:\n");
3759-
fast_unwind_plan->Dump(result.GetOutputStream(), thread.get(),
3760-
LLDB_INVALID_ADDRESS);
3751+
plan_sp->Dump(result.GetOutputStream(), thread.get(),
3752+
LLDB_INVALID_ADDRESS);
37613753
result.GetOutputStream().Printf("\n");
37623754
}
37633755

0 commit comments

Comments
 (0)