riscv-software-src / riscv-software-src/opensbi

frame point trace is in loop

Open
#375 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
1.5k
Forks
712
PR merge metrics
No merged PRs in 30d

Description

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?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the stack trace with QEMU using both opensbi.bin and rustsbi.bin, comparing the reported ra and fp values. Start from the supplied print_stack_trace entry point and determine whether OpenSBI or the caller's frame-pointer termination assumptions produce the repeated frame; done means the cause is identified and the differing behavior is explained.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.