diff options
author | FalseHonesty <thefalsehonesty@gmail.com> | 2021-04-13 17:01:30 -0400 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-04-21 13:42:09 +0200 |
commit | 58d6781cbbea972f343e483ee30aae835f365fdb (patch) | |
tree | e46ca265a62946750d3ad3a263cbd8e46621b81a | |
parent | 5a31ca06db58a121f11b698e03a2b228d4349dc1 (diff) | |
download | serenity-58d6781cbbea972f343e483ee30aae835f365fdb.zip |
HackStudio+LibDebug: Support stopping a debugged process
In LibDebug this required implementing the Kill debug action, and
in HackStudio this required making the toolbar's stop action stop
the debugger if active.
-rw-r--r-- | Userland/DevTools/HackStudio/Debugger/Debugger.cpp | 11 | ||||
-rw-r--r-- | Userland/DevTools/HackStudio/Debugger/Debugger.h | 2 | ||||
-rw-r--r-- | Userland/DevTools/HackStudio/HackStudioWidget.cpp | 17 | ||||
-rw-r--r-- | Userland/Libraries/LibDebug/DebugSession.h | 3 |
4 files changed, 24 insertions, 9 deletions
diff --git a/Userland/DevTools/HackStudio/Debugger/Debugger.cpp b/Userland/DevTools/HackStudio/Debugger/Debugger.cpp index 7f8ef8eada..dda63c1ada 100644 --- a/Userland/DevTools/HackStudio/Debugger/Debugger.cpp +++ b/Userland/DevTools/HackStudio/Debugger/Debugger.cpp @@ -110,6 +110,11 @@ int Debugger::start_static() return 0; } +void Debugger::stop() +{ + set_requested_debugger_action(DebuggerAction::Exit); +} + void Debugger::start() { m_debug_session = Debug::DebugSession::exec_and_attach(m_executable_path, m_source_root); @@ -190,11 +195,9 @@ int Debugger::debugger_loop() do_step_over(regs); return Debug::DebugSession::DebugDecision::Continue; case DebuggerAction::Exit: - // NOTE: Is detaching from the debuggee the best thing to do here? - // We could display a dialog in the UI, remind the user that there is - // a live debugged process, and ask whether they want to terminate/detach. dbgln("Debugger exiting"); - return Debug::DebugSession::DebugDecision::Detach; + m_on_exit_callback(); + return Debug::DebugSession::DebugDecision::Kill; } VERIFY_NOT_REACHED(); }); diff --git a/Userland/DevTools/HackStudio/Debugger/Debugger.h b/Userland/DevTools/HackStudio/Debugger/Debugger.h index 1228a1ac0e..d3a2a151e1 100644 --- a/Userland/DevTools/HackStudio/Debugger/Debugger.h +++ b/Userland/DevTools/HackStudio/Debugger/Debugger.h @@ -60,6 +60,8 @@ public: Debug::DebugSession* session() { return m_debug_session.ptr(); } + void stop(); + // Thread entry point static int start_static(); diff --git a/Userland/DevTools/HackStudio/HackStudioWidget.cpp b/Userland/DevTools/HackStudio/HackStudioWidget.cpp index 3382a5dfe2..ef0d683d0d 100644 --- a/Userland/DevTools/HackStudio/HackStudioWidget.cpp +++ b/Userland/DevTools/HackStudio/HackStudioWidget.cpp @@ -626,6 +626,7 @@ NonnullRefPtr<GUI::Action> HackStudioWidget::create_debug_action() Debugger::the().set_executable_path(get_project_executable_path()); m_debugger_thread = LibThread::Thread::construct(Debugger::start_static); m_debugger_thread->start(); + m_stop_action->set_enabled(true); }); } @@ -662,16 +663,19 @@ void HackStudioWidget::initialize_debugger() [this]() { Core::EventLoop::main().post_event(*window(), make<Core::DeferredInvocationEvent>([this](auto&) { m_debug_info_widget->set_debug_actions_enabled(false); - if (m_current_editor_in_execution) { + if (m_current_editor_in_execution) m_current_editor_in_execution->editor().clear_execution_position(); - } })); Core::EventLoop::wake(); }, [this]() { Core::EventLoop::main().post_event(*window(), make<Core::DeferredInvocationEvent>([this](auto&) { + m_debug_info_widget->set_debug_actions_enabled(false); + if (m_current_editor_in_execution) + m_current_editor_in_execution->editor().clear_execution_position(); m_debug_info_widget->program_stopped(); m_disassembly_widget->program_stopped(); + m_stop_action->set_enabled(false); HackStudioWidget::hide_action_tabs(); GUI::MessageBox::show(window(), "Program Exited", "Debugger", GUI::MessageBox::Type::Information); })); @@ -1060,7 +1064,12 @@ void HackStudioWidget::create_help_menubar(GUI::Menubar& menubar) NonnullRefPtr<GUI::Action> HackStudioWidget::create_stop_action() { auto action = GUI::Action::create("&Stop", Gfx::Bitmap::load_from_file("/res/icons/16x16/program-stop.png"), [this](auto&) { - m_terminal_wrapper->kill_running_command(); + if (!Debugger::the().session()) { + m_terminal_wrapper->kill_running_command(); + return; + } + + Debugger::the().stop(); }); action->set_enabled(false); @@ -1089,7 +1098,7 @@ void HackStudioWidget::initialize_menubar(GUI::Menubar& menubar) HackStudioWidget::~HackStudioWidget() { if (!m_debugger_thread.is_null()) { - Debugger::the().set_requested_debugger_action(Debugger::DebuggerAction::Exit); + Debugger::the().stop(); dbgln("Waiting for debugger thread to terminate"); auto rc = m_debugger_thread->join(); if (rc.is_error()) { diff --git a/Userland/Libraries/LibDebug/DebugSession.h b/Userland/Libraries/LibDebug/DebugSession.h index 993ca4c805..89f12a6c8e 100644 --- a/Userland/Libraries/LibDebug/DebugSession.h +++ b/Userland/Libraries/LibDebug/DebugSession.h @@ -352,7 +352,8 @@ void DebugSession::run(DesiredInitialDebugeeState initial_debugee_state, Callbac break; } if (decision == DebugDecision::Kill) { - VERIFY_NOT_REACHED(); // TODO: implement + kill(m_debuggee_pid, SIGTERM); + break; } if (state == State::SingleStep && !did_single_step) { |