Commit Graph

26 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
Adrian Prantl
58c01bef79 [reflection] Generalize the implementation of getInstanceTypeInfo()
This is being indirectly tested by the LLDB testsuite.
2025-02-28 12:35:59 -08:00
Saleem Abdulrasool
d4c2e1cedb Basic: fix a small corner case for ODR violations
When building the runtime we define `SWIFT_RUNTIME`. `swiftCore_EXPORTS`
is only defined when building swiftCore as a shared library. This would
thus allow the ODR violations to appear in a static library form of the
standard library. This was uncovered with the new runtime build system.
2025-01-17 10:41:07 -08:00
Dave Lee
3e05e0bbf4 RemoteInspection: Append ResumeAsyncContext field to AsyncTaskInfo (#78645)
Expose a `Task`'s resume context via the `AsyncTaskInfo` struct.

This will be used by lldb, but since this data is not specific to lldb it seems reasonable to include it generally.
2025-01-15 11:41:41 -08:00
Dave Lee
b8f1876d0d RemoteInspection: Handle ObjC typerefs in computeUnalignedFieldStartOffset (#76678)
This change is part of a fix for a regression that wasn't noticed because lldb has a 
fallback to using ASTContexts when type metadata resolution fails.

For any Swift class that directly or indirectly inherits from an ObjC class (such as 
`NSObject`, `NSView`, etc), the function `computeUnalignedFieldStartOffset` will fail 
to compute the start offset. To compute the start offset, it traverses the parent 
classes and uses their sizes. Once the traversal reaches an ObjC class, the 
RemoteInspection does not know the size. The fix here is to get the size from the 
`TypeInfo` returned by the external `TypeInfoProvider` (which in LLDB is 
`LLDBTypeInforProvider`).

Depended on by https://github.com/swiftlang/llvm-project/pull/9320
2024-09-27 11:12:06 -07:00
Tim Kientzle
05c74e0d90 Revert "Merge pull request #74394 from tbkka/tbkka-remotemirror-no-more-mpe-metadata-partial"
This reverts commit a1708ef8b1, reversing
changes made to b5930625be.
2024-06-14 15:32:39 -07:00
Tim Kientzle
c20ef6de2a Remove RemoteInspection code to fetch no-longer-used reflection metadata
without relying on spare bit information in the reflection metadata
(which was added in #40906).  As a result, we can remove the
code from #40906.

This is the first step in such removal.  It removes the RemoteMirror
code for looking up such metadata.  It leaves behind:

* Sufficient stubs for LLDB to continue to build.  Once LLDB is updated, these stubs can be removed as well.

* The compiler code to emit such metadata.  This allows new binaries to still reflect MPEs on older runtimes.  This will need to be kept for a transitional period.
2024-06-13 09:34:43 -07:00
Augusto Noronha
03b422b810 [RemoteInspection] Add TypeInfoProvider to ReflectionContext function
Pass in a TypeInfoProvider parameter to computeUnalignedFieldStartOffset
because it calls getClassInstanceTypeInfo which might need the external
type info provider to find clang types.

rdar://128141491
2024-05-15 14:43:45 -07:00
Alastair Houghton
f5b1ef77a6 [RemoteInspection] Change "return false" to "return {}".
There are a number of instances in `ReflectionContext.h` where we
are doing `return false` with an `std::optional<...>` where it seems
we really mean to return an empty optional instead.

(The way to do this is either `return {}` or `return std::nullopt`.)

rdar://123504095
2024-04-29 10:48:23 +01:00
Alastair Houghton
bc64f6df9f [RemoteInspection] Add a big comment to ReflectionContext.h.
Add a comment to ReflectionContext.h explaining the situation regarding
`SHF_GNU_RETAIN` and the reflection metadata sections.

rdar://123504095
2024-04-29 10:48:22 +01:00
Alastair Houghton
cb4fd88ece [RemoteInspection] Use bool instead of !!.
Since this is adjacent to a `!=` operator, explicitly using `bool` seems clearer.

Co-authored-by: Evan Wilde <etceterawilde@gmail.com>
2024-04-29 10:48:22 +01:00
Alastair Houghton
c9dcee2774 [RemoteInspection] Update ReflectionContext to cope with multiple sections.
When linking with `gold`, we can end up with two separate sections
for each of the reflection sections; this happens because `swiftrt.o`
declares them with `SHF_GNU_RETAIN` set (to stop them from vanishing
when section GC is enabled), but if the compiler is set to allow the
reflection information to be stripped then *it* will generate them
*without* `SHF_GNU_RETAIN`.

The other Linux linkers will coalesce the two sections and leave the
`SHF_GNU_RETAIN` flag set, but `gold` does not, and adds both of them
separately to the output.

The upshot is that we want `ReflectionContext` to look for both the
retained and non-retained sections and read the data from both of
them.

rdar://123504095
2024-04-29 10:48:22 +01:00
Mike Ash
545441e2d1 [RemoteInspection] Ignore MetadataSource records with NULL source pointer.
We'd crash on a call to getKind(). Ignore them instead by returning false from isMetadataSourceReady. If this causes getClosureContextInfo to fail to make forward progress, then it will in turn fail and return nullptr to its caller.

rdar://126866747
2024-04-23 12:02:38 -04:00
Ben Barham
ef8825bfe6 Migrate llvm::Optional to std::optional
LLVM has removed llvm::Optional, move over to std::optional. Also
clang-format to fix up all the renamed #includes.
2024-02-21 11:20:06 -08:00
Adrian Prantl
09da198c93 Add ExternalTypeInfoProvider the the key of the ReflectionContext TypeInfo cache
This change is analogous to the TypeInfo cache in TypeLowering, which does the
exact same thing. In LLDB the ExternalTypeInfoProvider may gain new information
throughout the life of a process, and more importantly, it may return
context-dependent results.

rdar://122432501
2024-02-09 17:24:04 -08:00
Augusto Noronha
e2d516f3c9 Merge pull request #71328 from augusto2112/instance-start-typeref
Implement ReflectionContext::readInstanceStartFromTypeRef
2024-02-02 18:31:05 -08:00
Augusto Noronha
18a80f8941 Implement computeUnalignedFieldStartOffset
Implement computeUnalignedFieldStartOffset as an alternative way to
finding out the start of the fields that belong to the instance when
reading the field's start from binary is not possible (for example,
embedded Swift doesn't emit any reflection metadata on the binary).
2024-02-02 15:38:58 -08:00
Rick van Voorden
f8ae46b3f3 [inclusive-language] changed sanity to soundness 2024-01-25 18:18:02 -08:00
Augusto Noronha
f09f518abc Add interface for lookup up of externally stored type descriptors
Currently, TypeRefBuilder knows how to parse type descriptors from
reflection metadata. We aim to store the same information that lives
in type descriptors externally, as an effort to support embedded Swift
debugging. In order to take advantage of all of the existing type
information parsing code that exists today in remote mirrors, add an
interface for external lookup of type descriptors, and replace all the
usages of type descriptors with their generic counterpart (this patch
only adds support for builtin descriptors, but follow up patches will
add support for other descriptor types).
2023-11-08 15:57:05 -08: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
Mike Ash
238d1cdc6c [Reflection] Look for __AUTH segments as well as __DATA segments.
Some data is stored in __AUTH, which we need to add to our list of data segments so that `ownsAddress` works correctly.

rdar://116363531
2023-10-03 12:54:08 -04:00
Augusto Noronha
5282464876 [NFC] Replace std::unordered_map with llvm::DenseSet in metadata reader 2023-09-12 12:41:41 -07:00
Mike Ash
2faa2d6d37 [Reflection] Improve ownsAddress and metadataIsActor logic.
Separately track text and data segments for ownsAddress. We were previously tracking one range per image, encompassing the range from the start of the image through the end of the data segment. This ends up including a lot of unwanted address space if the two aren't adjacent, as is the case for libraries in the shared cache on Darwin.

This makes metadataIsActor a lot more reliable, as it was previously identifying a lot of garbage as actor metadata due to the supposed descriptor pointer falling in this range.

rdar://113417637
2023-08-07 16:49:39 -04:00
Hiroshi Yamauchi
50ef384f88 Fix the swift-inspect dump-generic-metadata operation.
ReflectionContext::allocationMetadataPointer() was reading the
metadata pointer from a wrong offset because of the out-of-sync struct
layouts and dump-generic-metadata was not working correctly.

This change resync's the layouts and adds a static_assert to verify
that the offsets match between GenericMetadataCacheEntry and
GenericCacheEntry.
2023-06-09 18:33:06 -07:00
Dave Lee
af733e7905 [RemoteInspection] Specify precise return type of RecordTypeInfo (NFC) 2023-04-14 11:18:50 -06:00
Alejandro Alonso
382510fa50 Rename Reflection library to RemoteInspection (#62846) 2023-01-06 13:21:32 -05:00