fix(rtos/zephyr): place current thread first in thread list (OCD-1334)#391
fix(rtos/zephyr): place current thread first in thread list (OCD-1334)#391wes-myers-II wants to merge 1 commit into
Conversation
Workaround for GDB caching live CPU registers before thread list is available. Reorder threads so current thread is first, ensuring Thread 1's cached registers match the actual running thread. Signed-off-by: Wesley Myers <wesleygenemyers@gmail.com>
|
@wes-myers-II thanks for the PR. When the target is halted, OpenOCD reports the current thread ID to GDB. After that, GDB requests the registers for all threads one by one. Before moving forward with this change, it would be helpful to review the relevant logs to better understand the current behavior. Additionally, if this turns out to be an issue, it should be handled in a place that applies to all RTOS implementations. In that case, the appropriate place for the fix would be rtos.c. Could you please share the OpenOCD verbose logs (using -d3) as well as the GDB remote protocol logs? The latter can be enabled with |
Hey @erhankur, I'll take a look at this and address your comments on my other PR soon. Have been pulled into another task, but will return. |
|
@wes-myers-II any update? If not, I will close this PR soon. |
Summary
Workaround for Thread 1 displaying incorrect backtraces when debugging Zephyr applications.
Problem
When GDB connects to OpenOCD with RTOS awareness:
Result: Thread 1 "stats" shows idle's backtrace (
arch_cpu_idle()).Fix
Reorder the thread list so the current thread is always first. This ensures:
This is a Workaround
This fix addresses the symptom, not the root cause. A proper fix would require changes to GDB:
Since GDB protocol changes would require upstream GDB maintainer buy-in and could take significant time, this workaround provides immediate relief. The resulting behavior (Thread 1 = current thread) also matches most users' expectations.
Verification
Before:
After:
Related
This complements PR #390 which fixes register values for non-current threads.
Both issues were discovered while debugging Zephyr on ESP32-S3.