blob: e6a5958d2c1048dcaa87e0afaee9848a3b7d435c [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"
Robert Flack13c7ad92015-03-30 14:12:17 +000019@skipUnlessDarwin
Johnny Chen3b83d632011-03-04 18:17:49 +000020class 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
Tamas Berghammerc8fd1302015-09-30 10:12:40 +000027 def test_break(self):
Johnny Chen3b83d632011-03-04 18:17:49 +000028 """Test 'expr member' continues to work for optimized build."""
Tamas Berghammerc8fd1302015-09-30 10:12:40 +000029 self.build()
Johnny Chen3b83d632011-03-04 18:17:49 +000030 exe = os.path.join(os.getcwd(), "a.out")
31 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
32
Jim Ingham63dfc722012-09-22 00:05:11 +000033 lldbutil.run_break_set_by_symbol (self, self.method_spec, num_expected_locations=1, sym_exact=True)
Johnny Chen3b83d632011-03-04 18:17:49 +000034
Sean Callanan05834cd2015-07-01 23:56:30 +000035 self.runCmd("run", RUN_SUCCEEDED)
Johnny Chen3b83d632011-03-04 18:17:49 +000036 self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT,
37 substrs = ["stop reason = breakpoint"],
38 patterns = ["frame.*0:.*%s %s" % (self.myclass, self.mymethod)])
39
40 self.expect('expression member',
41 startstr = "(int) $0 = 5")
42
Sean Callanan496970f2012-12-11 22:39:36 +000043 # <rdar://problem/12693963>
44 interp = self.dbg.GetCommandInterpreter()
45 result = lldb.SBCommandReturnObject()
46 interp.HandleCommand('frame variable self', result)
47 output = result.GetOutput()
48
49 desired_pointer = "0x0"
50
51 mo = re.search("0x[0-9a-f]+", output)
52
53 if mo:
54 desired_pointer = mo.group(0)
55
56 self.expect('expression (self)',
57 substrs = [("(%s *) $1 = " % self.myclass), desired_pointer])
Johnny Chen3b83d632011-03-04 18:17:49 +000058
59 self.expect('expression self->non_member', error=True,
60 substrs = ["does not have a member named 'non_member'"])
61
62
63if __name__ == '__main__':
64 import atexit
65 lldb.SBDebugger.Initialize()
66 atexit.register(lambda: lldb.SBDebugger.Terminate())
67 unittest2.main()