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