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