Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

arm: fix backtrace busyloop #7068

Merged
merged 3 commits into from
Sep 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 14 additions & 7 deletions arch/arm/src/common/arm_assert.c
Expand Up @@ -59,6 +59,12 @@

#ifdef CONFIG_ARCH_STACKDUMP

/****************************************************************************
* Private Data
****************************************************************************/

static uint8_t s_last_regs[XCPTCONTEXT_SIZE];

/****************************************************************************
* Private Functions
****************************************************************************/
Expand Down Expand Up @@ -383,12 +389,6 @@ static void arm_dumpstate(void)
struct tcb_s *rtcb = running_task();
uint32_t sp = up_getsp();

/* Show back trace */

#ifdef CONFIG_SCHED_BACKTRACE
sched_dumpstack(rtcb->pid);
#endif

/* Update the xcp context */

if (CURRENT_REGS)
Expand All @@ -397,9 +397,16 @@ static void arm_dumpstate(void)
}
else
{
up_saveusercontext(rtcb->xcp.regs);
up_saveusercontext(s_last_regs);
rtcb->xcp.regs = (uint32_t *)s_last_regs;
}

/* Show back trace */

#ifdef CONFIG_SCHED_BACKTRACE
sched_dumpstack(rtcb->pid);
#endif

/* Dump the registers */

arm_registerdump(rtcb->xcp.regs);
Expand Down
11 changes: 5 additions & 6 deletions arch/arm/src/common/arm_backtrace_fp.c
Expand Up @@ -52,14 +52,13 @@ static int backtrace(uintptr_t *base, uintptr_t *limit,

if (pc)
{
i++;
if ((*skip)-- <= 0)
{
*buffer++ = pc;
buffer[i++] = pc;
}
}

for (; i < size; fp = (uintptr_t *)*(fp - 1), i++)
for (; i < size; fp = (uintptr_t *)*(fp - 1))
{
if (fp > limit || fp < base || *fp == 0)
{
Expand All @@ -68,7 +67,7 @@ static int backtrace(uintptr_t *base, uintptr_t *limit,

if ((*skip)-- <= 0)
{
*buffer++ = (void *)*fp;
buffer[i++] = (void *)*fp;
}
}

Expand Down Expand Up @@ -144,8 +143,8 @@ int up_backtrace(struct tcb_s *tcb,
{
ret += backtrace(rtcb->stack_base_ptr,
rtcb->stack_base_ptr + rtcb->adj_stack_size,
(void *)CURRENT_REGS[REG_FP],
(void *)CURRENT_REGS[REG_PC],
(void *)rtcb->xcp.regs[REG_FP],
(void *)rtcb->xcp.regs[REG_PC],
&buffer[ret], size - ret, &skip);
}
}
Expand Down
4 changes: 2 additions & 2 deletions arch/arm/src/common/arm_backtrace_thumb.c
Expand Up @@ -504,10 +504,10 @@ int up_backtrace(struct tcb_s *tcb,
#endif
if (ret < size)
{
sp = (void *)CURRENT_REGS[REG_SP];
sp = (void *)rtcb->xcp.regs[REG_SP];
ret += backtrace_push(rtcb->stack_base_ptr +
rtcb->adj_stack_size, &sp,
(void *)CURRENT_REGS[REG_PC],
(void *)rtcb->xcp.regs[REG_PC],
&buffer[ret], size - ret, &skip);
}
}
Expand Down
21 changes: 14 additions & 7 deletions arch/risc-v/src/common/riscv_assert.c
Expand Up @@ -65,6 +65,12 @@

#ifdef CONFIG_ARCH_STACKDUMP

/****************************************************************************
* Private Data
****************************************************************************/

static uint8_t s_last_regs[XCPTCONTEXT_SIZE];

/****************************************************************************
* Private Functions
****************************************************************************/
Expand Down Expand Up @@ -360,12 +366,6 @@ static void riscv_dumpstate(void)
struct tcb_s *rtcb = running_task();
uintptr_t sp = up_getsp();

/* Show back trace */

#ifdef CONFIG_SCHED_BACKTRACE
sched_dumpstack(rtcb->pid);
#endif

/* Update the xcp context */

if (CURRENT_REGS)
Expand All @@ -374,9 +374,16 @@ static void riscv_dumpstate(void)
}
else
{
up_saveusercontext(rtcb->xcp.regs);
up_saveusercontext(s_last_regs);
rtcb->xcp.regs = (uintptr_t *)s_last_regs;
}

/* Show back trace */

#ifdef CONFIG_SCHED_BACKTRACE
sched_dumpstack(rtcb->pid);
#endif

/* Dump the registers (if available) */

riscv_registerdump(rtcb->xcp.regs);
Expand Down
4 changes: 2 additions & 2 deletions arch/risc-v/src/common/riscv_backtrace.c
Expand Up @@ -154,8 +154,8 @@ int up_backtrace(struct tcb_s *tcb, void **buffer, int size, int skip)
{
ret += backtrace(rtcb->stack_base_ptr,
rtcb->stack_base_ptr + rtcb->adj_stack_size,
(void *)CURRENT_REGS[REG_FP],
(void *)CURRENT_REGS[REG_EPC],
(void *)rtcb->xcp.regs[REG_FP],
(void *)rtcb->xcp.regs[REG_EPC],
&buffer[ret], size - ret, &skip);
}
}
Expand Down
4 changes: 2 additions & 2 deletions arch/xtensa/src/common/xtensa_backtrace.c
Expand Up @@ -253,8 +253,8 @@ int up_backtrace(struct tcb_s *tcb, void **buffer, int size, int skip)
#endif
ret += backtrace_stack(rtcb->stack_base_ptr,
rtcb->stack_base_ptr + rtcb->adj_stack_size,
(void *)CURRENT_REGS[REG_A1],
(void *)CURRENT_REGS[REG_A0],
(void *)rtcb->xcp.regs[REG_A1],
(void *)rtcb->xcp.regs[REG_A0],
&buffer[ret], size - ret, &skip);
}
else
Expand Down
9 changes: 8 additions & 1 deletion arch/xtensa/src/common/xtensa_dumpstate.c
Expand Up @@ -44,6 +44,12 @@

#ifdef CONFIG_DEBUG_ALERT

/****************************************************************************
* Private Data
****************************************************************************/

static uint8_t s_last_regs[XCPTCONTEXT_SIZE];

/****************************************************************************
* Private Functions
****************************************************************************/
Expand Down Expand Up @@ -343,7 +349,8 @@ void xtensa_dumpstate(void)
}
else
{
up_saveusercontext(rtcb->xcp.regs);
up_saveusercontext(s_last_regs);
rtcb->xcp.regs = (uint32_t *)s_last_regs;
}

/* Dump the registers (if available) */
Expand Down