@@ -1671,43 +1671,84 @@ DWARFASTParserClang::ParseStructureLikeDIE(const SymbolContext &sc,
1671
1671
attrs.is_forward_declaration = true ;
1672
1672
}
1673
1673
1674
+ DWARFDIE def_die;
1675
+ if (attrs.is_forward_declaration && cu_language == eLanguageTypeObjC) {
1676
+ def_die = dwarf->FindDefinitionDIE (die);
1677
+
1678
+ if (!def_die) {
1679
+ SymbolFileDWARFDebugMap *debug_map_symfile = dwarf->GetDebugMapSymfile ();
1680
+ if (debug_map_symfile) {
1681
+ // We weren't able to find a full declaration in this DWARF,
1682
+ // see if we have a declaration anywhere else...
1683
+ def_die = debug_map_symfile->FindDefinitionDIE (die);
1684
+ }
1685
+ }
1686
+
1687
+ if (log ) {
1688
+ dwarf->GetObjectFile ()->GetModule ()->LogMessage (
1689
+ log ,
1690
+ " SymbolFileDWARF({0:p}) - {1:x16}}: {2} ({3}) type \" {4}\" is a "
1691
+ " forward declaration, complete DIE is {5}" ,
1692
+ static_cast <void *>(this ), die.GetID (), DW_TAG_value_to_name (tag),
1693
+ tag, attrs.name .GetCString (),
1694
+ def_die ? llvm::utohexstr (def_die.GetID ()) : " not found" );
1695
+ }
1696
+
1697
+ if (def_die) {
1698
+ if (auto [it, inserted] = dwarf->GetDIEToType ().try_emplace (
1699
+ def_die.GetDIE (), DIE_IS_BEING_PARSED);
1700
+ !inserted) {
1701
+ if (it->getSecond () == nullptr ||
1702
+ it->getSecond () == DIE_IS_BEING_PARSED)
1703
+ return nullptr ;
1704
+ return it->getSecond ()->shared_from_this ();
1705
+ }
1706
+ attrs = ParsedDWARFTypeAttributes (def_die);
1707
+ }
1708
+ }
1709
+
1710
+ if (!def_die)
1711
+ def_die = die;
1712
+
1674
1713
if (attrs.name ) {
1675
- GetUniqueTypeNameAndDeclaration (die , cu_language, unique_typename,
1714
+ GetUniqueTypeNameAndDeclaration (def_die , cu_language, unique_typename,
1676
1715
unique_decl);
1677
1716
if (log ) {
1678
1717
dwarf->GetObjectFile ()->GetModule ()->LogMessage (
1679
1718
log , " SymbolFileDWARF({0:p}) - {1:x16}: {2} has unique name: {3} " ,
1680
- static_cast <void *>(this ), die .GetID (), DW_TAG_value_to_name (tag),
1719
+ static_cast <void *>(this ), def_die .GetID (), DW_TAG_value_to_name (tag),
1681
1720
unique_typename.AsCString ());
1682
1721
}
1683
1722
if (UniqueDWARFASTType *unique_ast_entry_type =
1684
1723
dwarf->GetUniqueDWARFASTTypeMap ().Find (
1685
- unique_typename, die , unique_decl, byte_size,
1724
+ unique_typename, def_die , unique_decl, byte_size,
1686
1725
attrs.is_forward_declaration )) {
1687
1726
if (TypeSP type_sp = unique_ast_entry_type->m_type_sp ) {
1688
- dwarf->GetDIEToType ()[die .GetDIE ()] = type_sp.get ();
1727
+ dwarf->GetDIEToType ()[def_die .GetDIE ()] = type_sp.get ();
1689
1728
LinkDeclContextToDIE (
1690
- GetCachedClangDeclContextForDIE (unique_ast_entry_type->m_die ), die);
1729
+ GetCachedClangDeclContextForDIE (unique_ast_entry_type->m_die ),
1730
+ def_die);
1691
1731
// If the DIE being parsed in this function is a definition and the
1692
1732
// entry in the map is a declaration, then we need to update the entry
1693
1733
// to point to the definition DIE.
1694
1734
if (!attrs.is_forward_declaration &&
1695
1735
unique_ast_entry_type->m_is_forward_declaration ) {
1696
- unique_ast_entry_type->UpdateToDefDIE (die, unique_decl, byte_size);
1736
+ unique_ast_entry_type->UpdateToDefDIE (def_die, unique_decl,
1737
+ byte_size);
1697
1738
clang_type = type_sp->GetForwardCompilerType ();
1698
1739
1699
1740
CompilerType compiler_type_no_qualifiers =
1700
1741
ClangUtil::RemoveFastQualifiers (clang_type);
1701
1742
dwarf->GetForwardDeclCompilerTypeToDIE ().insert_or_assign (
1702
1743
compiler_type_no_qualifiers.GetOpaqueQualType (),
1703
- *die .GetDIERef ());
1744
+ *def_die .GetDIERef ());
1704
1745
}
1705
1746
return type_sp;
1706
1747
}
1707
1748
}
1708
1749
}
1709
1750
1710
- DEBUG_PRINTF (" 0x%8.8" PRIx64 " : %s (\" %s\" )\n " , die .GetID (),
1751
+ DEBUG_PRINTF (" 0x%8.8" PRIx64 " : %s (\" %s\" )\n " , def_die .GetID (),
1711
1752
DW_TAG_value_to_name (tag), type_name_cstr);
1712
1753
1713
1754
int tag_decl_kind = -1 ;
@@ -1726,22 +1767,22 @@ DWARFASTParserClang::ParseStructureLikeDIE(const SymbolContext &sc,
1726
1767
if ((attrs.class_language == eLanguageTypeObjC ||
1727
1768
attrs.class_language == eLanguageTypeObjC_plus_plus) &&
1728
1769
!attrs.is_complete_objc_class &&
1729
- die .Supports_DW_AT_APPLE_objc_complete_type ()) {
1770
+ def_die .Supports_DW_AT_APPLE_objc_complete_type ()) {
1730
1771
// We have a valid eSymbolTypeObjCClass class symbol whose name
1731
1772
// matches the current objective C class that we are trying to find
1732
1773
// and this DIE isn't the complete definition (we checked
1733
1774
// is_complete_objc_class above and know it is false), so the real
1734
1775
// definition is in here somewhere
1735
1776
TypeSP type_sp =
1736
- dwarf->FindCompleteObjCDefinitionTypeForDIE (die , attrs.name , true );
1777
+ dwarf->FindCompleteObjCDefinitionTypeForDIE (def_die , attrs.name , true );
1737
1778
1738
1779
if (!type_sp) {
1739
1780
SymbolFileDWARFDebugMap *debug_map_symfile = dwarf->GetDebugMapSymfile ();
1740
1781
if (debug_map_symfile) {
1741
1782
// We weren't able to find a full declaration in this DWARF,
1742
1783
// see if we have a declaration anywhere else...
1743
1784
type_sp = debug_map_symfile->FindCompleteObjCDefinitionTypeForDIE (
1744
- die , attrs.name , true );
1785
+ def_die , attrs.name , true );
1745
1786
}
1746
1787
}
1747
1788
@@ -1751,8 +1792,9 @@ DWARFASTParserClang::ParseStructureLikeDIE(const SymbolContext &sc,
1751
1792
log ,
1752
1793
" SymbolFileDWARF({0:p}) - {1:x16}: {2} ({3}) type \" {4}\" is an "
1753
1794
" incomplete objc type, complete type is {5:x8}" ,
1754
- static_cast <void *>(this ), die.GetID (), DW_TAG_value_to_name (tag),
1755
- tag, attrs.name .GetCString (), type_sp->GetID ());
1795
+ static_cast <void *>(this ), def_die.GetID (),
1796
+ DW_TAG_value_to_name (tag), tag, attrs.name .GetCString (),
1797
+ type_sp->GetID ());
1756
1798
}
1757
1799
return type_sp;
1758
1800
}
@@ -1761,18 +1803,18 @@ DWARFASTParserClang::ParseStructureLikeDIE(const SymbolContext &sc,
1761
1803
if (attrs.is_forward_declaration ) {
1762
1804
// See if the type comes from a Clang module and if so, track down
1763
1805
// that type.
1764
- TypeSP type_sp = ParseTypeFromClangModule (sc, die , log );
1806
+ TypeSP type_sp = ParseTypeFromClangModule (sc, def_die , log );
1765
1807
if (type_sp)
1766
1808
return type_sp;
1767
1809
}
1768
1810
1769
1811
assert (tag_decl_kind != -1 );
1770
1812
UNUSED_IF_ASSERT_DISABLED (tag_decl_kind);
1771
1813
clang::DeclContext *containing_decl_ctx =
1772
- GetClangDeclContextContainingDIE (die , nullptr );
1814
+ GetClangDeclContextContainingDIE (def_die , nullptr );
1773
1815
1774
1816
PrepareContextToReceiveMembers (m_ast, GetClangASTImporter (),
1775
- containing_decl_ctx, die ,
1817
+ containing_decl_ctx, def_die ,
1776
1818
attrs.name .GetCString ());
1777
1819
1778
1820
if (attrs.accessibility == eAccessNone && containing_decl_ctx) {
@@ -1785,31 +1827,32 @@ DWARFASTParserClang::ParseStructureLikeDIE(const SymbolContext &sc,
1785
1827
}
1786
1828
1787
1829
ClangASTMetadata metadata;
1788
- metadata.SetUserID (die .GetID ());
1789
- metadata.SetIsDynamicCXXType (dwarf->ClassOrStructIsVirtual (die ));
1830
+ metadata.SetUserID (def_die .GetID ());
1831
+ metadata.SetIsDynamicCXXType (dwarf->ClassOrStructIsVirtual (def_die ));
1790
1832
1791
1833
TypeSystemClang::TemplateParameterInfos template_param_infos;
1792
- if (ParseTemplateParameterInfos (die , template_param_infos)) {
1834
+ if (ParseTemplateParameterInfos (def_die , template_param_infos)) {
1793
1835
clang::ClassTemplateDecl *class_template_decl =
1794
1836
m_ast.ParseClassTemplateDecl (
1795
- containing_decl_ctx, GetOwningClangModule (die), attrs.accessibility ,
1796
- attrs.name .GetCString (), tag_decl_kind, template_param_infos);
1837
+ containing_decl_ctx, GetOwningClangModule (def_die),
1838
+ attrs.accessibility , attrs.name .GetCString (), tag_decl_kind,
1839
+ template_param_infos);
1797
1840
if (!class_template_decl) {
1798
1841
if (log ) {
1799
1842
dwarf->GetObjectFile ()->GetModule ()->LogMessage (
1800
1843
log ,
1801
1844
" SymbolFileDWARF({0:p}) - {1:x16}: {2} ({3}) type \" {4}\" "
1802
1845
" clang::ClassTemplateDecl failed to return a decl." ,
1803
- static_cast <void *>(this ), die .GetID (), DW_TAG_value_to_name (tag ),
1804
- tag, attrs.name .GetCString ());
1846
+ static_cast <void *>(this ), def_die .GetID (),
1847
+ DW_TAG_value_to_name (tag), tag, attrs.name .GetCString ());
1805
1848
}
1806
1849
return TypeSP ();
1807
1850
}
1808
1851
1809
1852
clang::ClassTemplateSpecializationDecl *class_specialization_decl =
1810
1853
m_ast.CreateClassTemplateSpecializationDecl (
1811
- containing_decl_ctx, GetOwningClangModule (die), class_template_decl ,
1812
- tag_decl_kind, template_param_infos);
1854
+ containing_decl_ctx, GetOwningClangModule (def_die) ,
1855
+ class_template_decl, tag_decl_kind, template_param_infos);
1813
1856
clang_type =
1814
1857
m_ast.CreateClassTemplateSpecializationType (class_specialization_decl);
1815
1858
@@ -1819,13 +1862,13 @@ DWARFASTParserClang::ParseStructureLikeDIE(const SymbolContext &sc,
1819
1862
1820
1863
if (!clang_type) {
1821
1864
clang_type = m_ast.CreateRecordType (
1822
- containing_decl_ctx, GetOwningClangModule (die ), attrs.accessibility ,
1865
+ containing_decl_ctx, GetOwningClangModule (def_die ), attrs.accessibility ,
1823
1866
attrs.name .GetCString (), tag_decl_kind, attrs.class_language , metadata,
1824
1867
attrs.exports_symbols );
1825
1868
}
1826
1869
1827
1870
TypeSP type_sp = dwarf->MakeType (
1828
- die .GetID (), attrs.name , attrs.byte_size , nullptr , LLDB_INVALID_UID,
1871
+ def_die .GetID (), attrs.name , attrs.byte_size , nullptr , LLDB_INVALID_UID,
1829
1872
Type::eEncodingIsUID, &attrs.decl , clang_type,
1830
1873
Type::ResolveState::Forward,
1831
1874
TypePayloadClang (OptionalClangModuleID (), attrs.is_complete_objc_class ));
@@ -1835,7 +1878,7 @@ DWARFASTParserClang::ParseStructureLikeDIE(const SymbolContext &sc,
1835
1878
// function prototypes.
1836
1879
clang::DeclContext *type_decl_ctx =
1837
1880
TypeSystemClang::GetDeclContextForType (clang_type);
1838
- LinkDeclContextToDIE (type_decl_ctx, die );
1881
+ LinkDeclContextToDIE (type_decl_ctx, def_die );
1839
1882
1840
1883
// UniqueDWARFASTType is large, so don't create a local variables on the
1841
1884
// stack, put it on the heap. This function is often called recursively and
@@ -1846,7 +1889,7 @@ DWARFASTParserClang::ParseStructureLikeDIE(const SymbolContext &sc,
1846
1889
// copies of the same type over and over in the ASTContext for our
1847
1890
// module
1848
1891
unique_ast_entry_up->m_type_sp = type_sp;
1849
- unique_ast_entry_up->m_die = die ;
1892
+ unique_ast_entry_up->m_die = def_die ;
1850
1893
unique_ast_entry_up->m_declaration = unique_decl;
1851
1894
unique_ast_entry_up->m_byte_size = byte_size;
1852
1895
unique_ast_entry_up->m_is_forward_declaration = attrs.is_forward_declaration ;
@@ -1862,7 +1905,7 @@ DWARFASTParserClang::ParseStructureLikeDIE(const SymbolContext &sc,
1862
1905
dwarf->GetForwardDeclCompilerTypeToDIE ()
1863
1906
.try_emplace (
1864
1907
ClangUtil::RemoveFastQualifiers (clang_type).GetOpaqueQualType (),
1865
- *die .GetDIERef ())
1908
+ *def_die .GetDIERef ())
1866
1909
.second ;
1867
1910
assert (inserted && " Type already in the forward declaration map!" );
1868
1911
(void )inserted;
0 commit comments