Skip to content

Commit d6f9d81

Browse files
committed
Add Swift tests for memory read -t <typename>
1 parent 6833b6c commit d6f9d81

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SWIFT_SOURCES := main.swift
2+
SWIFTFLAGS_EXTRAS := -parse-as-library
3+
include Makefile.rules
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import lldb
2+
from lldbsuite.test.lldbtest import *
3+
from lldbsuite.test.decorators import *
4+
import lldbsuite.test.lldbutil as lldbutil
5+
6+
7+
class TestCase(TestBase):
8+
@swiftTest
9+
def test_scalar_types(self):
10+
self.build()
11+
_, _, thread, _ = lldbutil.run_to_source_breakpoint(
12+
self, "break here", lldb.SBFileSpec("main.swift")
13+
)
14+
frame = thread.selected_frame
15+
16+
child = frame.var("name")
17+
for t in ("String", "$sSSD"):
18+
self.expect(
19+
f"memory read -t {t} {child.load_addr}",
20+
substrs=[f'(String) 0x{child.load_addr:x} = "dirk"'],
21+
)
22+
23+
child = frame.var("number")
24+
for t in ("Int", "$sSiD"):
25+
self.expect(
26+
f"memory read -t {t} {child.load_addr}",
27+
substrs=[f"(Int) 0x{child.load_addr:x} = 41"],
28+
)
29+
30+
child = frame.var("fact")
31+
for t in ("Bool", "$sSbD"):
32+
self.expect(
33+
f"memory read -t {t} {child.load_addr}",
34+
substrs=[f"(Bool) 0x{child.load_addr:x} = true"],
35+
)
36+
37+
@swiftTest
38+
@expectedFailureAll
39+
def test_generic_types(self):
40+
self.build()
41+
_, _, thread, _ = lldbutil.run_to_source_breakpoint(
42+
self, "break here", lldb.SBFileSpec("main.swift")
43+
)
44+
frame = thread.selected_frame
45+
46+
child = frame.var("maybe")
47+
for t in ("UInt64?", "$ss6UInt64VSgD"):
48+
self.expect(
49+
f"memory read -t {t} {child.load_addr}",
50+
substrs=[f"(UInt64?) 0x{child.load_addr:x} = nil"],
51+
)
52+
53+
child = frame.var("bytes")
54+
for t in ("[UInt8]", "$sSays5UInt8VGD"):
55+
self.expect(
56+
f"memory read -t {t} {child.load_addr}",
57+
substrs=[f"([UInt8]) 0x{child.load_addr:x} = [1, 2, 4, 8]"],
58+
)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@main enum Entry {
2+
static func main() {
3+
var name: String = "dirk"
4+
var number: Int = 41
5+
var fact: Bool = true
6+
var maybe: UInt64? = nil
7+
var bytes: [UInt8] = [1, 2, 4, 8]
8+
print("break here", name, number, fact, maybe, bytes)
9+
}
10+
}

0 commit comments

Comments
 (0)