Skip to content

[Swift async] Add a baseline test for arguments and locals in logical frames #2632

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

Merged
merged 1 commit into from
Mar 8, 2021
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SWIFT_SOURCES := main.swift
SWIFTFLAGS_EXTRAS := -Xfrontend -enable-experimental-concurrency -parse-as-library
include Makefile.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import lldb
from lldbsuite.test.decorators import *
import lldbsuite.test.lldbtest as lldbtest
import lldbsuite.test.lldbutil as lldbutil
import unittest2


class TestSwiftAsyncBacktraceLocals(lldbtest.TestBase):

mydir = lldbtest.TestBase.compute_mydir(__file__)

@swiftTest
@skipIf(oslist=['windows', 'linux'])
def test(self):
"""Test async unwind"""
self.build()
src = lldb.SBFileSpec('main.swift')
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
self, 'main breakpoint', src)

start_bkpt = target.BreakpointCreateBySourceRegex('function start', src, None)
end_bkpt = target.BreakpointCreateBySourceRegex('end iteration', src, None)

if self.TraceOn():
self.runCmd("bt all")

for n in range(10):
lldbutil.continue_to_breakpoint(process, start_bkpt)
for f in range(n+1):
frame = thread.GetFrameAtIndex(f)
self.assertIn("fibonacci", frame.GetFunctionName(),
"Redundantly confirm that we're stopped in fibonacci()")
if f == 0:
# Get arguments (arguments, locals, statics, in_scope_only)
args = frame.GetVariables(True, False, False, True)
self.assertEqual(len(args), 1, "Found one argument")
self.assertEqual(args[0].GetName(), "n", "Found n argument")
self.assertEqual(args[0].GetValue(), str(10-n), "n has correct value")
self.assertIn("Main.main", thread.GetFrameAtIndex(n+1).GetFunctionName())

lldbutil.continue_to_breakpoint(process, end_bkpt)
frame = thread.GetFrameAtIndex(0)
args = frame.GetVariables(True, False, False, True)
self.assertEqual(len(args), 1, "Found one argument")
self.assertEqual(args[0].GetName(), "n", "Found n argument")
self.assertEqual(args[0].GetValue(), str(1), "n has correct value")

lldbutil.continue_to_breakpoint(process, end_bkpt)
frame = thread.GetFrameAtIndex(0)
args = frame.GetVariables(True, False, False, True)
self.assertEqual(len(args), 1, "Found one argument")
self.assertEqual(args[0].GetName(), "n", "Found n argument")
self.assertEqual(args[0].GetValue(), str(0), "n has correct value")
15 changes: 15 additions & 0 deletions lldb/test/API/lang/swift/async/unwind/backtrace_locals/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
func fibonacci(_ n: Int) async -> Int {
if n == 0 || n == 1 { // function start
return n // end iteration
}
let n_1 = await fibonacci(n - 1)
let n_2 = await fibonacci(n - 2)
return n_1 + n_2
}

@main struct Main {
static func main() async {
let n = await fibonacci(10) // main breakpoint
print(n)
}
}