Decl/def matching with templates without template parameters in the DW_AT_name

David Blaikie
Wed Jan 18 22:04:30 GMT 2023

On Wed, Jan 11, 2023 at 6:32 PM Simon Marchi <> wrote:
> > Yeah, this is a case where DWARF is like "here are some tools you
> > could use to express some language features, have at!" and doesn't say
> > "to describe this particular language feature you must use DWARF in
> > this particular way"
> I just found this:
>     For template instantiations, the DW_AT_name attribute should contain
>     both the source language name of the object and the template
>     parameters that distinguish one instantiation from another. The
>     resulting string should be in the natural form for the language, and
>     should have a canonical representation (i.e., different producers
>     should generate the same representation). For C++, the string should
>     match that produced by the target platform's canonical demangler;
>     spaces should only be inserted where syntactically required by the
>     compiler.
> Of course, it's not normative.  According to the wiki history, this
> particular bit was added by Cary Coutant, in case you want to ask him
> why it is considered best practice.
> I Googled bits of the previous quote, and found this bug about template
> string canonicalization, and not including template parameters in the
> string:
> And this one, that sounds like the 2 vs 2u thing I talked about earler:
> Ah, and the thread that was on the GDB list about that:
> And the corresponding one on llvm-dev, to which you participated:
> It's not all relevant, but I re-read those to remember what the trouble
> with the name strings with template parameters was.
> My thought on all this is that if the name strings with template
> parameters are not reliable and take a lot of space, and the same
> information is described in a more structured way (as DIEs), then it
> makes sense to drop the parameters from the string.

Yeah, though I'll be the first to admit that the DIEs aren't perfect
either - there's a bunch of cases I opted out of the name
simplification (keeping their full name) because the DIEs weren't
adequate to reproduce the original name (in an effort to be
conservatively correct - in some cases it's the original name that's
the problem (some of those I fixed, some were too complex for me to
fix immediately, so I punted on them and kept the unsimplified name) -
lambdas, operator overloads come to mind, but there were some others).

It'd be good to get those DIE issues fixed, imho & then be able to
rely on simplified names uniformly.

(also as I mentioned in the bug I filed about the simplified names +
index, there's a bunch of inconsistencies here with both Clang and GCC
about alias templates and variable templates, as to whether they get
simplified or unsimplified names and whether they get DIEs or not...
:/ )

More information about the Gdb mailing list