xref: /llvm-project/lldb/test/API/lang/cpp/dynamic-value-same-basename/TestDynamicValueSameBase.py (revision 2238dcc39358353cac21df75c3c3286ab20b8f53)
199451b44SJordan Rupprecht"""
299451b44SJordan RupprechtMake sure if we have two classes with the same base name the
399451b44SJordan Rupprechtdynamic value calculator doesn't confuse them
499451b44SJordan Rupprecht"""
599451b44SJordan Rupprecht
699451b44SJordan Rupprecht
799451b44SJordan Rupprechtimport lldb
899451b44SJordan Rupprechtimport lldbsuite.test.lldbutil as lldbutil
999451b44SJordan Rupprechtfrom lldbsuite.test.lldbtest import *
1099451b44SJordan Rupprecht
1199451b44SJordan Rupprecht
1299451b44SJordan Rupprechtclass DynamicValueSameBaseTestCase(TestBase):
13c6ad6901SVenkata Ramanaiah Nalamothu    # If your test case doesn't stress debug info, then
1499451b44SJordan Rupprecht    # set this to true.  That way it won't be run once for
1599451b44SJordan Rupprecht    # each debug info format.
1699451b44SJordan Rupprecht    NO_DEBUG_INFO_TESTCASE = True
1799451b44SJordan Rupprecht
1899451b44SJordan Rupprecht    def test_same_basename_this(self):
1999451b44SJordan Rupprecht        """Test that the we use the full name to resolve dynamic types."""
2099451b44SJordan Rupprecht        self.build()
2199451b44SJordan Rupprecht        self.main_source_file = lldb.SBFileSpec("main.cpp")
2299451b44SJordan Rupprecht        self.sample_test()
2399451b44SJordan Rupprecht
2499451b44SJordan Rupprecht    def sample_test(self):
25*2238dcc3SJonas Devlieghere        (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
26*2238dcc3SJonas Devlieghere            self, "Break here to get started", self.main_source_file
27*2238dcc3SJonas Devlieghere        )
2899451b44SJordan Rupprecht
2999451b44SJordan Rupprecht        # Set breakpoints in the two class methods and run to them:
30*2238dcc3SJonas Devlieghere        namesp_bkpt = target.BreakpointCreateBySourceRegex(
31*2238dcc3SJonas Devlieghere            "namesp function did something.", self.main_source_file
32*2238dcc3SJonas Devlieghere        )
33*2238dcc3SJonas Devlieghere        self.assertEqual(
34*2238dcc3SJonas Devlieghere            namesp_bkpt.GetNumLocations(), 1, "Namespace breakpoint invalid"
35*2238dcc3SJonas Devlieghere        )
3699451b44SJordan Rupprecht
37*2238dcc3SJonas Devlieghere        virtual_bkpt = target.BreakpointCreateBySourceRegex(
38*2238dcc3SJonas Devlieghere            "Virtual function did something.", self.main_source_file
39*2238dcc3SJonas Devlieghere        )
40*2238dcc3SJonas Devlieghere        self.assertEqual(
41*2238dcc3SJonas Devlieghere            virtual_bkpt.GetNumLocations(), 1, "Virtual breakpoint invalid"
42*2238dcc3SJonas Devlieghere        )
4399451b44SJordan Rupprecht
4499451b44SJordan Rupprecht        threads = lldbutil.continue_to_breakpoint(process, namesp_bkpt)
4599451b44SJordan Rupprecht        self.assertEqual(len(threads), 1, "Didn't stop at namespace breakpoint")
4699451b44SJordan Rupprecht
4799451b44SJordan Rupprecht        frame = threads[0].frame[0]
4899451b44SJordan Rupprecht        namesp_this = frame.FindVariable("this", lldb.eDynamicCanRunTarget)
4999451b44SJordan Rupprecht        # Clang specifies the type of this as "T *", gcc as "T * const". This
5099451b44SJordan Rupprecht        # erases the difference.
5199451b44SJordan Rupprecht        namesp_type = namesp_this.GetType().GetUnqualifiedType()
52*2238dcc3SJonas Devlieghere        self.assertEqual(
53*2238dcc3SJonas Devlieghere            namesp_type.GetName(),
54*2238dcc3SJonas Devlieghere            "namesp::Virtual *",
55*2238dcc3SJonas Devlieghere            "Didn't get the right dynamic type",
56*2238dcc3SJonas Devlieghere        )
5799451b44SJordan Rupprecht
5899451b44SJordan Rupprecht        threads = lldbutil.continue_to_breakpoint(process, virtual_bkpt)
5999451b44SJordan Rupprecht        self.assertEqual(len(threads), 1, "Didn't stop at virtual breakpoint")
6099451b44SJordan Rupprecht
6199451b44SJordan Rupprecht        frame = threads[0].frame[0]
6299451b44SJordan Rupprecht        virtual_this = frame.FindVariable("this", lldb.eDynamicCanRunTarget)
6399451b44SJordan Rupprecht        virtual_type = virtual_this.GetType().GetUnqualifiedType()
64*2238dcc3SJonas Devlieghere        self.assertEqual(
65*2238dcc3SJonas Devlieghere            virtual_type.GetName(), "Virtual *", "Didn't get the right dynamic type"
66*2238dcc3SJonas Devlieghere        )
67