Skip to content

Zephyr: support RISC-V stack pointer and don't hang the panel on errors - #103

Merged
haneefdm merged 1 commit into
mcu-debug:mainfrom
emece67:zephyr-riscv-stack-pointer
Oct 20, 2026
Merged

haneefdm merged 1 commit into
mcu-debug:mainfrom
emece67:zephyr-riscv-stack-pointer

Conversation

@emece67

@emece67 emece67 commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Problem

On a Zephyr target that is not Cortex-M (seen on an ESP32-C6, RISC-V, Zephyr 4.2, Cortex-Debug 1.12.1 + OpenOCD), the xRTOS panel detects Zephyr and then stays on "RTOS Views: Busy updating..." forever.

Two things combine:

  1. getStackInfo() reads callee_saved.psp, which only exists on Cortex-M (the code already has a FIXME about this). On RISC-V struct _callee_saved has sp, ra, s0…s11, so callee_saved.psp is undefined and .val throws.
  2. That exception is caught in getThreadInfo(), but the catch only logs it and never settles the promise, so refresh() never completes and the panel stays busy.

Fix

  • Use callee_saved.psp ?? callee_saved.sp. Cortex-M behaviour is unchanged (psp is still used when present).
  • Call resolve() in that catch, so an unexpected error shows the threads collected so far instead of hanging the view.

With both changes the panel shows the main and idle threads with their name, priority, running state and stack usage on the ESP32-C6.

Other things noticed (not addressed here)

  • Each thread sometimes appears twice, and the footer then reads "in 109 ms in 118 ms": two refresh() calls run concurrently and both push into the shared foundThreads.
  • The idle thread shows status ???. Zephyr never queues the idle thread, so its thread_state is 0, which has no name in OsTaskState.

🤖 Generated with Claude Code

getStackInfo() read callee_saved.psp, which only exists on Cortex-M.
On RISC-V the saved stack pointer is callee_saved.sp, so .val threw.
The exception was caught in getThreadInfo(), whose catch never settled
the promise, leaving the panel on "Busy updating..." forever.

Fall back to callee_saved.sp when psp is absent (Cortex-M unchanged)
and resolve() in that catch so errors show the threads found so far.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@haneefdm
haneefdm merged commit f645291 into mcu-debug:main Oct 20, 2026
3 checks passed
@haneefdm

Copy link
Copy Markdown
Member

Good fix. Especially not having a resolve()

Looks like a safe fix for non-Cortex-M processors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants