blob: 55127c392fd7cfa8f2b9af3e8c673f2964b03fbb [file] [log] [blame]
Johnny Chen3b83d632011-03-04 18:17:49 +00001"""
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 *
Jim Ingham63dfc722012-09-22 00:05:11 +000014import lldbutil
Sean Callanan496970f2012-12-11 22:39:36 +000015import re
Johnny Chen3b83d632011-03-04 18:17:49 +000016
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
Greg Clayton4570d3e2013-12-10 23:19:29 +000022 mydir = TestBase.compute_mydir(__file__)
Johnny Chen3b83d632011-03-04 18:17:49 +000023 myclass = "MyClass"
24 mymethod = "description"
25 method_spec = "-[%s %s]" % (myclass, mymethod)
26
Johnny Chen24086bc2012-04-06 19:54:10 +000027 @dsym_test
Johnny Chen3b83d632011-03-04 18:17:49 +000028 def test_break_with_dsym(self):
29 """Test 'expr member' continues to work for optimized build."""
30 self.buildDsym()
31 self.objc_optimized()
32
Johnny Chen24086bc2012-04-06 19:54:10 +000033 @dwarf_test
Johnny Chen3b83d632011-03-04 18:17:49 +000034 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
Jim Ingham63dfc722012-09-22 00:05:11 +000044 lldbutil.run_break_set_by_symbol (self, self.method_spec, num_expected_locations=1, sym_exact=True)
Johnny Chen3b83d632011-03-04 18:17:49 +000045
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
Sean Callanan496970f2012-12-11 22:39:36 +000054 # <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])
Johnny Chen3b83d632011-03-04 18:17:49 +000069
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()