1"""Test settings and readings of program variables."""
2
3
4
5import lldb
6from lldbsuite.test.decorators import *
7from lldbsuite.test.lldbtest import *
8from lldbsuite.test import lldbutil
9
10
11class SetValuesTestCase(TestBase):
12
13    mydir = TestBase.compute_mydir(__file__)
14
15    def setUp(self):
16        # Call super's setUp().
17        TestBase.setUp(self)
18        # Find the line numbers to break inside main().
19        self.line1 = line_number('main.c', '// Set break point #1.')
20        self.line2 = line_number('main.c', '// Set break point #2.')
21        self.line3 = line_number('main.c', '// Set break point #3.')
22        self.line4 = line_number('main.c', '// Set break point #4.')
23        self.line5 = line_number('main.c', '// Set break point #5.')
24
25    def test(self):
26        """Test settings and readings of program variables."""
27        self.build()
28        exe = self.getBuildArtifact("a.out")
29        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
30
31        # Set breakpoints on several places to set program variables.
32        lldbutil.run_break_set_by_file_and_line(
33            self, "main.c", self.line1, num_expected_locations=1, loc_exact=True)
34
35        lldbutil.run_break_set_by_file_and_line(
36            self, "main.c", self.line2, num_expected_locations=1, loc_exact=True)
37
38        lldbutil.run_break_set_by_file_and_line(
39            self, "main.c", self.line3, num_expected_locations=1, loc_exact=True)
40
41        lldbutil.run_break_set_by_file_and_line(
42            self, "main.c", self.line4, num_expected_locations=1, loc_exact=True)
43
44        lldbutil.run_break_set_by_file_and_line(
45            self, "main.c", self.line5, num_expected_locations=1, loc_exact=True)
46
47        self.runCmd("run", RUN_SUCCEEDED)
48
49        # The stop reason of the thread should be breakpoint.
50        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
51                    substrs=['stopped',
52                             'stop reason = breakpoint'])
53
54        # The breakpoint should have a hit count of 1.
55        lldbutil.check_breakpoint(self, bpno = 1, expected_hit_count = 1)
56
57        # main.c:15
58        # Check that 'frame variable --show-types' displays the correct data
59        # type and value.
60        self.expect(
61            "frame variable --show-types",
62            VARIABLES_DISPLAYED_CORRECTLY,
63            startstr="(char) i = 'a'")
64
65        # Now set variable 'i' and check that it is correctly displayed.
66        self.runCmd("expression i = 'b'")
67        self.expect(
68            "frame variable --show-types",
69            VARIABLES_DISPLAYED_CORRECTLY,
70            startstr="(char) i = 'b'")
71
72        self.runCmd("continue")
73
74        # main.c:36
75        # Check that 'frame variable --show-types' displays the correct data
76        # type and value.
77        self.expect(
78            "frame variable --show-types",
79            VARIABLES_DISPLAYED_CORRECTLY,
80            patterns=["\((short unsigned int|unsigned short)\) i = 33"])
81
82        # Now set variable 'i' and check that it is correctly displayed.
83        self.runCmd("expression i = 333")
84        self.expect(
85            "frame variable --show-types",
86            VARIABLES_DISPLAYED_CORRECTLY,
87            patterns=["\((short unsigned int|unsigned short)\) i = 333"])
88
89        self.runCmd("continue")
90
91        # main.c:57
92        # Check that 'frame variable --show-types' displays the correct data
93        # type and value.
94        self.expect(
95            "frame variable --show-types",
96            VARIABLES_DISPLAYED_CORRECTLY,
97            startstr="(long) i = 33")
98
99        # Now set variable 'i' and check that it is correctly displayed.
100        self.runCmd("expression i = 33333")
101        self.expect(
102            "frame variable --show-types",
103            VARIABLES_DISPLAYED_CORRECTLY,
104            startstr="(long) i = 33333")
105
106        self.runCmd("continue")
107
108        # main.c:78
109        # Check that 'frame variable --show-types' displays the correct data
110        # type and value.
111        self.expect(
112            "frame variable --show-types",
113            VARIABLES_DISPLAYED_CORRECTLY,
114            startstr="(double) i = 2.25")
115
116        # Now set variable 'i' and check that it is correctly displayed.
117        self.runCmd("expression i = 1.5")
118        self.expect(
119            "frame variable --show-types",
120            VARIABLES_DISPLAYED_CORRECTLY,
121            startstr="(double) i = 1.5")
122
123        self.runCmd("continue")
124
125        # main.c:85
126        # Check that 'frame variable --show-types' displays the correct data
127        # type and value.
128        self.expect(
129            "frame variable --show-types",
130            VARIABLES_DISPLAYED_CORRECTLY,
131            startstr="(long double) i = 2.25")
132
133        # Now set variable 'i' and check that it is correctly displayed.
134        self.runCmd("expression i = 1.5")
135        self.expect(
136            "frame variable --show-types",
137            VARIABLES_DISPLAYED_CORRECTLY,
138            startstr="(long double) i = 1.5")
139