From fc264bfdde3f3985a5fc49d9692714f00b1220e0 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Mon, 7 Apr 2025 17:04:31 -0700 Subject: [PATCH 1/2] [lldb] Make sure the process is stopped when computing the symbol context Make sure the process is stopped when computing the symbol context. Both Adrian and Felipe reported a handful of crashes in GetSymbolContext called from Statusline::Redraw on the default event thread. Given that we're handling a StackFrameSP, it's not clear to me how that could have gotten invalidated, but Jim points out that it doesn't make sense to compute the symbol context for the frame when the process isn't stopped. --- lldb/source/Core/Statusline.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lldb/source/Core/Statusline.cpp b/lldb/source/Core/Statusline.cpp index b7650503e16bc..a2ecebbefbfb1 100644 --- a/lldb/source/Core/Statusline.cpp +++ b/lldb/source/Core/Statusline.cpp @@ -12,6 +12,7 @@ #include "lldb/Host/StreamFile.h" #include "lldb/Interpreter/CommandInterpreter.h" #include "lldb/Symbol/SymbolContext.h" +#include "lldb/Target/Process.h" #include "lldb/Target/StackFrame.h" #include "lldb/Utility/AnsiTerminal.h" #include "lldb/Utility/StreamString.h" @@ -126,9 +127,7 @@ void Statusline::Redraw(bool update) { return; } - StreamString stream; - ExecutionContext exe_ctx = - m_debugger.GetCommandInterpreter().GetExecutionContext(); + 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. @@ -136,9 +135,15 @@ void Statusline::Redraw(bool update) { exe_ctx.SetTargetPtr(&m_debugger.GetSelectedOrDummyTarget()); SymbolContext symbol_ctx; - if (auto frame_sp = exe_ctx.GetFrameSP()) - symbol_ctx = frame_sp->GetSymbolContext(eSymbolContextEverything); + if (ProcessSP process_sp = exe_ctx.GetProcessSP()) { + 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; if (auto *format = m_debugger.GetStatuslineFormat()) FormatEntity::Format(*format, stream, &symbol_ctx, &exe_ctx, nullptr, nullptr, false, false); From 2bd4ee9a2c54d2c6da5fb26a399cf1badac41ceb Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Mon, 7 Apr 2025 17:19:19 -0700 Subject: [PATCH 2/2] Add comment --- lldb/source/Core/Statusline.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lldb/source/Core/Statusline.cpp b/lldb/source/Core/Statusline.cpp index a2ecebbefbfb1..e14691e2538a2 100644 --- a/lldb/source/Core/Statusline.cpp +++ b/lldb/source/Core/Statusline.cpp @@ -136,6 +136,8 @@ void Statusline::Redraw(bool update) { 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())