Home | History | Annotate | Download | only in objc-optimized
      1 """
      2 Test that objective-c expression parser continues to work for optimized build.
      3 
      4 http://llvm.org/viewvc/llvm-project?rev=126973&view=rev
      5 Fixed a bug in the expression parser where the 'this'
      6 or 'self' variable was not properly read if the compiler
      7 optimized it into a register.
      8 """
      9 
     10 import os, time
     11 import unittest2
     12 import lldb
     13 from lldbtest import *
     14 import lldbutil
     15 import re
     16 
     17 # rdar://problem/9087739
     18 # test failure: objc_optimized does not work for "-C clang -A i386"
     19 @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
     20 class ObjcOptimizedTestCase(TestBase):
     21 
     22     mydir = os.path.join("lang", "objc", "objc-optimized")
     23     myclass = "MyClass"
     24     mymethod = "description"
     25     method_spec = "-[%s %s]" % (myclass, mymethod)
     26 
     27     @dsym_test
     28     def test_break_with_dsym(self):
     29         """Test 'expr member' continues to work for optimized build."""
     30         self.buildDsym()
     31         self.objc_optimized()
     32 
     33     @dwarf_test
     34     def test_break_with_dwarf(self):
     35         """Test 'expr member' continues to work for optimized build."""
     36         self.buildDwarf()
     37         self.objc_optimized()
     38 
     39     def objc_optimized(self):
     40         """Test 'expr member' continues to work for optimized build."""
     41         exe = os.path.join(os.getcwd(), "a.out")
     42         self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
     43 
     44         lldbutil.run_break_set_by_symbol (self, self.method_spec, num_expected_locations=1, sym_exact=True)
     45 
     46         self.runCmd("run", RUN_SUCCEEDED)
     47         self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT,
     48             substrs = ["stop reason = breakpoint"],
     49             patterns = ["frame.*0:.*%s %s" % (self.myclass, self.mymethod)])
     50 
     51         self.expect('expression member',
     52             startstr = "(int) $0 = 5")
     53 
     54         # <rdar://problem/12693963>
     55         interp = self.dbg.GetCommandInterpreter()
     56         result = lldb.SBCommandReturnObject()
     57         interp.HandleCommand('frame variable self', result)
     58         output = result.GetOutput()
     59 
     60         desired_pointer = "0x0"
     61 
     62         mo = re.search("0x[0-9a-f]+", output)
     63 
     64         if mo:
     65             desired_pointer = mo.group(0)
     66 
     67         self.expect('expression (self)',
     68             substrs = [("(%s *) $1 = " % self.myclass), desired_pointer])
     69 
     70         self.expect('expression self->non_member', error=True,
     71             substrs = ["does not have a member named 'non_member'"])
     72 
     73         
     74 if __name__ == '__main__':
     75     import atexit
     76     lldb.SBDebugger.Initialize()
     77     atexit.register(lambda: lldb.SBDebugger.Terminate())
     78     unittest2.main()
     79