1*fae6e9adSlinfeng use crate::arch::interrupt::TrapFrame; 2*fae6e9adSlinfeng use crate::arch::kprobe::clear_single_step; 3*fae6e9adSlinfeng use crate::debug::kprobe::KPROBE_MANAGER; 4*fae6e9adSlinfeng use kprobe::{KprobeOps, ProbeArgs}; 5*fae6e9adSlinfeng use log::debug; 6*fae6e9adSlinfeng use system_error::SystemError; 7*fae6e9adSlinfeng 8*fae6e9adSlinfeng #[derive(Debug)] 9*fae6e9adSlinfeng pub struct DebugException; 10*fae6e9adSlinfeng 11*fae6e9adSlinfeng impl DebugException { handle(frame: &mut TrapFrame) -> Result<(), SystemError>12*fae6e9adSlinfeng pub fn handle(frame: &mut TrapFrame) -> Result<(), SystemError> { 13*fae6e9adSlinfeng Self::post_kprobe_handler(frame) 14*fae6e9adSlinfeng } 15*fae6e9adSlinfeng post_kprobe_handler(frame: &mut TrapFrame) -> Result<(), SystemError>16*fae6e9adSlinfeng fn post_kprobe_handler(frame: &mut TrapFrame) -> Result<(), SystemError> { 17*fae6e9adSlinfeng let pc = frame.debug_address(); 18*fae6e9adSlinfeng if let Some(kprobe_list) = KPROBE_MANAGER.lock().get_debug_list(pc) { 19*fae6e9adSlinfeng for kprobe in kprobe_list { 20*fae6e9adSlinfeng let guard = kprobe.read(); 21*fae6e9adSlinfeng if guard.is_enabled() { 22*fae6e9adSlinfeng guard.call_post_handler(frame); 23*fae6e9adSlinfeng guard.call_event_callback(frame); 24*fae6e9adSlinfeng } 25*fae6e9adSlinfeng } 26*fae6e9adSlinfeng let return_address = kprobe_list[0].read().probe_point().return_address(); 27*fae6e9adSlinfeng clear_single_step(frame, return_address); 28*fae6e9adSlinfeng } else { 29*fae6e9adSlinfeng debug!("There is no kprobe on pc {:#x}", pc); 30*fae6e9adSlinfeng } 31*fae6e9adSlinfeng Ok(()) 32*fae6e9adSlinfeng } 33*fae6e9adSlinfeng } 34