f96e9f614d8e4790ab86a45fff7c69e069821fb6
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / settings.exp
1 # This testcase is part of GDB, the GNU debugger.
2
3 # Copyright 2019 Free Software Foundation, Inc.
4
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 # Test the set/show commands framework. The test uses the
19 # "maintenance test-settings set/show xxx" subcommands to exercise
20 # TAB-completion and setting processing.
21
22 load_lib completion-support.exp
23
24 standard_testfile .c
25
26 if {[build_executable "failed to prepare" $testfile $srcfile debug]} {
27 return -1
28 }
29
30 clean_restart
31
32 if { ![readline_is_used] } {
33 untested "no tab completion support without readline"
34 return -1
35 }
36
37 # Test the show command SHOW_CMD. EXPECTED_RE is the expected output.
38 # This procedure exists in order to make it easier to make the test
39 # name/message unique, since we test the "show" commands many times.
40 # EXPECTED_RE is made part of the test name.
41 proc show_setting {show_cmd expected_re} {
42 gdb_test "$show_cmd" $expected_re "$show_cmd: $expected_re"
43 }
44
45 # var_Xinteger tests. VARIANT determines which command/variant to
46 # exercise.
47 proc test-integer {variant} {
48 set set_cmd "maint test-settings set $variant"
49 set show_cmd "maint test-settings show $variant"
50
51 # A bogus value.
52 gdb_test "$set_cmd bogus" \
53 "No symbol table is loaded\\. Use the \"file\" command\\."
54
55 # Seemingly-valid but not quite valid value.
56 gdb_test "$set_cmd 1a" \
57 "Invalid number \"1a\"\\."
58
59 # Valid value followed by garbage.
60 gdb_test "$set_cmd 1 1" \
61 "A syntax error in expression, near `1'\\."
62
63 # Valid value followed by garbage.
64 gdb_test "$set_cmd 1 x" \
65 "A syntax error in expression, near `x'\\."
66
67 if {$variant == "zuinteger-unlimited"} {
68 # -1 means unlimited. Other negative values are rejected. -1
69 # -is tested further below, along the "unlimited" tests.
70 gdb_test "$set_cmd -2" "only -1 is allowed to set as unlimited"
71 } elseif {$variant == "uinteger" || $variant == "zuinteger"} {
72 # Negative values are not accepted.
73 gdb_test "$set_cmd -1" "integer -1 out of range"
74 gdb_test "$set_cmd -2" "integer -2 out of range"
75 } else {
76 # Negative values are not accepted.
77 gdb_test_no_output "$set_cmd -1"
78 show_setting "$show_cmd" "-1"
79 gdb_test_no_output "$set_cmd -2"
80 show_setting "$show_cmd" "-2"
81 }
82
83 # Regular integer is accepted.
84 gdb_test_no_output "$set_cmd 999"
85 show_setting "$show_cmd" "999"
86
87 if {$variant == "zinteger" || $variant == "zuinteger"} {
88 # 0 means 0.
89 gdb_test_no_output "$set_cmd 0"
90 show_setting "$show_cmd" "0"
91 } else {
92 # Either 0 or -1 mean unlimited. Test both the number and
93 # "unlimited". For the latter, test both full name and
94 # abbreviations.
95
96 if {$variant == "zuinteger-unlimited"} {
97 gdb_test_no_output "$set_cmd -1"
98 } else {
99 gdb_test_no_output "$set_cmd 0"
100 }
101 show_setting "$show_cmd" "unlimited"
102
103 foreach_with_prefix value {
104 "u"
105 "un"
106 "unl"
107 "unli"
108 "unlim"
109 "unlimi"
110 "unlimit"
111 "unlimite"
112 "unlimited"
113 } {
114 # Alternate between integer and unlimited, to make sure the
115 # setting really took effect.
116 gdb_test_no_output "$set_cmd 1"
117 show_setting "$show_cmd" "1"
118
119 gdb_test_no_output "$set_cmd $value"
120 show_setting "$show_cmd" "unlimited"
121 }
122 }
123
124 if {$variant == "zuinteger"} {
125 test_gdb_complete_multiple "maint test-settings set " "zuinteger" "" {
126 "zuinteger"
127 "zuinteger-unlimited"
128 }
129 } else {
130 test_gdb_complete_unique \
131 "$set_cmd" \
132 "$set_cmd"
133 }
134
135 if {$variant == "zinteger" || $variant == "zuinteger"} {
136 test_gdb_complete_none \
137 "$set_cmd " \
138 } else {
139 test_gdb_complete_unique \
140 "$set_cmd " \
141 "$set_cmd unlimited"
142 }
143
144 gdb_test "$set_cmd unlimitedu" "No symbol table is loaded.*"
145
146 test_gdb_complete_none "$set_cmd unlimited "
147 test_gdb_complete_none "$set_cmd unlimitedu"
148 test_gdb_complete_none "$set_cmd unlimited u"
149 test_gdb_complete_none "$set_cmd unlimited 1"
150 test_gdb_complete_none "$set_cmd x"
151 test_gdb_complete_none "$set_cmd x "
152 test_gdb_complete_none "$set_cmd -1"
153 test_gdb_complete_none "$set_cmd -1 "
154 test_gdb_complete_none "$set_cmd 1 "
155
156 # Check show command completion.
157 if {$variant == "zuinteger"} {
158 test_gdb_complete_multiple "maintenance test-settings show " "zuinteger" "" {
159 "zuinteger"
160 "zuinteger-unlimited"
161 }
162 } else {
163 test_gdb_complete_unique \
164 "$show_cmd" \
165 "$show_cmd"
166 }
167 test_gdb_complete_none "$show_cmd "
168 }
169
170 # boolean tests.
171 proc_with_prefix test-boolean {} {
172 # Use these variables to make sure we don't call the wrong command
173 # by mistake.
174 set set_cmd "maint test-settings set boolean"
175 set show_cmd "maint test-settings show boolean"
176
177 # A bogus value.
178 gdb_test "$set_cmd bogus" \
179 "\"on\" or \"off\" expected\\."
180
181 # Seemingly-valid but not quite valid value.
182 gdb_test "$set_cmd on1" \
183 "\"on\" or \"off\" expected\\."
184
185 # Valid value followed by garbage.
186 gdb_test "$set_cmd on 1" \
187 "\"on\" or \"off\" expected\\."
188
189 # Unlike auto-bool settings, "-1" is not accepted.
190 gdb_test "$set_cmd -1" \
191 "\"on\" or \"off\" expected\\."
192
193 # Nor "auto".
194 gdb_test "$set_cmd auto" \
195 "\"on\" or \"off\" expected\\."
196
197 # Various valid values. Test both full value names and
198 # abbreviations.
199
200 # Note that unlike with auto-bool, empty value implies "on".
201 foreach_with_prefix value {
202 ""
203 "o"
204 "on"
205 "1"
206 "y"
207 "ye"
208 "yes"
209 "e"
210 "en"
211 "ena"
212 "enab"
213 "enabl"
214 "enable"
215 } {
216 gdb_test_no_output "$set_cmd off"
217 show_setting "$show_cmd" "off"
218
219 gdb_test_no_output "$set_cmd $value"
220 show_setting "$show_cmd" "on"
221 }
222
223 foreach_with_prefix value {
224 "of"
225 "off"
226 "0"
227 "n"
228 "no"
229 "d"
230 "di"
231 "dis"
232 "disa"
233 "disab"
234 "disabl"
235 "disable"
236 } {
237 gdb_test_no_output "$set_cmd on"
238 show_setting "$show_cmd" "on"
239
240 gdb_test_no_output "$set_cmd $value"
241 show_setting "$show_cmd" "off"
242 }
243
244 test_gdb_complete_multiple "$set_cmd " "" "o" {
245 "off"
246 "on"
247 }
248
249 test_gdb_complete_unique \
250 "$set_cmd of" \
251 "$set_cmd off"
252
253 test_gdb_complete_none "$set_cmd x"
254
255 # Check that the show command doesn't complete anything.
256 test_gdb_complete_unique \
257 "$show_cmd" \
258 "$show_cmd"
259 test_gdb_complete_none "$show_cmd "
260 }
261
262 # auto-boolean tests.
263 proc_with_prefix test-auto-boolean {} {
264 # Use these variables to make sure we don't call the wrong command
265 # by mistake.
266 set set_cmd "maint test-settings set auto-boolean"
267 set show_cmd "maint test-settings show auto-boolean"
268
269 # A bogus value.
270 gdb_test "$set_cmd bogus" \
271 "\"on\", \"off\" or \"auto\" expected\\."
272
273 # Seemingly-valid but not quite valid value.
274 gdb_test "$set_cmd on1" \
275 "\"on\", \"off\" or \"auto\" expected\\."
276
277 # Valid value followed by garbage.
278 gdb_test "$set_cmd on 1" \
279 "\"on\", \"off\" or \"auto\" expected\\."
280
281 # Various valid values. Test both full value names and
282 # abbreviations.
283
284 foreach_with_prefix value {
285 "o"
286 "on"
287 "1"
288 "y"
289 "ye"
290 "yes"
291 "e"
292 "en"
293 "ena"
294 "enab"
295 "enabl"
296 "enable"
297 } {
298 gdb_test_no_output "$set_cmd off"
299 show_setting "$show_cmd" "off"
300
301 gdb_test_no_output "$set_cmd $value"
302 show_setting "$show_cmd" "on"
303 }
304
305 foreach_with_prefix value {
306 "of"
307 "off"
308 "0"
309 "n"
310 "no"
311 "d"
312 "di"
313 "dis"
314 "disa"
315 "disab"
316 "disabl"
317 "disable"
318 } {
319 gdb_test_no_output "$set_cmd on"
320 show_setting "$show_cmd" "on"
321
322 gdb_test_no_output "$set_cmd $value"
323 show_setting "$show_cmd" "off"
324 }
325
326 foreach_with_prefix value {
327 "a"
328 "au"
329 "aut"
330 "auto"
331 "-1"
332 } {
333 gdb_test_no_output "$set_cmd on"
334 show_setting "$show_cmd" "on"
335
336 gdb_test_no_output "$set_cmd $value"
337 show_setting "$show_cmd" "auto"
338 }
339
340 # "-" is not accepted as abbreviation of "-1".
341 gdb_test "$set_cmd -" \
342 "\"on\", \"off\" or \"auto\" expected\\."
343
344 test_gdb_complete_multiple "$set_cmd " "" "" {
345 "auto"
346 "off"
347 "on"
348 }
349
350 test_gdb_complete_unique \
351 "$set_cmd of" \
352 "$set_cmd off"
353
354 test_gdb_complete_none "$set_cmd x"
355
356 # Check that the show command doesn't complete anything.
357 test_gdb_complete_unique \
358 "$show_cmd" \
359 "$show_cmd"
360 test_gdb_complete_none "$show_cmd "
361 }
362
363 # Enum option tests.
364 proc_with_prefix test-enum {} {
365 # Use these variables to make sure we don't call the wrong command
366 # by mistake.
367 set set_cmd "maint test-settings set enum"
368 set show_cmd "maint test-settings show enum"
369
370 # Missing value.
371 gdb_test "$set_cmd" \
372 "Requires an argument\\. Valid arguments are xxx, yyy, zzz\\."
373
374 # A bogus value.
375 gdb_test "$set_cmd bogus" \
376 "Undefined item: \"bogus\"."
377
378 # Seemingly-valid but not quite valid value.
379 gdb_test "$set_cmd xxx1" \
380 "Undefined item: \"xxx1\"."
381
382 # Valid value followed by garbage.
383 gdb_test "$set_cmd xxx 1" \
384 "Junk after item \"xxx\": 1"
385 # Valid value followed by garbage, with extra spaces.
386 gdb_test "$set_cmd xxx 1" \
387 "Junk after item \"xxx\": 1"
388 # Abbreviated value followed by garbage.
389 gdb_test "$set_cmd xx 1" \
390 "Junk after item \"xx\": 1"
391
392 # Various valid values. Test both full value names and
393 # abbreviations.
394 gdb_test_no_output "$set_cmd x"
395 show_setting "$show_cmd" "xxx"
396 gdb_test_no_output "$set_cmd yy"
397 show_setting "$show_cmd" "yyy"
398 gdb_test_no_output "$set_cmd zzz"
399 show_setting "$show_cmd" "zzz"
400
401 test_gdb_complete_multiple "$set_cmd " "" "" {
402 "xxx"
403 "yyy"
404 "zzz"
405 }
406
407 test_gdb_complete_unique \
408 "$set_cmd x" \
409 "$set_cmd xxx"
410
411 test_gdb_complete_none "$set_cmd a"
412
413 # Check that the show command doesn't complete anything.
414 test_gdb_complete_unique \
415 "$show_cmd" \
416 "$show_cmd"
417 test_gdb_complete_none "$show_cmd "
418 }
419
420 # string settings tests.
421 proc test-string {variant} {
422 global gdb_prompt
423 global srcfile binfile
424
425 # Load symbols for the completion test below.
426 clean_restart $binfile
427
428 # Use these variables to make sure we don't call the wrong command
429 # by mistake.
430 set set_cmd "maint test-settings set $variant"
431 set show_cmd "maint test-settings show $variant"
432
433 # Empty string. Also checks that gdb doesn't crash if we haven't
434 # set the string yet.
435 gdb_test "$show_cmd" "^$show_cmd\r\n" "$show_cmd: empty first time"
436
437 # A string value.
438 gdb_test_no_output "$set_cmd hello world"
439 show_setting "$show_cmd" "hello world"
440
441 # A quoted string value.
442 if {$variant == "string"} {
443 gdb_test_no_output "$set_cmd \"hello world\""
444 show_setting "$show_cmd" "\\\\\"hello world\\\\\""
445 } else {
446 gdb_test_no_output "$set_cmd \"hello world\""
447 show_setting "$show_cmd" "\"hello world\""
448 }
449
450 # Test clearing the string.
451 with_test_prefix "clear string" {
452 if {$variant == "filename"} {
453 gdb_test "$set_cmd" \
454 "Argument required \\(filename to set it to\\.\\)\\."
455
456 # Check the value didn't change.
457 show_setting "$show_cmd" "\"hello world\""
458 } else {
459 gdb_test_no_output "$set_cmd"
460 gdb_test "$show_cmd" \
461 "^$show_cmd\r\n" "$show_cmd: empty second time"
462 }
463 }
464
465 # Test completion.
466 if {$variant == "string" || $variant == "string-noescape" } {
467 # Make sure GDB doesn't try to complete on symbols, which
468 # doesn't make any sense.
469 test_gdb_complete_none "$set_cmd "
470 } else {
471 # Complete on filename.
472
473 # See comments in gdb.base/completion.exp.
474
475 # We `cd' to ${srcdir}, and then do the completion relative to
476 # the current directory.
477
478 # ${srcdir} may be a relative path. We want to make sure we
479 # end up in the right directory - so make sure we know where
480 # it is.
481 global srcdir
482 set mydir [pwd]
483 cd ${srcdir}
484 set fullsrcdir [pwd]
485 cd ${mydir}
486
487 gdb_test "cd ${fullsrcdir}" \
488 "Working directory [string_to_regexp ${fullsrcdir}].*" \
489 "cd to \${srcdir}"
490
491 set unique_file ../testsuite/gdb.base/comp-dir/subdir/dummy
492
493 test_gdb_complete_unique \
494 "$set_cmd ${unique_file}" \
495 "$set_cmd ${unique_file}.txt"
496
497 test_gdb_complete_none "$set_cmd ${unique_file}.abc"
498 }
499
500 # Check show command completion.
501 if {$variant == "string"} {
502 test_gdb_complete_multiple "maint test-settings show " "string" "" {
503 "string"
504 "string-noescape"
505 }
506 } else {
507 test_gdb_complete_unique \
508 "$show_cmd" \
509 "$show_cmd"
510 }
511 test_gdb_complete_none "$show_cmd "
512 }
513
514 foreach variant {
515 uinteger
516 integer
517 zinteger
518 zuinteger
519 zuinteger-unlimited
520 } {
521 with_test_prefix "test-integer $variant" {
522 test-integer $variant
523 }
524 }
525
526 test-boolean
527 test-auto-boolean
528 test-enum
529
530 foreach variant {
531 string
532 string-noescape
533 optional-filename
534 filename
535 } {
536 with_test_prefix "test-string $variant" {
537 test-string $variant
538 }
539 }
This page took 0.039492 seconds and 3 git commands to generate.