15#include "absl/status/status.h"
44 constexpr uint32_t PLAYER_HEALTH = 0x7EF36D;
45 constexpr uint32_t PLAYER_MAX_HEALTH = 0x7EF36C;
49 PLAYER_HEALTH, PLAYER_HEALTH,
53 "Player Health Tracking"
56 LOG_INFO(
"MemoryDebug",
"Added watchpoint for player health at $%06X (ID: %d)",
57 PLAYER_HEALTH, health_wp);
65 "Player Death Detection"
68 LOG_INFO(
"MemoryDebug",
"Added breakpoint for player death at $%06X (ID: %d)",
69 PLAYER_HEALTH, death_bp);
71 return absl::OkStatus();
79 constexpr uint32_t INVENTORY_START = 0x7EF340;
80 constexpr uint32_t INVENTORY_END = 0x7EF37F;
84 INVENTORY_START, INVENTORY_END,
91 LOG_INFO(
"MemoryDebug",
"Monitoring inventory range $%06X-$%06X (ID: %d)",
92 INVENTORY_START, INVENTORY_END, inv_wp);
94 return absl::OkStatus();
102 constexpr uint32_t SPRITE_TABLE_START = 0x7E0D00;
103 constexpr uint32_t SPRITE_TABLE_END = 0x7E0EFF;
107 SPRITE_TABLE_START, SPRITE_TABLE_END,
111 "Sprite Table Debugging"
114 LOG_INFO(
"MemoryDebug",
"Debugging sprite table $%06X-$%06X (ID: %d)",
115 SPRITE_TABLE_START, SPRITE_TABLE_END, sprite_wp);
117 return absl::OkStatus();
125 constexpr uint32_t DMA_REGS_START = 0x004300;
126 constexpr uint32_t DMA_REGS_END = 0x00437F;
130 DMA_REGS_START, DMA_REGS_END,
134 "DMA Transfer Monitoring"
137 LOG_INFO(
"MemoryDebug",
"Monitoring DMA registers $%06X-$%06X (ID: %d)",
138 DMA_REGS_START, DMA_REGS_END, dma_wp);
140 return absl::OkStatus();
150 for (
const auto& wp : watchpoints) {
151 LOG_INFO(
"MemoryDebug",
"Watchpoint '%s' (ID: %d):",
152 wp.description.c_str(), wp.id);
160 uint8_t last_value = 0;
161 bool value_changed =
false;
163 for (
const auto& access : history) {
164 if (access.is_write) {
166 if (access.new_value != last_value) {
167 value_changed =
true;
168 last_value = access.new_value;
175 LOG_INFO(
"MemoryDebug",
" - Reads: %d, Writes: %d, Value changes: %s",
176 read_count, write_count, value_changed ?
"Yes" :
"No");
179 if (write_count > 10) {
180 LOG_WARNING(
"MemoryDebug",
" - High write frequency detected!");
183 LOG_INFO(
"MemoryDebug",
" - Last value: $%02X", last_value);
187 return absl::OkStatus();
195 LOG_INFO(
"MemoryDebug",
"Exported watchpoint history to %s", filename.c_str());
196 return absl::OkStatus();
198 return absl::InternalError(
"Failed to export watchpoint history");
207 LOG_INFO(
"MemoryDebug",
"Cleared all breakpoints and watchpoints");
223 LOG_INFO(
"MemoryDebug",
"Memory debugging session initialized");
227 LOG_INFO(
"MemoryDebug",
"Running emulation to collect memory access data...");
238 return absl::OkStatus();
Demonstrates memory debugging capabilities for AI agents.
absl::Status MonitorInventory()
emu::WatchpointManager & watchpoint_mgr_
absl::Status TrackDMATransfers()
absl::Status AnalyzeWatchpointData()
MemoryDebuggingExample(emu::Emulator *emulator)
absl::Status ExportWatchpointHistory(const std::string &filename)
absl::Status TrackPlayerHealth()
absl::Status RunMemoryDebuggingSession()
absl::Status DebugSpriteData()
emu::BreakpointManager & breakpoint_mgr_
emu::Emulator * emulator_
Manages CPU and SPC700 breakpoints for debugging.
void ClearAll()
Clear all breakpoints.
uint32_t AddBreakpoint(uint32_t address, Type type, CpuType cpu, const std::string &condition="", const std::string &description="")
Add a new breakpoint.
A class for emulating and debugging SNES games.
void set_debugging(bool debugging)
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::vector< AccessLog > GetHistory(uint32_t address, int max_entries=100) const
Get access history for a specific address.
void ClearAll()
Clear all watchpoints.
#define LOG_INFO(category, format,...)
#define RETURN_IF_ERROR(expr)