1 # This testcase is part of GDB, the GNU debugger.
3 # Copyright 2019-2020 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 "with" command.
20 load_lib completion-support.exp
24 if {[build_executable "failed to prepare" $testfile $srcfile debug]} {
28 clean_restart $binfile
30 # Test "maint with". VALUES is a list of values. A nested "with" is
31 # performed with each combination of pair of values from this list.
32 # This exercises setting a value, and restoring it too. This is
33 # particularly important for the "special" values like "unlimited",
34 # which for example for var_uinteger maps to 0 at the user-visible
35 # level, but maps to -1 internally.
37 proc test_with {setting values} {
38 foreach val1 $values {
39 foreach val2 $values {
41 "maint with test-settings $setting $val1 -- maint with test-settings $setting $val2 -- p 1" \
47 # Test "maint with" in the error case. SETTING is the "maint set
48 # test-setting" setting to exercise. TMP_VAL is the value to set the
49 # setting to. EXPECTED_RE is the expected GDB output, which should be
50 # an error of some kind. Also checks that the setting's original
51 # value is preserved across the error.
53 proc test_with_error {setting tmp_val expected_re} {
56 with_test_prefix "$setting, $tmp_val" {
57 set test "save org value"
59 gdb_test_multiple "maint show test-settings $setting" $test {
60 -re "(.*)\r\n$gdb_prompt $" {
61 set org_val $expect_out(1,string)
67 "maint with test-settings $setting $tmp_val -- p 1" \
70 gdb_test "maint show test-settings $setting" "^$org_val" \
71 "value hasn't changed across error"
75 # Test "with" framework basics, using the internal "maint with
76 # test-settings" subcommands.
77 with_test_prefix "maint" {
78 test_with "auto-boolean" {"on" "off" "auto"}
79 test_with "boolean" {"" "on" "off" "0" "1" "enable" "disable"}
80 test_with "integer" {"0" "1" "-1" "unlimited"}
81 test_with "uinteger" {"0" "1" "unlimited"}
82 test_with "zinteger" {"0" "1" "-1"}
83 test_with "zuinteger" {"0" "1"}
84 test_with "zuinteger-unlimited" {"-1" "unlimited" "0" "1"}
85 test_with "string" {"" "foo" "\"hello world\""}
86 test_with "string-noescape" {"" "foo" "\"hello world\""}
87 test_with "filename" {"/foo" "bar/x/y"}
88 test_with "optional-filename" {"" "/foo" "bar/x/y"}
89 test_with "enum" {"xxx" "yyy"}
91 # Check the most important error conditions. E.g., empty,
92 # negative or "unlimited" values for settings that don't accept
93 # those. Exhaustive error coverage of the set/with value parsing
94 # is left to "set" testing, in gdb.base/settings.exp.
95 test_with_error "auto-boolean" "" \
96 "\"on\", \"off\" or \"auto\" expected\\."
97 test_with_error "auto-boolean" "xxx" \
98 "\"on\", \"off\" or \"auto\" expected\\."
99 test_with_error "boolean" "2" "\"on\" or \"off\" expected\\."
100 test_with_error "uinteger" "-1" "integer -1 out of range"
101 test_with_error "uinteger" "" \
102 "Argument required \\(integer to set it to, or \"unlimited\"\\.\\)\\."
103 test_with_error "zuinteger" "-1" "integer -1 out of range"
104 test_with_error "zuinteger" "" \
105 "Argument required \\(integer to set it to\\.\\)\\."
106 test_with_error "zuinteger-unlimited" "-2" \
107 "only -1 is allowed to set as unlimited"
108 test_with_error "zuinteger-unlimited" "" \
109 "Argument required \\(integer to set it to, or \"unlimited\"\\.\\)\\."
110 test_with_error "filename" "" \
111 "Argument required \\(filename to set it to\\.\\)\\."
112 test_with_error "enum" "" \
113 "Requires an argument\\. Valid arguments are xxx, yyy, zzz\\."
116 # Basic/core tests using user-visible commands.
117 with_test_prefix "basics" {
118 gdb_test "print g_s" " = {a = 1, b = 2, c = 3}"
119 gdb_test "with print pretty -- print g_s" \
128 gdb_test "with non-stop on -- show non-stop" \
129 "Controlling the inferior in non-stop mode is on\\."
130 gdb_test "show non-stop" \
131 "Controlling the inferior in non-stop mode is off\\."
134 gdb_test "with language pascal -- show language" \
135 "The current source language is \"pascal\"\\."
137 gdb_test "show language" \
138 "The current source language is \"auto; currently c\"\\."
140 gdb_test "with language ada -- print g_s" \
141 " = \\(a => 1, b => 2, c => 3\\)"
144 gdb_test "with language ada -- with language c -- print g_s" \
145 " = {a = 1, b = 2, c = 3}"
148 gdb_test "w language pascal -- show language" \
149 "The current source language is \"pascal\"\\." \
152 # An early prototype of the "with" command got this wrong.
154 "w print repeats unlimited -- w print repeats 1 -- p \"1223334444\"" \
155 " = \"1\", '2' <repeats 2 times>, '3' <repeats 3 times>, '4' <repeats 4 times>"
158 # Check a user-defined command.
159 with_test_prefix "user-defined" {
160 # A user defined command.
161 set test "define usercmd"
162 gdb_test_multiple "define usercmd" $test {
172 gdb_test "with language ada -- usercmd" \
173 " = \\(a => 1, b => 2, c => 3\\)"
177 with_test_prefix "repeat" {
178 clean_restart $binfile
180 # "with" with no command reinvokes the previous command.
181 gdb_test "with language ada" \
182 "No previous command to relaunch" \
183 "reinvoke with no previous command to relaunch"
185 gdb_test "print g_s" " = {a = 1, b = 2, c = 3}"
187 gdb_test "with language ada" \
188 " = \\(a => 1, b => 2, c => 3\\)" \
189 "reinvoke with language"
191 # Same, but with "--".
192 gdb_test "with language fortran --" \
193 " = \\( a = 1, b = 2, c = 3 \\)" \
194 "reinvoke with language and --"
196 # Repeating repeats the original "print g_s", not the last "with"
198 set test "repeat command line"
200 gdb_test_multiple "" $test {
201 -re " = {a = 1, b = 2, c = 3}\r\n$gdb_prompt $" {
208 with_test_prefix "run control" {
209 clean_restart $binfile
212 fail "cannot run to main"
216 # Check "with" with a synchronous execution command.
217 gdb_test "with disassemble-next-line on -- next" \
222 with_test_prefix "errors" {
223 gdb_test "with" "Missing arguments\\."
225 # Try both an unknown root setting and an unknown prefixed
226 # setting. The errors come from different locations in the
228 gdb_test "with xxxx yyyy" \
229 "Undefined set command: \"xxxx\". Try \"help set\"\\."
230 gdb_test "with print xxxx yyyy" \
231 "Undefined set print command: \"xxxx yyyy\". Try \"help set print\"\\."
232 # Try one error case for "maint with", to make sure the right
233 # "maintenance with" prefix is shown.
234 gdb_test "maint with xxxx yyyy" \
235 "Undefined maintenance set command: \"xxxx\". Try \"help maintenance set\"\\."
237 # Try ambiguous settings.
239 "Ambiguous set command \"w\": watchdog, width, write\\."
240 gdb_test "with print m" \
241 "Ambiguous set print command \"m\": max-depth, max-symbolic-offset\\."
243 gdb_test "with variable xxx=1" \
244 "Cannot use this setting with the \"with\" command"
246 gdb_test "with print elements -- p 1" \
247 "Argument required \\(integer to set it to, or \"unlimited\"\\.\\)\\."
249 gdb_test "with -- p 1" \
250 "Missing setting before '--' delimiter"
252 # Check that the setting is restored even if the command throws.
253 gdb_test "with print elements 1 -- unknowncommand" \
254 "Undefined command: \"unknowncommand\"\\. Try \"help\"\\."
255 gdb_test "show print elements" \
256 "Limit on string chars or array elements to print is 200\\."
260 with_test_prefix "completion" {
261 test_gdb_complete_unique \
265 test_gdb_complete_unique \
267 "with print elements"
269 test_gdb_complete_unique \
270 "with print elements u" \
271 "with print elements unlimited"
273 test_gdb_complete_none \
274 "with print elements unlimited "
276 test_gdb_completion_offers_commands "with print elements unlimited -- "
278 # Check that the completer nests into the nested command line's
280 test_gdb_complete_unique \
281 "with print elements unlimited -- with print ele" \
282 "with print elements unlimited -- with print elements"
284 # Check completion of "maint with". "maint with" and "with"'s
285 # completers share 99% of the code. All we need to care about
286 # here is that the completion word point is computed correctly, so
287 # any simple completion is sufficient.
288 test_gdb_complete_unique \
289 "maint with test-set" \
290 "maint with test-settings"