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 <string>
6#include <vector>
7#include <unordered_map>
8#include <deque>
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
66 uint32_t AddWatchpoint(uint32_t start_address, uint32_t end_address,
67 bool track_reads, bool track_writes,
68 bool break_on_access = false,
69 const std::string& description = "");
70
74 void RemoveWatchpoint(uint32_t id);
75
79 void SetEnabled(uint32_t id, bool enabled);
80
91 bool OnMemoryAccess(uint32_t pc, uint32_t address, bool is_write,
92 uint8_t old_value, uint8_t new_value, uint64_t cycle_count);
93
97 std::vector<Watchpoint> GetAllWatchpoints() const;
98
105 std::vector<AccessLog> GetHistory(uint32_t address, int max_entries = 100) const;
106
110 void ClearAll();
111
115 void ClearHistory();
116
122 bool ExportHistoryToCSV(const std::string& filepath) const;
123
124 private:
125 std::unordered_map<uint32_t, Watchpoint> watchpoints_;
126 uint32_t next_id_ = 1;
127
128 // Check if address is within watchpoint range
129 bool IsInRange(const Watchpoint& wp, uint32_t address) const {
130 return address >= wp.start_address && address <= wp.end_address;
131 }
132};
133
134} // namespace emu
135} // namespace yaze
136
137#endif // YAZE_APP_EMU_DEBUG_WATCHPOINT_MANAGER_H
138
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.
Main namespace for the application.