Re: [PATCH] xtensa: improve stack dumping

From: Dmitry Safonov
Date: Wed Nov 06 2019 - 15:51:12 EST


Hi Max,

On 11/6/19 6:16 PM, Max Filippov wrote:
> Collect whole stack dump lines in a buffer and print the whole buffer
> when it's ready with pr_info instead of pr_cont. This makes stack dump
> lines consistent in SMP case and relies less on pr_cont/printk
> differences related to timestamps.
> Make size of stack dump configurable.
> Drop extra newline output in show_trace as its output format does not
> depend on CONFIG_KALLSYMS.
>
> Signed-off-by: Max Filippov <jcmvbkbc@xxxxxxxxx>

[..]

> void show_stack(struct task_struct *task, unsigned long *sp)
> {
> int i = 0;
> unsigned long *stack;
> + char buf[9 * 8 + 1];
>
> if (!sp)
> sp = stack_pointer(task);
> @@ -512,10 +510,12 @@ void show_stack(struct task_struct *task, unsigned long *sp)
> for (i = 0; i < kstack_depth_to_print; i++) {
> if (kstack_end(sp))
> break;
> - pr_cont(" %08lx", *sp++);
> + sprintf(buf + (i % 8) * 9, " %08lx", *sp++);

buf is on the stack, does sprintf() put null-terminator for hex?

> if (i % 8 == 7)
> - pr_cont("\n");
> + pr_info("%s\n", buf);
> }
> + if (i % 8)
> + pr_info("%s\n", buf);

If the stack trace ends with (i % 8 == 7), you'll double-print the last
line?

Thanks,
Dmitry