1 # This testcase is part of GDB, the GNU debugger.
3 # Copyright 2019 Free Software Foundation, Inc.
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.
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.
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/>.
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.
22 load_lib completion-support.exp
26 if {[build_executable "failed to prepare" $testfile $srcfile debug]} {
32 if { ![readline_is_used] } {
33 untested "no tab completion support without readline"
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"
45 # var_Xinteger tests. VARIANT determines which command/variant to
47 proc test-integer {variant} {
48 set set_cmd "maint test-settings set $variant"
49 set show_cmd "maint test-settings show $variant"
52 gdb_test "$set_cmd bogus" \
53 "No symbol table is loaded\\. Use the \"file\" command\\."
55 # Seemingly-valid but not quite valid value.
56 gdb_test "$set_cmd 1a" \
57 "Invalid number \"1a\"\\."
59 # Valid value followed by garbage.
60 gdb_test "$set_cmd 1 1" \
61 "A syntax error in expression, near `1'\\."
63 # Valid value followed by garbage.
64 gdb_test "$set_cmd 1 x" \
65 "A syntax error in expression, near `x'\\."
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"
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"
83 # Regular integer is accepted.
84 gdb_test_no_output "$set_cmd 999"
85 show_setting "$show_cmd" "999"
87 if {$variant == "zinteger" || $variant == "zuinteger"} {
89 gdb_test_no_output "$set_cmd 0"
90 show_setting "$show_cmd" "0"
92 # Either 0 or -1 mean unlimited. Test both the number and
93 # "unlimited". For the latter, test both full name and
96 if {$variant == "zuinteger-unlimited"} {
97 gdb_test_no_output "$set_cmd -1"
99 gdb_test_no_output "$set_cmd 0"
101 show_setting "$show_cmd" "unlimited"
103 foreach_with_prefix value {
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"
119 gdb_test_no_output "$set_cmd $value"
120 show_setting "$show_cmd" "unlimited"
124 if {$variant == "zuinteger"} {
125 test_gdb_complete_multiple "maint test-settings set " "zuinteger" "" {
127 "zuinteger-unlimited"
130 test_gdb_complete_unique \
135 if {$variant == "zinteger" || $variant == "zuinteger"} {
136 test_gdb_complete_none \
139 test_gdb_complete_unique \
144 # Check junk after "unlimited".
145 gdb_test "$set_cmd unlimitedu" "No symbol table is loaded.*"
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.*"
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"
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 "
167 # Check show command completion.
168 if {$variant == "zuinteger"} {
169 test_gdb_complete_multiple "maintenance test-settings show " "zuinteger" "" {
171 "zuinteger-unlimited"
174 test_gdb_complete_unique \
178 test_gdb_complete_none "$show_cmd "
182 proc_with_prefix test-boolean {} {
183 # Use these variables to make sure we don't call the wrong command
185 set set_cmd "maint test-settings set boolean"
186 set show_cmd "maint test-settings show boolean"
189 gdb_test "$set_cmd bogus" \
190 "\"on\" or \"off\" expected\\."
192 # Seemingly-valid but not quite valid value.
193 gdb_test "$set_cmd on1" \
194 "\"on\" or \"off\" expected\\."
196 # Valid value followed by garbage.
197 gdb_test "$set_cmd on 1" \
198 "\"on\" or \"off\" expected\\."
200 # Unlike auto-bool settings, "-1" is not accepted.
201 gdb_test "$set_cmd -1" \
202 "\"on\" or \"off\" expected\\."
205 gdb_test "$set_cmd auto" \
206 "\"on\" or \"off\" expected\\."
209 gdb_test "$set_cmd o" \
210 "\"on\" or \"off\" expected\\."
212 # Various valid values. Test both full value names and
215 # Note that unlike with auto-bool, empty value implies "on".
216 foreach_with_prefix value {
230 gdb_test_no_output "$set_cmd off"
231 show_setting "$show_cmd" "off"
233 gdb_test_no_output "$set_cmd $value"
234 show_setting "$show_cmd" "on"
237 foreach_with_prefix value {
251 gdb_test_no_output "$set_cmd on"
252 show_setting "$show_cmd" "on"
254 gdb_test_no_output "$set_cmd $value"
255 show_setting "$show_cmd" "off"
258 test_gdb_complete_multiple "$set_cmd " "" "o" {
263 test_gdb_complete_unique \
267 test_gdb_complete_none "$set_cmd x"
269 # Check that the show command doesn't complete anything.
270 test_gdb_complete_unique \
273 test_gdb_complete_none "$show_cmd "
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
280 set set_cmd "maint test-settings set auto-boolean"
281 set show_cmd "maint test-settings show auto-boolean"
284 gdb_test "$set_cmd bogus" \
285 "\"on\", \"off\" or \"auto\" expected\\."
287 # Seemingly-valid but not quite valid value.
288 gdb_test "$set_cmd on1" \
289 "\"on\", \"off\" or \"auto\" expected\\."
291 # Valid value followed by garbage.
292 gdb_test "$set_cmd on 1" \
293 "\"on\", \"off\" or \"auto\" expected\\."
296 gdb_test "$set_cmd o" \
297 "\"on\", \"off\" or \"auto\" expected\\."
299 # Various valid values. Test both full value names and
302 foreach_with_prefix value {
315 gdb_test_no_output "$set_cmd off"
316 show_setting "$show_cmd" "off"
318 gdb_test_no_output "$set_cmd $value"
319 show_setting "$show_cmd" "on"
322 foreach_with_prefix value {
336 gdb_test_no_output "$set_cmd on"
337 show_setting "$show_cmd" "on"
339 gdb_test_no_output "$set_cmd $value"
340 show_setting "$show_cmd" "off"
343 foreach_with_prefix value {
350 gdb_test_no_output "$set_cmd on"
351 show_setting "$show_cmd" "on"
353 gdb_test_no_output "$set_cmd $value"
354 show_setting "$show_cmd" "auto"
357 # "-" is not accepted as abbreviation of "-1".
358 gdb_test "$set_cmd -" \
359 "\"on\", \"off\" or \"auto\" expected\\."
361 test_gdb_complete_multiple "$set_cmd " "" "" {
367 test_gdb_complete_unique \
371 test_gdb_complete_none "$set_cmd x"
373 # Check that the show command doesn't complete anything.
374 test_gdb_complete_unique \
377 test_gdb_complete_none "$show_cmd "
381 proc_with_prefix test-enum {} {
382 # Use these variables to make sure we don't call the wrong command
384 set set_cmd "maint test-settings set enum"
385 set show_cmd "maint test-settings show enum"
388 gdb_test "$set_cmd" \
389 "Requires an argument\\. Valid arguments are xxx, yyy, zzz\\."
392 gdb_test "$set_cmd bogus" \
393 "Undefined item: \"bogus\"."
395 # Seemingly-valid but not quite valid value.
396 gdb_test "$set_cmd xxx1" \
397 "Undefined item: \"xxx1\"."
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"
409 # Various valid values. Test both full value names and
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"
418 test_gdb_complete_multiple "$set_cmd " "" "" {
424 test_gdb_complete_unique \
428 test_gdb_complete_none "$set_cmd a"
430 # Check that the show command doesn't complete anything.
431 test_gdb_complete_unique \
434 test_gdb_complete_none "$show_cmd "
437 # string settings tests.
438 proc test-string {variant} {
440 global srcfile binfile
442 # Load symbols for the completion test below.
443 clean_restart $binfile
445 # Use these variables to make sure we don't call the wrong command
447 set set_cmd "maint test-settings set $variant"
448 set show_cmd "maint test-settings show $variant"
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"
455 gdb_test_no_output "$set_cmd hello world"
456 show_setting "$show_cmd" "hello world"
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\\\\\""
463 gdb_test_no_output "$set_cmd \"hello world\""
464 show_setting "$show_cmd" "\"hello world\""
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\\.\\)\\."
473 # Check the value didn't change.
474 show_setting "$show_cmd" "\"hello world\""
476 gdb_test_no_output "$set_cmd"
477 gdb_test "$show_cmd" \
478 "^$show_cmd\r\n" "$show_cmd: empty second time"
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 "
488 # Complete on filename.
490 # See comments in gdb.base/completion.exp.
492 # We `cd' to ${srcdir}, and then do the completion relative to
493 # the current directory.
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
504 gdb_test "cd ${fullsrcdir}" \
505 "Working directory [string_to_regexp ${fullsrcdir}].*" \
508 set unique_file ../testsuite/gdb.base/comp-dir/subdir/dummy
510 test_gdb_complete_unique \
511 "$set_cmd ${unique_file}" \
512 "$set_cmd ${unique_file}.txt"
514 test_gdb_complete_none "$set_cmd ${unique_file}.abc"
517 # Check show command completion.
518 if {$variant == "string"} {
519 test_gdb_complete_multiple "maint test-settings show " "string" "" {
524 test_gdb_complete_unique \
528 test_gdb_complete_none "$show_cmd "
538 with_test_prefix "test-integer $variant" {
539 test-integer $variant
553 with_test_prefix "test-string $variant" {