Skip to content

Commit 0e4b921

Browse files
authored
Merge pull request #1436 from vedantk/cherry
[Function] Lock the function when parsing call site info
2 parents 6b2ea61 + 83cc13b commit 0e4b921

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

lldb/include/lldb/Symbol/Function.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#include "lldb/Utility/UserID.h"
1818
#include "llvm/ADT/ArrayRef.h"
1919

20+
#include <mutex>
21+
2022
namespace lldb_private {
2123

2224
class ExecutionContext;
@@ -636,6 +638,9 @@ class Function : public UserID, public SymbolContextScope {
636638
uint32_t
637639
m_prologue_byte_size; ///< Compute the prologue size once and cache it
638640

641+
std::mutex
642+
m_call_edges_lock; ///< Exclusive lock that controls read/write
643+
/// access to m_call_edges and m_call_edges_resolved.
639644
bool m_call_edges_resolved = false; ///< Whether call site info has been
640645
/// parsed.
641646
std::vector<std::unique_ptr<CallEdge>> m_call_edges; ///< Outgoing call edges.

lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4030,6 +4030,11 @@ SymbolFileDWARF::CollectCallEdges(ModuleSP module, DWARFDIE function_die) {
40304030

40314031
std::vector<std::unique_ptr<lldb_private::CallEdge>>
40324032
SymbolFileDWARF::ParseCallEdgesInFunction(UserID func_id) {
4033+
// ParseCallEdgesInFunction must be called at the behest of an exclusively
4034+
// locked lldb::Function instance. Storage for parsed call edges is owned by
4035+
// the lldb::Function instance: locking at the SymbolFile level would be too
4036+
// late, because the act of storing results from ParseCallEdgesInFunction
4037+
// would be racy.
40334038
DWARFDIE func_die = GetDIE(func_id.GetID());
40344039
if (func_die.IsValid())
40354040
return CollectCallEdges(GetObjectFile()->GetModule(), func_die);

lldb/source/Symbol/Function.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,8 @@ void Function::GetEndLineSourceInfo(FileSpec &source_file, uint32_t &line_no) {
305305
}
306306

307307
llvm::ArrayRef<std::unique_ptr<CallEdge>> Function::GetCallEdges() {
308+
std::lock_guard<std::mutex> guard(m_call_edges_lock);
309+
308310
if (m_call_edges_resolved)
309311
return m_call_edges;
310312

0 commit comments

Comments
 (0)