8000 Regain the ability to detect a failure to load the Swift stdlib. · swiftlang/llvm-project@2f06068 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2f06068

Browse files
committed
Regain the ability to detect a failure to load the Swift stdlib.
This fixes a regression caused by turning on DWARFImporter by default. rdar://problem/59429786
1 parent 5e754ab commit 2f06068

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

lldb/source/Symbol/SwiftASTContext.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1858,6 +1858,17 @@ static lldb::ModuleSP GetUnitTestModule(lldb_private::ModuleList &modules) {
18581858
return ModuleSP();
18591859
}
18601860

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+
18611872
lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
18621873
Target &target,
18631874
const char *extra_options) {
@@ -2216,7 +2227,9 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
22162227
}
22172228

22182229
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)) {
22202233
logError("couldn't load the Swift stdlib");
22212234
return {};
22222235
}
@@ -8520,6 +8533,16 @@ LoadOneModule(const SourceModule &module, SwiftASTContext &swift_ast_context,
85208533
} else
85218534
swift_module = swift_ast_context.GetModule(module, error);
85228535

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+
85238546
if (!swift_module || !error.Success() || swift_ast_context.HasFatalErrors()) {
85248547
LOG_PRINTF(LIBLLDB_LOG_EXPRESSIONS, "Couldn't import module %s: %s",
85258548
toplevel.AsCString(), error.AsCString());

0 commit comments

Comments
 (0)
0