On Wed, Sep 17, 2025 at 2:17 PM HAGIO KAZUHITO(萩尾 一仁) <k-hagio...@nec.com>
wrote:

> Hi Lianbo,
>
> Thank you for fixing it quickly.
>
> btw, seeing 99bb57ac98af, I had a couple of questions, is there a way to
> print the original (not mangled) log buffer?
>

Good questions, Kazu.

Add an option(E.g -R) to the log command that can help solve it. For
example:
The log will print original messages.
crash> log
The log -R will print demangled Rust symbol names if there are any mangled
Rust symbol names.
crash> log -R


> also, if the log buffer has lines like "_R ... +" which are not rust
> symbols unexpectedly, how are they printed?
>

 For this case, the rust_demangle() will fail, and still print the original
messages.

                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);

How about the above solutions? Kazu.

BWT: Originally I tried the following code, but it looks ugly. So simplify
this one.

        char *p1 = strstr(buf, "_R");
        if (!p1)
                p1 = strstr(buf, "_ZN");
        char *p2 = strrchr(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);
                        if (CRASHDEBUG(1))
                                fprintf(fp, "%s", buf);
                        else
                                fprintf(fp, "%s",demangled);
                        free(res);
                } else
                        fprintf(fp, "%s", buf);
        } else
                fprintf(fp, "%s", buf);

I did not realize that the original messages(mangled Rust symbols names)
are still helpful to you.

Thanks
Lianbo

(nice function, but maybe such function should be an option imho..)
>
> Thanks,
> Kazu
>
> On 2025/09/17 7:55, Tao Liu wrote:
> > applied:
> https://github.com/crash-utility/crash/commit/0df76345db8f7bb2ce70138eee65b71e157b280a
> >
> > On Wed, Sep 17, 2025 at 10:34 AM Tao Liu <l...@redhat.com> wrote:
> >>
> >> Hi Lianbo,
> >>
> >> Thanks for the fix, LGTM, ack.
> >>
> >> Thanks,
> >> Tao Liu
> >>
> >> On Tue, Sep 16, 2025 at 8:05 PM Lianbo Jiang <liji...@redhat.com>
> wrote:
> >>>
> >>> The log command printed a couple of empty lines (only timestamps),
> which
> >>> was caused by the commit  99bb57ac98af ("Enable resolving mangled Rust
> >>> symbol in lockless ring buffer"), E.g:
> >>>
> >>>    $ 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
> >>>
> >>> This is because the strchrnul() returns a pointer to the null byte
> >>> instead NULL if the char to be searched is not in the string. Given
> >>> that, let's replace the strchrnul() with the strrchr().
> >>>
> >>> Fixes: 99bb57ac98af ("Enable resolving mangled Rust symbol in lockless
> ring buffer")
> >>> Reported-by: Kazuhito Hagio <k-hagio...@nec.com>
> >>> Signed-off-by: Lianbo Jiang <liji...@redhat.com>
> >>> ---
> >>>   printk.c | 2 +-
> >>>   1 file changed, 1 insertion(+), 1 deletion(-)
> >>>
> >>> diff --git a/printk.c b/printk.c
> >>> index ae28c4fa0b21..51b618e2a434 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};
> >>> --
> >>> 2.50.1
> >>>
--
Crash-utility mailing list -- devel@lists.crash-utility.osci.io
To unsubscribe send an email to devel-le...@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

Reply via email to