Skip to content

Commit

Permalink
[lldb] Add an expression evaluation test for modules built with
Browse files Browse the repository at this point in the history
-enable-testing and -enable-library-evolution

-enable-testing affects the visibility of types, which together with
-enable-library-evolution may cause the compiler embedded in LLDB to
generate incorrect code on expression evaluation.
  • Loading branch information
augusto2112 committed Jan 8, 2025
1 parent ca45c59 commit de8398e
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lldb/test/API/lang/swift/enable_testing/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
SWIFT_SOURCES := main.swift

all: libPublic.dylib a.out

include Makefile.rules
LD_EXTRAS = -lPublic -L$(BUILDDIR)
SWIFTFLAGS_EXTRAS = -I$(BUILDDIR)

libPublic.dylib: Public.swift
"$(MAKE)" MAKE_DSYM=YES CC=$(CC) SWIFTC=$(SWIFTC) \
ARCH=$(ARCH) DSYMUTIL=$(DSYMUTIL) \
BASENAME=Public \
SWIFTFLAGS_EXTRAS="-I$(BUILDDIR) -enable-library-evolution -enable-testing" \
VPATH=$(SRCDIR) -I $(SRCDIR) \
DYLIB_ONLY:=YES DYLIB_NAME=Public \
DYLIB_SWIFT_SOURCES:=Public.swift \
-f $(MAKEFILE_RULES)

clean::
"$(MAKE)" BASENAME=Public VPATH=$(SRCDIR) -I $(SRCDIR) -f $(SRCDIR)/dylib.mk clean


15 changes: 15 additions & 0 deletions lldb/test/API/lang/swift/enable_testing/Public.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class SomeClass {
let value = 42
}

class ClassWithProperty {
private var v = SomeClass()

func f() {
print(v) // break here
}
}

public func entry() {
ClassWithProperty().f()
}
21 changes: 21 additions & 0 deletions lldb/test/API/lang/swift/enable_testing/TestSwiftEnableTesting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import lldb
from lldbsuite.test.lldbtest import *
from lldbsuite.test.decorators import *
import lldbsuite.test.lldbutil as lldbutil


class TestSwiftEnableTesting(TestBase):

def setUp(self):
TestBase.setUp(self)

@swiftTest
def test(self):
"""Test that expression evaluation generates a direct member access to a private property in a module compiled with -enable-library-evolution and -enable-testing"""

self.build()
target, process, _, _ = lldbutil.run_to_source_breakpoint(
self, "break here", lldb.SBFileSpec("Public.swift"), extra_images=["Public"]
)

self.expect("expression v", substrs=["Public.SomeClass", "value = 42"])
3 changes: 3 additions & 0 deletions lldb/test/API/lang/swift/enable_testing/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Public

entry()

0 comments on commit de8398e

Please sign in to comment.