yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
breakpoint_manager.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EMU_DEBUG_BREAKPOINT_MANAGER_H
2#define YAZE_APP_EMU_DEBUG_BREAKPOINT_MANAGER_H
3
4#include <cstdint>
5#include <functional>
6#include <string>
7#include <unordered_map>
8#include <vector>
9
10namespace yaze {
11namespace emu {
12
27 public:
28 enum class Type {
29 EXECUTE, // Break when PC reaches this address
30 READ, // Break when this address is read
31 WRITE, // Break when this address is written
32 ACCESS, // Break when this address is read OR written
33 CONDITIONAL // Break when condition evaluates to true
34 };
35
36 enum class CpuType {
37 CPU_65816, // Main CPU
38 SPC700 // Audio CPU
39 };
40
41 struct Breakpoint {
42 uint32_t id;
43 uint32_t address;
46 bool enabled;
47 std::string condition; // For conditional breakpoints (e.g., "A > 0x10")
48 uint32_t hit_count;
49 std::string description; // User-friendly label
50
51 // Optional callback for advanced logic
52 std::function<bool(uint32_t pc, uint32_t address, uint8_t value)> callback;
53 };
54
55 BreakpointManager() = default;
56 ~BreakpointManager() = default;
57
67 uint32_t AddBreakpoint(uint32_t address, Type type, CpuType cpu,
68 const std::string& condition = "",
69 const std::string& description = "");
70
74 void RemoveBreakpoint(uint32_t id);
75
79 void SetEnabled(uint32_t id, bool enabled);
80
87 bool ShouldBreakOnExecute(uint32_t pc, CpuType cpu);
88
97 bool ShouldBreakOnMemoryAccess(uint32_t address, bool is_write,
98 uint8_t value, uint32_t pc);
99
103 std::vector<Breakpoint> GetAllBreakpoints() const;
104
108 std::vector<Breakpoint> GetBreakpoints(CpuType cpu) const;
109
113 void ClearAll();
114
118 void ClearAll(CpuType cpu);
119
123 const Breakpoint* GetLastHit() const { return last_hit_; }
124
128 void ResetHitCounts();
129
130 private:
131 std::unordered_map<uint32_t, Breakpoint> breakpoints_;
132 uint32_t next_id_ = 1;
133 const Breakpoint* last_hit_ = nullptr;
134
135 bool EvaluateCondition(const std::string& condition, uint32_t pc,
136 uint32_t address, uint8_t value);
137};
138
139} // namespace emu
140} // namespace yaze
141
142#endif // YAZE_APP_EMU_DEBUG_BREAKPOINT_MANAGER_H
143
Manages CPU and SPC700 breakpoints for debugging.
bool ShouldBreakOnExecute(uint32_t pc, CpuType cpu)
Check if execution should break at this address.
void RemoveBreakpoint(uint32_t id)
Remove a breakpoint by ID.
bool ShouldBreakOnMemoryAccess(uint32_t address, bool is_write, uint8_t value, uint32_t pc)
Check if execution should break on memory access.
void ClearAll()
Clear all breakpoints.
void SetEnabled(uint32_t id, bool enabled)
Enable or disable a breakpoint.
std::vector< Breakpoint > GetAllBreakpoints() const
Get all breakpoints.
bool EvaluateCondition(const std::string &condition, uint32_t pc, uint32_t address, uint8_t value)
void ResetHitCounts()
Reset hit counts for all breakpoints.
const Breakpoint * GetLastHit() const
Get the last breakpoint that was hit.
std::vector< Breakpoint > GetBreakpoints(CpuType cpu) const
Get breakpoints for specific CPU.
std::unordered_map< uint32_t, Breakpoint > breakpoints_
uint32_t AddBreakpoint(uint32_t address, Type type, CpuType cpu, const std::string &condition="", const std::string &description="")
Add a new breakpoint.
Main namespace for the application.
std::function< bool(uint32_t pc, uint32_t address, uint8_t value)> callback