yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
yaze::emu::WatchpointManager Class Reference

Manages memory watchpoints for debugging. More...

#include <watchpoint_manager.h>

Classes

struct  AccessLog
 
struct  Watchpoint
 

Public Member Functions

 WatchpointManager ()=default
 
 ~WatchpointManager ()=default
 
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.
 
void RemoveWatchpoint (uint32_t id)
 Remove a watchpoint.
 
void SetEnabled (uint32_t id, bool enabled)
 Enable or disable a watchpoint.
 
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.
 
std::vector< WatchpointGetAllWatchpoints () const
 Get all watchpoints.
 
std::vector< AccessLogGetHistory (uint32_t address, int max_entries=100) const
 Get access history for a specific address.
 
void ClearAll ()
 Clear all watchpoints.
 
void ClearHistory ()
 Clear history for all watchpoints.
 
bool ExportHistoryToCSV (const std::string &filepath) const
 Export access history to CSV.
 

Private Member Functions

bool IsInRange (const Watchpoint &wp, uint32_t address) const
 

Private Attributes

std::unordered_map< uint32_t, Watchpointwatchpoints_
 
uint32_t next_id_ = 1
 

Detailed Description

Manages memory watchpoints for debugging.

Watchpoints track memory accesses (reads/writes) and can break execution when specific memory locations are accessed. This is crucial for:

  • Finding where variables are modified
  • Detecting buffer overflows
  • Tracking down corruption bugs
  • Understanding data flow

Inspired by Mesen2's memory debugging capabilities.

Definition at line 26 of file watchpoint_manager.h.

Constructor & Destructor Documentation

◆ WatchpointManager()

yaze::emu::WatchpointManager::WatchpointManager ( )
default

◆ ~WatchpointManager()

yaze::emu::WatchpointManager::~WatchpointManager ( )
default

Member Function Documentation

◆ AddWatchpoint()

uint32_t yaze::emu::WatchpointManager::AddWatchpoint ( uint32_t start_address,
uint32_t end_address,
bool track_reads,
bool track_writes,
bool break_on_access = false,
const std::string & description = "" )

◆ RemoveWatchpoint()

void yaze::emu::WatchpointManager::RemoveWatchpoint ( uint32_t id)

Remove a watchpoint.

Definition at line 39 of file watchpoint_manager.cc.

References LOG_INFO, and watchpoints_.

◆ SetEnabled()

void yaze::emu::WatchpointManager::SetEnabled ( uint32_t id,
bool enabled )

Enable or disable a watchpoint.

Definition at line 47 of file watchpoint_manager.cc.

References LOG_INFO, and watchpoints_.

◆ OnMemoryAccess()

bool yaze::emu::WatchpointManager::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.

Parameters
pcCurrent program counter
addressMemory address being accessed
is_writeTrue for write, false for read
old_valuePrevious value at address
new_valueNew value (for writes) or value read
cycle_countCurrent CPU cycle
Returns
true if should break execution

Definition at line 56 of file watchpoint_manager.cc.

References yaze::emu::WatchpointManager::AccessLog::address, yaze::emu::WatchpointManager::AccessLog::cycle_count, yaze::emu::WatchpointManager::AccessLog::description, yaze::emu::WatchpointManager::AccessLog::is_write, IsInRange(), yaze::emu::WatchpointManager::Watchpoint::kMaxHistorySize, LOG_INFO, yaze::emu::WatchpointManager::AccessLog::new_value, yaze::emu::WatchpointManager::AccessLog::old_value, yaze::emu::WatchpointManager::AccessLog::pc, and watchpoints_.

Referenced by yaze::test::EmulatorTestSuite::RunWatchpointManagerTest().

Here is the call graph for this function:

◆ GetAllWatchpoints()

std::vector< WatchpointManager::Watchpoint > yaze::emu::WatchpointManager::GetAllWatchpoints ( ) const

Get all watchpoints.

Definition at line 105 of file watchpoint_manager.cc.

References watchpoints_.

Referenced by yaze::cli::agent::MemoryDebuggingExample::AnalyzeWatchpointData().

◆ GetHistory()

std::vector< WatchpointManager::AccessLog > yaze::emu::WatchpointManager::GetHistory ( uint32_t address,
int max_entries = 100 ) const

Get access history for a specific address.

Parameters
addressAddress to query
max_entriesMaximum number of entries to return
Returns
Vector of access logs

Definition at line 117 of file watchpoint_manager.cc.

References IsInRange(), and watchpoints_.

Referenced by yaze::cli::agent::MemoryDebuggingExample::AnalyzeWatchpointData(), and yaze::test::EmulatorTestSuite::RunWatchpointManagerTest().

Here is the call graph for this function:

◆ ClearAll()

void yaze::emu::WatchpointManager::ClearAll ( )

Clear all watchpoints.

Definition at line 137 of file watchpoint_manager.cc.

References LOG_INFO, and watchpoints_.

Referenced by yaze::cli::agent::MemoryDebuggingExample::ClearDebugging().

◆ ClearHistory()

void yaze::emu::WatchpointManager::ClearHistory ( )

Clear history for all watchpoints.

Definition at line 143 of file watchpoint_manager.cc.

References LOG_INFO, and watchpoints_.

◆ ExportHistoryToCSV()

bool yaze::emu::WatchpointManager::ExportHistoryToCSV ( const std::string & filepath) const

Export access history to CSV.

Parameters
filepathOutput file path
Returns
true if successful

Definition at line 150 of file watchpoint_manager.cc.

References LOG_INFO, and watchpoints_.

Referenced by yaze::cli::agent::MemoryDebuggingExample::ExportWatchpointHistory().

◆ IsInRange()

bool yaze::emu::WatchpointManager::IsInRange ( const Watchpoint & wp,
uint32_t address ) const
inlineprivate

Member Data Documentation

◆ watchpoints_

std::unordered_map<uint32_t, Watchpoint> yaze::emu::WatchpointManager::watchpoints_
private

◆ next_id_

uint32_t yaze::emu::WatchpointManager::next_id_ = 1
private

Definition at line 129 of file watchpoint_manager.h.

Referenced by AddWatchpoint().


The documentation for this class was generated from the following files: