Debugger: Allow to unpause a thread which has been paused by global pause

This commit is contained in:
Eladash 2021-01-31 20:25:15 +02:00 committed by Ivan
parent cf6606065d
commit cfc7865f82

View file

@ -33,6 +33,8 @@
constexpr auto qstr = QString::fromStdString; constexpr auto qstr = QString::fromStdString;
constexpr auto s_pause_flags = cpu_flag::dbg_pause + cpu_flag::dbg_global_pause;
debugger_frame::debugger_frame(std::shared_ptr<gui_settings> settings, QWidget *parent) debugger_frame::debugger_frame(std::shared_ptr<gui_settings> settings, QWidget *parent)
: custom_dock_widget(tr("Debugger"), parent), xgui_settings(settings) : custom_dock_widget(tr("Debugger"), parent), xgui_settings(settings)
{ {
@ -140,11 +142,24 @@ debugger_frame::debugger_frame(std::shared_ptr<gui_settings> settings, QWidget *
{ {
if (const auto cpu = get_cpu()) if (const auto cpu = get_cpu())
{ {
// Alter dbg_pause bit state (disable->enable, enable->disable) // If paused, unpause.
const auto old = cpu->state.xor_fetch(cpu_flag::dbg_pause); // If not paused, add dbg_pause.
const auto old = cpu->state.atomic_op([](bs_t<cpu_flag>& state)
{
if (state & s_pause_flags)
{
state -= s_pause_flags;
}
else
{
state += cpu_flag::dbg_pause;
}
return state;
});
// Notify only if no pause flags are set after this change // Notify only if no pause flags are set after this change
if (!(old & (cpu_flag::dbg_pause + cpu_flag::dbg_global_pause))) if (!(old & s_pause_flags))
{ {
cpu->notify(); cpu->notify();
} }
@ -441,7 +456,7 @@ void debugger_frame::UpdateUI()
m_last_pc = cia; m_last_pc = cia;
DoUpdate(); DoUpdate();
if (cpu->state & cpu_flag::dbg_pause) if (cpu->state & s_pause_flags)
{ {
m_btn_run->setText(RunString); m_btn_run->setText(RunString);
m_btn_step->setEnabled(true); m_btn_step->setEnabled(true);
@ -725,13 +740,7 @@ void debugger_frame::DoStep(bool stepOver)
{ {
bool should_step_over = stepOver && cpu->id_type() == 1; bool should_step_over = stepOver && cpu->id_type() == 1;
if (+cpu_flag::dbg_pause & +cpu->state.fetch_op([&](bs_t<cpu_flag>& state) if (cpu->state & s_pause_flags)
{
if (!should_step_over)
state += cpu_flag::dbg_step;
state -= cpu_flag::dbg_pause;
}))
{ {
if (should_step_over) if (should_step_over)
{ {
@ -751,6 +760,13 @@ void debugger_frame::DoStep(bool stepOver)
m_last_step_over_breakpoint = next_instruction_pc; m_last_step_over_breakpoint = next_instruction_pc;
} }
cpu->state.atomic_op([&](bs_t<cpu_flag>& state)
{
state -= s_pause_flags;
if (!should_step_over) state += cpu_flag::dbg_step;
});
cpu->notify(); cpu->notify();
} }
} }