1 """Test that a global ObjC object found before the process is started updates correctly."""
3 from __future__ import print_function
9 from lldbsuite.test.decorators import *
10 from lldbsuite.test.lldbtest import *
11 from lldbsuite.test import lldbutil
14 class TestObjCGlobalVar(TestBase):
16 mydir = TestBase.compute_mydir(__file__)
19 # Call super's setUp().
21 self.main_source = lldb.SBFileSpec("main.m")
24 @add_test_categories(['pyapi'])
25 def test_with_python_api(self):
26 """Test that a global ObjC object found before the process is started updates correctly."""
28 exe = os.path.join(os.getcwd(), "a.out")
30 target = self.dbg.CreateTarget(exe)
31 self.assertTrue(target, VALID_TARGET)
33 bkpt = target.BreakpointCreateBySourceRegex('NSLog', self.main_source)
34 self.assertTrue(bkpt, VALID_BREAKPOINT)
36 # Before we launch, make an SBValue for our global object pointer:
37 g_obj_ptr = target.FindFirstGlobalVariable("g_obj_ptr")
38 self.assertTrue(g_obj_ptr.GetError().Success(), "Made the g_obj_ptr")
40 g_obj_ptr.GetValueAsUnsigned(10) == 0,
41 "g_obj_ptr is initially null")
43 # Now launch the process, and do not stop at entry point.
44 process = target.LaunchSimple(
45 None, None, self.get_process_working_directory())
47 self.assertTrue(process, PROCESS_IS_VALID)
49 # The stop reason of the thread should be breakpoint.
50 threads = lldbutil.get_threads_stopped_at_breakpoint(process, bkpt)
52 self.fail("Failed to stop at breakpoint 1.")
56 dyn_value = g_obj_ptr.GetDynamicValue(lldb.eDynamicCanRunTarget)
58 dyn_value.GetError().Success(),
59 "Dynamic value is valid")
60 self.assertTrue(dyn_value.GetObjectDescription() == "Some NSString")