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 = "" 
)

Add a memory watchpoint.

Parameters
start_addressStarting address of range to watch
end_addressEnding address (inclusive), or same as start for single byte
track_readsTrack read accesses
track_writesTrack write accesses
break_on_accessPause emulation when accessed
descriptionUser-friendly description
Returns
Unique watchpoint ID

Definition at line 11 of file watchpoint_manager.cc.

References yaze::emu::WatchpointManager::Watchpoint::break_on_access, yaze::emu::WatchpointManager::Watchpoint::description, yaze::emu::WatchpointManager::Watchpoint::enabled, yaze::emu::WatchpointManager::Watchpoint::end_address, yaze::emu::WatchpointManager::Watchpoint::id, LOG_INFO, next_id_, yaze::emu::WatchpointManager::Watchpoint::start_address, yaze::emu::WatchpointManager::Watchpoint::track_reads, yaze::emu::WatchpointManager::Watchpoint::track_writes, and watchpoints_.

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

◆ RemoveWatchpoint()

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

Remove a watchpoint.

Definition at line 35 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 43 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 51 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 96 of file watchpoint_manager.cc.

References watchpoints_.

◆ 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 107 of file watchpoint_manager.cc.

References IsInRange(), and watchpoints_.

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

Here is the call graph for this function:

◆ ClearAll()

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

Clear all watchpoints.

Definition at line 127 of file watchpoint_manager.cc.

References LOG_INFO, and watchpoints_.

◆ ClearHistory()

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

Clear history for all watchpoints.

Definition at line 132 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 139 of file watchpoint_manager.cc.

References LOG_INFO, and watchpoints_.

◆ 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 126 of file watchpoint_manager.h.

Referenced by AddWatchpoint().


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