Files
Dave Lee 58c5252b28 [lldb] Automatic indexing for synthetic children of collections (#174885)
Synthetic providers for collection types use a child name format of
"[N]".

This `ValueObjectSynthetic` to automatically convert child names in this
convention to the index embedded in the subscript string. With this
change, synthetic formatters for collections will only need to implement
`GetIndexOfChildWithName` or `get_child_index` for non-indexed
collection children. Some examples of non-indexed children are
`$$dereference$$` support, or "hidden" children.

The automatic conversion applies to N values that are less than the
number of children reported by the synthetic provider.
2026-03-05 23:28:22 +00:00

24 lines
844 B
Python

import lldb
from lldbsuite.test.lldbtest import *
from lldbsuite.test.decorators import *
from lldbsuite.test import lldbutil
class TestCase(TestBase):
def test(self):
self.build()
_, process, _, _ = lldbutil.run_to_source_breakpoint(
self, "break here", lldb.SBFileSpec("main.c")
)
self.runCmd("command script import thing_formatter.py")
frame = process.selected_thread.selected_frame
x = frame.var("x")
names = ("zero", "one")
for i in range(x.num_children):
idx = x.GetIndexOfChildWithName(f"[{i}]")
self.assertEqual(idx, i)
child = x.GetChildAtIndex(idx)
self.assertEqual(child.name, names[idx])
idx = x.GetIndexOfChildWithName(f"[{x.num_children + 1}]")
self.assertEqual(idx, lldb.UINT32_MAX)