Skip to content

Commit 4f5555d

Browse files
Merge pull request #7633 from adrian-prantl/115747362-5.9
Don't update the triple when loading additional dylibs in the expression evaluator
2 parents c9eb76e + 88cc67d commit 4f5555d

File tree

8 files changed

+74
-11
lines changed

8 files changed

+74
-11
lines changed

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

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,7 +1177,8 @@ static bool DeserializeAllCompilerFlags(swift::CompilerInvocation &invocation,
11771177
const std::string &m_description,
11781178
llvm::raw_ostream &error,
11791179
bool &got_serialized_options,
1180-
bool &found_swift_modules) {
1180+
bool &found_swift_modules,
1181+
bool search_paths_only = false) {
11811182
bool found_validation_errors = false;
11821183
got_serialized_options = false;
11831184

@@ -1287,7 +1288,7 @@ static bool DeserializeAllCompilerFlags(swift::CompilerInvocation &invocation,
12871288

12881289
/// Initialize the compiler invocation with it the search paths from a
12891290
/// serialized AST.
1290-
auto deserializeCompilerFlags = [&]() -> bool {
1291+
auto deserializeCompilerFlags = [&](swift::CompilerInvocation &invocation) {
12911292
auto result = invocation.loadFromSerializedAST(moduleData);
12921293
if (result != swift::serialization::Status::Valid) {
12931294
error << "Could not deserialize " << info.name << ":\n"
@@ -1410,13 +1411,17 @@ static bool DeserializeAllCompilerFlags(swift::CompilerInvocation &invocation,
14101411
return true;
14111412
};
14121413

1413-
got_serialized_options |= deserializeCompilerFlags();
1414-
1415-
LOG_PRINTF(
1416-
GetLog(LLDBLog::Types), "SDK path from module \"%s\" was \"%s\".",
1417-
info.name.str().c_str(), invocation.getSDKPath().str().c_str());
1418-
// We will deduce a matching SDK path from DWARF later.
1419-
invocation.setSDKPath("");
1414+
if (search_paths_only) {
1415+
swift::CompilerInvocation fresh_invocation;
1416+
got_serialized_options |= deserializeCompilerFlags(fresh_invocation);
1417+
} else {
1418+
got_serialized_options |= deserializeCompilerFlags(invocation);
1419+
LOG_PRINTF(
1420+
GetLog(LLDBLog::Types), "SDK path from module \"%s\" was \"%s\".",
1421+
info.name.str().c_str(), invocation.getSDKPath().str().c_str());
1422+
// We will deduce a matching SDK path from DWARF later.
1423+
invocation.setSDKPath("");
1424+
}
14201425
}
14211426
}
14221427

@@ -8374,7 +8379,7 @@ bool SwiftASTContextForExpressions::CacheUserImports(
83748379
invocation, ast_file, {file_or_err->get()->getBuffer()},
83758380
path_remap, discover_implicit_search_paths,
83768381
m_description.str().str(), errs, got_serialized_options,
8377-
found_swift_modules)) {
8382+
found_swift_modules, /*search_paths_only = */true)) {
83788383
LOG_PRINTF(GetLog(LLDBLog::Types), "Could not parse %s: %s",
83798384
ast_file.str().c_str(), error.str().str().c_str());
83808385
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
SWIFT_SOURCES := main.swift
2+
SWIFTFLAGS_EXTRAS := -target $(TRIPLE)
23

34
include Makefile.rules

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")

lldb/test/API/lang/swift/xcode_sdk/Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
SWIFT_SOURCES := main.swift
2+
ifeq "$(TRIPLE)" ""
23
SWIFTFLAGS_EXTRAS := -Xfrontend -no-serialize-debugging-options
4+
else
5+
# Target override for the simulator testcase.
6+
SWIFTFLAGS_EXTRAS := -Xfrontend -no-serialize-debugging-options -target $(TRIPLE)
7+
endif
38
SWIFT_BRIDGING_HEADER := bridging-header.h
49
LD_EXTRAS := ignored.o
510

611
all: ignored.o $(EXE)
712

8-
# Artificially inject a wrong SDK into a C file to test that it is ebing ignored.
13+
# Artificially inject a wrong SDK into a C file to test that it is being ignored.
914
ignored.o: ignored.c
1015
$(CC) -target $(ARCH)-apple-macos -c $< -o $@ \
1116
-isysroot $(shell xcrun --sdk iphonesimulator --show-sdk-path)

0 commit comments

Comments
 (0)