Skip to content

[lldb] Introduce Swift "task info" command #9875

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

Conversation

kastiglione
Copy link

@kastiglione kastiglione commented Jan 24, 2025

Adds language swift task info, which accesses the thread's current Task, and prints the task instance.

This is equivalent to using withUnsafeCurrentTask, but works without expression evaluation. This lets users print the current task, even when there's no Task variable to reference.

@kastiglione kastiglione requested a review from a team as a code owner January 24, 2025 00:13
@kastiglione
Copy link
Author

@swift-ci test

@adrian-prantl
Copy link

I'm impressed by how pretty and useful the assertEqual() output is!

@kastiglione
Copy link
Author

agree!

@kastiglione
Copy link
Author

@swift-ci test macOS

2 similar comments
@kastiglione
Copy link
Author

@swift-ci test macOS

@kastiglione
Copy link
Author

@swift-ci test macOS

@kastiglione
Copy link
Author

@swift-ci test

@kastiglione
Copy link
Author

@swift-ci test

@kastiglione
Copy link
Author

@swift-ci test linux

1 similar comment
@kastiglione
Copy link
Author

@swift-ci test linux

@kastiglione kastiglione force-pushed the dl/lldb-Introduce-Swift-task-info-command branch from fedc00b to 140f2c6 Compare January 29, 2025 23:33
@kastiglione
Copy link
Author

I modified the commit history of this PR's branch so that I could cleanly cherry pick @felipepiovezan's commit a267f0f947abd97f1b5911bfd6a7be83317aed16 (from #9839).

See fedc00b7d8caab509fc7da6b80627a96d5fddb9f for the initial commit history of this PR.

@kastiglione
Copy link
Author

@swift-ci test

@kastiglione
Copy link
Author

@swift-ci test macOS

@@ -2642,30 +2642,32 @@ std::optional<lldb::addr_t> SwiftLanguageRuntime::TrySkipVirtualParentProlog(
return pc_value + prologue_size;
}

std::optional<lldb::addr_t> GetTaskAddrFromThreadLocalStorage(Thread &thread) {
llvm::Expected<lldb::addr_t> GetTaskAddrFromThreadLocalStorage(Thread &thread) {
#if SWIFT_THREADING_USE_DIRECT_TSD

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my own education, what does this mean?

@@ -2643,7 +2705,7 @@ std::optional<lldb::addr_t> SwiftLanguageRuntime::TrySkipVirtualParentProlog(
}

llvm::Expected<lldb::addr_t> GetTaskAddrFromThreadLocalStorage(Thread &thread) {
#if SWIFT_THREADING_USE_DIRECT_TSD
#if !SWIFT_THREADING_USE_RESERVED_TLS_KEYS

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh you flipped the condition later?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The swift::tis_get_key function is available only on Darwin. Using SWIFT_THREADING_USE_RESERVED_TLS_KEYS is to ensure that swift::tls_get_key exists. If that compiler condition is false, then this function (GetTaskAddrFromThreadLocalStorage) will return an error. On Linux and Windows we'll need to figure out how to implement this, where thread_local variables are used instead of TSD.


class TestCase(TestBase):

@skipUnlessDarwin
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this conceptual for the features tested in async/tasks? Or is this a workaround for the Windows test failure linked above? In that case, can we mark it xfail instead, so that it pops up when this is fixed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is specific to this task info command. A thread's current task is stored differently on Darwin, vs other platforms. This PR supports only Darwin, a follow up PR will need to support other platforms.

@kastiglione kastiglione merged commit 4cce7ea into stable/20240723 Jan 31, 2025
2 checks passed
@kastiglione kastiglione deleted the dl/lldb-Introduce-Swift-task-info-command branch January 31, 2025 21:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants