Skip to content

Conversation

@kastiglione
Copy link

@kastiglione kastiglione commented Mar 11, 2023

frame variable can print "ivars" directly (as lldb calls them, or equivalently "properties" in Swift parlance), without the user explicitly going through this or self.

This PR cherry picks upstream LLVM refactoring commits, and adds a single Swift specific commit: "Support direct ivar access in Swift".

Example:

class Thing {
    var number: Int = 41
    func run() {
        // ...
    }
}

Inside run():

(lldb) v self.number
(Int) 41
(lldb) v number
(Int) 41

@kastiglione
Copy link
Author

@swift-ci test

This applies to IsClassMethod as well.

(cherry picked from commit 77d2f26)
Add basic tests for `frame variable`'s ability to direct access fields of `this` and
ivars of `self`.

This splits the tests, preventing ObjC tests from running on Linux.

Differential Revision: https://reviews.llvm.org/D145348

(cherry picked from commit 23ee705)
The `v` (`frame variable`) command can directly access ivars/fields of `this` or `self`.
Such as `v field`, instead of `v this->field`. This change relaxes the criteria for
finding `this`/`self` variables.

There are cases where a `this`/`self` variable does exist, but up to now the `v` command
has not made use of it. The user would have to explicitly run `v this->field` or
`self->_ivar` to access ivars. This change allows such cases to also work (without
explicitly dereferencing `this`/`self`).

A very common example in Objective-C (and Swift) is weakly capturing `self`:

```
__weak Type *weakSelf = self;
void (^block)(void) = ^{
   Type *self = weakSelf; // Re-establish strong reference.
   // `v _ivar` should work just as well as `v self->_ivar`.
};
```

In this case, `self` exists but `v` would not have used it. With this change, the fact
that a variable named `self` exists is enough for it to be used.

Differential Revision: https://reviews.llvm.org/D145276

(cherry picked from commit 6c599b1)
Move responsibility of providing the instance variable name (`this`, `self`) from
`TypeSystem` to `Language`.

`Language` the natural place for this, but also has downstream benefits. Some languages
have multiple `TypeSystem` implementations (ex Swift), and by placing this logic in the
`Language`, redundancy is avoided.

This change relies on the tests from D145348 and D146320.

Differential Revision: https://reviews.llvm.org/D146548

(cherry picked from commit 0a7488d72ceb59942cc14f567d77f2e97f72a2e4)
@kastiglione kastiglione force-pushed the dl/this-or-self-ivar-direct-access branch from e6fbf4c to b6a93e2 Compare March 21, 2023 20:50
@kastiglione
Copy link
Author

@swift-ci test

@kastiglione kastiglione force-pushed the dl/this-or-self-ivar-direct-access branch from b6a93e2 to 1946914 Compare March 21, 2023 22:28
@kastiglione
Copy link
Author

@swift-ci test

@kastiglione kastiglione changed the title [lldb] Cherry pick improvements to this/self direct ivar access [lldb] Implement direct ivar access for Swift Mar 22, 2023

Choose a reason for hiding this comment

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

Nice!

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.

This is great!

@kastiglione kastiglione force-pushed the dl/this-or-self-ivar-direct-access branch from 1946914 to 47e8dc8 Compare March 22, 2023 17:03
@kastiglione
Copy link
Author

@swift-ci test

@kastiglione kastiglione merged commit ba3a5bc into stable/20221013 Mar 22, 2023
@kastiglione kastiglione deleted the dl/this-or-self-ivar-direct-access branch March 22, 2023 18:18
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.

4 participants