-
Notifications
You must be signed in to change notification settings - Fork 10.6k
[Debug] Add pointer based stringForPrintObject #84742
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
Changes from all commits
c4bd263
5154ce0
581580f
54dd931
c554d84
18939b3
31834f9
4504063
ef06bb2
92a23dd
2b68a58
2263a34
c7f97ba
8200910
506fc9f
81f6c15
1834644
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -328,6 +328,38 @@ public enum _DebuggerSupport { | |
|
|
||
| return target | ||
| } | ||
|
|
||
| // Print an object or value without the caller having a concrete type. | ||
| // | ||
| // For simplicity of data handling in LLDB avoids using an enum return type, | ||
| // using (Bool, String) instead of Optional<String>. | ||
| @available(SwiftStdlib 6.3, *) | ||
| public static func stringForPrintObject(_ pointer: UnsafeRawPointer?, mangledTypeName: String) -> (Bool, String) { | ||
| guard let pointer = unsafe pointer else { | ||
| return (false, "invalid pointer") | ||
| } | ||
|
|
||
| guard let type = | ||
| unsafe _getTypeByMangledNameInContext( | ||
| mangledTypeName, | ||
| UInt(mangledTypeName.count), | ||
| genericContext: nil, | ||
| genericArguments: nil) | ||
| else { | ||
| return (false, "type not found for mangled name: \(mangledTypeName)") | ||
| } | ||
|
|
||
| func loadPointer<T>(type: T.Type) -> Any { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure what would happen here if T is noncopyable. Presumably it would be OK not to support noncopyable types as a first implementation, but we should make sure they at least do something vaguely sensible when failing. I don't think we can use reflection on them at all, but we could potentially check for noncopyable types and return the demangled type name and some message about not being able to show the contents.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. turns out execution doesn't make it this far ( |
||
| if type is AnyObject.Type { | ||
| unsafe unsafeBitCast(pointer, to: T.self) | ||
| } else { | ||
| unsafe pointer.load(as: T.self) | ||
|
Comment on lines
+353
to
+356
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mikeash following on our conversation last week, what do you think of this approach for handling objects? This is instead of providing a pointer to the object (pointer to pointer).
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should work, but it seems a bit overcomplicated. If you unconditionally If there's some case where lldb naturally ends up with an object pointer rather than a pointer to a value of class type, maybe that suggests a second entrypoint specifically class types?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm torn. I can see the argument of consistency, but it also seems more natural, to me, to pass an object to the pointer argument, since it is already a pointer, rather than passing a pointer to an object. I'm also uncertain whether it will always be possible to get a pointer to an object, for example an object stored register.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm thinking that can also happen with a non-class type. A sufficiently small struct may be stored into a register. Somewhat larger ones may be stored in multiple registers. So you'll want a way to materialize a value regardless. However, working with object pointers directly would allow you to support objects even if you don't yet have such a generalized mechanism.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm going to merge this as is, because it allows forward progress, and merging does not prevent either of the following changes:
This function is used only by lldb and we have the freedom to alter it as needed in the coming weeks, while development and testing happens on the lldb side. I'll also be thinking about how materialize small structs stored in registers. thanks Mike.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good to me. |
||
| } | ||
| } | ||
|
|
||
| let anyValue = _openExistential(type, do: loadPointer) | ||
| return (true, stringForPrintObject(anyValue)) | ||
| } | ||
| } | ||
|
|
||
| public func _stringForPrintObject(_ value: Any) -> String { | ||
|
|
||
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.
Since we're passing
nilhere, does it mean this doesn't work with generic types the moment?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.
It will work with generic types as long as the mangled name is fully bound, i.e. there aren't any "get the 3rd type parameter from the type I'm in" directives. It may not work for generic types that depend on the context (e.g. you have a
[T]local variable), depending on how this mangled name is obtained. But as long as you can get a name with all the parts in it, it will work.Uh oh!
There was an error while loading. Please reload this page.
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.
as Mike says, this depends on lldb being able to construct a concrete mangled type name. @augusto2112 you've dealt the most with generic types within expression evaluation, are there known cases where this will be a problem?
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.
Yes, the generic expression evaluator can have unbound types, in fact that's essentially its whole purpose for existing, so we'd need to figure out how to pass those parameters in as well.
An easy test for you is to stop in a generic type with one generic parameter and po self: