Skip to content

[lldb] Name UnsafePointer's single child 'pointee' #3264

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 Sep 17, 2021

Currently, the builtin formatter for UnsafePointer and UnsafeMutablePointer provide a single child, which is named [0]. This changes that child to be named pointee. This has two advantages:

First, it enables v ptr.pointee to work, which matches p ptr.pointee. This is typically how unsafe pointers access their contents, not via subscript.

Second, it avoids a behavior that looks like a bug to the user. For example:

let ptr = UnsafeMutablePointer<Int>.allocate(capacity: 2)
ptr[0] = 41
ptr[1] = 23
print(ptr) // break here

On that last line, running v ptr produces:

(lldb) v ptr
(UnsafeMutablePointer<Int>) ptr = 0x100404080 {
  [0] = 41
}

Both UnsafePointer and UnsafeMutablePointer will only ever print the single child. A user may think their data is wrong, when it's in fact correct (because they aren't shown the second value). Or, they might think lldb has a bug, when in fact printing a single child expected behavior. Unless I have missed something, Unsafe(Mutable)?Pointer does not capture state that would indicate it was created with a specific capacity, that information is "erased". If a capacity were available at runtime, lldb could print all of the children.

Note that with this change v ptr[0] still succeeds, so that behavior is maintained. Also note that v ptr[1] does not currently work regardless of whether it's valid. This is because the provider reports only 1 child. The work around is to run p ptr[1].

After this change, the above v command prints:

(lldb) v ptr
(UnsafeMutablePointer<Int>) ptr = 0x100404080 {
  pointee = 41
}

rdar://83155374

@kastiglione
Copy link
Author

@swift-ci test

@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.

That's a nice ergonomics improvement!

Copy link

@augusto2112 augusto2112 left a comment

Choose a reason for hiding this comment

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

LGTM!

@kastiglione
Copy link
Author

@swift-ci test

@kastiglione kastiglione force-pushed the lldb-Name-UnsafePointer-s-single-child-pointee branch from bb3addd to 1242ce6 Compare September 20, 2021 20:28
@kastiglione
Copy link
Author

@swift-ci test

@kastiglione kastiglione merged commit 1fc7432 into stable/20210726 Sep 21, 2021
@kastiglione kastiglione deleted the lldb-Name-UnsafePointer-s-single-child-pointee branch September 21, 2021 20:57
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.

3 participants