52 lines · python
1import lldb2from lldbsuite.test.decorators import *3from lldbsuite.test.lldbtest import *4from lldbsuite.test import lldbutil5 6 7class TestSBValueSynthetic(TestBase):8 NO_DEBUG_INFO_TESTCASE = True9 10 def test_str(self):11 self.build()12 lldbutil.run_to_source_breakpoint(13 self, "break here", lldb.SBFileSpec("main.cpp")14 )15 self.runCmd("command script import formatter.py")16 self.runCmd(17 "type synthetic add --python-class formatter.FooSyntheticProvider Foo"18 )19 20 formatted = self.frame().FindVariable("foo")21 has_formatted = self.frame().FindVariable("has_foo")22 self.expect(str(formatted), exe=False, substrs=["synth_child"])23 self.expect(str(has_formatted), exe=False, substrs=["synth_child"])24 25 def test_synth_arr(self):26 self.build()27 lldbutil.run_to_source_breakpoint(28 self, "break here", lldb.SBFileSpec("main.cpp")29 )30 point_arr = self.frame().FindVariable("point_arr")31 point_ptr = self.frame().FindVariable("point_ptr")32 for v in [point_arr, point_ptr]:33 for i in range(3):34 child = v.GetChildAtIndex(i, lldb.eDynamicDontRunTarget, True)35 check = ValueCheck(36 name=f"[{i}]",37 type="Point",38 children=[39 ValueCheck(name="x", value=str(2 * i + 1)),40 ValueCheck(name="y", value=str(2 * i + 2)),41 ],42 )43 check.check_value(self, child, f"{child}, child {i} of {v.GetName()}")44 45 int_arr = self.frame().FindVariable("int_arr")46 int_ptr = self.frame().FindVariable("int_ptr")47 for v in [int_arr, int_ptr]:48 for i in range(3):49 child = v.GetChildAtIndex(i, lldb.eDynamicDontRunTarget, True)50 check = ValueCheck(name=f"[{i}]", type="int", value=str(i + 1))51 check.check_value(self, child, f"{child}, child {i} of {v.GetName()}")52