mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-30 00:23:24 +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.
|
//! Panic support.
|
||||||
|
|
||||||
use alloc::{boxed::Box, string::ToString};
|
|
||||||
use core::ffi::c_void;
|
use core::ffi::c_void;
|
||||||
|
|
||||||
use log::error;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
arch::qemu::{exit_qemu, QemuExitCode},
|
arch::qemu::{exit_qemu, QemuExitCode},
|
||||||
early_print, early_println,
|
early_print, early_println,
|
||||||
@ -15,12 +12,9 @@ use crate::{
|
|||||||
extern crate cfg_if;
|
extern crate cfg_if;
|
||||||
extern crate gimli;
|
extern crate gimli;
|
||||||
use gimli::Register;
|
use gimli::Register;
|
||||||
use unwinding::{
|
use unwinding::abi::{
|
||||||
abi::{
|
|
||||||
UnwindContext, UnwindReasonCode, _Unwind_Backtrace, _Unwind_FindEnclosingFunction,
|
UnwindContext, UnwindReasonCode, _Unwind_Backtrace, _Unwind_FindEnclosingFunction,
|
||||||
_Unwind_GetGR, _Unwind_GetIP,
|
_Unwind_GetGR, _Unwind_GetIP,
|
||||||
},
|
|
||||||
panic::begin_panic,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The panic handler must be defined in the binary crate or in the crate that the binary
|
/// The panic handler must be defined in the binary crate or in the crate that the binary
|
||||||
@ -29,6 +23,13 @@ use unwinding::{
|
|||||||
/// panic handler in the binary crate.
|
/// panic handler in the binary crate.
|
||||||
#[export_name = "__aster_panic_handler"]
|
#[export_name = "__aster_panic_handler"]
|
||||||
pub fn panic_handler(info: &core::panic::PanicInfo) -> ! {
|
pub fn panic_handler(info: &core::panic::PanicInfo) -> ! {
|
||||||
|
// 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 {
|
let throw_info = ostd_test::PanicInfo {
|
||||||
message: info.message().to_string(),
|
message: info.message().to_string(),
|
||||||
file: info.location().unwrap().file().to_string(),
|
file: info.location().unwrap().file().to_string(),
|
||||||
@ -37,9 +38,7 @@ pub fn panic_handler(info: &core::panic::PanicInfo) -> ! {
|
|||||||
};
|
};
|
||||||
// Throw an exception and expecting it to be caught.
|
// Throw an exception and expecting it to be caught.
|
||||||
begin_panic(Box::new(throw_info.clone()));
|
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!");
|
|
||||||
early_println!("{}", info);
|
early_println!("{}", info);
|
||||||
early_println!("printing stack trace:");
|
early_println!("printing stack trace:");
|
||||||
print_stack_trace();
|
print_stack_trace();
|
||||||
|
Reference in New Issue
Block a user