1"""Test printing ObjC objects that use unbacked properties - so that the static ivar offsets are incorrect."""
2
3
4
5import lldb
6from lldbsuite.test.decorators import *
7from lldbsuite.test.lldbtest import *
8from lldbsuite.test import lldbutil
9
10
11class TestObjCIvarOffsets(TestBase):
12
13    mydir = TestBase.compute_mydir(__file__)
14
15    def setUp(self):
16        # Call super's setUp().
17        TestBase.setUp(self)
18        # Find the line numbers to break inside main().
19        self.main_source = "main.m"
20        self.stop_line = line_number(
21            self.main_source, '// Set breakpoint here.')
22
23    @skipUnlessDarwin
24    @add_test_categories(['pyapi'])
25    def test_with_python_api(self):
26        """Test printing ObjC objects that use unbacked properties"""
27        self.build()
28        exe = self.getBuildArtifact("a.out")
29
30        target = self.dbg.CreateTarget(exe)
31        self.assertTrue(target, VALID_TARGET)
32
33        breakpoint = target.BreakpointCreateByLocation(
34            self.main_source, self.stop_line)
35        self.assertTrue(breakpoint, VALID_BREAKPOINT)
36
37        process = target.LaunchSimple(
38            None, None, self.get_process_working_directory())
39        self.assertTrue(process, "Created a process.")
40        self.assertTrue(
41            process.GetState() == lldb.eStateStopped,
42            "Stopped it too.")
43
44        thread_list = lldbutil.get_threads_stopped_at_breakpoint(
45            process, breakpoint)
46        self.assertEquals(len(thread_list), 1)
47        thread = thread_list[0]
48
49        frame = thread.GetFrameAtIndex(0)
50        self.assertTrue(frame, "frame 0 is valid")
51
52        mine = thread.GetFrameAtIndex(0).FindVariable("mine")
53        self.assertTrue(mine, "Found local variable mine.")
54
55        # Test the value object value for BaseClass->_backed_int
56
57        error = lldb.SBError()
58
59        mine_backed_int = mine.GetChildMemberWithName("_backed_int")
60        self.assertTrue(
61            mine_backed_int,
62            "Found mine->backed_int local variable.")
63        backed_value = mine_backed_int.GetValueAsSigned(error)
64        self.assertTrue(error.Success())
65        self.assertEquals(backed_value, 1111)
66
67        # Test the value object value for DerivedClass->_derived_backed_int
68
69        mine_derived_backed_int = mine.GetChildMemberWithName(
70            "_derived_backed_int")
71        self.assertTrue(mine_derived_backed_int,
72                        "Found mine->derived_backed_int local variable.")
73        derived_backed_value = mine_derived_backed_int.GetValueAsSigned(error)
74        self.assertTrue(error.Success())
75        self.assertEquals(derived_backed_value, 3333)
76
77        # Make sure we also get bit-field offsets correct:
78
79        mine_flag2 = mine.GetChildMemberWithName("flag2")
80        self.assertTrue(mine_flag2, "Found mine->flag2 local variable.")
81        flag2_value = mine_flag2.GetValueAsUnsigned(error)
82        self.assertTrue(error.Success())
83        self.assertEquals(flag2_value, 7)
84