Skip to content

Commit 885ba1c

Browse files
committed
Don't update the triple when loading additional dylibs in the expression evaluator
This is a surgical fix for the 5.9 branch to address a design problem. When a new Swift module is imported in the expression evaluator, LLDB deserialized the compiler invocation from it and the way the code was written it replaced the existing compiler invocation instead of just adding additional search paths. This patch fixes this by adding a paths-only mode that uses a temporary compiler invocation object. rdar://115747362 (cherry picked from commit 88cc67d)
1 parent 4976bb1 commit 885ba1c

File tree

5 files changed

+67
-10
lines changed

5 files changed

+67
-10
lines changed

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

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,7 +1168,8 @@ static bool DeserializeAllCompilerFlags(swift::CompilerInvocation &invocation,
11681168
const std::string &m_description,
11691169
llvm::raw_ostream &error,
11701170
bool &got_serialized_options,
1171-
bool &found_swift_modules) {
1171+
bool &found_swift_modules,
1172+
bool search_paths_only = false) {
11721173
bool found_validation_errors = false;
11731174
got_serialized_options = false;
11741175

@@ -1278,7 +1279,7 @@ static bool DeserializeAllCompilerFlags(swift::CompilerInvocation &invocation,
12781279

12791280
/// Initialize the compiler invocation with it the search paths from a
12801281
/// serialized AST.
1281-
auto deserializeCompilerFlags = [&]() -> bool {
1282+
auto deserializeCompilerFlags = [&](swift::CompilerInvocation &invocation) {
12821283
auto result = invocation.loadFromSerializedAST(moduleData);
12831284
if (result != swift::serialization::Status::Valid) {
12841285
error << "Could not deserialize " << info.name << ":\n"
@@ -1401,13 +1402,17 @@ static bool DeserializeAllCompilerFlags(swift::CompilerInvocation &invocation,
14011402
return true;
14021403
};
14031404

1404-
got_serialized_options |= deserializeCompilerFlags();
1405-
1406-
LOG_PRINTF(
1407-
GetLog(LLDBLog::Types), "SDK path from module \"%s\" was \"%s\".",
1408-
info.name.str().c_str(), invocation.getSDKPath().str().c_str());
1409-
// We will deduce a matching SDK path from DWARF later.
1410-
invocation.setSDKPath("");
1405+
if (search_paths_only) {
1406+
swift::CompilerInvocation fresh_invocation;
1407+
got_serialized_options |= deserializeCompilerFlags(fresh_invocation);
1408+
} else {
1409+
got_serialized_options |= deserializeCompilerFlags(invocation);
1410+
LOG_PRINTF(
1411+
GetLog(LLDBLog::Types), "SDK path from module \"%s\" was \"%s\".",
1412+
info.name.str().c_str(), invocation.getSDKPath().str().c_str());
1413+
// We will deduce a matching SDK path from DWARF later.
1414+
invocation.setSDKPath("");
1415+
}
14111416
}
14121417
}
14131418

@@ -8371,7 +8376,7 @@ bool SwiftASTContextForExpressions::CacheUserImports(
83718376
invocation, ast_file, {file_or_err->get()->getBuffer()},
83728377
path_remap, discover_implicit_search_paths,
83738378
m_description.str().str(), errs, got_serialized_options,
8374-
found_swift_modules)) {
8379+
found_swift_modules, /*search_paths_only = */true)) {
83758380
LOG_PRINTF(GetLog(LLDBLog::Types), "Could not parse %s: %s",
83768381
ast_file.str().c_str(), error.str().str().c_str());
83778382
}

lldb/test/API/lang/swift/late_expr_dylib/Dylib.swift

Whitespace-only changes.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# This Makefile recursively calls itself, hence the ?=.
2+
SWIFT_SOURCES ?= main.swift
3+
SWIFTFLAGS_EXTRAS ?= -target $(TRIPLE) -I$(BUILDDIR)
4+
all: Dylib $(EXE)
5+
6+
include Makefile.rules
7+
8+
.PHONY: Dylib
9+
Dylib:
10+
$(MAKE) MAKE_DSYM=$(MAKE_DSYM) CC=$(CC) SWIFTC=$(SWIFTC) \
11+
ARCH=$(ARCH) DSYMUTIL=$(DSYMUTIL) \
12+
VPATH=$(SRCDIR) -I $(SRCDIR) \
13+
SWIFT_SOURCES= \
14+
SWIFTFLAGS_EXTRAS="-target $(DYLIB_TRIPLE) -I__PATH_FROM_DYLIB__" \
15+
-f $(SRCDIR)/Makefile \
16+
DYLIB_FILENAME=Dylib.dylib \
17+
DYLIB_SWIFT_SOURCES=Dylib.swift \
18+
DYLIB_NAME=Dylib \
19+
DYLIB_ONLY=YES \
20+
LD_EXTRAS="-lSwiftCore" \
21+
Dylib.dylib
22+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from lldbsuite.test.lldbtest import *
2+
from lldbsuite.test.decorators import *
3+
import lldbsuite.test.lldbutil as lldbutil
4+
5+
6+
class TestSwiftLateDylib(TestBase):
7+
mydir = TestBase.compute_mydir(__file__)
8+
9+
@skipUnlessDarwin
10+
@swiftTest
11+
@skipIfDarwinEmbedded
12+
def test(self):
13+
"""Test that a late loaded Swift dylib is debuggable"""
14+
arch = self.getArchitecture()
15+
self.build(dictionary={"TRIPLE": arch + "-apple-macosx11.0.0", "ARCH": arch,
16+
"DYLIB_TRIPLE": arch + "-apple-macosx12.0.0"})
17+
log = self.getBuildArtifact("types.log")
18+
self.runCmd('log enable lldb types -f "%s"' % log)
19+
lldbutil.run_to_source_breakpoint(self, "break here",
20+
lldb.SBFileSpec("main.swift"))
21+
self.expect("expr -- import Dylib")
22+
# Scan through the types log.
23+
self.filecheck('platform shell cat "%s"' % log, __file__)
24+
# CHECK: SwiftASTContextForExpressions::LogConfiguration(){{.*}}Architecture{{.*}}-apple-macosx11.0.0
25+
# CHECK-NOT: __PATH_FROM_DYLIB__
26+
# Verify that the deployment target didn't change:
27+
# CHECK: SwiftASTContextForExpressions::LogConfiguration(){{.*}}Architecture{{.*}}-apple-macosx11.0.0
28+
# But LLDB has picked up extra paths:
29+
# CHECK: SwiftASTContextForExpressions::LogConfiguration(){{.*}}__PATH_FROM_DYLIB__
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)