From 93776707a9a4c2ebc5abbf057b711ccd34fd52df Mon Sep 17 00:00:00 2001 From: Ty Lamontagne Date: Thu, 26 Oct 2023 18:40:53 -0400 Subject: [PATCH] Debugger: Stub the current opcode if no function is selected --- pcsx2-qt/Debugger/DisassemblyWidget.cpp | 27 ++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/pcsx2-qt/Debugger/DisassemblyWidget.cpp b/pcsx2-qt/Debugger/DisassemblyWidget.cpp index 0440542833..de93c18fae 100644 --- a/pcsx2-qt/Debugger/DisassemblyWidget.cpp +++ b/pcsx2-qt/Debugger/DisassemblyWidget.cpp @@ -292,9 +292,14 @@ void DisassemblyWidget::contextStubFunction() QtHost::RunOnUIThread([this] { VMUpdate(); }); }); } - else + else // Stub the current opcode instead { - QMessageBox::warning(this, tr("Stub Function Error"), tr("No function / symbol is currently selected.")); + Host::RunOnCPUThread([this, cpu = m_cpu] { + this->m_stubbedFunctions.insert({m_selectedAddressStart, {cpu->read32(m_selectedAddressStart), cpu->read32(m_selectedAddressStart + 4)}}); + cpu->write32(m_selectedAddressStart, 0x03E00008); // jr $ra + cpu->write32(m_selectedAddressStart + 4, 0x00000000); // nop + QtHost::RunOnUIThread([this] { VMUpdate(); }); + }); } } @@ -310,9 +315,18 @@ void DisassemblyWidget::contextRestoreFunction() QtHost::RunOnUIThread([this] { VMUpdate(); }); }); } + else if (m_stubbedFunctions.find(m_selectedAddressStart) != m_stubbedFunctions.end()) + { + Host::RunOnCPUThread([this, cpu = m_cpu] { + cpu->write32(m_selectedAddressStart, std::get<0>(this->m_stubbedFunctions[m_selectedAddressStart])); + cpu->write32(m_selectedAddressStart + 4, std::get<1>(this->m_stubbedFunctions[m_selectedAddressStart])); + this->m_stubbedFunctions.erase(m_selectedAddressStart); + QtHost::RunOnUIThread([this] { VMUpdate(); }); + }); + } else { - QMessageBox::warning(this, tr("Restore Function Error"), tr("No function / symbol is currently selected.")); + QMessageBox::warning(this, tr("Restore Function Error"), tr("Unable to stub selected address.")); } } void DisassemblyWidget::SetCpu(DebugInterface* cpu) @@ -848,5 +862,12 @@ bool DisassemblyWidget::FunctionCanRestore(u32 address) return true; } } + else + { + if (m_stubbedFunctions.find(address) != this->m_stubbedFunctions.end()) + { + return true; + } + } return false; }