Skip to content

Commit 83cc13b

Browse files
committed
[Function] Lock the function when parsing call site info
Summary: DWARF-parsing methods in SymbolFileDWARF which update module state typically take the module lock. ParseCallEdgesInFunction doesn't do this, but higher-level locking within lldb::Function (which owns the storage for parsed call edges) is necessary. The lack of locking could explain some as-of-yet unreproducible crashes which occur in Function::GetTailCallingEdges(). In these crashes, the `m_call_edges` vector is non-empty but contains a nullptr, which shouldn't be possible. (If this vector is non-empty, it _must_ contain a non-null unique_ptr.) This may address rdar://55622443 and rdar://65119458. Reviewers: jasonmolenda, friss, jingham Subscribers: aprantl, lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D83359 (cherry picked from commit 6cfc90b)
1 parent 2e659d4 commit 83cc13b

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)