8000 [lldb] Fix task ids in task thread names by kastiglione · Pull Request #10940 · swiftlang/llvm-project · GitHub
[go: up one dir, main page]

Skip to content

[lldb] Fix task ids in task thread names #10940

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
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 10000 view
Diff view
10000
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ void OperatingSystemSwiftTasks::Terminate() {
PluginManager::UnregisterPlugin(CreateInstance);
}

/// Mask applied to task IDs to generate thread IDs that to don't conflicts with
/// core thread IDs.
static constexpr uint64_t TASK_MASK = 0x0000000f00000000ULL;

/// A wrapper around ThreadMemory providing lazy name evaluation, as this is
/// expensive to compute for Swift Tasks.
class SwiftTaskThreadMemory : public ThreadMemory {
Expand All @@ -61,8 +65,13 @@ class SwiftTaskThreadMemory : public ThreadMemory {
}

private:
uint64_t GetTaskID() const {
auto thread_id = GetID();
return thread_id & ~TASK_MASK;
}

std::string GetDefaultTaskName() const {
return llvm::formatv("Task {0}", GetID());
return llvm::formatv("Task {0}", GetTaskID());
}

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

if (!task_name->has_value())
return GetDefaultTaskName();
return llvm::formatv("{0} (Task {1})", *task_name, GetID());
return llvm::formatv("{0} (Task {1})", *task_name, GetTaskID());
}

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

// If we already had a thread for this Task in the last stop, re-use it.
if (ThreadSP old_thread = old_thread_list.FindThreadByID(masked_task_id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def test_summary_contains_name(self):
lldbutil.run_to_source_breakpoint(
self, "break outside", lldb.SBFileSpec("main.swift")
)
self.expect("v task", patterns=[r'"Chore" id:[1-9]\d*'])
self.expect("v task", patterns=[r'"Chore" id:[1-9]'])

@swiftTest
@skipIfLinux # rdar://151471067
Expand All @@ -22,4 +22,4 @@ def test_thread_contains_name(self):
_, _, thread, _ = lldbutil.run_to_source_breakpoint(
self, "break inside", lldb.SBFileSpec("main.swift")
)
self.assertRegex(thread.name, r"Chore \(Task [1-9]\d*\)")
self.assertRegex(thread.name, r"Chore \(Task [1-9]\)")
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test(self):
self, "BREAK HERE", source_file
)

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

queue_plugin = self.get_queue_from_thread_info_command(False)
queue_backing = self.get_queue_from_thread_info_command(True)
Expand Down
0