1"""Test that a global ObjC object found before the process is started updates correctly.""" 2 3 4 5import lldb 6from lldbsuite.test.decorators import * 7from lldbsuite.test.lldbtest import * 8from lldbsuite.test import lldbutil 9 10 11class TestObjCGlobalVar(TestBase): 12 13 def setUp(self): 14 # Call super's setUp(). 15 TestBase.setUp(self) 16 self.main_source = lldb.SBFileSpec("main.m") 17 18 @add_test_categories(['pyapi']) 19 def test_with_python_api(self): 20 """Test that a global ObjC object found before the process is started updates correctly.""" 21 self.build() 22 exe = self.getBuildArtifact("a.out") 23 24 target = self.dbg.CreateTarget(exe) 25 self.assertTrue(target, VALID_TARGET) 26 27 bkpt = target.BreakpointCreateBySourceRegex('NSLog', self.main_source) 28 self.assertTrue(bkpt, VALID_BREAKPOINT) 29 30 # Before we launch, make an SBValue for our global object pointer: 31 g_obj_ptr = target.FindFirstGlobalVariable("g_obj_ptr") 32 self.assertSuccess(g_obj_ptr.GetError(), "Made the g_obj_ptr") 33 self.assertEqual( 34 g_obj_ptr.GetValueAsUnsigned(10), 0, 35 "g_obj_ptr is initially null") 36 37 # Now launch the process, and do not stop at entry point. 38 process = target.LaunchSimple( 39 None, None, self.get_process_working_directory()) 40 41 self.assertTrue(process, PROCESS_IS_VALID) 42 43 # The stop reason of the thread should be breakpoint. 44 threads = lldbutil.get_threads_stopped_at_breakpoint(process, bkpt) 45 if len(threads) != 1: 46 self.fail("Failed to stop at breakpoint 1.") 47 48 thread = threads[0] 49 50 dyn_value = g_obj_ptr.GetDynamicValue(lldb.eDynamicCanRunTarget) 51 self.assertTrue( 52 dyn_value.GetError().Success(), 53 "Dynamic value is valid") 54 self.assertEquals(dyn_value.GetObjectDescription(), "Some NSString") 55