Commit Graph

140 Commits

Author SHA1 Message Date
Saleem Abdulrasool
9fb9561f67 swift-inspect: clean up incorrect casts introduced in #66973
Clean up some casts that would cause warnings on Windows introduced in
PR #66973.  Rewrite some of the path computation for the DLL path to
avoid some unnecessary conversions.  Split out some of the merged guards
to allow for split diagnostic emissions.
2023-07-17 09:51:38 -07:00
Hiroshi Yamauchi
af890f3cbf Improve the dump-arrays performance on Windows
Use the HeapWalk API for heap iteration instead of the
Heap32First/Next API, which was known to be slow. Since HeapWalk only
works locally, it requires using a remote thread and a DLL.
2023-07-14 16:13:10 -07:00
Josh Soref
9e54b97e4f Spelling tools swift inspect (#58559) 2022-05-27 22:07:24 -07:00
Saleem Abdulrasool
ebf1cec6a6 swift-inspect: update instructions for Windows
Remove the reference to `DEVELOPER_DIR` and update the instructions to
actually be usable with a released snapshot (and official releases).
The development setup should mimic the actual layout further and is a
separate issue.  This requires a new snapshot with
apple/swift-installer-scripts#128 included.
2022-05-02 08:22:18 -07:00
Daniel Duan
3dfc40898c [NFC] Remove Python 2 imports from __future__ (#42086)
The `__future__` we relied on is now,  where the 3 specific things are
all included [since Python 3.0](https://docs.python.org/3/library/__future__.html):

* absolute_import
* print_function
* unicode_literals
* division

These import statements are no-ops and are no longer necessary.
2022-04-13 14:01:30 -07:00
Mike Ash
43df54caee [swift-inspect] Support forking corpses and self-inspection of the swift-inspect process on Darwin.
Support inspecting the swift-inspect process itself. `pidFromHint` skips the process it's in, so we manually check the requested name against `argv[0]` as a special case.

Add a `--fork-corpse` flag which uses `task_generate_corpse` on the target task before inspecting it. This allows the target to keep running while we inspect it, and also works around a bug when self-inspecting.
2022-03-22 16:30:16 -04:00
Mike Ash
ae2b5140ed [RemoteMirror][swift-inspect] Decode locks in priority-escalation concurrency runtime.
When possible, decode the DrainLock/ExecutionLock fields of tasks and actors in concurrency runtimes built with priority escalation, and show the corresponding thread info in swift-inspect output.

We weren't properly decoding actor flags previously, so fix that up as well and have Remote Mirror split them out into separate fields so clients don't have to. We were missing the Job Storage field from the definition of DefaultActorImpl in RuntimeInternals.h, fix that so we actually read the right data.

rdar://88598003
2022-03-18 15:41:16 -04:00
Mike Ash
9fd97d5b52 Merge pull request #41676 from mikeash/swift-inspect-concurrency-flags
[swift-inspect][RemoteMirror] Decode job/task/actor flags.
2022-03-16 10:21:40 -04:00
Mike Ash
5fd87a8ee3 [swift-inspect][RemoteMirror] Decode job/task/actor flags.
Have RemoteMirror internally decode these flags fields and return them as separate fields in the task/actor info. Handle the structures both with and without task escalation support.

Also show when a task is the current task on a thread in swift-inspect's task listing.

rdar://88598003
2022-03-14 16:20:05 -04:00
Mike Ash
4b85670ffc [swift-inspect] Fix some missing type conversions when targeting watchOS. 2022-03-04 13:56:12 -05:00
Mike Ash
bf4fbdc43a [Runtime] Tiny fix for swift-inspect, let -> var. 2022-03-02 17:00:00 -05:00
Mike Ash
282b8125c9 Merge pull request #41620 from mikeash/fix-swift-inspect-darwin
[swift-inspect] Fix the swift-inspect build on Darwin.
2022-03-02 16:34:04 -05:00
Mike Ash
e29434d4de [swift-inspect] Fix the swift-inspect build on Darwin.
We had a few typos and such from the recent reorganization.
2022-03-02 14:29:35 -05:00
Saleem Abdulrasool
18ec9bffc1 swift-inspect: enable dump-arrays on Windows
Hoist `iterateHeaps` into the `RemoteProcess` protocol, requiring an
implementation on all platforms.  If the platform is unable to implement
heap traversal, it would be possible to simply leave the callback
uncalled.

Be more careful about memory queries, we may receive invalid memory
addresses.
2022-02-25 14:55:18 -08:00
Saleem Abdulrasool
21edf9c322 swift-inspect: more typo/correctness fixes
This cleans up the DumpArray operation and fixes an unintentional,
undesirable change to the heap iteration on Darwin.
2022-02-24 11:04:20 -08:00
Saleem Abdulrasool
4a64b9f8f8 swift-inspect: add some documentation
This adds some documentation about swift-inspect and how to build it on
Windows, which requires additional flags to locate the SwiftRemoteMirror
library from the toolchain.
2022-02-24 08:34:50 -08:00
Saleem Abdulrasool
7f789ba319 swift-inspect: port to windows
This adds an initial port to Windows which allows inspection of the
processes.  It is not possible to port `dump-arrays` or
`dump-concurrency` due to the need to iterate the heap.  This still
allows for gaining some insight into the metadata and protocol caches.
2022-02-21 08:59:27 -08:00
Saleem Abdulrasool
f085f2b42f swift-inspect: fix all the typos/correctness issues
Fix the many typos and missing `)` instances.  Replace the inline array
removal with explicit duplication due to the behaviour of `#if`.  This
allows the tool to build after the changes for the refactoring.
2022-02-20 15:58:37 -08:00
Saleem Abdulrasool
eef3a8f60a swift-inspect: restructure the project for porting
This restructures and refactors the project to split up the
implementation into smaller fragments.  The majority of the operations
are portable: the ones which are not require iterating the heap
allocations which is not guaranteed to be a portable operation.
Additionally, the `Inspector` class is renamed into `RemoteProcess`
which is also converted to a protocol to allow adding in an
implementation for other targets.  The inspection operations are split
off into individual files to make it easier to follow.  Take the
opportunity to use `@main` for the entry point.
2022-02-18 12:58:11 -08:00
Mike Ash
f829167882 [swift-inspect] Fix errors when targeting 32-bit.
The C APIs are somewhat inconsistent about what kind of integers they use, so we need a bunch of conversions when targeting 32-bit.
2022-02-08 11:34:37 -05:00
Mike Ash
a82ea120a4 [RemoteMirror][swift-inspect] Add a command to inspect the state of the 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
2022-02-04 09:28:32 -05:00
Mike Ash
9fa76e2f4f [swift-inspect] Add a command to dump information about allocated arrays in the target process. 2021-11-04 16:15:15 -04:00
Arnold Schwaighofer
3dfede7482 Remove fatalError calls 2021-10-28 09:18:00 -07:00
Arnold Schwaighofer
f0c864063e Print whether the metadata is a _ContiguousArrayStorage with a class element type 2021-10-28 07:59:44 -07:00
Arnold Schwaighofer
28b53dec31 Use the utility function to add the reflection info from loaded images 2021-10-28 07:58:53 -07:00
Arnold Schwaighofer
86c9407cba Add a utility function to Inspector to load the reflection metadata from
loaded images
2021-10-28 07:58:53 -07:00
Doug Gregor
9a8847dd4f [swift-inspect] Make sure to initialize backtrace flags.
This eliminates a compilation error with Swift 5.5 and the latest
argument parser library.
2021-08-31 09:56:50 -07:00
Mike Ash
ecd6d4ddec Add a new ConcurrentReadableHashMap type. Switch the protocol conformance cache
to use it.

ConcurrentReadableHashMap is lock-free for readers, with writers using a lock to
ensure mutual exclusion amongst each other. The intent is to eventually replace
all uses ConcurrentMap with ConcurrentReadableHashMap.

ConcurrentReadableHashMap provides for relatively quick lookups by using a hash
table. Rearders perform an atomic increment/decrement in order to inform writers
that there are active readers. The design attempts to minimize wasted memory by
storing the actual elements out-of-line, and having the table store indices into
a separate array of elements.

The protocol conformance cache now uses ConcurrentReadableHashMap, which
provides faster lookups and less memory use than the previous ConcurrentMap
implementation. The previous implementation caches
ProtocolConformanceDescriptors and extracts the WitnessTable after the cache
lookup. The new implementation directly caches the WitnessTable, removing an
extra step (potentially a quite slow one) from the fast path.

The previous implementation used a generational scheme to detect when negative
cache entries became obsolete due to new dynamic libraries being loaded, and
update them in place. The new implementation just clears the entire cache when
libraries are loaded, greatly simplifying the code and saving the memory needed
to track the current generation in each negative cache entry. This means we need
to re-cache all requested conformances after loading a dynamic library, but
loading libraries at runtime is rare and slow anyway.

rdar://problem/67268325
2020-08-20 13:05:30 -04:00
Mike Ash
5347179739 [swift-inspect] Consolidate options into OptionGroups shared between subcommands. 2020-07-15 14:01:49 -04:00
Mike Ash
b65d2b5f99 [Reflection][swift-inspect] Add a command for dumping metadata cache nodes. 2020-07-15 14:01:49 -04:00
Mike Ash
5eb226557b [swift-inspect] Support DLQ_GetPtrAuthMask. While we're in there, fix an snprintf warning in ReflectionContext.h 2020-07-10 12:34:25 -04:00
Mike Ash
c925ce502b Merge pull request #32388 from mikeash/swift-inspect-tag-names
[Reflection][swift-inspect] Show tag names when dumping raw metadata allocations.
2020-06-17 16:14:20 -04:00
Mike Ash
3fcf86ac01 [Reflection][swift-inspect] Show tag names when dumping raw metadata allocations. 2020-06-17 11:31:12 -04:00
nate-chandler
e2a20ab864 Merge pull request #32360 from nate-chandler/gardening/ignore-swift-inpect-products
[Gardening] Ignored Package.resolved for swift-inspect.
2020-06-15 09:34:43 -07:00
Nate Chandler
2efde2507d [Gardening] Ignored Package.resolved for swift-inspect.
When running build-script with --swift-inspect, the Package.resolved
file is created in tools/swift-inspect.  Ignore it.
2020-06-12 17:10:25 -07:00
Mike Ash
cd624bf380 [Runtime][Reflection][swift-inspect] Add facilities for tracking and examining backtraces for metadata allocations.
rdar://problem/63674755
2020-06-11 14:49:52 -04:00
Mike Ash
2a55b9d08f Fix python lint errors. 2020-05-30 14:04:32 -04:00
Ben Cohen
b3a5cb7550 Separate raw metadata and generic metadata dump commands 2020-05-29 10:55:36 -07:00
Ben Cohen
23ebf78e0d Add copywrite headers 2020-05-29 08:55:02 -07:00
Ben Cohen
49cbf9788f Rename swiftdt to swift-inspect 2020-05-29 08:31:04 -07:00