121 lines · python
1"""2Test diamond inheritance.3"""4 5import lldb6from lldbsuite.test.lldbtest import *7from lldbsuite.test.decorators import *8import lldbsuite.test.lldbutil as lldbutil9 10 11class TestCase(TestBase):12 @no_debug_info_test13 def test_with_sbvalue(self):14 """15 Test that virtual base classes work in when SBValue objects are16 used to explore the class.17 """18 self.build()19 lldbutil.run_to_source_breakpoint(20 self, "// breakpoint 1", lldb.SBFileSpec("main.cpp")21 )22 23 self.runCmd("settings set target.prefer-dynamic-value no-dynamic-values")24 25 j1 = self.frame().FindVariable("j1")26 j1_Derived1 = j1.GetChildAtIndex(0)27 j1_Derived2 = j1.GetChildAtIndex(1)28 j1_Derived1_VBase = j1_Derived1.GetChildAtIndex(0)29 j1_Derived2_VBase = j1_Derived2.GetChildAtIndex(0)30 j1_Derived1_VBase_m_value = j1_Derived1_VBase.GetChildAtIndex(0)31 j1_Derived2_VBase_m_value = j1_Derived2_VBase.GetChildAtIndex(0)32 33 self.assertEqual(34 j1_Derived1_VBase.GetLoadAddress(),35 j1_Derived2_VBase.GetLoadAddress(),36 "ensure virtual base class is the same between Derived1 and Derived2",37 )38 self.assertEqual(39 j1_Derived1_VBase_m_value.GetValueAsUnsigned(1),40 j1_Derived2_VBase_m_value.GetValueAsUnsigned(2),41 "ensure m_value in VBase is the same",42 )43 self.assertEqual(44 self.frame()45 .FindVariable("d")46 .GetChildAtIndex(0)47 .GetChildAtIndex(0)48 .GetValueAsUnsigned(0),49 12345,50 "ensure Derived2 from j1 is correct",51 )52 53 # This reassigns 'd' to point to 'j2'.54 self.thread().StepOver()55 56 self.assertEqual(57 self.frame()58 .FindVariable("d")59 .GetChildAtIndex(0)60 .GetChildAtIndex(0)61 .GetValueAsUnsigned(0),62 12346,63 "ensure Derived2 from j2 is correct",64 )65 66 @no_debug_info_test67 def test(self):68 self.build()69 lldbutil.run_to_source_breakpoint(70 self, "// breakpoint 1", lldb.SBFileSpec("main.cpp")71 )72 73 # All the children of j1.74 children = [75 ValueCheck(76 type="Derived1",77 children=[78 ValueCheck(79 type="VBase",80 children=[81 ValueCheck(type="int", name="m_value", value="12345")82 ],83 )84 ],85 ),86 ValueCheck(87 type="Derived2",88 children=[89 ValueCheck(90 type="VBase",91 children=[92 ValueCheck(type="int", name="m_value", value="12345")93 ],94 )95 ],96 ),97 ValueCheck(type="long", value="1"),98 ]99 # Try using the class with expression evaluator/variable paths.100 self.expect_expr("j1", result_type="Joiner1", result_children=children)101 self.expect_var_path("j1", type="Joiner1", children=children)102 103 # Use the expression evaluator to access the members.104 self.expect_expr("j1.x", result_type="long", result_value="1")105 self.expect_expr("j1.m_value", result_type="int", result_value="12345")106 107 # Use variable paths to access the members.108 self.expect_var_path("j1.x", type="long", value="1")109 110 @expectedFailureAll111 @no_debug_info_test112 def test_invalid_member(self):113 self.build()114 lldbutil.run_to_source_breakpoint(115 self, "// breakpoint 1", lldb.SBFileSpec("main.cpp")116 )117 # FIXME: This is completely broken and 'succeeds' with an error that118 # there is noch such value/member in Joiner1. Move this up to the test119 # above when fixed.120 self.expect_var_path("j1.m_value", type="int", value="12345")121