Commit Graph

102 Commits

Author SHA1 Message Date
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
John McCall
0fb407943f [NFC] Rename swift_runtime_unreachable to swift_unreachable and make it use LLVM's support when available. 2020-10-03 02:54:56 -04:00
adrian-prantl
4247b6008e Merge pull request #33417 from adrian-prantl/55412920
Add a callback to swift::reflection::MemoryReader that allows LLDB to…
2020-09-08 09:56:21 -07:00
Mike Ash
50ea66d1d9 Merge pull request #33585 from mikeash/type-lookup-error-reporting
Add error reporting when looking up types by demangled name.
2020-08-28 17:42:47 -04:00
Mike Ash
fd6922f92d Add error reporting when looking up types by demangled name. 2020-08-28 14:43:51 -04:00
Mike Ash
9962f799b7 [RemoteMirror] Fix potential uninitialized data access in convertChild.
The else branch of the type checking code just does assert(false). When asserts are off, the code will fall through and access the uninitialized FieldInfo variable. Instead, return something sensible for this error case.
2020-08-26 11:46:13 -04:00
Adrian Prantl
4b9cf31ba0 Add a callback to swift::reflection::MemoryReader that allows LLDB to provide
swift::reflection::TypeInfo for (Clang-)imported non-Objective-C types. This is
needed to reflect on the size mixed Swift / Clang types, when no type metadata
is available for the C types.

This is a necessary ingredient for the TypeRef-based Swift context in
LLDB. Because we do not have reflection metadata for pure C types in Swift,
reflection cannot compute TypeInfo for NominalTypeRefs for those types. By
providing this callback, LLDB can supply this information for DWARF, and
reflection can compute TypeInfos for mixed Swift/C types.
2020-08-25 15:19:49 -07: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
c42c8d23c4 [RemoteMirror] Gracefully handle a NULL TypeInfo passed to convertChild.
rdar://problem/64066210
2020-06-29 11:35:25 -04: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
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
7ca1392678 [Reflection] Clean up the ReflectionContext additions.
Move the internal runtime structures into RuntimeInternals.h. Remove leftover methods. Comment the new methods.

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
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
e05720cd09 [RemoteMirror] Add a call to get the demangled name for a typeref.
rdar://problem/59909982
2020-03-23 13:53:35 -04: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
Slava Pestov
2ae049121f Reflection: Fix a compiler warning 2020-02-20 17:19:21 -05:00
Adrian Prantl
ea2b5eced9 Reflection: Implement a TypeRef -> Demangle tree adapter.
To allow more pervasive use of TypeRefs in LLDB, we need a way to build mangled
names from TypeRef pointers to allow round-tripping between TypeRefs and AST
types. The goal is to experiment with making lldb::CompilerType backed by
TypeRefs instead of AST types.

<rdar://problem/55412775>
2020-01-14 17:50:01 -08:00
Ivan Smetanin
dd7d173c97 [stdlib] [reflection] Excise iostream from reflection 2019-10-14 20:28:20 +03:00
Joe Groff
14453147d6 Reflection: Remove StartAddress from ReflectionInfo.
We now get the local/remote mapping from RemoteRef when we need it.
2019-09-26 12:09:52 -07:00
Joe Groff
8c4df3b4c2 Reflection: Traffic in RemoteRefs.
Instead of passing around raw local pointers and references, and spreading
tricky offset arithmetic around with the Local/RemoteAddress fields in
ReflectionInfo, have the TypeRefBuilder code use RemoteRefs everywhere,
which keep the remote/local mapping together in one unit and provide
centralized API for this logic.

This doesn't yet change how code uses the RemoteRef address data to
follow pointers across objects, for things like reading type refs, but
that should be much easier to do after this lands.
2019-09-25 20:28:03 -07:00
Joe Groff
bc3795eb53 Reflection: Remove vestigial Offset fields from ReflectionInfo
These are now always zero, because memory readers handle virtual address mapping.
The `swift_reflection_info_t` structure used by the C RemoteMirror API keeps
its offset fields because it's supposed to be a stable API, but we now assert that
the values are always zero.
2019-09-23 14:32:26 -07:00
Mike Ash
0c2c0eabe5 [RemoteMirror] Rearrange #includes to fix warnings generated from the addition of __weak_import__ to classIsSwiftMask. 2019-04-24 12:56:17 -04:00
Mike Ash
8b0ab1cc49 [RemoteMirror] Mark swift_reflection_classIsSwiftMask as a weak import.
Also have swift-reflection-test check if the symbol exists. This allows swift-reflection-test to work with older Remote Mirror dylibs that don't have it.

