Skip to content

arch/tricore: Improve up_backtrace implementation#18910

Merged
xiaoxiang781216 merged 1 commit into
apache:masterfrom
zyfeier:tricore/add-backtrace
May 21, 2026
Merged

arch/tricore: Improve up_backtrace implementation#18910
xiaoxiang781216 merged 1 commit into
apache:masterfrom
zyfeier:tricore/add-backtrace

Conversation

@zyfeier
Copy link
Copy Markdown
Contributor

@zyfeier zyfeier commented May 20, 2026

Summary

Improve the existing TriCore up_backtrace() implementation (merged in #18899):

  1. Conditional compilation — Make tricore_backtrace.c conditional on CONFIG_SCHED_BACKTRACE, consistent with RISC-V and ARM architectures.
  2. NULL return address check — Terminate backtrace early when csa[REG_UA11] == 0 to avoid invalid entries.
  3. Fix non-current task backtrace — Use regs[REG_LPCXI] instead of tricore_addr2csa(tcb->xcp.regs) to preserve the UL bit needed for correct CSA type identification.

Testing

Verified on TC4D9 EVB (triboard_tc4x9_com:nsh) with CONFIG_SCHED_BACKTRACE=y:

  • ostest passes completely (Exiting with status 0)
  • Triggered PANIC() in hello app, backtrace output:
sched_dumpstack: backtrace| 4: 0x80028be4 0x80024650 0x800141b0 0x800144aa 0x800115d0 0x80011570

addr2line verification:

0x80028be4 → sched_dumpstack (libs/libc/sched/sched_dumpstack.c:71)
0x80024650 → dump_assert_info (sched/misc/assert.c:727)
0x800141b0 → __assert (libs/libc/assert/lib_assert.c:39)
0x800144aa → nxtask_startup (libs/libc/sched/task_startup.c:72)
0x800115d0 → nxtask_start (sched/task/task_start.c:72)
0x80011570 → nxtask_start (sched/task/task_start.c:70)

Call chain is correct. User-space functions (hello_main/func_a/func_b/func_c) are not in backtrace because the compiler optimized them into tail-jumps (j instead of call), which is expected TriCore behavior — only call instructions save Upper CSA.

@zyfeier zyfeier force-pushed the tricore/add-backtrace branch from b732d96 to 921d776 Compare May 20, 2026 07:45
@zyfeier zyfeier changed the title arch/tricore: Add backtrace arch/tricore: Add backtrace. May 20, 2026
@xiaoxiang781216
Copy link
Copy Markdown
Contributor

@zyfeier please fix the conflict

1. Make tricore_backtrace.c conditional on CONFIG_SCHED_BACKTRACE,
   consistent with RISC-V and ARM architectures.
2. Add NULL return address check to terminate early on invalid entries.
3. Fix non-current task backtrace to use regs[REG_LPCXI] which
   preserves the UL bit needed for correct CSA type identification.

Signed-off-by: liwenxiang1 <liwenxiang1@xiaomi.com>
@zyfeier zyfeier force-pushed the tricore/add-backtrace branch from 921d776 to 058a3d4 Compare May 20, 2026 13:54
@zyfeier zyfeier changed the title arch/tricore: Add backtrace. arch/tricore: Improve up_backtrace implementation May 20, 2026
@zyfeier zyfeier marked this pull request as ready for review May 20, 2026 13:55
@github-actions github-actions Bot added Arch: tricore Issues related to the TriCore architecture from Infineon Size: S The size of the change in this PR is small labels May 20, 2026
@xiaoxiang781216 xiaoxiang781216 merged commit bb27808 into apache:master May 21, 2026
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Arch: tricore Issues related to the TriCore architecture from Infineon Size: S The size of the change in this PR is small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants