Skip to content

Commit

Permalink
Debugger: Stub the current opcode if no function is selected
Browse files Browse the repository at this point in the history
  • Loading branch information
F0bes committed Oct 26, 2023
1 parent 5ac0c39 commit d02689f
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions pcsx2-qt/Debugger/DisassemblyWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(); });
});
}
}

Expand All @@ -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)
Expand Down Expand Up @@ -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;
}

0 comments on commit d02689f

Please sign in to comment.