Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/rtos/zephyr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,20 @@ static int zephyr_fetch_thread_list(struct rtos *rtos, uint32_t current_thread)
rtos->thread_count = (int)thread_array.elements;
rtos->thread_details = zephyr_array_detach_ptr(&thread_array);

/* Reorder thread list so current thread is first (Thread 1 in GDB).
* This fixes the issue where GDB caches live CPU registers for Thread 1
* before the thread list is populated, causing incorrect backtraces. */
td = rtos->thread_details;
for (size_t i = 1; i < (size_t)rtos->thread_count; i++) {
if (td[i].threadid == current_thread) {
struct thread_detail tmp = td[0];
td[0] = td[i];
td[i] = tmp;
LOG_DEBUG("Zephyr: moved current thread to position 0");
break;
}
}

rtos->current_thread = current_thread;

return ERROR_OK;
Expand Down