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 gdb_test "$set_cmd unlimitedu" "No symbol table is loaded.*"
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 "
156 # Check show command completion.
157 if {$variant == "zuinteger"} {
158 test_gdb_complete_multiple "maintenance test-settings show " "zuinteger" "" {
160 "zuinteger-unlimited"
163 test_gdb_complete_unique \
167 test_gdb_complete_none "$show_cmd "
171 proc_with_prefix test-boolean {} {
172 # Use these variables to make sure we don't call the wrong command
174 set set_cmd "maint test-settings set boolean"
175 set show_cmd "maint test-settings show boolean"
178 gdb_test "$set_cmd bogus" \
179 "\"on\" or \"off\" expected\\."
181 # Seemingly-valid but not quite valid value.
182 gdb_test "$set_cmd on1" \
183 "\"on\" or \"off\" expected\\."
185 # Valid value followed by garbage.
186 gdb_test "$set_cmd on 1" \
187 "\"on\" or \"off\" expected\\."
189 # Unlike auto-bool settings, "-1" is not accepted.
190 gdb_test "$set_cmd -1" \
191 "\"on\" or \"off\" expected\\."
194 gdb_test "$set_cmd auto" \
195 "\"on\" or \"off\" expected\\."
197 # Various valid values. Test both full value names and
200 # Note that unlike with auto-bool, empty value implies "on".
201 foreach_with_prefix value {
216 gdb_test_no_output "$set_cmd off"
217 show_setting "$show_cmd" "off"
219 gdb_test_no_output "$set_cmd $value"
220 show_setting "$show_cmd" "on"
223 foreach_with_prefix value {
237 gdb_test_no_output "$set_cmd on"
238 show_setting "$show_cmd" "on"
240 gdb_test_no_output "$set_cmd $value"
241 show_setting "$show_cmd" "off"
244 test_gdb_complete_multiple "$set_cmd " "" "o" {
249 test_gdb_complete_unique \
253 test_gdb_complete_none "$set_cmd x"
255 # Check that the show command doesn't complete anything.
256 test_gdb_complete_unique \
259 test_gdb_complete_none "$show_cmd "
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
266 set set_cmd "maint test-settings set auto-boolean"
267 set show_cmd "maint test-settings show auto-boolean"
270 gdb_test "$set_cmd bogus" \
271 "\"on\", \"off\" or \"auto\" expected\\."
273 # Seemingly-valid but not quite valid value.
274 gdb_test "$set_cmd on1" \
275 "\"on\", \"off\" or \"auto\" expected\\."
277 # Valid value followed by garbage.
278 gdb_test "$set_cmd on 1" \
279 "\"on\", \"off\" or \"auto\" expected\\."
281 # Various valid values. Test both full value names and
284 foreach_with_prefix value {
298 gdb_test_no_output "$set_cmd off"
299 show_setting "$show_cmd" "off"
301 gdb_test_no_output "$set_cmd $value"
302 show_setting "$show_cmd" "on"
305 foreach_with_prefix value {
319 gdb_test_no_output "$set_cmd on"
320 show_setting "$show_cmd" "on"
322 gdb_test_no_output "$set_cmd $value"
323 show_setting "$show_cmd" "off"
326 foreach_with_prefix value {
333 gdb_test_no_output "$set_cmd on"
334 show_setting "$show_cmd" "on"
336 gdb_test_no_output "$set_cmd $value"
337 show_setting "$show_cmd" "auto"
340 # "-" is not accepted as abbreviation of "-1".
341 gdb_test "$set_cmd -" \
342 "\"on\", \"off\" or \"auto\" expected\\."
344 test_gdb_complete_multiple "$set_cmd " "" "" {
350 test_gdb_complete_unique \
354 test_gdb_complete_none "$set_cmd x"
356 # Check that the show command doesn't complete anything.
357 test_gdb_complete_unique \
360 test_gdb_complete_none "$show_cmd "
364 proc_with_prefix test-enum {} {
365 # Use these variables to make sure we don't call the wrong command
367 set set_cmd "maint test-settings set enum"
368 set show_cmd "maint test-settings show enum"
371 gdb_test "$set_cmd" \
372 "Requires an argument\\. Valid arguments are xxx, yyy, zzz\\."
375 gdb_test "$set_cmd bogus" \
376 "Undefined item: \"bogus\"."
378 # Seemingly-valid but not quite valid value.
379 gdb_test "$set_cmd xxx1" \
380 "Undefined item: \"xxx1\"."
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"
392 # Various valid values. Test both full value names and
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"
401 test_gdb_complete_multiple "$set_cmd " "" "" {
407 test_gdb_complete_unique \
411 test_gdb_complete_none "$set_cmd a"
413 # Check that the show command doesn't complete anything.
414 test_gdb_complete_unique \
417 test_gdb_complete_none "$show_cmd "
420 # string settings tests.
421 proc test-string {variant} {
423 global srcfile binfile
425 # Load symbols for the completion test below.
426 clean_restart $binfile
428 # Use these variables to make sure we don't call the wrong command
430 set set_cmd "maint test-settings set $variant"
431 set show_cmd "maint test-settings show $variant"
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"
438 gdb_test_no_output "$set_cmd hello world"
439 show_setting "$show_cmd" "hello world"
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\\\\\""
446 gdb_test_no_output "$set_cmd \"hello world\""
447 show_setting "$show_cmd" "\"hello world\""
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\\.\\)\\."
456 # Check the value didn't change.
457 show_setting "$show_cmd" "\"hello world\""
459 gdb_test_no_output "$set_cmd"
460 gdb_test "$show_cmd" \
461 "^$show_cmd\r\n" "$show_cmd: empty second time"
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 "
471 # Complete on filename.
473 # See comments in gdb.base/completion.exp.
475 # We `cd' to ${srcdir}, and then do the completion relative to
476 # the current directory.
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
487 gdb_test "cd ${fullsrcdir}" \
488 "Working directory [string_to_regexp ${fullsrcdir}].*" \
491 set unique_file ../testsuite/gdb.base/comp-dir/subdir/dummy
493 test_gdb_complete_unique \
494 "$set_cmd ${unique_file}" \
495 "$set_cmd ${unique_file}.txt"
497 test_gdb_complete_none "$set_cmd ${unique_file}.abc"
500 # Check show command completion.
501 if {$variant == "string"} {
502 test_gdb_complete_multiple "maint test-settings show " "string" "" {
507 test_gdb_complete_unique \
511 test_gdb_complete_none "$show_cmd "
521 with_test_prefix "test-integer $variant" {
522 test-integer $variant
536 with_test_prefix "test-string $variant" {