Skip to content

Commit 16733ed

Browse files
[lldb][nfc] Update Swift OS plugin to use the new name of ThreadMemory
1 parent 5bde767 commit 16733ed

File tree

4 files changed

+67
-4
lines changed

4 files changed

+67
-4
lines changed

lldb/source/Plugins/OperatingSystem/SwiftTasks/OperatingSystemSwiftTasks.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,9 @@ OperatingSystemSwiftTasks::FindOrCreateSwiftThread(ThreadList &old_thread_list,
9393
return old_thread;
9494

9595
std::string name = llvm::formatv("Swift Task {0}", task_id);
96-
llvm::StringRef queue_name = "";
97-
return std::make_shared<ThreadMemory>(*m_process, masked_task_id, name,
98-
queue_name,
99-
/*register_data_addr*/ 0);
96+
return std::make_shared<ThreadMemoryProvidingName>(*m_process, masked_task_id,
97+
/*register_data_addr*/ 0,
98+
name);
10099
}
101100

102101
bool OperatingSystemSwiftTasks::UpdateThreadList(ThreadList &old_thread_list,
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: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
@swiftTest
10+
@skipIf(oslist=["windows", "linux"])
11+
def test(self):
12+
"""Test `frame variable` in async functions"""
13+
self.build()
14+
15+
self.runCmd("settings set target.experimental.swift-tasks-plugin-enabled true")
16+
17+
source_file = lldb.SBFileSpec("main.swift")
18+
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
19+
self, "BREAK HERE", source_file
20+
)
21+
22+
self.assertIn("Swift Task", thread.GetName())
23+
24+
queue_plugin = self.get_queue_from_thread_info_command(False)
25+
queue_backing = self.get_queue_from_thread_info_command(True)
26+
self.assertEqual(queue_plugin, queue_backing)
27+
self.assertEqual(queue_plugin, thread.GetQueueName())
28+
29+
num_queues = process.GetNumQueues()
30+
self.assertEqual(num_queues, 1)
31+
32+
queue_regex = re.compile(r"queue = '([^']+)'")
33+
34+
def get_queue_from_thread_info_command(self, use_backing_thread):
35+
interp = self.dbg.GetCommandInterpreter()
36+
result = lldb.SBCommandReturnObject()
37+
38+
backing_thread_arg = ""
39+
if use_backing_thread:
40+
backing_thread_arg = "--backing-thread"
41+
42+
interp.HandleCommand(
43+
"thread info {0}".format(backing_thread_arg),
44+
result,
45+
True,
46+
)
47+
self.assertTrue(result.Succeeded(), "failed to run thread info")
48+
match = self.queue_regex.search(result.GetOutput())
49+
self.assertNotEqual(match, None)
50+
return match.group(1)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
func async_foo() async -> Int {
2+
var myvar = 111; // BREAK HERE
3+
return myvar
4+
}
5+
6+
@main struct Main {
7+
static func main() async {
8+
let result = await async_foo()
9+
print(result)
10+
}
11+
}

0 commit comments

Comments
 (0)