Skip to content

Commit 26f172a

Browse files
author
git apple-llvm automerger
committed
Merge commit '16a54eb23290' from swift/release/6.2 into stable/20240723
2 parents 8c19757 + 16a54eb commit 26f172a

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ void OperatingSystemSwiftTasks::Terminate() {
3838
PluginManager::UnregisterPlugin(CreateInstance);
3939
}
4040

41+
/// Mask applied to task IDs to generate thread IDs that to don't conflicts with
42+
/// core thread IDs.
43+
static constexpr uint64_t TASK_MASK = 0x0000000f00000000ULL;
44+
4145
/// A wrapper around ThreadMemory providing lazy name evaluation, as this is
4246
/// expensive to compute for Swift Tasks.
4347
class SwiftTaskThreadMemory : public ThreadMemory {
@@ -61,8 +65,13 @@ class SwiftTaskThreadMemory : public ThreadMemory {
6165
}
6266

6367
private:
68+
uint64_t GetTaskID() const {
69+
auto thread_id = GetID();
70+
return thread_id & ~TASK_MASK;
71+
}
72+
6473
std::string GetDefaultTaskName() const {
65-
return llvm::formatv("Task {0}", GetID());
74+
return llvm::formatv("Task {0}", GetTaskID());
6675
}
6776

6877
/// If possible, read a user-provided task name from memory, otherwise use a
@@ -80,7 +89,7 @@ class SwiftTaskThreadMemory : public ThreadMemory {
8089

8190
if (!task_name->has_value())
8291
return GetDefaultTaskName();
83-
return llvm::formatv("{0} (Task {1})", *task_name, GetID());
92+
return llvm::formatv("{0} (Task {1})", *task_name, GetTaskID());
8493
}
8594

8695
std::string m_task_name = "";
@@ -131,7 +140,7 @@ ThreadSP
131140
OperatingSystemSwiftTasks::FindOrCreateSwiftThread(ThreadList &old_thread_list,
132141
uint64_t task_id) {
133142
// Mask higher bits to avoid conflicts with core thread IDs.
134-
uint64_t masked_task_id = 0x0000000f00000000 | task_id;
143+
uint64_t masked_task_id = TASK_MASK | task_id;
135144

136145
// If we already had a thread for this Task in the last stop, re-use it.
137146
if (ThreadSP old_thread = old_thread_list.FindThreadByID(masked_task_id);

lldb/test/API/lang/swift/async/formatters/task/name/TestSwiftTaskName.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def test_summary_contains_name(self):
1313
lldbutil.run_to_source_breakpoint(
1414
self, "break outside", lldb.SBFileSpec("main.swift")
1515
)
16-
self.expect("v task", patterns=[r'"Chore" id:[1-9]\d*'])
16+
self.expect("v task", patterns=[r'"Chore" id:[1-9]'])
1717

1818
@swiftTest
1919
@skipIfLinux # rdar://151471067
@@ -22,4 +22,4 @@ def test_thread_contains_name(self):
2222
_, _, thread, _ = lldbutil.run_to_source_breakpoint(
2323
self, "break inside", lldb.SBFileSpec("main.swift")
2424
)
25-
self.assertRegex(thread.name, r"Chore \(Task [1-9]\d*\)")
25+
self.assertRegex(thread.name, r"Chore \(Task [1-9]\)")

lldb/test/API/lang/swift/async/queues/TestSwiftPluginQueues.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def test(self):
1919
self, "BREAK HERE", source_file
2020
)
2121

22-
self.assertRegex(thread.GetName(), r"^Task [1-9]\d*$")
22+
self.assertRegex(thread.GetName(), r"^Task [1-9]$")
2323

2424
queue_plugin = self.get_queue_from_thread_info_command(False)
2525
queue_backing = self.get_queue_from_thread_info_command(True)

0 commit comments

Comments
 (0)