Skip to content

Commit 0c32b2f

Browse files
committed
add debug handler for x86_64
Signed-off-by: Godones <chenlinfeng25@outlook.com>
1 parent 1b026ee commit 0c32b2f

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/trap.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ pub static PAGE_FAULT: [fn(VirtAddr, PageFaultFlags) -> bool];
1919
#[def_trap_handler]
2020
pub static BREAK_HANDLER: [fn(&mut TrapFrame) -> bool];
2121

22+
/// A slice of debug handler functions.
23+
#[def_trap_handler]
24+
pub static DEBUG_HANDLER: [fn(&mut TrapFrame) -> bool];
25+
2226
#[allow(unused_macros)]
2327
macro_rules! handle_trap {
2428
($trap:ident, $($args:tt)*) => {{

src/x86_64/trap.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,18 @@ fn handle_breakpoint(tf: &mut TrapFrame) {
4646
}
4747
}
4848

49+
fn handle_debug(tf: &mut TrapFrame) {
50+
debug!("#DB @ {:#x} ", tf.rip);
51+
if core::hint::likely(handle_trap!(DEBUG_HANDLER, tf)) {
52+
return;
53+
}
54+
}
55+
4956
#[unsafe(no_mangle)]
5057
fn x86_trap_handler(tf: &mut TrapFrame) {
5158
match tf.vector as u8 {
5259
PAGE_FAULT_VECTOR => handle_page_fault(tf),
60+
DEBUG_VECTOR => handle_debug(tf),
5361
BREAKPOINT_VECTOR => handle_breakpoint(tf),
5462
GENERAL_PROTECTION_FAULT_VECTOR => {
5563
panic!(

0 commit comments

Comments
 (0)