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

xtensa/esp32[|s2|s3]: Fix task backtrace dump #13546

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

tmedicci
Copy link
Contributor

Summary

  • Documentation: Document stack and backtrace dump for Espressif SoCs

    • Stack and backtrace dump for Espressif's SoCs (ESP32, ESP32-S2, ESP32-S3, ESP32-C3, ESP32-C6 and ESP32-H2) is now documented in a new section for each chip entry page.
  • xtensa/esp32[|s2|s3]: Fix task backtrace dump

    • Fix MAKE_PC_FROM_RA macro to consider the instruction region base address;
    • Add sanity check for calculated PC and SP registers;
    • Check if the stack pointer is within the interrupt stack to enable backtrace dump if an exception occurs during the ISR;
    • Update the script for decoding the backtrace dump to consider the syntax of the backtrace format and properly handle the dump when SMP is enabled;
  • xtensa/Kconfig: Fix dependency for backtrace dump on Xtensas

    • CONFIG_XTENSA_INTBACKTRACE is necessary to enable backtrace dump for the tasks because exceptions are treated like interrupts (even when an exception occurs during a normal task execution). It's now automatically selected when CONFIG_SCHED_BACKTRACE is enabled. This commit also removes outdated Kconfig options.

Impact

Fix backtrace dump on assertions considering assertions triggered by tasks or during an interrupt service.

Testing

Internal CI testing with HW on all Xtensa-based devices.

How to Test on ESP32:

Use esp32-devkitc:nsh. Enable CONFIG_SCHED_BACKTRACE and CONFIG_SYSTEM_DUMPSTACK. On nsh, run dumpstack:

nsh> dumpstack
sched_dumpstack: backtrace| 2: 0x400ee9bc 0x400ef817 0x400e2d0b 0x400e1d63 0x40000000

Save this output to a file and use ./tools/espressif/btdecode.sh esp32 /tmp/backtrace.txt to check the backtrace dump:

./tools/espressif/btdecode.sh esp32 /tmp/backtrace.txt       
Backtrace for task 2:
0x400ee9bc: sched_dumpstack at ??:?
0x400ef817: dumpstack_main at ??:?
0x400e2d0b: nxtask_startup at ??:?
0x400e1d63: nxtask_start at ??:?
0x40000000: ?? ??:0

Before this PR, the output would generate wrong addresses:

Backtrace for task 2:
0x000ee998: ?? ??:0
0x000ef7f3: ?? ??:0
0x000e2ce7: ?? ??:0
0x000e1d3f: ?? ??:0

@github-actions github-actions bot added the Size: L The size of the change in this PR is large label Sep 19, 2024
@nuttxpr
Copy link

nuttxpr commented Sep 19, 2024

[Experimental Bot, please feedback here]

Squash The Commits: This PR contains 3 Commits. Please Squash the Multiple Commits into a Single Commit.

NuttX PR Requirements Review

This PR appears to meet the NuttX requirements. Here's a breakdown:

Summary:

  • Clear explanation of the change: The summary clearly states the purpose of the change, addressing a fix for the backtrace dump functionality specifically for Espressif SoCs.
  • Functional area: The affected area is clearly identified (stack and backtrace dump for xtensa/esp32).
  • Mechanism: The summary outlines how the change works, including fixes to the MAKE_PC_FROM_RA macro, sanity checks, and script updates.
  • Issue references: While not explicitly mentioned, the summary implies addressing an existing issue with backtrace dumps on the mentioned architectures. It would be beneficial to add specific issue references if applicable.

Impact:

  • Feature change: This PR focuses on fixing an existing feature (backtrace dump), not introducing a new one.
  • User impact: No user-facing changes are described, implying minimal impact.
  • Build impact: No build process changes are mentioned.
  • Hardware impact: The changes are specific to Xtensa-based devices, specifically ESP32 and its variants, which is clearly stated.
  • Documentation impact: The summary explicitly mentions updating documentation for each affected chip.
  • Security impact: No security implications are mentioned.
  • Compatibility impact: No backward or forward compatibility issues are mentioned.

Testing:

  • Verification: The author confirms testing on local setup with positive results.
  • Host and Target: While "Internal CI testing" is mentioned, listing specific host OS, compiler versions, and target boards used for testing would strengthen the validation.
  • Logs: The PR provides clear steps to reproduce the issue and verify the fix on an ESP32. Including snippets of actual logs before and after the change would further enhance the testing section.

Overall:

This PR demonstrates a good understanding of NuttX requirements. Adding specific issue references and detailing the testing environment would further strengthen it.

`CONFIG_XTENSA_INTBACKTRACE` is necessary to enable backtrace dump
for the tasks because exceptions are treated like interrupts (even
when an exception occurs during a normal task execution). It's now
automatically selected when `CONFIG_SCHED_BACKTRACE` is enabled.
This commit also removes outdated Kconfig options.
- Fix `MAKE_PC_FROM_RA` macro to consider the instruction region
base address;
- Add sanity check for calculated PC and SP registers;
- Check if the stack pointer is within the interrupt stack to
enable backtrace dump if an exception occurs during the ISR;
- Update the script for decoding the backtrace dump to consider the
syntax of the backtrace format and properly handle the dump when
SMP is enabled;
Stack and backtrace dump for Espressif's SoCs (ESP32, ESP32-S2,
ESP32-S3, ESP32-C3, ESP32-C6 and ESP32-H2) is now documented in a
new section for each chip entry page.
@tmedicci tmedicci force-pushed the improvement/xtensa_int_backtrace branch from 6bb1570 to a7a4aae Compare September 19, 2024 20:14
bool "Full backtrace from interrupts"
default n
depends on XTENSA_DUMPBT_ON_ASSERT
bool
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how to disable this option if without the prompt string?

@@ -0,0 +1,144 @@
#!/usr/bin/env bash
############################################################################
# tools/espressif/btdecode.sh
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's a general tool, let's move out of espressif folder


# Set the appropriate addr2line tool based on the chip

case $chip in
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's support specify toolchain directly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Size: L The size of the change in this PR is large
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants