Skip to content
This repository has been archived by the owner on Jan 1, 2024. It is now read-only.

Commit

Permalink
Colorize panic and program crash message
Browse files Browse the repository at this point in the history
  • Loading branch information
SamZhang3 committed Jun 10, 2023
1 parent 6d53ae0 commit c8c8e58
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion kernel/src/interrupt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ fn cpu_exception_common(frame: &InterruptStackFrame, id: u64, errcode: Option<u6
// handler; this puts the interrupt flag and cli_count in agreement.
interrupts::enable();

kprint!("\x1B[1;35m");
kprintln!("Thread {} has crashed and was terminated.", thread::id());
kprint!("[{}, stack frame: {:?}, ", exception_id_to_name(id), frame);
if id == 14 {
Expand All @@ -264,7 +265,7 @@ fn cpu_exception_common(frame: &InterruptStackFrame, id: u64, errcode: Option<u6
} else {
kprintln!("error code: {:?}]", errcode);
}

kprint!("\x1B[m");
thread::terminate();
// No code afterwards will be run in this case
}
Expand Down
2 changes: 1 addition & 1 deletion kernel/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ fn panic(panic_info: &PanicInfo) -> ! {
if let Some(mut locked_term) = TERMINAL.as_inner().try_lock() {
// The terminal may not yet be initialized.
if let Some(ref mut term) = &mut *locked_term {
let _ = core::fmt::write(term, format_args!("{}", panic_info));
let _ = core::fmt::write(term, format_args!("\x1B[1;31m{}\x1B[m", panic_info));
}
}

Expand Down

0 comments on commit c8c8e58

Please sign in to comment.