1"""Show local variables and check that they can be inspected.
2
3This test was added after we made a change in clang to normalize
4DW_OP_constu(X < 32) to DW_OP_litX which broke the debugger because
5it didn't read the value as an unsigned.
6"""
7
8
9
10from lldbsuite.test.decorators import *
11from lldbsuite.test.lldbtest import *
12from lldbsuite.test import lldbutil
13
14
15class LocalVariablesTestCase(TestBase):
16
17    mydir = TestBase.compute_mydir(__file__)
18
19    def setUp(self):
20        # Call super's setUp().
21        TestBase.setUp(self)
22        # Find the line number to break inside main().
23        self.source = 'main.c'
24        self.line = line_number(
25            self.source, '// Set break point at this line.')
26
27    @skipIfWindows
28    def test_c_local_variables(self):
29        """Test local variable value."""
30        self.build()
31
32        # Create a target by the debugger.
33        target = self.dbg.CreateTarget(self.getBuildArtifact("a.out"))
34        self.assertTrue(target, VALID_TARGET)
35
36        # Break inside the main.
37        lldbutil.run_break_set_by_file_and_line(
38            self, self.source, self.line, num_expected_locations=1, loc_exact=True)
39
40        # Now launch the process, and do not stop at entry point.
41        process = target.LaunchSimple(
42            None, None, self.get_process_working_directory())
43        self.assertTrue(process, PROCESS_IS_VALID)
44
45        # The stop reason of the thread should be breakpoint.
46        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
47                    substrs=['stopped',
48                             'stop reason = breakpoint'])
49
50        # The breakpoint should have a hit count of 1.
51        self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
52                    substrs=[' resolved, hit count = 1'])
53
54        self.expect("frame variable i", VARIABLES_DISPLAYED_CORRECTLY,
55                    substrs=['(unsigned int) i = 10'])
56