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] [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());

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

Reply via email to