1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 16:47:36 +00:00

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.
This commit is contained in:
FalseHonesty 2021-04-13 17:01:30 -04:00 committed by Linus Groh
parent 5a31ca06db
commit 58d6781cbb
4 changed files with 24 additions and 9 deletions

View file

@ -110,6 +110,11 @@ int Debugger::start_static()
return 0; return 0;
} }
void Debugger::stop()
{
set_requested_debugger_action(DebuggerAction::Exit);
}
void Debugger::start() void Debugger::start()
{ {
m_debug_session = Debug::DebugSession::exec_and_attach(m_executable_path, m_source_root); 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); do_step_over(regs);
return Debug::DebugSession::DebugDecision::Continue; return Debug::DebugSession::DebugDecision::Continue;
case DebuggerAction::Exit: 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"); dbgln("Debugger exiting");
return Debug::DebugSession::DebugDecision::Detach; m_on_exit_callback();
return Debug::DebugSession::DebugDecision::Kill;
} }
VERIFY_NOT_REACHED(); VERIFY_NOT_REACHED();
}); });

View file

@ -60,6 +60,8 @@ public:
Debug::DebugSession* session() { return m_debug_session.ptr(); } Debug::DebugSession* session() { return m_debug_session.ptr(); }
void stop();
// Thread entry point // Thread entry point
static int start_static(); static int start_static();

View file

@ -626,6 +626,7 @@ NonnullRefPtr<GUI::Action> HackStudioWidget::create_debug_action()
Debugger::the().set_executable_path(get_project_executable_path()); Debugger::the().set_executable_path(get_project_executable_path());
m_debugger_thread = LibThread::Thread::construct(Debugger::start_static); m_debugger_thread = LibThread::Thread::construct(Debugger::start_static);
m_debugger_thread->start(); m_debugger_thread->start();
m_stop_action->set_enabled(true);
}); });
} }
@ -662,16 +663,19 @@ void HackStudioWidget::initialize_debugger()
[this]() { [this]() {
Core::EventLoop::main().post_event(*window(), make<Core::DeferredInvocationEvent>([this](auto&) { Core::EventLoop::main().post_event(*window(), make<Core::DeferredInvocationEvent>([this](auto&) {
m_debug_info_widget->set_debug_actions_enabled(false); 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(); m_current_editor_in_execution->editor().clear_execution_position();
}
})); }));
Core::EventLoop::wake(); Core::EventLoop::wake();
}, },
[this]() { [this]() {
Core::EventLoop::main().post_event(*window(), make<Core::DeferredInvocationEvent>([this](auto&) { 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_debug_info_widget->program_stopped();
m_disassembly_widget->program_stopped(); m_disassembly_widget->program_stopped();
m_stop_action->set_enabled(false);
HackStudioWidget::hide_action_tabs(); HackStudioWidget::hide_action_tabs();
GUI::MessageBox::show(window(), "Program Exited", "Debugger", GUI::MessageBox::Type::Information); 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() 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&) { 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); action->set_enabled(false);
@ -1089,7 +1098,7 @@ void HackStudioWidget::initialize_menubar(GUI::Menubar& menubar)
HackStudioWidget::~HackStudioWidget() HackStudioWidget::~HackStudioWidget()
{ {
if (!m_debugger_thread.is_null()) { 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"); dbgln("Waiting for debugger thread to terminate");
auto rc = m_debugger_thread->join(); auto rc = m_debugger_thread->join();
if (rc.is_error()) { if (rc.is_error()) {

View file

@ -352,7 +352,8 @@ void DebugSession::run(DesiredInitialDebugeeState initial_debugee_state, Callbac
break; break;
} }
if (decision == DebugDecision::Kill) { if (decision == DebugDecision::Kill) {
VERIFY_NOT_REACHED(); // TODO: implement kill(m_debuggee_pid, SIGTERM);
break;
} }
if (state == State::SingleStep && !did_single_step) { if (state == State::SingleStep && !did_single_step) {