On Tue, Sep 16, 2025 at 2:26 PM lijiang <lijiang@redhat.com> wrote:
On Tue, Sep 16, 2025 at 12:51 PM HAGIO KAZUHITO(萩尾 一仁) <k-hagio-ab@nec.com> wrote:
Hi Lianbo, Tao,

Just a report, with this patch (99bb57ac98af), I observed that
the log command printed a couple of empty lines (only timestamps).
Could you reproduce this at your end?

Thank you for reporting this, Kazu.
I will check it, and did not see it before this.
 
Could you please try this one? Kazu.

diff --git a/printk.c b/printk.c
index ae28c4f..51b618e 100644
--- a/printk.c
+++ b/printk.c
@@ -221,7 +221,7 @@ dump_record(struct prb_map *m, unsigned long id, int msg_flags)
        char *p1 = strstr(buf, "_R");
        if (!p1)
                p1 = strstr(buf, "_ZN");
-       char *p2 = strchrnul(buf, '+');
+       char *p2 = strrchr(buf, '+');
        if (p1 && p2) {
                char mangled[BUFSIZE] = {0};
                char demangled[BUFSIZE] = {0};

I did not reproduce it, but I guess that this should be related to the strchrnul(), let's replace it with the strrchr().

Thanks.
Lianbo
 

Thanks.
Lianbo


$ diff -u log.pre log.cur
--- log.pre     2025-09-16 13:14:31.022206514 +0900
+++ log.cur     2025-09-16 13:14:56.220390987 +0900
@@ -210,7 +210,7 @@
  [    0.169375] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 1911260446275000 ns
  [    0.169375] futex hash table entries: 1024 (order: 4, 65536 bytes, linear)
  [    0.169375] pinctrl core: initialized pinctrl subsystem
-[    0.172925] NET: Registered PF_NETLINK/PF_ROUTE protocol family
+[    0.172925]
  [    0.172983] DMA: preallocated 512 KiB GFP_KERNEL pool for atomic allocations
  [    0.172986] DMA: preallocated 512 KiB GFP_KERNEL|GFP_DMA pool for atomic allocations
  [    0.172988] DMA: preallocated 512 KiB GFP_KERNEL|GFP_DMA32 pool for atomic allocations
@@ -807,7 +807,7 @@
  [771438.513231]  entry_SYSCALL_64_after_hwframe+0x72/0xdc
  [771438.513423] RIP: 0033:0x7fbd9f8fda57
  [771438.513576] Code: 0f 00 f7 d8 64 89 02 48 c7 c0 ff ff ff ff eb b7 0f 1f 00 f3 0f 1e fa 64 8b 04 25 18 00 00 00 85 c0 75 10 b8 01 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 51 c3 48 83 ec 28 48 89 54 24 18 48 89 74 24
-[771438.514251] RSP: 002b:00007ffee0de2b98 EFLAGS: 00000246 ORIG_RAX: 0000000000000001
+[771438.514251]
  [771438.514534] RAX: ffffffffffffffda RBX: 0000000000000002 RCX: 00007fbd9f8fda57
  [771438.514800] RDX: 0000000000000002 RSI: 00005647ccc0a330 RDI: 0000000000000001
  [771438.515066] RBP: 00005647ccc0a330 R08: 0000000000000003 R09: 0000000000000000

log.cur: 99bb57ac98afd89fcf23f0c8bc637821dcbd278f
log.pre: a5942e3acfd9330d101cc65ef2e19e627233ddf6
  vmcore: panic by sysrq-trigger on 5.14.0-427.13.1.el9_4.x86_64
(found also on 6.17-rc6)

Thanks,
Kazu

On 2025/09/15 10:19, Tao Liu wrote:
> applied: https://github.com/crash-utility/crash/commit/99bb57ac98afd89fcf23f0c8bc637821dcbd278f
>
> On Wed, Sep 10, 2025 at 2:33 PM Tao Liu <ltao@redhat.com> wrote:
>>
>> Hi lianbo,
>>
>> Thanks for the v2, LGTM, ack.
>>
>>
>> On Mon, Sep 8, 2025 at 8:42 PM Lianbo Jiang <lijiang@redhat.com> wrote:
>>>
>>> Without the patch:
>>>    crash> log
>>>    ...
>>>    [ 2174.308966] Call Trace:
>>>    [ 2174.311693]  <TASK>
>>>    [ 2174.314033]  dump_stack_lvl+0x5d/0x80
>>>    [ 2174.318125]  panic+0x156/0x32a
>>>    [ 2174.321539]  _RNvCscb18lrEyTSA_10rust_panic10area_in_hp+0xf7/0x120 [rust_panic]
>>>    [ 2174.329700]  ? console_unlock+0x9c/0x140
>>>    [ 2174.334080]  ? irq_work_queue+0x2d/0x50
>>>    [ 2174.338352]  ? __pfx_init_module+0x10/0x10 [rust_panic]
>>>    [ 2174.344183]  _RNvMCscb18lrEyTSA_10rust_panicNtB2_10HelloPanic8step_two+0x20/0xe0 [rust_panic]
>>>    [ 2174.353698]  ? _printk+0x6b/0x90
>>>    ...
>>>
>>> With the patch:
>>>    crash> log
>>>    ...
>>>    [ 2174.308966] Call Trace:
>>>    [ 2174.311693]  <TASK>
>>>    [ 2174.314033]  dump_stack_lvl+0x5d/0x80
>>>    [ 2174.318125]  panic+0x156/0x32a
>>>    [ 2174.321539]  rust_panic::area_in_hp+0xf7/0x120 [rust_panic]
>>>    [ 2174.329700]  ? console_unlock+0x9c/0x140
>>>    [ 2174.334080]  ? irq_work_queue+0x2d/0x50
>>>    [ 2174.338352]  ? __pfx_init_module+0x10/0x10 [rust_panic]
>>>    [ 2174.344183]  <rust_panic::HelloPanic>::step_two+0x20/0xe0 [rust_panic]
>>>    [ 2174.353698]  ? _printk+0x6b/0x90
>>>    ...
>>>
>>> Signed-off-by: Lianbo Jiang <lijiang@redhat.com>
>>> ---
>>> Note:
>>> 1. Add some checks to avoid the risk of buffer overflow.
>>>
>>>   Makefile |  2 +-
>>>   printk.c | 33 ++++++++++++++++++++++++++++++++-
>>>   2 files changed, 33 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/Makefile b/Makefile
>>> index fc1c9588dcfa..b277129f6df2 100644
>>> --- a/Makefile
>>> +++ b/Makefile
>>> @@ -421,7 +421,7 @@ kernel.o: ${GENERIC_HFILES} kernel.c
>>>          ${CC} -c ${CRASH_CFLAGS} kernel.c -I${BFD_DIRECTORY} -I${GDB_INCLUDE_DIRECTORY} ${WARNING_OPTIONS} ${WARNING_ERROR}
>>>
>>>   printk.o: ${GENERIC_HFILES} printk.c
>>> -       ${CC} -c ${CRASH_CFLAGS} printk.c ${WARNING_OPTIONS} ${WARNING_ERROR}
>>> +       ${CC} -c ${CRASH_CFLAGS} printk.c -I${GDB_INCLUDE_DIRECTORY} ${WARNING_OPTIONS} ${WARNING_ERROR}
>>>
>>>   gdb_interface.o: ${GENERIC_HFILES} gdb_interface.c
>>>          ${CC} -c ${CRASH_CFLAGS} gdb_interface.c ${WARNING_OPTIONS} ${WARNING_ERROR}
>>> diff --git a/printk.c b/printk.c
>>> index 95db7e607e4c..ae28c4fa0b21 100644
>>> --- a/printk.c
>>> +++ b/printk.c
>>> @@ -1,5 +1,6 @@
>>>   #include "defs.h"
>>>   #include <ctype.h>
>>> +#include "demangle.h"
>>>
>>>   /* convenience struct for passing many values to helper functions */
>>>   struct prb_map {
>>> @@ -201,14 +202,44 @@ dump_record(struct prb_map *m, unsigned long id, int msg_flags)
>>>
>>>          text = m->text_data + begin;
>>>
>>> +       if (text_len > BUFSIZE) {
>>> +               error(WARNING, "\nThe messages could be truncated!\n");
>>> +               text_len = BUFSIZE;
>>> +       }
>>> +
>>>          for (i = 0, p = text; i < text_len; i++, p++) {
>>>                  if (*p == '\n')
>>>                          fprintf(fp, "\n%s", space(ilen));
>>>                  else if (isprint(*p) || isspace(*p))
>>> -                       fputc(*p, fp);
>>> +                       sprintf(&buf[i], "%c", *p);
>>>                  else
>>>                          fputc('.', fp);
>>>          }
>>> +       /*
>>> +        * Try to demangle a mangled Rust symbol(calltrace) from log buffer
>>> +        */
>>> +       char *p1 = strstr(buf, "_R");
>>> +       if (!p1)
>>> +               p1 = strstr(buf, "_ZN");
>>> +       char *p2 = strchrnul(buf, '+');
>>> +       if (p1 && p2) {
>>> +               char mangled[BUFSIZE] = {0};
>>> +               char demangled[BUFSIZE] = {0};
>>> +               char *res;
>>> +               size_t slen = p1 - buf;
>>> +
>>> +               if (slen)
>>> +                       memcpy(demangled, buf, slen);
>>> +
>>> +               memcpy(mangled, p1, p2-p1);
>>> +               res = rust_demangle(mangled, DMGL_RUST);
>>> +               if (res) {
>>> +                       snprintf(demangled+slen, BUFSIZE-slen, "%s%s", res, p2);
>>> +                       fprintf(fp, "%s",demangled);
>>> +                       free(res);
>>> +               }
>>> +       } else
>>> +               fprintf(fp, "%s", buf);
>>>
>>>          if (msg_flags & SHOW_LOG_DICT) {
>>>                  text = info + OFFSET(printk_info_dev_info) +
>>> --
>>> 2.50.1
>>>
> --
> Crash-utility mailing list -- devel@lists.crash-utility.osci.io
> To unsubscribe send an email to devel-leave@lists.crash-utility.osci.io
> https://${domain_name}/admin/lists/devel.lists.crash-utility.osci.io/
> Contribution Guidelines: https://github.com/crash-utility/crash/wiki