1""" 2Test that objective-c expression parser continues to work for optimized build. 3 4http://llvm.org/viewvc/llvm-project?rev=126973&view=rev 5Fixed a bug in the expression parser where the 'this' 6or 'self' variable was not properly read if the compiler 7optimized it into a register. 8""" 9 10import os, time 11import unittest2 12import lldb 13from lldbtest import * 14import lldbutil 15import 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") 20class 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 74if __name__ == '__main__': 75 import atexit 76 lldb.SBDebugger.Initialize() 77 atexit.register(lambda: lldb.SBDebugger.Terminate()) 78 unittest2.main() 79