From 1ec917aa23dbc0e3d95e0dfe5f279971789cfcb8 Mon Sep 17 00:00:00 2001 From: Itamar Date: Mon, 20 Dec 2021 22:42:03 +0200 Subject: [PATCH] HackStudio: Attach debuggee to "Console" terminal tab Previously the debuggee process used the same tty of the HackStudio process. We now set things up so the debuggee gets attached to the TerminalWrapper in the "Console" tab. --- Userland/DevTools/HackStudio/Debugger/Debugger.cpp | 8 +++++++- Userland/DevTools/HackStudio/Debugger/Debugger.h | 3 +++ Userland/DevTools/HackStudio/HackStudioWidget.cpp | 14 ++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/Userland/DevTools/HackStudio/Debugger/Debugger.cpp b/Userland/DevTools/HackStudio/Debugger/Debugger.cpp index 4f2a4c6447..b2464e8e54 100644 --- a/Userland/DevTools/HackStudio/Debugger/Debugger.cpp +++ b/Userland/DevTools/HackStudio/Debugger/Debugger.cpp @@ -112,7 +112,13 @@ void Debugger::stop() void Debugger::start() { - m_debug_session = Debug::DebugSession::exec_and_attach(m_executable_path, m_source_root); + + auto child_setup_callback = [this]() { + if (m_child_setup_callback) + return m_child_setup_callback(); + return ErrorOr {}; + }; + m_debug_session = Debug::DebugSession::exec_and_attach(m_executable_path, m_source_root, move(child_setup_callback)); VERIFY(!!m_debug_session); for (const auto& breakpoint : m_breakpoints) { diff --git a/Userland/DevTools/HackStudio/Debugger/Debugger.h b/Userland/DevTools/HackStudio/Debugger/Debugger.h index 1ef6f67bc4..eca9d30b76 100644 --- a/Userland/DevTools/HackStudio/Debugger/Debugger.h +++ b/Userland/DevTools/HackStudio/Debugger/Debugger.h @@ -60,6 +60,8 @@ public: void set_requested_debugger_action(DebuggerAction); void reset_breakpoints() { m_breakpoints.clear(); } + void set_child_setup_callback(Function()> callback) { m_child_setup_callback = move(callback); } + private: class DebuggingState { public: @@ -119,6 +121,7 @@ private: Function m_on_stopped_callback; Function m_on_continue_callback; Function m_on_exit_callback; + Function()> m_child_setup_callback; }; } diff --git a/Userland/DevTools/HackStudio/HackStudioWidget.cpp b/Userland/DevTools/HackStudio/HackStudioWidget.cpp index 320fdcca98..63977a92d4 100644 --- a/Userland/DevTools/HackStudio/HackStudioWidget.cpp +++ b/Userland/DevTools/HackStudio/HackStudioWidget.cpp @@ -797,6 +797,20 @@ NonnullRefPtr HackStudioWidget::create_debug_action() } Debugger::the().set_executable_path(get_project_executable_path()); + + m_terminal_wrapper->clear_including_history(); + + // The debugger calls wait() on the debugee, so the TerminalWrapper can't do that. + auto ptm_res = m_terminal_wrapper->setup_master_pseudoterminal(TerminalWrapper::WaitForChildOnExit::No); + if (ptm_res.is_error()) { + perror("setup_master_pseudoterminal"); + return; + } + + Debugger::the().set_child_setup_callback([this, ptm_res]() { + return m_terminal_wrapper->setup_slave_pseudoterminal(ptm_res.value()); + }); + m_debugger_thread = Threading::Thread::construct(Debugger::start_static); m_debugger_thread->start(); m_stop_action->set_enabled(true);