On Mon, Sep 15, 2025 at 1:14 PM Tao Liu <ltao@redhat.com> wrote:
Hi Lianbo,

On Wed, Aug 27, 2025 at 4:09 PM Lianbo Jiang <lijiang@redhat.com> wrote:
>
> Without the patch:
>   crash> bt
>   PID: 3520     TASK: ffff8f240f670000  CPU: 1    COMMAND: "insmod"
>    #0 [ffffd08c4f063a20] machine_kexec at ffffffff9575e60e
>    #1 [ffffd08c4f063a40] __crash_kexec at ffffffff958db711
>    #2 [ffffd08c4f063b00] panic at ffffffff9560cede
>    #3 [ffffd08c4f063b80] _RNvCscb18lrEyTSA_10rust_panic10area_in_hp at ffffffffc07fe107 [rust_panic]
>    #4 [ffffd08c4f063c20] _RNvMCscb18lrEyTSA_10rust_panicNtB2_10HelloPanic8step_two at ffffffffc07fe160 [rust_panic]
>       ...
>
>   crash> sym _RNvCscb18lrEyTSA_10rust_panic10area_in_hp
>   ffffffffc07fe010 (t) _RNvCscb18lrEyTSA_10rust_panic10area_in_hp [rust_panic] /root/linux-6.16.3/samples/rust/rust_panic.rs: 22
>
> With the patch:
>   crash> bt
>   PID: 3520     TASK: ffff8f240f670000  CPU: 1    COMMAND: "insmod"
>    #0 [ffffd08c4f063a20] machine_kexec at ffffffff9575e60e
>    #1 [ffffd08c4f063a40] __crash_kexec at ffffffff958db711
>    #2 [ffffd08c4f063b00] panic at ffffffff9560cede
>    #3 [ffffd08c4f063b80] rust_panic::area_in_hp at ffffffffc07fe107 [rust_panic]
>    #4 [ffffd08c4f063c20] <rust_panic::HelloPanic>::step_two at ffffffffc07fe160 [rust_panic]
>       ...
>
>   crash> sym "rust_panic::area_in_hp"
>   ffffffffc07fe010 (t) rust_panic::area_in_hp [rust_panic] /root/linux-6.16.3/samples/rust/rust_panic.rs: 22
>
> Signed-off-by: Lianbo Jiang <lijiang@redhat.com>
> ---
>  symbols.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 45 insertions(+)
>
> diff --git a/symbols.c b/symbols.c
> index 052196265be0..7e9f57be7cec 100644
> --- a/symbols.c
> +++ b/symbols.c
> @@ -3277,6 +3277,46 @@ load_module_filter(char *s, int type)
>
>  #define AVERAGE_SYMBOL_SIZE (16)
>
> +static size_t rust_demangle_symbol(const char *symbol, char *out, size_t out_size)
> +{
> +       int i;
> +       size_t loc = 0;
> +       size_t len = strlen(symbol);
> +       char *buf = NULL;
> +       /*
> +        * Rust symbols always start with _R (v0) or _ZN (legacy)
> +        */
> +       const char *mangled_rust[] = {
> +               "_R",
> +               "_ZN",
> +               NULL
> +       };
> +
> +       if (!out || out_size < len)
> +               return 0;
> +
> +       for (i = 0; mangled_rust[i]; i++) {
> +               size_t sz = strlen(mangled_rust[i]);
> +               char *p = memmem(symbol, len, mangled_rust[i], sz);
> +               if (p) {
> +                       loc = p - symbol;
> +                       if (loc)
> +                               memcpy(out, symbol, loc);
> +                       break;
> +               }
> +       }
> +
> +       buf = rust_demangle(symbol + loc, DMGL_RUST);
> +       if (buf) {
> +               memcpy(out + loc, buf, strlen(buf));
> +               free(buf);
> +               return 1;
> +       } else if (loc != 0)
> +               memset(out, 0, loc);
> +
> +       return 0;
> +}
> +
>  static int
>  namespace_ctl(int cmd, struct symbol_namespace *ns, void *nsarg1, void *nsarg2)
>  {
> @@ -3315,9 +3355,14 @@ namespace_ctl(int cmd, struct symbol_namespace *ns, void *nsarg1, void *nsarg2)
>                 return TRUE;
>
>         case NAMESPACE_INSTALL:
> +               char demangled[BUFSIZE] = {0};

Just found a compiling error on this in rhel8: gcc version 8.5.0

gcc -c -g -DX86_64 -DLZO -DSNAPPY -DZSTD -DGDB_16_2  symbols.c
-I./gdb-16.2/bfd -I./gdb-16.2/include
symbols.c: In function ‘namespace_ctl’:
symbols.c:3358:3: error: a label can only be part of a statement and a
declaration is not a statement
   char demangled[BUFSIZE] = {0};
   ^~~~
make[4]: *** [Makefile:403: symbols.o] Error 1

Looks "char demangled[]" cannot follow the "case XX:" tag in older gcc.

I have merged your rust patchset, because the github test pipeline
doesn't find this issue, maybe due to the gcc is newer. Could you
please fix this issue, as well as the ci pipeline?

Thank you for pointing out this issue, Tao.
I did not build it with the old gcc . I'll check it.

Thanks
Lianbo
 

Thanks,
Tao Liu