-
Notifications
You must be signed in to change notification settings - Fork 6.1k
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
arch: riscv: implement frame-pointer based stack unwinding #69912
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,24 @@ config RISCV_ALWAYS_SWITCH_THROUGH_ECALL | |
and most people should say n here to minimize context switching | ||
overhead. | ||
|
||
config RISCV_ENABLE_FRAME_POINTER | ||
bool | ||
default y | ||
depends on OVERRIDE_FRAME_POINTER_DEFAULT && !OMIT_FRAME_POINTER | ||
help | ||
Hidden option to simplify access to OVERRIDE_FRAME_POINTER_DEFAULT | ||
and OMIT_FRAME_POINTER. It is automatically enabled when the frame | ||
pointer unwinding is enabled. | ||
|
||
config RISCV_EXCEPTION_STACK_TRACE | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
bool | ||
default y | ||
depends on RISCV_ENABLE_FRAME_POINTER | ||
depends on EXCEPTION_STACK_TRACE | ||
imply THREAD_STACK_INFO | ||
help | ||
Internal config to enable runtime stack traces on fatal exceptions. | ||
|
||
menu "RISCV Processor Options" | ||
|
||
config INCLUDE_RESET_VECTOR | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,10 @@ Architectures | |
|
||
* ARM | ||
|
||
* RISC-V | ||
|
||
* Implemented frame-pointer based stack unwinding. | ||
|
||
* Xtensa | ||
|
||
Bluetooth | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Copyright (c) 2024 Meta | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
cmake_minimum_required(VERSION 3.20.0) | ||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) | ||
project(stack_unwind_test) | ||
|
||
FILE(GLOB app_sources src/*.c) | ||
target_sources(app PRIVATE ${app_sources}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
CONFIG_TEST=y | ||
|
||
CONFIG_LOG=y | ||
CONFIG_LOG_BUFFER_SIZE=2048 | ||
|
||
CONFIG_EXCEPTION_STACK_TRACE=y | ||
CONFIG_OVERRIDE_FRAME_POINTER_DEFAULT=y | ||
CONFIG_OMIT_FRAME_POINTER=n | ||
CONFIG_DEBUG=y | ||
CONFIG_DEBUG_INFO=y | ||
CONFIG_DEBUG_OPTIMIZATIONS=y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright (c) 2024 Meta | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <stdbool.h> | ||
|
||
#include <zephyr/kernel.h> | ||
|
||
static void func1(int a); | ||
static void func2(int a); | ||
|
||
static void func2(int a) | ||
{ | ||
printf("%d: %s\n", a, __func__); | ||
|
||
if (a >= 5) { | ||
k_oops(); | ||
} | ||
|
||
func1(a + 1); | ||
} | ||
|
||
static void func1(int a) | ||
{ | ||
printf("%d: %s\n", a, __func__); | ||
func2(a + 1); | ||
} | ||
|
||
int main(void) | ||
{ | ||
printf("Hello World! %s\n", CONFIG_BOARD); | ||
|
||
func1(1); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
common: | ||
harness: console | ||
ignore_faults: true | ||
ignore_qemu_crash: true | ||
tags: kernel | ||
tests: | ||
arch.common.stack_unwind.riscv: | ||
arch_allow: riscv | ||
integration_platforms: | ||
- qemu_riscv32 | ||
- qemu_riscv64 | ||
harness_config: | ||
type: multi_line | ||
regex: | ||
- "E: call trace:" | ||
- "E: 0: fp: \\w+ ra: \\w+" | ||
- "E: 1: fp: \\w+ ra: \\w+" | ||
arch.common.stack_unwind.x86: | ||
arch_allow: x86 | ||
extra_configs: | ||
- CONFIG_NO_OPTIMIZATIONS=y | ||
integration_platforms: | ||
- qemu_x86 | ||
- qemu_x86_64 | ||
harness_config: | ||
type: multi_line | ||
regex: | ||
- "E: call trace:" | ||
- "E: (E|R)IP: \\w+" | ||
arch.common.stack_unwind.arm: | ||
arch_allow: | ||
- arm64 | ||
integration_platforms: | ||
- qemu_cortex_a53 | ||
harness_config: | ||
type: multi_line | ||
regex: | ||
- "E: backtrace 0: fp: \\w+ lr: \\w+" | ||
- "E: backtrace 1: fp: \\w+ lr: \\w+" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would be nice to make this a generic arch kconfig (CONFIG_FRAME_POINTER), we now have two architectures doing this