xref: /llvm-project/lldb/test/API/lang/cpp/dynamic-value-same-basename/TestDynamicValueSameBase.py (revision 99451b4453688a94c6014cac233d371ab4cc342d)
1"""
2Make sure if we have two classes with the same base name the
3dynamic value calculator doesn't confuse them
4"""
5
6
7
8import lldb
9import lldbsuite.test.lldbutil as lldbutil
10from lldbsuite.test.lldbtest import *
11
12
13class DynamicValueSameBaseTestCase(TestBase):
14
15    mydir = TestBase.compute_mydir(__file__)
16
17    # If your test case doesn't stress debug info, the
18    # set this to true.  That way it won't be run once for
19    # each debug info format.
20    NO_DEBUG_INFO_TESTCASE = True
21
22    def test_same_basename_this(self):
23        """Test that the we use the full name to resolve dynamic types."""
24        self.build()
25        self.main_source_file = lldb.SBFileSpec("main.cpp")
26        self.sample_test()
27
28    def sample_test(self):
29        (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self,
30                                   "Break here to get started", self.main_source_file)
31
32        # Set breakpoints in the two class methods and run to them:
33        namesp_bkpt = target.BreakpointCreateBySourceRegex("namesp function did something.", self.main_source_file)
34        self.assertEqual(namesp_bkpt.GetNumLocations(), 1, "Namespace breakpoint invalid")
35
36        virtual_bkpt = target.BreakpointCreateBySourceRegex("Virtual function did something.", self.main_source_file)
37        self.assertEqual(virtual_bkpt.GetNumLocations(), 1, "Virtual breakpoint invalid")
38
39        threads = lldbutil.continue_to_breakpoint(process, namesp_bkpt)
40        self.assertEqual(len(threads), 1, "Didn't stop at namespace breakpoint")
41
42        frame = threads[0].frame[0]
43        namesp_this = frame.FindVariable("this", lldb.eDynamicCanRunTarget)
44        # Clang specifies the type of this as "T *", gcc as "T * const". This
45        # erases the difference.
46        namesp_type = namesp_this.GetType().GetUnqualifiedType()
47        self.assertEqual(namesp_type.GetName(), "namesp::Virtual *", "Didn't get the right dynamic type")
48
49        threads = lldbutil.continue_to_breakpoint(process, virtual_bkpt)
50        self.assertEqual(len(threads), 1, "Didn't stop at virtual breakpoint")
51
52        frame = threads[0].frame[0]
53        virtual_this = frame.FindVariable("this", lldb.eDynamicCanRunTarget)
54        virtual_type = virtual_this.GetType().GetUnqualifiedType()
55        self.assertEqual(virtual_type.GetName(), "Virtual *", "Didn't get the right dynamic type")
56
57
58
59