Re: [PATCH v1] perf symbol: Add rust v0 demangling support
From: Ian Rogers
Date: Thu Jan 30 2025 - 11:06:18 EST
On Thu, Jan 30, 2025 at 12:40 AM Alice Ryhl <aliceryhl@xxxxxxxxxx> wrote:
>
> On Wed, Jan 29, 2025 at 8:30 PM Ian Rogers <irogers@xxxxxxxxxx> wrote:
> >
> > Implement symbol demangling based on:
> > https://doc.rust-lang.org/rustc/symbol-mangling/index.html
> >
> > Ensure recommended demangling examples match the expectations in the
> > documentation.
> >
> > This was requested by Daniel Xu <dxu@xxxxxxxxx> in:
> > https://lore.kernel.org/lkml/jgxfnphfo3nzlfipnuuzdlfc4ehbr2tnh2evz3mdhynd6wvrsu@fcz6vrvepybb/
> >
> > Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
> > ---
> > This change is on top of the 18 patch v3 series:
> > https://lore.kernel.org/lkml/20250122174308.350350-1-irogers@xxxxxxxxxx/
> > ---
[..snip..]
> > +static int test__demangle_rust(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
> > +{
> > + int ret = TEST_OK;
> > + char *buf = NULL;
> > + size_t i;
> > +
> > + struct {
> > + const char *mangled, *demangled;
> > + } test_cases[] = {
> > + { "_RNvMsr_NtCs3ssYzQotkvD_3std4pathNtB5_7PathBuf3newCs15kBYyAo9fc_7mycrate",
> > + "<std::path::PathBuf>::new" },
>
> I think you would normally not have the < and > here? I usually only
> see that when you do <type as trait>.
Thanks Alice! The example comes from here:
https://doc.rust-lang.org/rustc/symbol-mangling/v0.html#symbol-name
so maybe it is just trying to show what the mangling can do rather
than show an actual symbol. Fwiw, I did compare the output with that
from rustfilt and it matches.
On the Rust bug for this change:
https://github.com/rust-lang/rust/issues/60705
it was pointed out that using:
https://github.com/rust-lang/rustc-demangle/blob/main/crates/native-c/src/demangle.c
that supports legacy and v0 symbols would probably be better than this
patch. It would be nice if that code's author could contribute it.
Thanks,
Ian
> Alice