Skip to content

Commit d6ebd84

Browse files
authored
Merge pull request swiftlang#1435 from vedantk/eng/PR-55622443
[Function] Lock the function when parsing call site info
2 parents 093eb28 + a957d13 commit d6ebd84

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;
@@ -644,6 +646,9 @@ class Function : public UserID, public SymbolContextScope {
644646
uint32_t
645647
m_prologue_byte_size; ///< Compute the prologue size once and cache it
646648

649+
std::mutex
650+
m_call_edges_lock; ///< Exclusive lock that controls read/write
651+
/// access to m_call_edges and m_call_edges_resolved.
647652
bool m_call_edges_resolved = false; ///< Whether call site info has been
648653
/// parsed.
649654
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
@@ -4112,6 +4112,11 @@ SymbolFileDWARF::CollectCallEdges(ModuleSP module, DWARFDIE function_die) {
41124112

41134113
std::vector<std::unique_ptr<lldb_private::CallEdge>>
41144114
SymbolFileDWARF::ParseCallEdgesInFunction(UserID func_id) {
4115+
// ParseCallEdgesInFunction must be called at the behest of an exclusively
4116+
// locked lldb::Function instance. Storage for parsed call edges is owned by
4117+
// the lldb::Function instance: locking at the SymbolFile level would be too
4118+
// late, because the act of storing results from ParseCallEdgesInFunction
4119+
// would be racy.
41154120
DWARFDIE func_die = GetDIE(func_id.GetID());
41164121
if (func_die.IsValid())
41174122
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
@@ -310,6 +310,8 @@ void Function::GetEndLineSourceInfo(FileSpec &source_file, uint32_t &line_no) {
310310
}
311311

312312
llvm::ArrayRef<std::unique_ptr<CallEdge>> Function::GetCallEdges() {
313+
std::lock_guard<std::mutex> guard(m_call_edges_lock);
314+
313315
if (m_call_edges_resolved)
314316
return m_call_edges;
315317

0 commit comments

Comments
 (0)