1"""
2Test that objective-c expression parser continues to work for optimized build.
3
4Fixed a bug in the expression parser where the 'this'
5or 'self' variable was not properly read if the compiler
6optimized it into a register.
7"""
8
9
10
11import lldb
12import re
13
14from lldbsuite.test.decorators import *
15from lldbsuite.test.lldbtest import *
16from lldbsuite.test import lldbutil
17
18# rdar://problem/9087739
19# test failure: objc_optimized does not work for "-C clang -A i386"
20
21
22class ObjcOptimizedTestCase(TestBase):
23
24    mydir = TestBase.compute_mydir(__file__)
25    myclass = "MyClass"
26    mymethod = "description"
27    method_spec = "-[%s %s]" % (myclass, mymethod)
28
29    def test_break(self):
30        """Test 'expr member' continues to work for optimized build."""
31        self.build()
32        exe = self.getBuildArtifact("a.out")
33        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
34
35        lldbutil.run_break_set_by_symbol(
36            self,
37            self.method_spec,
38            num_expected_locations=1,
39            sym_exact=True)
40
41        self.runCmd("run", RUN_SUCCEEDED)
42        self.expect(
43            "thread backtrace",
44            STOPPED_DUE_TO_BREAKPOINT,
45            substrs=["stop reason = breakpoint"],
46            patterns=[
47                "frame.*0:.*%s %s" %
48                (self.myclass,
49                 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