JunyuanShen943 opened a new pull request, #22200:
URL: https://github.com/apache/nuttx/pull/22200
## Summary
* Why: an assert or crash raised in IRQ context on x86_64 printed a
backtrace that stopped at the interrupted task and never showed the
interrupt handler chain.
* IRQs ran on `g_isrstackalloc` (IST1) while `up_get_intstackbase()`
reported `g_intstackalloc`, so assert, coredump and backtrace looked
at a stack the IRQ was not using. `irq_common`'s CFI also took the
caller from the TCB save area, which a crash log does not contain.
* How: swap IST1/IST2 so hardware IRQs run on the stack that
`up_get_intstackbase()` reports and CPU exceptions keep a separate
stack; describe `irq_common` by the CPU-pushed frame as a signal
frame so gdb unwinds into the interrupted stack; let `up_backtrace()`
walk the exception stack when it is running there.
## Impact
* New feature or changed behavior: NO new feature. Backtraces from IRQ
context now include the handler chain.
* User adaptation needed: NO.
* Build: NO.
* Hardware: x86_64 (intel64) only.
* Documentation: NO.
* Security: NO.
* Compatibility: NO.
## Testing
I confirm that changes are verified on local setup and works as intended:
* Build Host: Ubuntu 22.04 x86_64, gcc 13.1.0
* Target: qemu-intel64:ostest, qemu-intel64:nsh (QEMU/KVM, x86_64)
Steps:
1. `qemu-intel64:ostest` on master and on this PR, booted with
`qemu-system-x86_64 -cpu host -enable-kvm -m 2G -kernel nuttx -nographic`:
`ostest_main: Exiting with status 0` on both.
2. `qemu-intel64:nsh` with `CONFIG_SCHED_BACKTRACE=y`,
`CONFIG_X86_64_UNWINDER_FRAME_POINTER=y`,
`CONFIG_ARCH_INTERRUPTSTACK=8192`
and a small local test program that starts a wdog whose callback calls
`ASSERT(0)` (so the assert fires in the timer interrupt).
Backtrace of the running task, resolved with addr2line:
Testing logs before change:
```
sched_dumpstack: backtrace| 4: 0x000000010090ec80 0x000000010092d90b
0x0000000100914d2b 0x000000010090b543
wd_start_abstick sched/wdog/wd_start.c:356
irqcrash_main irqcrash_main.c:24
nxtask_startup libs/libc/sched/task_startup.c:72
nxtask_start sched/task/task_start.c:72
```
Testing logs after change:
```
sched_dumpstack: backtrace| 4: 0x000000010094b80a 0x000000010092b102
0x000000010092882e ...
sched_backtrace sched/sched/sched_backtrace.c:136
sched_dumpstack libs/libc/sched/sched_dumpstack.c:74
dump_assert_info sched/misc/assert.c:772
__assert libs/libc/assert/lib_assert.c:39
irqcrash_level2 irqcrash_main.c:12
irqcrash_cb irqcrash_main.c:19
wd_expiration sched/wdog/wd_start.c:152
oneshot_callback drivers/timers/arch_alarm.c:166
intel64_tsc_compare_isr arch/x86_64/src/intel64/intel64_tsc_oneshot.c:187
irq_dispatch sched/irq/irq_dispatch.c:165
common_handler arch/x86_64/src/intel64/intel64_handlers.c:77
irq_common arch/x86_64/src/intel64/intel64_vectors.S:816
wd_start_abstick sched/wdog/wd_start.c:356
irqcrash_main irqcrash_main.c:24
nxtask_startup libs/libc/sched/task_startup.c:72
nxtask_start sched/task/task_start.c:72
```
Also: `tools/checkpatch.sh -m` clean, sim:nsh make and CMake builds and
ostest pass. Verified on QEMU only, not on physical x86_64 hardware.
## PR verification Self-Check
* [x] This PR introduces only one functional change.
* [x] I have updated all required description fields above.
* [x] My PR adheres to Contributing Guidelines and Documentation (git commit
title and message, coding standard, etc).
* [ ] My PR is still work in progress (not ready for review).
* [x] My PR is ready for review and can be safely merged into a codebase.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]