Re: [PATCH] xtensa: improve stack dumping

From: Dmitry Safonov
Date: Wed Nov 06 2019 - 17:18:59 EST


On 11/6/19 10:00 PM, Max Filippov wrote:
> On Wed, Nov 6, 2019 at 12:51 PM Dmitry Safonov <dima@xxxxxxxxxx> wrote:
>> On 11/6/19 6:16 PM, Max Filippov wrote:
>>> @@ -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?
>
> It should put null-terminator regardless of the format string.

Always unsure what to expect from printf() :)

>
>>> 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?
>
> No, I don't think so. 'For' loop condition is checked after i++, so if
> loop ends with i % 8 == 7 then its last iteration was done with
> i % 8 == 6 and thus the buf haven't been printed.

Ah, right - me being stupid.

Thanks,
Dmitry