Fix "set integer-command unlimited junk"
[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 # Check junk after "unlimited".
145 gdb_test "$set_cmd unlimitedu" "No symbol table is loaded.*"
146
147 if {$variant == "zinteger" || $variant == "zuinteger"} {
148 gdb_test "$set_cmd unlimited u" "No symbol table is loaded.*"
149 gdb_test "$set_cmd unlimited 1" "No symbol table is loaded.*"
150 gdb_test "$set_cmd unlimited -1" "No symbol table is loaded.*"
151 } else {
152 gdb_test "$set_cmd unlimited u" "Junk after \"unlimited\": u"
153 gdb_test "$set_cmd unlimited 1" "Junk after \"unlimited\": 1"
154 gdb_test "$set_cmd unlimited -1" "Junk after \"unlimited\": -1"
155 }
156
157 test_gdb_complete_none "$set_cmd unlimited "
158 test_gdb_complete_none "$set_cmd unlimitedu"
159 test_gdb_complete_none "$set_cmd unlimited u"
160 test_gdb_complete_none "$set_cmd unlimited 1"
161 test_gdb_complete_none "$set_cmd x"
162 test_gdb_complete_none "$set_cmd x "
163 test_gdb_complete_none "$set_cmd -1"
164 test_gdb_complete_none "$set_cmd -1 "
165 test_gdb_complete_none "$set_cmd 1 "
166
167 # Check show command completion.
168 if {$variant == "zuinteger"} {
169 test_gdb_complete_multiple "maintenance test-settings show " "zuinteger" "" {
170 "zuinteger"
171 "zuinteger-unlimited"
172 }
173 } else {
174 test_gdb_complete_unique \
175 "$show_cmd" \
176 "$show_cmd"
177 }
178 test_gdb_complete_none "$show_cmd "
179 }
180
181 # boolean tests.
182 proc_with_prefix test-boolean {} {
183 # Use these variables to make sure we don't call the wrong command
184 # by mistake.
185 set set_cmd "maint test-settings set boolean"
186 set show_cmd "maint test-settings show boolean"
187
188 # A bogus value.
189 gdb_test "$set_cmd bogus" \
190 "\"on\" or \"off\" expected\\."
191
192 # Seemingly-valid but not quite valid value.
193 gdb_test "$set_cmd on1" \
194 "\"on\" or \"off\" expected\\."
195
196 # Valid value followed by garbage.
197 gdb_test "$set_cmd on 1" \
198 "\"on\" or \"off\" expected\\."
199
200 # Unlike auto-bool settings, "-1" is not accepted.
201 gdb_test "$set_cmd -1" \
202 "\"on\" or \"off\" expected\\."
203
204 # Nor "auto".
205 gdb_test "$set_cmd auto" \
206 "\"on\" or \"off\" expected\\."
207
208 # "o" is ambiguous.
209 gdb_test "$set_cmd o" \
210 "\"on\" or \"off\" expected\\."
211
212 # Various valid values. Test both full value names and
213 # abbreviations.
214
215 # Note that unlike with auto-bool, empty value implies "on".
216 foreach_with_prefix value {
217 ""
218 "on"
219 "1"
220 "y"
221 "ye"
222 "yes"
223 "e"
224 "en"
225 "ena"
226 "enab"
227 "enabl"
228 "enable"
229 } {
230 gdb_test_no_output "$set_cmd off"
231 show_setting "$show_cmd" "off"
232
233 gdb_test_no_output "$set_cmd $value"
234 show_setting "$show_cmd" "on"
235 }
236
237 foreach_with_prefix value {
238 "of"
239 "off"
240 "0"
241 "n"
242 "no"
243 "d"
244 "di"
245 "dis"
246 "disa"
247 "disab"
248 "disabl"
249 "disable"
250 } {
251 gdb_test_no_output "$set_cmd on"
252 show_setting "$show_cmd" "on"
253
254 gdb_test_no_output "$set_cmd $value"
255 show_setting "$show_cmd" "off"
256 }
257
258 test_gdb_complete_multiple "$set_cmd " "" "o" {
259 "off"
260 "on"
261 }
262
263 test_gdb_complete_unique \
264 "$set_cmd of" \
265 "$set_cmd off"
266
267 test_gdb_complete_none "$set_cmd x"
268
269 # Check that the show command doesn't complete anything.
270 test_gdb_complete_unique \
271 "$show_cmd" \
272 "$show_cmd"
273 test_gdb_complete_none "$show_cmd "
274 }
275
276 # auto-boolean tests.
277 proc_with_prefix test-auto-boolean {} {
278 # Use these variables to make sure we don't call the wrong command
279 # by mistake.
280 set set_cmd "maint test-settings set auto-boolean"
281 set show_cmd "maint test-settings show auto-boolean"
282
283 # A bogus value.
284 gdb_test "$set_cmd bogus" \
285 "\"on\", \"off\" or \"auto\" expected\\."
286
287 # Seemingly-valid but not quite valid value.
288 gdb_test "$set_cmd on1" \
289 "\"on\", \"off\" or \"auto\" expected\\."
290
291 # Valid value followed by garbage.
292 gdb_test "$set_cmd on 1" \
293 "\"on\", \"off\" or \"auto\" expected\\."
294
295 # "o" is ambiguous.
296 gdb_test "$set_cmd o" \
297 "\"on\", \"off\" or \"auto\" expected\\."
298
299 # Various valid values. Test both full value names and
300 # abbreviations.
301
302 foreach_with_prefix value {
303 "on"
304 "1"
305 "y"
306 "ye"
307 "yes"
308 "e"
309 "en"
310 "ena"
311 "enab"
312 "enabl"
313 "enable"
314 } {
315 gdb_test_no_output "$set_cmd off"
316 show_setting "$show_cmd" "off"
317
318 gdb_test_no_output "$set_cmd $value"
319 show_setting "$show_cmd" "on"
320 }
321
322 foreach_with_prefix value {
323 "of"
324 "off"
325 "0"
326 "n"
327 "no"
328 "d"
329 "di"
330 "dis"
331 "disa"
332 "disab"
333 "disabl"
334 "disable"
335 } {
336 gdb_test_no_output "$set_cmd on"
337 show_setting "$show_cmd" "on"
338
339 gdb_test_no_output "$set_cmd $value"
340 show_setting "$show_cmd" "off"
341 }
342
343 foreach_with_prefix value {
344 "a"
345 "au"
346 "aut"
347 "auto"
348 "-1"
349 } {
350 gdb_test_no_output "$set_cmd on"
351 show_setting "$show_cmd" "on"
352
353 gdb_test_no_output "$set_cmd $value"
354 show_setting "$show_cmd" "auto"
355 }
356
357 # "-" is not accepted as abbreviation of "-1".
358 gdb_test "$set_cmd -" \
359 "\"on\", \"off\" or \"auto\" expected\\."
360
361 test_gdb_complete_multiple "$set_cmd " "" "" {
362 "auto"
363 "off"
364 "on"
365 }
366
367 test_gdb_complete_unique \
368 "$set_cmd of" \
369 "$set_cmd off"
370
371 test_gdb_complete_none "$set_cmd x"
372
373 # Check that the show command doesn't complete anything.
374 test_gdb_complete_unique \
375 "$show_cmd" \
376 "$show_cmd"
377 test_gdb_complete_none "$show_cmd "
378 }
379
380 # Enum option tests.
381 proc_with_prefix test-enum {} {
382 # Use these variables to make sure we don't call the wrong command
383 # by mistake.
384 set set_cmd "maint test-settings set enum"
385 set show_cmd "maint test-settings show enum"
386
387 # Missing value.
388 gdb_test "$set_cmd" \
389 "Requires an argument\\. Valid arguments are xxx, yyy, zzz\\."
390
391 # A bogus value.
392 gdb_test "$set_cmd bogus" \
393 "Undefined item: \"bogus\"."
394
395 # Seemingly-valid but not quite valid value.
396 gdb_test "$set_cmd xxx1" \
397 "Undefined item: \"xxx1\"."
398
399 # Valid value followed by garbage.
400 gdb_test "$set_cmd xxx 1" \
401 "Junk after item \"xxx\": 1"
402 # Valid value followed by garbage, with extra spaces.
403 gdb_test "$set_cmd xxx 1" \
404 "Junk after item \"xxx\": 1"
405 # Abbreviated value followed by garbage.
406 gdb_test "$set_cmd xx 1" \
407 "Junk after item \"xx\": 1"
408
409 # Various valid values. Test both full value names and
410 # abbreviations.
411 gdb_test_no_output "$set_cmd x"
412 show_setting "$show_cmd" "xxx"
413 gdb_test_no_output "$set_cmd yy"
414 show_setting "$show_cmd" "yyy"
415 gdb_test_no_output "$set_cmd zzz"
416 show_setting "$show_cmd" "zzz"
417
418 test_gdb_complete_multiple "$set_cmd " "" "" {
419 "xxx"
420 "yyy"
421 "zzz"
422 }
423
424 test_gdb_complete_unique \
425 "$set_cmd x" \
426 "$set_cmd xxx"
427
428 test_gdb_complete_none "$set_cmd a"
429
430 # Check that the show command doesn't complete anything.
431 test_gdb_complete_unique \
432 "$show_cmd" \
433 "$show_cmd"
434 test_gdb_complete_none "$show_cmd "
435 }
436
437 # string settings tests.
438 proc test-string {variant} {
439 global gdb_prompt
440 global srcfile binfile
441
442 # Load symbols for the completion test below.
443 clean_restart $binfile
444
445 # Use these variables to make sure we don't call the wrong command
446 # by mistake.
447 set set_cmd "maint test-settings set $variant"
448 set show_cmd "maint test-settings show $variant"
449
450 # Empty string. Also checks that gdb doesn't crash if we haven't
451 # set the string yet.
452 gdb_test "$show_cmd" "^$show_cmd\r\n" "$show_cmd: empty first time"
453
454 # A string value.
455 gdb_test_no_output "$set_cmd hello world"
456 show_setting "$show_cmd" "hello world"
457
458 # A quoted string value.
459 if {$variant == "string"} {
460 gdb_test_no_output "$set_cmd \"hello world\""
461 show_setting "$show_cmd" "\\\\\"hello world\\\\\""
462 } else {
463 gdb_test_no_output "$set_cmd \"hello world\""
464 show_setting "$show_cmd" "\"hello world\""
465 }
466
467 # Test clearing the string.
468 with_test_prefix "clear string" {
469 if {$variant == "filename"} {
470 gdb_test "$set_cmd" \
471 "Argument required \\(filename to set it to\\.\\)\\."
472
473 # Check the value didn't change.
474 show_setting "$show_cmd" "\"hello world\""
475 } else {
476 gdb_test_no_output "$set_cmd"
477 gdb_test "$show_cmd" \
478 "^$show_cmd\r\n" "$show_cmd: empty second time"
479 }
480 }
481
482 # Test completion.
483 if {$variant == "string" || $variant == "string-noescape" } {
484 # Make sure GDB doesn't try to complete on symbols, which
485 # doesn't make any sense.
486 test_gdb_complete_none "$set_cmd "
487 } else {
488 # Complete on filename.
489
490 # See comments in gdb.base/completion.exp.
491
492 # We `cd' to ${srcdir}, and then do the completion relative to
493 # the current directory.
494
495 # ${srcdir} may be a relative path. We want to make sure we
496 # end up in the right directory - so make sure we know where
497 # it is.
498 global srcdir
499 set mydir [pwd]
500 cd ${srcdir}
501 set fullsrcdir [pwd]
502 cd ${mydir}
503
504 gdb_test "cd ${fullsrcdir}" \
505 "Working directory [string_to_regexp ${fullsrcdir}].*" \
506 "cd to \${srcdir}"
507
508 set unique_file ../testsuite/gdb.base/comp-dir/subdir/dummy
509
510 test_gdb_complete_unique \
511 "$set_cmd ${unique_file}" \
512 "$set_cmd ${unique_file}.txt"
513
514 test_gdb_complete_none "$set_cmd ${unique_file}.abc"
515 }
516
517 # Check show command completion.
518 if {$variant == "string"} {
519 test_gdb_complete_multiple "maint test-settings show " "string" "" {
520 "string"
521 "string-noescape"
522 }
523 } else {
524 test_gdb_complete_unique \
525 "$show_cmd" \
526 "$show_cmd"
527 }
528 test_gdb_complete_none "$show_cmd "
529 }
530
531 foreach variant {
532 uinteger
533 integer
534 zinteger
535 zuinteger
536 zuinteger-unlimited
537 } {
538 with_test_prefix "test-integer $variant" {
539 test-integer $variant
540 }
541 }
542
543 test-boolean
544 test-auto-boolean
545 test-enum
546
547 foreach variant {
548 string
549 string-noescape
550 optional-filename
551 filename
552 } {
553 with_test_prefix "test-string $variant" {
554 test-string $variant
555 }
556 }
This page took 0.049179 seconds and 4 git commands to generate.