]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/lang/objc/global_ptrs/TestGlobalObjects.py
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / lang / objc / global_ptrs / TestGlobalObjects.py
1 """Test that a global ObjC object found before the process is started updates correctly."""
2
3 from __future__ import print_function
4
5
6 import os
7 import time
8 import lldb
9 from lldbsuite.test.decorators import *
10 from lldbsuite.test.lldbtest import *
11 from lldbsuite.test import lldbutil
12
13
14 class TestObjCGlobalVar(TestBase):
15
16     mydir = TestBase.compute_mydir(__file__)
17
18     def setUp(self):
19         # Call super's setUp().
20         TestBase.setUp(self)
21         self.main_source = lldb.SBFileSpec("main.m")
22
23     @skipUnlessDarwin
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."""
27         self.build()
28         exe = os.path.join(os.getcwd(), "a.out")
29
30         target = self.dbg.CreateTarget(exe)
31         self.assertTrue(target, VALID_TARGET)
32
33         bkpt = target.BreakpointCreateBySourceRegex('NSLog', self.main_source)
34         self.assertTrue(bkpt, VALID_BREAKPOINT)
35
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")
39         self.assertTrue(
40             g_obj_ptr.GetValueAsUnsigned(10) == 0,
41             "g_obj_ptr is initially null")
42
43         # Now launch the process, and do not stop at entry point.
44         process = target.LaunchSimple(
45             None, None, self.get_process_working_directory())
46
47         self.assertTrue(process, PROCESS_IS_VALID)
48
49         # The stop reason of the thread should be breakpoint.
50         threads = lldbutil.get_threads_stopped_at_breakpoint(process, bkpt)
51         if len(threads) != 1:
52             self.fail("Failed to stop at breakpoint 1.")
53
54         thread = threads[0]
55
56         dyn_value = g_obj_ptr.GetDynamicValue(lldb.eDynamicCanRunTarget)
57         self.assertTrue(
58             dyn_value.GetError().Success(),
59             "Dynamic value is valid")
60         self.assertTrue(dyn_value.GetObjectDescription() == "Some NSString")