Skip to content
This repository has been archived by the owner on May 23, 2024. It is now read-only.

Commit

Permalink
Improve backtrace (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
bjoernQ authored Jan 31, 2024
1 parent 445b700 commit cd74226
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
7 changes: 7 additions & 0 deletions src/riscv.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
6 changes: 6 additions & 0 deletions src/xtensa.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down

0 comments on commit cd74226

Please sign in to comment.