Skip to content

[lldb] Adapt class resolution to work without reflection in binaries #8105

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

Conversation

augusto2112
Copy link

When metadata is stripped (or simply not emitted) in the binary, querying reflection information starting out from a class's instance pointer will not work. Adapt SwiftLanguageRuntimeDynamicTypeResolution to handle this use case gracefully.

@augusto2112
Copy link
Author

swiftlang/swift#71328

@swift-ci test

@augusto2112
Copy link
Author

swiftlang/swift#71328

@swift-ci test


if (supers.size() == 0) {
LLDBTypeInfoProvider tip(*this, *instance_ts);
// Try out the instance pointer based super class traversion first, as its

Choose a reason for hiding this comment

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

Suggested change
// Try out the instance pointer based super class traversion first, as its
// Try out the instance-pointer-based super class traversal first, as its

reflection_ctx->ForEachSuperClassType(&tip, ts->GetDescriptorFinder(), tr,
superclass_finder);

if (supers.empty()) {

Choose a reason for hiding this comment

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

why twice the same condition in a row?

Copy link
Author

Choose a reason for hiding this comment

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

Dynamic type resolution first tries the pointer-based ForEachSuperClassType, if that fails, it tries the typeref-based ForEachSuperClassType, if that also fails then we're out of luck.

Choose a reason for hiding this comment

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

I think my question was aiming at: does ForEachSuperClassType modify supers?
Otherwise why isn't this

if (supers.empty()) {
   ForEachSuperClassType ...;
  LLDB_LOG
}

Copy link
Author

Choose a reason for hiding this comment

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

Yes, it's being captured by reference by the superclass_finder lambda

Copy link

@adrian-prantl adrian-prantl left a comment

Choose a reason for hiding this comment

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

Can you add a test for this?

@augusto2112
Copy link
Author

Can you add a test for this?

This is not testable by itself, I'll add a test to #8112 which works in conjunction with this patch to debug embedded Swift programs.

@augusto2112
Copy link
Author

@swift-ci test

@augusto2112
Copy link
Author

@swift-ci test Windows


auto start =
m_reflection_ctx.computeUnalignedFieldStartOffset(type_ref);
if (!start) {

Choose a reason for hiding this comment

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

Can you wrap this in if(GetLog(LLDBLog::Types)), so we don't do the string operations if we don't log?

@adrian-prantl adrian-prantl self-requested a review February 7, 2024 17:20
When metadata is stripped (or simply not emitted) in the binary,
querying reflection information starting out from a class's instance
pointer will not work. Adapt SwiftLanguageRuntimeDynamicTypeResolution
to handle this use case gracefully.
@augusto2112
Copy link
Author

@swift-ci test

@augusto2112
Copy link
Author

@swift-ci test Windows

1 similar comment
@augusto2112
Copy link
Author

@swift-ci test Windows

@augusto2112 augusto2112 merged commit addc6fb into swiftlang:stable/20230725 Feb 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants