aeubanks created this revision.
Herald added a reviewer: shafik.
Herald added a project: All.
aeubanks requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.
Without checking template parameters, we would sometimes lookup the
wrong type definition for a type declaration because different
instantiations of the same template class had the same debug info name.
The added GetForwardDeclarationDIETemplateParams() shouldn't need a
cache because we'll cache the results of the declaration -> definition
lookup anyway. (DWARFASTParserClang::ParseStructureLikeDIE()
is_forward_declaration branch)
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D138834
Files:
lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h
lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
lldb/test/API/lang/cpp/unique-types3/Makefile
lldb/test/API/lang/cpp/unique-types3/TestUniqueTypes3.py
lldb/test/API/lang/cpp/unique-types3/a.cpp
lldb/test/API/lang/cpp/unique-types3/main.cpp
Index: lldb/test/API/lang/cpp/unique-types3/main.cpp
===================================================================
--- /dev/null
+++ lldb/test/API/lang/cpp/unique-types3/main.cpp
@@ -0,0 +1,14 @@
+#include <atomic>
+#include <vector>
+
+std::atomic<double> a1;
+std::atomic<int> a2;
+std::atomic<float> a3;
+
+std::vector<double> v1;
+std::vector<int> v2;
+std::vector<float> v3;
+
+void f(std::atomic<int> &, std::vector<int> &);
+
+int main() { f(a2, v2); }
Index: lldb/test/API/lang/cpp/unique-types3/a.cpp
===================================================================
--- /dev/null
+++ lldb/test/API/lang/cpp/unique-types3/a.cpp
@@ -0,0 +1,6 @@
+#include <atomic>
+#include <vector>
+
+void f(std::atomic<int> &a, std::vector<int> &v) {
+ (void)a; // Set breakpoint here
+}
Index: lldb/test/API/lang/cpp/unique-types3/TestUniqueTypes3.py
===================================================================
--- /dev/null
+++ lldb/test/API/lang/cpp/unique-types3/TestUniqueTypes3.py
@@ -0,0 +1,28 @@
+"""
+Test that we return only the requested template instantiation.
+"""
+
+import lldb
+import lldbsuite.test.lldbutil as lldbutil
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+
+class UniqueTypesTestCase3(TestBase):
+ def do_test(self, debug_flags):
+ """Test that we display the correct template instantiation."""
+ self.build(dictionary=debug_flags)
+ lldbutil.run_to_source_breakpoint(self, "// Set breakpoint here", lldb.SBFileSpec("a.cpp"))
+ self.assertIn("int", self.frame().GetValueForVariablePath("a").GetDisplayTypeName())
+ self.assertIn("int", self.frame().GetValueForVariablePath("v").GetDisplayTypeName())
+
+ @skipIf(compiler=no_match("clang"))
+ @skipIf(compiler_version=["<", "15.0"])
+ def test_simple_template_names(self):
+ # Can't directly set CFLAGS_EXTRAS here because the Makefile can't
+ # override an environment variable.
+ self.do_test(dict(TEST_CFLAGS_EXTRAS="-gsimple-template-names"))
+
+ @skipIf(compiler=no_match("clang"))
+ @skipIf(compiler_version=["<", "15.0"])
+ def test_no_simple_template_names(self):
+ self.do_test(dict(CFLAGS_EXTRAS="-gno-simple-template-names"))
Index: lldb/test/API/lang/cpp/unique-types3/Makefile
===================================================================
--- /dev/null
+++ lldb/test/API/lang/cpp/unique-types3/Makefile
@@ -0,0 +1,5 @@
+CXX_SOURCES := main.cpp a.cpp
+
+CFLAGS_EXTRAS = $(TEST_CFLAGS_EXTRAS) $(LIMIT_DEBUG_INFO_FLAGS)
+
+include Makefile.rules
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -2979,6 +2979,16 @@
}
}
+ // See comments below about -gsimple-template-names for why we attempt to
+ // compute missing template parameter names.
+ ConstString template_params;
+ if (type_system && !type_name.GetStringRef().contains('<')) {
+ DWARFASTParser *dwarf_ast = type_system->GetDWARFParser();
+ if (dwarf_ast)
+ template_params =
+ dwarf_ast->GetForwardDeclarationDIETemplateParams(die);
+ }
+
m_index->GetTypes(type_name, [&](DWARFDIE type_die) {
// Make sure type_die's language matches the type system we are
// looking for. We don't want to find a "Foo" type from Java if we
@@ -3050,6 +3060,25 @@
if (!resolved_type || resolved_type == DIE_IS_BEING_PARSED)
return true;
+ // With -gsimple-template-names, the DIE name may not contain the template
+ // parameters. If we've the declaration has template parameters but
+ // doesn't contain '<', check that the child template parameters match.
+ if (template_params) {
+ llvm::StringRef test_base_name =
+ GetTypeForDIE(type_die)->GetBaseName().GetStringRef();
+ if (auto i = test_base_name.find('<'); i != llvm::StringRef::npos) {
+ llvm::StringRef test_template_params =
+ test_base_name.slice(i, test_base_name.size());
+ // Bail if template parameters don't match.
+ if (test_template_params != template_params.GetStringRef())
+ return true;
+ } else {
+ // Full name from clang AST doesn't contain '<' so this type_die isn't
+ // a template parameter, but we're expecting template parameters, so bail.
+ return true;
+ }
+ }
+
type_sp = resolved_type->shared_from_this();
return false;
});
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
@@ -88,6 +88,9 @@
ExtractIntFromFormValue(const lldb_private::CompilerType &int_type,
const DWARFFormValue &form_value) const;
+ lldb_private::ConstString
+ GetForwardDeclarationDIETemplateParams(const DWARFDIE &die) override;
+
protected:
/// Protected typedefs and members.
/// @{
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -740,6 +740,33 @@
return type_sp;
}
+ConstString DWARFASTParserClang::GetForwardDeclarationDIETemplateParams(
+ const DWARFDIE &die) {
+ clang::DeclContext *decl_ctx = GetClangDeclContextContainingDIE(die, nullptr);
+ TypeSystemClang::TemplateParameterInfos template_param_infos;
+ if (ParseTemplateParameterInfos(die, template_param_infos) &&
+ (!template_param_infos.args.empty() ||
+ template_param_infos.packed_args)) {
+ clang::ClassTemplateDecl *class_template_decl =
+ m_ast.ParseClassTemplateDecl(decl_ctx, GetOwningClangModule(die),
+ eAccessPublic, "", clang::TTK_Struct,
+ template_param_infos);
+ if (!class_template_decl)
+ return ConstString();
+
+ clang::ClassTemplateSpecializationDecl *class_specialization_decl =
+ m_ast.CreateClassTemplateSpecializationDecl(
+ decl_ctx, GetOwningClangModule(die), class_template_decl,
+ clang::TTK_Struct, template_param_infos);
+ if (!class_specialization_decl)
+ return ConstString();
+ CompilerType clang_type =
+ m_ast.CreateClassTemplateSpecializationType(class_specialization_decl);
+ return clang_type.GetTypeName(/*BaseOnly*/ true);
+ }
+ return ConstString();
+}
+
TypeSP DWARFASTParserClang::ParseEnum(const SymbolContext &sc,
const DWARFDIE &die,
ParsedDWARFTypeAttributes &attrs) {
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h
@@ -55,6 +55,9 @@
virtual void EnsureAllDIEsInDeclContextHaveBeenParsed(
lldb_private::CompilerDeclContext decl_context) = 0;
+ virtual lldb_private::ConstString
+ GetForwardDeclarationDIETemplateParams(const DWARFDIE &die) = 0;
+
static llvm::Optional<lldb_private::SymbolFile::ArrayInfo>
ParseChildArrayInfo(const DWARFDIE &parent_die,
const lldb_private::ExecutionContext *exe_ctx = nullptr);
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits