Skip to content

Commit 40468df

Browse files
committed
Collect module import remarks in the types log.
This patch enables the module import remarks in the Swift LangOpts, and sends them straight to the types log. Over the existing log entry in LoadOneModule, this has the advantage that these remarks are generated also for modules that are dependencies of other modules, not just the top level imports. It works for Swift and Clang modules imported by Swift modules.
1 parent f853e1e commit 40468df

File tree

5 files changed

+34
-0
lines changed

5 files changed

+34
-0
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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -999,6 +999,7 @@ void SwiftASTContext::SetCompilerInvocationLLDBOverrides() {
999999
// for the protocol conforming types.
10001000
lang_opts.AllowModuleWithCompilerErrors = true;
10011001
lang_opts.EnableTargetOSChecking = false;
1002+
lang_opts.EnableModuleLoadingRemarks = true;
10021003

10031004
// Bypass deserialization safety to allow deserializing internal details from
10041005
// swiftmodule files.
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")

0 commit comments

Comments
 (0)