Home | History | Annotate | Download | only in objc-ivar-stripped
      1 """Test printing ObjC objects that use unbacked properties - so that the static ivar offsets are incorrect."""
      2 
      3 import os, time
      4 import unittest2
      5 import lldb
      6 from lldbtest import *
      7 import lldbutil
      8 
      9 class TestObjCIvarStripped(TestBase):
     10 
     11     mydir = os.path.join("lang", "objc", "objc-ivar-stripped")
     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 that we can find stripped Objective-C ivars in the runtime"""
     18         self.buildDsym()
     19         self.objc_ivar_offsets()
     20 
     21     def setUp(self):
     22         # Call super's setUp().
     23         TestBase.setUp(self)
     24         # Find the line numbers to break inside main().
     25         self.main_source = "main.m"
     26         self.stop_line = line_number(self.main_source, '// Set breakpoint here.')
     27 
     28     def objc_ivar_offsets(self):
     29         """Test that we can find stripped Objective-C ivars in the runtime"""
     30         exe = os.path.join(os.getcwd(), "a.out.stripped")
     31 
     32         target = self.dbg.CreateTarget(exe)
     33         self.assertTrue(target, VALID_TARGET)
     34 
     35         breakpoint = target.BreakpointCreateByLocation(self.main_source, self.stop_line)
     36         self.assertTrue(breakpoint, VALID_BREAKPOINT)
     37 
     38         process = target.LaunchSimple (None, None, os.getcwd())
     39         self.assertTrue (process, "Created a process.")
     40         self.assertTrue (process.GetState() == lldb.eStateStopped, "Stopped it too.")
     41 
     42         thread_list = lldbutil.get_threads_stopped_at_breakpoint (process, breakpoint)
     43         self.assertTrue (len(thread_list) == 1)
     44         thread = thread_list[0]
     45         
     46         frame = thread.GetFrameAtIndex(0)
     47         self.assertTrue (frame, "frame 0 is valid")
     48         
     49         # Test the expression for mc->_foo
     50 
     51         error = lldb.SBError()
     52 
     53         ivar = frame.EvaluateExpression ("(mc->_foo)")
     54         self.assertTrue(ivar, "Got result for mc->_foo")
     55         ivar_value = ivar.GetValueAsSigned (error)
     56         self.assertTrue (error.Success())
     57         self.assertTrue (ivar_value == 3)
     58         
     59 if __name__ == '__main__':
     60     import atexit
     61     lldb.SBDebugger.Initialize()
     62     atexit.register(lambda: lldb.SBDebugger.Terminate())
     63     unittest2.main()
     64