| #
2661af29 |
| 26-May-2023 |
Alvin Chang <alvinga@andestech.com> |
libunw: Implement RISC-V stack unwinding
This patch implements stack unwinding for RISC-V architecture into libunw. In RISC-V, the caller stores its frame pointer into register s0 before calling the
libunw: Implement RISC-V stack unwinding
This patch implements stack unwinding for RISC-V architecture into libunw. In RISC-V, the caller stores its frame pointer into register s0 before calling the function. In the prologue of callee function, the return address and the caller's frame pointer are saved into the bottom of the callee's stack frame, and the callee's frame pointer is also calculated and stored into s0 within the process of callee function. Therefore, the caller's stack frame can be traced back from the callee's stack frame.
The following steps describe the stack unwinding on RV64 system: 1. When an exception occurs, we get the current frame pointer from trapped register s0/fp. 2. Get the ra from the memory address (fp-0x8). 3. Get the caller's frame pointer from the memory address (fp-0x10). 4. Update the caller's pc as (ra-0x4), this is information we want from stack unwinding. 5. Repeat the step 2 to step 4, until we exceed the stack frame of the thread.
Signed-off-by: Alvin Chang <alvinga@andestech.com> Acked-by: Jerome Forissier <jerome.forissier@linaro.org> Acked-by: Etienne Carriere <etienne.carriere@foss.st.com>
show more ...
|