1"""Test evaluating expressions which ref. index variable 'i' which just goes
2from out of scope to in scope when stopped at the breakpoint."""
3
4import unittest2
5import lldb
6from lldbtest import *
7import lldbutil
8
9class NonOverlappingIndexVariableCase(TestBase):
10
11    mydir = os.path.join("functionalities", "non-overlapping-index-variable-i")
12
13    def setUp(self):
14        TestBase.setUp(self)
15        self.source = 'main.cpp'
16        self.line_to_break = line_number(self.source, '// Set breakpoint here.')
17
18    # rdar://problem/9890530
19    def test_eval_index_variable(self):
20        """Test expressions of variable 'i' which appears in two for loops."""
21        self.buildDefault()
22        self.exe_name = 'a.out'
23        self.eval_index_variable_i(self.exe_name)
24
25    def eval_index_variable_i(self, exe_name):
26        """Test expressions of variable 'i' which appears in two for loops."""
27        exe = os.path.join(os.getcwd(), exe_name)
28        self.runCmd("file %s" % exe, CURRENT_EXECUTABLE_SET)
29
30        lldbutil.run_break_set_by_file_and_line (self, self.source, self.line_to_break, num_expected_locations=1, loc_exact=True)
31
32        self.runCmd("run", RUN_SUCCEEDED)
33
34        # The stop reason of the thread should be breakpoint.
35        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
36            substrs = ['stopped',
37                       'stop reason = breakpoint'])
38
39        self.runCmd('frame variable i')
40        self.runCmd('expr i')
41        self.runCmd('expr ptr[0]->point.x')
42        self.runCmd('expr ptr[0]->point.y')
43        self.runCmd('expr ptr[i]->point.x')
44        self.runCmd('expr ptr[i]->point.y')
45
46if __name__ == '__main__':
47    import atexit
48    lldb.SBDebugger.Initialize()
49    atexit.register(lambda: lldb.SBDebugger.Terminate())
50    unittest2.main()
51