1 use crate::arch::interrupt::TrapFrame; 2 use crate::arch::kprobe::setup_single_step; 3 use crate::debug::kprobe::KPROBE_MANAGER; 4 use crate::exception::debug::DebugException; 5 use kprobe::{KprobeOps, ProbeArgs}; 6 use system_error::SystemError; 7 8 #[derive(Debug)] 9 pub struct EBreak; 10 11 impl EBreak { 12 pub fn handle(frame: &mut TrapFrame) -> Result<(), SystemError> { 13 Self::kprobe_handler(frame) 14 } 15 fn kprobe_handler(frame: &mut TrapFrame) -> Result<(), SystemError> { 16 let break_addr = frame.break_address(); 17 let guard = KPROBE_MANAGER.lock(); 18 let kprobe_list = guard.get_break_list(break_addr); 19 if let Some(kprobe_list) = kprobe_list { 20 for kprobe in kprobe_list { 21 let guard = kprobe.read(); 22 if guard.is_enabled() { 23 guard.call_pre_handler(frame); 24 } 25 } 26 let single_step_address = kprobe_list[0].read().probe_point().single_step_address(); 27 // setup_single_step 28 setup_single_step(frame, single_step_address); 29 } else { 30 // For some architectures, they do not support single step execution, 31 // and we need to use breakpoint exceptions to simulate 32 drop(guard); 33 DebugException::handle(frame)?; 34 } 35 Ok(()) 36 } 37 } 38