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

Controller for intelligent step operations. More...

#include <step_controller.h>

Public Types

using MemoryReader = std::function<uint8_t(uint32_t)>
 
using SingleStepper = std::function<void()>
 
using PcGetter = std::function<uint32_t()>
 

Public Member Functions

 StepController ()=default
 
void SetMemoryReader (MemoryReader reader)
 
void SetSingleStepper (SingleStepper stepper)
 
void SetPcGetter (PcGetter getter)
 
StepResult StepInto ()
 Step a single instruction and update call stack.
 
StepResult StepOver (uint32_t max_instructions=1000000)
 Step over the current instruction.
 
StepResult StepOut (uint32_t max_instructions=1000000)
 Step out of the current subroutine.
 
const std::vector< CallStackEntry > & GetCallStack () const
 Get the current call stack.
 
size_t GetCallDepth () const
 Get the current call depth.
 
void ClearCallStack ()
 Clear the call stack (e.g., on reset)
 

Static Public Member Functions

static bool IsCallInstruction (uint8_t opcode)
 Check if an opcode is a call instruction (JSR/JSL)
 
static bool IsReturnInstruction (uint8_t opcode)
 Check if an opcode is a return instruction (RTS/RTL/RTI)
 
static bool IsBranchInstruction (uint8_t opcode)
 Check if an opcode is a branch instruction.
 
static uint8_t GetInstructionSize (uint8_t opcode, bool m_flag, bool x_flag)
 Get instruction size for step over calculations.
 

Private Member Functions

void ProcessInstruction (uint32_t pc)
 
uint32_t CalculateReturnAddress (uint32_t pc, uint8_t opcode) const
 
uint32_t CalculateCallTarget (uint32_t pc, uint8_t opcode) const
 

Private Attributes

MemoryReader read_byte_
 
SingleStepper step_
 
PcGetter get_pc_
 
std::vector< CallStackEntrycall_stack_
 

Detailed Description

Controller for intelligent step operations.

Provides step-over, step-out, and step-into functionality by tracking the call stack during execution.

Usage: StepController controller; controller.SetMemoryReader([&](uint32_t addr) { return mem.ReadByte(addr); }); controller.SetSingleStepper([&]() { cpu.ExecuteInstruction(); });

// Step over a JSR - will run until it returns auto result = controller.StepOver(current_pc);

// Step out of current subroutine auto result = controller.StepOut(current_pc, call_depth);

Definition at line 70 of file step_controller.h.

Member Typedef Documentation

◆ MemoryReader

using yaze::emu::debug::StepController::MemoryReader = std::function<uint8_t(uint32_t)>

Definition at line 72 of file step_controller.h.

◆ SingleStepper

using yaze::emu::debug::StepController::SingleStepper = std::function<void()>

Definition at line 73 of file step_controller.h.

◆ PcGetter

using yaze::emu::debug::StepController::PcGetter = std::function<uint32_t()>

Definition at line 74 of file step_controller.h.

Constructor & Destructor Documentation

◆ StepController()

yaze::emu::debug::StepController::StepController ( )
default

Member Function Documentation

◆ SetMemoryReader()

void yaze::emu::debug::StepController::SetMemoryReader ( MemoryReader reader)
inline

Definition at line 78 of file step_controller.h.

References read_byte_.

Referenced by yaze::agent::EmulatorServiceImpl::InitializeStepController().

◆ SetSingleStepper()

void yaze::emu::debug::StepController::SetSingleStepper ( SingleStepper stepper)
inline

Definition at line 79 of file step_controller.h.

References step_.

Referenced by yaze::agent::EmulatorServiceImpl::InitializeStepController().

◆ SetPcGetter()

void yaze::emu::debug::StepController::SetPcGetter ( PcGetter getter)
inline

Definition at line 80 of file step_controller.h.

References get_pc_.

Referenced by yaze::agent::EmulatorServiceImpl::InitializeStepController().

◆ StepInto()

◆ StepOver()

StepResult yaze::emu::debug::StepController::StepOver ( uint32_t max_instructions = 1000000)

Step over the current instruction.

If the current instruction is JSR/JSL, this executes until the subroutine returns. Otherwise, it's equivalent to StepInto.

Parameters
max_instructionsMaximum instructions before timeout
Returns
Step result

Definition at line 257 of file step_controller.cc.

References CalculateCallTarget(), CalculateReturnAddress(), yaze::emu::debug::StepResult::call, call_stack_, get_pc_, yaze::emu::debug::StepResult::instructions_executed, IsCallInstruction(), IsReturnInstruction(), yaze::emu::debug::opcode::JSL, yaze::emu::debug::StepResult::message, yaze::emu::debug::StepResult::new_pc, read_byte_, step_, StepInto(), and yaze::emu::debug::StepResult::success.

