@@ -1556,13 +1556,21 @@ static llvm::Optional<StringRef> GetDSYMBundle(Module &module) {
1556
1556
return dsym;
1557
1557
}
1558
1558
1559
+ // / Detect whether a Swift module was "imported" by DWARFImporter.
1560
+ // / All this *really* means is that it couldn't be loaded through any
1561
+ // / other mechanism.
1562
+ static bool IsDWARFImported (swift::ModuleDecl &module ) {
1563
+ return std::any_of (module .getFiles ().begin (), module .getFiles ().end (),
1564
+ [](swift::FileUnit *file_unit) {
1565
+ return (file_unit->getKind () ==
1566
+ swift::FileUnitKind::DWARFModule);
1567
+ });
1568
+ }
1569
+
1559
1570
lldb::TypeSystemSP SwiftASTContext::CreateInstance (lldb::LanguageType language,
1560
1571
Module &module ,
1561
1572
Target *target,
1562
1573
bool fallback) {
1563
- std::vector<std::string> module_search_paths;
1564
- std::vector<std::pair<std::string, bool >> framework_search_paths;
1565
-
1566
1574
if (!SwiftASTContextSupportsLanguage (language))
1567
1575
return lldb::TypeSystemSP ();
1568
1576
@@ -1576,16 +1584,33 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
1576
1584
module .GetDescription (ss, eDescriptionLevelBrief);
1577
1585
ss << ' "' << ' )' ;
1578
1586
}
1587
+ std::vector<std::string> module_search_paths;
1588
+ std::vector<std::pair<std::string, bool >> framework_search_paths;
1589
+
1590
+ LOG_PRINTF (LIBLLDB_LOG_TYPES, " (Module)" );
1591
+
1592
+ auto logError = [&](const char *message) {
1593
+ LOG_PRINTF (LIBLLDB_LOG_TYPES, " Failed to create module context - %s" ,
1594
+ message);
1595
+ };
1579
1596
1580
1597
ArchSpec arch = module .GetArchitecture ();
1598
+ if (!arch.IsValid ()) {
1599
+ logError (" invalid module architecture" );
1600
+ return TypeSystemSP ();
1601
+ }
1581
1602
1582
1603
ObjectFile *objfile = module .GetObjectFile ();
1583
- if (!objfile)
1584
- return {};
1604
+ if (!objfile) {
1605
+ logError (" no object file for module" );
1606
+ return TypeSystemSP ();
1607
+ }
1585
1608
1586
1609
ArchSpec object_arch = objfile->GetArchitecture ();
1587
- if (!object_arch.IsValid ())
1588
- return {};
1610
+ if (!object_arch.IsValid ()) {
1611
+ logError (" invalid objfile architecture" );
1612
+ return TypeSystemSP ();
1613
+ }
1589
1614
1590
1615
lldb::CompUnitSP main_compile_unit_sp = module .GetCompileUnitAtIndex (0 );
1591
1616
@@ -1641,9 +1666,6 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
1641
1666
swift_ast_sp->GetLanguageOptions ().EnableAccessControl = false ;
1642
1667
swift_ast_sp->GetLanguageOptions ().EnableTargetOSChecking = false ;
1643
1668
1644
- if (!arch.IsValid ())
1645
- return TypeSystemSP ();
1646
-
1647
1669
swift_ast_sp->SetTriple (triple, &module );
1648
1670
1649
1671
bool set_triple = false ;
@@ -1654,7 +1676,7 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
1654
1676
std::string target_triple;
1655
1677
1656
1678
if (sym_file) {
1657
- bool got_serialized_options;
1679
+ bool got_serialized_options = false ;
1658
1680
llvm::SmallString<0 > error;
1659
1681
llvm::raw_svector_ostream errs (error);
1660
1682
if (DeserializeAllCompilerFlags (*swift_ast_sp, module , m_description, errs,
@@ -1784,6 +1806,20 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
1784
1806
swift_ast_sp->LogConfiguration ();
1785
1807
}
1786
1808
}
1809
+
1810
+ if (swift_ast_sp->HasFatalErrors ()) {
1811
+ logError (swift_ast_sp->GetFatalErrors ().AsCString ());
1812
+ return {};
1813
+ }
1814
+
1815
+ const bool can_create = true ;
1816
+ swift::ModuleDecl *stdlib =
1817
+ swift_ast_sp->m_ast_context_ap ->getStdlibModule (can_create);
1818
+ if (!stdlib || IsDWARFImported (*stdlib)) {
1819
+ logError (" couldn't load the Swift stdlib" );
1820
+ return {};
1821
+ }
1822
+
1787
1823
return swift_ast_sp;
1788
1824
}
1789
1825
@@ -1840,17 +1876,6 @@ static lldb::ModuleSP GetUnitTestModule(lldb_private::ModuleList &modules) {
1840
1876
return ModuleSP ();
1841
1877
}
1842
1878
1843
- // / Detect whether a Swift module was "imported" by DWARFImporter.
1844
- // / All this *really* means is that it couldn't be loaded through any
1845
- // / other mechanism.
1846
- static bool IsDWARFImported (swift::ModuleDecl &module ) {
1847
- return std::any_of (module .getFiles ().begin (), module .getFiles ().end (),
1848
- [](swift::FileUnit *file_unit) {
1849
- return (file_unit->getKind () ==
1850
- swift::FileUnitKind::DWARFModule);
1851
- });
1852
- }
1853
-
1854
1879
lldb::TypeSystemSP SwiftASTContext::CreateInstance (lldb::LanguageType language,
1855
1880
Target &target,
1856
1881
const char *extra_options) {
0 commit comments