Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[lldb] Add an expression evaluation test for modules built with ... #9809

Open
wants to merge 2 commits into
base: stable/20240723
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions lldb/test/API/lang/swift/enable_testing/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
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)

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("break here")
}
}

public func entry() {
ClassWithProperty().f()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import lldb
from lldbsuite.test.lldbtest import *
from lldbsuite.test.decorators import *
import lldbsuite.test.lldbutil as lldbutil


class TestSwiftEnableTesting(TestBase):

@skipUnlessDarwin
@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()
27 changes: 27 additions & 0 deletions lldb/test/API/lang/swift/resilience_other_module/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
SWIFT_SOURCES := main.swift

all: libWithDebInfo.dylib libWithoutDebInfo.dylib a.out

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

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

libWithoutDebInfo.dylib: WithoutDebInfo.swift
"$(MAKE)" MAKE_DSYM=YES CC=$(CC) SWIFTC=$(SWIFTC) \
ARCH=$(ARCH) DSYMUTIL=$(DSYMUTIL) \
BASENAME=WithoutDebInfo \
SWIFTFLAGS_EXTRAS="-I$(BUILDDIR) -enable-library-evolution" \
VPATH=$(SRCDIR) -I $(SRCDIR) \
DYLIB_ONLY:=YES DYLIB_NAME=WithoutDebInfo \
DYLIB_SWIFT_SOURCES:=WithoutDebInfo.swift \
-f $(MAKEFILE_RULES)
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import lldb
from lldbsuite.test.lldbtest import *
from lldbsuite.test.decorators import *
import lldbsuite.test.lldbutil as lldbutil


class TestSwiftResilienceOtherModule(TestBase):

@skipUnlessDarwin
@swiftTest
def test_with_debug_info(self):
self.impl('break here with debug info')

@skipUnlessDarwin
@swiftTest
def test_without_debug_info(self):
self.impl('break here without debug info')

def impl(self, break_str):
self.build()
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
self, break_str, lldb.SBFileSpec('main.swift'))

self.expect("expression s.a", substrs=["Int", "100"])
self.expect("expression s.b", substrs=["Int", "200"])
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public struct S {
public var a = 100
private var b = 200
public init() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public struct S {
public var a = 100
private var b = 200
public init() {}
}
15 changes: 15 additions & 0 deletions lldb/test/API/lang/swift/resilience_other_module/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import WithDebInfo
import WithoutDebInfo

func withDebugInfo() {
var s = WithDebInfo.S()
print("break here with debug info")
}

func withoutDebugInfo() {
var s = WithoutDebInfo.S()
print("break here without debug info")
}

withDebugInfo()
withoutDebugInfo()
4 changes: 4 additions & 0 deletions lldb/test/API/lang/swift/resilience_superclass/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SWIFT_SOURCES := main.swift
SWIFTFLAGS_EXTRAS = -enable-library-evolution

include Makefile.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import lldb
from lldbsuite.test.lldbtest import *
from lldbsuite.test.decorators import *
import lldbsuite.test.lldbutil as lldbutil


class TestSwiftResilienceSuperclass(TestBase):
@skipUnlessDarwin
@swiftTest
def test(self):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def test(self):
def test(self):
"""
This test tests that ...
"""

self.build()
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
self, 'break here', lldb.SBFileSpec('main.swift'))

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

public class SuperClass<T>: NSObject {
var someVar: T
init(_ someVar: T) {
self.someVar = someVar
super.init()
}
}

class Class<T>: SuperClass<T> {
var v = 42

override init(_ t: T) {
super.init(t)
}
}


open class OpenSuperClass<T>: NSObject {
var someVar: T
init(_ someVar: T) {
self.someVar = someVar
super.init()
}
}

class InheritingOpenClass<T>: OpenSuperClass<T> {
var v = 100

override init(_ t: T) {
super.init(t)
}
}

func main() {
let c = Class(true)
let c2 = InheritingOpenClass(true)
print("break here")
}

