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