@@ -1858,6 +1858,17 @@ static lldb::ModuleSP GetUnitTestModule(lldb_private::ModuleList &modules) {
1858
1858
return ModuleSP ();
1859
1859
}
1860
1860
1861
+ // / Detect whether a Swift module was "imported" by DWARFImporter.
1862
+ // / All this *really* means is that it couldn't be loaded through any
1863
+ // / other mechanism.
1864
+ static bool IsDWARFImported (swift::ModuleDecl &module ) {
1865
+ return std::any_of (module .getFiles ().begin (), module .getFiles ().end (),
1866
+ [](swift::FileUnit *file_unit) {
1867
+ return (file_unit->getKind () ==
1868
+ swift::FileUnitKind::DWARFModule);
1869
+ });
1870
+ }
1871
+
1861
1872
lldb::TypeSystemSP SwiftASTContext::CreateInstance (lldb::LanguageType language,
1862
1873
Target &target,
1863
1874
const char *extra_options) {
@@ -2216,7 +2227,9 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
2216
2227
}
2217
2228
2218
2229
const bool can_create = true ;
2219
- if (!swift_ast_sp->m_ast_context_ap ->getStdlibModule (can_create)) {
2230
+ swift::ModuleDecl *stdlib =
2231
+ swift_ast_sp->m_ast_context_ap ->getStdlibModule (can_create);
2232
+ if (!stdlib || IsDWARFImported (*stdlib)) {
2220
2233
logError (" couldn't load the Swift stdlib" );
2221
2234
return {};
2222
2235
}
@@ -8520,6 +8533,16 @@ LoadOneModule(const SourceModule &module, SwiftASTContext &swift_ast_context,
8520
8533
} else
8521
8534
swift_module = swift_ast_context.GetModule (module , error);
8522
8535
8536
+ if (swift_module && IsDWARFImported (*swift_module)) {
8537
+ // This module was "imported" from DWARF. This basically means the
8538
+ // import as a Swift or Clang module failed. We have not yet
8539
+ // checked that DWARF debug info for this module actually exists
8540
+ // and there is no good mechanism to do so ahead of time.
8541
+ // We do know that we never load the stdlib from DWARF though.
8542
+ if (toplevel.GetStringRef () == swift::STDLIB_NAME)
8543
+ swift_module = nullptr ;
8544
+ }
8545
+
8523
8546
if (!swift_module || !error.Success () || swift_ast_context.HasFatalErrors ()) {
8524
8547
LOG_PRINTF (LIBLLDB_LOG_EXPRESSIONS, " Couldn't import module %s: %s" ,
8525
8548
toplevel.AsCString (), error.AsCString ());
0 commit comments