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
12 changes: 12 additions & 0 deletions lldb/include/lldb/Target/StackFrameList.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ class StackFrameList {
/// Mark a stack frame as the currently selected frame and return its index.
uint32_t SetSelectedFrame(lldb_private::StackFrame *frame);

/// Resets the selected frame index of this object.
void ClearSelectedFrameIndex();

/// Get the currently selected frame index.
/// We should only call SelectMostRelevantFrame if (a) the user hasn't already
/// selected a frame, and (b) if this really is a user facing
Expand Down Expand Up @@ -172,6 +175,15 @@ class StackFrameList {
/// The currently selected frame. An optional is used to record whether anyone
/// has set the selected frame on this stack yet. We only let recognizers
/// change the frame if this is the first time GetSelectedFrame is called.
///
/// Thread-safety:
/// This member is not protected by a mutex.
/// LLDB really only should have an opinion about the selected frame index
/// when a process stops, before control gets handed back to the user.
/// After that, it's up to them to change it whenever they feel like it.
/// If two parts of lldb decided they wanted to be in control of the selected
/// frame index on stop the right way to fix it would need to be some explicit
/// negotiation for who gets to control this.
std::optional<uint32_t> m_selected_frame_idx;

/// Protect access to m_selected_frame_idx. Always acquire after m_list_mutex
Expand Down
5 changes: 5 additions & 0 deletions lldb/include/lldb/Target/Thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,11 @@ class Thread : public std::enable_shared_from_this<Thread>,
bool SetSelectedFrameByIndexNoisily(uint32_t frame_idx,
Stream &output_stream);

/// Resets the selected frame index of this object.
void ClearSelectedFrameIndex() {
return GetStackFrameList()->ClearSelectedFrameIndex();
}

void SetDefaultFileAndLineToSelectedFrame() {
GetStackFrameList()->SetDefaultFileAndLineToSelectedFrame();
}
Expand Down
8 changes: 8 additions & 0 deletions lldb/source/Target/Process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4269,6 +4269,14 @@ bool Process::ProcessEventData::ShouldStop(Event *event_ptr,
// appropriately. We also need to stop processing actions, since they
// aren't expecting the target to be running.

// Clear the selected frame which may have been set as part of utility
// expressions that have been run as part of this stop. If we didn't
// clear this, then StopInfo::GetSuggestedStackFrameIndex would not
// take affect when we next called SelectMostRelevantFrame.
// PerformAction should not be the one setting a selected frame, instead
// this should be done via GetSuggestedStackFrameIndex.
thread_sp->ClearSelectedFrameIndex();

// FIXME: we might have run.
if (stop_info_sp->HasTargetRunSinceMe()) {
SetRestarted(true);
Expand Down
2 changes: 2 additions & 0 deletions lldb/source/Target/StackFrameList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -944,3 +944,5 @@ size_t StackFrameList::GetStatus(Stream &strm, uint32_t first_frame,
strm.IndentLess();
return num_frames_displayed;
}

void StackFrameList::ClearSelectedFrameIndex() { m_selected_frame_idx.reset(); }
Loading