Skip to content

Commit 572a5a4

Browse files
Merge pull request #7857 from adrian-prantl/module-remarks
Collect module import remarks in the types log.
2 parents bbe4879 + 40468df commit 572a5a4

File tree

7 files changed

+50
-15
lines changed

7 files changed

+50
-15
lines changed

lldb/source/Plugins/TypeSystem/Swift/StoringDiagnosticConsumer.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include "Plugins/ExpressionParser/Swift/SwiftDiagnostic.h"
1717

18+
#include "lldb/Utility/LLDBLog.h"
1819
#include "lldb/Utility/StreamString.h"
1920

2021
#include "swift/AST/DiagnosticEngine.h"
@@ -198,6 +199,13 @@ class StoringDiagnosticConsumer : public swift::DiagnosticConsumer {
198199
std::string &s = os.str();
199200
formatted_text = !s.empty() ? std::move(s) : std::string(text);
200201
}
202+
if (info.Kind == swift::DiagnosticKind::Remark &&
203+
info.ID == swift::diag::module_loaded.ID) {
204+
// Divert module import remarks into the logs.
205+
LLDB_LOG(GetLog(LLDBLog::Types), "{0} Module import remark: {1}",
206+
m_ast_context.GetDescription(), formatted_text);
207+
return;
208+
}
201209
RawDiagnostic diagnostic(
202210
formatted_text, info.Kind, bufferName.str(), bufferID, line_col.first,
203211
line_col.second,

lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,9 @@ SwiftASTContext::SwiftASTContext(std::string description,
979979
// Set the clang modules cache path.
980980
m_compiler_invocation_ap->setClangModuleCachePath(
981981
GetClangModulesCacheProperty());
982+
}
982983

984+
void SwiftASTContext::SetCompilerInvocationLLDBOverrides() {
983985
swift::IRGenOptions &ir_gen_opts =
984986
m_compiler_invocation_ap->getIRGenOptions();
985987
ir_gen_opts.OutputKind = swift::IRGenOutputKind::Module;
@@ -997,6 +999,7 @@ SwiftASTContext::SwiftASTContext(std::string description,
997999
// for the protocol conforming types.
9981000
lang_opts.AllowModuleWithCompilerErrors = true;
9991001
lang_opts.EnableTargetOSChecking = false;
1002+
lang_opts.EnableModuleLoadingRemarks = true;
10001003

10011004
// Bypass deserialization safety to allow deserializing internal details from
10021005
// swiftmodule files.
@@ -1964,6 +1967,8 @@ SwiftASTContext::CreateInstance(lldb::LanguageType language, Module &module,
19641967
ConfigureResourceDirs(swift_ast_sp->GetCompilerInvocation(), resource_dir,
19651968
triple);
19661969

1970+
swift_ast_sp->SetCompilerInvocationLLDBOverrides();
1971+
19671972
// Apply the working directory to all relative paths.
19681973
std::vector<std::string> DeserializedArgs = swift_ast_sp->GetClangArguments();
19691974
swift_ast_sp->GetClangImporterOptions().ExtraArgs.clear();
@@ -2490,6 +2495,8 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(
24902495
// otherwise no modules will be found.
24912496
swift_ast_sp->InitializeSearchPathOptions(module_search_paths,
24922497
framework_search_paths);
2498+
swift_ast_sp->SetCompilerInvocationLLDBOverrides();
2499+
24932500
if (!swift_ast_sp->GetClangImporter()) {
24942501
logError("couldn't create a ClangImporter");
24952502
return {};
@@ -2771,6 +2778,8 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(
27712778
// otherwise no modules will be found.
27722779
swift_ast_sp->InitializeSearchPathOptions(module_search_paths,
27732780
framework_search_paths);
2781+
swift_ast_sp->SetCompilerInvocationLLDBOverrides();
2782+
27742783
if (!swift_ast_sp->GetClangImporter()) {
27752784
logError("couldn't create a ClangImporter");
27762785
return {};

lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,9 @@ class SwiftASTContext : public TypeSystemSwift {
211211
std::set<lldb::LanguageType> &languages_for_types,
212212
std::set<lldb::LanguageType> &languages_for_expressions);
213213

214+
/// Set LangOpt overrides LLDB needs.
215+
void SetCompilerInvocationLLDBOverrides();
216+
214217
bool SupportsLanguage(lldb::LanguageType language) override;
215218

216219
SwiftASTContext *GetSwiftASTContext(const SymbolContext *sc) const override {
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
SWIFT_SOURCES := main.swift
2+
include Makefile.rules
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import lldb
2+
from lldbsuite.test.decorators import *
3+
import lldbsuite.test.lldbtest as lldbtest
4+
import lldbsuite.test.lldbutil as lldbutil
5+
import unittest2
6+
7+
class TestSwiftModuleImport(lldbtest.TestBase):
8+
9+
mydir = lldbtest.TestBase.compute_mydir(__file__)
10+
NO_DEBUG_INFO_TESTCASE = True
11+
12+
@swiftTest
13+
def test(self):
14+
self.build()
15+
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
16+
self, 'break here', lldb.SBFileSpec('main.swift'))
17+
18+
log = self.getBuildArtifact("types.log")
19+
self.runCmd('log enable lldb types -f "%s"' % log)
20+
self.expect("expression -- 0")
21+
self.filecheck('platform shell cat "%s"' % log, __file__)
22+
# CHECK: SwiftASTContextForExpressions{{.*}}Module import remark: loaded module 'a'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
print("break here")

lldb/test/API/lang/swift/system_framework/TestSwiftSystemFramework.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22
from lldbsuite.test.decorators import *
33
import lldbsuite.test.lldbtest as lldbtest
44
import lldbsuite.test.lldbutil as lldbutil
5-
import os
65
import unittest2
76

8-
97
class TestSwiftSystemFramework(lldbtest.TestBase):
108

119
mydir = lldbtest.TestBase.compute_mydir(__file__)
10+
NO_DEBUG_INFO_TESTCASE = True
1211

1312
@swiftTest
1413
@skipIf(oslist=no_match(["macosx"]))
@@ -22,16 +21,7 @@ def test_system_framework(self):
2221
self.runCmd('log enable lldb types -f "%s"' % log)
2322
self.expect("settings set target.use-all-compiler-flags true")
2423
self.expect("expression -- 0")
25-
pos = 0
26-
neg = 0
27-
import io
28-
with open(log, "r", encoding='utf-8') as logfile:
29-
for line in logfile:
30-
if "-- rejecting framework path " in line:
31-
pos += 1
32-
elif ("reflection metadata" not in line) and \
33-
("/System/Library/Frameworks" in line):
34-
neg += 1
35-
36-
self.assertGreater(pos, 0, "sanity check failed")
37-
self.assertEqual(neg, 0, "found /System/Library/Frameworks in log")
24+
self.filecheck('platform shell cat "%s"' % log, __file__)
25+
# CHECK: SwiftASTContextForExpressions{{.*}}-- rejecting framework path
26+
# CHECK: SwiftASTContextForExpressions{{.*}}LogConfiguration()
27+
# CHECK-NOT: LogConfiguration(){{.*}}/System/Library/Frameworks

0 commit comments

Comments
 (0)