Skip to content

Commit b889ab8

Browse files
authored
Merge pull request #8009 from augusto2112/check-if-interop-in-dwarf
[lldb] Implement check for potential Swift interop types in DWARF
2 parents 6c6872b + 7a6cdb2 commit b889ab8

File tree

5 files changed

+57
-2
lines changed

5 files changed

+57
-2
lines changed

lldb/source/Plugins/ExpressionParser/Clang/ClangASTMetadata.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,12 @@ void ClangASTMetadata::Dump(Stream *s) {
3131
if (m_is_dynamic_cxx) {
3232
s->Printf("is_dynamic_cxx=%i ", m_is_dynamic_cxx);
3333
}
34+
35+
// BEGIN SWIFT
36+
if (m_is_potentially_swift_interop_type) {
37+
s->Printf("is_swift_interop_type=%i ", m_is_potentially_swift_interop_type);
38+
}
39+
// END SWIFT
40+
3441
s->EOL();
3542
}

lldb/source/Plugins/ExpressionParser/Clang/ClangASTMetadata.h

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,15 @@ class ClangASTMetadata {
2020
ClangASTMetadata()
2121
: m_user_id(0), m_union_is_user_id(false), m_union_is_isa_ptr(false),
2222
m_has_object_ptr(false), m_is_self(false), m_is_dynamic_cxx(true),
23-
m_is_forcefully_completed(false) {}
23+
m_is_forcefully_completed(false)
24+
// BEGIN SWIFT
25+
// This is initialized to true because in the off-chance we don't parse
26+
// this type in debug info we should stil take the regular, expensive
27+
// path to figure out if the type is a Swift interop type or not.
28+
,
29+
m_is_potentially_swift_interop_type(true)
30+
// END SWIFT
31+
{}
2432

2533
bool GetIsDynamicCXXType() const { return m_is_dynamic_cxx; }
2634

@@ -93,6 +101,16 @@ class ClangASTMetadata {
93101
m_is_forcefully_completed = true;
94102
}
95103

104+
// BEGIN SWIFT
105+
bool GetIsPotentiallySwiftInteropType() {
106+
return m_is_potentially_swift_interop_type;
107+
}
108+
109+
void SetIsPotentiallySwiftInteropType(bool is_swift_interop_type) {
110+
m_is_potentially_swift_interop_type = is_swift_interop_type;
111+
}
112+
// END SWIFT
113+
96114
void Dump(Stream *s);
97115

98116
private:
@@ -102,7 +120,12 @@ class ClangASTMetadata {
102120
};
103121

104122
bool m_union_is_user_id : 1, m_union_is_isa_ptr : 1, m_has_object_ptr : 1,
105-
m_is_self : 1, m_is_dynamic_cxx : 1, m_is_forcefully_completed : 1;
123+
m_is_self : 1, m_is_dynamic_cxx : 1,
124+
m_is_forcefully_completed : 1
125+
// BEGIN SWIFT
126+
, m_is_potentially_swift_interop_type : 1
127+
// END SWIFT
128+
;
106129
};
107130

108131
} // namespace lldb_private

lldb/source/Plugins/Language/Swift/SwiftLanguage.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "lldb/DataFormatters/FormattersHelpers.h"
2424
#include "lldb/DataFormatters/StringPrinter.h"
2525

26+
#include "Plugins/ExpressionParser/Clang/ClangASTMetadata.h"
2627
#include "Plugins/LanguageRuntime/Swift/SwiftLanguageRuntime.h"
2728
#include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
2829
#include "lldb/Symbol/CompileUnit.h"
@@ -768,6 +769,10 @@ ExtractSwiftTypeNameFromCxxInteropType(CompilerType type) {
768769
}
769770

770771
const clang::RecordDecl *record_decl = record_type->getDecl();
772+
auto *metadata = tsc->GetMetadata(record_decl);
773+
if (metadata && !metadata->GetIsPotentiallySwiftInteropType())
774+
return {};
775+
771776
for (auto *child_decl : record_decl->decls()) {
772777
auto *var_decl = llvm::dyn_cast<clang::VarDecl>(child_decl);
773778
if (!var_decl)

lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,6 +1572,16 @@ DWARFASTParserClang::GetCPlusPlusQualifiedName(const DWARFDIE &die) {
15721572
return qualified_name;
15731573
}
15741574

1575+
// BEGIN SWIFT
1576+
bool DWARFASTParserClang::IsSwiftInteropType(const DWARFDIE &die) {
1577+
for (DWARFDIE die : die.children())
1578+
if (die.Tag() == llvm::dwarf::DW_TAG_member &&
1579+
llvm::StringRef(die.GetName()) == "__swift_mangled_name")
1580+
return true;
1581+
return false;
1582+
}
1583+
// END SWIFT
1584+
15751585
TypeSP
15761586
DWARFASTParserClang::ParseStructureLikeDIE(const SymbolContext &sc,
15771587
const DWARFDIE &die,
@@ -1770,6 +1780,9 @@ DWARFASTParserClang::ParseStructureLikeDIE(const SymbolContext &sc,
17701780
ClangASTMetadata metadata;
17711781
metadata.SetUserID(die.GetID());
17721782
metadata.SetIsDynamicCXXType(dwarf->ClassOrStructIsVirtual(die));
1783+
// BEGIN SWIFT
1784+
metadata.SetIsPotentiallySwiftInteropType(IsSwiftInteropType(die));
1785+
// END SWIFT
17731786

17741787
TypeSystemClang::TemplateParameterInfos template_param_infos;
17751788
if (ParseTemplateParameterInfos(die, template_param_infos)) {

lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,13 @@ class DWARFASTParserClang : public lldb_private::plugin::dwarf::DWARFASTParser {
374374
lldb_private::CompilerType &class_clang_type,
375375
const lldb::AccessType default_accesibility,
376376
lldb_private::ClangASTImporter::LayoutInfo &layout_info);
377+
378+
// BEGIN SWIFT
379+
/// Returns true if the C++ type is a compiler-generated wrapper around a
380+
/// Swift type.
381+
bool IsSwiftInteropType(const lldb_private::plugin::dwarf::DWARFDIE &die);
382+
// END SWIFT
383+
377384
};
378385

379386
/// Parsed form of all attributes that are relevant for type reconstruction.

0 commit comments

Comments
 (0)