GDBStub: Refactor the whole code

This commit is contained in:
aldelaro5
2021-10-01 11:15:30 -04:00
parent 94a0f416eb
commit 1b92f81379
8 changed files with 279 additions and 333 deletions

View File

@ -97,6 +97,7 @@ void Run()
s_state_cpu_cvar.wait(state_lock, [] { return !s_state_paused_and_locked; });
ExecutePendingJobs(state_lock);
Common::Event gdb_step_sync_event;
switch (s_state)
{
case State::Running:
@ -130,16 +131,24 @@ void Run()
case State::Stepping:
// Wait for step command.
s_state_cpu_cvar.wait(state_lock, [&state_lock] {
s_state_cpu_cvar.wait(state_lock, [&state_lock, &gdb_step_sync_event] {
ExecutePendingJobs(state_lock);
state_lock.unlock();
if (gdb_active() && gdb_hasControl())
if (GDBStub::IsActive() && GDBStub::HasControl())
{
gdb_signal(GDB_SIGTRAP);
gdb_handle_exception(true);
GDBStub::SendSignal(GDBStub::Signal::Sigtrap);
GDBStub::ProcessCommands(true);
// If we are still going to step, emulate the fact we just sent a step command
if (gdb_hasControl())
if (GDBStub::HasControl())
{
// Make sure the previous step by gdb was serviced
if (s_state_cpu_step_instruction_sync &&
s_state_cpu_step_instruction_sync != &gdb_step_sync_event)
s_state_cpu_step_instruction_sync->Set();
s_state_cpu_step_instruction = true;
s_state_cpu_step_instruction_sync = &gdb_step_sync_event;
}
}
state_lock.lock();
return s_state_cpu_step_instruction || !IsStepping();
@ -293,6 +302,12 @@ void Break()
RunAdjacentSystems(false);
}
void Continue()
{
CPU::EnableStepping(false);
Core::CallOnStateChangedCallbacks(Core::State::Running);
}
bool PauseAndLock(bool do_lock, bool unpause_on_unlock, bool control_adjacent)
{
// NOTE: This is protected by s_stepping_lock.