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< CallStackEntry > | call_stack_ |
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.
| using yaze::emu::debug::StepController::MemoryReader = std::function<uint8_t(uint32_t)> |
Definition at line 72 of file step_controller.h.
| using yaze::emu::debug::StepController::SingleStepper = std::function<void()> |
Definition at line 73 of file step_controller.h.
| using yaze::emu::debug::StepController::PcGetter = std::function<uint32_t()> |
Definition at line 74 of file step_controller.h.
|
default |
|
inline |
Definition at line 78 of file step_controller.h.
References read_byte_.
Referenced by yaze::agent::EmulatorServiceImpl::InitializeStepController().
|
inline |
Definition at line 79 of file step_controller.h.
References step_.
Referenced by yaze::agent::EmulatorServiceImpl::InitializeStepController().
|
inline |
Definition at line 80 of file step_controller.h.
References get_pc_.
Referenced by yaze::agent::EmulatorServiceImpl::InitializeStepController().
| StepResult yaze::emu::debug::StepController::StepInto | ( | ) |
Step a single instruction and update call stack.
Definition at line 204 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_, yaze::emu::debug::StepResult::ret, step_, and yaze::emu::debug::StepResult::success.
Referenced by 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.
| max_instructions | Maximum instructions before timeout |
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().
| 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.
| max_instructions | Maximum instructions before timeout |
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().

|
inline |
Get the current call stack.
Definition at line 112 of file step_controller.h.
References call_stack_.
|
inline |
Get the current call depth.
Definition at line 119 of file step_controller.h.
References call_stack_.
Referenced by yaze::agent::EmulatorServiceImpl::StepOut().
|
inline |
Clear the call stack (e.g., on reset)
Definition at line 124 of file step_controller.h.
References call_stack_.
|
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().
|
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().
|
static |
Check if an opcode is a branch instruction.
Definition at line 21 of file step_controller.cc.
References yaze::emu::debug::opcode::BCC, yaze::emu::debug::opcode::BCS, yaze::emu::debug::opcode::BEQ, yaze::emu::debug::opcode::BMI, yaze::emu::debug::opcode::BNE, yaze::emu::debug::opcode::BPL, yaze::emu::debug::opcode::BRA, yaze::emu::debug::opcode::BRL, yaze::emu::debug::opcode::BVC, yaze::emu::debug::opcode::BVS, yaze::emu::debug::opcode::JMP_ABS, yaze::emu::debug::opcode::JMP_ABS_X, yaze::emu::debug::opcode::JMP_IND, yaze::emu::debug::opcode::JMP_IND_L, and yaze::emu::debug::opcode::JMP_LONG.
|
static |
Get instruction size for step over calculations.
Definition at line 39 of file step_controller.cc.
Referenced by CalculateReturnAddress().
|
private |
Definition at line 184 of file step_controller.cc.
References CalculateCallTarget(), CalculateReturnAddress(), call_stack_, IsCallInstruction(), IsReturnInstruction(), yaze::emu::debug::opcode::JSL, and read_byte_.

|
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().

|
private |
Definition at line 158 of file step_controller.cc.
References yaze::emu::debug::opcode::JSL, yaze::emu::debug::opcode::JSR, yaze::emu::debug::opcode::JSR_X, and read_byte_.
Referenced by ProcessInstruction(), StepInto(), StepOut(), and StepOver().
|
private |
Definition at line 156 of file step_controller.h.
Referenced by CalculateCallTarget(), ProcessInstruction(), SetMemoryReader(), StepInto(), StepOut(), and StepOver().
|
private |
Definition at line 157 of file step_controller.h.
Referenced by SetSingleStepper(), StepInto(), StepOut(), and StepOver().
|
private |
Definition at line 158 of file step_controller.h.
Referenced by SetPcGetter(), StepInto(), StepOut(), and StepOver().
|
private |
Definition at line 159 of file step_controller.h.
Referenced by ClearCallStack(), GetCallDepth(), GetCallStack(), ProcessInstruction(), StepInto(), StepOut(), and StepOver().