]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/with.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / with.exp
CommitLineData
fdbc9870
PA
1# This testcase is part of GDB, the GNU debugger.
2
1d506c26 3# Copyright 2019-2024 Free Software Foundation, Inc.
fdbc9870
PA
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 "with" command.
19
20load_lib completion-support.exp
21
22standard_testfile .c
23
24if {[build_executable "failed to prepare" $testfile $srcfile debug]} {
25 return -1
26}
27
28clean_restart $binfile
29
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.
36
37proc test_with {setting values} {
38 foreach val1 $values {
39 foreach val2 $values {
40 gdb_test \
41 "maint with test-settings $setting $val1 -- maint with test-settings $setting $val2 -- p 1" \
42 " = 1"
43 }
44 }
45}
46
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.
52
53proc test_with_error {setting tmp_val expected_re} {
54 global gdb_prompt
55
56 with_test_prefix "$setting, $tmp_val" {
fdbc9870 57 set org_val ""
08ec06d6
AB
58 gdb_test_multiple "maint show test-settings $setting" \
59 "save org value" {
60 -re "^maint show test-settings $setting\r\n" {
61 exp_continue
62 }
63 -re "^(.*)\r\n$gdb_prompt $" {
64 set org_val $expect_out(1,string)
65 pass $gdb_test_name
66 }
fdbc9870 67 }
fdbc9870
PA
68
69 gdb_test \
70 "maint with test-settings $setting $tmp_val -- p 1" \
71 $expected_re
72
73 gdb_test "maint show test-settings $setting" "^$org_val" \
74 "value hasn't changed across error"
75 }
76}
77
78# Test "with" framework basics, using the internal "maint with
79# test-settings" subcommands.
80with_test_prefix "maint" {
81 test_with "auto-boolean" {"on" "off" "auto"}
82 test_with "boolean" {"" "on" "off" "0" "1" "enable" "disable"}
83 test_with "integer" {"0" "1" "-1" "unlimited"}
84 test_with "uinteger" {"0" "1" "unlimited"}
85 test_with "zinteger" {"0" "1" "-1"}
86 test_with "zuinteger" {"0" "1"}
87 test_with "zuinteger-unlimited" {"-1" "unlimited" "0" "1"}
88 test_with "string" {"" "foo" "\"hello world\""}
89 test_with "string-noescape" {"" "foo" "\"hello world\""}
90 test_with "filename" {"/foo" "bar/x/y"}
91 test_with "optional-filename" {"" "/foo" "bar/x/y"}
92 test_with "enum" {"xxx" "yyy"}
93
94 # Check the most important error conditions. E.g., empty,
95 # negative or "unlimited" values for settings that don't accept
96 # those. Exhaustive error coverage of the set/with value parsing
97 # is left to "set" testing, in gdb.base/settings.exp.
98 test_with_error "auto-boolean" "" \
99 "\"on\", \"off\" or \"auto\" expected\\."
100 test_with_error "auto-boolean" "xxx" \
101 "\"on\", \"off\" or \"auto\" expected\\."
102 test_with_error "boolean" "2" "\"on\" or \"off\" expected\\."
103 test_with_error "uinteger" "-1" "integer -1 out of range"
104 test_with_error "uinteger" "" \
575fd4cf 105 "Argument required \\(integer to set it to, or \"unlimited\"\\)\\."
fdbc9870
PA
106 test_with_error "zuinteger" "-1" "integer -1 out of range"
107 test_with_error "zuinteger" "" \
575fd4cf 108 "Argument required \\(integer to set it to\\)\\."
fdbc9870 109 test_with_error "zuinteger-unlimited" "-2" \
7aeb03e2 110 "integer -2 out of range"
fdbc9870 111 test_with_error "zuinteger-unlimited" "" \
575fd4cf 112 "Argument required \\(integer to set it to, or \"unlimited\"\\)\\."
fdbc9870
PA
113 test_with_error "filename" "" \
114 "Argument required \\(filename to set it to\\.\\)\\."
115 test_with_error "enum" "" \
116 "Requires an argument\\. Valid arguments are xxx, yyy, zzz\\."
117}
118
119# Basic/core tests using user-visible commands.
120with_test_prefix "basics" {
121 gdb_test "print g_s" " = {a = 1, b = 2, c = 3}"
122 gdb_test "with print pretty -- print g_s" \
123 [multi_line \
124 " = {" \
125 " a = 1," \
126 " b = 2," \
127 " c = 3" \
128 "}"]
129
130 # A boolean setting.
131 gdb_test "with non-stop on -- show non-stop" \
132 "Controlling the inferior in non-stop mode is on\\."
133 gdb_test "show non-stop" \
134 "Controlling the inferior in non-stop mode is off\\."
135
136 # Language.
137 gdb_test "with language pascal -- show language" \
138 "The current source language is \"pascal\"\\."
139
140 gdb_test "show language" \
141 "The current source language is \"auto; currently c\"\\."
142
143 gdb_test "with language ada -- print g_s" \
144 " = \\(a => 1, b => 2, c => 3\\)"
145
146 # Nested "with"s.
147 gdb_test "with language ada -- with language c -- print g_s" \
148 " = {a = 1, b = 2, c = 3}"
149
150 # "w" alias.
151 gdb_test "w language pascal -- show language" \
152 "The current source language is \"pascal\"\\." \
153 "w alias works"
154
155 # An early prototype of the "with" command got this wrong.
156 gdb_test \
157 "w print repeats unlimited -- w print repeats 1 -- p \"1223334444\"" \
158 " = \"1\", '2' <repeats 2 times>, '3' <repeats 3 times>, '4' <repeats 4 times>"
159}
160
161# Check a user-defined command.
162with_test_prefix "user-defined" {
163 # A user defined command.
164 set test "define usercmd"
165 gdb_test_multiple "define usercmd" $test {
166 -re "End with" {
167 gdb_test \
168 [multi_line_input \
169 {print g_s} \
170 {end}] \
171 "" \
172 $test
173 }
174 }
175 gdb_test "with language ada -- usercmd" \
176 " = \\(a => 1, b => 2, c => 3\\)"
177}
178
179# Check repeating.
180with_test_prefix "repeat" {
181 clean_restart $binfile
182
183 # "with" with no command reinvokes the previous command.
184 gdb_test "with language ada" \
185 "No previous command to relaunch" \
186 "reinvoke with no previous command to relaunch"
187
188 gdb_test "print g_s" " = {a = 1, b = 2, c = 3}"
189
190 gdb_test "with language ada" \
191 " = \\(a => 1, b => 2, c => 3\\)" \
192 "reinvoke with language"
193
194 # Same, but with "--".
195 gdb_test "with language fortran --" \
196 " = \\( a = 1, b = 2, c = 3 \\)" \
197 "reinvoke with language and --"
198
199 # Repeating repeats the original "print g_s", not the last "with"
200 # command.
201 set test "repeat command line"
202 send_gdb "\n"
203 gdb_test_multiple "" $test {
204 -re " = {a = 1, b = 2, c = 3}\r\n$gdb_prompt $" {
205 pass $test
206 }
207 }
208}
209
210# Basic run control.
211with_test_prefix "run control" {
212 clean_restart $binfile
213
214 if ![runto_main] {
fdbc9870
PA
215 return
216 }
217
218 # Check "with" with a synchronous execution command.
219 gdb_test "with disassemble-next-line on -- next" \
220 "return 0;.*=>.*"
221}
222
223# Check errors.
224with_test_prefix "errors" {
26c957f1
PA
225 gdb_test "with" "Missing arguments\\."
226
fdbc9870
PA
227 # Try both an unknown root setting and an unknown prefixed
228 # setting. The errors come from different locations in the
229 # sources.
230 gdb_test "with xxxx yyyy" \
231 "Undefined set command: \"xxxx\". Try \"help set\"\\."
232 gdb_test "with print xxxx yyyy" \
233 "Undefined set print command: \"xxxx yyyy\". Try \"help set print\"\\."
234 # Try one error case for "maint with", to make sure the right
235 # "maintenance with" prefix is shown.
236 gdb_test "maint with xxxx yyyy" \
237 "Undefined maintenance set command: \"xxxx\". Try \"help maintenance set\"\\."
238
239 # Try ambiguous settings.
240 gdb_test "with w" \
241 "Ambiguous set command \"w\": watchdog, width, write\\."
242 gdb_test "with print m" \
bef382e6 243 "Ambiguous set print command \"m\": max-depth, max-symbolic-offset, memory-tag-violations\\."
fdbc9870
PA
244
245 gdb_test "with variable xxx=1" \
246 "Cannot use this setting with the \"with\" command"
247
248 gdb_test "with print elements -- p 1" \
575fd4cf 249 "Argument required \\(integer to set it to, or \"unlimited\"\\)\\."
fdbc9870
PA
250
251 gdb_test "with -- p 1" \
252 "Missing setting before '--' delimiter"
253
254 # Check that the setting is restored even if the command throws.
255 gdb_test "with print elements 1 -- unknowncommand" \
256 "Undefined command: \"unknowncommand\"\\. Try \"help\"\\."
257 gdb_test "show print elements" \
258 "Limit on string chars or array elements to print is 200\\."
259}
260
261# Check completion.
262with_test_prefix "completion" {
263 test_gdb_complete_unique \
264 "with pri" \
265 "with print"
266
267 test_gdb_complete_unique \
268 "with print ele" \
269 "with print elements"
270
271 test_gdb_complete_unique \
272 "with print elements u" \
273 "with print elements unlimited"
274
275 test_gdb_complete_none \
276 "with print elements unlimited "
277
278 test_gdb_completion_offers_commands "with print elements unlimited -- "
279
280 # Check that the completer nests into the nested command line's
281 # completer.
282 test_gdb_complete_unique \
283 "with print elements unlimited -- with print ele" \
284 "with print elements unlimited -- with print elements"
285
286 # Check completion of "maint with". "maint with" and "with"'s
287 # completers share 99% of the code. All we need to care about
288 # here is that the completion word point is computed correctly, so
289 # any simple completion is sufficient.
290 test_gdb_complete_unique \
291 "maint with test-set" \
292 "maint with test-settings"
293}