Skip to content

Commit a178aff

Browse files
committed
Add nested generic LLDB metadata tests
Add tests to check that LLDB is able to correctly read the types of generic classes nested in various contexts from instance metadata. (cherry picked from commit 20d8357)
1 parent 1b42e91 commit a178aff

File tree

12 files changed

+116
-0
lines changed

12 files changed

+116
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
SWIFT_SOURCES := main.swift
2+
include Makefile.rules
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import lldb
2+
from lldbsuite.test.lldbtest import *
3+
from lldbsuite.test.decorators import *
4+
import lldbsuite.test.lldbutil as lldbutil
5+
import unittest2
6+
7+
8+
class SwiftGenericClassNestedInFunctionTest(TestBase):
9+
10+
@swiftTest
11+
def test(self):
12+
"""Tests that a generic class type nested inside a function can be resolved correctly from the instance metadata"""
13+
self.build()
14+
lldbutil.run_to_source_breakpoint(self, "break here", lldb.SBFileSpec("main.swift"))
15+
self.expect("v self", substrs=["B<Int>"])
16+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// This test was created to ensure that the changes in in: apple/swift#61819 did not break behaviour.
2+
3+
func a() {
4+
class B<T>{
5+
func f() {
6+
print(1) // break here
7+
}
8+
}
9+
B<Int>().f()
10+
}
11+
a()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
SWIFT_SOURCES := main.swift
2+
include Makefile.rules
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import lldb
2+
from lldbsuite.test.lldbtest import *
3+
from lldbsuite.test.decorators import *
4+
import lldbsuite.test.lldbutil as lldbutil
5+
import unittest2
6+
7+
8+
class SwiftGenericClassInHashedContainerTest(TestBase):
9+
10+
@swiftTest
11+
def test(self):
12+
"""Tests that the type of hashed container whose value type is a non-generic class declared inside a generic class can be read from instance metadata"""
13+
self.build()
14+
lldbutil.run_to_source_breakpoint(self,"break here", lldb.SBFileSpec("main.swift"))
15+
self.expect("v val", substrs=["(a.A<Int>.B) val"])
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
public class A<T> {
2+
public func addValue() {
3+
self.dict["key"] = B()
4+
}
5+
private class B {}
6+
private var dict: [String: B] = [:]
7+
func test() {
8+
let val = dict["key"]!
9+
print(1) // break here
10+
}
11+
}
12+
13+
let foo = A<Int>()
14+
foo.addValue()
15+
foo.test()
16+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
SWIFT_SOURCES := main.swift
2+
include Makefile.rules
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import lldb
2+
from lldbsuite.test.lldbtest import *
3+
from lldbsuite.test.decorators import *
4+
import lldbsuite.test.lldbutil as lldbutil
5+
import unittest2
6+
7+
8+
class SwiftNestedGenericClassTest(TestBase):
9+
10+
@swiftTest
11+
def test(self):
12+
"""Tests that a generic class type nested inside another generic class can be resolved correctly from the instance metadata"""
13+
self.build()
14+
lldbutil.run_to_source_breakpoint(self, "break here", lldb.SBFileSpec("main.swift"))
15+
self.expect("v foo", substrs=["a.A<Int>.B<String>"])
16+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
public class A<T> {
2+
public class B<U> {
3+
}
4+
}
5+
6+
let foo = A<Int>.B<String>()
7+
print(1) // break here
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
SWIFT_SOURCES := main.swift
2+
include Makefile.rules
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import lldb
2+
from lldbsuite.test.lldbtest import *
3+
from lldbsuite.test.decorators import *
4+
import lldbsuite.test.lldbutil as lldbutil
5+
import unittest2
6+
7+
8+
class SwiftPrivateNestedGenericClassTest(TestBase):
9+
10+
@swiftTest
11+
def test(self):
12+
"""Tests that a private generic class type nested inside another generic class can be resolved correctly from the instance metadata"""
13+
self.build()
14+
lldbutil.run_to_source_breakpoint(self, "break here", lldb.SBFileSpec("main.swift"))
15+
self.expect("v self", substrs=["A<Int>.B<String>"])
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
public class A<T> {
2+
private class B<U> {
3+
func f() {
4+
print(1) // break here
5+
}
6+
}
7+
func g() {
8+
B<String>().f()
9+
}
10+
}
11+
12+
A<Int>().g()

0 commit comments

Comments
 (0)