Skip to content

Commit c5c7a76

Browse files
committed
rtos/zephyr: riscv32 thread awareness debug logs
Debug logs left here make it easier to trace openocd/zephyr's unwrapping of the riscv stacks. And could be used for extending support for riscv64. Signed-off-by: Alp Sayin <alpsayin@gmail.com>
1 parent dffb637 commit c5c7a76

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/rtos/zephyr.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,14 @@ static int zephyr_get_riscv_state(struct rtos *rtos, target_addr_t *addr,
426426
if (retval != ERROR_OK)
427427
return retval;
428428

429+
430+
#if 0
431+
for (int i = 0; i < num_callee_saved_regs; i++) {
432+
LOG_OUTPUT("%x ", *(uint32_t *)callee_saved_reg_list[i].value);
433+
}
434+
LOG_OUTPUT("\r\n");
435+
#endif
436+
429437
/* This part is a bit weird; this is absolutely necessary because rtos_generic_stack_read initializes
430438
* a neat little GDB compatible register list for us. But then we move onto reading some bogus values
431439
* because indexes are incompatble with the Zephyr callee-saved layout.
@@ -640,6 +648,9 @@ static int zephyr_fetch_thread(const struct rtos *rtos,
640648
if (retval != ERROR_OK)
641649
return retval;
642650

651+
LOG_DEBUG("thread->ptr=0x%x, thread->next_ptr=0x%x, thread->stack_pointer=0x%x",
652+
thread->ptr, thread->next_ptr, thread->stack_pointer);
653+
643654
retval = target_read_u8(rtos->target, ptr + param->offsets[OFFSET_T_STATE],
644655
&thread->state);
645656
if (retval != ERROR_OK)
@@ -692,6 +703,9 @@ static int zephyr_fetch_thread_list(struct rtos *rtos, uint32_t current_thread)
692703
return retval;
693704
}
694705

706+
LOG_DEBUG("zephyr_kptr(rtos, OFFSET_K_THREADS)=0x%x, curr=0x%x",
707+
zephyr_kptr(rtos, OFFSET_K_THREADS), curr);
708+
695709
zephyr_array_init(&thread_array);
696710

697711
for (; curr; curr = thread.next_ptr) {
@@ -704,6 +718,7 @@ static int zephyr_fetch_thread_list(struct rtos *rtos, uint32_t current_thread)
704718
goto error;
705719

706720
td->threadid = thread.ptr;
721+
LOG_DEBUG("td->threadid=0x%x", (uint32_t)td->threadid);
707722
td->exists = true;
708723

709724
if (thread.name[0])
@@ -728,6 +743,7 @@ static int zephyr_fetch_thread_list(struct rtos *rtos, uint32_t current_thread)
728743
rtos->thread_details = zephyr_array_detach_ptr(&thread_array);
729744

730745
rtos->current_threadid = curr_id;
746+
LOG_DEBUG("rtos->current_threadid=%lx", rtos->current_threadid);
731747
rtos->current_thread = current_thread;
732748

733749
return ERROR_OK;
@@ -833,6 +849,9 @@ static int zephyr_update_threads(struct rtos *rtos)
833849
LOG_ERROR("Could not fetch offsets from Zephyr");
834850
return ERROR_FAIL;
835851
}
852+
else {
853+
LOG_DEBUG("Zephyr offset %zu: 0x%" PRIx32, i, param->offsets[i]);
854+
}
836855
}
837856

838857
LOG_DEBUG("Zephyr OpenOCD support version %" PRId32,
@@ -875,6 +894,9 @@ static int zephyr_get_thread_reg_list(struct rtos *rtos, int64_t thread_id,
875894
if (!params)
876895
return ERROR_FAIL;
877896

897+
LOG_DEBUG("thread_id=%lx, params->offsets[OFFSET_T_STACK_POINTER]=%x, params->callee_saved_stacking->register_offsets[0].offset=%x",
898+
thread_id, params->offsets[OFFSET_T_STACK_POINTER], params->callee_saved_stacking->register_offsets[0].offset);
899+
878900
addr = thread_id + params->offsets[OFFSET_T_STACK_POINTER]
879901
- params->callee_saved_stacking->register_offsets[0].offset;
880902

0 commit comments

Comments
 (0)