diff --git a/lldb/source/Plugins/TypeSystem/Swift/StoringDiagnosticConsumer.h b/lldb/source/Plugins/TypeSystem/Swift/StoringDiagnosticConsumer.h index 0b55620f4674f..0eb9df77d7fce 100644 --- a/lldb/source/Plugins/TypeSystem/Swift/StoringDiagnosticConsumer.h +++ b/lldb/source/Plugins/TypeSystem/Swift/StoringDiagnosticConsumer.h @@ -15,6 +15,7 @@ #include "Plugins/ExpressionParser/Swift/SwiftDiagnostic.h" +#include "lldb/Utility/LLDBLog.h" #include "lldb/Utility/StreamString.h" #include "swift/AST/DiagnosticEngine.h" @@ -198,6 +199,13 @@ class StoringDiagnosticConsumer : public swift::DiagnosticConsumer { std::string &s = os.str(); formatted_text = !s.empty() ? std::move(s) : std::string(text); } + if (info.Kind == swift::DiagnosticKind::Remark && + info.ID == swift::diag::module_loaded.ID) { + // Divert module import remarks into the logs. + LLDB_LOG(GetLog(LLDBLog::Types), "{0} Module import remark: {1}", + m_ast_context.GetDescription(), formatted_text); + return; + } RawDiagnostic diagnostic( formatted_text, info.Kind, bufferName.str(), bufferID, line_col.first, line_col.second, diff --git a/lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp b/lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp index 66b014cb62b6d..aeb5f00dcd9da 100644 --- a/lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp +++ b/lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp @@ -979,7 +979,9 @@ SwiftASTContext::SwiftASTContext(std::string description, // Set the clang modules cache path. m_compiler_invocation_ap->setClangModuleCachePath( GetClangModulesCacheProperty()); +} +void SwiftASTContext::SetCompilerInvocationLLDBOverrides() { swift::IRGenOptions &ir_gen_opts = m_compiler_invocation_ap->getIRGenOptions(); ir_gen_opts.OutputKind = swift::IRGenOutputKind::Module; @@ -997,6 +999,7 @@ SwiftASTContext::SwiftASTContext(std::string description, // for the protocol conforming types. lang_opts.AllowModuleWithCompilerErrors = true; lang_opts.EnableTargetOSChecking = false; + lang_opts.EnableModuleLoadingRemarks = true; // Bypass deserialization safety to allow deserializing internal details from // swiftmodule files. @@ -1964,6 +1967,8 @@ SwiftASTContext::CreateInstance(lldb::LanguageType language, Module &module, ConfigureResourceDirs(swift_ast_sp->GetCompilerInvocation(), resource_dir, triple); + swift_ast_sp->SetCompilerInvocationLLDBOverrides(); + // Apply the working directory to all relative paths. std::vector DeserializedArgs = swift_ast_sp->GetClangArguments(); swift_ast_sp->GetClangImporterOptions().ExtraArgs.clear(); @@ -2490,6 +2495,8 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance( // otherwise no modules will be found. swift_ast_sp->InitializeSearchPathOptions(module_search_paths, framework_search_paths); + swift_ast_sp->SetCompilerInvocationLLDBOverrides(); + if (!swift_ast_sp->GetClangImporter()) { logError("couldn't create a ClangImporter"); return {}; @@ -2771,6 +2778,8 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance( // otherwise no modules will be found. swift_ast_sp->InitializeSearchPathOptions(module_search_paths, framework_search_paths); + swift_ast_sp->SetCompilerInvocationLLDBOverrides(); + if (!swift_ast_sp->GetClangImporter()) { logError("couldn't create a ClangImporter"); return {}; diff --git a/lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.h b/lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.h index 1caf5f3fa0f93..e48d240f5fc2b 100644 --- a/lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.h +++ b/lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.h @@ -211,6 +211,9 @@ class SwiftASTContext : public TypeSystemSwift { std::set &languages_for_types, std::set &languages_for_expressions); + /// Set LangOpt overrides LLDB needs. + void SetCompilerInvocationLLDBOverrides(); + bool SupportsLanguage(lldb::LanguageType language) override; SwiftASTContext *GetSwiftASTContext(const SymbolContext *sc) const override { diff --git a/lldb/test/API/lang/swift/module_import/Makefile b/lldb/test/API/lang/swift/module_import/Makefile new file mode 100644 index 0000000000000..cb73d9276d0ed --- /dev/null +++ b/lldb/test/API/lang/swift/module_import/Makefile @@ -0,0 +1,2 @@ +SWIFT_SOURCES := main.swift +include Makefile.rules diff --git a/lldb/test/API/lang/swift/module_import/TestSwiftModuleImport.py b/lldb/test/API/lang/swift/module_import/TestSwiftModuleImport.py new file mode 100644 index 0000000000000..793fb3df6f494 --- /dev/null +++ b/lldb/test/API/lang/swift/module_import/TestSwiftModuleImport.py @@ -0,0 +1,22 @@ +import lldb +from lldbsuite.test.decorators import * +import lldbsuite.test.lldbtest as lldbtest +import lldbsuite.test.lldbutil as lldbutil +import unittest2 + +class TestSwiftModuleImport(lldbtest.TestBase): + + mydir = lldbtest.TestBase.compute_mydir(__file__) + NO_DEBUG_INFO_TESTCASE = True + + @swiftTest + def test(self): + self.build() + target, process, thread, bkpt = lldbutil.run_to_source_breakpoint( + self, 'break here', lldb.SBFileSpec('main.swift')) + + log = self.getBuildArtifact("types.log") + self.runCmd('log enable lldb types -f "%s"' % log) + self.expect("expression -- 0") + self.filecheck('platform shell cat "%s"' % log, __file__) +# CHECK: SwiftASTContextForExpressions{{.*}}Module import remark: loaded module 'a' diff --git a/lldb/test/API/lang/swift/module_import/main.swift b/lldb/test/API/lang/swift/module_import/main.swift new file mode 100644 index 0000000000000..532969a603478 --- /dev/null +++ b/lldb/test/API/lang/swift/module_import/main.swift @@ -0,0 +1 @@ +print("break here") diff --git a/lldb/test/API/lang/swift/system_framework/TestSwiftSystemFramework.py b/lldb/test/API/lang/swift/system_framework/TestSwiftSystemFramework.py index 5477d5ff6a130..32c01ad05e0e7 100644 --- a/lldb/test/API/lang/swift/system_framework/TestSwiftSystemFramework.py +++ b/lldb/test/API/lang/swift/system_framework/TestSwiftSystemFramework.py @@ -2,13 +2,12 @@ from lldbsuite.test.decorators import * import lldbsuite.test.lldbtest as lldbtest import lldbsuite.test.lldbutil as lldbutil -import os import unittest2 - class TestSwiftSystemFramework(lldbtest.TestBase): mydir = lldbtest.TestBase.compute_mydir(__file__) + NO_DEBUG_INFO_TESTCASE = True @swiftTest @skipIf(oslist=no_match(["macosx"])) @@ -22,16 +21,7 @@ def test_system_framework(self): self.runCmd('log enable lldb types -f "%s"' % log) self.expect("settings set target.use-all-compiler-flags true") self.expect("expression -- 0") - pos = 0 - neg = 0 - import io - with open(log, "r", encoding='utf-8') as logfile: - for line in logfile: - if "-- rejecting framework path " in line: - pos += 1 - elif ("reflection metadata" not in line) and \ - ("/System/Library/Frameworks" in line): - neg += 1 - - self.assertGreater(pos, 0, "sanity check failed") - self.assertEqual(neg, 0, "found /System/Library/Frameworks in log") + self.filecheck('platform shell cat "%s"' % log, __file__) +# CHECK: SwiftASTContextForExpressions{{.*}}-- rejecting framework path +# CHECK: SwiftASTContextForExpressions{{.*}}LogConfiguration() +# CHECK-NOT: LogConfiguration(){{.*}}/System/Library/Frameworks