Skip to content

Commit 8b30cf0

Browse files
committed
[LLDB] Prefer serialized bridging headers.
Especially in an explicit modules project, LLDB might not know all the search paths needed to imported the on disk header. rdar://156542351
1 parent b42bc8f commit 8b30cf0

File tree

5 files changed

+51
-1
lines changed

5 files changed

+51
-1
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3636,9 +3636,12 @@ ThreadSafeASTContext SwiftASTContext::GetASTContext() {
36363636
m_dwarfimporter_delegate_up =
36373637
std::make_unique<SwiftDWARFImporterDelegate>(*this);
36383638
auto importer_diags = getScopedDiagnosticConsumer();
3639+
const bool ignore_file_mapping = false;
3640+
const bool prefer_serialized_bridging_header = true;
36393641
clang_importer_ap = swift::ClangImporter::create(
36403642
*m_ast_context_ap, "", m_dependency_tracker.get(),
3641-
m_dwarfimporter_delegate_up.get());
3643+
m_dwarfimporter_delegate_up.get(), ignore_file_mapping,
3644+
prefer_serialized_bridging_header);
36423645

36433646
// Handle any errors.
36443647
if (!clang_importer_ap || importer_diags->HasErrors()) {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
SWIFT_SOURCES := main.swift
2+
SWIFT_ENABLE_EXPLICIT_MODULES := Yes
3+
SWIFT_BRIDGING_HEADER := bridging.h
4+
SWIFTFLAGS_EXTRAS = -Xcc -I$(BUILDDIR)/secret
5+
6+
all: secret.h $(EXE)
7+
8+
include Makefile.rules
9+
10+
.PHONY: secret.h
11+
12+
secret.h:
13+
mkdir -p $(BUILDDIR)/secret
14+
echo "struct S { int i; };" > $(BUILDDIR)/secret/secret.h
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import lldb
2+
from lldbsuite.test.decorators import *
3+
import lldbsuite.test.lldbtest as lldbtest
4+
import lldbsuite.test.lldbutil as lldbutil
5+
6+
7+
class TestSwiftExplicitModules(lldbtest.TestBase):
8+
NO_DEBUG_INFO_TESTCASE = True
9+
@swiftTest
10+
def test(self):
11+
"""Test explicit Swift modules with bridging headers"""
12+
self.build()
13+
secret = self.getBuildArtifact("secret")
14+
import shutil
15+
shutil.rmtree(secret)
16+
17+
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
18+
self, 'Set breakpoint here', lldb.SBFileSpec('main.swift'))
19+
log = self.getBuildArtifact("types.log")
20+
self.expect('log enable lldb types -f "%s"' % log)
21+
22+
self.expect("expression s", substrs=['i = 23'])
23+
self.filecheck('platform shell cat "%s"' % log, __file__)
24+
# CHECK: LogConfiguration
25+
# CHECK-NOT: secret
26+
# CHECK: Import
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#include "secret.h"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
func main() {
2+
let s = S(i: 23)
3+
print(s) // Set breakpoint here
4+
}
5+
6+
main()

0 commit comments

Comments
 (0)