[lldb] Let 'v' command directly access ivars of _any_ self/this
authorDave Lee <davelee.com@gmail.com>
Fri, 3 Mar 2023 19:15:55 +0000 (11:15 -0800)
committerDave Lee <davelee.com@gmail.com>
Wed, 8 Mar 2023 19:19:43 +0000 (11:19 -0800)
commit6c599b1e9b7e1b57952565468aed2de16af21082
treee8c131fb25d031b2e9ab1a2500b9a2850cd3726a
parentac763b9fdf5b8b6cc563b30c3fe90499f3706b13
[lldb] Let 'v' command directly access ivars of _any_ self/this

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
lldb/include/lldb/Symbol/CompilerDeclContext.h
lldb/include/lldb/Symbol/SymbolContext.h
lldb/include/lldb/Symbol/TypeSystem.h
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
lldb/source/Symbol/CompilerDeclContext.cpp
lldb/source/Symbol/SymbolContext.cpp
lldb/source/Target/StackFrame.cpp
lldb/test/API/commands/frame/var/direct-ivar/objc/Makefile
lldb/test/API/commands/frame/var/direct-ivar/objc/TestFrameVarDirectIvarObjC.py
lldb/test/API/commands/frame/var/direct-ivar/objc/main.m