[Lldb-commits] [lldb] Bugfix: Not showing the synthetic children of values behind pointers (PR #117755)

Greg Clayton via lldb-commits lldb-commits at lists.llvm.org
Fri Dec 6 16:23:07 PST 2024


clayborg wrote:

You also are overwriting the original `lldb.SBValue` with the statement `self.valobj = self.valobj.Dereference()` here:
```
    def extract_entries(self):
        if self.valobj.type.is_pointer:
            self.valobj = self.valobj.Dereference()
```
You never want to do this because if your value is a pointer, that pointer can change, and now you have replaced the value that is the pointer value with the first dereference value and that value will never change. Now when you run this function again, you won't get the right value because you will have locked onto the first dereferenced pointer. So if you have code like:
```
auto  *int_ptr = &myHash1;
int_ptr = &myHash2;
```
You will always be showing `myHash1` as the value and it will never update. So you never touch the original `self. valobj` value as that is always your starting point. So lets say `&myHash1` is 0x1000 and `&myHash2` is 0x2000, with your code you will always dereference the pointer from 0x1000 and then you re-write your `self.valobj` to now always be that reference.

You also don't need to dereference the type. So your `extract_entries` function that currently looks like:
```
    def extract_entries(self):
        if self.valobj.type.is_pointer:
            self.valobj = self.valobj.Dereference()
        self.size = 0 if self.valobj.GetChildMemberWithName("size").value is None else self.valobj.GetChildMemberWithName("size").unsigned
        self.entries = []
```
Should be:
```
    def update(self):
        self.size = self.valobj.GetChildMemberWithName("size").GetValueAsUnsigned(0)
        self.entries = []
```

https://github.com/llvm/llvm-project/pull/117755


More information about the lldb-commits mailing list