-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[lldb] Rework how we pass the execution context to the statusline #159887
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
4fe7308
afdf9a7
06817bb
8966b2c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,9 +35,7 @@ using namespace lldb_private; | |
|
||
Statusline::Statusline(Debugger &debugger) | ||
: m_debugger(debugger), m_terminal_width(m_debugger.GetTerminalWidth()), | ||
m_terminal_height(m_debugger.GetTerminalHeight()) { | ||
Enable(); | ||
} | ||
m_terminal_height(m_debugger.GetTerminalHeight()) {} | ||
JDevlieghere marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Statusline::~Statusline() { Disable(); } | ||
|
||
|
@@ -47,16 +45,16 @@ void Statusline::TerminalSizeChanged() { | |
|
||
UpdateScrollWindow(ResizeStatusline); | ||
|
||
// Draw the old statusline. | ||
Redraw(/*update=*/false); | ||
// Redraw the old statusline. | ||
Redraw(std::nullopt); | ||
} | ||
|
||
void Statusline::Enable() { | ||
void Statusline::Enable(std::optional<ExecutionContextRef> exe_ctx_ref) { | ||
// Reduce the scroll window to make space for the status bar below. | ||
UpdateScrollWindow(EnableStatusline); | ||
|
||
// Draw the statusline. | ||
Redraw(/*update=*/true); | ||
Redraw(exe_ctx_ref); | ||
} | ||
|
||
void Statusline::Disable() { | ||
|
@@ -69,8 +67,6 @@ void Statusline::Draw(std::string str) { | |
if (!stream_sp) | ||
return; | ||
|
||
m_last_str = str; | ||
|
||
str = ansi::TrimAndPad(str, m_terminal_width); | ||
|
||
LockedStreamFile locked_stream = stream_sp->Lock(); | ||
|
@@ -127,33 +123,30 @@ void Statusline::UpdateScrollWindow(ScrollWindowMode mode) { | |
m_debugger.RefreshIOHandler(); | ||
} | ||
|
||
void Statusline::Redraw(bool update) { | ||
if (!update) { | ||
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); | ||
} | ||
void Statusline::Redraw(std::optional<ExecutionContextRef> exe_ctx_ref) { | ||
// Update the cached execution context. | ||
if (exe_ctx_ref) | ||
m_exe_ctx_ref = *exe_ctx_ref; | ||
|
||
// Lock the execution context. | ||
ExecutionContext exe_ctx = | ||
m_exe_ctx_ref.Lock(/*thread_and_frame_only_if_stopped=*/false); | ||
|
||
// Compute the symbol context if we're stopped. | ||
SymbolContext sym_ctx; | ||
llvm::Expected<StoppedExecutionContext> stopped_exe_ctx = | ||
GetStoppedExecutionContext(&m_exe_ctx_ref); | ||
if (stopped_exe_ctx) { | ||
if (auto frame_sp = stopped_exe_ctx->GetFrameSP()) | ||
sym_ctx = frame_sp->GetSymbolContext(eSymbolContextEverything); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I kinda want an assert here if this isn't true. How could a StoppedExecutionContext not have a frame? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A little counter-intuitively, the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, makes sense. Might want to add that as a comment, since that's not 100% obvious. |
||
} else { | ||
// We can draw the statusline without being stopped. | ||
llvm::consumeError(stopped_exe_ctx.takeError()); | ||
} | ||
|
||
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()); | ||
|
Uh oh!
There was an error while loading. Please reload this page.