Test 'set print frame-info|frame-arguments presence'.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / options.exp
1 # This testcase is part of GDB, the GNU debugger.
2
3 # Copyright 2019 Free Software Foundation, Inc.
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 gdb::option framework.
19
20 # The test uses the "maintenance test-options" subcommands to exercise
21 # TAB-completion and option processing.
22 #
23 # It also tests option integration in various commands, including:
24 #
25 # - print
26 # - compile print
27 # - backtrace
28 # - frame apply
29 # - faas
30 # - tfaas
31 # - thread apply
32 # - taas
33
34 load_lib completion-support.exp
35
36 standard_testfile .c
37
38 if {[build_executable "failed to prepare" $testfile $srcfile debug]} {
39 return -1
40 }
41
42 clean_restart
43
44 if { ![readline_is_used] } {
45 untested "no tab completion support without readline"
46 return -1
47 }
48
49 # Check the completion result, as returned by the "maintenance show
50 # test-options-completion-result" command. TEST is used as test name.
51 proc check_completion_result {expected test} {
52 gdb_test "maintenance show test-options-completion-result" \
53 "$expected" \
54 "$test: res=$expected"
55 }
56
57 # Like test_gdb_complete_unique, but the expected output is expected
58 # to be the input line. I.e., the line is already complete. We're
59 # just checking whether GDB recognizes the option and auto-appends a
60 # space.
61 proc test_completer_recognizes {res input_line} {
62 set expected_re [string_to_regexp $input_line]
63 test_gdb_complete_unique $input_line $expected_re
64 check_completion_result $res $input_line
65 }
66
67 # Wrapper around test_gdb_complete_multiple that also checks the
68 # completion result is RES.
69 proc res_test_gdb_complete_multiple {res cmd_prefix completion_word args} {
70 test_gdb_complete_multiple $cmd_prefix $completion_word {*}$args
71 check_completion_result $res "$cmd_prefix$completion_word"
72 }
73
74 # Wrapper around test_gdb_complete_none that also checks the
75 # completion result is RES.
76 proc res_test_gdb_complete_none { res input_line } {
77 test_gdb_complete_none $input_line
78 check_completion_result $res "$input_line"
79 }
80
81 # Wrapper around test_gdb_complete_unique that also checks the
82 # completion result is RES.
83 proc res_test_gdb_complete_unique { res input_line args} {
84 test_gdb_complete_unique $input_line {*}$args
85 check_completion_result $res "$input_line"
86 }
87
88 # Make a full command name from VARIANT. VARIANT is either
89 # "require-delimiter", "unknown-is-error" or "unknown-is-operand".
90 proc make_cmd {variant} {
91 return "maint test-options $variant"
92 }
93
94 # Return a string for the expected result of running "maint
95 # test-options xxx", with no flag/option set. OPERAND is the expected
96 # operand.
97 proc expect_none {operand} {
98 return "-flag 0 -xx1 0 -xx2 0 -bool 0 -enum xxx -uint 0 -zuint-unl 0 -string '' -- $operand"
99 }
100
101 # Return a string for the expected result of running "maint
102 # test-options xxx", with -flag set. OPERAND is the expected operand.
103 proc expect_flag {operand} {
104 return "-flag 1 -xx1 0 -xx2 0 -bool 0 -enum xxx -uint 0 -zuint-unl 0 -string '' -- $operand"
105 }
106
107 # Return a string for the expected result of running "maint
108 # test-options xxx", with -bool set. OPERAND is the expected operand.
109 proc expect_bool {operand} {
110 return "-flag 0 -xx1 0 -xx2 0 -bool 1 -enum xxx -uint 0 -zuint-unl 0 -string '' -- $operand"
111 }
112
113 # Return a string for the expected result of running "maint
114 # test-options xxx", with one of the integer options set to $VAL.
115 # OPTION determines which option to expect set. OPERAND is the
116 # expected operand.
117 proc expect_integer {option val operand} {
118 if {$option == "uinteger"} {
119 return "-flag 0 -xx1 0 -xx2 0 -bool 0 -enum xxx -uint $val -zuint-unl 0 -string '' -- $operand"
120 } elseif {$option == "zuinteger-unlimited"} {
121 return "-flag 0 -xx1 0 -xx2 0 -bool 0 -enum xxx -uint 0 -zuint-unl $val -string '' -- $operand"
122 } else {
123 error "unsupported option: $option"
124 }
125 }
126
127 # Return a string for the expected result of running "maint
128 # test-options xxx", with -string set to $STR. OPERAND is the
129 # expected operand.
130 proc expect_string {str operand} {
131 # Dequote the string in the expected output.
132 if { ( [string range $str 0 0] == "\""
133 && [string range $str end end] == "\"")
134 || ([string range $str 0 0] == "'"
135 && [string range $str end end] == "'")} {
136 set str [string range $str 1 end-1]
137 }
138 return "-flag 0 -xx1 0 -xx2 0 -bool 0 -enum xxx -uint 0 -zuint-unl 0 -string '$str' -- $operand"
139 }
140
141 set all_options {
142 "-bool"
143 "-enum"
144 "-flag"
145 "-string"
146 "-uinteger"
147 "-xx1"
148 "-xx2"
149 "-zuinteger-unlimited"
150 }
151
152 # Basic option-machinery + "print" command integration tests.
153 proc_with_prefix test-print {{prefix ""}} {
154 clean_restart
155
156 # Completing "print" with no argument completes on symbols only,
157 # no options are offered. Since we haven't loaded any symbols,
158 # the match list should be empty.
159 test_gdb_complete_none "${prefix}print "
160
161 # OTOH, completing at "-" should list all options.
162 test_gdb_complete_multiple "${prefix}print " "-" "" {
163 "-address"
164 "-array"
165 "-array-indexes"
166 "-elements"
167 "-max-depth"
168 "-null-stop"
169 "-object"
170 "-pretty"
171 "-repeats"
172 "-static-members"
173 "-symbol"
174 "-union"
175 "-vtbl"
176 }
177
178 global binfile
179 clean_restart $binfile
180
181 if ![runto_main] {
182 fail "cannot run to main"
183 return
184 }
185
186 # Mix options and format.
187 gdb_test "${prefix}print -pretty -- /x 1" " = 0x1"
188
189 # Smoke test that options actually work.
190 gdb_test "${prefix}print -pretty -- g_s" \
191 [multi_line \
192 " = {" \
193 " a = 1," \
194 " b = 2," \
195 " c = 3" \
196 "}"]
197
198 test_gdb_complete_unique \
199 "${prefix}print xxx" \
200 "${prefix}print xxx1"
201 test_gdb_complete_unique \
202 "${prefix}print -- xxx" \
203 "${prefix}print -- xxx1"
204
205 # Error messages when testing with "compile" are different from
206 # the error messages gdb's internal parser throws. This procedure
207 # hides the difference. EXPECTED_RE is only considered when not
208 # testing with "compile".
209 proc test_invalid_expression {cmd expected_re} {
210 upvar prefix prefix
211
212 if {$prefix != "compile "} {
213 gdb_test $cmd $expected_re
214 } else {
215 # Error messages depend on compiler version, so we just
216 # look for the last line indicating a failure.
217 gdb_test $cmd "Compilation failed\\."
218 }
219 }
220
221 # Check that '-XXX' without a "--" is handled as an
222 # expression.
223 gdb_test "${prefix}print -1" " = -1"
224 test_invalid_expression \
225 "${prefix}print --1" \
226 "Left operand of assignment is not an lvalue\\."
227 test_invalid_expression \
228 "${prefix}print -object" \
229 "No symbol \"object\".*"
230
231 # Test printing with options and no expression.
232 set test "${prefix}print -object --"
233 if {$prefix != "compile "} {
234 # Regular "print" repeats the last history value.
235 gdb_test $test " = -1"
236 } else {
237 # "compile print" starts a multiline expression.
238 gdb_test_multiple $test $test {
239 -re ">$" {
240 gdb_test "-1\nend" " = -1" \
241 $test
242 }
243 }
244 }
245
246 # Check that everything after "-- " is treated as an
247 # expression, not confused with an option.
248 test_invalid_expression \
249 "${prefix}print -- -address" \
250 "No symbol.*"
251 gdb_test "${prefix}print -- -1" " = -1"
252 test_invalid_expression \
253 "${prefix}print -- --1" \
254 "Left operand of assignment is not an lvalue\\."
255 }
256
257 # Basic option-machinery + "backtrace" command integration tests.
258 proc_with_prefix test-backtrace {} {
259 clean_restart
260
261 test_gdb_complete_unique "backtrace" "backtrace"
262 test_gdb_complete_none "backtrace "
263
264 gdb_test "backtrace -" "Ambiguous option at: -"
265 gdb_test "backtrace --" "No stack\\."
266 gdb_test "backtrace -- -" "No stack\\."
267
268 test_gdb_complete_multiple "backtrace " "-" "" {
269 "-entry-values"
270 "-frame-arguments"
271 "-frame-info"
272 "-full"
273 "-hide"
274 "-no-filters"
275 "-past-entry"
276 "-past-main"
277 "-raw-frame-arguments"
278 }
279
280 # Test that we complete the qualifiers, if there's any.
281 test_gdb_complete_unique \
282 "backtrace ful" \
283 "backtrace full"
284 test_gdb_complete_unique \
285 "backtrace hid" \
286 "backtrace hide"
287 test_gdb_complete_unique \
288 "backtrace no-fil" \
289 "backtrace no-filters"
290
291 global binfile
292 clean_restart $binfile
293
294 if ![runto_main] {
295 fail "cannot run to main"
296 return
297 }
298
299 # COUNT in "backtrace COUNT" is parsed as an expression. Check
300 # that we complete expressions.
301
302 test_gdb_complete_unique \
303 "backtrace xxx" \
304 "backtrace xxx1"
305
306 test_gdb_complete_unique \
307 "backtrace -xxx" \
308 "backtrace -xxx1"
309
310 test_gdb_complete_unique \
311 "backtrace 1 + xxx" \
312 "backtrace 1 + xxx1"
313
314 test_gdb_complete_unique \
315 "backtrace (1 + xxx" \
316 "backtrace (1 + xxx1"
317 }
318
319 # Basic option-machinery + "frame apply" command integration tests.
320 proc_with_prefix test-frame-apply {} {
321 test_gdb_complete_unique "frame apply all" "frame apply all"
322
323 gdb_test "frame apply level 0-" \
324 "Please specify a command to apply on the selected frames"
325 test_gdb_complete_none "frame apply level 0-"
326
327 foreach cmd {
328 "frame apply all"
329 "frame apply 1"
330 "frame apply level 0"
331 "faas"
332 "tfaas"
333 } {
334 test_gdb_completion_offers_commands "$cmd "
335
336 # tfaas is silent on command error by design. This procedure
337 # hides that aspect. EXPECTED_RE is only considered when not
338 # testing with "faas"/"tfaas".
339 proc test_error_cmd {cmd arg expected_re} {
340 if {$cmd == "tfaas"} {
341 gdb_test_no_output "$cmd$arg"
342 } else {
343 gdb_test "$cmd$arg" $expected_re
344 }
345 }
346 # Same, but for tests where both "faas" and "tfaas" are
347 # expected to be silent.
348 proc test_error_cmd2 {cmd arg expected_re} {
349 if {$cmd == "tfaas" || $cmd == "faas"} {
350 gdb_test_no_output "$cmd$arg"
351 } else {
352 gdb_test "$cmd$arg" $expected_re
353 }
354 }
355
356 test_error_cmd $cmd " -" "Ambiguous option at: -"
357 test_gdb_complete_multiple "$cmd " "-" "" {
358 "-c"
359 "-past-entry"
360 "-past-main"
361 "-q"
362 "-s"
363 }
364
365 with_test_prefix "no-trailing-space" {
366 test_error_cmd $cmd " --" \
367 "Please specify a command to apply on the selected frames"
368 test_gdb_complete_unique "$cmd --" "$cmd --"
369 }
370
371 with_test_prefix "trailing-space" {
372 test_error_cmd $cmd " -- " \
373 "Please specify a command to apply on the selected frames"
374 test_gdb_completion_offers_commands "$cmd -- "
375 }
376
377 # '-' is a valid TUI command.
378 test_error_cmd2 $cmd " -- -" \
379 "Cannot enable the TUI when output is not a terminal"
380 test_gdb_complete_unique \
381 "$cmd -- -" \
382 "$cmd -- -"
383
384 test_error_cmd2 $cmd " -foo" \
385 "Undefined command: \"-foo\". Try \"help\"\\."
386 test_gdb_complete_none "$cmd -foo"
387
388 test_gdb_completion_offers_commands "$cmd -s "
389 }
390 }
391
392 # Basic option-machinery + "thread apply" command integration tests.
393 proc_with_prefix test-thread-apply {} {
394
395 test_gdb_complete_unique "thread apply all" "thread apply all"
396 test_gdb_complete_unique "taas" "taas"
397
398 gdb_test "thread apply 1-" \
399 "inverted range"
400 test_gdb_complete_none "frame apply level 1-"
401
402 foreach cmd {
403 "thread apply all"
404 "thread apply 1"
405 "taas"
406 } {
407 test_gdb_completion_offers_commands "$cmd "
408
409 # taas is silent on command error by design. This procedure
410 # hides the difference. EXPECTED_RE is only considered when
411 # not testing with "taas".
412 proc test_invalid_cmd {cmd arg expected_re} {
413 if {$cmd != "taas"} {
414 gdb_test "$cmd$arg" $expected_re
415 } else {
416 gdb_test_no_output "$cmd$arg"
417 }
418 }
419
420 gdb_test "$cmd -" "Ambiguous option at: -"
421
422 if {$cmd != "thread apply 1"} {
423 test_gdb_complete_multiple "$cmd " "-" "" {
424 "-ascending"
425 "-c"
426 "-q"
427 "-s"
428 }
429 } else {
430 # "-ascending" only works with "all".
431 test_gdb_complete_multiple "$cmd " "-" "" {
432 "-c"
433 "-q"
434 "-s"
435 }
436 }
437
438 if {$cmd == "thread apply all" || $cmd == "taas"} {
439 set errmsg \
440 "Please specify a command at the end of 'thread apply all'"
441 } elseif {$cmd == "thread apply 1"} {
442 set errmsg \
443 "Please specify a command following the thread ID list"
444 } else {
445 error "unexpected cmd: $cmd"
446 }
447
448 with_test_prefix "no-trailing-space" {
449 gdb_test "$cmd --" $errmsg
450 test_gdb_complete_unique "$cmd --" "$cmd --"
451 }
452
453 with_test_prefix "trailing-space" {
454 gdb_test "$cmd -- " $errmsg
455 test_gdb_completion_offers_commands "$cmd -- "
456 }
457
458 # '-' is a valid TUI command.
459 test_invalid_cmd "$cmd" " -- -" \
460 "Cannot enable the TUI when output is not a terminal"
461 test_gdb_complete_unique \
462 "$cmd -- -" \
463 "$cmd -- -"
464
465 test_invalid_cmd $cmd " -foo" \
466 "Undefined command: \"-foo\". Try \"help\"\\."
467 test_gdb_complete_none "$cmd -foo"
468
469 test_gdb_completion_offers_commands "$cmd -c "
470 }
471 }
472
473 # Basic option-machinery + "info threads" command integration tests.
474 proc_with_prefix test-info-threads {} {
475 test_gdb_complete_multiple "info threads " "" "" {
476 "-gid"
477 "ID"
478 }
479
480 test_gdb_complete_unique \
481 "info threads -" \
482 "info threads -gid"
483
484 # "ID" isn't really something the user can type.
485 test_gdb_complete_none "info threads I"
486 }
487
488 # Miscellaneous tests.
489 proc_with_prefix test-misc {variant} {
490 global all_options
491
492 set cmd [make_cmd $variant]
493
494 # Call test command with no arguments at all.
495 gdb_test "$cmd" [expect_none ""]
496
497 # Now with a single dash.
498 if {$variant == "require-delimiter"} {
499 gdb_test "$cmd -" [expect_none "-"]
500 } else {
501 gdb_test "$cmd -" "Ambiguous option at: -"
502 }
503
504 # Completing at "-" should list all options.
505 res_test_gdb_complete_multiple \
506 "1 [expect_none "-"]" \
507 "$cmd " "-" "" $all_options
508
509 # Now with a double dash.
510 gdb_test "$cmd --" [expect_none ""]
511
512 # "--" is recognized by options completer, gdb auto-appends a
513 # space.
514 test_completer_recognizes \
515 "1 [expect_none "--"]" \
516 "$cmd --"
517
518 # Now with a double dash, plus a dash as operand.
519 gdb_test "$cmd -- -" [expect_none "-"]
520 res_test_gdb_complete_none "0 -" "$cmd -- -"
521
522 # Completing an unambiguous option just appends an empty space.
523 test_completer_recognizes \
524 "1 [expect_none "-flag"]" \
525 "$cmd -flag"
526
527 # Try running an ambiguous option.
528 if {$variant == "require-delimiter"} {
529 gdb_test "$cmd -xx" [expect_none "-xx"]
530 } else {
531 gdb_test "$cmd -xx" "Ambiguous option at: -xx"
532 }
533
534 # Check that options are not case insensitive.
535 gdb_test "$cmd -flag --" [expect_flag ""]
536
537 # Check how the different modes behave on unknown option, with a
538 # delimiter.
539 gdb_test "$cmd -FLAG --" \
540 "Unrecognized option at: -FLAG --"
541
542 # Check how the different modes behave on unknown option, without
543 # a delimiter.
544 if {$variant == "unknown-is-error"} {
545 gdb_test "$cmd -FLAG" \
546 "Unrecognized option at: -FLAG"
547 } else {
548 gdb_test "$cmd -FLAG" [expect_none "-FLAG"]
549 }
550
551 # Test parsing stops at a negative integer.
552 gdb_test "$cmd -1 --" \
553 "Unrecognized option at: -1 --"
554 gdb_test "$cmd -2 --" \
555 "Unrecognized option at: -2 --"
556 }
557
558 # Flag option tests.
559 proc_with_prefix test-flag {variant} {
560 global all_options
561
562 set cmd [make_cmd $variant]
563
564 # Completing a flag just appends a space.
565 test_completer_recognizes \
566 "1 [expect_none "-flag"]" \
567 "$cmd -flag"
568
569 # Add a dash, and all options should be shown.
570 res_test_gdb_complete_multiple \
571 "1 [expect_flag "-"]" \
572 "$cmd -flag " "-" "" $all_options
573
574 # Basic smoke tests of accepted / not accepted values.
575
576 # Check all the different variants a bool option may be specified.
577 if {$variant == "require-delimiter"} {
578 gdb_test "$cmd -flag 999" [expect_none "-flag 999"]
579 } else {
580 gdb_test "$cmd -flag 999" [expect_flag "999"]
581 }
582 gdb_test "$cmd -flag -- 999" [expect_flag "999"]
583
584 # If the "--" separator is present, then GDB errors out if the
585 # flag option is passed some value -- check that too.
586 gdb_test "$cmd -flag xxx 999 --" "Unrecognized option at: xxx 999 --"
587 gdb_test "$cmd -flag o 999 --" "Unrecognized option at: o 999 --"
588 gdb_test "$cmd -flag 1 999 --" "Unrecognized option at: 1 999 --"
589
590 # Extract twice the same flag, separated by one space.
591 gdb_test "$cmd -flag -flag -- non flags args" \
592 [expect_flag "non flags args"]
593
594 # Extract twice the same flag, separated by one space.
595 gdb_test "$cmd -xx1 -xx2 -xx1 -xx2 -xx1 -- non flags args" \
596 "-flag 0 -xx1 1 -xx2 1 -bool 0 -enum xxx -uint 0 -zuint-unl 0 -string '' -- non flags args"
597
598 # Extract 2 known flags in front of unknown flags.
599 gdb_test "$cmd -xx1 -xx2 -a -b -c -xx1 --" \
600 "Unrecognized option at: -a -b -c -xx1 --"
601
602 # Check that combined flags are not recognised.
603 gdb_test "$cmd -xx1 -xx1xx2 -xx1 --" \
604 "Unrecognized option at: -xx1xx2 -xx1 --"
605
606 # Make sure the completer don't confuse a flag option with a
607 # boolean option. Specifically, "o" should not complete to
608 # "on/off".
609
610 if {$variant == "require-delimiter"} {
611 res_test_gdb_complete_none \
612 "1 [expect_flag "o"]" \
613 "$cmd -flag o"
614
615 gdb_test "$cmd -flag o" [expect_none "-flag o"]
616 } else {
617 res_test_gdb_complete_none "0 o" "$cmd -flag o"
618
619 gdb_test "$cmd -flag o" [expect_flag "o"]
620 }
621 }
622
623 # Boolean option tests.
624 proc_with_prefix test-boolean {variant} {
625 global all_options
626
627 set cmd [make_cmd $variant]
628
629 # Boolean option's values are optional -- "on" is implied. Check
630 # that:
631 #
632 # - For require-delimiter commands, completing after a boolean
633 # option lists all other options, plus "on/off". This is
634 # because operands won't be processed until we see a "--"
635 # delimiter.
636 #
637 # - For !require-delimiter commands, completing after a boolean
638 # option completes as an operand, since that will tend to be
639 # more common than typing "on/off".
640 # E.g., "frame apply all -past-main COMMAND".
641
642 if {$variant == "require-delimiter"} {
643 set match_list $all_options
644 lappend match_list "off" "on"
645 res_test_gdb_complete_multiple \
646 "1 [expect_none ""]" \
647 "$cmd -bool " "" "" $match_list
648 } else {
649 res_test_gdb_complete_none "0 " "$cmd -bool "
650 }
651
652 # Add another dash, and "on/off" are no longer offered:
653 res_test_gdb_complete_multiple \
654 "1 [expect_bool "-"]" \
655 "$cmd -bool " "-" "" $all_options
656
657 # Basic smoke tests of accepted / not accepted values.
658
659 # The command accepts all of "1/0/enable/disable/yes/no" too, even
660 # though like the "set" command, we don't offer those as
661 # completion candidates if you complete right after the boolean
662 # command's name, like:
663 #
664 # (gdb) maint test-options require-delimiter -bool [TAB]
665 # off on
666 #
667 # However, the completer does recognize them if you start typing
668 # the boolean value.
669 foreach value {"0" "1"} {
670 test_completer_recognizes \
671 "1 [expect_none ""]" \
672 "$cmd -bool $value"
673 }
674 foreach value {"of" "off"} {
675 res_test_gdb_complete_unique \
676 "1 [expect_none ""]" \
677 "$cmd -bool $value" \
678 "$cmd -bool off"
679 }
680 foreach value {"y" "ye" "yes"} {
681 res_test_gdb_complete_unique \
682 "1 [expect_none ""]" \
683 "$cmd -bool $value" \
684 "$cmd -bool yes"
685 }
686 foreach value {"n" "no"} {
687 res_test_gdb_complete_unique \
688 "1 [expect_none ""]" \
689 "$cmd -bool $value" \
690 "$cmd -bool no"
691 }
692 foreach value {
693 "e"
694 "en"
695 "ena"
696 "enab"
697 "enabl"
698 "enable"
699 } {
700 res_test_gdb_complete_unique \
701 "1 [expect_none ""]" \
702 "$cmd -bool $value" \
703 "$cmd -bool enable"
704 }
705 foreach value {
706 "d"
707 "di"
708 "dis"
709 "disa"
710 "disab"
711 "disabl"
712 "disable"
713 } {
714 res_test_gdb_complete_unique \
715 "1 [expect_none ""]" \
716 "$cmd -bool $value" \
717 "$cmd -bool disable"
718 }
719
720 if {$variant == "require-delimiter"} {
721 res_test_gdb_complete_none \
722 "1 [expect_none "xxx"]" \
723 "$cmd -bool xxx"
724 } else {
725 res_test_gdb_complete_none "0 xxx" "$cmd -bool xxx"
726 }
727
728 # The command accepts abbreviations of "enable/disable/yes/no",
729 # even though we don't offer those for completion.
730 foreach value {
731 "1"
732 "y" "ye" "yes"
733 "e"
734 "en"
735 "ena"
736 "enab"
737 "enabl"
738 "enable"} {
739 gdb_test "$cmd -bool $value --" [expect_bool ""]
740 }
741 foreach value {
742 "0"
743 "of" "off"
744 "n" "no"
745 "d"
746 "di"
747 "dis"
748 "disa"
749 "disab"
750 "disabl"
751 "disable"} {
752 gdb_test "$cmd -bool $value --" [expect_none ""]
753 }
754
755 if {$variant == "require-delimiter"} {
756 gdb_test "$cmd -bool 999" [expect_none "-bool 999"]
757 } else {
758 gdb_test "$cmd -bool 999" [expect_bool "999"]
759 }
760 gdb_test "$cmd -bool -- 999" [expect_bool "999"]
761
762 # Since "on" is implied after a boolean option, for
763 # !require-delimiter commands, anything that is not
764 # yes/no/1/0/on/off/enable/disable should be considered as the raw
765 # input after the last option. Also check "o", which might look
766 # like "on" or "off", but it's treated the same.
767
768 foreach arg {"xxx" "o"} {
769 if {$variant == "require-delimiter"} {
770 gdb_test "$cmd -bool $arg" [expect_none "-bool $arg"]
771 } else {
772 gdb_test "$cmd -bool $arg" [expect_bool "$arg"]
773 }
774 }
775 # Also try -1. "unknown-is-error" commands error out saying that
776 # that's not a valid option.
777 if {$variant == "require-delimiter"} {
778 gdb_test "$cmd -bool -1" \
779 [expect_none "-bool -1"]
780 } elseif {$variant == "unknown-is-error"} {
781 gdb_test "$cmd -bool -1" \
782 "Unrecognized option at: -1"
783 } else {
784 gdb_test "$cmd -bool -1" [expect_bool "-1"]
785 }
786
787 # OTOH, if the "--" separator is present, then GDB errors out if
788 # the boolean option is passed an invalid value -- check that too.
789 gdb_test "$cmd -bool -1 999 --" \
790 "Unrecognized option at: -1 999 --"
791 gdb_test "$cmd -bool xxx 999 --" \
792 "Value given for `-bool' is not a boolean: xxx"
793 gdb_test "$cmd -bool o 999 --" \
794 "Value given for `-bool' is not a boolean: o"
795
796 # Completing after a boolean option + "o" does list "on/off",
797 # though.
798 if {$variant == "require-delimiter"} {
799 res_test_gdb_complete_multiple \
800 "1 [expect_none "o"]" \
801 "$cmd -bool " "o" "" {
802 "off"
803 "on"
804 }
805 } else {
806 res_test_gdb_complete_multiple "0 o" "$cmd -bool " "o" "" {
807 "off"
808 "on"
809 }
810 }
811 }
812
813 # Uinteger option tests. OPTION is which integer option we're
814 # testing. Can be "uinteger" or "zuinteger-unlimited".
815 proc_with_prefix test-uinteger {variant option} {
816 global all_options
817
818 set cmd "[make_cmd $variant] -$option"
819
820 # Test completing a uinteger option:
821 res_test_gdb_complete_multiple \
822 "1 [expect_none ""]" \
823 "$cmd " "" "" {
824 "NUMBER"
825 "unlimited"
826 }
827
828 # NUMBER above is just a placeholder, make sure we don't complete
829 # it as a valid option.
830 res_test_gdb_complete_none \
831 "1 [expect_none "NU"]" \
832 "$cmd NU"
833
834 # "unlimited" is valid though.
835 res_test_gdb_complete_unique \
836 "1 [expect_none "u"]" \
837 "$cmd u" \
838 "$cmd unlimited"
839
840 # Basic smoke test of accepted / not accepted values.
841 gdb_test "$cmd 1 -- 999" [expect_integer $option "1" "999"]
842 gdb_test "$cmd unlimited -- 999" \
843 [expect_integer $option "unlimited" "999"]
844 if {$option == "zuinteger-unlimited"} {
845 gdb_test "$cmd -1 --" [expect_integer $option "unlimited" ""]
846 gdb_test "$cmd 0 --" [expect_integer $option "0" ""]
847 } else {
848 gdb_test "$cmd -1 --" "integer -1 out of range"
849 gdb_test "$cmd 0 --" [expect_integer $option "unlimited" ""]
850 }
851 gdb_test "$cmd xxx --" \
852 "Expected integer at: xxx --"
853 gdb_test "$cmd unlimitedx --" \
854 "Expected integer at: unlimitedx --"
855
856 # Don't offer completions until we're past the
857 # -uinteger/-zuinteger-unlimited argument.
858 res_test_gdb_complete_none \
859 "1 [expect_none ""]" \
860 "$cmd 1"
861
862 # A number of invalid values.
863 foreach value {"x" "x " "1a" "1a " "1-" "1- " "unlimitedx"} {
864 res_test_gdb_complete_none \
865 "1 [expect_none $value]" \
866 "$cmd $value"
867 }
868
869 # Try "-1".
870 if {$option == "uinteger"} {
871 # -1 is invalid uinteger.
872 foreach value {"-1" "-1 "} {
873 res_test_gdb_complete_none \
874 "1 [expect_none ""]" \
875 "$cmd $value"
876 }
877 } else {
878 # -1 is valid for zuinteger-unlimited.
879 res_test_gdb_complete_none \
880 "1 [expect_none ""]" \
881 "$cmd -1"
882 if {$variant == "require-delimiter"} {
883 res_test_gdb_complete_multiple \
884 "1 [expect_integer $option "unlimited" ""]" \
885 "$cmd -1 " "" "-" $all_options
886 } else {
887 res_test_gdb_complete_none "0 " "$cmd -1 "
888 }
889 }
890
891 # Check that after a fully parsed option:
892 #
893 # - for require-delimiter commands, completion offers all
894 # options.
895 #
896 # - for !require-delimiter commands, completion offers nothing
897 # and returns false.
898 if {$variant == "require-delimiter"} {
899 res_test_gdb_complete_multiple \
900 "1 [expect_integer $option 1 ""]" \
901 "$cmd 1 " "" "-" $all_options
902 } else {
903 res_test_gdb_complete_none "0 " "$cmd 1 "
904 }
905
906 # Test completing non-option arguments after "-uinteger 1 ".
907 foreach operand {"x" "x " "1a" "1a " "1-" "1- "} {
908 if {$variant == "require-delimiter"} {
909 res_test_gdb_complete_none \
910 "1 [expect_integer $option 1 $operand]" \
911 "$cmd 1 $operand"
912 } else {
913 res_test_gdb_complete_none "0 $operand" "$cmd 1 $operand"
914 }
915 }
916 # These look like options, but they aren't.
917 foreach operand {"-1" "-1 "} {
918 if {$variant == "unknown-is-operand"} {
919 res_test_gdb_complete_none "0 $operand" "$cmd 1 $operand"
920 } else {
921 res_test_gdb_complete_none \
922 "1 [expect_integer $option 1 $operand]" \
923 "$cmd 1 $operand"
924 }
925 }
926 }
927
928 # Enum option tests.
929 proc_with_prefix test-enum {variant} {
930 set cmd [make_cmd $variant]
931
932 res_test_gdb_complete_multiple \
933 "1 [expect_none ""]" \
934 "$cmd -enum " "" "" {
935 "xxx"
936 "yyy"
937 "zzz"
938 }
939
940 # Check that "-" where a value is expected does not show the
941 # command's options. I.e., an enum's value is not optional.
942 # Check both completion and running the command.
943 res_test_gdb_complete_none \
944 "1 [expect_none "-"]" \
945 "$cmd -enum -"
946 gdb_test "$cmd -enum --"\
947 "Requires an argument. Valid arguments are xxx, yyy, zzz\\."
948
949 # Try passing an undefined item to an enum option.
950 gdb_test "$cmd -enum www --" "Undefined item: \"www\"."
951 }
952
953 # String option tests.
954 proc_with_prefix test-string {variant} {
955 global all_options
956
957 set cmd [make_cmd $variant]
958
959 res_test_gdb_complete_none \
960 "1 [expect_none ""]" \
961 "$cmd -string "
962
963 # Check that "-" where a value is expected does not show the
964 # command's options. I.e., a string's value is not optional.
965 # Check both completion and running the command.
966 res_test_gdb_complete_none \
967 "1 [expect_none ""]" \
968 "$cmd -string -"
969 gdb_test "$cmd -string --"\
970 "-string requires an argument"
971 if {$variant == "require-delimiter"} {
972 gdb_test "$cmd -string" [expect_none "-string"]
973 } else {
974 gdb_test "$cmd -string"\
975 "-string requires an argument"
976 }
977
978 foreach_with_prefix str {
979 "STR"
980 "\"STR\""
981 "\\\"STR"
982 "'STR'"
983 "\\'STR"
984 "\"STR AAA\""
985 "'STR BBB'"
986 "\"STR 'CCC' DDD\""
987 "'STR \"EEE\" FFF'"
988 "\"STR \\\"GGG\\\" HHH\""
989 "'STR \\\'III\\\' JJJ'"
990 } {
991 res_test_gdb_complete_none \
992 "1 [expect_none ""]" \
993 "$cmd -string ${str}"
994 gdb_test "$cmd -string ${str} --" [expect_string "${str}" ""]
995
996 # Completing at "-" after parsing STR should list all options.
997 res_test_gdb_complete_multiple \
998 "1 [expect_string "${str}" "-"]" \
999 "$cmd -string ${str} " "-" "" $all_options
1000
1001 # Check that only $STR is considered part of the string's value.
1002 # I.e., that we stop parsing the string at the first
1003 # whitespace or after the closing quote of $STR.
1004 if {$variant == "require-delimiter"} {
1005 res_test_gdb_complete_none \
1006 "1 [expect_string "${str}" "BAR"]" \
1007 "$cmd -string ${str} BAR"
1008 } else {
1009 res_test_gdb_complete_none "0 BAR" "$cmd -string ${str} BAR"
1010 }
1011 gdb_test "$cmd -string ${str} BAR --" "Unrecognized option at: BAR --"
1012 }
1013 }
1014
1015 # Run the options framework tests first.
1016 foreach_with_prefix cmd {
1017 "require-delimiter"
1018 "unknown-is-error"
1019 "unknown-is-operand"
1020 } {
1021 test-misc $cmd
1022 test-flag $cmd
1023 test-boolean $cmd
1024 foreach subcmd {"uinteger" "zuinteger-unlimited" } {
1025 test-uinteger $cmd $subcmd
1026 }
1027 test-enum $cmd
1028 test-string $cmd
1029 }
1030
1031 # Run the print integration tests, both as "standalone", and under
1032 # "frame/thread apply". The latter checks that the "frame/thread
1033 # apply ... COMMAND" commands recurse the completion machinery for
1034 # COMMAND completion correctly.
1035 foreach prefix {
1036 ""
1037 "frame apply all "
1038 "frame apply 1 "
1039 "frame apply level 0 "
1040 "thread apply all "
1041 "thread apply 1 "
1042 "thread apply 1 frame apply 1 "
1043 } {
1044 test-print $prefix
1045 }
1046
1047 # Same for "compile print". Not really a wrapper prefix command like
1048 # "frame apply", but similar enough that we test pretty much the same
1049 # things.
1050 if ![skip_compile_feature_tests] {
1051 test-print "compile "
1052 }
1053
1054 # Basic "backtrace" integration tests.
1055 test-backtrace
1056
1057 # Basic "frame apply" integration tests.
1058 test-frame-apply
1059
1060 # Basic "thread apply" integration tests.
1061 test-thread-apply
1062
1063 # Basic "info threads" integration tests.
1064 test-info-threads
This page took 0.070293 seconds and 4 git commands to generate.