Skip to content

Commit f5e8a14

Browse files
committed
The UnwindTable (one per module) used to hand out shared pointers
to its unwind assembly profiler to all of the FuncUnwinders (one per symbol) under it. If lldb is running multiple targets, you could get two different FuncUnwinders in the same Module trying to use the same llvm disassembler simultaneously and that may be a re-entrancy problem. Instead, the UnwindTable has the unwind assembly profiler and when the FuncUnwinders want to use it, they get exclusive access to the assembly profiler until they're done using it. <rdar://problem/16992332> llvm-svn: 209488
1 parent cbb8438 commit f5e8a14

File tree

4 files changed

+28
-13
lines changed

4 files changed

+28
-13
lines changed

lldb/include/lldb/Symbol/FuncUnwinders.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class FuncUnwinders
3131
// instructions are finished for migrating breakpoints past the
3232
// stack frame setup instructions when we don't have line table information.
3333

34-
FuncUnwinders (lldb_private::UnwindTable& unwind_table, const lldb::UnwindAssemblySP& assembly_profiler, AddressRange range);
34+
FuncUnwinders (lldb_private::UnwindTable& unwind_table, AddressRange range);
3535

3636
~FuncUnwinders ();
3737

@@ -77,7 +77,6 @@ class FuncUnwinders
7777

7878
private:
7979
UnwindTable& m_unwind_table;
80-
lldb::UnwindAssemblySP m_assembly_profiler;
8180
AddressRange m_range;
8281

8382
Mutex m_mutex;

lldb/include/lldb/Symbol/UnwindTable.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313

1414
#include <map>
1515

16-
#include "lldb/lldb-private.h"
16+
#include "lldb/lldb-private.h"
17+
#include "lldb/Host/Mutex.h"
1718

1819
namespace lldb_private {
1920

@@ -42,6 +43,8 @@ class UnwindTable
4243
lldb::FuncUnwindersSP
4344
GetUncachedFuncUnwindersContainingAddress (const Address& addr, SymbolContext &sc);
4445

46+
lldb::UnwindAssemblySP GetUnwindAssemblyProfiler (lldb_private::Mutex::Locker &locker);
47+
4548
private:
4649
void
4750
Dump (Stream &s);
@@ -58,6 +61,7 @@ class UnwindTable
5861
bool m_initialized; // delay some initialization until ObjectFile is set up
5962

6063
lldb::UnwindAssemblySP m_assembly_profiler;
64+
Mutex m_assembly_mutex;
6165

6266
DWARFCallFrameInfo* m_eh_frame;
6367

lldb/source/Symbol/FuncUnwinders.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,9 @@ using namespace lldb_private;
2828
FuncUnwinders::FuncUnwinders
2929
(
3030
UnwindTable& unwind_table,
31-
const lldb::UnwindAssemblySP& assembly_profiler,
3231
AddressRange range
3332
) :
3433
m_unwind_table(unwind_table),
35-
m_assembly_profiler(assembly_profiler),
3634
m_range(range),
3735
m_mutex (Mutex::eMutexTypeNormal),
3836
m_unwind_plan_call_site_sp (),
@@ -114,10 +112,12 @@ FuncUnwinders::GetUnwindPlanAtNonCallSite (Thread& thread)
114112
if (m_tried_unwind_at_non_call_site == false && m_unwind_plan_non_call_site_sp.get() == nullptr)
115113
{
116114
m_tried_unwind_at_non_call_site = true;
117-
if (m_assembly_profiler)
115+
Mutex::Locker assembly_locker;
116+
UnwindAssemblySP assembly_profiler = m_unwind_table.GetUnwindAssemblyProfiler (assembly_locker);
117+
if (assembly_profiler)
118118
{
119119
m_unwind_plan_non_call_site_sp.reset (new UnwindPlan (lldb::eRegisterKindGeneric));
120-
if (!m_assembly_profiler->GetNonCallSiteUnwindPlanFromAssembly (m_range, thread, *m_unwind_plan_non_call_site_sp))
120+
if (!assembly_profiler->GetNonCallSiteUnwindPlanFromAssembly (m_range, thread, *m_unwind_plan_non_call_site_sp))
121121
m_unwind_plan_non_call_site_sp.reset();
122122
}
123123
}
@@ -143,10 +143,12 @@ FuncUnwinders::GetUnwindPlanFastUnwind (Thread& thread)
143143
if (m_tried_unwind_fast == false && m_unwind_plan_fast_sp.get() == nullptr)
144144
{
145145
m_tried_unwind_fast = true;
146-
if (m_assembly_profiler)
146+
Mutex::Locker assembly_locker;
147+
UnwindAssemblySP assembly_profiler = m_unwind_table.GetUnwindAssemblyProfiler (assembly_locker);
148+
if (assembly_profiler)
147149
{
148150
m_unwind_plan_fast_sp.reset (new UnwindPlan (lldb::eRegisterKindGeneric));
149-
if (!m_assembly_profiler->GetFastUnwindPlan (m_range, thread, *m_unwind_plan_fast_sp))
151+
if (!assembly_profiler->GetFastUnwindPlan (m_range, thread, *m_unwind_plan_fast_sp))
150152
m_unwind_plan_fast_sp.reset();
151153
}
152154
}
@@ -232,8 +234,10 @@ FuncUnwinders::GetFirstNonPrologueInsn (Target& target)
232234
if (m_first_non_prologue_insn.IsValid())
233235
return m_first_non_prologue_insn;
234236
ExecutionContext exe_ctx (target.shared_from_this(), false);
235-
if (m_assembly_profiler)
236-
m_assembly_profiler->FirstNonPrologueInsn (m_range, exe_ctx, m_first_non_prologue_insn);
237+
Mutex::Locker assembly_locker;
238+
UnwindAssemblySP assembly_profiler = m_unwind_table.GetUnwindAssemblyProfiler (assembly_locker);
239+
if (assembly_profiler)
240+
assembly_profiler->FirstNonPrologueInsn (m_range, exe_ctx, m_first_non_prologue_insn);
237241
return m_first_non_prologue_insn;
238242
}
239243

