Skip to content

Commit ce1c30b

Browse files
committed
Reflection: Support reading the remote process's isaMask
Also, use the instance layout entry point in swift-reflection-test, so that we can dump the layout of a class instance and not the lowering of the reference value.
1 parent 04f4552 commit ce1c30b

File tree

5 files changed

+44
-1
lines changed

5 files changed

+44
-1
lines changed

include/swift/Reflection/ReflectionContext.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ class ReflectionContext
6565
getBuilder().addReflectionInfo(I);
6666
}
6767

68+
std::pair<bool, StoredPointer> readerIsaMask() {
69+
return getReader().readIsaMask();
70+
}
71+
6872
/// Return a description of the layout of a heap object having the given
6973
/// metadata as its isa pointer.
7074
const TypeInfo *getInstanceTypeInfo(StoredPointer MetadataAddress) {

include/swift/Remote/MetadataReader.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,10 @@ class MetadataReader {
425425
using OwnedCaptureDescriptor =
426426
std::unique_ptr<const CaptureDescriptor, delete_with_free>;
427427

428+
/// Cached isa mask.
429+
StoredPointer isaMask;
430+
bool hasIsaMask = false;
431+
428432
public:
429433
BuilderType Builder;
430434

@@ -456,6 +460,19 @@ class MetadataReader {
456460
return swift::remote::decodeMangledType(Builder, Node);
457461
}
458462

463+
/// Get the remote process's swift_isaMask.
464+
std::pair<bool, StoredPointer> readIsaMask() {
465+
auto address = Reader->getSymbolAddress("swift_isaMask");
466+
if (!address)
467+
return {false, 0};
468+
469+
if (!Reader->readInteger(address, &isaMask))
470+
return {false, 0};
471+
472+
hasIsaMask = true;
473+
return {true, isaMask};
474+
}
475+
459476
/// Given a remote pointer to metadata, attempt to discover its MetadataKind.
460477
std::pair<bool, MetadataKind>
461478
readKindFromMetadata(StoredPointer MetadataAddress) {

include/swift/SwiftRemoteMirror/SwiftRemoteMirror.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ swift_reflection_addReflectionInfo(SwiftReflectionContextRef ContextRef,
5959
swift_reflection_section_t reflstr);
6060

6161

62+
/// Returns a boolean indicating if the isa mask was successfully
63+
/// read, in which case it is stored in the isaMask out parameter.
64+
int
65+
swift_reflection_readIsaMask(SwiftReflectionContextRef ContextRef,
66+
uintptr_t *outIsaMask);
67+
6268
/// Returns an opaque type reference for a metadata pointer, or
6369
/// NULL if one can't be constructed.
6470
swift_typeref_t

stdlib/public/SwiftRemoteMirror/SwiftRemoteMirror.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,15 @@ swift_reflection_addReflectionInfo(SwiftReflectionContextRef ContextRef,
6969
Context->addReflectionInfo(Info);
7070
}
7171

72+
int
73+
swift_reflection_readIsaMask(SwiftReflectionContextRef ContextRef,
74+
uintptr_t *outIsaMask) {
75+
auto Context = reinterpret_cast<NativeReflectionContext *>(ContextRef);
76+
auto isaMask = Context->readIsaMask();
77+
*outIsaMask = isaMask.second;
78+
return isaMask.first;
79+
}
80+
7281
swift_typeref_t
7382
swift_reflection_typeRefForMetadata(SwiftReflectionContextRef ContextRef,
7483
uintptr_t metadata) {

tools/swift-reflection-test/swift-reflection-test.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,12 +410,19 @@ int doDumpHeapInstance(const char *BinaryFilename) {
410410
Info.reflstr);
411411
}
412412

413+
uintptr_t isaMask;
414+
if (!swift_reflection_readIsaMask(RC, &isaMask))
415+
errorAndExit("Couldn't read isa mask");
416+
printf("Parent: isa mask in child address space: 0x%lx\n", isaMask);
417+
418+
isa &= isaMask;
419+
413420
printf("Parent: metadata pointer in child address space: 0x%lx\n", isa);
414421
printf("Decoding type reference ...\n");
415422

416423
swift_typeref_t TR = swift_reflection_typeRefForMetadata(RC, isa);
417424
swift_reflection_dumpTypeRef(TR);
418-
swift_reflection_dumpInfoForTypeRef(RC, TR);
425+
swift_reflection_dumpInfoForMetadata(RC, isa);
419426
}
420427
}
421428

0 commit comments

Comments
 (0)