[Lldb-commits] [lldb] [lldb] Add lookup by name to SBValue.child (PR #118814)

Greg Clayton via lldb-commits lldb-commits at lists.llvm.org
Fri Dec 6 11:22:06 PST 2024


================
@@ -23,6 +23,13 @@ STRING_EXTENSION_OUTSIDE(SBValue)
                     if -count <= key < count:
                         key %= count
                         return self.sbvalue.GetChildAtIndex(key)
+                elif isinstance(key, str):
+                    if child := self.sbvalue.GetChildMemberWithName(key):
+                        return child
+                    # Support base classes, which are children but not members.
+                    for child in self.sbvalue:
+                        if child.name == key:
+                            return child
----------------
clayborg wrote:

NOTE: Base classes will only be returned by `GetChildAtIndex(N)` if they have something to show the user, i.e. they have instance variables or have base classes that have instance variables. If a base class has no ivars, it will not be returned. So if we are looking for a reliable way to get base classes, it is better to use the exsting APIs on `lldb.SBType`.

The other thing is, do we want to add a `SBValue.__get_item__(self, arg)` method to easily access base classes or members where we just return the value of `SBValue.GetChildAtIndex(...)`? Then we can do:
```
var = lldb.frame.FindVariable('my_struct')
first_child = var[0]
```
Instead of:
```
first_child = None
if (len(value.bases) > 0)
  first_child = value.bases[0]
else:
  first_child = value.members[0]
```

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


More information about the lldb-commits mailing list