-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Add a callback to swift::reflection::MemoryReader that allows LLDB to… #33417
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
Conversation
@augusto2112 For some reason github did not let me request a review from you. |
Some more context: I'm working on a |
For pure C types that are referenced from code, we emit BuiltinTypeDescriptors in IRGen. I'm guessing here you need the callback because expression evaluation can pull in arbitrary C types that are not referenced from code? If so this approach sounds great. I have reservations about adding this to MemoryReader since it's not really about reading memory. Maybe we need a second callback interface, or would that be too awkward to plumb through? |
@@ -623,7 +623,7 @@ class ReflectionContext | |||
|
|||
// Perform layout | |||
if (start) | |||
TI = TC.getClassInstanceTypeInfo(TR, *start); | |||
TI = TC.getClassInstanceTypeInfo(TR, *start, getReader()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is why I think a different callback would be nice. In theory it should be possible to look up TypeInfos without a remote process attached; and you could still have a callback to get C type info.
if (ThickFunctionTI != nullptr) | ||
return ThickFunctionTI; | ||
|
||
RecordTypeInfoBuilder builder(*this, RecordKind::ThickFunction); | ||
builder.addField("function", getThinFunctionTypeRef()); | ||
builder.addField("context", getNativeObjectTypeRef()); | ||
builder.addField("function", getThinFunctionTypeRef(), reader); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't need a reader. A thick function is just a pair of pointers as far as RemoteMirrors are concerned.
@@ -1176,12 +1180,12 @@ class ExistentialTypeInfoBuilder { | |||
// Class existentials consist of a single retainable pointer | |||
// followed by witness tables. | |||
if (Refcounting == ReferenceCounting::Unknown) | |||
builder.addField("object", TC.getUnknownObjectTypeRef()); | |||
builder.addField("object", TC.getUnknownObjectTypeRef(), reader); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
None of these should need to read imported TypeInfo either
// to instantiate a dummy reader here. This helps preserving the | ||
// layering. | ||
remote::MemoryReader dummyReader; | ||
auto *SuperclassTI = TC.getTypeInfo(Superclass, dummyReader); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could the reader parameter to getTypeInfo() be a pointer instead, with handing of the null case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe llvm:Optional to make it clear the reader is... well... optional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe llvm::Optional also has the benefit of being able to keep queryDataLayout
, getSymbolAddress
and readString
deleted in the base class.
Probably because I'm not a project member (that's why I have to @ people when I want a review). |
Interesting! The case I primarily debugged this with was using a type referenced in the code, but perhaps the example program was too simple to trigger emission of the metadata. I'll look into that — but it also seems like this could be useful even if that were a bug because of the pulling-extra-types-in scenario you mentioned.
That sounds totally reasonable, I'll take a look at how well that fit. |
I inspected the LLVM IR generated for my testcase and there is no mention of the imported C type outside of debug info. When adding a |
I see, you're right. The compiler only emits the builtin descriptor when the type appears as the field type of another type, because the original use case for RemoteMirrors was to enable object graph debugging. It's reasonable to pull in additional type info for the types of local variables and such using the callback. |
2bbc71e
to
54c8104
Compare
I have now created a new |
757c094
to
203923e
Compare
… provide swift::reflection::TypeInfo for (Clang-)imported non-Objective-C types. This is needed to reflect on the size mixed Swift / Clang types, when no type metadata is available for the C types. This is a necessary ingredient for the TypeRef-based Swift context in LLDB. Because we do not have reflection metadata for pure C types in Swift, reflection cannot compute TypeInfo for NominalTypeRefs for those types. By providing this callback, LLDB can supply this information for DWARF, and reflection can compute TypeInfos for mixed Swift/C types.
b535050
to
56b2e90
Compare
@slavapestov The LLDB side of this is ready now. Can you check if I addressed all your concerns? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I only have one last suggestion. I think we should stick the TypeInfoProvider inside the TypeConverter, so that it doesn't have to be passed around. What do you think?
My understanding is that |
I didn't realize we had one TypeInfoProvider per Module. In that case, I think it's fine to do what you're doing now (but we could also investigate having one TypeConverter per module or something?). |
@adrian-prantl This PR need to be updated to target master branch form master-rebranch. |
@swift-ci test |
@swift-ci test |
Build failed |
Build failed |
@swift-ci smoke test |
test with swiftlang/llvm-project#1636 |
Build failed |
Build failed |
test with swiftlang/llvm-project#1636 |
test with swiftlang/llvm-project#1636 |
Build failed |
Build failed |
test with swiftlang/llvm-project#1636 |
test with swiftlang/llvm-project#1636 |
Build failed |
test with swiftlang/llvm-project#1636 |
test with swiftlang/llvm-project#1636 |
@adrian-prantl this seems to have caused a regression on the Windows builds :-( |
Add a callback to swift::reflection::MemoryReader that allows LLDB to provide
swift::reflection::TypeInfo for (Clang-)imported non-Objective-C types. This is
needed to reflect on the size mixed Swift / Clang types.