Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lldb / test / API / lang / objc / global_ptrs / TestGlobalObjects.py
blob76ca9c6ba92c55dbb9948af0784f43bc84ab9c43
1 """Test that a global ObjC object found before the process is started updates correctly."""
4 import lldb
5 from lldbsuite.test.decorators import *
6 from lldbsuite.test.lldbtest import *
7 from lldbsuite.test import lldbutil
10 class TestObjCGlobalVar(TestBase):
11 def setUp(self):
12 # Call super's setUp().
13 TestBase.setUp(self)
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."""
19 self.build()
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")
31 self.assertEqual(
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)
42 if len(threads) != 1:
43 self.fail("Failed to stop at breakpoint 1.")
45 thread = threads[0]
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")