risc-v/backtrace: correct stack pointer if enable ARCH_KERNEL_STACK

Signed-off-by: chao an <anchao@xiaomi.com>
This commit is contained in:
chao an 2023-06-06 09:33:25 +08:00 committed by Xiang Xiao
parent b7b3c3c550
commit 76e5204a80

View File

@ -162,20 +162,44 @@ int up_backtrace(struct tcb_s *tcb, void **buffer, int size, int skip)
}
else
{
ret = backtrace(rtcb->stack_base_ptr,
rtcb->stack_base_ptr + rtcb->adj_stack_size,
(void *)getfp(), NULL, buffer, size, &skip);
#ifdef CONFIG_ARCH_KERNEL_STACK
if (rtcb->xcp.ustkptr != NULL)
{
ret = backtrace(rtcb->stack_base_ptr,
rtcb->stack_base_ptr + rtcb->adj_stack_size,
(void *)*(rtcb->xcp.ustkptr + 1), NULL,
buffer, size, &skip);
}
else
#endif
{
ret = backtrace(rtcb->stack_base_ptr,
rtcb->stack_base_ptr + rtcb->adj_stack_size,
(void *)getfp(), NULL, buffer, size, &skip);
}
}
}
else
{
flags = enter_critical_section();
ret = backtrace(tcb->stack_base_ptr,
tcb->stack_base_ptr + tcb->adj_stack_size,
(void *)tcb->xcp.regs[REG_FP],
(void *)tcb->xcp.regs[REG_EPC],
buffer, size, &skip);
#ifdef CONFIG_ARCH_KERNEL_STACK
if (tcb->xcp.ustkptr != NULL)
{
ret = backtrace(tcb->stack_base_ptr,
tcb->stack_base_ptr + tcb->adj_stack_size,
(void *)*(tcb->xcp.ustkptr + 1), NULL,
buffer, size, &skip);
}
else
#endif
{
ret = backtrace(tcb->stack_base_ptr,
tcb->stack_base_ptr + tcb->adj_stack_size,
(void *)tcb->xcp.regs[REG_FP],
(void *)tcb->xcp.regs[REG_EPC],
buffer, size, &skip);
}
leave_critical_section(flags);
}