From 4743d74985f49fc30f6c44b2192faaa59327fb38 Mon Sep 17 00:00:00 2001 From: iwubcode Date: Thu, 22 Dec 2022 17:33:53 -0600 Subject: [PATCH] Core: add helper function to apply a memory patch and mark the 'PPCPatches' as final --- Source/Core/Common/Debug/MemoryPatches.h | 1 + Source/Core/Common/DebugInterface.h | 1 + .../Core/Core/Debugger/PPCDebugInterface.cpp | 20 +++++++++++++++++-- Source/Core/Core/Debugger/PPCDebugInterface.h | 8 +++++++- 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/Source/Core/Common/Debug/MemoryPatches.h b/Source/Core/Common/Debug/MemoryPatches.h index abf88b0499..634382f3b3 100644 --- a/Source/Core/Common/Debug/MemoryPatches.h +++ b/Source/Core/Common/Debug/MemoryPatches.h @@ -42,6 +42,7 @@ public: bool HasEnabledPatch(u32 address) const; void RemovePatch(std::size_t index); void ClearPatches(); + virtual void ApplyExistingPatch(std::size_t index) = 0; protected: virtual void Patch(std::size_t index) = 0; diff --git a/Source/Core/Common/DebugInterface.h b/Source/Core/Common/DebugInterface.h index a59ac79f69..90ff647bec 100644 --- a/Source/Core/Common/DebugInterface.h +++ b/Source/Core/Common/DebugInterface.h @@ -50,6 +50,7 @@ public: virtual bool HasEnabledPatch(u32 address) const = 0; virtual void RemovePatch(std::size_t index) = 0; virtual void ClearPatches() = 0; + virtual void ApplyExistingPatch(std::size_t index) = 0; // Threads virtual Debug::Threads GetThreads() const = 0; diff --git a/Source/Core/Core/Debugger/PPCDebugInterface.cpp b/Source/Core/Core/Debugger/PPCDebugInterface.cpp index 2cbeae41fb..6161cd304b 100644 --- a/Source/Core/Core/Debugger/PPCDebugInterface.cpp +++ b/Source/Core/Core/Debugger/PPCDebugInterface.cpp @@ -23,9 +23,8 @@ #include "Core/PowerPC/PPCSymbolDB.h" #include "Core/PowerPC/PowerPC.h" -void PPCPatches::Patch(std::size_t index) +void ApplyMemoryPatch(Common::Debug::MemoryPatch& patch) { - auto& patch = m_patches[index]; if (patch.value.empty()) return; @@ -50,6 +49,18 @@ void PPCPatches::Patch(std::size_t index) } } +void PPCPatches::ApplyExistingPatch(std::size_t index) +{ + auto& patch = m_patches[index]; + ApplyMemoryPatch(patch); +} + +void PPCPatches::Patch(std::size_t index) +{ + auto& patch = m_patches[index]; + ApplyMemoryPatch(patch); +} + PPCDebugInterface::PPCDebugInterface() = default; PPCDebugInterface::~PPCDebugInterface() = default; @@ -168,6 +179,11 @@ void PPCDebugInterface::ClearPatches() m_patches.ClearPatches(); } +void PPCDebugInterface::ApplyExistingPatch(std::size_t index) +{ + m_patches.ApplyExistingPatch(index); +} + Common::Debug::Threads PPCDebugInterface::GetThreads() const { Common::Debug::Threads threads; diff --git a/Source/Core/Core/Debugger/PPCDebugInterface.h b/Source/Core/Core/Debugger/PPCDebugInterface.h index 4c5dfb0fec..533863fa14 100644 --- a/Source/Core/Core/Debugger/PPCDebugInterface.h +++ b/Source/Core/Core/Debugger/PPCDebugInterface.h @@ -12,8 +12,13 @@ #include "Common/DebugInterface.h" #include "Core/NetworkCaptureLogger.h" -class PPCPatches : public Common::Debug::MemoryPatches +void ApplyMemoryPatch(Common::Debug::MemoryPatch& patch); + +class PPCPatches final : public Common::Debug::MemoryPatches { +public: + void ApplyExistingPatch(std::size_t index) override; + private: void Patch(std::size_t index) override; }; @@ -52,6 +57,7 @@ public: bool HasEnabledPatch(u32 address) const override; void RemovePatch(std::size_t index) override; void ClearPatches() override; + void ApplyExistingPatch(std::size_t index) override; // Threads Common::Debug::Threads GetThreads() const override;