Replace hardcoded instruction length with size_of in backtrace

master
Jiajie Chen 6 years ago
parent 5350ecb09f
commit 6e887d5505

@ -1,3 +1,5 @@
use core::intrinsics::size_of;
extern "C" { extern "C" {
fn stext(); fn stext();
fn etext(); fn etext();
@ -45,7 +47,7 @@ pub fn backtrace() {
let mut current_fp = fp(); let mut current_fp = fp();
let mut stack_num = 0; let mut stack_num = 0;
while current_pc >= stext as usize && current_pc <= etext as usize && current_fp as usize != 0 { while current_pc >= stext as usize && current_pc <= etext as usize && current_fp as usize != 0 {
println!("#{} {:#018X} fp {:#018X}", stack_num, current_pc - 4, current_fp); println!("#{} {:#018X} fp {:#018X}", stack_num, current_pc - size_of::<usize>(), current_fp);
stack_num = stack_num + 1; stack_num = stack_num + 1;
#[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))] #[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))]
{ {

@ -6,6 +6,7 @@
#![feature(optin_builtin_traits)] #![feature(optin_builtin_traits)]
#![feature(panic_info_message)] #![feature(panic_info_message)]
#![feature(global_asm)] #![feature(global_asm)]
#![feature(core_intrinsics)]
#![no_std] #![no_std]
// just keep it ... // just keep it ...

Loading…
Cancel
Save