-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[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 1 commit
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 |
|---|---|---|
|
|
@@ -253,16 +253,18 @@ Status Debugger::SetPropertyValue(const ExecutionContext *exe_ctx, | |
| // Statusline setting changed. If we have a statusline instance, update it | ||
| // now. Otherwise it will get created in the default event handler. | ||
| std::lock_guard<std::mutex> guard(m_statusline_mutex); | ||
| if (StatuslineSupported()) | ||
| if (StatuslineSupported()) { | ||
| m_statusline.emplace(*this); | ||
| else | ||
| m_statusline->Enable(GetSelectedExecutionContextRef()); | ||
| } else { | ||
| m_statusline.reset(); | ||
| } | ||
| } else if (property_path == | ||
| g_debugger_properties[ePropertyStatuslineFormat].name || | ||
| property_path == | ||
| g_debugger_properties[ePropertySeparator].name) { | ||
| // Statusline format changed. Redraw the statusline. | ||
| RedrawStatusline(); | ||
| RedrawStatusline(std::nullopt); | ||
| } else if (property_path == | ||
| g_debugger_properties[ePropertyUseSourceCache].name) { | ||
| // use-source-cache changed. Wipe out the cache contents if it was | ||
|
|
@@ -501,7 +503,7 @@ FormatEntity::Entry Debugger::GetStatuslineFormat() const { | |
| bool Debugger::SetStatuslineFormat(const FormatEntity::Entry &format) { | ||
| constexpr uint32_t idx = ePropertyStatuslineFormat; | ||
| bool ret = SetPropertyAtIndex(idx, format); | ||
| RedrawStatusline(); | ||
| RedrawStatusline(std::nullopt); | ||
| return ret; | ||
| } | ||
|
|
||
|
|
@@ -526,7 +528,7 @@ llvm::StringRef Debugger::GetDisabledAnsiSuffix() const { | |
| bool Debugger::SetSeparator(llvm::StringRef s) { | ||
| constexpr uint32_t idx = ePropertySeparator; | ||
| bool ret = SetPropertyAtIndex(idx, s); | ||
| RedrawStatusline(); | ||
| RedrawStatusline(std::nullopt); | ||
| return ret; | ||
| } | ||
|
|
||
|
|
@@ -1210,14 +1212,18 @@ void Debugger::RestoreInputTerminalState() { | |
| { | ||
| std::lock_guard<std::mutex> guard(m_statusline_mutex); | ||
| if (m_statusline) | ||
| m_statusline->Enable(); | ||
| m_statusline->Enable(GetSelectedExecutionContext()); | ||
| } | ||
| } | ||
|
|
||
| void Debugger::RedrawStatusline(bool update) { | ||
| void Debugger::RedrawStatusline( | ||
| std::optional<ExecutionContextRef> exe_ctx_ref) { | ||
| std::lock_guard<std::mutex> guard(m_statusline_mutex); | ||
| if (m_statusline) | ||
| m_statusline->Redraw(update); | ||
|
|
||
JDevlieghere marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (!m_statusline) | ||
| return; | ||
|
|
||
| m_statusline->Redraw(GetSelectedExecutionContextRef()); | ||
| } | ||
|
|
||
| ExecutionContext Debugger::GetSelectedExecutionContext() { | ||
|
|
@@ -1226,6 +1232,13 @@ ExecutionContext Debugger::GetSelectedExecutionContext() { | |
| return ExecutionContext(exe_ctx_ref); | ||
| } | ||
|
|
||
| ExecutionContextRef Debugger::GetSelectedExecutionContextRef() { | ||
| if (TargetSP selected_target_sp = GetSelectedTarget()) | ||
| return ExecutionContextRef(selected_target_sp.get(), | ||
| /*adopt_selected=*/true); | ||
| return ExecutionContextRef(m_dummy_target_sp.get(), /*adopt_selected=*/false); | ||
| } | ||
|
|
||
| void Debugger::DispatchInputInterrupt() { | ||
| std::lock_guard<std::recursive_mutex> guard(m_io_handler_stack.GetMutex()); | ||
| IOHandlerSP reader_sp(m_io_handler_stack.Top()); | ||
|
|
@@ -1941,8 +1954,7 @@ void Debugger::FlushProcessOutput(Process &process, bool flush_stdout, | |
| } | ||
|
|
||
| // This function handles events that were broadcast by the process. | ||
| void Debugger::HandleProcessEvent(const EventSP &event_sp) { | ||
| using namespace lldb; | ||
| ProcessSP Debugger::HandleProcessEvent(const EventSP &event_sp) { | ||
| const uint32_t event_type = event_sp->GetType(); | ||
| ProcessSP process_sp = | ||
| (event_type == Process::eBroadcastBitStructuredData) | ||
|
|
@@ -2024,23 +2036,24 @@ void Debugger::HandleProcessEvent(const EventSP &event_sp) { | |
| if (pop_process_io_handler) | ||
| process_sp->PopProcessIOHandler(); | ||
| } | ||
| return process_sp; | ||
| } | ||
|
|
||
| void Debugger::HandleThreadEvent(const EventSP &event_sp) { | ||
| ThreadSP Debugger::HandleThreadEvent(const EventSP &event_sp) { | ||
| // At present the only thread event we handle is the Frame Changed event, and | ||
| // all we do for that is just reprint the thread status for that thread. | ||
| using namespace lldb; | ||
| const uint32_t event_type = event_sp->GetType(); | ||
| const bool stop_format = true; | ||
| ThreadSP thread_sp; | ||
| if (event_type == Thread::eBroadcastBitStackChanged || | ||
| event_type == Thread::eBroadcastBitThreadSelected) { | ||
| ThreadSP thread_sp( | ||
| Thread::ThreadEventData::GetThreadFromEvent(event_sp.get())); | ||
| thread_sp = Thread::ThreadEventData::GetThreadFromEvent(event_sp.get()); | ||
| if (thread_sp) { | ||
| thread_sp->GetStatus(*GetAsyncOutputStream(), 0, 1, 1, stop_format, | ||
| /*show_hidden*/ true); | ||
| } | ||
| } | ||
| return thread_sp; | ||
| } | ||
|
|
||
| bool Debugger::IsForwardingEvents() { return (bool)m_forward_listener_sp; } | ||
|
|
@@ -2109,28 +2122,33 @@ lldb::thread_result_t Debugger::DefaultEventHandler() { | |
|
|
||
| if (StatuslineSupported()) { | ||
| std::lock_guard<std::mutex> guard(m_statusline_mutex); | ||
| if (!m_statusline) | ||
| if (!m_statusline) { | ||
| m_statusline.emplace(*this); | ||
| m_statusline->Enable(GetSelectedExecutionContextRef()); | ||
| } | ||
| } | ||
|
|
||
| bool done = false; | ||
| while (!done) { | ||
| EventSP event_sp; | ||
| if (listener_sp->GetEvent(event_sp, std::nullopt)) { | ||
| std::optional<ExecutionContextRef> exe_ctx_ref = std::nullopt; | ||
| if (event_sp) { | ||
| Broadcaster *broadcaster = event_sp->GetBroadcaster(); | ||
| if (broadcaster) { | ||
| uint32_t event_type = event_sp->GetType(); | ||
| ConstString broadcaster_class(broadcaster->GetBroadcasterClass()); | ||
| if (broadcaster_class == broadcaster_class_process) { | ||
| HandleProcessEvent(event_sp); | ||
| if (ProcessSP process_sp = HandleProcessEvent(event_sp)) | ||
| exe_ctx_ref = ExecutionContext(process_sp); | ||
|
||
| } else if (broadcaster_class == broadcaster_class_target) { | ||
| if (Breakpoint::BreakpointEventData::GetEventDataFromEvent( | ||
| event_sp.get())) { | ||
| HandleBreakpointEvent(event_sp); | ||
| } | ||
| } else if (broadcaster_class == broadcaster_class_thread) { | ||
| HandleThreadEvent(event_sp); | ||
| if (ThreadSP thread_sp = HandleThreadEvent(event_sp)) | ||
| exe_ctx_ref = ExecutionContext(thread_sp); | ||
| } else if (broadcaster == m_command_interpreter_up.get()) { | ||
| if (event_type & | ||
| CommandInterpreter::eBroadcastBitQuitCommandReceived) { | ||
|
|
@@ -2168,7 +2186,7 @@ lldb::thread_result_t Debugger::DefaultEventHandler() { | |
| if (m_forward_listener_sp) | ||
| m_forward_listener_sp->AddEvent(event_sp); | ||
| } | ||
| RedrawStatusline(); | ||
| RedrawStatusline(exe_ctx_ref); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| 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=*/true); | ||
|
|
||
| // 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); | ||
|
Collaborator
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?
Member
Author
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
Collaborator
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.