@@ -1792,6 +1792,28 @@ createSpecializedStructOrClassType(NominalOrBoundGenericNominalType *Type,
1792
1792
return InternalType;
1793
1793
}
1794
1794
1795
+ llvm::DIType *SpecificationOf = nullptr ;
1796
+ if (auto *TypeDecl = DbgTy.getType ()->getNominalOrBoundGenericNominal ()) {
1797
+ // If this is a nominal type that has the @_originallyDefinedIn attribute,
1798
+ // IRGenDebugInfo emits a forward declaration of the type as a child
1799
+ // of the original module, and the type with a specification pointing to
1800
+ // the forward declaraation. We do this so LLDB has enough information to
1801
+ // both find the type in reflection metadata (the parent module name) and
1802
+ // find it in the swiftmodule (the module name in the type mangled name).
1803
+ if (auto Attribute =
1804
+ TypeDecl->getAttrs ().getAttribute <OriginallyDefinedInAttr>()) {
1805
+ auto Identifier = IGM.getSILModule ().getASTContext ().getIdentifier (
1806
+ Attribute->OriginalModuleName );
1807
+
1808
+ void *Key = (void *)Identifier.get ();
1809
+ auto InnerScope =
1810
+ getOrCreateModule (Key, TheCU, Attribute->OriginalModuleName , {});
1811
+ SpecificationOf = DBuilder.createForwardDecl (
1812
+ llvm::dwarf::DW_TAG_structure_type, TypeDecl->getNameStr (),
1813
+ InnerScope, File, 0 , llvm::dwarf::DW_LANG_Swift, 0 , 0 );
1814
+ }
1815
+ }
1816
+
1795
1817
// Here goes!
1796
1818
switch (BaseTy->getKind ()) {
1797
1819
case TypeKind::BuiltinUnboundGeneric:
@@ -1894,7 +1916,8 @@ createSpecializedStructOrClassType(NominalOrBoundGenericNominalType *Type,
1894
1916
llvm::dwarf::DW_TAG_structure_type, MangledName, Scope, L.File ,
1895
1917
FwdDeclLine, llvm::dwarf::DW_LANG_Swift, 0 , AlignInBits);
1896
1918
return createOpaqueStruct (Scope, Name, L.File , FwdDeclLine, SizeInBits,
1897
- AlignInBits, Flags, MangledName);
1919
+ AlignInBits, Flags, MangledName, {},
1920
+ SpecificationOf);
1898
1921
}
1899
1922
1900
1923
case TypeKind::Class: {
@@ -1931,7 +1954,8 @@ createSpecializedStructOrClassType(NominalOrBoundGenericNominalType *Type,
1931
1954
return DIType;
1932
1955
}
1933
1956
return createPointerSizedStruct (Scope, Decl->getNameStr (), L.File ,
1934
- FwdDeclLine, Flags, MangledName);
1957
+ FwdDeclLine, Flags, MangledName,
1958
+ SpecificationOf);
1935
1959
}
1936
1960
1937
1961
case TypeKind::Protocol: {
@@ -1977,11 +2001,11 @@ createSpecializedStructOrClassType(NominalOrBoundGenericNominalType *Type,
1977
2001
return createSpecializedStructOrClassType (
1978
2002
StructTy, Decl, Scope, L.File , L.Line , SizeInBits, AlignInBits,
1979
2003
Flags, MangledName);
1980
-
2004
+
1981
2005
return createOpaqueStructWithSizedContainer (
1982
2006
Scope, Decl ? Decl->getNameStr () : " " , L.File , FwdDeclLine,
1983
2007
SizeInBits, AlignInBits, Flags, MangledName,
1984
- collectGenericParams (StructTy));
2008
+ collectGenericParams (StructTy), SpecificationOf );
1985
2009
}
1986
2010
1987
2011
case TypeKind::BoundGenericClass: {
@@ -1999,9 +2023,9 @@ createSpecializedStructOrClassType(NominalOrBoundGenericNominalType *Type,
1999
2023
// attribute accordingly.
2000
2024
assert (SizeInBits ==
2001
2025
CI.getTargetInfo ().getPointerWidth (clang::LangAS::Default));
2002
- return createPointerSizedStruct (Scope,
2003
- Decl ? Decl->getNameStr () : MangledName,
2004
- L. File , FwdDeclLine, Flags, MangledName);
2026
+ return createPointerSizedStruct (
2027
+ Scope, Decl ? Decl->getNameStr () : MangledName, L. File , FwdDeclLine ,
2028
+ Flags, MangledName, SpecificationOf );
2005
2029
}
2006
2030
2007
2031
case TypeKind::Pack:
@@ -2122,7 +2146,7 @@ createSpecializedStructOrClassType(NominalOrBoundGenericNominalType *Type,
2122
2146
}
2123
2147
return createOpaqueStruct (Scope, Decl->getName ().str (), L.File ,
2124
2148
FwdDeclLine, SizeInBits, AlignInBits, Flags,
2125
- MangledName);
2149
+ MangledName, {}, SpecificationOf );
2126
2150
}
2127
2151
2128
2152
case TypeKind::BoundGenericEnum: {
@@ -2142,7 +2166,8 @@ createSpecializedStructOrClassType(NominalOrBoundGenericNominalType *Type,
2142
2166
}
2143
2167
return createOpaqueStructWithSizedContainer (
2144
2168
Scope, Decl->getName ().str (), L.File , FwdDeclLine, SizeInBits,
2145
- AlignInBits, Flags, MangledName, collectGenericParams (EnumTy));
2169
+ AlignInBits, Flags, MangledName, collectGenericParams (EnumTy),
2170
+ SpecificationOf);
2146
2171
}
2147
2172
2148
2173
case TypeKind::BuiltinVector: {
@@ -2322,7 +2347,8 @@ createSpecializedStructOrClassType(NominalOrBoundGenericNominalType *Type,
2322
2347
}
2323
2348
}
2324
2349
2325
- llvm::DIType *getOrCreateType (DebugTypeInfo DbgTy) {
2350
+ llvm::DIType *getOrCreateType (DebugTypeInfo DbgTy,
2351
+ llvm::DIScope *Scope = nullptr ) {
2326
2352
// Is this an empty type?
2327
2353
if (DbgTy.isNull ())
2328
2354
// We can't use the empty type as an index into DenseMap.
@@ -2354,7 +2380,6 @@ createSpecializedStructOrClassType(NominalOrBoundGenericNominalType *Type,
2354
2380
//
2355
2381
// FIXME: Builtin and qualified types in LLVM have no parent
2356
2382
// scope. TODO: This can be fixed by extending DIBuilder.
2357
- llvm::DIScope *Scope = nullptr ;
2358
2383
// Make sure to retrieve the context of the type alias, not the pointee.
2359
2384
DeclContext *Context = nullptr ;
2360
2385
const Decl *TypeDecl = nullptr ;
0 commit comments