[Lldb-commits] [lldb] [lldb] Make CompilerDecl::GetName (always) return template args (PR #116068)

Michael Buch via lldb-commits lldb-commits at lists.llvm.org
Thu Nov 14 09:47:54 PST 2024


https://github.com/Michael137 commented:

Very interesting find, I *think* this makes sense since the `FindTypes` query expects to find template parameters if we're looking up templates. And given this API is used specifically to perform these kinds of queries, this LGTM. But please confirm if my understanding is correct:

In the non-simple names case, when we stop at the breakpoint and start formatting the function arguments, LLDB creates a `CXXRecordDecl` with the name `bar<int>` in the shared library TypeSystem because it only sees a `DW_TAG_structure_type "bar<int>"` forward declaration without any template parameter children DIEs. Then when we call `FindCompleteType`, the `Decl`s `DeclarationName` would've been set to `bar<int>`, so we construct a `TypeQuery`, it's able to match the `bar<int>` definition using the index. When `FindTypes` resolves the definition DIE we get from the index, it triggers the creation of a `ClassTemplateSpecializationDecl` in the main module's TypeSystem and everything works out.

But in the non-simple names case we create a `ClassTemplateSpecializationDecl` in the shared library module (as opposed to a plain `CXXRecordDecl`), because the forward declaration with `-gsimple-template-names` has a template parameter DIE. But that declaration name is `bar`, because that's what DWARF told us the `DeclarationName` of this `ClassTemplateSpecializationDecl` was. But then `FindTypes` does know what to do. It finds the `bar` definition DIE from the index, but we actually end up *not* doing a `simple-template-names` lookup because [UpdateCompilerContextForSimpleTemplateNames](https://github.com/llvm/llvm-project/blob/593be023615a456ca6ee0ef9bedc21301d73b73c/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp#L2816) is only true if the query contained template parameters.

So I guess my question is, why is a `TypeQuery` by basename without template parameters not supported if we compiled with `-gsimple-template-names`? Despite us being able to find the definition DIE in the index? I guess the idea of `UpdateCompilerContextForSimpleTemplateNames` was to avoid doing a double-lookup if the first `FindTypes` failed for a template basename? (I vaguely remember this coming up on the original review)

https://github.com/llvm/llvm-project/pull/116068


More information about the lldb-commits mailing list