Skip to content

[lldb] Protect the selected frame idx in StackFrameList #150718

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 1 commit into from
Jul 26, 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
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