Skip to content

Commit 9b06e78

Browse files
committed
SwiftRemoteMirror: More convenience APIs for dumping
Add convenience functions for dumping the typeinfos via an isa pointer and a typeref.
1 parent 069efee commit 9b06e78

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

include/swift/SwiftRemoteMirror/SwiftRemoteMirror.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,14 @@ bool swift_reflection_projectExistential(SwiftReflectionContextRef ContextRef,
126126
/// Dump a brief description of the typeref as a tree to stderr.
127127
void swift_reflection_dumpTypeRef(swift_typeref_t OpaqueTypeRef);
128128

129+
/// Dump information about the layout of a class instance from its isa pointer.
130+
void swift_reflection_dumpInfoForMetadata(SwiftReflectionContextRef ContextRef,
131+
uintptr_t Metadata);
132+
133+
/// Dump information about the layout for a typeref.
134+
void swift_reflection_dumpInfoForTypeRef(SwiftReflectionContextRef ContextRef,
135+
swift_typeref_t OpaqueTypeRef);
136+
129137
#ifdef __cplusplus
130138
} // extern "C"
131139
#endif

stdlib/public/SwiftRemoteMirror/SwiftRemoteMirror.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,26 @@ void swift_reflection_dumpTypeRef(swift_typeref_t OpaqueTypeRef) {
231231
TR->dump();
232232
}
233233
}
234+
235+
void swift_reflection_dumpInfoForMetadata(SwiftReflectionContextRef ContextRef,
236+
uintptr_t Metadata) {
237+
auto Context = reinterpret_cast<NativeReflectionContext *>(ContextRef);
238+
auto TI = Context->getInstanceTypeInfo(Metadata);
239+
if (TI == nullptr) {
240+
std::cerr << "<null type info>" << std::endl;
241+
} else {
242+
TI->dump();
243+
}
244+
}
245+
246+
void swift_reflection_dumpInfoForTypeRef(SwiftReflectionContextRef ContextRef,
247+
swift_typeref_t OpaqueTypeRef) {
248+
auto Context = reinterpret_cast<NativeReflectionContext *>(ContextRef);
249+
auto TR = reinterpret_cast<const TypeRef *>(OpaqueTypeRef);
250+
auto TI = Context->getTypeInfo(TR);
251+
if (TI == nullptr) {
252+
std::cerr << "<null type info>" << std::endl;
253+
} else {
254+
TI->dump();
255+
}
256+
}

0 commit comments

Comments
 (0)