1"""Check that compiler-generated constant values work correctly"""
2
3
4
5import lldb
6from lldbsuite.test.decorators import *
7from lldbsuite.test.lldbtest import *
8from lldbsuite.test import lldbutil
9
10
11class ConstVariableTestCase(TestBase):
12
13    mydir = TestBase.compute_mydir(__file__)
14
15    @expectedFailureAll(oslist=["freebsd", "linux"], compiler="icc")
16    @expectedFailureAll(archs=['mips', 'mipsel', 'mips64', 'mips64el'])
17    @expectedFailureAll(
18        oslist=["windows"],
19        bugnumber="llvm.org/pr24489: Name lookup not working correctly on Windows")
20    def test_and_run_command(self):
21        """Test interpreted and JITted expressions on constant values."""
22        self.build()
23        exe = self.getBuildArtifact("a.out")
24        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
25
26        # Break inside the main.
27        lldbutil.run_break_set_by_symbol(
28            self, "main", num_expected_locations=1)
29
30        self.runCmd("run", RUN_SUCCEEDED)
31
32        # The stop reason of the thread should be breakpoint.
33        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
34                    substrs=['stopped',
35                             'stop reason = breakpoint'])
36
37        # The breakpoint should have a hit count of 1.
38        lldbutil.check_breakpoint(self, bpno = 1, expected_hit_count = 1)
39
40        self.runCmd("next")
41        self.runCmd("next")
42
43        # Try frame variable.
44        self.expect("frame variable index", VARIABLES_DISPLAYED_CORRECTLY,
45                    substrs=['(int32_t) index = 512'])
46
47        # Try an interpreted expression.
48        self.expect("expr (index + 512)", VARIABLES_DISPLAYED_CORRECTLY,
49                    substrs=['1024'])
50
51        # Try a JITted expression.
52        self.expect(
53            "expr (int)getpid(); (index - 256)",
54            VARIABLES_DISPLAYED_CORRECTLY,
55            substrs=['256'])
56
57        self.runCmd("kill")
58