Skip to content

[RemoteMirror][swift-inspect] Add a command to inspect the state of the concurrency runtime. #41160

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 1 commit into from
Feb 4, 2022

Conversation

mikeash
Copy link
Contributor

@mikeash mikeash commented Feb 2, 2022

Most of the new inspection logic is in Remote Mirror. New code in swift-inspect calls the new Remote Mirror functions and formats the resulting information for display.

Specific Remote Mirror changes:

  • Add a call to check if a given metadata is an actor.
  • Add calls to get information about actors and tasks.
  • Add a readObj call to MemoryReader that combines the read and the cast, greatly simplifying code chasing pointers in the remote process.
  • Add a generalized facility to the C shims that can allocate a temporary object that remains valid until at least the next call, which is used to return various temporary arrays from the new calls. Remove the existing lastString and lastChunks member variables in favor of this new facility.

Swift-inspect changes:

  • Add a new dump-concurrency command.
  • Add a new ConcurrencyDumper.swift file with the implementation. The dumper needs to do some additional work with the results from Remote Mirror to build up the task tree and this keeps it all organized.
  • Extend Inspector to query the target's threads and fetch each thread's current task.

Concurrency runtime changes:

  • Add _swift_concurrency_debug variables pointing to the various future adapters. Remote Mirror uses these to provide a better view of a tasks's resume pointer.

A note on testing: I've been testing this manually. Automatic tests are difficult because the remote process inspection calls require root. I plan to work around this by having a swift-inspect mode that can inspect itself without root, either using the current calls (which may be able to inspect the current process without special privileges) or having a separate implemenattion of Inspector that uses in-process calls. That's going to be a bunch more work, though, so I'll do that in a separate PR afterwards.

rdar://88493833

@mikeash
Copy link
Contributor Author

mikeash commented Feb 2, 2022

Here's an example of what this tool prints: https://gist.github.com/mikeash/80750c2f26ee13e5e60fdbc65da2c8c1

@mikeash mikeash requested a review from al45tair February 3, 2022 15:03
@DougGregor
Copy link
Member

Here's an example of what this tool prints: https://gist.github.com/mikeash/80750c2f26ee13e5e60fdbc65da2c8c1

This is AMAZING. It's going to be our best favoritist debugging tool for concurrency runtime issues.

@mikeash
Copy link
Contributor Author

mikeash commented Feb 3, 2022

@swift-ci please test

@swift-ci
Copy link
Contributor

swift-ci commented Feb 3, 2022

Build failed
Swift Test Linux Platform
Git Sha - fb9550c5dca814eb41a7caee8b452178693b7860

@mikeash mikeash force-pushed the swift-inspect-concurrency branch from fb9550c to fea6767 Compare February 3, 2022 21:02
@mikeash
Copy link
Contributor Author

mikeash commented Feb 3, 2022

@swift-ci please test

Copy link
Contributor

@al45tair al45tair left a comment

Choose a reason for hiding this comment

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

A couple of little things to look at, but looking good.

…he concurrency runtime.

Most of the new inspection logic is in Remote Mirror. New code in swift-inspect calls the new Remote Mirror functions and formats the resulting information for display.

Specific Remote Mirror changes:

* Add a call to check if a given metadata is an actor.
* Add calls to get information about actors and tasks.
* Add a `readObj` call to MemoryReader that combines the read and the cast, greatly simplifying code chasing pointers in the remote process.
* Add a generalized facility to the C shims that can allocate a temporary object that remains valid until at least the next call, which is used to return various temporary arrays from the new calls. Remove the existing `lastString` and `lastChunks` member variables in favor of this new facility.

Swift-inspect changes:

* Add a new dump-concurrency command.
* Add a new `ConcurrencyDumper.swift` file with the implementation. The dumper needs to do some additional work with the results from Remote Mirror to build up the task tree and this keeps it all organized.
* Extend `Inspector` to query the target's threads and fetch each thread's current task.

Concurrency runtime changes:

* Add `_swift_concurrency_debug` variables pointing to the various future adapters. Remote Mirror uses these to provide a better view of a tasks's resume pointer.

rdar://85231338
@mikeash mikeash force-pushed the swift-inspect-concurrency branch from fea6767 to a82ea12 Compare February 4, 2022 14:28
@mikeash
Copy link
Contributor Author

mikeash commented Feb 4, 2022

@al45tair Thanks much for the review, pushed fixes now.

@mikeash
Copy link
Contributor Author

mikeash commented Feb 4, 2022

@swift-ci please smoke test

@mikeash mikeash merged commit bd434d4 into swiftlang:main Feb 4, 2022
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