https://github.com/JDevlieghere updated 
https://github.com/llvm/llvm-project/pull/148994

>From ee116a937d165f4862aae34206d112682b8ce0ee Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere <jo...@devlieghere.com>
Date: Tue, 15 Jul 2025 16:54:05 -0700
Subject: [PATCH 1/2] [lldb] Always compute the execution & symbol context

Always compute the execution and symbol context, regardless of whether
the statusline is enabled. This code gets called from the default event
handler thread and has uncovered threading issues that otherwise only
reproduce when the statusline is enabled.
---
 lldb/include/lldb/Core/Debugger.h   |  3 +++
 lldb/include/lldb/Core/Statusline.h |  6 ++---
 lldb/source/Core/Debugger.cpp       | 34 ++++++++++++++++++++++++++++-
 lldb/source/Core/Statusline.cpp     | 32 +++++++--------------------
 4 files changed, 47 insertions(+), 28 deletions(-)

diff --git a/lldb/include/lldb/Core/Debugger.h 
b/lldb/include/lldb/Core/Debugger.h
index 250ad64b76d9a..35f94b603f679 100644
--- a/lldb/include/lldb/Core/Debugger.h
+++ b/lldb/include/lldb/Core/Debugger.h
@@ -421,6 +421,9 @@ class Debugger : public 
std::enable_shared_from_this<Debugger>,
   /// Redraw the statusline if enabled.
   void RedrawStatusline(bool update = true);
 
+  /// Compute the current execution and symbol context.
+  std::pair<ExecutionContext, SymbolContext> GetCurrentContext();
+
   /// 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 6bda153f822d2..13866a9083c63 100644
--- a/lldb/include/lldb/Core/Statusline.h
+++ b/lldb/include/lldb/Core/Statusline.h
@@ -25,9 +25,9 @@ class Statusline {
   /// Hide the statusline and extend the scroll window.
   void Disable();
 
-  /// Redraw the statusline. If update is false, this will redraw the last
-  /// string.
-  void Redraw(bool update = true);
+  /// Redraw the statusline. If both exe_ctx and sym_ctx are NULL, this redraws
+  /// the last string.
+  void Redraw(const ExecutionContext *exe_ctx, const SymbolContext *sym_ctx);
 
   /// 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 ed674ee1275c7..321031d21a32c 100644
--- a/lldb/source/Core/Debugger.cpp
+++ b/lldb/source/Core/Debugger.cpp
@@ -1214,10 +1214,42 @@ void Debugger::RestoreInputTerminalState() {
   }
 }
 
