Skip to content

Commit 8ed72ef

Browse files
committed
[lldb] Make sure the process is stopped when computing the symbol context (llvm#134757)
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. (cherry picked from commit e84a804)
1 parent 2ae8d3f commit 8ed72ef

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

lldb/source/Core/Statusline.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "lldb/Host/StreamFile.h"
1313
#include "lldb/Interpreter/CommandInterpreter.h"
1414
#include "lldb/Symbol/SymbolContext.h"
15+
#include "lldb/Target/Process.h"
1516
#include "lldb/Target/StackFrame.h"
1617
#include "lldb/Utility/AnsiTerminal.h"
1718
#include "lldb/Utility/StreamString.h"
@@ -119,19 +120,25 @@ void Statusline::Redraw(bool update) {
119120
return;
120121
}
121122

122-
StreamString stream;
123-
ExecutionContext exe_ctx =
124-
m_debugger.GetCommandInterpreter().GetExecutionContext();
123+
ExecutionContext exe_ctx = m_debugger.GetSelectedExecutionContext();
125124

126125
// For colors and progress events, the format entity needs access to the
127126
// debugger, which requires a target in the execution context.
128127
if (!exe_ctx.HasTargetScope())
129128
exe_ctx.SetTargetPtr(&m_debugger.GetSelectedOrDummyTarget());
130129

131130
SymbolContext symbol_ctx;
132-
if (auto frame_sp = exe_ctx.GetFrameSP())
133-
symbol_ctx = frame_sp->GetSymbolContext(eSymbolContextEverything);
131+
if (ProcessSP process_sp = exe_ctx.GetProcessSP()) {
132+
// Check if the process is stopped, and if it is, make sure it remains
133+
// stopped until we've computed the symbol context.
134+
Process::StopLocker stop_locker;
135+
if (stop_locker.TryLock(&process_sp->GetRunLock())) {
136+
if (auto frame_sp = exe_ctx.GetFrameSP())
137+
symbol_ctx = frame_sp->GetSymbolContext(eSymbolContextEverything);
138+
}
139+
}
134140

141+
StreamString stream;
135142
if (auto *format = m_debugger.GetStatuslineFormat())
136143
FormatEntity::Format(*format, stream, &symbol_ctx, &exe_ctx, nullptr,
137144
nullptr, false, false);

0 commit comments

Comments
 (0)