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