Skip to content

Commit d282f3f

Browse files
[lldb][swift] Add test demonstrating how step out fails
1 parent 8f9beda commit d282f3f

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-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: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import lldb
2+
from lldbsuite.test.decorators import *
3+
import lldbsuite.test.lldbtest as lldbtest
4+
import lldbsuite.test.lldbutil as lldbutil
5+
import re
6+
7+
8+
class TestCase(lldbtest.TestBase):
9+
10+
def check_and_get_frame_names(self, process):
11+
frames = process.GetSelectedThread().frames
12+
# Expected frames:
13+
# ASYNC___0___ <- ASYNC___1___ <- ASYNC___2___ <- ASYNC___3___ <- Main
14+
num_frames = 5
15+
func_names = [frame.GetFunctionName() for frame in frames[:num_frames]]
16+
for idx in range(num_frames - 1):
17+
self.assertIn(f"ASYNC___{idx}___", func_names[idx])
18+
self.assertIn("Main", func_names[num_frames - 1])
19+
return func_names
20+
21+
def step_out_checks(self, thread, expected_func_names):
22+
# Keep stepping out, comparing the top frame's name with the expected name.
23+
for expected_func_name in expected_func_names:
24+
error = lldb.SBError()
25+
thread.StepOut(error)
26+
self.assertSuccess(error, "step out failed")
27+
stop_reason = thread.GetStopReason()
28+
self.assertStopReason(stop_reason, lldb.eStopReasonPlanComplete)
29+
self.assertEqual(thread.frames[0].GetFunctionName(), expected_func_name)
30+
31+
@swiftTest
32+
@skipIf(oslist=["windows", "linux"])
33+
@skipIf("rdar://133849022")
34+
def test(self):
35+
"""Test `frame variable` in async functions"""
36+
self.build()
37+
38+
source_file = lldb.SBFileSpec("main.swift")
39+
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
40+
self, "BREAK HERE", source_file
41+
)
42+
43+
func_names = self.check_and_get_frame_names(process)
44+
self.step_out_checks(thread, func_names[1:])
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
func work() {
2+
print("working")
3+
}
4+
5+
func ASYNC___0___() async -> Int {
6+
var myvar = 111;
7+
work()
8+
myvar += 1; // BREAK HERE
9+
return myvar
10+
}
11+
12+
func ASYNC___1___() async -> Int {
13+
var blah = 333
14+
work()
15+
var result = await ASYNC___0___()
16+
work()
17+
return result + blah
18+
}
19+
20+
func ASYNC___2___() async -> Int {
21+
work()
22+
var result1 = await ASYNC___1___()
23+
work()
24+
return result1
25+
}
26+
27+
func ASYNC___3___() async -> Int {
28+
var result = await ASYNC___2___()
29+
work()
30+
return result
31+
}
32+
33+
@main struct Main {
34+
static func main() async {
35+
let result = await ASYNC___3___()
36+
print(result)
37+
}
38+
}

0 commit comments

Comments
 (0)