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    @add_test_categories(['pyapi'])
24    def test_with_python_api(self):
25        """Test printing ObjC objects that use unbacked properties"""
26        self.build()
27        exe = self.getBuildArtifact("a.out")
28
29        target = self.dbg.CreateTarget(exe)
30        self.assertTrue(target, VALID_TARGET)
31
32        breakpoint = target.BreakpointCreateByLocation(
33            self.main_source, self.stop_line)
34        self.assertTrue(breakpoint, VALID_BREAKPOINT)
35
36        process = target.LaunchSimple(
37            None, None, self.get_process_working_directory())
38        self.assertTrue(process, "Created a process.")
39        self.assertEqual(
40            process.GetState(), lldb.eStateStopped,
41            "Stopped it too.")
42
43        thread_list = lldbutil.get_threads_stopped_at_breakpoint(
44            process, breakpoint)
45        self.assertEquals(len(thread_list), 1)
46        thread = thread_list[0]
47
48        frame = thread.GetFrameAtIndex(0)
49        self.assertTrue(frame, "frame 0 is valid")
50
51        mine = thread.GetFrameAtIndex(0).FindVariable("mine")
52        self.assertTrue(mine, "Found local variable mine.")
53
54        # Test the value object value for BaseClass->_backed_int
55
56        error = lldb.SBError()
57
58        mine_backed_int = mine.GetChildMemberWithName("_backed_int")
59        self.assertTrue(
60            mine_backed_int,
61            "Found mine->backed_int local variable.")
62        backed_value = mine_backed_int.GetValueAsSigned(error)
63        self.assertTrue(error.Success())
64        self.assertEquals(backed_value, 1111)
65
66        # Test the value object value for DerivedClass->_derived_backed_int
67
68        mine_derived_backed_int = mine.GetChildMemberWithName(
69            "_derived_backed_int")
70        self.assertTrue(mine_derived_backed_int,
71                        "Found mine->derived_backed_int local variable.")
72        derived_backed_value = mine_derived_backed_int.GetValueAsSigned(error)
73        self.assertTrue(error.Success())
74        self.assertEquals(derived_backed_value, 3333)
75
76        # Make sure we also get bit-field offsets correct:
77
78        mine_flag2 = mine.GetChildMemberWithName("flag2")
79        self.assertTrue(mine_flag2, "Found mine->flag2 local variable.")
80        flag2_value = mine_flag2.GetValueAsUnsigned(error)
81        self.assertTrue(error.Success())
82        self.assertEquals(flag2_value, 7)
83