Skip to content

Commit e84a804

Browse files
authored
[lldb] Make sure the process is stopped when computing the symbol context (#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.
1 parent 19ee7ff commit e84a804

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

lldb/source/Core/Statusline.cpp

+12-5
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"
@@ -126,19 +127,25 @@ void Statusline::Redraw(bool update) {
126127
return;
127128
}
128129

129-
StreamString stream;
130-
ExecutionContext exe_ctx =
131-
m_debugger.GetCommandInterpreter().GetExecutionContext();
130+
ExecutionContext exe_ctx = m_debugger.GetSelectedExecutionContext();
132131

133132
// For colors and progress events, the format entity needs access to the
134133
// debugger, which requires a target in the execution context.
135134
if (!exe_ctx.HasTargetScope())
136135
exe_ctx.SetTargetPtr(&m_debugger.GetSelectedOrDummyTarget());
137136

138137
SymbolContext symbol_ctx;
139-
if (auto frame_sp = exe_ctx.GetFrameSP())
140-
symbol_ctx = frame_sp->GetSymbolContext(eSymbolContextEverything);
138+
if (ProcessSP process_sp = exe_ctx.GetProcessSP()) {
139+
// Check if the process is stopped, and if it is, make sure it remains
140+
// stopped until we've computed the symbol context.
141+
Process::StopLocker stop_locker;
142+
if (stop_locker.TryLock(&process_sp->GetRunLock())) {
143+
if (auto frame_sp = exe_ctx.GetFrameSP())
144+
symbol_ctx = frame_sp->GetSymbolContext(eSymbolContextEverything);
145+
}
146+
}
141147

148+
StreamString stream;
142149
if (auto *format = m_debugger.GetStatuslineFormat())
143150
FormatEntity::Format(*format, stream, &symbol_ctx, &exe_ctx, nullptr,
144151
nullptr, false, false);

0 commit comments

Comments
 (0)