Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -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<std::string> DeserializedArgs = swift_ast_sp->GetClangArguments();
swift_ast_sp->GetClangImporterOptions().ExtraArgs.clear();
Expand Down Expand Up @@ -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 {};
Expand Down Expand Up @@ -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 {};
Expand Down
3 changes: 3 additions & 0 deletions lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ class SwiftASTContext : public TypeSystemSwift {
std::set<lldb::LanguageType> &languages_for_types,
std::set<lldb::LanguageType> &languages_for_expressions);

/// Set LangOpt overrides LLDB needs.
void SetCompilerInvocationLLDBOverrides();

bool SupportsLanguage(lldb::LanguageType language) override;

SwiftASTContext *GetSwiftASTContext(const SymbolContext *sc) const override {
Expand Down
2 changes: 2 additions & 0 deletions lldb/test/API/lang/swift/module_import/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SWIFT_SOURCES := main.swift
include Makefile.rules
22 changes: 22 additions & 0 deletions lldb/test/API/lang/swift/module_import/TestSwiftModuleImport.py
Original file line number Diff line number Diff line change
@@ -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'
1 change: 1 addition & 0 deletions lldb/test/API/lang/swift/module_import/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print("break here")
Original file line number Diff line number Diff line change
Expand Up @@ -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"]))
Expand All @@ -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