1"""Test printing ObjC objects that use unbacked properties - so that the static ivar offsets are incorrect.""" 2 3 4 5import lldb 6from lldbsuite.test.decorators import * 7from lldbsuite.test.lldbtest import * 8from lldbsuite.test import lldbutil 9 10 11class TestObjCIvarOffsets(TestBase): 12 13 def setUp(self): 14 # Call super's setUp(). 15 TestBase.setUp(self) 16 # Find the line numbers to break inside main(). 17 self.main_source = "main.m" 18 self.stop_line = line_number( 19 self.main_source, '// Set breakpoint here.') 20 21 @add_test_categories(['pyapi']) 22 def test_with_python_api(self): 23 """Test printing ObjC objects that use unbacked properties""" 24 self.build() 25 exe = self.getBuildArtifact("a.out") 26 27 target = self.dbg.CreateTarget(exe) 28 self.assertTrue(target, VALID_TARGET) 29 30 breakpoint = target.BreakpointCreateByLocation( 31 self.main_source, self.stop_line) 32 self.assertTrue(breakpoint, VALID_BREAKPOINT) 33 34 process = target.LaunchSimple( 35 None, None, self.get_process_working_directory()) 36 self.assertTrue(process, "Created a process.") 37 self.assertEqual( 38 process.GetState(), lldb.eStateStopped, 39 "Stopped it too.") 40 41 thread_list = lldbutil.get_threads_stopped_at_breakpoint( 42 process, breakpoint) 43 self.assertEquals(len(thread_list), 1) 44 thread = thread_list[0] 45 46 frame = thread.GetFrameAtIndex(0) 47 self.assertTrue(frame, "frame 0 is valid") 48 49 mine = thread.GetFrameAtIndex(0).FindVariable("mine") 50 self.assertTrue(mine, "Found local variable mine.") 51 52 # Test the value object value for BaseClass->_backed_int 53 54 error = lldb.SBError() 55 56 mine_backed_int = mine.GetChildMemberWithName("_backed_int") 57 self.assertTrue( 58 mine_backed_int, 59 "Found mine->backed_int local variable.") 60 backed_value = mine_backed_int.GetValueAsSigned(error) 61 self.assertSuccess(error) 62 self.assertEquals(backed_value, 1111) 63 64 # Test the value object value for DerivedClass->_derived_backed_int 65 66 mine_derived_backed_int = mine.GetChildMemberWithName( 67 "_derived_backed_int") 68 self.assertTrue(mine_derived_backed_int, 69 "Found mine->derived_backed_int local variable.") 70 derived_backed_value = mine_derived_backed_int.GetValueAsSigned(error) 71 self.assertSuccess(error) 72 self.assertEquals(derived_backed_value, 3333) 73 74 # Make sure we also get bit-field offsets correct: 75 76 mine_flag2 = mine.GetChildMemberWithName("flag2") 77 self.assertTrue(mine_flag2, "Found mine->flag2 local variable.") 78 flag2_value = mine_flag2.GetValueAsUnsigned(error) 79 self.assertSuccess(error) 80 self.assertEquals(flag2_value, 7) 81