Skip to content

Commit

Permalink
riscv: simplify backtrace report
Browse files Browse the repository at this point in the history
* We already have a header 'backtrace', there is no need to repeat the
  word backtrace on every line.
* Add a blank line before the backtrace section of the crash report for
  improved readability.
* If U-Boot is compiled without backtrace, there is no need to write a
  message at all.
* Avoid #ifdef. We prefer functions to always be compiled and let
  the linker remove them if not needed.
* Foresee 3 digits for the backtrace index.

For testing the 'exception' command can be used.

Signed-off-by: Heinrich Schuchardt <[email protected]>
Reviewed-by: Leo Yu-Chi Liang <[email protected]>
  • Loading branch information
xypron authored and Leo Yu-Chi Liang committed May 14, 2024
1 parent fcaf019 commit 409259e
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions arch/riscv/lib/interrupts.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,20 @@ static void show_regs(struct pt_regs *regs)
#endif
}

#if defined(CONFIG_FRAMEPOINTER) || defined(CONFIG_SPL_FRAMEPOINTER)
static void show_backtrace(struct pt_regs *regs)
static void __maybe_unused show_backtrace(struct pt_regs *regs)
{
uintptr_t *fp = (uintptr_t *)regs->s0;
unsigned count = 0;
ulong ra;

printf("backtrace:\n");
printf("\nbacktrace:\n");

/* there are a few entry points where the s0 register is
* set to gd, so to avoid changing those, just abort if
* the value is the same */
while (fp != NULL && fp != (uintptr_t *)gd) {
ra = fp[-1];
printf("backtrace %2d: FP: " REG_FMT " RA: " REG_FMT,
printf("%3d: FP: " REG_FMT " RA: " REG_FMT,
count, (ulong)fp, ra);

if (gd && gd->flags & GD_FLG_RELOC)
Expand All @@ -87,12 +86,6 @@ static void show_backtrace(struct pt_regs *regs)
count++;
}
}
#else
static void show_backtrace(struct pt_regs *regs)
{
printf("No backtrace support enabled\n");
}
#endif

/**
* instr_len() - get instruction length
Expand Down Expand Up @@ -165,7 +158,8 @@ static void _exit_trap(ulong code, ulong epc, ulong tval, struct pt_regs *regs)
epc - gd->reloc_off, regs->ra - gd->reloc_off);

show_regs(regs);
show_backtrace(regs);
if (CONFIG_IS_ENABLED(FRAMEPOINTER))
show_backtrace(regs);
show_code(epc);
show_efi_loaded_images(epc);
panic("\n");
Expand Down

0 comments on commit 409259e

Please sign in to comment.