[Lldb-commits] [lldb] [lldb][Target] Clear selected frame index after a StopInfo::PerformAction (PR #133078)
Michael Buch via lldb-commits
lldb-commits at lists.llvm.org
Fri Mar 28 08:46:58 PDT 2025
https://github.com/Michael137 updated https://github.com/llvm/llvm-project/pull/133078
>From 4a0d13ef2751071505ab797c63c2ee20d14a6c61 Mon Sep 17 00:00:00 2001
From: Michael Buch <michaelbuch12 at gmail.com>
Date: Wed, 26 Mar 2025 13:20:24 +0000
Subject: [PATCH 1/4] [lldb][Target] Clear selected frame index after a
StopInfo::PerformAction
---
lldb/include/lldb/Target/StackFrameList.h | 3 +++
lldb/include/lldb/Target/Thread.h | 5 +++++
lldb/source/Target/Process.cpp | 2 ++
lldb/source/Target/StackFrameList.cpp | 4 ++++
4 files changed, 14 insertions(+)
diff --git a/lldb/include/lldb/Target/StackFrameList.h b/lldb/include/lldb/Target/StackFrameList.h
index 8a66296346f2d..d805b644b0b31 100644
--- a/lldb/include/lldb/Target/StackFrameList.h
+++ b/lldb/include/lldb/Target/StackFrameList.h
@@ -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
diff --git a/lldb/include/lldb/Target/Thread.h b/lldb/include/lldb/Target/Thread.h
index 6ede7fa301a82..688c056da2633 100644
--- a/lldb/include/lldb/Target/Thread.h
+++ b/lldb/include/lldb/Target/Thread.h
@@ -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();
}
diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
index 369933234ccca..c51bab20f56ee 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -4295,6 +4295,8 @@ 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.
+ thread_sp->ClearSelectedFrameIndex();
+
// FIXME: we might have run.
if (stop_info_sp->HasTargetRunSinceMe()) {
SetRestarted(true);
diff --git a/lldb/source/Target/StackFrameList.cpp b/lldb/source/Target/StackFrameList.cpp
index 9c6208e9e0a65..3592c3c03db74 100644
--- a/lldb/source/Target/StackFrameList.cpp
+++ b/lldb/source/Target/StackFrameList.cpp
@@ -936,3 +936,7 @@ size_t StackFrameList::GetStatus(Stream &strm, uint32_t first_frame,
strm.IndentLess();
return num_frames_displayed;
}
+
+void StackFrameList::ClearSelectedFrameIndex() {
+ m_selected_frame_idx.reset();
+}
>From 1a1a55786de369b1c9771623c21de459848c7e20 Mon Sep 17 00:00:00 2001
From: Michael Buch <michaelbuch12 at gmail.com>
Date: Wed, 26 Mar 2025 13:35:23 +0000
Subject: [PATCH 2/4] fixup! clang-format
---
lldb/source/Target/Process.cpp | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
index c51bab20f56ee..46e8028160d04 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -4295,6 +4295,12 @@ 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.
>From 158f0b2cd664ba1864e510bf8293d16790c6a65a Mon Sep 17 00:00:00 2001
From: Michael Buch <michaelbuch12 at gmail.com>
Date: Fri, 28 Mar 2025 15:40:47 +0000
Subject: [PATCH 3/4] fixup! add thread-safety comment
---
lldb/include/lldb/Target/StackFrameList.h | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/lldb/include/lldb/Target/StackFrameList.h b/lldb/include/lldb/Target/StackFrameList.h
index d805b644b0b31..8d455dc831df3 100644
--- a/lldb/include/lldb/Target/StackFrameList.h
+++ b/lldb/include/lldb/Target/StackFrameList.h
@@ -175,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;
/// The number of concrete frames fetched while filling the frame list. This
>From dd454d8c8321d51e19fb33a310890fc6501580f2 Mon Sep 17 00:00:00 2001
From: Michael Buch <michaelbuch12 at gmail.com>
Date: Fri, 28 Mar 2025 15:46:40 +0000
Subject: [PATCH 4/4] fixup! clang-format
---
lldb/source/Target/Process.cpp | 6 +++---
lldb/source/Target/StackFrameList.cpp | 4 +---
2 files changed, 4 insertions(+), 6 deletions(-)
diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
index 46e8028160d04..e6c46ce7e70f3 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -4298,9 +4298,9 @@ bool Process::ProcessEventData::ShouldStop(Event *event_ptr,
// 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.
+ // 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.
diff --git a/lldb/source/Target/StackFrameList.cpp b/lldb/source/Target/StackFrameList.cpp
index 3592c3c03db74..5292618ac8562 100644
--- a/lldb/source/Target/StackFrameList.cpp
+++ b/lldb/source/Target/StackFrameList.cpp
@@ -937,6 +937,4 @@ size_t StackFrameList::GetStatus(Stream &strm, uint32_t first_frame,
return num_frames_displayed;
}
-void StackFrameList::ClearSelectedFrameIndex() {
- m_selected_frame_idx.reset();
-}
+void StackFrameList::ClearSelectedFrameIndex() { m_selected_frame_idx.reset(); }
More information about the lldb-commits
mailing list