Debugger: Visually show what CPU triggered a breakpoint

This commit is contained in:
Ty Lamontagne 2023-10-15 12:44:37 -04:00 committed by refractionpcsx2
parent 95d1dcc521
commit be405eb705
8 changed files with 43 additions and 14 deletions

View File

@ -48,7 +48,7 @@ DebuggerWindow::DebuggerWindow(QWidget* parent)
connect(g_emu_thread, &EmuThread::onVMResumed, this, &DebuggerWindow::onVMStateChanged);
onVMStateChanged(); // If we missed a state change while we weren't loaded
// We can't do this in the designer, but we want to right align the actionOnTop action in the toolbar
QWidget* spacer = new QWidget(this);
spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
@ -67,6 +67,14 @@ DebuggerWindow::DebuggerWindow(QWidget* parent)
DebuggerWindow::~DebuggerWindow() = default;
// There is no straightforward way to set the tab text to bold in Qt
// Sorry colour blind people, but this is the best we can do for now
void DebuggerWindow::setTabActiveStyle(BreakPointCpu enabledCpu)
{
m_ui.cpuTabs->tabBar()->setTabTextColor(m_ui.cpuTabs->indexOf(m_cpuWidget_r5900), (enabledCpu == BREAKPOINT_EE) ? Qt::red : this->palette().text().color());
m_ui.cpuTabs->tabBar()->setTabTextColor(m_ui.cpuTabs->indexOf(m_cpuWidget_r3000), (enabledCpu == BREAKPOINT_IOP) ? Qt::red : this->palette().text().color());
}
void DebuggerWindow::onVMStateChanged()
{
if (!QtHost::IsVMPaused())
@ -76,6 +84,7 @@ void DebuggerWindow::onVMStateChanged()
m_ui.actionStepInto->setEnabled(false);
m_ui.actionStepOver->setEnabled(false);
m_ui.actionStepOut->setEnabled(false);
setTabActiveStyle(BREAKPOINT_IOP_AND_EE);
}
else
{
@ -84,17 +93,32 @@ void DebuggerWindow::onVMStateChanged()
m_ui.actionStepInto->setEnabled(true);
m_ui.actionStepOver->setEnabled(true);
m_ui.actionStepOut->setEnabled(true);
Host::RunOnCPUThread([] {
if (CBreakPoints::GetBreakpointTriggered())
// Switch to the CPU tab that triggered the breakpoint
// Also bold the tab text to indicate that a breakpoint was triggered
if (CBreakPoints::GetBreakpointTriggered())
{
const BreakPointCpu triggeredCpu = CBreakPoints::GetBreakpointTriggeredCpu();
setTabActiveStyle(triggeredCpu);
switch (triggeredCpu)
{
case BREAKPOINT_EE:
m_ui.cpuTabs->setCurrentWidget(m_cpuWidget_r5900);
break;
case BREAKPOINT_IOP:
m_ui.cpuTabs->setCurrentWidget(m_cpuWidget_r3000);
break;
default:
break;
}
Host::RunOnCPUThread([] {
CBreakPoints::ClearTemporaryBreakPoints();
CBreakPoints::SetBreakpointTriggered(false);
CBreakPoints::SetBreakpointTriggered(false, BREAKPOINT_IOP_AND_EE);
// Our current PC is on a breakpoint.
// When we run the core again, we want to skip this breakpoint and run
CBreakPoints::SetSkipFirst(BREAKPOINT_EE, r5900Debug.getPC());
CBreakPoints::SetSkipFirst(BREAKPOINT_IOP, r3000Debug.getPC());
}
});
});
}
}
return;
}

View File

@ -44,4 +44,6 @@ private:
CpuWidget* m_cpuWidget_r5900;
CpuWidget* m_cpuWidget_r3000;
};
void setTabActiveStyle(BreakPointCpu toggledCPU);
};

View File

@ -30,6 +30,7 @@ u64 CBreakPoints::breakSkipFirstTicksIop_ = 0;
std::vector<MemCheck> CBreakPoints::memChecks_;
std::vector<MemCheck*> CBreakPoints::cleanupMemChecks_;
bool CBreakPoints::breakpointTriggered_ = false;
BreakPointCpu CBreakPoints::breakpointTriggeredCpu_;
bool CBreakPoints::corePaused = false;
std::function<void()> CBreakPoints::cb_bpUpdated_;

View File

@ -153,8 +153,9 @@ public:
static void Update(BreakPointCpu cpu = BREAKPOINT_IOP_AND_EE, u32 addr = 0);
static void SetBreakpointTriggered(bool b) { breakpointTriggered_ = b; };
static void SetBreakpointTriggered(bool triggered, BreakPointCpu cpu = BreakPointCpu::BREAKPOINT_IOP_AND_EE) { breakpointTriggered_ = triggered; breakpointTriggeredCpu_ = cpu; };
static bool GetBreakpointTriggered() { return breakpointTriggered_; };
static BreakPointCpu GetBreakpointTriggeredCpu() { return breakpointTriggeredCpu_; };
static bool GetCorePaused() { return corePaused; };
static void SetCorePaused(bool b) { corePaused = b; };
@ -175,6 +176,7 @@ private:
static u64 breakSkipFirstTicksIop_;
static bool breakpointTriggered_;
static BreakPointCpu breakpointTriggeredCpu_;
static bool corePaused;
static std::function<void()> cb_bpUpdated_;

View File

@ -54,7 +54,7 @@ void intBreakpoint(bool memcheck)
return;
}
CBreakPoints::SetBreakpointTriggered(true);
CBreakPoints::SetBreakpointTriggered(true, BREAKPOINT_EE);
VMManager::SetPaused(true);
Cpu->ExitExecution();
}

View File

@ -143,7 +143,7 @@ void psxBreakpoint(bool memcheck)
return;
}
CBreakPoints::SetBreakpointTriggered(true);
CBreakPoints::SetBreakpointTriggered(true, BREAKPOINT_IOP);
VMManager::SetPaused(true);
Cpu->ExitExecution();
}

View File

@ -1289,7 +1289,7 @@ static bool psxDynarecCheckBreakpoint()
if (!hit)
return false;
CBreakPoints::SetBreakpointTriggered(true);
CBreakPoints::SetBreakpointTriggered(true, BREAKPOINT_IOP);
VMManager::SetPaused(true);
// Exit the EE too.
@ -1303,7 +1303,7 @@ static bool psxDynarecMemcheck()
if (CBreakPoints::CheckSkipFirst(BREAKPOINT_IOP, pc) == pc)
return false;
CBreakPoints::SetBreakpointTriggered(true);
CBreakPoints::SetBreakpointTriggered(true, BREAKPOINT_IOP);
VMManager::SetPaused(true);
// Exit the EE too.

View File

@ -1537,7 +1537,7 @@ void dynarecCheckBreakpoint()
if (!hit)
return;
CBreakPoints::SetBreakpointTriggered(true);
CBreakPoints::SetBreakpointTriggered(true, BREAKPOINT_EE);
VMManager::SetPaused(true);
recExitExecution();
}
@ -1548,7 +1548,7 @@ void dynarecMemcheck()
if (CBreakPoints::CheckSkipFirst(BREAKPOINT_EE, pc) != 0)
return;
CBreakPoints::SetBreakpointTriggered(true);
CBreakPoints::SetBreakpointTriggered(true, BREAKPOINT_EE);
VMManager::SetPaused(true);
recExitExecution();
}