Skip to content

Commit 62cb20e

Browse files
authored
Merge pull request #25705 from mikeash/more-dump-methods
[Runtime] Add dump() methods to TypeContextDescriptor and EnumDescriptor.
2 parents 1e3c674 + d05a8ca commit 62cb20e

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

include/swift/ABI/Metadata.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3637,6 +3637,11 @@ class TargetTypeContextDescriptor
36373637
return cd->getKind() >= ContextDescriptorKind::Type_First
36383638
&& cd->getKind() <= ContextDescriptorKind::Type_Last;
36393639
}
3640+
3641+
#ifndef NDEBUG
3642+
LLVM_ATTRIBUTE_DEPRECATED(void dump() const,
3643+
"Only meant for use in the debugger");
3644+
#endif
36403645
};
36413646

36423647
using TypeContextDescriptor = TargetTypeContextDescriptor<InProcess>;
@@ -4238,6 +4243,11 @@ class TargetEnumDescriptor final
42384243
static bool classof(const TargetContextDescriptor<Runtime> *cd) {
42394244
return cd->getKind() == ContextDescriptorKind::Enum;
42404245
}
4246+
4247+
#ifndef NDEBUG
4248+
LLVM_ATTRIBUTE_DEPRECATED(void dump() const,
4249+
"Only meant for use in the debugger");
4250+
#endif
42414251
};
42424252

42434253
using EnumDescriptor = TargetEnumDescriptor<InProcess>;

stdlib/public/runtime/Metadata.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3934,6 +3934,10 @@ StringRef swift::getStringForMetadataKind(MetadataKind kind) {
39343934
}
39353935
}
39363936

3937+
/***************************************************************************/
3938+
/*** Debugging dump methods ************************************************/
3939+
/***************************************************************************/
3940+
39373941
#ifndef NDEBUG
39383942
template <>
39393943
LLVM_ATTRIBUTE_USED
@@ -3945,6 +3949,33 @@ void Metadata::dump() const {
39453949
printf("Type Context Description: %p.\n", getTypeContextDescriptor());
39463950
printf("Generic Args: %p.\n", getGenericArgs());
39473951
}
3952+
3953+
template <>
3954+
LLVM_ATTRIBUTE_USED
3955+
void TypeContextDescriptor::dump() const {
3956+
printf("TargetTypeContextDescriptor.\n");
3957+
printf("Flags: 0x%x.\n", this->Flags);
3958+
printf("Parent: %p.\n", this->Parent.get());
3959+
printf("Name: %s.\n", Name.get());
3960+
printf("Access function: %p.\n", getAccessFunction());
3961+
printf("Fields: %p.\n", Fields.get());
3962+
}
3963+
3964+
template<>
3965+
LLVM_ATTRIBUTE_USED
3966+
void EnumDescriptor::dump() const {
3967+
printf("TargetEnumDescriptor.\n");
3968+
printf("Flags: 0x%x.\n", this->Flags);
3969+
printf("Parent: %p.\n", this->Parent.get());
3970+
printf("Name: %s.\n", Name.get());
3971+
printf("Access function: %p.\n", getAccessFunction());
3972+
printf("Fields: %p.\n", Fields.get());
3973+
printf("NumPayloadCasesAndPayloadSizeOffset: 0x%08x "
3974+
"(payload cases: %u - payload size offset: %u).\n",
3975+
NumPayloadCasesAndPayloadSizeOffset,
3976+
getNumPayloadCases(), getPayloadSizeOffset());
3977+
printf("NumEmptyCases: %u\n", NumEmptyCases);
3978+
}
39483979
#endif
39493980

39503981
/***************************************************************************/

0 commit comments

Comments
 (0)