From 92827820bc025b5a41a6dcf8e92942840aecd37b Mon Sep 17 00:00:00 2001 From: Sepalani Date: Sat, 27 Feb 2021 14:48:18 +0400 Subject: [PATCH] DebugInterface: Add original_value to MemoryPatch --- Source/Core/Common/Debug/MemoryPatches.cpp | 11 ++++++----- Source/Core/Common/Debug/MemoryPatches.h | 3 ++- .../Core/Core/Debugger/PPCDebugInterface.cpp | 18 +++++++++++++----- .../DolphinQt/Debugger/MemoryPatchWidget.cpp | 13 ++++++++++--- 4 files changed, 31 insertions(+), 14 deletions(-) diff --git a/Source/Core/Common/Debug/MemoryPatches.cpp b/Source/Core/Common/Debug/MemoryPatches.cpp index 9e054029ad43..6104647f0a53 100644 --- a/Source/Core/Common/Debug/MemoryPatches.cpp +++ b/Source/Core/Common/Debug/MemoryPatches.cpp @@ -10,14 +10,14 @@ namespace Common::Debug { -MemoryPatch::MemoryPatch(u32 address_, std::vector value_) - : address(address_), value(std::move(value_)) +MemoryPatch::MemoryPatch(u32 address_, std::vector value) + : address(address_), patch_value(std::move(value)), original_value() { } -MemoryPatch::MemoryPatch(u32 address_, u32 value_) - : MemoryPatch(address_, {static_cast(value_ >> 24), static_cast(value_ >> 16), - static_cast(value_ >> 8), static_cast(value_)}) +MemoryPatch::MemoryPatch(u32 address_, u32 value) + : MemoryPatch(address_, {static_cast(value >> 24), static_cast(value >> 16), + static_cast(value >> 8), static_cast(value)}) { } @@ -80,6 +80,7 @@ void MemoryPatches::DisablePatch(std::size_t index) return; m_patches[index].is_enabled = MemoryPatch::State::Disabled; Patch(index); + m_patches[index].original_value.clear(); } bool MemoryPatches::HasEnabledPatch(u32 address) const diff --git a/Source/Core/Common/Debug/MemoryPatches.h b/Source/Core/Common/Debug/MemoryPatches.h index 0456f17f541e..b338c5371848 100644 --- a/Source/Core/Common/Debug/MemoryPatches.h +++ b/Source/Core/Common/Debug/MemoryPatches.h @@ -24,7 +24,8 @@ struct MemoryPatch MemoryPatch(u32 address_, u32 value_); u32 address; - std::vector value; + std::vector patch_value; + std::vector original_value; State is_enabled = State::Enabled; }; diff --git a/Source/Core/Core/Debugger/PPCDebugInterface.cpp b/Source/Core/Core/Debugger/PPCDebugInterface.cpp index b9cac6b30d94..1ed6871207c1 100644 --- a/Source/Core/Core/Debugger/PPCDebugInterface.cpp +++ b/Source/Core/Core/Debugger/PPCDebugInterface.cpp @@ -24,19 +24,27 @@ void PPCPatches::Patch(std::size_t index) { auto& patch = m_patches[index]; - if (patch.value.empty()) + if (patch.patch_value.empty()) return; const u32 address = patch.address; - const std::size_t size = patch.value.size(); + const std::size_t size = patch.patch_value.size(); if (!PowerPC::HostIsRAMAddress(address)) return; + const bool is_enabled = patch.is_enabled == Common::Debug::MemoryPatch::State::Enabled; for (u32 offset = 0; offset < size; ++offset) { - const u8 value = PowerPC::HostRead_U8(address + offset); - PowerPC::HostWrite_U8(patch.value[offset], address + offset); - patch.value[offset] = value; + if (is_enabled) + { + const u8 original_value = PowerPC::HostRead_U8(address + offset); + PowerPC::HostWrite_U8(patch.patch_value[offset], address + offset); + patch.original_value.push_back(original_value); + } + else + { + PowerPC::HostWrite_U8(patch.original_value[offset], address + offset); + } if (((address + offset) % 4) == 3) PowerPC::ScheduleInvalidateCacheThreadSafe(Common::AlignDown(address + offset, 4)); diff --git a/Source/Core/DolphinQt/Debugger/MemoryPatchWidget.cpp b/Source/Core/DolphinQt/Debugger/MemoryPatchWidget.cpp index 4a660c814e83..d004a2660796 100644 --- a/Source/Core/DolphinQt/Debugger/MemoryPatchWidget.cpp +++ b/Source/Core/DolphinQt/Debugger/MemoryPatchWidget.cpp @@ -74,12 +74,12 @@ void MemoryPatchWidget::CreateWidgets() m_toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); m_table = new QTableWidget; - m_table->setColumnCount(3); m_table->setSelectionMode(QAbstractItemView::SingleSelection); m_table->setSelectionBehavior(QAbstractItemView::SelectRows); m_table->setEditTriggers(QAbstractItemView::NoEditTriggers); - const QStringList header{{tr("Active"), tr("Address"), tr("Value")}}; + const QStringList header{{tr("Active"), tr("Address"), tr("Patch value"), tr("Original value")}}; + m_table->setColumnCount(header.size()); m_table->setHorizontalHeaderLabels(header); m_table->verticalHeader()->hide(); @@ -139,12 +139,19 @@ void MemoryPatchWidget::Update() std::ostringstream oss; oss << std::hex << std::setfill('0'); - for (u8 b : patch.value) + for (u8 b : patch.patch_value) { oss << std::setw(2) << static_cast(b); } m_table->setItem(patch_id, 2, create_item(QString::fromStdString(oss.str()))); + oss.str(""); + for (u8 b : patch.original_value) + { + oss << std::setw(2) << static_cast(b); + } + m_table->setItem(patch_id, 3, create_item(QString::fromStdString(oss.str()))); + patch_id += 1; } }