diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h --- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h +++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h @@ -644,7 +644,7 @@ // Accessors ConstString GetTypeName(lldb::opaque_compiler_type_t type, - bool BaseOnly) override; + bool base_only) override; ConstString GetDisplayTypeName(lldb::opaque_compiler_type_t type) override; @@ -1051,7 +1051,8 @@ clang::PrintingPolicy GetTypePrintingPolicy(); /// Returns the internal type name for the given NamedDecl using the /// type printing policy. - std::string GetTypeNameForDecl(const clang::NamedDecl *named_decl); + std::string GetTypeNameForDecl(const clang::NamedDecl *named_decl, + bool qualified = true); const clang::ClassTemplateSpecializationDecl * GetAsTemplateSpecialization(lldb::opaque_compiler_type_t type); diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp --- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp +++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp @@ -2131,11 +2131,12 @@ return printing_policy; } -std::string TypeSystemClang::GetTypeNameForDecl(const NamedDecl *named_decl) { +std::string TypeSystemClang::GetTypeNameForDecl(const NamedDecl *named_decl, + bool qualified) { clang::PrintingPolicy printing_policy = GetTypePrintingPolicy(); std::string result; llvm::raw_string_ostream os(result); - named_decl->printQualifiedName(os, printing_policy); + named_decl->getNameForDiagnostic(os, printing_policy, qualified); return result; } @@ -3768,7 +3769,7 @@ } ConstString TypeSystemClang::GetTypeName(lldb::opaque_compiler_type_t type, - bool BaseOnly) { + bool base_only) { if (!type) return ConstString(); @@ -3790,9 +3791,13 @@ return ConstString(GetTypeNameForDecl(typedef_decl)); } - clang::PrintingPolicy printing_policy(GetTypePrintingPolicy()); - printing_policy.SuppressScope = BaseOnly; - return ConstString(qual_type.getAsString(printing_policy)); + // For consistency, this follows the same code path that clang uses to emit + // debug info. This also handles when we don't want any scopes preceding the + // name. + if (auto *named_decl = qual_type->getAsTagDecl()) + return ConstString(GetTypeNameForDecl(named_decl, !base_only)); + + return ConstString(qual_type.getAsString(GetTypePrintingPolicy())); } ConstString diff --git a/lldb/test/API/lang/cpp/unique-types2/TestUniqueTypes2.py b/lldb/test/API/lang/cpp/unique-types2/TestUniqueTypes2.py --- a/lldb/test/API/lang/cpp/unique-types2/TestUniqueTypes2.py +++ b/lldb/test/API/lang/cpp/unique-types2/TestUniqueTypes2.py @@ -36,6 +36,7 @@ self.expect("image lookup -A -t 'Foo::Nested'", DATA_TYPES_DISPLAYED_CORRECTLY, error=True) self.expect("image lookup -A -t 'Nested'", DATA_TYPES_DISPLAYED_CORRECTLY, substrs=["1 match found"]) self.expect("image lookup -A -t '::Nested'", DATA_TYPES_DISPLAYED_CORRECTLY, error=True) + self.expect("image lookup -A -t 'Foo::Nested'", DATA_TYPES_DISPLAYED_CORRECTLY, substrs=["1 match found"]) self.expect_expr("t1", result_type="Foo") self.expect_expr("t1", result_type="Foo") @@ -49,6 +50,7 @@ self.expect_expr("p6", result_type="FooPack") self.expect_expr("p7", result_type="FooPack") self.expect_expr("n1", result_type="Foo::Nested") + self.expect_expr("n2", result_type="Foo::Nested") @skipIf(compiler=no_match("clang")) @skipIf(compiler_version=["<", "15.0"]) diff --git a/lldb/test/API/lang/cpp/unique-types2/main.cpp b/lldb/test/API/lang/cpp/unique-types2/main.cpp --- a/lldb/test/API/lang/cpp/unique-types2/main.cpp +++ b/lldb/test/API/lang/cpp/unique-types2/main.cpp @@ -1,3 +1,7 @@ +namespace ns { +struct Bar {}; +} // namespace ns + template struct Foo { T t; template class Nested { @@ -23,5 +27,6 @@ FooPack p7; Foo::Nested n1; + Foo::Nested n2; // Set breakpoint here }