Backtrace: panic handler with proper backtrace.

This commit is contained in:
pca006132 2020-07-02 13:10:11 +08:00
parent 3f2024e4e0
commit f3c3bd7384
3 changed files with 30 additions and 0 deletions

View File

@ -39,6 +39,7 @@ mod llvm_libunwind {
let cfg = &mut cc::Build::new();
setup_options(cfg);
cfg.compiler("clang");
cfg.flag("-funwind-tables");
let unwind_sources = vec![
"Unwind-sjlj.c",

View File

@ -2,6 +2,8 @@
#![no_main]
#![recursion_limit="1024"] // for futures_util::select!
#![feature(llvm_asm)]
#![feature(alloc_error_handler)]
#![feature(panic_info_message)]
extern crate alloc;
@ -24,6 +26,7 @@ mod kernel;
mod moninj;
mod load_pl;
mod eh_artiq;
mod panic;
fn identifier_read(buf: &mut [u8]) -> &str {
unsafe {

26
src/runtime/src/panic.rs Normal file
View File

@ -0,0 +1,26 @@
use libboard_zynq::{slcr, print, println};
use unwind::backtrace;
#[panic_handler]
fn panic(info: &core::panic::PanicInfo) -> ! {
print!("panic at ");
if let Some(location) = info.location() {
print!("{}:{}:{}", location.file(), location.line(), location.column());
} else {
print!("unknown location");
}
if let Some(message) = info.message() {
println!(": {}", message);
} else {
println!("");
}
println!("Backtrace: ");
let _ = backtrace(|ip| {
// Backtrace gives us the return address, i.e. the address after the delay slot,
// but we're interested in the call instruction.
println!("{:#08x}", ip - 2 * 4);
});
println!("End backtrace");
slcr::RegisterBlock::unlocked(|slcr| slcr.soft_reset());
loop {}
}