Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

frame point trace is in loop #375

Open
wangwss opened this issue Sep 24, 2024 · 1 comment
Open

frame point trace is in loop #375

wangwss opened this issue Sep 24, 2024 · 1 comment

Comments

@wangwss
Copy link

wangwss commented Sep 24, 2024

when I use rust write os in qemu, I wrote a stack trace function to resolve frame point trace, but found qemu in loop.
my code is like this:
pub unsafe fn print_stack_trace() {
let mut fp: *const usize;

asm!("mv {}, fp", out(reg) fp);

let mut saved_ra = *fp.sub(1);
let mut saved_fp = *fp.sub(2);

println!("== Begin stack trace ==");

while (!fp.is_null() && saved_fp != 0) || (saved_ra == *fp) {
    println!("0x{:016x}, fp = 0x{:016x}", saved_ra, saved_fp);

    fp = saved_fp as *const usize;

    saved_ra = *fp.sub(1);
    saved_fp = *fp.sub(2);
}

println!("== End stack trace ==");

}

but with "-bios opensbi.bin" ,the console out like this:
ra =0x0000000080200010, fp = 0x000000008020fa60
ra =0x0000000080210158, fp = 0x000000008020fcd0
ra =0x0000000080213c3c, fp = 0x000000008020fd10
ra =0x0000000080212190, fp = 0x0000000080210010
ra =0x0000000080200010, fp = 0x000000008020fa60
.........
when I use "-bios rustsbi.bin" (version 0.0.4") run the same code ,the console out like this:
== Begin stack trace ==
0x0000000080210158, fp = 0x000000008020fcd0
0x0000000080213c3c, fp = 0x000000008020fd10
0x0000000080212190, fp = 0x0000000080210010
== End stack trace ==

the result is correct.

Then I write out the ra & fp ,found when
use rustsbi : ra = 0x0000000080210010,fp=0,
so that the code is correct over.
but use opensbi :ra =0x0000000080200010, fp = 0x000000008020fa60
fp is not null, so that is in loop.

where opensbi code has bug?

@wxjstz
Copy link
Contributor

wxjstz commented Dec 17, 2024

I don't know where you call this function, but opensbi uses -O2 to compile by default, and the frame pointer will be optimized away.

Regards,
Xiang W

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants