Skip to content

Commit e68fd77

Browse files
committed
[lldb] Be aware of async functions in the form of closures (#4966) (#4980)
Recognize async closures as being async, in `IsSwiftAsyncFunctionSymbol`. Like `static` functions, this requires peeling off a wrapper node to get to the `Function` node. rdar://94840584 (cherry-picked from commit ed878fe) (cherry-picked from commit 5c812fe)
1 parent 448f071 commit e68fd77

File tree

3 files changed

+38
-15
lines changed

3 files changed

+38
-15
lines changed

lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntimeNames.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,17 @@ static bool IsSwiftAsyncFunctionSymbol(swift::Demangle::NodePointer node) {
8282
return false;
8383
if (hasChild(node, Node::Kind::AsyncSuspendResumePartialFunction))
8484
return false;
85-
if (node->getFirstChild()->getKind() == Node::Kind::Static)
86-
// Traverse forward to the static node, to handle static functions.
85+
86+
// Peel off layers over top of Function nodes.
87+
switch (node->getFirstChild()->getKind()) {
88+
case Node::Kind::Static:
89+
case Node::Kind::ExplicitClosure:
8790
node = node->getFirstChild();
91+
break;
92+
default:
93+
break;
94+
}
95+
8896
return childAtPath(node,
8997
{Node::Kind::Function, Node::Kind::Type,
9098
Node::Kind::FunctionType, Node::Kind::AsyncAnnotation}) ||

lldb/test/API/lang/swift/async/async_fnargs/TestSwiftAsyncFnArgs.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,6 @@ def test(self):
1818
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
1919
self, 'Set breakpoint here', src)
2020

21-
self.expect("frame var -d run-target -- msg", substrs=['"world"'])
22-
23-
# Continue into the second coroutine funclet.
24-
bkpt2 = target.BreakpointCreateBySourceRegex("And also here", src, None)
25-
self.assertGreater(bkpt2.GetNumLocations(), 0)
26-
process.Continue()
27-
self.assertEqual(
28-
len(lldbutil.get_threads_stopped_at_breakpoint(process, bkpt2)), 1)
29-
30-
self.expect("frame var -d run-target -- msg", substrs=['"world"'])
21+
while process.selected_thread.stop_reason == lldb.eStopReasonBreakpoint:
22+
self.expect("frame var -d run-target msg", patterns=['"(basic|generic|static|closure) world"'])
23+
process.Continue()

lldb/test/API/lang/swift/async/async_fnargs/main.swift

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,37 @@ func sayHello() async {
55
print("hello")
66
}
77

8+
func sayBasic(_ msg: String) async {
9+
print("Set breakpoint here")
10+
await sayHello()
11+
print(msg) // Set breakpoint here
12+
}
13+
814
func sayGeneric<T>(_ msg: T) async {
915
print("Set breakpoint here")
1016
await sayHello()
11-
print(msg) // And also here.
17+
print(msg) // Set breakpoint here
18+
}
19+
20+
struct Struct {
21+
static func sayStatic(_ msg: String) async {
22+
print("Set breakpoint here")
23+
await sayHello()
24+
print(msg) // Set breakpoint here
25+
}
1226
}
1327

1428
@main struct Main {
1529
static func main() async {
16-
await sayHello()
17-
await sayGeneric("world")
30+
let closure = { msg in
31+
print("Set breakpoint here")
32+
await sayHello()
33+
print(msg) // Set breakpoint here
34+
}
35+
36+
await sayBasic("basic world")
37+
await sayGeneric("generic world")
38+
await Struct.sayStatic("static world")
39+
await closure("closure world")
1840
}
1941
}

0 commit comments

Comments
 (0)