Re: [RFA] Use rust_demangle

Tom Tromey
2017-04-22T06:17:40Z

>>>>> "Simon" == Simon Marchi <simon.marchi@polymtl.ca> writes:

Simon> It looks like you got the wrong PR number, I think it should be 20367.

Oops. Thanks for catching that.

Simon> Here for example, could you provide an example of when things go wrong
Simon> (a Rust symbol wrongfully demangled as a C++ symbol)?

Sure, there's one in the patch:

_ZN34_$LT$bc..X$u20$as$u20$bc..What$GT$4what17hec04869420f7eb7fE

The C++ demangler thinks it understands this and transforms it to

_$LT$bc..X$u20$as$u20$bc..What$GT$::what::hec04869420f7eb7f

However, it's actually the Rust symbol:

<bc::X as bc::What>::what

The issue here is that Rust chose a C++-like mangling. This was
probably a mistake. Maybe something can be done about it, maybe not --
but meanwhile I think it's nice if gdb can try to cope.

>> * ... and, in light of this change, "set demangle-style" seems a bit
>> weird because it allows the setting of styles to things obviously
>> not related to C++ at all, hence a change in demangle.c.

Simon> If other languages have mangling too, why shouldn't we be able to set
Simon> the mangling to that style? For example, why shouldn't we be able to
Simon> do "set demangle-style rust"?

In my view, "set demangle-style" is not very useful.

If you do set it, it affects future symbols only. It doesn't affect the
ones already read. And, if you set it to something nonsensical, like
"java", then other parts of the C++ support will break, because
cp-name-parser only understands the C++ form.

Also it mixes the mangled form (like "Lucid") with the output form (like
"Java"), which seems odd.

>> +char *
>> +gdb_demangle_cxx (const char *mangled, int options)
>> +{
>> + int style = (DMGL_GNU | DMGL_LUCID | DMGL_ARM
>> + | DMGL_HP | DMGL_EDG | DMGL_GNU_V3);
>> +
>> + if ((current_demangling_style & DMGL_AUTO) == 0)
>> + style &= current_demangling_style;

Simon> This deserves a comment, what does it accomplish? Restrict the style
Simon> to a restricted set of styles?

Yes, it tries to obey "set demangle-style". However, if demangle-style
is "auto", then there's no need to do anything else.

Simon> Shouldn't this be libiberty_demangers[i].demangling_style_name?

Yeah.

I'll make the other changes.

Tom