Backtrace: panic handler with proper backtrace.
This commit is contained in:
parent
3f2024e4e0
commit
f3c3bd7384
|
@ -39,6 +39,7 @@ mod llvm_libunwind {
|
||||||
let cfg = &mut cc::Build::new();
|
let cfg = &mut cc::Build::new();
|
||||||
setup_options(cfg);
|
setup_options(cfg);
|
||||||
cfg.compiler("clang");
|
cfg.compiler("clang");
|
||||||
|
cfg.flag("-funwind-tables");
|
||||||
|
|
||||||
let unwind_sources = vec![
|
let unwind_sources = vec![
|
||||||
"Unwind-sjlj.c",
|
"Unwind-sjlj.c",
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
#![no_main]
|
#![no_main]
|
||||||
#![recursion_limit="1024"] // for futures_util::select!
|
#![recursion_limit="1024"] // for futures_util::select!
|
||||||
#![feature(llvm_asm)]
|
#![feature(llvm_asm)]
|
||||||
|
#![feature(alloc_error_handler)]
|
||||||
|
#![feature(panic_info_message)]
|
||||||
|
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
|
|
||||||
|
@ -24,6 +26,7 @@ mod kernel;
|
||||||
mod moninj;
|
mod moninj;
|
||||||
mod load_pl;
|
mod load_pl;
|
||||||
mod eh_artiq;
|
mod eh_artiq;
|
||||||
|
mod panic;
|
||||||
|
|
||||||
fn identifier_read(buf: &mut [u8]) -> &str {
|
fn identifier_read(buf: &mut [u8]) -> &str {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
|
@ -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 {}
|
||||||
|
}
|
Loading…
Reference in New Issue