summaryrefslogtreecommitdiffstats
path: root/lldb/test/functionalities/non-overlapping-index-variable-i/TestIndexVariable.py
blob: c4488104d68596d624770ae43eac2c0687161435 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"""Test evaluating expressions which ref. index variable 'i' which just goes
from out of scope to in scope when stopped at the breakpoint."""

import unittest2
import lldb
from lldbtest import *

class NonOverlappingIndexVariableCase(TestBase):

    mydir = os.path.join("functionalities", "non-overlapping-index-variable-i")

    def setUp(self):
        TestBase.setUp(self)
        self.source = 'main.cpp'
        self.line_to_break = line_number(self.source, '// Set breakpoint here.')
        self.lldb_avg = None
        self.gdb_avg = None

    def test_eval_index_variable(self):
        """Test expressions of variable 'i' which appears in two for loops."""
        self.buildDefault()
        self.exe_name = 'a.out'
        self.eval_index_variable_i(self.exe_name)

    def eval_index_variable_i(self, exe_name):
        """Test expressions of variable 'i' which appears in two for loops."""
        self.runCmd("file %s" % exe_name, CURRENT_EXECUTABLE_SET)

        self.expect('breakpoint set -f %s -l %d' % (self.source, self.line_to_break),
                    BREAKPOINT_CREATED,
            startstr = "Breakpoint created: 1: file ='%s', line = %d, locations = 1" %
                        (self.source, self.line_to_break))

        self.runCmd("run", RUN_SUCCEEDED)

        # The stop reason of the thread should be breakpoint.
        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
            substrs = ['stopped',
                       'stop reason = breakpoint'])

        self.runCmd('frame variable i')
        self.runCmd('expr i')
        self.runCmd('expr ptr[0]->point.x')
        self.runCmd('expr ptr[0]->point.y')
        self.runCmd('expr ptr[i]->point.x')
        self.runCmd('expr ptr[i]->point.y')

if __name__ == '__main__':
    import atexit
    lldb.SBDebugger.Initialize()
    atexit.register(lambda: lldb.SBDebugger.Terminate())
    unittest2.main()
OpenPOWER on IntegriCloud