with.exp revision 1.1.1.3 1 1.1 christos # This testcase is part of GDB, the GNU debugger.
2 1.1 christos
3 1.1.1.3 christos # Copyright 2019-2024 Free Software Foundation, Inc.
4 1.1 christos
5 1.1 christos # This program is free software; you can redistribute it and/or modify
6 1.1 christos # it under the terms of the GNU General Public License as published by
7 1.1 christos # the Free Software Foundation; either version 3 of the License, or
8 1.1 christos # (at your option) any later version.
9 1.1 christos #
10 1.1 christos # This program is distributed in the hope that it will be useful,
11 1.1 christos # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 1.1 christos # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 1.1 christos # GNU General Public License for more details.
14 1.1 christos #
15 1.1 christos # You should have received a copy of the GNU General Public License
16 1.1 christos # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 1.1 christos
18 1.1 christos # Test the "with" command.
19 1.1 christos
20 1.1 christos load_lib completion-support.exp
21 1.1 christos
22 1.1 christos standard_testfile .c
23 1.1 christos
24 1.1 christos if {[build_executable "failed to prepare" $testfile $srcfile debug]} {
25 1.1 christos return -1
26 1.1 christos }
27 1.1 christos
28 1.1 christos clean_restart $binfile
29 1.1 christos
30 1.1 christos # Test "maint with". VALUES is a list of values. A nested "with" is
31 1.1 christos # performed with each combination of pair of values from this list.
32 1.1 christos # This exercises setting a value, and restoring it too. This is
33 1.1 christos # particularly important for the "special" values like "unlimited",
34 1.1 christos # which for example for var_uinteger maps to 0 at the user-visible
35 1.1 christos # level, but maps to -1 internally.
36 1.1 christos
37 1.1 christos proc test_with {setting values} {
38 1.1 christos foreach val1 $values {
39 1.1 christos foreach val2 $values {
40 1.1 christos gdb_test \
41 1.1 christos "maint with test-settings $setting $val1 -- maint with test-settings $setting $val2 -- p 1" \
42 1.1 christos " = 1"
43 1.1 christos }
44 1.1 christos }
45 1.1 christos }
46 1.1 christos
47 1.1 christos # Test "maint with" in the error case. SETTING is the "maint set
48 1.1 christos # test-setting" setting to exercise. TMP_VAL is the value to set the
49 1.1 christos # setting to. EXPECTED_RE is the expected GDB output, which should be
50 1.1 christos # an error of some kind. Also checks that the setting's original
51 1.1 christos # value is preserved across the error.
52 1.1 christos
53 1.1 christos proc test_with_error {setting tmp_val expected_re} {
54 1.1 christos global gdb_prompt
55 1.1 christos
56 1.1 christos with_test_prefix "$setting, $tmp_val" {
57 1.1 christos set org_val ""
58 1.1.1.3 christos gdb_test_multiple "maint show test-settings $setting" \
59 1.1.1.3 christos "save org value" {
60 1.1.1.3 christos -re "^maint show test-settings $setting\r\n" {
61 1.1.1.3 christos exp_continue
62 1.1.1.3 christos }
63 1.1.1.3 christos -re "^(.*)\r\n$gdb_prompt $" {
64 1.1.1.3 christos set org_val $expect_out(1,string)
65 1.1.1.3 christos pass $gdb_test_name
66 1.1.1.3 christos }
67 1.1 christos }
68 1.1 christos
69 1.1 christos gdb_test \
70 1.1 christos "maint with test-settings $setting $tmp_val -- p 1" \
71 1.1 christos $expected_re
72 1.1 christos
73 1.1 christos gdb_test "maint show test-settings $setting" "^$org_val" \
74 1.1 christos "value hasn't changed across error"
75 1.1 christos }
76 1.1 christos }
77 1.1 christos
78 1.1 christos # Test "with" framework basics, using the internal "maint with
79 1.1 christos # test-settings" subcommands.
80 1.1 christos with_test_prefix "maint" {
81 1.1 christos test_with "auto-boolean" {"on" "off" "auto"}
82 1.1 christos test_with "boolean" {"" "on" "off" "0" "1" "enable" "disable"}
83 1.1 christos test_with "integer" {"0" "1" "-1" "unlimited"}
84 1.1 christos test_with "uinteger" {"0" "1" "unlimited"}
85 1.1 christos test_with "zinteger" {"0" "1" "-1"}
86 1.1 christos test_with "zuinteger" {"0" "1"}
87 1.1 christos test_with "zuinteger-unlimited" {"-1" "unlimited" "0" "1"}
88 1.1 christos test_with "string" {"" "foo" "\"hello world\""}
89 1.1 christos test_with "string-noescape" {"" "foo" "\"hello world\""}
90 1.1 christos test_with "filename" {"/foo" "bar/x/y"}
91 1.1 christos test_with "optional-filename" {"" "/foo" "bar/x/y"}
92 1.1 christos test_with "enum" {"xxx" "yyy"}
93 1.1 christos
94 1.1 christos # Check the most important error conditions. E.g., empty,
95 1.1 christos # negative or "unlimited" values for settings that don't accept
96 1.1 christos # those. Exhaustive error coverage of the set/with value parsing
97 1.1 christos # is left to "set" testing, in gdb.base/settings.exp.
98 1.1 christos test_with_error "auto-boolean" "" \
99 1.1 christos "\"on\", \"off\" or \"auto\" expected\\."
100 1.1 christos test_with_error "auto-boolean" "xxx" \
101 1.1 christos "\"on\", \"off\" or \"auto\" expected\\."
102 1.1 christos test_with_error "boolean" "2" "\"on\" or \"off\" expected\\."
103 1.1 christos test_with_error "uinteger" "-1" "integer -1 out of range"
104 1.1 christos test_with_error "uinteger" "" \
105 1.1.1.2 christos "Argument required \\(integer to set it to, or \"unlimited\"\\)\\."
106 1.1 christos test_with_error "zuinteger" "-1" "integer -1 out of range"
107 1.1 christos test_with_error "zuinteger" "" \
108 1.1.1.2 christos "Argument required \\(integer to set it to\\)\\."
109 1.1 christos test_with_error "zuinteger-unlimited" "-2" \
110 1.1.1.3 christos "integer -2 out of range"
111 1.1 christos test_with_error "zuinteger-unlimited" "" \
112 1.1.1.2 christos "Argument required \\(integer to set it to, or \"unlimited\"\\)\\."
113 1.1 christos test_with_error "filename" "" \
114 1.1 christos "Argument required \\(filename to set it to\\.\\)\\."
115 1.1 christos test_with_error "enum" "" \
116 1.1 christos "Requires an argument\\. Valid arguments are xxx, yyy, zzz\\."
117 1.1 christos }
118 1.1 christos
119 1.1 christos # Basic/core tests using user-visible commands.
120 1.1 christos with_test_prefix "basics" {
121 1.1 christos gdb_test "print g_s" " = {a = 1, b = 2, c = 3}"
122 1.1 christos gdb_test "with print pretty -- print g_s" \
123 1.1 christos [multi_line \
124 1.1 christos " = {" \
125 1.1 christos " a = 1," \
126 1.1 christos " b = 2," \
127 1.1 christos " c = 3" \
128 1.1 christos "}"]
129 1.1 christos
130 1.1 christos # A boolean setting.
131 1.1 christos gdb_test "with non-stop on -- show non-stop" \
132 1.1 christos "Controlling the inferior in non-stop mode is on\\."
133 1.1 christos gdb_test "show non-stop" \
134 1.1 christos "Controlling the inferior in non-stop mode is off\\."
135 1.1 christos
136 1.1 christos # Language.
137 1.1 christos gdb_test "with language pascal -- show language" \
138 1.1 christos "The current source language is \"pascal\"\\."
139 1.1 christos
140 1.1 christos gdb_test "show language" \
141 1.1 christos "The current source language is \"auto; currently c\"\\."
142 1.1 christos
143 1.1 christos gdb_test "with language ada -- print g_s" \
144 1.1 christos " = \\(a => 1, b => 2, c => 3\\)"
145 1.1 christos
146 1.1 christos # Nested "with"s.
147 1.1 christos gdb_test "with language ada -- with language c -- print g_s" \
148 1.1 christos " = {a = 1, b = 2, c = 3}"
149 1.1 christos
150 1.1 christos # "w" alias.
151 1.1 christos gdb_test "w language pascal -- show language" \
152 1.1 christos "The current source language is \"pascal\"\\." \
153 1.1 christos "w alias works"
154 1.1 christos
155 1.1 christos # An early prototype of the "with" command got this wrong.
156 1.1 christos gdb_test \
157 1.1 christos "w print repeats unlimited -- w print repeats 1 -- p \"1223334444\"" \
158 1.1 christos " = \"1\", '2' <repeats 2 times>, '3' <repeats 3 times>, '4' <repeats 4 times>"
159 1.1 christos }
160 1.1 christos
161 1.1 christos # Check a user-defined command.
162 1.1 christos with_test_prefix "user-defined" {
163 1.1 christos # A user defined command.
164 1.1 christos set test "define usercmd"
165 1.1 christos gdb_test_multiple "define usercmd" $test {
166 1.1 christos -re "End with" {
167 1.1 christos gdb_test \
168 1.1 christos [multi_line_input \
169 1.1 christos {print g_s} \
170 1.1 christos {end}] \
171 1.1 christos "" \
172 1.1 christos $test
173 1.1 christos }
174 1.1 christos }
175 1.1 christos gdb_test "with language ada -- usercmd" \
176 1.1 christos " = \\(a => 1, b => 2, c => 3\\)"
177 1.1 christos }
178 1.1 christos
179 1.1 christos # Check repeating.
180 1.1 christos with_test_prefix "repeat" {
181 1.1 christos clean_restart $binfile
182 1.1 christos
183 1.1 christos # "with" with no command reinvokes the previous command.
184 1.1 christos gdb_test "with language ada" \
185 1.1 christos "No previous command to relaunch" \
186 1.1 christos "reinvoke with no previous command to relaunch"
187 1.1 christos
188 1.1 christos gdb_test "print g_s" " = {a = 1, b = 2, c = 3}"
189 1.1 christos
190 1.1 christos gdb_test "with language ada" \
191 1.1 christos " = \\(a => 1, b => 2, c => 3\\)" \
192 1.1 christos "reinvoke with language"
193 1.1 christos
194 1.1 christos # Same, but with "--".
195 1.1 christos gdb_test "with language fortran --" \
196 1.1 christos " = \\( a = 1, b = 2, c = 3 \\)" \
197 1.1 christos "reinvoke with language and --"
198 1.1 christos
199 1.1 christos # Repeating repeats the original "print g_s", not the last "with"
200 1.1 christos # command.
201 1.1 christos set test "repeat command line"
202 1.1 christos send_gdb "\n"
203 1.1 christos gdb_test_multiple "" $test {
204 1.1 christos -re " = {a = 1, b = 2, c = 3}\r\n$gdb_prompt $" {
205 1.1 christos pass $test
206 1.1 christos }
207 1.1 christos }
208 1.1 christos }
209 1.1 christos
210 1.1 christos # Basic run control.
211 1.1 christos with_test_prefix "run control" {
212 1.1 christos clean_restart $binfile
213 1.1 christos
214 1.1 christos if ![runto_main] {
215 1.1 christos return
216 1.1 christos }
217 1.1 christos
218 1.1 christos # Check "with" with a synchronous execution command.
219 1.1 christos gdb_test "with disassemble-next-line on -- next" \
220 1.1 christos "return 0;.*=>.*"
221 1.1 christos }
222 1.1 christos
223 1.1 christos # Check errors.
224 1.1 christos with_test_prefix "errors" {
225 1.1 christos gdb_test "with" "Missing arguments\\."
226 1.1 christos
227 1.1 christos # Try both an unknown root setting and an unknown prefixed
228 1.1 christos # setting. The errors come from different locations in the
229 1.1 christos # sources.
230 1.1 christos gdb_test "with xxxx yyyy" \
231 1.1 christos "Undefined set command: \"xxxx\". Try \"help set\"\\."
232 1.1 christos gdb_test "with print xxxx yyyy" \
233 1.1 christos "Undefined set print command: \"xxxx yyyy\". Try \"help set print\"\\."
234 1.1 christos # Try one error case for "maint with", to make sure the right
235 1.1 christos # "maintenance with" prefix is shown.
236 1.1 christos gdb_test "maint with xxxx yyyy" \
237 1.1 christos "Undefined maintenance set command: \"xxxx\". Try \"help maintenance set\"\\."
238 1.1 christos
239 1.1 christos # Try ambiguous settings.
240 1.1 christos gdb_test "with w" \
241 1.1 christos "Ambiguous set command \"w\": watchdog, width, write\\."
242 1.1 christos gdb_test "with print m" \
243 1.1.1.2 christos "Ambiguous set print command \"m\": max-depth, max-symbolic-offset, memory-tag-violations\\."
244 1.1 christos
245 1.1 christos gdb_test "with variable xxx=1" \
246 1.1 christos "Cannot use this setting with the \"with\" command"
247 1.1 christos
248 1.1 christos gdb_test "with print elements -- p 1" \
249 1.1.1.2 christos "Argument required \\(integer to set it to, or \"unlimited\"\\)\\."
250 1.1 christos
251 1.1 christos gdb_test "with -- p 1" \
252 1.1 christos "Missing setting before '--' delimiter"
253 1.1 christos
254 1.1 christos # Check that the setting is restored even if the command throws.
255 1.1 christos gdb_test "with print elements 1 -- unknowncommand" \
256 1.1 christos "Undefined command: \"unknowncommand\"\\. Try \"help\"\\."
257 1.1 christos gdb_test "show print elements" \
258 1.1 christos "Limit on string chars or array elements to print is 200\\."
259 1.1 christos }
260 1.1 christos
261 1.1 christos # Check completion.
262 1.1 christos with_test_prefix "completion" {
263 1.1 christos test_gdb_complete_unique \
264 1.1 christos "with pri" \
265 1.1 christos "with print"
266 1.1 christos
267 1.1 christos test_gdb_complete_unique \
268 1.1 christos "with print ele" \
269 1.1 christos "with print elements"
270 1.1 christos
271 1.1 christos test_gdb_complete_unique \
272 1.1 christos "with print elements u" \
273 1.1 christos "with print elements unlimited"
274 1.1 christos
275 1.1 christos test_gdb_complete_none \
276 1.1 christos "with print elements unlimited "
277 1.1 christos
278 1.1 christos test_gdb_completion_offers_commands "with print elements unlimited -- "
279 1.1 christos
280 1.1 christos # Check that the completer nests into the nested command line's
281 1.1 christos # completer.
282 1.1 christos test_gdb_complete_unique \
283 1.1 christos "with print elements unlimited -- with print ele" \
284 1.1 christos "with print elements unlimited -- with print elements"
285 1.1 christos
286 1.1 christos # Check completion of "maint with". "maint with" and "with"'s
287 1.1 christos # completers share 99% of the code. All we need to care about
288 1.1 christos # here is that the completion word point is computed correctly, so
289 1.1 christos # any simple completion is sufficient.
290 1.1 christos test_gdb_complete_unique \
291 1.1 christos "maint with test-set" \
292 1.1 christos "maint with test-settings"
293 1.1 christos }
294