Skip to content

[lldb] Reimplement and implement GetPointerType #1908

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

kastiglione
Copy link

@kastiglione kastiglione commented Oct 6, 2020

Reimplement SwiftASTContext::GetPointerType to return the given type wrapped in UnsafePointer<T>. Also implement TypeSystemSwiftTypeRef::GetPointerType with a matching demangle-based implementation that also wraps in UnsafePointer.

Given a variable x: Int, here is some output:

(lldb) script print(lldb.frame.vars["x"][0].AddressOf())
(UnsafePointer<Int>) &x = 0x7ffeefbff728 {
  [0] = 23
}
(lldb) script print(lldb.frame.vars["x"][0].AddressOf().type)
@frozen struct UnsafePointer<Pointee> : Swift._Pointer {
...

rdar://68171356

@@ -90,8 +90,7 @@ GetClangTypeNode(CompilerType clang_type, swift::Demangle::Demangler &dem) {
}

/// \return the child of the \p Type node.
static swift::Demangle::NodePointer GetType(swift::Demangle::Demangler &dem,
swift::Demangle::NodePointer n) {
static NodePointer GetType(swift::Demangle::NodePointer n) {
Copy link
Author

Choose a reason for hiding this comment

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

I removed the unused Demangler parameter.

@kastiglione
Copy link
Author

@swift-ci test

@kastiglione
Copy link
Author

A follow up will be to fix the following:

(lldb) sc print(lldb.frame.vars["x"][0].AddressOf().Dereference())
No value

@kastiglione
Copy link
Author

Looking closer at this output:

(lldb) sc print(lldb.frame.vars["x"][0].AddressOf())
(UnsafePointer<Int>) &x = 0x7ffeefbff728 {
  [0] = 23
}
  1. Do we expect/like the output of (UnsafePointer<Int>) &x = <addr>?
  2. Do we expect/like the fact that it's formatted as a single element array?

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.

Apart from some stylistic nitpicks inline, this looks good!

@adrian-prantl
Copy link

Looking closer at this output:

(lldb) sc print(lldb.frame.vars["x"][0].AddressOf())
(UnsafePointer<Int>) &x = 0x7ffeefbff728 {
  [0] = 23
}
  1. Do we expect/like the output of (UnsafePointer<Int>) &x = <addr>?
  2. Do we expect/like the fact that it's formatted as a single element array?

I guess that is coming from a C-centric view that arrays and pointers are interchangeable. It does make much less sense in Swift.

@adrian-prantl
Copy link

... but that's a separate problem that presumably affects all pointer types.

@kastiglione
Copy link
Author

@swift-ci test

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.

Nice!

@kastiglione kastiglione merged commit a9caeb3 into swift/main Oct 7, 2020
@kastiglione kastiglione deleted the lldb-Reimplement-and-implement-GetPointerType branch October 7, 2020 05:21
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