Skip to content

Commit eb68120

Browse files
committed
[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.
1 parent 6ec0bbd commit eb68120

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

include/swift/Reflection/ReflectionContext.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,16 @@ class ReflectionContext
687687

688688
return false;
689689
}
690-
690+
691+
/// Returns the address of the nominal type descriptor given a metadata
692+
/// address.
693+
StoredPointer nominalTypeDescriptorFromMetadata(StoredPointer MetadataAddress) {
694+
auto Metadata = readMetadata(MetadataAddress);
695+
if (!Metadata)
696+
return 0;
697+
return super::readAddressOfNominalTypeDescriptor(Metadata, true);
698+
}
699+
691700
/// Return a description of the layout of a class instance with the given
692701
/// metadata as its isa pointer.
693702
const TypeInfo *

include/swift/SwiftRemoteMirror/SwiftRemoteMirror.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,13 @@ uintptr_t
136136
swift_reflection_metadataForObject(SwiftReflectionContextRef ContextRef,
137137
uintptr_t Object);
138138

139+
/// Returns the nominal type descriptor given the metadata
140+
SWIFT_REMOTE_MIRROR_LINKAGE
141+
swift_reflection_ptr_t
142+
swift_reflection_metadataNominalTypeDescriptor(SwiftReflectionContextRef ContextRef,
143+
swift_reflection_ptr_t Metadata);
144+
145+
139146
/// Returns an opaque type reference for a class or closure context
140147
/// instance pointer, or NULL if one can't be constructed.
141148
///

stdlib/public/SwiftRemoteMirror/SwiftRemoteMirror.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,13 @@ swift_reflection_metadataForObject(SwiftReflectionContextRef ContextRef,
282282
return *MetadataAddress;
283283
}
284284

285+
swift_reflection_ptr_t
286+
swift_reflection_metadataNominalTypeDescriptor(SwiftReflectionContextRef ContextRef,
287+
swift_reflection_ptr_t MetadataAddress) {
288+
auto Context = ContextRef->nativeContext;
289+
return Context->nominalTypeDescriptorFromMetadata(MetadataAddress);
290+
}
291+
285292
swift_typeref_t
286293
swift_reflection_typeRefForInstance(SwiftReflectionContextRef ContextRef,
287294
uintptr_t Object) {

0 commit comments

Comments
 (0)