From da9f55b01f8fda55fd33d976c02f1ccc011a85f5 Mon Sep 17 00:00:00 2001 From: Zhang Junyang Date: Sat, 27 Jul 2024 05:34:27 +0000 Subject: [PATCH] Stop trying to catch panics except for unit tests --- ostd/src/panicking.rs | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/ostd/src/panicking.rs b/ostd/src/panicking.rs index d9e4cb1fb..54d3de1e8 100644 --- a/ostd/src/panicking.rs +++ b/ostd/src/panicking.rs @@ -2,11 +2,8 @@ //! Panic support. -use alloc::{boxed::Box, string::ToString}; use core::ffi::c_void; -use log::error; - use crate::{ arch::qemu::{exit_qemu, QemuExitCode}, early_print, early_println, @@ -15,12 +12,9 @@ use crate::{ extern crate cfg_if; extern crate gimli; use gimli::Register; -use unwinding::{ - abi::{ - UnwindContext, UnwindReasonCode, _Unwind_Backtrace, _Unwind_FindEnclosingFunction, - _Unwind_GetGR, _Unwind_GetIP, - }, - panic::begin_panic, +use unwinding::abi::{ + UnwindContext, UnwindReasonCode, _Unwind_Backtrace, _Unwind_FindEnclosingFunction, + _Unwind_GetGR, _Unwind_GetIP, }; /// The panic handler must be defined in the binary crate or in the crate that the binary @@ -29,17 +23,22 @@ use unwinding::{ /// panic handler in the binary crate. #[export_name = "__aster_panic_handler"] pub fn panic_handler(info: &core::panic::PanicInfo) -> ! { - let throw_info = ostd_test::PanicInfo { - message: info.message().to_string(), - file: info.location().unwrap().file().to_string(), - line: info.location().unwrap().line() as usize, - col: info.location().unwrap().column() as usize, - }; - // Throw an exception and expecting it to be caught. - begin_panic(Box::new(throw_info.clone())); - // If the exception is not caught (e.g. by ktest) and resumed, - // then print the information and abort. - error!("Uncaught panic!"); + // If in ktest, we would like to catch the panics and resume the test. + #[cfg(ktest)] + { + use alloc::{boxed::Box, string::ToString}; + + use unwinding::panic::begin_panic; + + let throw_info = ostd_test::PanicInfo { + message: info.message().to_string(), + file: info.location().unwrap().file().to_string(), + line: info.location().unwrap().line() as usize, + col: info.location().unwrap().column() as usize, + }; + // Throw an exception and expecting it to be caught. + begin_panic(Box::new(throw_info.clone())); + } early_println!("{}", info); early_println!("printing stack trace:"); print_stack_trace();