From eb65b19ee401417c6105d79ad93533f2bc77e072 Mon Sep 17 00:00:00 2001 From: Adrian Prantl Date: Mon, 16 Oct 2023 14:45:07 -0700 Subject: [PATCH 1/3] Update testcases for upstream Makefile.rules change that removed TRIPLE The variable was removed in https://reviews.llvm.org/D85539 (cherry picked from commit 70d531958bfcdc2f3b92e8c893aa35b5e783ca9f) --- lldb/test/API/lang/swift/availability/Makefile | 1 + lldb/test/API/lang/swift/xcode_sdk/Makefile | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lldb/test/API/lang/swift/availability/Makefile b/lldb/test/API/lang/swift/availability/Makefile index 2a69023633b34..0044ade137d35 100644 --- a/lldb/test/API/lang/swift/availability/Makefile +++ b/lldb/test/API/lang/swift/availability/Makefile @@ -1,3 +1,4 @@ SWIFT_SOURCES := main.swift +SWIFTFLAGS_EXTRAS := -target $(TRIPLE) include Makefile.rules diff --git a/lldb/test/API/lang/swift/xcode_sdk/Makefile b/lldb/test/API/lang/swift/xcode_sdk/Makefile index b3027067f77fa..be73a89d73f48 100644 --- a/lldb/test/API/lang/swift/xcode_sdk/Makefile +++ b/lldb/test/API/lang/swift/xcode_sdk/Makefile @@ -1,11 +1,16 @@ SWIFT_SOURCES := main.swift +ifeq "$(TRIPLE)" "" SWIFTFLAGS_EXTRAS := -Xfrontend -no-serialize-debugging-options +else +# Target override for the simulator testcase. +SWIFTFLAGS_EXTRAS := -Xfrontend -no-serialize-debugging-options -target $(TRIPLE) +endif SWIFT_BRIDGING_HEADER := bridging-header.h LD_EXTRAS := ignored.o all: ignored.o $(EXE) -# Artificially inject a wrong SDK into a C file to test that it is ebing ignored. +# Artificially inject a wrong SDK into a C file to test that it is being ignored. ignored.o: ignored.c $(CC) -target $(ARCH)-apple-macos -c $< -o $@ \ -isysroot $(shell xcrun --sdk iphonesimulator --show-sdk-path) From 4976bb1cafaafd2cda32de646844973abcf842a1 Mon Sep 17 00:00:00 2001 From: Adrian Prantl Date: Mon, 16 Oct 2023 14:46:44 -0700 Subject: [PATCH 2/3] Rename test for consistency (cherry picked from commit 51b0973ab39bc1d0ffe97432b49ff6b618cce369) --- .../{TestAvailability.py => TestSwiftAvailability.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename lldb/test/API/lang/swift/availability/{TestAvailability.py => TestSwiftAvailability.py} (100%) diff --git a/lldb/test/API/lang/swift/availability/TestAvailability.py b/lldb/test/API/lang/swift/availability/TestSwiftAvailability.py similarity index 100% rename from lldb/test/API/lang/swift/availability/TestAvailability.py rename to lldb/test/API/lang/swift/availability/TestSwiftAvailability.py From 885ba1c0c3d5d138aa021f37b7d92912796d65c7 Mon Sep 17 00:00:00 2001 From: Adrian Prantl Date: Mon, 16 Oct 2023 15:18:10 -0700 Subject: [PATCH 3/3] 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 88cc67d7e66091e2730b6772cf3e6df7ad94192f) --- .../TypeSystem/Swift/SwiftASTContext.cpp | 25 +++++++++------- .../lang/swift/late_expr_dylib/Dylib.swift | 0 .../API/lang/swift/late_expr_dylib/Makefile | 22 ++++++++++++++ .../late_expr_dylib/TestSwiftLateExprDylib.py | 29 +++++++++++++++++++ .../API/lang/swift/late_expr_dylib/main.swift | 1 + 5 files changed, 67 insertions(+), 10 deletions(-) create mode 100644 lldb/test/API/lang/swift/late_expr_dylib/Dylib.swift create mode 100644 lldb/test/API/lang/swift/late_expr_dylib/Makefile create mode 100644 lldb/test/API/lang/swift/late_expr_dylib/TestSwiftLateExprDylib.py create mode 100644 lldb/test/API/lang/swift/late_expr_dylib/main.swift diff --git a/lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp b/lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp index 52a577745b549..8d399f57bbef1 100644 --- a/lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp +++ b/lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp @@ -1168,7 +1168,8 @@ static bool DeserializeAllCompilerFlags(swift::CompilerInvocation &invocation, const std::string &m_description, llvm::raw_ostream &error, bool &got_serialized_options, - bool &found_swift_modules) { + bool &found_swift_modules, + bool search_paths_only = false) { bool found_validation_errors = false; got_serialized_options = false; @@ -1278,7 +1279,7 @@ static bool DeserializeAllCompilerFlags(swift::CompilerInvocation &invocation, /// Initialize the compiler invocation with it the search paths from a /// serialized AST. - auto deserializeCompilerFlags = [&]() -> bool { + auto deserializeCompilerFlags = [&](swift::CompilerInvocation &invocation) { auto result = invocation.loadFromSerializedAST(moduleData); if (result != swift::serialization::Status::Valid) { error << "Could not deserialize " << info.name << ":\n" @@ -1401,13 +1402,17 @@ static bool DeserializeAllCompilerFlags(swift::CompilerInvocation &invocation, return true; }; - got_serialized_options |= deserializeCompilerFlags(); - - LOG_PRINTF( - GetLog(LLDBLog::Types), "SDK path from module \"%s\" was \"%s\".", - info.name.str().c_str(), invocation.getSDKPath().str().c_str()); - // We will deduce a matching SDK path from DWARF later. - invocation.setSDKPath(""); + if (search_paths_only) { + swift::CompilerInvocation fresh_invocation; + got_serialized_options |= deserializeCompilerFlags(fresh_invocation); + } else { + got_serialized_options |= deserializeCompilerFlags(invocation); + LOG_PRINTF( + GetLog(LLDBLog::Types), "SDK path from module \"%s\" was \"%s\".", + info.name.str().c_str(), invocation.getSDKPath().str().c_str()); + // We will deduce a matching SDK path from DWARF later. + invocation.setSDKPath(""); + } } } @@ -8371,7 +8376,7 @@ bool SwiftASTContextForExpressions::CacheUserImports( invocation, ast_file, {file_or_err->get()->getBuffer()}, path_remap, discover_implicit_search_paths, m_description.str().str(), errs, got_serialized_options, - found_swift_modules)) { + found_swift_modules, /*search_paths_only = */true)) { LOG_PRINTF(GetLog(LLDBLog::Types), "Could not parse %s: %s", ast_file.str().c_str(), error.str().str().c_str()); } diff --git a/lldb/test/API/lang/swift/late_expr_dylib/Dylib.swift b/lldb/test/API/lang/swift/late_expr_dylib/Dylib.swift new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/lldb/test/API/lang/swift/late_expr_dylib/Makefile b/lldb/test/API/lang/swift/late_expr_dylib/Makefile new file mode 100644 index 0000000000000..5772fe78b1a2f --- /dev/null +++ b/lldb/test/API/lang/swift/late_expr_dylib/Makefile @@ -0,0 +1,22 @@ +# This Makefile recursively calls itself, hence the ?=. +SWIFT_SOURCES ?= main.swift +SWIFTFLAGS_EXTRAS ?= -target $(TRIPLE) -I$(BUILDDIR) +all: Dylib $(EXE) + +include Makefile.rules + +.PHONY: Dylib +Dylib: + $(MAKE) MAKE_DSYM=$(MAKE_DSYM) CC=$(CC) SWIFTC=$(SWIFTC) \ + ARCH=$(ARCH) DSYMUTIL=$(DSYMUTIL) \ + VPATH=$(SRCDIR) -I $(SRCDIR) \ + SWIFT_SOURCES= \ + SWIFTFLAGS_EXTRAS="-target $(DYLIB_TRIPLE) -I__PATH_FROM_DYLIB__" \ + -f $(SRCDIR)/Makefile \ + DYLIB_FILENAME=Dylib.dylib \ + DYLIB_SWIFT_SOURCES=Dylib.swift \ + DYLIB_NAME=Dylib \ + DYLIB_ONLY=YES \ + LD_EXTRAS="-lSwiftCore" \ + Dylib.dylib + diff --git a/lldb/test/API/lang/swift/late_expr_dylib/TestSwiftLateExprDylib.py b/lldb/test/API/lang/swift/late_expr_dylib/TestSwiftLateExprDylib.py new file mode 100644 index 0000000000000..daaba38a8b2d6 --- /dev/null +++ b/lldb/test/API/lang/swift/late_expr_dylib/TestSwiftLateExprDylib.py @@ -0,0 +1,29 @@ +from lldbsuite.test.lldbtest import * +from lldbsuite.test.decorators import * +import lldbsuite.test.lldbutil as lldbutil + + +class TestSwiftLateDylib(TestBase): + mydir = TestBase.compute_mydir(__file__) + + @skipUnlessDarwin + @swiftTest + @skipIfDarwinEmbedded + def test(self): + """Test that a late loaded Swift dylib is debuggable""" + arch = self.getArchitecture() + self.build(dictionary={"TRIPLE": arch + "-apple-macosx11.0.0", "ARCH": arch, + "DYLIB_TRIPLE": arch + "-apple-macosx12.0.0"}) + log = self.getBuildArtifact("types.log") + self.runCmd('log enable lldb types -f "%s"' % log) + lldbutil.run_to_source_breakpoint(self, "break here", + lldb.SBFileSpec("main.swift")) + self.expect("expr -- import Dylib") + # Scan through the types log. + self.filecheck('platform shell cat "%s"' % log, __file__) +# CHECK: SwiftASTContextForExpressions::LogConfiguration(){{.*}}Architecture{{.*}}-apple-macosx11.0.0 +# CHECK-NOT: __PATH_FROM_DYLIB__ +# Verify that the deployment target didn't change: +# CHECK: SwiftASTContextForExpressions::LogConfiguration(){{.*}}Architecture{{.*}}-apple-macosx11.0.0 +# But LLDB has picked up extra paths: +# CHECK: SwiftASTContextForExpressions::LogConfiguration(){{.*}}__PATH_FROM_DYLIB__ diff --git a/lldb/test/API/lang/swift/late_expr_dylib/main.swift b/lldb/test/API/lang/swift/late_expr_dylib/main.swift new file mode 100644 index 0000000000000..532969a603478 --- /dev/null +++ b/lldb/test/API/lang/swift/late_expr_dylib/main.swift @@ -0,0 +1 @@ +print("break here")