1 """Test that a global ObjC object found before the process is started updates correctly."""
5 from lldbsuite
.test
.decorators
import *
6 from lldbsuite
.test
.lldbtest
import *
7 from lldbsuite
.test
import lldbutil
10 class TestObjCGlobalVar(TestBase
):
12 # Call super's setUp().
14 self
.main_source
= lldb
.SBFileSpec("main.m")
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."""
20 exe
= self
.getBuildArtifact("a.out")
22 target
= self
.dbg
.CreateTarget(exe
)
23 self
.assertTrue(target
, VALID_TARGET
)
25 bkpt
= target
.BreakpointCreateBySourceRegex("NSLog", self
.main_source
)
26 self
.assertTrue(bkpt
, VALID_BREAKPOINT
)
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")
32 g_obj_ptr
.GetValueAsUnsigned(10), 0, "g_obj_ptr is initially null"
35 # Now launch the process, and do not stop at entry point.
36 process
= target
.LaunchSimple(None, None, self
.get_process_working_directory())
38 self
.assertTrue(process
, PROCESS_IS_VALID
)
40 # The stop reason of the thread should be breakpoint.
41 threads
= lldbutil
.get_threads_stopped_at_breakpoint(process
, bkpt
)
43 self
.fail("Failed to stop at breakpoint 1.")
47 dyn_value
= g_obj_ptr
.GetDynamicValue(lldb
.eDynamicCanRunTarget
)
48 self
.assertTrue(dyn_value
.GetError().Success(), "Dynamic value is valid")
49 self
.assertEquals(dyn_value
.GetObjectDescription(), "Some NSString")