1"""
2Tests that ObjC member variables are available where they should be.
3"""
4import lldb
5from lldbsuite.test.decorators import *
6from lldbsuite.test.lldbtest import *
7from lldbsuite.test import lldbutil
8
9
10class ObjCSelfTestCase(TestBase):
11
12    mydir = TestBase.compute_mydir(__file__)
13
14    @skipUnlessDarwin
15    def test_with_run_command(self):
16        """Test that the appropriate member variables are available when stopped in Objective-C class and instance methods"""
17        self.build()
18        self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
19
20        self.set_breakpoint(line_number('main.m', '// breakpoint 1'))
21        self.set_breakpoint(line_number('main.m', '// breakpoint 2'))
22
23        self.runCmd("process launch", RUN_SUCCEEDED)
24
25        self.expect("expression -- m_a = 2",
26                    startstr="(int) $0 = 2")
27
28        self.runCmd("process continue")
29
30        # This would be disallowed if we enforced const.  But we don't.
31        self.expect("expression -- m_a = 2",
32                    error=True)
33
34        self.expect("expression -- s_a",
35                    startstr="(int) $1 = 5")
36
37    def set_breakpoint(self, line):
38        lldbutil.run_break_set_by_file_and_line(
39            self, "main.m", line, num_expected_locations=1, loc_exact=True)
40