main()
4 changes: 4 additions & 0 deletions lldb/test/API/lang/swift/resilience_superclass_mod/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SWIFT_SOURCES := main.swift
SWIFTFLAGS_EXTRAS = -enable-library-evolution

include Makefile.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import Foundation

open class SuperClass<T>: NSObject {
var someVar: T
public init(_ someVar: T) {
self.someVar = someVar
super.init()
}
}

class Class<T>: SuperClass<T> {
var v = 42

override init(_ t: T) {
super.init(t)
}

func f() -> Int {
let abc = v
return v
}
}

public func entry() {
let c = Class(true)
print("break here")
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import lldb
from lldbsuite.test.lldbtest import *
from lldbsuite.test.decorators import *
import lldbsuite.test.lldbutil as lldbutil


class TestSwiftResilienceSuperclassMod(TestBase):
@skipUnlessDarwin
@swiftTest
def test(self):
self.build()
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
self, 'break here', lldb.SBFileSpec('main.swift'))

self.expect("expression c.v", substrs=["Int", "42"])
24 changes: 24 additions & 0 deletions lldb/test/API/lang/swift/resilience_superclass_mod/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import Foundation

public class SuperClass<T>: NSObject {
var someVar: T
init(_ someVar: T) {
self.someVar = someVar
super.init()
}
}

class Class<T>: SuperClass<T> {
var v = 42

override init(_ t: T) {
super.init(t)
}
}

func main() {
let c = Class(true)
print("break here")
}

main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
SWIFT_SOURCES := main.swift

all: libModWithClass.dylib libModWithSuper.dylib a.out

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

libModWithClass.dylib: ModWithClass.swift libModWithSuper.dylib
"$(MAKE)" MAKE_DSYM=YES CC=$(CC) SWIFTC=$(SWIFTC) \
ARCH=$(ARCH) DSYMUTIL=$(DSYMUTIL) \
BASENAME=ModWithClass \
SWIFTFLAGS_EXTRAS="-I$(BUILDDIR) -enable-library-evolution" \
LD_EXTRAS="-lModWithSuper -L$(BUILDDIR)" \
VPATH=$(SRCDIR) -I $(SRCDIR) \
DYLIB_ONLY:=YES DYLIB_NAME=ModWithClass \
DYLIB_SWIFT_SOURCES:=ModWithClass.swift \
-f $(MAKEFILE_RULES)

libModWithSuper.dylib: ModWithSuper.swift
"$(MAKE)" MAKE_DSYM=YES CC=$(CC) SWIFTC=$(SWIFTC) \
ARCH=$(ARCH) DSYMUTIL=$(DSYMUTIL) \
BASENAME=ModWithSuper \
SWIFTFLAGS_EXTRAS="-I$(BUILDDIR) -enable-library-evolution" \
VPATH=$(SRCDIR) -I $(SRCDIR) \
DYLIB_ONLY:=YES DYLIB_NAME=ModWithSuper \
DYLIB_SWIFT_SOURCES:=ModWithSuper.swift \
-f $(MAKEFILE_RULES)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import ModWithSuper

class Class<T>: SuperClass<T> {
var v = 42

override init(_ t: T) {
super.init(t)
}

func f() -> Int {
let abc = v
return v
}
}

public func entry() {
let c = Class(true)
print("break here")
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Foundation

open class SuperClass<T>: NSObject {
var someVar: T
public init(_ someVar: T) {
self.someVar = someVar
super.init()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import lldb
from lldbsuite.test.lldbtest import *
from lldbsuite.test.decorators import *
import lldbsuite.test.lldbutil as lldbutil


class TestSwiftResilienceSuperclassOtherMod(TestBase):
@skipUnlessDarwin
@swiftTest
def test(self):
self.build()
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
self, 'break here', lldb.SBFileSpec('ModWithClass.swift'))

self.expect("expression c.v", substrs=["Int", "42"])
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import ModWithClass

entry()