mirror of
https://github.com/esp-rs/esp-hal.git
synced 2025-10-02 14:44:42 +00:00
Force spill registers to fix missing backtrace (#3272)
This commit is contained in:
parent
d7eae19a70
commit
284b0666f0
@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- Stack traces no longer stop at recursive functions (#3270)
|
- Stack traces no longer stop at recursive functions (#3270)
|
||||||
|
- ESP32/S2/S3: Fixed an issue where the backtrace wasn't correctly captured in some cases (#3272)
|
||||||
|
|
||||||
### Removed
|
### Removed
|
||||||
|
|
||||||
|
@ -357,15 +357,40 @@ F15=0x{:08x}",
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get an array of backtrace addresses.
|
/// This function returns the caller's frame pointer.
|
||||||
pub fn backtrace() -> [Option<usize>; MAX_BACKTRACE_ADDRESSES] {
|
#[inline(never)]
|
||||||
let sp = unsafe {
|
#[cold]
|
||||||
let mut _tmp: u32;
|
fn sp() -> u32 {
|
||||||
asm!("mov {0}, a1", out(reg) _tmp);
|
let mut sp: u32;
|
||||||
_tmp
|
unsafe {
|
||||||
};
|
asm!(
|
||||||
|
"mov {0}, a1", // current stack pointer
|
||||||
|
// Spill registers, otherwise `sp - 12` will not contain the previous stack pointer
|
||||||
|
"add a12,a12,a12",
|
||||||
|
"rotw 3",
|
||||||
|
"add a12,a12,a12",
|
||||||
|
"rotw 3",
|
||||||
|
"add a12,a12,a12",
|
||||||
|
"rotw 3",
|
||||||
|
"add a12,a12,a12",
|
||||||
|
"rotw 3",
|
||||||
|
"add a12,a12,a12",
|
||||||
|
"rotw 4",
|
||||||
|
out(reg) sp
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
backtrace_internal(sp, 1)
|
// current frame pointer, caller's stack pointer
|
||||||
|
unsafe { ((sp - 12) as *const u32).read_volatile() }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get an array of backtrace addresses.
|
||||||
|
#[inline(never)]
|
||||||
|
#[cold]
|
||||||
|
pub fn backtrace() -> [Option<usize>; MAX_BACKTRACE_ADDRESSES] {
|
||||||
|
let sp = sp();
|
||||||
|
|
||||||
|
backtrace_internal(sp, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn remove_window_increment(address: u32) -> u32 {
|
pub(crate) fn remove_window_increment(address: u32) -> u32 {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user