mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-29 15:33:22 +00:00
Stop trying to catch panics except for unit tests
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
460234a18b
commit
da9f55b01f
@ -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();
|
||||
|
Reference in New Issue
Block a user