xref: /llvm-project/lldb/test/API/lang/cpp/diamond/TestCppDiamond.py (revision a4c18137d84bc48df49ee0101bef465a955e62ac)
178e17e23SRaphael Isemann"""
278e17e23SRaphael IsemannTest diamond inheritance.
378e17e23SRaphael Isemann"""
478e17e23SRaphael Isemann
578e17e23SRaphael Isemannimport lldb
678e17e23SRaphael Isemannfrom lldbsuite.test.lldbtest import *
778e17e23SRaphael Isemannfrom lldbsuite.test.decorators import *
878e17e23SRaphael Isemannimport lldbsuite.test.lldbutil as lldbutil
978e17e23SRaphael Isemann
1078e17e23SRaphael Isemann
1178e17e23SRaphael Isemannclass TestCase(TestBase):
1278e17e23SRaphael Isemann    @no_debug_info_test
1378e17e23SRaphael Isemann    def test_with_sbvalue(self):
1478e17e23SRaphael Isemann        """
1578e17e23SRaphael Isemann        Test that virtual base classes work in when SBValue objects are
1678e17e23SRaphael Isemann        used to explore the class.
1778e17e23SRaphael Isemann        """
1878e17e23SRaphael Isemann        self.build()
192238dcc3SJonas Devlieghere        lldbutil.run_to_source_breakpoint(
202238dcc3SJonas Devlieghere            self, "// breakpoint 1", lldb.SBFileSpec("main.cpp")
212238dcc3SJonas Devlieghere        )
2278e17e23SRaphael Isemann
23c21dfa9eSDave Lee        self.runCmd("settings set target.prefer-dynamic-value no-dynamic-values")
24c21dfa9eSDave Lee
2578e17e23SRaphael Isemann        j1 = self.frame().FindVariable("j1")
2678e17e23SRaphael Isemann        j1_Derived1 = j1.GetChildAtIndex(0)
2778e17e23SRaphael Isemann        j1_Derived2 = j1.GetChildAtIndex(1)
2878e17e23SRaphael Isemann        j1_Derived1_VBase = j1_Derived1.GetChildAtIndex(0)
2978e17e23SRaphael Isemann        j1_Derived2_VBase = j1_Derived2.GetChildAtIndex(0)
3078e17e23SRaphael Isemann        j1_Derived1_VBase_m_value = j1_Derived1_VBase.GetChildAtIndex(0)
3178e17e23SRaphael Isemann        j1_Derived2_VBase_m_value = j1_Derived2_VBase.GetChildAtIndex(0)
3278e17e23SRaphael Isemann
3378e17e23SRaphael Isemann        self.assertEqual(
342238dcc3SJonas Devlieghere            j1_Derived1_VBase.GetLoadAddress(),
352238dcc3SJonas Devlieghere            j1_Derived2_VBase.GetLoadAddress(),
362238dcc3SJonas Devlieghere            "ensure virtual base class is the same between Derived1 and Derived2",
372238dcc3SJonas Devlieghere        )
382238dcc3SJonas Devlieghere        self.assertEqual(
392238dcc3SJonas Devlieghere            j1_Derived1_VBase_m_value.GetValueAsUnsigned(1),
402238dcc3SJonas Devlieghere            j1_Derived2_VBase_m_value.GetValueAsUnsigned(2),
412238dcc3SJonas Devlieghere            "ensure m_value in VBase is the same",
422238dcc3SJonas Devlieghere        )
432238dcc3SJonas Devlieghere        self.assertEqual(
442238dcc3SJonas Devlieghere            self.frame()
452238dcc3SJonas Devlieghere            .FindVariable("d")
462238dcc3SJonas Devlieghere            .GetChildAtIndex(0)
472238dcc3SJonas Devlieghere            .GetChildAtIndex(0)
482238dcc3SJonas Devlieghere            .GetValueAsUnsigned(0),
492238dcc3SJonas Devlieghere            12345,
502238dcc3SJonas Devlieghere            "ensure Derived2 from j1 is correct",
512238dcc3SJonas Devlieghere        )
5278e17e23SRaphael Isemann
5378e17e23SRaphael Isemann        # This reassigns 'd' to point to 'j2'.
5478e17e23SRaphael Isemann        self.thread().StepOver()
5578e17e23SRaphael Isemann
562238dcc3SJonas Devlieghere        self.assertEqual(
572238dcc3SJonas Devlieghere            self.frame()
582238dcc3SJonas Devlieghere            .FindVariable("d")
592238dcc3SJonas Devlieghere            .GetChildAtIndex(0)
602238dcc3SJonas Devlieghere            .GetChildAtIndex(0)
612238dcc3SJonas Devlieghere            .GetValueAsUnsigned(0),
622238dcc3SJonas Devlieghere            12346,
632238dcc3SJonas Devlieghere            "ensure Derived2 from j2 is correct",
642238dcc3SJonas Devlieghere        )
6578e17e23SRaphael Isemann
6678e17e23SRaphael Isemann    @no_debug_info_test
6778e17e23SRaphael Isemann    def test(self):
6878e17e23SRaphael Isemann        self.build()
692238dcc3SJonas Devlieghere        lldbutil.run_to_source_breakpoint(
702238dcc3SJonas Devlieghere            self, "// breakpoint 1", lldb.SBFileSpec("main.cpp")
712238dcc3SJonas Devlieghere        )
7278e17e23SRaphael Isemann
7378e17e23SRaphael Isemann        # All the children of j1.
7478e17e23SRaphael Isemann        children = [
752238dcc3SJonas Devlieghere            ValueCheck(
762238dcc3SJonas Devlieghere                type="Derived1",
772238dcc3SJonas Devlieghere                children=[
782238dcc3SJonas Devlieghere                    ValueCheck(
792238dcc3SJonas Devlieghere                        type="VBase",
802238dcc3SJonas Devlieghere                        children=[
8178e17e23SRaphael Isemann                            ValueCheck(type="int", name="m_value", value="12345")
822238dcc3SJonas Devlieghere                        ],
832238dcc3SJonas Devlieghere                    )
842238dcc3SJonas Devlieghere                ],
852238dcc3SJonas Devlieghere            ),
862238dcc3SJonas Devlieghere            ValueCheck(
872238dcc3SJonas Devlieghere                type="Derived2",
882238dcc3SJonas Devlieghere                children=[
892238dcc3SJonas Devlieghere                    ValueCheck(
902238dcc3SJonas Devlieghere                        type="VBase",
912238dcc3SJonas Devlieghere                        children=[
9278e17e23SRaphael Isemann                            ValueCheck(type="int", name="m_value", value="12345")
932238dcc3SJonas Devlieghere                        ],
942238dcc3SJonas Devlieghere                    )
952238dcc3SJonas Devlieghere                ],
962238dcc3SJonas Devlieghere            ),
9778e17e23SRaphael Isemann            ValueCheck(type="long", value="1"),
9878e17e23SRaphael Isemann        ]
9978e17e23SRaphael Isemann        # Try using the class with expression evaluator/variable paths.
10078e17e23SRaphael Isemann        self.expect_expr("j1", result_type="Joiner1", result_children=children)
10178e17e23SRaphael Isemann        self.expect_var_path("j1", type="Joiner1", children=children)
10278e17e23SRaphael Isemann
10378e17e23SRaphael Isemann        # Use the expression evaluator to access the members.
10478e17e23SRaphael Isemann        self.expect_expr("j1.x", result_type="long", result_value="1")
10578e17e23SRaphael Isemann        self.expect_expr("j1.m_value", result_type="int", result_value="12345")
10678e17e23SRaphael Isemann
10778e17e23SRaphael Isemann        # Use variable paths to access the members.
10878e17e23SRaphael Isemann        self.expect_var_path("j1.x", type="long", value="1")
10978e17e23SRaphael Isemann
11078e17e23SRaphael Isemann    @expectedFailureAll
11178e17e23SRaphael Isemann    @no_debug_info_test
112*a4c18137SMichael Buch    def test_invalid_member(self):
11378e17e23SRaphael Isemann        self.build()
1142238dcc3SJonas Devlieghere        lldbutil.run_to_source_breakpoint(
1152238dcc3SJonas Devlieghere            self, "// breakpoint 1", lldb.SBFileSpec("main.cpp")
1162238dcc3SJonas Devlieghere        )
11778e17e23SRaphael Isemann        # FIXME: This is completely broken and 'succeeds' with an error that
11878e17e23SRaphael Isemann        # there is noch such value/member in Joiner1. Move this up to the test
11978e17e23SRaphael Isemann        # above when fixed.
12078e17e23SRaphael Isemann        self.expect_var_path("j1.m_value", type="int", value="12345")
121