diff --git a/src/lib.rs b/src/lib.rs index 516569f..02d1496 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -83,7 +83,7 @@ fn panic_handler(info: &core::panic::PanicInfo) -> ! { } for e in backtrace { if let Some(addr) = e { - println!("0x{:x}", addr); + println!("0x{:x}", addr - crate::arch::RA_OFFSET); } } diff --git a/src/riscv.rs b/src/riscv.rs index b315d78..b597b02 100644 --- a/src/riscv.rs +++ b/src/riscv.rs @@ -1,6 +1,13 @@ use crate::MAX_BACKTRACE_ADDRESSES; use core::arch::asm; +// subtract 4 from the return address +// the return address is the address following the JALR +// we get better results (especially if the caller was the last function in the calling function) +// if we report the address of the JALR itself +// even if it was a C.JALR we should get good results using RA - 4 +pub(super) const RA_OFFSET: usize = 4; + /// Registers saved in trap handler #[doc(hidden)] #[allow(missing_docs)] diff --git a/src/xtensa.rs b/src/xtensa.rs index 7af2314..60a4920 100644 --- a/src/xtensa.rs +++ b/src/xtensa.rs @@ -1,6 +1,12 @@ use crate::MAX_BACKTRACE_ADDRESSES; use core::arch::asm; +// subtract 3 from the return address +// the return address is the address following the callxN +// we get better results (especially if the caller was the last function in the calling function) +// if we report the address of callxN itself +pub(super) const RA_OFFSET: usize = 3; + #[doc(hidden)] #[allow(missing_docs)] #[derive(Debug, Clone, Copy)]