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