| Johnny Chen | 3b83d63 | 2011-03-04 18:17:49 +0000 | [diff] [blame] | 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 * |
| Jim Ingham | 63dfc72 | 2012-09-22 00:05:11 +0000 | [diff] [blame] | 14 | import lldbutil |
| Sean Callanan | 496970f | 2012-12-11 22:39:36 +0000 | [diff] [blame] | 15 | import re |
| Johnny Chen | 3b83d63 | 2011-03-04 18:17:49 +0000 | [diff] [blame] | 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 | |
| Greg Clayton | 4570d3e | 2013-12-10 23:19:29 +0000 | [diff] [blame^] | 22 | mydir = TestBase.compute_mydir(__file__) |
| Johnny Chen | 3b83d63 | 2011-03-04 18:17:49 +0000 | [diff] [blame] | 23 | myclass = "MyClass" |
| 24 | mymethod = "description" |
| 25 | method_spec = "-[%s %s]" % (myclass, mymethod) |
| 26 | |
| Johnny Chen | 24086bc | 2012-04-06 19:54:10 +0000 | [diff] [blame] | 27 | @dsym_test |
| Johnny Chen | 3b83d63 | 2011-03-04 18:17:49 +0000 | [diff] [blame] | 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 | |
| Johnny Chen | 24086bc | 2012-04-06 19:54:10 +0000 | [diff] [blame] | 33 | @dwarf_test |
| Johnny Chen | 3b83d63 | 2011-03-04 18:17:49 +0000 | [diff] [blame] | 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 | |
| Jim Ingham | 63dfc72 | 2012-09-22 00:05:11 +0000 | [diff] [blame] | 44 | lldbutil.run_break_set_by_symbol (self, self.method_spec, num_expected_locations=1, sym_exact=True) |
| Johnny Chen | 3b83d63 | 2011-03-04 18:17:49 +0000 | [diff] [blame] | 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 | |
| Sean Callanan | 496970f | 2012-12-11 22:39:36 +0000 | [diff] [blame] | 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]) |
| Johnny Chen | 3b83d63 | 2011-03-04 18:17:49 +0000 | [diff] [blame] | 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() |