Skip to content

Commit c5fcceb

Browse files
committed
xtensa: improve stack dumping
Calculate printable stack size and use print_hex_dump instead of opencoding it. Drop extra newline output in show_trace as its output format does not depend on CONFIG_KALLSYMS. Reviewed-by: Petr Mladek <[email protected]> Signed-off-by: Max Filippov <[email protected]>
1 parent 5eff6ca commit c5fcceb

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

arch/xtensa/kernel/traps.c

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -491,32 +491,27 @@ void show_trace(struct task_struct *task, unsigned long *sp)
491491

492492
pr_info("Call Trace:\n");
493493
walk_stackframe(sp, show_trace_cb, NULL);
494-
#ifndef CONFIG_KALLSYMS
495-
pr_cont("\n");
496-
#endif
497494
}
498495

499-
static int kstack_depth_to_print = 24;
496+
#define STACK_DUMP_ENTRY_SIZE 4
497+
#define STACK_DUMP_LINE_SIZE 32
498+
static size_t kstack_depth_to_print = 24;
500499

501500
void show_stack(struct task_struct *task, unsigned long *sp)
502501
{
503-
int i = 0;
504-
unsigned long *stack;
502+
size_t len;
505503

506504
if (!sp)
507505
sp = stack_pointer(task);
508-
stack = sp;
509506

510-
pr_info("Stack:\n");
507+
len = min((-(size_t)sp) & (THREAD_SIZE - STACK_DUMP_ENTRY_SIZE),
508+
kstack_depth_to_print * STACK_DUMP_ENTRY_SIZE);
511509

512-
for (i = 0; i < kstack_depth_to_print; i++) {
513-
if (kstack_end(sp))
514-
break;
515-
pr_cont(" %08lx", *sp++);
516-
if (i % 8 == 7)
517-
pr_cont("\n");
518-
}
519-
show_trace(task, stack);
510+
pr_info("Stack:\n");
511+
print_hex_dump(KERN_INFO, " ", DUMP_PREFIX_NONE,
512+
STACK_DUMP_LINE_SIZE, STACK_DUMP_ENTRY_SIZE,
513+
sp, len, false);
514+
show_trace(task, sp);
520515
}
521516

522517
DEFINE_SPINLOCK(die_lock);

0 commit comments

Comments
 (0)