Merge pull request #11201 from JoshuaMKW/fix-instruction-patches

MemoryPatches: Fix instruction patches
This commit is contained in:
Pokechu22 2022-10-29 12:34:00 -07:00 committed by GitHub
commit 6dcf8a6fc9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 12 deletions

View File

@ -32,6 +32,7 @@ void MemoryPatches::SetPatch(u32 address, u32 value)
void MemoryPatches::SetPatch(u32 address, std::vector<u8> value) void MemoryPatches::SetPatch(u32 address, std::vector<u8> value)
{ {
UnsetPatch(address);
const std::size_t index = m_patches.size(); const std::size_t index = m_patches.size();
m_patches.emplace_back(address, std::move(value)); m_patches.emplace_back(address, std::move(value));
Patch(index); Patch(index);
@ -44,20 +45,14 @@ const std::vector<MemoryPatch>& MemoryPatches::GetPatches() const
void MemoryPatches::UnsetPatch(u32 address) void MemoryPatches::UnsetPatch(u32 address)
{ {
const auto it = std::remove_if(m_patches.begin(), m_patches.end(), const auto it = std::find_if(m_patches.begin(), m_patches.end(),
[address](const auto& patch) { return patch.address == address; }); [address](const auto& patch) { return patch.address == address; });
if (it == m_patches.end()) if (it == m_patches.end())
return; return;
const std::size_t size = m_patches.size(); const std::size_t index = std::distance(m_patches.begin(), it);
std::size_t index = size - std::distance(it, m_patches.end()); RemovePatch(index);
while (index < size)
{
DisablePatch(index);
++index;
}
m_patches.erase(it, m_patches.end());
} }
void MemoryPatches::EnablePatch(std::size_t index) void MemoryPatches::EnablePatch(std::size_t index)

View File

@ -513,7 +513,6 @@ void CodeViewWidget::SetAddress(u32 address, SetAddressUpdate update)
void CodeViewWidget::ReplaceAddress(u32 address, ReplaceWith replace) void CodeViewWidget::ReplaceAddress(u32 address, ReplaceWith replace)
{ {
PowerPC::debug_interface.UnsetPatch(address);
PowerPC::debug_interface.SetPatch(address, replace == ReplaceWith::BLR ? 0x4e800020 : 0x60000000); PowerPC::debug_interface.SetPatch(address, replace == ReplaceWith::BLR ? 0x4e800020 : 0x60000000);
Update(); Update();
} }
@ -823,7 +822,6 @@ void CodeViewWidget::OnReplaceInstruction()
if (dialog.exec() == QDialog::Accepted) if (dialog.exec() == QDialog::Accepted)
{ {
PowerPC::debug_interface.UnsetPatch(addr);
PowerPC::debug_interface.SetPatch(addr, dialog.GetCode()); PowerPC::debug_interface.SetPatch(addr, dialog.GetCode());
Update(); Update();
} }