Commit Graph

139 Commits

Author SHA1 Message Date
Konrad `ktoso` Malawski
92ead521b8 [Concurrency] Fix swift-inspect and remote mirror build (#79715) 2025-03-04 07:04:42 +09:00
Alejandro Alonso
c62e851e38 Implement RemoteInspection support for Builtin.FixedArray 2025-01-08 10:37:17 -08:00
Mike Ash
890c8adeeb [RemoteMirror] Remove legacy interop headers.
It's no longer useful to interface with older Remote Mirror libraries, so remove the legacy interop headers that helped out with that.
2024-02-22 09:42:47 -05:00
Ben Troller
bb3c7f5ee8 [RemoteMirror] Allow clients to specify whether Obj-C interop is enabled.
rdar://119570103
2024-01-26 13:11:10 -08:00
Mike Ash
246e6d169f Merge pull request #70598 from mikeash/fix-swift-inspect-attribute
[RemoteMirror] Use __attribute__((deprecated)) instead of [[deprecated]].
2024-01-05 19:23:07 -05:00
Mike Ash
679db9af4e [RemoteMirror] Use __attribute__((deprecated)) instead of [[deprecated]].
Use __attribute__((deprecated)) in SwiftRemoteMirror.h as it needs to be includable from C.
2024-01-02 13:10:43 -05:00
Rose
873a423da6 Some methods swap the number of elements and the size arguments
For calloc, the variable denoting the of elements comes first,
then the variable denoting the size of each element. However, both
arguments are swapped when calling this function in many places in this codebase.
2023-12-23 11:00:31 -05:00
Emre Celebi
b6f77a46be [swift-inspect] Add an option to print mangled names while dumping generic metadata. 2023-10-30 23:39:42 -07:00
Josh Soref
871634b9f3 Spelling include (#42616)
* spelling: accessible

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: are

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: assume

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: attempt

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: children

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: convenience

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: creation

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: default

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: dereference

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: deserialization

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: embedded

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: enriched

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: excluding

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: for

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: global

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: guarantee

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: initialization

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: initialize

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: label

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: lifting

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: mangled

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: metadata

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: minimum

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: offset

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: only

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: otherwise

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: output

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: overall

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: parameter

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: passed

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: performance

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: referenced

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: standard

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: syntax

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: that

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: the

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: trivia

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: truncate

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: undesirable

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: uniformly

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: uninitialized

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: value

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: verification

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

Co-authored-by: Josh Soref <jsoref@users.noreply.github.com>
2022-04-25 09:00:59 -07: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
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
Tim Kientzle
4d91b45988 [RemoteMirror] Get spare bit info from reflection records (#40906)
This adds a new reflection record type carrying spare bit information for multi-payload enums.

The compiler includes this for any type that might need it in order to accurately reflect the contents of the enum. The RemoteMirror library will use this if present to determine how to project the contents of the enum. If not present (for example, in older binaries), the RemoteMirror library falls back on an internal calculation of the spare bitmask.

A few notes:
 * The internal calculation is not perfect.  In particular, it does not support MPEs that contain other enums (e.g., optionals).  It should accurately refuse to project any MPE that it does not correctly support.
 * The new reflection field is designed to be expandable; this might someday avoid the need for a new section.

Resolves rdar://61158214
2022-02-21 17:06:14 -08: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
2128a44ed8 [RemoteMirror] Bump swift_reflection_libraryVersion to 3.
This indicates the presence of the fix for the async task slab size calculation in f3493bf149.

rdar://87607280
2022-01-20 16:57:34 -05:00
Mike Ash
cf3c131e7c [Reflection] Add API for inspecting async task allocation slabs.
We remove the existing `swift_reflection_iterateAsyncTaskAllocations` API that attempts to provide all necessary information about a tasks's allocations starting from the task. Instead, we split it into two pieces: `swift_reflection_asyncTaskSlabPointer` to get the first slab for a task, and `+swift_reflection_asyncTaskSlabAllocations` to get the allocations in a slab, and a pointer to the next slab.

We also add a dummy metadata pointer to the beginning of each slab. This allows tools to identify slab allocations on the heap without needing to locate every single async task object. They can then use `swift_reflection_asyncTaskSlabAllocations` on such allocations to find out about the contents.

rdar://82549631
2021-11-18 14:15:25 -05:00
Saleem Abdulrasool
3c9c564eba Revert "[Reflection] Add API for inspecting async task allocation slabs." 2021-11-17 18:47:13 -08:00
Mike Ash
7c7dc5d5b3 [Reflection] Add API for inspecting async task allocation slabs.
We remove the existing `swift_reflection_iterateAsyncTaskAllocations` API that attempts to provide all necessary information about a tasks's allocations starting from the task. Instead, we split it into two pieces: `swift_reflection_asyncTaskSlabPointer` to get the first slab for a task, and `+swift_reflection_asyncTaskSlabAllocations` to get the allocations in a slab, and a pointer to the next slab.

We also add a dummy metadata pointer to the beginning of each slab. This allows tools to identify slab allocations on the heap without needing to locate every single async task object. They can then use `swift_reflection_asyncTaskSlabAllocations` on such allocations to find out about the contents.

rdar://82549631
2021-11-11 16:58:14 -05:00
Mike Ash
d959b3dd70 [Reflection] Fix iterateAsyncTaskAllocations again.
We were missing a Status field. The reflect_task test didn't catch this becasue it was reading LastAllocation as FirstSlab, which still worked well enough in that context.

rdar://81427584
2021-08-05 13:40:09 -04:00
Alastair Houghton
96dce956e8 [RemoteMirror] Add swift_reflection_interop_projectEnumValue()
Added a counterpart to the swift_reflection_projectEnumValue() API for the
legacy interop support in SwiftRemoteMirrorLegacyInterop.h.

Also updated the test to use it to extract information from an enum.

rdar://62128103
2021-07-09 13:19:53 +01:00
Mike Ash
c0e6e1d878 [Reflection] Fix iterateAsyncTaskAllocations.
Fix the declaration of AsyncTask and add a test for iterateAsyncTaskAllocations. Reflection's declaration of AsyncTask had fallen out of sync with the real thing. The test that was supposed to catch this was never actually committed, oops.

Add a swift_reflection_libraryVersion variable to Remote Mirror to indicate the presence of this fix. In the future, the value can be incremented to signal the presence of other changes that can't otherwise be detected.

rdar://80035307
2021-07-02 17:33:20 -04:00
Alastair Houghton
eb68120112 [RemoteMirror] Add new API for getting the type descriptor address.
This will allow the heap tool to work out which binary a dynamically allocated
class comes from, by looking up its nominal type descriptor address and then
seeing which binary contains that.

Fixes rdar://65742351.
2021-06-17 10:50:21 +01:00
Augusto Noronha
f41d192b48 Implement projectExistentialAndUnwrapClass
Implement a version of projectExistential tailored for LLDB. There are 2
differences when projecting existentials for LLDB:

1 - When it comes to existentials, LLDB stores the address of the error
    pointer, which must be dereferenced.
2 - When the existential wraps a class type, LLDB expects the address
    returned is the class instance itself and not the address of the
    reference.

This patch also adapts the swift reflection test machinery to test
projectExistentialAndUnwrapClass as well. This is done by exposing
the new functionality from swift reflection test.  It is tested in
existentials.swift, and ensures that the typeref information is
exactly the same as what is expected from projectExistential,
except the out address.

(cherry picked from commit 55e971e06750c3ba29722d558cc5400298f6bdaf)
2021-06-16 08:54:50 -03:00
Mike Ash
31f68b1687 [RemoteMirror] Add a call for iterating over the allocations belonging to an AsyncTask.
rdar://72907056
2021-02-11 17:14:38 -05:00
Augusto Noronha
3cb8f9b6fc Add entrypoints to the runtime that exposes metadata necessary for reflection tests on Linux (#32339) 2020-07-24 15:26:15 -07:00
Mike Ash
b65d2b5f99 [Reflection][swift-inspect] Add a command for dumping metadata cache nodes. 2020-07-15 14:01:49 -04:00
Mishal Shah
6336b14db4 [Apple Silicon] [In-process memory reader] Adjust low-bits computation for arm64 macOS 2020-07-02 18:32:23 -07:00
Mike Ash
3fcf86ac01 [Reflection][swift-inspect] Show tag names when dumping raw metadata allocations. 2020-06-17 11:31:12 -04:00
Mike Ash
6527a216fb Merge pull request #32244 from mikeash/metadata-allocation-backtrace-inspection
[Runtime][Reflection][swift-inspect] Add facilities for tracking and examining backtraces for metadata allocations.
2020-06-12 12:50:52 -04: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
Anthony Latsis
9fd1aa5d59 [NFC] Pre- increment and decrement where possible 2020-06-01 15:39:29 +03:00
Mike Ash
aea7d03063 [Reflection] Remove useless TaggedUnion.h include. Comment swift_metadata_allocation_tag. 2020-05-29 08:31:04 -07:00
Michael Gottesman
404867eee7 [build-script] Convert swiftdt to be a swiftpm project that is built via a build-script product. 2020-05-29 08:31:03 -07:00
Mike Ash
88046363f1 Minor cleanup of initial swiftdt work. 2020-05-29 08:31:03 -07:00
Mike Ash
3a498cace5 [RemoteMirror] Add comments to the new APIs and types.
rdar://problem/55481578
2020-05-29 08:31:03 -07:00
Mike Ash
d9805ca4eb [Reflection] Add error messages to the new Remote Mirror calls and plumb them through swiftdt.
rdar://problem/55481578
2020-05-29 08:31:03 -07:00
Mike Ash
df5580bcfc [Tools] Move metadata dumping into swiftdt, have Remote Mirror just iterate and inspect.
rdar://problem/55481578
2020-05-29 08:31:03 -07:00
Mike Ash
342cbbea97 [Tools] Add rudimentary command parsing to swiftdt.
rdar://problem/55481578
2020-05-29 08:31:03 -07:00
Mike Ash
22cfe461ec [Tools] Super rough draft of swiftdt dumping MetadataAllocator contents.
rdar://problem/55481578
2020-05-29 08:31:03 -07:00
Mike Ash
98c2a35d77 [Tools] Get a first pass of swiftdt conformance cache dumping up and running.
rdar://problem/55481578
2020-05-29 08:31:03 -07:00
Mike Ash
7103ee8b8d [Tools] Start hooking up swiftdt to Remote Mirror.
rdar://problem/55481578
2020-05-29 08:31:02 -07:00
Mike Ash
a317b8737a Merge pull request #30739 from mikeash/remote-mirror-fix-ownsaddress
[Reflection] Fix the ownsAddress function to claim heap-allocated Metadatas
2020-04-01 14:46:49 -04:00
tbkka
3c8fde7885 Implement MultiPayloadEnum support for projectEnumValue (#30635)
This code rearchitects and simplifies the projectEnumValue support by
introducing a new `TypeInfo` subclass for each kind of enum, including trivial,
no-payload, single-payload, and three different classes for multi-payload enums:

* "UnsupportedEnum" that we don't understand.  This returns "don't know" answers for all requests in cases where the runtime lacks enough information to accurately handle a particular enum.

* MP Enums that only use a separate tag value.  This includes generic enums and other dynamic layouts, as well as enums whose payloads have no spare bits.

* MP Enums that use spare bits, possibly in addition to a separate tag.  This logic can only be used, of course, if we can in fact compute a spare bit mask that agrees with the compiler.

The final challenge is to choose one of the above three handlings for every MPE.  Currently, we do not have an accurate source of information for the spare bit mask, so we never choose the third option above.  We use the second option for dynamic MPE layouts (including generics) and the first for everything else.

TODO: Once we can arrange for the compiler to expose spare bit mask data, we'll be able to use that to drive more MPE cases.
2020-03-31 15:12:44 -07:00
Mike Ash
5da118eef2 [Reflection] Fix the ownsAddress function to claim heap-allocated Metadatas.
ownsAddress was a simple range check on images, but that won't find Metadatas that get allocated on the heap. If an address isn't found, try reading it as a Metadata and doing a range check on the type context descriptor too.

rdar://problem/60981575
2020-03-31 16:49:56 -04:00
Mike Ash
15468ee70a [RemoteMirror] Remove C++isms from interop header and clean up.
* Change nullptr to NULL.
* Change bool to int.
* Fix missing DataLayout parameter in createReflectionContext.
* Silence unused parameter warnings in the minimalDataLayoutQueryFunctions.

rdar://problem/59909982
2020-03-23 13:53:35 -04:00
Mike Ash
308695b7f3 [RemoteMirror] Add copyDemangledNameForTypeRef to interop header.
rdar://problem/59909982
2020-03-23 13:53:35 -04:00
Mike Ash
e05720cd09 [RemoteMirror] Add a call to get the demangled name for a typeref.
rdar://problem/59909982
2020-03-23 13:53:35 -04:00
Kuba (Brecka) Mracek
ab6533a40f Merge branch 'master' into mracek/arm64e 2020-03-06 15:07:01 -08:00
tbkka
0d361bd3ea Teach RemoteMirror how to project enum values (#30161)
Teach RemoteMirror how to project enum values

This adds two new functions to the SwiftRemoteMirror
facility that support inspecting enum values.

Currently, these support non-payload enums and
single-payload enums, including nested enums and
payloads with struct, tuple, and reference payloads.
In particular, it handles nested `Optional` types.

TODO: Multi-payload enums use different strategies for
encoding the cases that aren't yet supported by this
code.

Note: This relies on information from dataLayoutQuery
to correctly decode invalid pointer values that are used
to encode enums.  Existing clients will need to augment
their DLQ functions before using these new APIs.

Resolves rdar://59961527

```
/// Projects the value of an enum.
///
/// Takes the address and typeref for an enum and determines the
/// index of the currently-selected case within the enum.
///
/// Returns true iff the enum case could be successfully determined.
/// In particular, note that this code may fail for valid in-memory data
/// if the compiler is using a strategy we do not yet understand.
SWIFT_REMOTE_MIRROR_LINKAGE
int swift_reflection_projectEnumValue(SwiftReflectionContextRef ContextRef,
                                      swift_addr_t EnumAddress,
                                      swift_typeref_t EnumTypeRef,
                                      uint64_t *CaseIndex);

/// Finds information about a particular enum case.
///
/// Given an enum typeref and index of a case, returns:
/// * Typeref of the associated payload or zero if there is no payload
/// * Name of the case if known.
///
/// The Name points to a freshly-allocated C string on the heap.  You
/// are responsible for freeing the string (via `free()`) when you are finished.
SWIFT_REMOTE_MIRROR_LINKAGE
int swift_reflection_getEnumCaseTypeRef(SwiftReflectionContextRef ContextRef,
                                        swift_typeref_t EnumTypeRef,
                                        unsigned CaseIndex,
                                        char **CaseName,
                                        swift_typeref_t *PayloadTypeRef);
```


Co-authored-by: Mike Ash <mikeash@apple.com>
2020-03-06 13:17:40 -08:00
Kuba Mracek
84c4864911 [arm64e] Add Swift compiler support for arm64e pointer authentication 2020-02-27 16:10:31 -08:00
Max Desiatov
67297904ac [WebAssembly] Add ifdefs for the WASI target 2020-02-08 07:37:10 +00:00