From 847de2c76e6a671097c65301fbe86242c2c8ea45 Mon Sep 17 00:00:00 2001 From: Adrian Prantl Date: Thu, 10 Apr 2025 09:49:09 -0700 Subject: [PATCH 1/2] [lldb] Add a test for calling open resilient functions in expressions See https://github.com/swiftlang/swift/pull/80691 (cherry picked from commit 6f8e332f00c1af564af092383e6460a80fffee07) --- .../classes/open_resilient/Library.swift | 4 ++++ .../expression/classes/open_resilient/Makefile | 14 ++++++++++++++ .../TestSwiftExpressionOpenResilientClass.py | 15 +++++++++++++++ .../expression/classes/open_resilient/main.swift | 8 ++++++++ 4 files changed, 41 insertions(+) create mode 100644 lldb/test/API/lang/swift/expression/classes/open_resilient/Library.swift create mode 100644 lldb/test/API/lang/swift/expression/classes/open_resilient/Makefile create mode 100644 lldb/test/API/lang/swift/expression/classes/open_resilient/TestSwiftExpressionOpenResilientClass.py create mode 100644 lldb/test/API/lang/swift/expression/classes/open_resilient/main.swift diff --git a/lldb/test/API/lang/swift/expression/classes/open_resilient/Library.swift b/lldb/test/API/lang/swift/expression/classes/open_resilient/Library.swift new file mode 100644 index 0000000000000..9ea79076e09da --- /dev/null +++ b/lldb/test/API/lang/swift/expression/classes/open_resilient/Library.swift @@ -0,0 +1,4 @@ +open class A { + public init() {} + open func foo() -> Int { return 23 } +} diff --git a/lldb/test/API/lang/swift/expression/classes/open_resilient/Makefile b/lldb/test/API/lang/swift/expression/classes/open_resilient/Makefile new file mode 100644 index 0000000000000..e4515a44a48ea --- /dev/null +++ b/lldb/test/API/lang/swift/expression/classes/open_resilient/Makefile @@ -0,0 +1,14 @@ +SWIFT_SOURCES := main.swift +SWIFTFLAGS_EXTRAS := -I. +LD_EXTRAS = -lLibrary -L$(BUILDDIR) +all: libLibrary.dylib a.out + +lib%.dylib: %.swift + "$(MAKE)" MAKE_DSYM=NO DYLIB_ONLY=YES \ + DYLIB_HIDE_SWIFTMODULE=YES \ + DYLIB_NAME=$(shell basename $< .swift) \ + DYLIB_SWIFT_SOURCES=$(shell basename $<) \ + SWIFTFLAGS_EXTRAS=-enable-library-evolution \ + VPATH=$(SRCDIR) -I $(SRCDIR) -f $(MAKEFILE_RULES) all + +include Makefile.rules diff --git a/lldb/test/API/lang/swift/expression/classes/open_resilient/TestSwiftExpressionOpenResilientClass.py b/lldb/test/API/lang/swift/expression/classes/open_resilient/TestSwiftExpressionOpenResilientClass.py new file mode 100644 index 0000000000000..87e4def20ee6d --- /dev/null +++ b/lldb/test/API/lang/swift/expression/classes/open_resilient/TestSwiftExpressionOpenResilientClass.py @@ -0,0 +1,15 @@ +import lldb +from lldbsuite.test.lldbtest import * +from lldbsuite.test.decorators import * +import lldbsuite.test.lldbutil as lldbutil + +class TestExpressionOpenResilientClass(TestBase): + NO_DEBUG_INFO_TEST = True + @swiftTest + def test(self): + """Tests calling an open resilient function""" + self.build() + lldbutil.run_to_source_breakpoint( + self, 'break here', lldb.SBFileSpec('main.swift')) + + self.expect("expr -- a.foo()", substrs=["23"]) diff --git a/lldb/test/API/lang/swift/expression/classes/open_resilient/main.swift b/lldb/test/API/lang/swift/expression/classes/open_resilient/main.swift new file mode 100644 index 0000000000000..0cf6cfddaeee8 --- /dev/null +++ b/lldb/test/API/lang/swift/expression/classes/open_resilient/main.swift @@ -0,0 +1,8 @@ +import Library + +func f() { + let a = A() + print("break here \(a)") +} + +f() From 788e6fea9fbc444862d014aa143bff817b00da95 Mon Sep 17 00:00:00 2001 From: Adrian Prantl Date: Thu, 10 Apr 2025 13:03:50 -0700 Subject: [PATCH 2/2] [lldb] Add dylib to extra_images --- .../open_resilient/TestSwiftExpressionOpenResilientClass.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lldb/test/API/lang/swift/expression/classes/open_resilient/TestSwiftExpressionOpenResilientClass.py b/lldb/test/API/lang/swift/expression/classes/open_resilient/TestSwiftExpressionOpenResilientClass.py index 87e4def20ee6d..42347a0aba262 100644 --- a/lldb/test/API/lang/swift/expression/classes/open_resilient/TestSwiftExpressionOpenResilientClass.py +++ b/lldb/test/API/lang/swift/expression/classes/open_resilient/TestSwiftExpressionOpenResilientClass.py @@ -10,6 +10,7 @@ def test(self): """Tests calling an open resilient function""" self.build() lldbutil.run_to_source_breakpoint( - self, 'break here', lldb.SBFileSpec('main.swift')) + self, 'break here', lldb.SBFileSpec('main.swift'), + extra_images=['Library']) self.expect("expr -- a.foo()", substrs=["23"])