Skip to content

Commit 284b674

Browse files
committed
[Runtime] Improve dump() for Metadata and (Type)ContextDescriptor
No functionality change.
1 parent 9bd600e commit 284b674

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

include/swift/ABI/Metadata.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2485,6 +2485,12 @@ struct TargetContextDescriptor {
24852485
? genericContext->getGenericContextHeader().NumParams
24862486
: 0;
24872487
}
2488+
2489+
#ifndef NDEBUG
2490+
LLVM_ATTRIBUTE_DEPRECATED(void dump() const,
2491+
"only for use in the debugger");
2492+
#endif
2493+
24882494
private:
24892495
TargetContextDescriptor(const TargetContextDescriptor &) = delete;
24902496
TargetContextDescriptor(TargetContextDescriptor &&) = delete;
@@ -3649,11 +3655,6 @@ class TargetTypeContextDescriptor
36493655
return cd->getKind() >= ContextDescriptorKind::Type_First
36503656
&& cd->getKind() <= ContextDescriptorKind::Type_Last;
36513657
}
3652-
3653-
#ifndef NDEBUG
3654-
LLVM_ATTRIBUTE_DEPRECATED(void dump() const,
3655-
"Only meant for use in the debugger");
3656-
#endif
36573658
};
36583659

36593660
using TypeContextDescriptor = TargetTypeContextDescriptor<InProcess>;

stdlib/public/runtime/Metadata.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3945,20 +3945,33 @@ void Metadata::dump() const {
39453945
printf("TargetMetadata.\n");
39463946
printf("Kind: %s.\n", getStringForMetadataKind(getKind()).data());
39473947
printf("Value Witnesses: %p.\n", getValueWitnesses());
3948-
printf("Class Object: %p.\n", getClassObject());
3949-
printf("Type Context Description: %p.\n", getTypeContextDescriptor());
3948+
3949+
auto *contextDescriptor = getTypeContextDescriptor();
3950+
printf("Name: %s.\n", contextDescriptor->Name.get());
3951+
printf("Type Context Description: %p.\n", contextDescriptor);
39503952
printf("Generic Args: %p.\n", getGenericArgs());
3953+
3954+
#if SWIFT_OBJC_INTEROP
3955+
if (auto *classObject = getClassObject()) {
3956+
printf("ObjC Name: %s.\n", class_getName(
3957+
reinterpret_cast<Class>(const_cast<ClassMetadata *>(classObject))));
3958+
printf("Class Object: %p.\n", classObject);
3959+
}
3960+
#endif
39513961
}
39523962

39533963
template <>
39543964
LLVM_ATTRIBUTE_USED
3955-
void TypeContextDescriptor::dump() const {
3965+
void ContextDescriptor::dump() const {
39563966
printf("TargetTypeContextDescriptor.\n");
39573967
printf("Flags: 0x%x.\n", this->Flags.getIntValue());
39583968
printf("Parent: %p.\n", this->Parent.get());
3959-
printf("Name: %s.\n", Name.get());
3960-
printf("Access function: %p.\n", static_cast<void *>(getAccessFunction()));
3961-
printf("Fields: %p.\n", Fields.get());
3969+
if (auto *typeDescriptor = dyn_cast<TypeContextDescriptor>(this)) {
3970+
printf("Name: %s.\n", typeDescriptor->Name.get());
3971+
printf("Fields: %p.\n", typeDescriptor->Fields.get());
3972+
printf("Access function: %p.\n",
3973+
static_cast<void *>(typeDescriptor->getAccessFunction()));
3974+
}
39623975
}
39633976

39643977
template<>

0 commit comments

Comments
 (0)