lldb/source/Symbol/UnwindTable.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ UnwindTable::UnwindTable (ObjectFile& objfile) :
3131
m_unwinds (),
3232
m_initialized (false),
3333
m_assembly_profiler (nullptr),
34+
m_assembly_mutex (),
3435
m_eh_frame (nullptr)
3536
{
3637
}
@@ -100,7 +101,7 @@ UnwindTable::GetFuncUnwindersContainingAddress (const Address& addr, SymbolConte
100101
}
101102
}
102103

103-
FuncUnwindersSP func_unwinder_sp(new FuncUnwinders(*this, m_assembly_profiler, range));
104+
FuncUnwindersSP func_unwinder_sp(new FuncUnwinders(*this, range));
104105
m_unwinds.insert (insert_pos, std::make_pair(range.GetBaseAddress().GetFileAddress(), func_unwinder_sp));
105106
// StreamFile s(stdout, false);
106107
// Dump (s);
@@ -127,7 +128,7 @@ UnwindTable::GetUncachedFuncUnwindersContainingAddress (const Address& addr, Sym
127128
}
128129
}
129130

130-
FuncUnwindersSP func_unwinder_sp(new FuncUnwinders(*this, m_assembly_profiler, range));
131+
FuncUnwindersSP func_unwinder_sp(new FuncUnwinders(*this, range));
131132
return func_unwinder_sp;
132133
}
133134

@@ -151,3 +152,10 @@ UnwindTable::GetEHFrameInfo ()
151152
Initialize();
152153
return m_eh_frame;
153154
}
155+
156+
lldb::UnwindAssemblySP
157+
UnwindTable::GetUnwindAssemblyProfiler (lldb_private::Mutex::Locker &locker)
158+
{
159+
locker.Lock (m_assembly_mutex);
160+
return m_assembly_profiler;
161+
}

0 commit comments

Comments
 (0)