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.
This commit is contained in:
Itamar 2021-12-20 22:42:03 +02:00 committed by Brian Gianforcaro
parent a02d8e5710
commit 1ec917aa23
3 changed files with 24 additions and 1 deletions

View file

@ -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<void> {};
};
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) {

View file

@ -60,6 +60,8 @@ public:
void set_requested_debugger_action(DebuggerAction);
void reset_breakpoints() { m_breakpoints.clear(); }
void set_child_setup_callback(Function<ErrorOr<void>()> callback) { m_child_setup_callback = move(callback); }
private:
class DebuggingState {
public:
@ -119,6 +121,7 @@ private:
Function<HasControlPassedToUser(const PtraceRegisters&)> m_on_stopped_callback;
Function<void()> m_on_continue_callback;
Function<void()> m_on_exit_callback;
Function<ErrorOr<void>()> m_child_setup_callback;
};
}

View file

@ -797,6 +797,20 @@ NonnullRefPtr<GUI::Action> 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);