xref: /DragonOS/kernel/src/debug/panic/hook.rs (revision 539ee3eaeb83834e020efbb7582ed5ce2e9646ce)
1 use unwinding::abi::{UnwindContext, UnwindReasonCode, _Unwind_GetIP};
2 use unwinding::panic::UserUnwindTrace;
3 
4 extern "C" {
lookup_kallsyms(addr: u64, level: i32) -> i325     fn lookup_kallsyms(addr: u64, level: i32) -> i32;
6 }
7 
8 /// User hook for unwinding
9 ///
10 /// During stack backtrace, the user can print the function location of the current stack frame.
11 pub struct Tracer;
12 pub struct CallbackData {
13     pub counter: usize,
14 }
15 impl UserUnwindTrace for Tracer {
16     type Arg = CallbackData;
17 
trace(ctx: &UnwindContext<'_>, arg: *mut Self::Arg) -> UnwindReasonCode18     fn trace(ctx: &UnwindContext<'_>, arg: *mut Self::Arg) -> UnwindReasonCode {
19         let data = unsafe { &mut *(arg) };
20         data.counter += 1;
21         let pc = _Unwind_GetIP(ctx);
22         unsafe {
23             lookup_kallsyms(pc as u64, data.counter as i32);
24         }
25         UnwindReasonCode::NO_REASON
26     }
27 }
28