]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/setshow.exp
Automatic date update in version.in
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / setshow.exp
1 # Copyright 1992-2024 Free Software Foundation, Inc.
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16 # This file was written by Michael Snyder (msnyder@cygnus.com)
17
18 # Test gdb set and show commands. The goal here is to verify that parameters
19 # are set and shown correctly, not test whether setting the parameter has the
20 # desired effect.
21
22
23 standard_testfile .c
24
25 if { [gdb_compile ${srcdir}/${subdir}/${srcfile} ${binfile} executable {debug}] != "" } {
26 untested "failed to compile"
27 return -1
28 }
29
30 proc_with_prefix test_setshow_annotate {} {
31 # Start with a fresh gdb
32 clean_restart $::binfile
33
34 if {![runto_main]} {
35 return
36 }
37
38 #test default annotation_level is 0
39 gdb_test "show annotate" "Annotation_level is 0..*" "default annotation_level is zero"
40
41 #test set annotate 2
42
43 # Here we need to fiddle with prompts.
44 save_vars { ::gdb_prompt } {
45 set old_gdb_prompt $::gdb_prompt
46 set ::gdb_prompt "\r\n\032\032pre-prompt\r\n$::gdb_prompt \r\n\032\032prompt\r\n"
47
48 gdb_test_multiple "set annotate 2" "set annotate 2" {
49 -re "\r\n$::gdb_prompt$" {
50 pass "set annotate 2"
51 }
52 }
53
54 gdb_test_multiple "show annotate" "show annotate 2" {
55 -re ".*\032\032post-prompt.*Annotation_level is 2..*\032\032pre-prompt.*$old_gdb_prompt .*\032\032prompt.*$" {
56 pass "show annotate 2"
57 }
58 }
59
60 #test annotation_level 2
61 gdb_test_multiple "info line 1" "annotation_level 2" {
62 -re ".*\032\032post-prompt.*Line 1 of .* is at address .* but contains no code.*:1:0:beg:0x.*\032\032pre-prompt.*$old_gdb_prompt .*\032\032prompt.*$" {
63 pass "annotation_level 2"
64 }
65 }
66 }
67
68 #test set annotate 1
69 gdb_test "set annotate 1" ".*post-prompt.*"
70 gdb_test "show annotate" "Annotation_level is 1..*" "show annotate, 1"
71 #test annotation_level 1
72 gdb_test "info line 1" "Line 1 of .* is at address .* but contains no code.*:1:0:beg:0x.*" "annotation_level 1"
73 #test set annotate 0
74 gdb_test_no_output "set annotate 0" "set annotate 0"
75 gdb_test "show annotate" "Annotation_level is 0..*" "show annotate, 0"
76 #test annotation_level 0
77 gdb_test "info line 1" "Line 1 of .* is at address .* but contains no code.*" "annotation_level 0"
78 }
79
80 proc_with_prefix test_setshow_args {} {
81 clean_restart $::binfile
82
83 if {![runto_main]} {
84 return
85 }
86
87 gdb_test "show args" "Argument list to give program being debugged when it is started is \"\"\." \
88 "show args empty"
89 gdb_test "p \$_gdb_setting_str(\"args\")" " = \"\""
90
91 gdb_test_no_output "set args ~"
92 gdb_test "show args" "Argument list to give program being debugged when it is started is \"~\"..*" \
93 "show args ~"
94
95 #test set args
96 gdb_test_no_output "set args foo bar blup baz bubble" "set args"
97
98 #test show args
99 gdb_test "show args" "Argument list to give program being debugged when it is started is \"foo bar blup baz bubble\"..*" \
100 "show args multiple words"
101 gdb_test "p \$_gdb_setting(\"args\")" " = \"foo bar blup baz bubble\"" \
102 "_gdb_setting args"
103
104 # Don't test if we can't pass args or if we're using a stub.
105 if { !$::use_gdb_stub && ![target_info exists noargs] } {
106 #test passing args
107 gdb_test "cont" "Continuing.*" "continuing"
108 delete_breakpoints
109 gdb_test "run" "Starting program:.*foo bar blup baz bubble.*" "passing args"
110 }
111 }
112
113 proc_with_prefix test_setshow_check {} {
114 clean_restart
115
116 #test set check range on
117 # Note: the below might produce a warning, so match anything.
118 gdb_test "set check range on" ""
119
120 gdb_test "p \$_gdb_setting(\"check range\")" " = \"on\"" \
121 "_gdb_setting check range on"
122
123 #test show check range on
124 gdb_test "show check range" "Range checking is \"on\"\..*" "show check range, on"
125
126 #test set check range off with trailing space
127 gdb_test_no_output "set check range off " "set check range off"
128
129 #test show check range off
130 gdb_test "show check range" "Range checking is \"off\"\..*" "show check range, off"
131 gdb_test "p \$_gdb_setting(\"check range\")" " = \"off\"" \
132 "_gdb_setting check range off"
133
134 #test set check range auto
135 gdb_test_no_output "set check range auto" "set check range auto"
136
137 #test show check range auto
138 gdb_test "show check range" "Range checking is \"auto; currently .*" "show check range (auto)"
139 gdb_test "p \$_gdb_setting(\"check range\")" " = \"auto\"" \
140 "_gdb_setting check range auto"
141
142 # Test set check type on
143 gdb_test_no_output "set check type on"
144
145 # Test show check type on
146 gdb_test "show check type" "Strict type checking is on\..*" \
147 "show check type, on"
148 gdb_test "p \$_gdb_setting_str(\"check type\")" " = \"on\"" \
149 "_gdb_setting_str check type on"
150 gdb_test "p \$_gdb_setting(\"check type\")" " = 1" \
151 "_gdb_setting check type on 1"
152
153 # Test set check type off with trailing space
154 gdb_test_no_output "set check type off " "set check type off"
155 gdb_test "p \$_gdb_setting_str(\"check type\")" " = \"off\"" \
156 "_gdb_setting_str check type off"
157 gdb_test "p \$_gdb_setting(\"check type\")" " = 0" \
158 "_gdb_setting check type off 0"
159
160 # Test show check type off
161 gdb_test "show check type" "Strict type checking is off\..*" \
162 "show check type, off"
163 }
164
165 proc_with_prefix test_setshow_breakpoint_pending {} {
166 #test set breakpoint pending
167
168 #test set breakpoint pending on
169 gdb_test_no_output "set breakpoint pending on"
170 gdb_test "p \$_gdb_setting_str(\"breakpoint pending\")" " = \"on\"" \
171 "_gdb_setting_str breakpoint pending on"
172 gdb_test "p \$_gdb_setting(\"breakpoint pending\")" " = 1" \
173 "_gdb_setting breakpoint pending 1"
174
175 #test show breakpoint pending on
176 gdb_test "show breakpoint pending" " is on\..*" "show breakpoint pending on"
177
178 #test show breakpoint pending off
179 gdb_test_no_output "set breakpoint pending off"
180 gdb_test "show breakpoint pending" " is off\..*" "show breakpoint pending off"
181 gdb_test "p \$_gdb_setting_str(\"breakpoint pending\")" " = \"off\"" \
182 "_gdb_setting_str breakpoint pending off"
183 gdb_test "p \$_gdb_setting(\"breakpoint pending\")" " = 0" \
184 "_gdb_setting breakpoint pending 0"
185
186 #test set breakpoint pending auto
187 gdb_test_no_output "set breakpoint pending auto"
188
189 #test show breakpoint pending auto
190 gdb_test "show breakpoint pending" " is auto.*" "show breakpoint pending auto"
191 gdb_test "p \$_gdb_setting_str(\"breakpoint pending\")" " = \"auto\"" \
192 "_gdb_setting_str breakpoint pending auto"
193 gdb_test "p \$_gdb_setting(\"breakpoint pending\")" " = -1" \
194 "_gdb_setting breakpoint pending -1"
195 }
196
197 proc_with_prefix test_setshow_complaints {} {
198 clean_restart
199
200 #test set complaints 100
201 gdb_test_no_output "set complaints 100" "set complaints 100"
202 #test show complaints 100
203 gdb_test "show complaints" "Max number of complaints about incorrect symbols is 100..*" "show complaints, 100"
204 #test set complaints 0
205 gdb_test_no_output "set complaints 0" "set complaints 0"
206 #test show complaints 0
207 gdb_test "show complaints" "Max number of complaints about incorrect symbols is 0..*" "show complaints, 0"
208 }
209
210 proc_with_prefix test_setshow_confirm {} {
211 clean_restart
212
213 #test set confirm off
214 gdb_test_no_output "set confirm off" "set confirm off"
215 #test show confirm off
216 gdb_test "show confirm" "Whether to confirm potentially dangerous operations is off..*" "show confirm, off"
217 #test set confirm on
218 gdb_test_no_output "set confirm on" "set confirm on"
219 #test show confirm on
220 gdb_test "show confirm" "Whether to confirm potentially dangerous operations is on..*" "show confirm, on"
221 }
222
223 proc_with_prefix test_setshow_editing {} {
224 clean_restart
225
226 #test set editing off
227 gdb_test_no_output "set editing off" "set editing off"
228
229 #test show editing off
230 gdb_test "show editing" "Editing of command lines as they are typed is off..*" "show editing (off)"
231
232 #test set editing on
233 #gdb_test_no_output "set editing on" "set editing on"
234
235 #test show editing on
236 #gdb_test "show editing" "Editing of command lines as they are typed is on..*" "show editing (on)"
237 }
238
239 proc_with_prefix test_setshow_environment {} {
240 clean_restart
241
242 #test set environment FOOBARBAZ
243 gdb_test_no_output "set environment FOOBARBAZ = grbxgrbxgrbx" \
244 "set environment FOOBARBAZ"
245
246 #test show environment FOOBARBAZ
247 gdb_test "show environment FOOBARBAZ" "FOOBARBAZ = grbxgrbxgrbx.*"
248 }
249
250 proc_with_prefix test_setshow_height {} {
251 clean_restart
252
253 #test set height 100
254 gdb_test_no_output "set height 100" "set height 100"
255
256 #test show height 100
257 gdb_test "show height" "Number of lines gdb thinks are in a page is 100..*"
258 gdb_test "p \$_gdb_setting_str(\"height\")" " = \"100\"" \
259 "_gdb_setting_str height 100"
260 gdb_test "p \$_gdb_setting(\"height\")" " = 100" \
261 "_gdb_setting height 100"
262
263 # Back to infinite height to avoid pagers. While at it, check that
264 # literal "unlimited" works just as well as 0.
265 gdb_test_no_output "set height unlimited"
266 gdb_test "p \$_gdb_setting_str(\"height\")" " = \"unlimited\"" \
267 "_gdb_setting_str height unlimited"
268 gdb_test "p \$_gdb_setting(\"height\")" " = 0" \
269 "_gdb_setting height unlimited"
270 }
271
272 proc_with_prefix test_setshow_history {} {
273 clean_restart
274
275 #test set history expansion on
276 gdb_test_no_output "set history expansion on" "set history expansion on"
277
278 #test show history expansion on
279 gdb_test "show history expansion on" "History expansion on command input is on.*" "show history expansion"
280
281 #get home directory path
282 set HOME ""
283 set STRINGHOME ""
284 set test "show environment HOME"
285 gdb_test_multiple $test $test {
286 -re "\nHOME = (\[^\r\n\]*)\[\r\n\]+$::gdb_prompt $" {
287 set HOME $expect_out(1,string)
288 if { [ishost *-*-mingw*] } {
289 # STRINGHOME is how HOME prints with C string escapes.
290 # Specifically, all backslashes "\" in the pathname
291 # string have to be escaped as "\\". If you have other
292 # weird characters in your HOME pathname that need
293 # escaping too, maybe you shouldn't do that. :-P
294 regsub -all {\\} $HOME {\\\\} STRINGHOME
295 } else {
296 set STRINGHOME $HOME
297 }
298 pass $test
299 }
300 }
301
302 #test set history filename ~/foobar.baz
303 gdb_test_no_output "set history filename ~/foobar.baz" \
304 "set history filename ~/foobar.baz"
305
306 #test show history filename ~/foobar.baz
307 gdb_test "show history filename" \
308 "The filename in which to record the command history is \"[string_to_regexp $HOME]/foobar.baz\"..*" \
309 "show history filename (~/foobar.baz)"
310 gdb_test "p \$_gdb_setting(\"history filename\")" \
311 " = \"[string_to_regexp $STRINGHOME]/foobar.baz\"" \
312 "_gdb_setting history filename"
313 gdb_test "p \$_gdb_setting_str(\"history filename\")" \
314 " = \"[string_to_regexp $STRINGHOME]/foobar.baz\"" \
315 "_gdb_setting_str history filename"
316
317 #get current working directory
318 set PWD ""
319 set test "show working directory"
320 gdb_test_multiple "pwd" $test {
321 -re "\nWorking directory (\[^\r\n\]*)\\.\[\r\n\]+$::gdb_prompt $" {
322 set PWD $expect_out(1,string)
323 pass $test
324 }
325 }
326
327 #test set history filename foobar.baz
328 gdb_test_no_output "set history filename foobar.baz" \
329 "set history filename foobar.baz"
330
331 #test show history filename foobar.baz
332 gdb_test "show history filename" \
333 "The filename in which to record the command history is \"[string_to_regexp $PWD]/foobar.baz\"..*" \
334 "show history filename, current_directory/foobar.baz"
335
336 #test set history save on
337 gdb_test_no_output "set history save on" "set history save on"
338
339 #test show history save on
340 gdb_test "show history save" "Saving of the history record on exit is on..*" "show history save (on)"
341
342 #history saving should stay disabled
343 gdb_test_no_output "set history save off" "set history save off"
344
345 #test set history size 100
346 gdb_test_no_output "set history size 100" "set history size 100"
347
348 #test show history size 100
349 gdb_test "show history size" "The size of the command history is 100..*" "show history size (100)"
350 }
351
352 proc_with_prefix test_setshow_language {} {
353 clean_restart
354
355 #test set language asm
356 gdb_test_no_output "set language asm"
357
358 #test show language asm
359 gdb_test "show language" "The current source language is \"asm\"..*" "show language, asm"
360
361 #test set language rust, with a trailing space
362 gdb_test_no_output "set language rust " "set language rust"
363
364 #test show language rust
365 gdb_test "show language" "The current source language is \"rust\"..*" "show language, rust"
366
367 #test completion for set language.
368 gdb_test "complete set language min" "set language minimal" \
369 "complete set language minimal"
370
371 #test set language auto
372 gdb_test_no_output "set language auto" "set language auto"
373
374 #test show language
375 gdb_test "show language" "The current source language is \"auto.*\"..*" "show language, auto"
376 }
377
378 proc_with_prefix test_setshow_listsize {} {
379 clean_restart
380
381 #test set listsize 100
382 gdb_test_no_output "set listsize 100" "set listsize 100"
383
384 #test show listsize 100
385 gdb_test "show listsize" "Number of source lines gdb will list by default is 100..*" "show listsize (100)"
386 }
387
388 proc_with_prefix test_setshow_print_characters {} {
389 clean_restart
390
391 gdb_test "p \$_gdb_setting(\"print characters\")" " = void" \
392 "_gdb_setting print characters default"
393 gdb_test "p \$_gdb_setting_str(\"print characters\")" " = \"elements\"" \
394 "_gdb_setting_str print characters default"
395
396 gdb_test_no_output "set print characters unlimited"
397 gdb_test "p \$_gdb_setting(\"print characters\")" " = 0" \
398 "_gdb_setting print characters unlimited"
399 gdb_test "p \$_gdb_setting_str(\"print characters\")" " = \"unlimited\"" \
400 "_gdb_setting_str print characters unlimited"
401
402 gdb_test_no_output "set print characters 1"
403 gdb_test "p \$_gdb_setting(\"print characters\")" " = 1" \
404 "_gdb_setting print characters 1"
405 gdb_test "p \$_gdb_setting_str(\"print characters\")" " = \"1\"" \
406 "_gdb_setting_str print characters 1"
407 }
408
409 proc_with_prefix test_setshow_prompt {} {
410 clean_restart
411
412 if [board_info target exists gdb_prompt] {
413 return
414 }
415
416 #test set prompt (FooBarBaz)
417 set newprompt "\\(FooBarBaz\\)"
418
419 gdb_test_multiple "set prompt (FooBarBaz) " "set prompt FooBarBaz" {
420 -re "\[\r\n\]$newprompt $" {
421 pass "set prompt FooBarBaz"
422 }
423 }
424
425 #test show prompt (FooBarBaz)
426 gdb_test_multiple "show prompt" "show prompt FooBarBaz" {
427 -re "Gdb's prompt is \"$newprompt \"..* $" {
428 pass "show prompt FooBarBaz"
429 }
430 }
431
432 #test set prompt (gdb)
433 gdb_test_multiple "set prompt (gdb) " "set prompt gdb" {
434 -re "\[\r\n\]$::gdb_prompt $" {
435 pass "set prompt gdb"
436 }
437 }
438 }
439
440 proc_with_prefix test_setshow_radix {} {
441 clean_restart
442
443 #test set radix 11
444 gdb_test "set radix 11" "Unsupported output radix ``decimal 11''; output radix unchanged..*"
445
446 #test set radix 16
447 gdb_test "set radix 16" "Input and output radices now set to decimal 16, hex 10, octal 20..*"
448
449 #test show radix 16
450 gdb_test "show radix" "Input and output radices set to decimal 16, hex 10, octal 20..*" "show radix, 16"
451
452 #test set radix 10
453 gdb_test "set radix" "Input and output radices now set to decimal 10, hex a, octal 12..*" "set radix 10"
454
455 #test show radix 10
456 gdb_test "show radix" "Input and output radices set to decimal 10, hex a, octal 12..*" "show radix, 10"
457 }
458
459 proc_with_prefix test_setshow_width {} {
460 clean_restart
461
462 #test set width 90
463 gdb_test_no_output "set width 90" "set width 90"
464
465 #test show width 90
466 gdb_test "show width" "Number of characters gdb thinks are in a line is 90..*" "show width (90)"
467 }
468
469 proc_with_prefix test_setshow_write {} {
470 clean_restart
471
472 #test set write on
473 # This is only supported on targets which use exec.o.
474 gdb_test_no_output "set write on" "set write on"
475
476 #test show write on
477 # This is only supported on targets which use exec.o.
478 gdb_test "show write" "Writing into executable and core files is on..*" "show write (on)"
479 }
480
481 proc_with_prefix test_show_user {} {
482 clean_restart
483
484 #test show user
485 gdb_test_no_output "show user" "show user"
486 }
487
488 proc_with_prefix test_setshow_verbose {} {
489 clean_restart
490
491 #test set verbose on
492 gdb_test_no_output "set verbose on" "set verbose on"
493
494 #test show verbose on
495 gdb_test "show verbose" "Verbose printing of informational messages is on..*" "show verbose, on"
496
497 #test set verbose off
498 gdb_test_no_output "set verbose off" "set verbose off"
499
500 #test show verbose off
501 gdb_test "show verbose" "Verbosity is off..*" "show verbose, off"
502 }
503
504 proc_with_prefix test_argument_preceded_by_space {} {
505 clean_restart
506
507 #test argument must be preceded by space
508 foreach x {"history file" "solib-search-path" "data-directory"} {
509 foreach y {"/home/" "~/home" "=home"} {
510 gdb_test "set $x$y" "Argument must be preceded by space." \
511 "$x is not set to $y"
512 }
513 }
514 }
515
516 test_setshow_annotate
517 test_setshow_args
518 test_setshow_check
519 test_setshow_breakpoint_pending
520 test_setshow_complaints
521 test_setshow_confirm
522 test_setshow_editing
523 test_setshow_environment
524 test_setshow_height
525 test_setshow_history
526 test_setshow_language
527 test_setshow_listsize
528 test_setshow_print_characters
529 test_setshow_prompt
530 test_setshow_radix
531 test_setshow_width
532 test_setshow_write
533 test_show_user
534 test_setshow_verbose
535 test_argument_preceded_by_space