1""" 2Test diamond inheritance. 3""" 4 5import lldb 6from lldbsuite.test.lldbtest import * 7from lldbsuite.test.decorators import * 8import lldbsuite.test.lldbutil as lldbutil 9 10 11class TestCase(TestBase): 12 13 mydir = TestBase.compute_mydir(__file__) 14 15 @no_debug_info_test 16 def test_with_sbvalue(self): 17 """ 18 Test that virtual base classes work in when SBValue objects are 19 used to explore the class. 20 """ 21 self.build() 22 lldbutil.run_to_source_breakpoint(self, "// breakpoint 1", lldb.SBFileSpec("main.cpp")) 23 24 j1 = self.frame().FindVariable("j1") 25 j1_Derived1 = j1.GetChildAtIndex(0) 26 j1_Derived2 = j1.GetChildAtIndex(1) 27 j1_Derived1_VBase = j1_Derived1.GetChildAtIndex(0) 28 j1_Derived2_VBase = j1_Derived2.GetChildAtIndex(0) 29 j1_Derived1_VBase_m_value = j1_Derived1_VBase.GetChildAtIndex(0) 30 j1_Derived2_VBase_m_value = j1_Derived2_VBase.GetChildAtIndex(0) 31 32 self.assertEqual( 33 j1_Derived1_VBase.GetLoadAddress(), j1_Derived2_VBase.GetLoadAddress(), 34 "ensure virtual base class is the same between Derived1 and Derived2") 35 self.assertEqual(j1_Derived1_VBase_m_value.GetValueAsUnsigned( 36 1), j1_Derived2_VBase_m_value.GetValueAsUnsigned(2), "ensure m_value in VBase is the same") 37 self.assertEqual(self.frame().FindVariable("d").GetChildAtIndex(0).GetChildAtIndex( 38 0).GetValueAsUnsigned(0), 12345, "ensure Derived2 from j1 is correct") 39 40 # This reassigns 'd' to point to 'j2'. 41 self.thread().StepOver() 42 43 self.assertEqual(self.frame().FindVariable("d").GetChildAtIndex(0).GetChildAtIndex( 44 0).GetValueAsUnsigned(0), 12346, "ensure Derived2 from j2 is correct") 45 46 @no_debug_info_test 47 def test(self): 48 self.build() 49 lldbutil.run_to_source_breakpoint(self, "// breakpoint 1", lldb.SBFileSpec("main.cpp")) 50 51 # All the children of j1. 52 children = [ 53 ValueCheck(type="Derived1", children=[ 54 ValueCheck(type="VBase", children=[ 55 ValueCheck(type="int", name="m_value", value="12345") 56 ]) 57 ]), 58 ValueCheck(type="Derived2", children=[ 59 ValueCheck(type="VBase", children=[ 60 ValueCheck(type="int", name="m_value", value="12345") 61 ]) 62 ]), 63 ValueCheck(type="long", value="1"), 64 ] 65 # Try using the class with expression evaluator/variable paths. 66 self.expect_expr("j1", result_type="Joiner1", result_children=children) 67 self.expect_var_path("j1", type="Joiner1", children=children) 68 69 # Use the expression evaluator to access the members. 70 self.expect_expr("j1.x", result_type="long", result_value="1") 71 self.expect_expr("j1.m_value", result_type="int", result_value="12345") 72 73 # Use variable paths to access the members. 74 self.expect_var_path("j1.x", type="long", value="1") 75 76 @expectedFailureAll 77 @no_debug_info_test 78 def test(self): 79 self.build() 80 lldbutil.run_to_source_breakpoint(self, "// breakpoint 1", lldb.SBFileSpec("main.cpp")) 81 # FIXME: This is completely broken and 'succeeds' with an error that 82 # there is noch such value/member in Joiner1. Move this up to the test 83 # above when fixed. 84 self.expect_var_path("j1.m_value", type="int", value="12345") 85