Referenced by yaze::agent::EmulatorServiceImpl::StepOver().

◆ StepOut()

StepResult yaze::emu::debug::StepController::StepOut ( uint32_t max_instructions = 1000000)

Step out of the current subroutine.

Executes until RTS/RTL returns to a higher call level.

Parameters
max_instructionsMaximum instructions before timeout
Returns
Step result

Definition at line 328 of file step_controller.cc.

References CalculateCallTarget(), CalculateReturnAddress(), call_stack_, get_pc_, yaze::emu::debug::StepResult::instructions_executed, IsCallInstruction(), IsReturnInstruction(), yaze::emu::debug::opcode::JSL, yaze::emu::debug::StepResult::message, yaze::emu::debug::StepResult::new_pc, read_byte_, yaze::emu::debug::StepResult::ret, step_, and yaze::emu::debug::StepResult::success.

Referenced by yaze::agent::EmulatorServiceImpl::StepOut().

Here is the call graph for this function:

◆ GetCallStack()

const std::vector< CallStackEntry > & yaze::emu::debug::StepController::GetCallStack ( ) const
inline

Get the current call stack.

Definition at line 112 of file step_controller.h.

References call_stack_.

◆ GetCallDepth()

size_t yaze::emu::debug::StepController::GetCallDepth ( ) const
inline

Get the current call depth.

Definition at line 119 of file step_controller.h.

References call_stack_.

Referenced by yaze::agent::EmulatorServiceImpl::StepOut().

◆ ClearCallStack()

void yaze::emu::debug::StepController::ClearCallStack ( )
inline

Clear the call stack (e.g., on reset)

Definition at line 124 of file step_controller.h.

References call_stack_.

◆ IsCallInstruction()

bool yaze::emu::debug::StepController::IsCallInstruction ( uint8_t opcode)
static

Check if an opcode is a call instruction (JSR/JSL)

Definition at line 9 of file step_controller.cc.

References yaze::emu::debug::opcode::JSL, yaze::emu::debug::opcode::JSR, and yaze::emu::debug::opcode::JSR_X.

Referenced by ProcessInstruction(), StepInto(), StepOut(), and StepOver().

◆ IsReturnInstruction()

bool yaze::emu::debug::StepController::IsReturnInstruction ( uint8_t opcode)
static

Check if an opcode is a return instruction (RTS/RTL/RTI)

Definition at line 15 of file step_controller.cc.

References yaze::emu::debug::opcode::RTI, yaze::emu::debug::opcode::RTL, and yaze::emu::debug::opcode::RTS.

Referenced by ProcessInstruction(), StepInto(), StepOut(), and StepOver().

◆ IsBranchInstruction()

◆ GetInstructionSize()

uint8_t yaze::emu::debug::StepController::GetInstructionSize ( uint8_t opcode,
bool m_flag,
bool x_flag )
static

Get instruction size for step over calculations.

Definition at line 39 of file step_controller.cc.

Referenced by CalculateReturnAddress().

◆ ProcessInstruction()

void yaze::emu::debug::StepController::ProcessInstruction ( uint32_t pc)
private

◆ CalculateReturnAddress()

uint32_t yaze::emu::debug::StepController::CalculateReturnAddress ( uint32_t pc,
uint8_t opcode ) const
private

Definition at line 142 of file step_controller.cc.

References GetInstructionSize(), and yaze::emu::debug::opcode::JSL.

Referenced by ProcessInstruction(), StepInto(), StepOut(), and StepOver().

Here is the call graph for this function:

◆ CalculateCallTarget()

uint32_t yaze::emu::debug::StepController::CalculateCallTarget ( uint32_t pc,
uint8_t opcode ) const
private

Member Data Documentation

◆ read_byte_

MemoryReader yaze::emu::debug::StepController::read_byte_
private

◆ step_

SingleStepper yaze::emu::debug::StepController::step_
private

Definition at line 157 of file step_controller.h.

Referenced by SetSingleStepper(), StepInto(), StepOut(), and StepOver().

◆ get_pc_

PcGetter yaze::emu::debug::StepController::get_pc_
private

Definition at line 158 of file step_controller.h.

Referenced by SetPcGetter(), StepInto(), StepOut(), and StepOver().

◆ call_stack_

std::vector<CallStackEntry> yaze::emu::debug::StepController::call_stack_
private

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