• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1"""Test printing ObjC objects that use unbacked properties - so that the static ivar offsets are incorrect."""
2
3import os, time
4import unittest2
5import lldb
6from lldbtest import *
7import lldbutil
8
9class TestObjCIvarOffsets(TestBase):
10
11    mydir = os.path.join("lang", "objc", "objc-ivar-offsets")
12
13    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
14    @python_api_test
15    @dsym_test
16    def test_with_dsym_and_python_api(self):
17        """Test printing ObjC objects that use unbacked properties"""
18        self.buildDsym()
19        self.objc_ivar_offsets()
20
21    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
22    @python_api_test
23    @dwarf_test
24    def test_with_dwarf_and_python_api(self):
25        """Test printing ObjC objects that use unbacked properties"""
26        self.buildDwarf()
27        self.objc_ivar_offsets()
28
29    def setUp(self):
30        # Call super's setUp().
31        TestBase.setUp(self)
32        # Find the line numbers to break inside main().
33        self.main_source = "main.m"
34        self.stop_line = line_number(self.main_source, '// Set breakpoint here.')
35
36    def objc_ivar_offsets(self):
37        """Use Python APIs to test stepping into ObjC methods."""
38        exe = os.path.join(os.getcwd(), "a.out")
39
40        target = self.dbg.CreateTarget(exe)
41        self.assertTrue(target, VALID_TARGET)
42
43        breakpoint = target.BreakpointCreateByLocation(self.main_source, self.stop_line)
44        self.assertTrue(breakpoint, VALID_BREAKPOINT)
45
46        process = target.LaunchSimple (None, None, os.getcwd())
47        self.assertTrue (process, "Created a process.")
48        self.assertTrue (process.GetState() == lldb.eStateStopped, "Stopped it too.")
49
50        thread_list = lldbutil.get_threads_stopped_at_breakpoint (process, breakpoint)
51        self.assertTrue (len(thread_list) == 1)
52        thread = thread_list[0]
53
54        frame = thread.GetFrameAtIndex(0)
55        self.assertTrue (frame, "frame 0 is valid")
56
57        mine = thread.GetFrameAtIndex(0).FindVariable("mine")
58        self.assertTrue(mine, "Found local variable mine.")
59
60        # Test the value object value for BaseClass->_backed_int
61
62        error = lldb.SBError()
63
64        mine_backed_int = mine.GetChildMemberWithName ("_backed_int")
65        self.assertTrue(mine_backed_int, "Found mine->backed_int local variable.")
66        backed_value = mine_backed_int.GetValueAsSigned (error)
67        self.assertTrue (error.Success())
68        self.assertTrue (backed_value == 1111)
69
70        # Test the value object value for DerivedClass->_derived_backed_int
71
72        mine_derived_backed_int = mine.GetChildMemberWithName ("_derived_backed_int")
73        self.assertTrue(mine_derived_backed_int, "Found mine->derived_backed_int local variable.")
74        derived_backed_value = mine_derived_backed_int.GetValueAsSigned (error)
75        self.assertTrue (error.Success())
76        self.assertTrue (derived_backed_value == 3333)
77
78        # Make sure we also get bit-field offsets correct:
79
80        mine_flag2 = mine.GetChildMemberWithName ("flag2")
81        self.assertTrue(mine_flag2, "Found mine->flag2 local variable.")
82        flag2_value = mine_flag2.GetValueAsUnsigned (error)
83        self.assertTrue (error.Success())
84        self.assertTrue (flag2_value == 7)
85
86if __name__ == '__main__':
87    import atexit
88    lldb.SBDebugger.Initialize()
89    atexit.register(lambda: lldb.SBDebugger.Terminate())
90    unittest2.main()
91