From 189fa64b3f1daf21ce2909edb61bff935223eaaf Mon Sep 17 00:00:00 2001 From: Fenrir Date: Fri, 5 Aug 2016 02:23:52 -0700 Subject: [PATCH] Implement proper panic messages --- src/lib.rs | 8 +------- src/panic.rs | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 7 deletions(-) create mode 100644 src/panic.rs diff --git a/src/lib.rs b/src/lib.rs index ca5c249..618bed9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,14 +11,8 @@ pub mod gfx; pub mod sdmc; pub mod services; +pub mod panic; pub use srv::Srv; pub use gfx::Gfx; pub use sdmc::Sdmc; - -#[lang = "eh_personality"] -extern "C" fn eh_personality() {} -#[lang = "panic_fmt"] -fn panic_fmt() -> ! { - unsafe { libctru::libc::abort() } -} diff --git a/src/panic.rs b/src/panic.rs new file mode 100644 index 0000000..c0e4d0a --- /dev/null +++ b/src/panic.rs @@ -0,0 +1,22 @@ +use core::fmt::{Arguments, Write}; + +#[lang = "eh_personality"] +extern "C" fn eh_personality() {} + +#[lang = "panic_fmt"] +extern fn panic_fmt(fmt: Arguments, file: &str, line: u32) -> ! { + use gfx::Screen; + use console::Console; + + let mut error_top = Console::init(Screen::Top); + let mut error_bottom = Console::init(Screen::Bottom); + + writeln!(error_top, "--------------------------------------------------").unwrap(); + writeln!(error_top, "PANIC in {} at line {}:", file, line).unwrap(); + writeln!(error_top, " {}", fmt).unwrap(); + write!(error_top, "\x1b[29;00H--------------------------------------------------").unwrap(); + + writeln!(error_bottom, "").unwrap(); + + loop {} +}