diff --git a/lldb/include/lldb/Core/Debugger.h b/lldb/include/lldb/Core/Debugger.h index fa4483c93e639..5f1f598a051a2 100644 --- a/lldb/include/lldb/Core/Debugger.h +++ b/lldb/include/lldb/Core/Debugger.h @@ -457,6 +457,9 @@ class Debugger : public std::enable_shared_from_this, /// Redraw the statusline if enabled. void RedrawStatusline(std::optional exe_ctx_ref); + /// Flush cached state (e.g. stale execution context in the statusline). + void FlushStatusLine(); + /// This is the correct way to query the state of Interruption. /// If you are on the RunCommandInterpreter thread, it will check the /// command interpreter state, and if it is on another thread it will diff --git a/lldb/include/lldb/Core/Statusline.h b/lldb/include/lldb/Core/Statusline.h index a5ab1927b57f5..eacdec306ccf9 100644 --- a/lldb/include/lldb/Core/Statusline.h +++ b/lldb/include/lldb/Core/Statusline.h @@ -32,6 +32,9 @@ class Statusline { /// Redraw the statusline. void Redraw(std::optional exe_ctx_ref); + /// Clear the cached execution context to discard stale pointers. + void ClearExecutionContext(); + /// Inform the statusline that the terminal dimensions have changed. void TerminalSizeChanged(); diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp index e1b2ce1b063e0..aea2240612617 100644 --- a/lldb/source/Core/Debugger.cpp +++ b/lldb/source/Core/Debugger.cpp @@ -1284,6 +1284,15 @@ void Debugger::RedrawStatusline( m_statusline->Redraw(exe_ctx_ref); } +void Debugger::FlushStatusLine() { + std::lock_guard guard(m_statusline_mutex); + + if (!m_statusline) + return; + + m_statusline->ClearExecutionContext(); +} + ExecutionContext Debugger::GetSelectedExecutionContext() { bool adopt_selected = true; ExecutionContextRef exe_ctx_ref(GetSelectedTarget().get(), adopt_selected); diff --git a/lldb/source/Core/Statusline.cpp b/lldb/source/Core/Statusline.cpp index bdc649580637c..d49735b3c64c2 100644 --- a/lldb/source/Core/Statusline.cpp +++ b/lldb/source/Core/Statusline.cpp @@ -125,6 +125,8 @@ void Statusline::UpdateScrollWindow(ScrollWindowMode mode) { m_debugger.RefreshIOHandler(); } +void Statusline::ClearExecutionContext() { m_exe_ctx_ref.ClearFrame(); } + void Statusline::Redraw(std::optional exe_ctx_ref) { // Update the cached execution context. if (exe_ctx_ref) diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp index 587d9f6408ae4..91004bca57c57 100644 --- a/lldb/source/Target/Process.cpp +++ b/lldb/source/Target/Process.cpp @@ -6025,6 +6025,7 @@ void Process::Flush() { m_extended_thread_stop_id = 0; m_queue_list.Clear(); m_queue_list_stop_id = 0; + GetTarget().GetDebugger().FlushStatusLine(); } lldb::addr_t Process::GetCodeAddressMask() {