+std::pair<ExecutionContext, SymbolContext> Debugger::GetCurrentContext() {
+  ExecutionContext exe_ctx = GetSelectedExecutionContext();
+
+  if (!exe_ctx.HasTargetScope())
+    exe_ctx.SetTargetPtr(&GetSelectedOrDummyTarget());
+
+  SymbolContext sym_ctx;
+  if (ProcessSP process_sp = exe_ctx.GetProcessSP()) {
+    // Check if the process is stopped, and if it is, make sure it remains
+    // stopped until we've computed the symbol context.
+    Process::StopLocker stop_locker;
+    if (stop_locker.TryLock(&process_sp->GetRunLock())) {
+      if (auto frame_sp = exe_ctx.GetFrameSP())
+        sym_ctx = frame_sp->GetSymbolContext(eSymbolContextEverything);
+    }
+  }
+
+  return {exe_ctx, sym_ctx};
+}
+
 void Debugger::RedrawStatusline(bool update) {
   std::lock_guard<std::mutex> guard(m_statusline_mutex);
+
+  if (!update && m_statusline) {
+    m_statusline->Redraw(nullptr, nullptr);
+    return;
+  }
+
+  // Always compute the execution and symbol context, regardless of whether the
+  // statusline is enabled. This code gets called from the default event 
handler
+  // thread and has uncovered threading issues that otherwise only reproduce
+  // when the statusline is enabled.
+  auto [exe_ctx, sym_ctx] = GetCurrentContext();
+
   if (m_statusline)
-    m_statusline->Redraw(update);
+    m_statusline->Redraw(&exe_ctx, &sym_ctx);
 }
 
 ExecutionContext Debugger::GetSelectedExecutionContext() {
diff --git a/lldb/source/Core/Statusline.cpp b/lldb/source/Core/Statusline.cpp
index 393d427241021..ef05f73099f98 100644
--- a/lldb/source/Core/Statusline.cpp
+++ b/lldb/source/Core/Statusline.cpp
@@ -47,8 +47,8 @@ void Statusline::TerminalSizeChanged() {
 
   UpdateScrollWindow(ResizeStatusline);
 
-  // Draw the old statusline.
-  Redraw(/*update=*/false);
+  // Redraw the old statusline.
+  Redraw(nullptr, nullptr);
 }
 
 void Statusline::Enable() {
@@ -56,7 +56,8 @@ void Statusline::Enable() {
   UpdateScrollWindow(EnableStatusline);
 
   // Draw the statusline.
-  Redraw(/*update=*/true);
+  auto [exe_ctx, sym_ctx] = m_debugger.GetCurrentContext();
+  Redraw(&exe_ctx, &sym_ctx);
 }
 
 void Statusline::Disable() {
@@ -127,33 +128,16 @@ void Statusline::UpdateScrollWindow(ScrollWindowMode 
mode) {
   m_debugger.RefreshIOHandler();
 }
 
-void Statusline::Redraw(bool update) {
-  if (!update) {
+void Statusline::Redraw(const ExecutionContext *exe_ctx,
+                        const SymbolContext *sym_ctx) {
+  if (!exe_ctx && !sym_ctx) {
     Draw(m_last_str);
     return;
   }
 
-  ExecutionContext exe_ctx = m_debugger.GetSelectedExecutionContext();
-
-  // For colors and progress events, the format entity needs access to the
-  // debugger, which requires a target in the execution context.
-  if (!exe_ctx.HasTargetScope())
-    exe_ctx.SetTargetPtr(&m_debugger.GetSelectedOrDummyTarget());
-
-  SymbolContext symbol_ctx;
-  if (ProcessSP process_sp = exe_ctx.GetProcessSP()) {
-    // Check if the process is stopped, and if it is, make sure it remains
-    // stopped until we've computed the symbol context.
-    Process::StopLocker stop_locker;
-    if (stop_locker.TryLock(&process_sp->GetRunLock())) {
-      if (auto frame_sp = exe_ctx.GetFrameSP())
-        symbol_ctx = frame_sp->GetSymbolContext(eSymbolContextEverything);
-    }
-  }
-
   StreamString stream;
   FormatEntity::Entry format = m_debugger.GetStatuslineFormat();
-  FormatEntity::Format(format, stream, &symbol_ctx, &exe_ctx, nullptr, nullptr,
+  FormatEntity::Format(format, stream, sym_ctx, exe_ctx, nullptr, nullptr,
                        false, false);
 
   Draw(stream.GetString().str());

>From 9a99f8393739416d5f50eacdb5f248c9f9168638 Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere <jo...@devlieghere.com>
Date: Thu, 17 Jul 2025 14:42:22 -0700
Subject: [PATCH 2/2] Rename Current -> Selected

---
 lldb/include/lldb/Core/Debugger.h |  8 +++---
 lldb/source/Core/Debugger.cpp     | 42 +++++++++++++++----------------
 lldb/source/Core/Statusline.cpp   |  2 +-
 3 files changed, 27 insertions(+), 25 deletions(-)

diff --git a/lldb/include/lldb/Core/Debugger.h 
b/lldb/include/lldb/Core/Debugger.h
index 35f94b603f679..4b111912fcd87 100644
--- a/lldb/include/lldb/Core/Debugger.h
+++ b/lldb/include/lldb/Core/Debugger.h
@@ -181,7 +181,12 @@ class Debugger : public 
std::enable_shared_from_this<Debugger>,
     return m_target_list.GetSelectedTarget();
   }
 
+  /// Get the execution context for the selected target.
   ExecutionContext GetSelectedExecutionContext();
+
+  /// Get the execution and symbol context for the selected target.
+  std::pair<ExecutionContext, SymbolContext> GetSelectedContext();
+
   /// Get accessor for the target list.
   ///
   /// The target list is part of the global debugger object. This the single
@@ -421,9 +426,6 @@ class Debugger : public 
std::enable_shared_from_this<Debugger>,
   /// Redraw the statusline if enabled.
   void RedrawStatusline(bool update = true);
 
-  /// Compute the current execution and symbol context.
-  std::pair<ExecutionContext, SymbolContext> GetCurrentContext();
-
   /// 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/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp
index 321031d21a32c..5be41a8844ccb 100644
--- a/lldb/source/Core/Debugger.cpp
+++ b/lldb/source/Core/Debugger.cpp
@@ -1214,26 +1214,6 @@ void Debugger::RestoreInputTerminalState() {
   }
 }
 
-std::pair<ExecutionContext, SymbolContext> Debugger::GetCurrentContext() {
-  ExecutionContext exe_ctx = GetSelectedExecutionContext();
-
-  if (!exe_ctx.HasTargetScope())
-    exe_ctx.SetTargetPtr(&GetSelectedOrDummyTarget());
-
-  SymbolContext sym_ctx;
-  if (ProcessSP process_sp = exe_ctx.GetProcessSP()) {
-    // Check if the process is stopped, and if it is, make sure it remains
-    // stopped until we've computed the symbol context.
-    Process::StopLocker stop_locker;
-    if (stop_locker.TryLock(&process_sp->GetRunLock())) {
-      if (auto frame_sp = exe_ctx.GetFrameSP())
-        sym_ctx = frame_sp->GetSymbolContext(eSymbolContextEverything);
-    }
-  }
-
-  return {exe_ctx, sym_ctx};
-}
-
 void Debugger::RedrawStatusline(bool update) {
   std::lock_guard<std::mutex> guard(m_statusline_mutex);
 
@@ -1246,7 +1226,7 @@ void Debugger::RedrawStatusline(bool update) {
   // statusline is enabled. This code gets called from the default event 
handler
   // thread and has uncovered threading issues that otherwise only reproduce
   // when the statusline is enabled.
-  auto [exe_ctx, sym_ctx] = GetCurrentContext();
+  auto [exe_ctx, sym_ctx] = GetSelectedContext();
 
   if (m_statusline)
     m_statusline->Redraw(&exe_ctx, &sym_ctx);
@@ -1258,6 +1238,26 @@ ExecutionContext Debugger::GetSelectedExecutionContext() 
{
   return ExecutionContext(exe_ctx_ref);
 }
 
+std::pair<ExecutionContext, SymbolContext> Debugger::GetSelectedContext() {
+  ExecutionContext exe_ctx = GetSelectedExecutionContext();
+
+  if (!exe_ctx.HasTargetScope())
+    exe_ctx.SetTargetPtr(&GetSelectedOrDummyTarget());
+
+  SymbolContext sym_ctx;
+  if (ProcessSP process_sp = exe_ctx.GetProcessSP()) {
+    // Check if the process is stopped, and if it is, make sure it remains
+    // stopped until we've computed the symbol context.
+    Process::StopLocker stop_locker;
+    if (stop_locker.TryLock(&process_sp->GetRunLock())) {
+      if (auto frame_sp = exe_ctx.GetFrameSP())
+        sym_ctx = frame_sp->GetSymbolContext(eSymbolContextEverything);
+    }
+  }
+
+  return {exe_ctx, sym_ctx};
+}
+
 void Debugger::DispatchInputInterrupt() {
   std::lock_guard<std::recursive_mutex> guard(m_io_handler_stack.GetMutex());
   IOHandlerSP reader_sp(m_io_handler_stack.Top());
diff --git a/lldb/source/Core/Statusline.cpp b/lldb/source/Core/Statusline.cpp
index ef05f73099f98..65c95e1174c19 100644
--- a/lldb/source/Core/Statusline.cpp
+++ b/lldb/source/Core/Statusline.cpp
@@ -56,7 +56,7 @@ void Statusline::Enable() {
   UpdateScrollWindow(EnableStatusline);
 
   // Draw the statusline.
-  auto [exe_ctx, sym_ctx] = m_debugger.GetCurrentContext();
+  auto [exe_ctx, sym_ctx] = m_debugger.GetSelectedContext();
   Redraw(&exe_ctx, &sym_ctx);
 }
 

_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to