xref: /llvm-project/lldb/test/API/functionalities/non-overlapping-index-variable-i/TestIndexVariable.py (revision 2238dcc39358353cac21df75c3c3286ab20b8f53)
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
4
5import lldb
6from lldbsuite.test.lldbtest import *
7import lldbsuite.test.lldbutil as lldbutil
8
9
10class NonOverlappingIndexVariableCase(TestBase):
11    def setUp(self):
12        TestBase.setUp(self)
13        self.source = "main.cpp"
14        self.line_to_break = line_number(self.source, "// Set breakpoint here.")
15
16    # rdar://problem/9890530
17    def test_eval_index_variable(self):
18        """Test expressions of variable 'i' which appears in two for loops."""
19        self.build()
20        self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
21
22        lldbutil.run_break_set_by_file_and_line(
23            self,
24            self.source,
25            self.line_to_break,
26            num_expected_locations=1,
27            loc_exact=True,
28        )
29
30        self.runCmd("run", RUN_SUCCEEDED)
31
32        # The stop reason of the thread should be breakpoint.
33        self.expect(
34            "thread list",
35            STOPPED_DUE_TO_BREAKPOINT,
36            substrs=["stopped", "stop reason = breakpoint"],
37        )
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