rdar://problem/50030805
2019-04-23 11:37:37 -04:00
Saleem Abdulrasool
fbd456b84d SwiftRemoteMirror: repair the windows build
This symbol is meant to be exposed to users of the SwiftRemoteMirror
library which requires that it is explicitly marked with the appropriate
DLL storage on Windows.  This should repair the Windows build.
2019-03-08 07:59:21 -08:00
Mike Ash
fbe990481b [Runtime] Dynamically select the is-Swift bit at runtime on Apple platforms.
Recent Swift uses 2 as the is-Swift bit when running on newer versions, and 1 on older versions. Since it's difficult or impossible to know what we'll be running on at build time, make the selection at runtime.
2019-03-07 10:12:27 -05:00
Saleem Abdulrasool
70a7dda5b1 SwiftRemoteMirror: resolve ambiguity in name lookup
There are `swift::ReflectionContext` and `swift::reflection::ReflectionContext`
which makes the name lookup ambiguous on Windows.  Elaborate the type.
2019-02-19 11:37:03 -08:00
Davide Italiano
0e5fa49b53 [stdlib] Remove dead code in SwiftRemoteMirror. 2018-07-20 12:49:16 -07:00
David Zarzycki
da506fc0f5 [Reflection] NFC: Adopt reference storage type meta-programming macros 2018-06-30 06:44:34 -04:00
Mike Ash
ce0ef072f7 Merge pull request #15395 from mikeash/remotemirror-hide-reflection-sections
[RemoteMirrors] Interop header fixes and library lookup caching.
2018-03-21 14:43:43 -07:00
Kuba (Brecka) Mracek
84e71b8d7a Change the RemoteMirror API to have extensible data layout callback (#15291)
* Change the RemoteMirror API to have extensible data layout callback

* Use DLQ_Get prefix on DataLayoutQueryType enum values

* Simplify MemoryReaderImpl and synthesize minimalDataLayoutQueryFunction
2018-03-16 14:54:04 -07:00
Mike Ash
ac026128d1 [RemoteMirrors] Provide interop function for converting a raw metadata pointer into a swift_metadata_interop_t.
rdar://problem/37538580
2018-03-08 13:25:09 -05:00
Mike Ash
1434fce417 [RemoteMirrors] Switch #ifdef __APPLE__ to #if defined(__APPLE__) && defined(__MACH__) to be more specific about the fact that this code is for MachO. 2018-03-02 11:03:45 -05:00
Mike Ash
83837ccd12 [RemoteMirrors] Clean up some documentation, comments and macros. Add an assert for pointer sizes that don't match what SwiftRemoteMirror.cpp was built with. 2018-03-01 15:39:14 -05:00
Mike Ash
4864e2c4dc [RemoteMirrors] Don't #include the interop header in SwiftRemoteMirror.cpp. 2018-02-28 16:36:31 -05:00
Mike Ash
c059ff2a5c [RemoteMirrors] Fix the ownership check for legacy libraries. The working implementation requires a non-legacy library to be present. Fall back to always saying "yes" otherwise. 2018-02-27 17:06:37 -05:00
Mike Ash
71f1c391ab [RemoteMirrors] Move FreeBytesFunction from an out-parameter on ReadBytesFunction to a function pointer passed in when creating a reflection context. 2018-02-27 12:51:04 -05:00
Mike Ash
7d01c79f57 [RemoteMirrors] Remove a cast from swift_addr_t to uint64_t that didn't compile. 2018-02-27 10:33:39 -05:00
Mike Ash
e4564087af [RemoteMirrors] Move ownsObject into ReflectionContext. 2018-02-27 10:32:32 -05:00
Davide Italiano
7d4b3ae372 [RemoteMirrors] Remove now unused code. 2018-02-26 17:42:29 -08:00
Davide Italiano
ec39bbb08c [RemoteMirrors] Move addImage from stdlib to Reflection. 2018-02-26 17:41:08 -08:00
Mike Ash
6f887475a3 [Reflection] Lots of smaller fixes and API changes due to testing the interop code.
* Remove getPointerSize and getSizeSize functions, replace with a single PointerSize value.
* Remove imageLength parameter from addImage, calculate it internally instead.
* Check remote mirrors libraries' metadata version and reject them if it's too old.
* Shim GetStringLength and GetSymbolAddress for the legacy library since we don't pass the caller's context pointer through directly.
* Actually set the IsLegacy flag in the Library struct.
* Implement ownsObject by tracking each added image's data segment and checking metadata pointers against them. The previous approach didn't work.
2018-02-26 16:56:54 -05:00
Mike Ash
4c7d203574 [Reflection] Implement more interop API calls.
rdar://problem/37538580
2018-02-23 11:47:24 -05:00
Mike Ash
29beaa3126 [Reflection] Track the memory returned from readBytes calls in addImage and free it when destroying the context.
rdar://problem/37538580
2018-02-22 17:17:48 -05:00