yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
watchpoint_manager.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EMU_DEBUG_WATCHPOINT_MANAGER_H
2#define YAZE_APP_EMU_DEBUG_WATCHPOINT_MANAGER_H
3
4#include <cstdint>
5#include <deque>
6#include <string>
7#include <unordered_map>
8#include <vector>
9
10namespace yaze {
11namespace emu {
12
27 public:
28 struct AccessLog {
29 uint32_t pc; // Where the access happened (program counter)
30 uint32_t address; // What address was accessed
31 uint8_t old_value; // Value before write (0 for reads)
32 uint8_t new_value; // Value after write / value read
33 bool is_write; // True for write, false for read
34 uint64_t cycle_count; // When it happened (CPU cycle)
35 std::string description; // Optional description
36 };
37
38 struct Watchpoint {
39 uint32_t id;
40 uint32_t start_address;
41 uint32_t end_address; // For range watchpoints
44 bool break_on_access; // If true, pause emulation on access
45 bool enabled;
46 std::string description;
47
48 // Access history for this watchpoint
49 std::deque<AccessLog> history;
50 static constexpr size_t kMaxHistorySize = 1000;
51 };
52
53 WatchpointManager() = default;
54 ~WatchpointManager() = default;
55
67 uint32_t AddWatchpoint(uint32_t start_address, uint32_t end_address,
68 bool track_reads, bool track_writes,
69 bool break_on_access = false,
70 const std::string& description = "");
71
75 void RemoveWatchpoint(uint32_t id);
76
80 void SetEnabled(uint32_t id, bool enabled);
81
92 bool OnMemoryAccess(uint32_t pc, uint32_t address, bool is_write,
93 uint8_t old_value, uint8_t new_value,
94 uint64_t cycle_count);
95
99 std::vector<Watchpoint> GetAllWatchpoints() const;
100
107 std::vector<AccessLog> GetHistory(uint32_t address,
108 int max_entries = 100) const;
109
113 void ClearAll();
114
118 void ClearHistory();
119
125 bool ExportHistoryToCSV(const std::string& filepath) const;
126
127 private:
128 std::unordered_map<uint32_t, Watchpoint> watchpoints_;
129 uint32_t next_id_ = 1;
130
131 // Check if address is within watchpoint range
132 bool IsInRange(const Watchpoint& wp, uint32_t address) const {
133 return address >= wp.start_address && address <= wp.end_address;
134 }
135};
136
137} // namespace emu
138} // namespace yaze
139
140#endif // YAZE_APP_EMU_DEBUG_WATCHPOINT_MANAGER_H
Manages memory watchpoints for debugging.
uint32_t AddWatchpoint(uint32_t start_address, uint32_t end_address, bool track_reads, bool track_writes, bool break_on_access=false, const std::string &description="")
Add a memory watchpoint.
bool ExportHistoryToCSV(const std::string &filepath) const
Export access history to CSV.
std::vector< Watchpoint > GetAllWatchpoints() const
Get all watchpoints.
std::unordered_map< uint32_t, Watchpoint > watchpoints_
std::vector< AccessLog > GetHistory(uint32_t address, int max_entries=100) const
Get access history for a specific address.
bool IsInRange(const Watchpoint &wp, uint32_t address) const
void ClearAll()
Clear all watchpoints.
bool OnMemoryAccess(uint32_t pc, uint32_t address, bool is_write, uint8_t old_value, uint8_t new_value, uint64_t cycle_count)
Check if memory access should break/log.
void ClearHistory()
Clear history for all watchpoints.
void SetEnabled(uint32_t id, bool enabled)
Enable or disable a watchpoint.
void RemoveWatchpoint(uint32_t id)
Remove a watchpoint.