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 # If your test case doesn't stress debug info, then 16 # set this to true. That way it won't be run once for 17 # each debug info format. 18 NO_DEBUG_INFO_TESTCASE = True 19 20 def test_same_basename_this(self): 21 """Test that the we use the full name to resolve dynamic types.""" 22 self.build() 23 self.main_source_file = lldb.SBFileSpec("main.cpp") 24 self.sample_test() 25 26 def sample_test(self): 27 (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self, 28 "Break here to get started", self.main_source_file) 29 30 # Set breakpoints in the two class methods and run to them: 31 namesp_bkpt = target.BreakpointCreateBySourceRegex("namesp function did something.", self.main_source_file) 32 self.assertEqual(namesp_bkpt.GetNumLocations(), 1, "Namespace breakpoint invalid") 33 34 virtual_bkpt = target.BreakpointCreateBySourceRegex("Virtual function did something.", self.main_source_file) 35 self.assertEqual(virtual_bkpt.GetNumLocations(), 1, "Virtual breakpoint invalid") 36 37 threads = lldbutil.continue_to_breakpoint(process, namesp_bkpt) 38 self.assertEqual(len(threads), 1, "Didn't stop at namespace breakpoint") 39 40 frame = threads[0].frame[0] 41 namesp_this = frame.FindVariable("this", lldb.eDynamicCanRunTarget) 42 # Clang specifies the type of this as "T *", gcc as "T * const". This 43 # erases the difference. 44 namesp_type = namesp_this.GetType().GetUnqualifiedType() 45 self.assertEqual(namesp_type.GetName(), "namesp::Virtual *", "Didn't get the right dynamic type") 46 47 threads = lldbutil.continue_to_breakpoint(process, virtual_bkpt) 48 self.assertEqual(len(threads), 1, "Didn't stop at virtual breakpoint") 49 50 frame = threads[0].frame[0] 51 virtual_this = frame.FindVariable("this", lldb.eDynamicCanRunTarget) 52 virtual_type = virtual_this.GetType().GetUnqualifiedType() 53 self.assertEqual(virtual_type.GetName(), "Virtual *", "Didn't get the right dynamic type") 54 55 56 57