Skip to content

[Runtime] Add dump() methods to TypeContextDescriptor and EnumDescriptor. #25705

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions include/swift/ABI/Metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -3637,6 +3637,11 @@ class TargetTypeContextDescriptor
return cd->getKind() >= ContextDescriptorKind::Type_First
&& cd->getKind() <= ContextDescriptorKind::Type_Last;
}

#ifndef NDEBUG
LLVM_ATTRIBUTE_DEPRECATED(void dump() const,
"Only meant for use in the debugger");
#endif
};

using TypeContextDescriptor = TargetTypeContextDescriptor<InProcess>;
Expand Down Expand Up @@ -4238,6 +4243,11 @@ class TargetEnumDescriptor final
static bool classof(const TargetContextDescriptor<Runtime> *cd) {
return cd->getKind() == ContextDescriptorKind::Enum;
}

#ifndef NDEBUG
LLVM_ATTRIBUTE_DEPRECATED(void dump() const,
"Only meant for use in the debugger");
#endif
};

using EnumDescriptor = TargetEnumDescriptor<InProcess>;
Expand Down
31 changes: 31 additions & 0 deletions stdlib/public/runtime/Metadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3934,6 +3934,10 @@ StringRef swift::getStringForMetadataKind(MetadataKind kind) {
}
}

/***************************************************************************/
/*** Debugging dump methods ************************************************/
/***************************************************************************/

#ifndef NDEBUG
template <>
LLVM_ATTRIBUTE_USED
Expand All @@ -3945,6 +3949,33 @@ void Metadata::dump() const {
printf("Type Context Description: %p.\n", getTypeContextDescriptor());
printf("Generic Args: %p.\n", getGenericArgs());
}

template <>
LLVM_ATTRIBUTE_USED
void TypeContextDescriptor::dump() const {
printf("TargetTypeContextDescriptor.\n");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks awesome! My only question is why you are using this in only some of the places.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I banged these out while debugging a problem and figured I should add them in. We should definitely make more though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No that isn't what I meant. I meant in some parts you are using "this->" and others you aren't.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, this! Hah. The compiler complained about not finding those fields without it. I don't really understand why.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From talking with JoeG it is due to dependent member lookup and c++ being what it is. This looks great to me!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

printf("Flags: 0x%x.\n", this->Flags);
printf("Parent: %p.\n", this->Parent.get());
printf("Name: %s.\n", Name.get());
printf("Access function: %p.\n", getAccessFunction());
printf("Fields: %p.\n", Fields.get());
}

template<>
LLVM_ATTRIBUTE_USED
void EnumDescriptor::dump() const {
printf("TargetEnumDescriptor.\n");
printf("Flags: 0x%x.\n", this->Flags);
printf("Parent: %p.\n", this->Parent.get());
printf("Name: %s.\n", Name.get());
printf("Access function: %p.\n", getAccessFunction());
printf("Fields: %p.\n", Fields.get());
printf("NumPayloadCasesAndPayloadSizeOffset: 0x%08x "
"(payload cases: %u - payload size offset: %u).\n",
NumPayloadCasesAndPayloadSizeOffset,
getNumPayloadCases(), getPayloadSizeOffset());
printf("NumEmptyCases: %u\n", NumEmptyCases);
}
#endif

/***************************************************************************/
Expand Down