mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:07:34 +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:
parent
5a31ca06db
commit
58d6781cbb
4 changed files with 24 additions and 9 deletions
|
@ -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();
|
||||
});
|
||||
|
|
|
@ -60,6 +60,8 @@ public:
|
|||
|
||||
Debug::DebugSession* session() { return m_debug_session.ptr(); }
|
||||
|
||||
void stop();
|
||||
|
||||
// Thread entry point
|
||||
static int start_static();
|
||||
|
||||
|
|
|
@ -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&) {
|
||||
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()) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue