[Lldb-commits] [lldb] [LLDB] Add an API to check whether a variable is writable (PR #208042)
via lldb-commits
lldb-commits at lists.llvm.org
Tue Jul 7 14:47:55 PDT 2026
jimingham wrote:
I think this patch is fine but I have some quibbles about the description of the feature in the comments.
In the context of ValueObjectVariable, it's appropriate to speak about what DWARF tells you about the nature of the variable, and how that would inform the decision about whether the value can be altered or not.
But you use the same language in other ValueObject classes where it isn't as appropriate. For instance I could make a value object wholly out of a DataBufferHeap and I would expect to be able to change that ValueObject even though it has no representation in the target. So requiring memory isn't a necessary condition for variables being editable.
As another example, ValueObjectConstResult ValueObjects often mirror the value that was stored on the host side to a value in the target. For the ones we make for "result variables" we artificially mark them as constant (with SetIsConstant). But the ones we make for expression result variables are modifiable. For instance, with:
```
2 int
3 print_ref(int *int_ptr) {
4 *int_ptr += 11;
5 return printf("I got: %d\n", *int_ptr);
6 }
```
I can do:
```
(lldb) expr int $my_int = 10
(lldb) expr print_ref(&$my_int)
I got: 21
(int) $0 = 10
(lldb) expr $my_int
(int) $my_int = 21
(lldb) expr $my_int = 30
(int) $1 = 30
(lldb) expr print_ref(&$my_int)
I got: 41
```
So we were able to pass the value by address to a function we actually called, and change its value and effect the value in the target. This doesn't happen for expression result variables because we don't copy back the results of expressions. We really should also reset the value, but we don't, leading to:
```
(lldb) expr argc
(int) $3 = 1
(lldb) expr print_ref(&$3)
I got: 12
(int) $4 = 10
(lldb) expr $3
(int) $3 = 1
(lldb) expr print_ref(&$3)
I got: 23
(int) $5 = 10
```
The fact that we said $3 was still 1 but the expression that used the target-side representation saw 12 is a bug.
That was way too many words for the suggestion that the discussion of what makes ValueObjectVariables not changeable is not what makes other ValueObject subclasses changeable...
https://github.com/llvm/llvm-project/pull/208042
More information about the lldb-commits
mailing list