Skip to content
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
5 changes: 5 additions & 0 deletions lldb/include/lldb/Target/StackFrameList.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ class StackFrameList {
/// change the frame if this is the first time GetSelectedFrame is called.
std::optional<uint32_t> m_selected_frame_idx;

/// Protect access to m_selected_frame_idx. Always acquire after m_list_mutex
/// to avoid lock inversion. A recursive mutex because GetSelectedFrameIndex
/// may indirectly call SetSelectedFrame.
std::recursive_mutex m_selected_frame_mutex;

/// The number of concrete frames fetched while filling the frame list. This
/// is only used when synthetic frames are enabled.
uint32_t m_concrete_frames_fetched;
Expand Down
6 changes: 6 additions & 0 deletions lldb/source/Target/StackFrameList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,8 @@ void StackFrameList::SelectMostRelevantFrame() {

uint32_t
StackFrameList::GetSelectedFrameIndex(SelectMostRelevant select_most_relevant) {
std::lock_guard<std::recursive_mutex> guard(m_selected_frame_mutex);

if (!m_selected_frame_idx && select_most_relevant)
SelectMostRelevantFrame();
if (!m_selected_frame_idx) {
Expand All @@ -798,6 +800,8 @@ StackFrameList::GetSelectedFrameIndex(SelectMostRelevant select_most_relevant) {

uint32_t StackFrameList::SetSelectedFrame(lldb_private::StackFrame *frame) {
std::shared_lock<std::shared_mutex> guard(m_list_mutex);
std::lock_guard<std::recursive_mutex> selected_frame_guard(
m_selected_frame_mutex);

const_iterator pos;
const_iterator begin = m_frames.begin();
Expand Down Expand Up @@ -851,6 +855,8 @@ void StackFrameList::Clear() {
std::unique_lock<std::shared_mutex> guard(m_list_mutex);
m_frames.clear();
m_concrete_frames_fetched = 0;
std::lock_guard<std::recursive_mutex> selected_frame_guard(
m_selected_frame_mutex);
m_selected_frame_idx.reset();
}

Expand Down
Loading