Fix single stepping after breakpoints

This commit is contained in:
momo5502
2025-04-06 17:50:02 +02:00
parent e40e1bfb83
commit cacf2c152c

View File

@@ -130,7 +130,6 @@ impl icicle_vm::CodeInjector for InstructionHookInjector {
}
struct ExecutionHooks {
vm_ptr: *mut icicle_vm::Vm,
skip_ip: Option<u64>,
stop: Rc<RefCell<bool>>,
generic_hooks: HookContainer<dyn Fn(u64)>,
@@ -139,9 +138,8 @@ struct ExecutionHooks {
}
impl ExecutionHooks {
pub fn new(stop_value: Rc<RefCell<bool>>, vm: &mut icicle_vm::Vm) -> Self {
pub fn new(stop_value: Rc<RefCell<bool>>) -> Self {
Self {
vm_ptr: vm as *mut icicle_vm::Vm,
skip_ip: None,
stop: stop_value,
generic_hooks: HookContainer::new(),
@@ -173,13 +171,6 @@ impl ExecutionHooks {
if self.skip_ip.is_some() {
skip = self.skip_ip.unwrap() == address;
self.skip_ip = None;
// TODO: Get rid of that
unsafe {
let vm = &mut *self.vm_ptr;
vm.icount_limit = vm.icount_limit.saturating_sub(1);
vm.next_timer = vm.next_timer.saturating_sub(1);
}
}
if !skip {
@@ -222,7 +213,7 @@ impl ExecutionHooks {
pub struct IcicleEmulator {
executing_thread: std::thread::ThreadId,
vm: Box<icicle_vm::Vm>,
vm: icicle_vm::Vm,
reg: registers::X64RegisterNodes,
syscall_hooks: HookContainer<dyn Fn()>,
violation_hooks: HookContainer<dyn Fn(u64, u8, bool) -> bool>,
@@ -277,9 +268,9 @@ impl icicle_cpu::mem::IoMemory for MmioHandler {
impl IcicleEmulator {
pub fn new() -> Self {
let mut virtual_machine = Box::new(create_x64_vm());
let mut virtual_machine = create_x64_vm();
let stop_value = Rc::new(RefCell::new(false));
let exec_hooks = Rc::new(RefCell::new(ExecutionHooks::new(stop_value.clone(), &mut virtual_machine)));
let exec_hooks = Rc::new(RefCell::new(ExecutionHooks::new(stop_value.clone())));
let exec_hooks_clone = Rc::clone(&exec_hooks);
@@ -307,7 +298,6 @@ impl IcicleEmulator {
pub fn start(&mut self, count: u64) {
self.executing_thread = std::thread::current().id();
*self.stop.borrow_mut() = false;
self.vm.icount_limit = match count {
0 => u64::MAX,
@@ -315,6 +305,12 @@ impl IcicleEmulator {
};
loop {
self.vm.cpu.block_id = u64::MAX;
self.vm.cpu.block_offset = 0;
self.vm.cpu.pending_exception = None;
self.vm.cpu.exception.clear();
*self.stop.borrow_mut() = false;
let reason = self.vm.run();
match reason {