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

Sergey Kuznetsov via lldb-commits lldb-commits at lists.llvm.org
Mon Dec 2 11:34:44 PST 2024


skuznetsov wrote:

> Can you post a copy of a the python code for the synthetic child provider you are creating and also how you are registering it with LLDB?

Here it is:
```
# Hash(K,V) class support providers
class CrystalHashSyntheticProvider:
    def __init__(self, valobj, internal_dict):
        self.valobj = valobj
        self.extract_entries()

    def has_children(self):
        return True

    def num_children(self):
        size = self.valobj.GetChildMemberWithName("size").unsigned
        return size

    def get_child_index(self, name):
        name = name.lstrip('[').rstrip(']')
        if name == "size":
            return len(self._entries) + 1 if self._entries else 1
        try:
            idx = next((index for index, obj in enumerate(self._entries) if getattr(self._entries, "key") == name), -1)
            return idx
        except:
            return -1

    def get_child_at_index(self, index):
        if index > len(self.entries):
            return None
        if index == len(self.entries):
            return self.valobj.GetChildMemberWithName("size")
        entry = self.entries[index]
        key = entry.GetChildMemberWithName("key").GetSummary()
        value = entry.GetChildMemberWithName("value").deref
        return value.CreateChildAtOffset("[%s]" % key, 0, value.type)
        # return entry.CreateChildAtOffset("[%d]" % index, 0, entry.type)

    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 = []

        for index in range(self.size):
            try:
                valuePath = "entries[%d]" % index
                value = self.valobj.EvaluateExpression(valuePath)
                if value.type.is_pointer:
                    value = value.deref
                self.entries.append(value)

            except Exception as e:
                print('Got exception %s' % (str(e)))
                return None
        print ("Created %d entries." % len(self.entries))

```

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


More information about the lldb-commits mailing list