• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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    mydir = TestBase.compute_mydir(__file__)
14
15    def setUp(self):
16        # Call super's setUp().
17        TestBase.setUp(self)
18        self.main_source = lldb.SBFileSpec("main.m")
19
20    @add_test_categories(['pyapi'])
21    def test_with_python_api(self):
22        """Test that a global ObjC object found before the process is started updates correctly."""
23        self.build()
24        exe = self.getBuildArtifact("a.out")
25
26        target = self.dbg.CreateTarget(exe)
27        self.assertTrue(target, VALID_TARGET)
28
29        bkpt = target.BreakpointCreateBySourceRegex('NSLog', self.main_source)
30        self.assertTrue(bkpt, VALID_BREAKPOINT)
31
32        # Before we launch, make an SBValue for our global object pointer:
33        g_obj_ptr = target.FindFirstGlobalVariable("g_obj_ptr")
34        self.assertTrue(g_obj_ptr.GetError().Success(), "Made the g_obj_ptr")
35        self.assertTrue(
36            g_obj_ptr.GetValueAsUnsigned(10) == 0,
37            "g_obj_ptr is initially null")
38
39        # Now launch the process, and do not stop at entry point.
40        process = target.LaunchSimple(
41            None, None, self.get_process_working_directory())
42
43        self.assertTrue(process, PROCESS_IS_VALID)
44
45        # The stop reason of the thread should be breakpoint.
46        threads = lldbutil.get_threads_stopped_at_breakpoint(process, bkpt)
47        if len(threads) != 1:
48            self.fail("Failed to stop at breakpoint 1.")
49
50        thread = threads[0]
51
52        dyn_value = g_obj_ptr.GetDynamicValue(lldb.eDynamicCanRunTarget)
53        self.assertTrue(
54            dyn_value.GetError().Success(),
55            "Dynamic value is valid")
56        self.assertEquals(dyn_value.GetObjectDescription(), "Some NSString")
57