Debian Codegraph @

Source/Core/Common/Debug/MemoryPatches.h

raw symbols SCIP
1 // Copyright 2018 Dolphin Emulator Project
2 // SPDX-License-Identifier: GPL-2.0-or-later
3
4 #pragma once
5
6 #include <cstddef>
7 #include <vector>
8
9 #include "Common/CommonTypes.h"
10
11 namespace Core
12 {
13 class CPUThreadGuard;
14 }
15
16 namespace Common::Debug
17 {
18 struct MemoryPatch
19 {
20 enum class State
21 {
22 Enabled,
23 Disabled
24 };
25
26 enum class ApplyType
27 {
28 Once,
29 EachFrame
30 };
31
32 MemoryPatch(u32 address_, std::vector<u8> value_);
33 MemoryPatch(u32 address_, u32 value_);
34
35 u32 address;
36 std::vector<u8> value;
37 State is_enabled = State::Enabled;
38 ApplyType type = ApplyType::Once;
39 };
40
41 class MemoryPatches
42 {
43 public:
44 MemoryPatches();
45 virtual ~MemoryPatches();
46
47 void SetPatch(const Core::CPUThreadGuard& guard, u32 address, u32 value);
48 void SetPatch(const Core::CPUThreadGuard& guard, u32 address, std::vector<u8> value);
49 void SetFramePatch(const Core::CPUThreadGuard& guard, u32 address, u32 value);
50 void SetFramePatch(const Core::CPUThreadGuard& guard, u32 address, std::vector<u8> value);
51 const std::vector<MemoryPatch>& GetPatches() const;
52 void UnsetPatch(const Core::CPUThreadGuard& guard, u32 address);
53 void EnablePatch(const Core::CPUThreadGuard& guard, std::size_t index);
54 void DisablePatch(const Core::CPUThreadGuard& guard, std::size_t index);
55 bool HasEnabledPatch(u32 address) const;
56 void RemovePatch(const Core::CPUThreadGuard& guard, std::size_t index);
57 void ClearPatches(const Core::CPUThreadGuard& guard);
58 virtual void ApplyExistingPatch(const Core::CPUThreadGuard& guard, std::size_t index) = 0;
59
60 protected:
61 virtual void Patch(const Core::CPUThreadGuard& guard, std::size_t index) = 0;
62 virtual void UnPatch(std::size_t index) = 0;
63
64 std::vector<MemoryPatch> m_patches;
65 };
66 } // namespace Common::Debug