1 """Test settings and readings of program variables."""
3 from __future__ import print_function
9 from lldbsuite.test.decorators import *
10 from lldbsuite.test.lldbtest import *
11 from lldbsuite.test import lldbutil
14 class SetValuesTestCase(TestBase):
16 mydir = TestBase.compute_mydir(__file__)
19 # Call super's setUp().
21 # Find the line numbers to break inside main().
22 self.line1 = line_number('main.c', '// Set break point #1.')
23 self.line2 = line_number('main.c', '// Set break point #2.')
24 self.line3 = line_number('main.c', '// Set break point #3.')
25 self.line4 = line_number('main.c', '// Set break point #4.')
26 self.line5 = line_number('main.c', '// Set break point #5.')
29 """Test settings and readings of program variables."""
31 exe = self.getBuildArtifact("a.out")
32 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
34 # Set breakpoints on several places to set program variables.
35 lldbutil.run_break_set_by_file_and_line(
36 self, "main.c", self.line1, num_expected_locations=1, loc_exact=True)
38 lldbutil.run_break_set_by_file_and_line(
39 self, "main.c", self.line2, num_expected_locations=1, loc_exact=True)
41 lldbutil.run_break_set_by_file_and_line(
42 self, "main.c", self.line3, num_expected_locations=1, loc_exact=True)
44 lldbutil.run_break_set_by_file_and_line(
45 self, "main.c", self.line4, num_expected_locations=1, loc_exact=True)
47 lldbutil.run_break_set_by_file_and_line(
48 self, "main.c", self.line5, num_expected_locations=1, loc_exact=True)
50 self.runCmd("run", RUN_SUCCEEDED)
52 # The stop reason of the thread should be breakpoint.
53 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
55 'stop reason = breakpoint'])
57 # The breakpoint should have a hit count of 1.
58 self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
59 substrs=[' resolved, hit count = 1'])
62 # Check that 'frame variable --show-types' displays the correct data
65 "frame variable --show-types",
66 VARIABLES_DISPLAYED_CORRECTLY,
67 startstr="(char) i = 'a'")
69 # Now set variable 'i' and check that it is correctly displayed.
70 self.runCmd("expression i = 'b'")
72 "frame variable --show-types",
73 VARIABLES_DISPLAYED_CORRECTLY,
74 startstr="(char) i = 'b'")
76 self.runCmd("continue")
79 # Check that 'frame variable --show-types' displays the correct data
82 "frame variable --show-types",
83 VARIABLES_DISPLAYED_CORRECTLY,
84 patterns=["\((short unsigned int|unsigned short)\) i = 33"])
86 # Now set variable 'i' and check that it is correctly displayed.
87 self.runCmd("expression i = 333")
89 "frame variable --show-types",
90 VARIABLES_DISPLAYED_CORRECTLY,
91 patterns=["\((short unsigned int|unsigned short)\) i = 333"])
93 self.runCmd("continue")
96 # Check that 'frame variable --show-types' displays the correct data
99 "frame variable --show-types",
100 VARIABLES_DISPLAYED_CORRECTLY,
101 startstr="(long) i = 33")
103 # Now set variable 'i' and check that it is correctly displayed.
104 self.runCmd("expression i = 33333")
106 "frame variable --show-types",
107 VARIABLES_DISPLAYED_CORRECTLY,
108 startstr="(long) i = 33333")
110 self.runCmd("continue")
113 # Check that 'frame variable --show-types' displays the correct data
116 "frame variable --show-types",
117 VARIABLES_DISPLAYED_CORRECTLY,
118 startstr="(double) i = 2.25")
120 # Now set variable 'i' and check that it is correctly displayed.
121 self.runCmd("expression i = 1.5")
123 "frame variable --show-types",
124 VARIABLES_DISPLAYED_CORRECTLY,
125 startstr="(double) i = 1.5")
127 self.runCmd("continue")
130 # Check that 'frame variable --show-types' displays the correct data
133 "frame variable --show-types",
134 VARIABLES_DISPLAYED_CORRECTLY,
135 startstr="(long double) i = 2.25")
137 # Now set variable 'i' and check that it is correctly displayed.
138 self.runCmd("expression i = 1.5")
140 "frame variable --show-types",
141 VARIABLES_DISPLAYED_CORRECTLY,
142 startstr="(long double) i = 1.5")