Skip to content

[lldb][plugin] Use counter directly for number of readers #139252

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,21 +189,20 @@ DWARFUnit::ScopedExtractDIEs DWARFUnit::ExtractDIEsScoped() {
}

DWARFUnit::ScopedExtractDIEs::ScopedExtractDIEs(DWARFUnit &cu) : m_cu(&cu) {
m_cu->m_die_array_scoped_mutex.lock_shared();
llvm::sys::ScopedLock lock(m_cu->m_die_array_scoped_mutex);
++m_cu->m_die_array_scoped_count;
}

DWARFUnit::ScopedExtractDIEs::~ScopedExtractDIEs() {
if (!m_cu)
return;
m_cu->m_die_array_scoped_mutex.unlock_shared();
if (!m_clear_dies || m_cu->m_cancel_scopes)
return;
// Be sure no other ScopedExtractDIEs is running anymore.
llvm::sys::ScopedWriter lock_scoped(m_cu->m_die_array_scoped_mutex);
llvm::sys::ScopedWriter lock(m_cu->m_die_array_mutex);
if (m_cu->m_cancel_scopes)
return;
m_cu->ClearDIEsRWLocked();
llvm::sys::ScopedLock lock(m_cu->m_die_array_scoped_mutex);
--m_cu->m_die_array_scoped_count;
if (m_cu->m_die_array_scoped_count == 0 && m_clear_dies &&
!m_cu->m_cancel_scopes) {
llvm::sys::ScopedWriter lock(m_cu->m_die_array_mutex);
m_cu->ClearDIEsRWLocked();
}
}

DWARFUnit::ScopedExtractDIEs::ScopedExtractDIEs(ScopedExtractDIEs &&rhs)
Expand Down
4 changes: 3 additions & 1 deletion lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "llvm/DebugInfo/DWARF/DWARFAddressRange.h"
#include "llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h"
#include "llvm/DebugInfo/DWARF/DWARFDebugRnglists.h"
#include "llvm/Support/Mutex.h"
#include "llvm/Support/RWMutex.h"
#include <atomic>
#include <optional>
Expand Down Expand Up @@ -328,7 +329,8 @@ class DWARFUnit : public DWARFExpression::Delegate, public UserID {
DWARFDebugInfoEntry::collection m_die_array;
mutable llvm::sys::RWMutex m_die_array_mutex;
// It is used for tracking of ScopedExtractDIEs instances.
mutable llvm::sys::RWMutex m_die_array_scoped_mutex;
mutable llvm::sys::Mutex m_die_array_scoped_mutex;
mutable int m_die_array_scoped_count = 0;
// ScopedExtractDIEs instances should not call ClearDIEsRWLocked()
// as someone called ExtractDIEsIfNeeded().
std::atomic<bool> m_cancel_scopes;
Expand Down
2 changes: 1 addition & 1 deletion lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def test_diagnositcs(self):
f"target create --core {core}", context="repl"
)

output = self.get_important()
output = self.get_important(timeout=2.0)
self.assertIn(
"warning: unable to retrieve process ID from minidump file",
output,
Expand Down
Loading