[Lldb-commits] [lldb] [lldb] Real-time console pane for output in lldb tui (PR #177160)
Nagesh Nazare via lldb-commits
lldb-commits at lists.llvm.org
Tue Apr 7 08:53:47 PDT 2026
================
@@ -6309,6 +6309,236 @@ HandleCharResult HelpDialogDelegate::WindowDelegateHandleChar(Window &window,
return eKeyHandled;
}
+class ConsoleOutputWindowDelegate : public WindowDelegate {
+private:
+ void PollProcessOutput() {
+ ExecutionContext exe_ctx =
+ m_debugger.GetCommandInterpreter().GetExecutionContext();
+ Process *process = exe_ctx.GetProcessPtr();
+
+ if (!process || !process->IsAlive())
+ return;
+
+ // Buffer for reading output.
+ char buffer[1024];
+ Status error;
+
+ // Read process's stdout.
+ size_t stdout_bytes = process->GetSTDOUT(buffer, sizeof(buffer) - 1, error);
+ if (stdout_bytes > 0) {
+ buffer[stdout_bytes] = '\0';
+ AppendOutput(buffer, false);
+ }
+
+ // Read process's stderr.
+ size_t stderr_bytes = process->GetSTDERR(buffer, sizeof(buffer) - 1, error);
+ if (stderr_bytes > 0) {
+ buffer[stderr_bytes] = '\0';
+ AppendOutput(buffer, true);
+ }
+ }
+
+ void AppendOutput(const char *text, bool is_stderr) {
+ if (!text || text[0] == '\0')
+ return;
+
+ std::lock_guard<std::mutex> lock(m_output_mutex);
+
+ // Split text into lines and add to buffer.
+ std::string remaining = m_partial_line;
+ remaining += text;
+
+ size_t start = 0, pos = 0;
+ while ((pos = remaining.find('\n', start)) != std::string::npos) {
+ std::string line = remaining.substr(start, pos - start);
+ if (is_stderr)
+ line = "[stderr] " + line;
+ m_output_lines.push_back(line);
+
+ // Keep buffer size under limit.
+ while (m_output_lines.size() > m_max_lines) {
+ m_output_lines.pop_front();
+ if (m_first_visible_line > 0)
+ --m_first_visible_line;
+ }
+
+ start = pos + 1;
+ }
+
+ // Save any remaining partial line.
+ m_partial_line = remaining.substr(start);
+
+ // Auto-scroll to bottom if enabled.
+ if (m_auto_scroll && !m_output_lines.empty()) {
+ m_first_visible_line =
+ m_output_lines.size() > 0 ? m_output_lines.size() - 1 : 0;
+ }
+ }
+
+public:
+ ConsoleOutputWindowDelegate(Debugger &debugger)
+ : m_debugger(debugger), m_first_visible_line(0), m_auto_scroll(true),
+ m_max_lines(10000) {}
----------------
nageshnnazare wrote:
Added a variable to set non-default value
https://github.com/llvm/llvm-project/pull/177160
More information about the lldb-commits
mailing list