Make "thread apply" use the gdb::option framework
[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 -- $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 -- $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 -- $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 -- $operand"
120 } elseif {$option == "zuinteger-unlimited"} {
121 return "-flag 0 -xx1 0 -xx2 0 -bool 0 -enum xxx -uint 0 -zuint-unl $val -- $operand"
122 } else {
123 error "unsupported option: $option"
124 }
125 }
126
127 set all_options {
128 "-bool"
129 "-enum"
130 "-flag"
131 "-uinteger"
132 "-xx1"
133 "-xx2"
134 "-zuinteger-unlimited"
135 }
136
137 # Basic option-machinery + "print" command integration tests.
138 proc_with_prefix test-print {{prefix ""}} {
139 clean_restart
140
141 # Completing "print" with no argument completes on symbols only,
142 # no options are offered. Since we haven't loaded any symbols,
143 # the match list should be empty.
144 test_gdb_complete_none "${prefix}print "
145
146 # OTOH, completing at "-" should list all options.
147 test_gdb_complete_multiple "${prefix}print " "-" "" {
148 "-address"
149 "-array"
150 "-array-indexes"
151 "-elements"
152 "-max-depth"
153 "-null-stop"
154 "-object"
155 "-pretty"
156 "-repeats"
157 "-static-members"
158 "-symbol"
159 "-union"
160 "-vtbl"
161 }
162
163 global binfile
164 clean_restart $binfile
165
166 if ![runto_main] {
167 fail "cannot run to main"
168 return
169 }
170
171 # Mix options and format.
172 gdb_test "${prefix}print -pretty -- /x 1" " = 0x1"
173
174 # Smoke test that options actually work.
175 gdb_test "${prefix}print -pretty -- g_s" \
176 [multi_line \
177 " = {" \
178 " a = 1," \
179 " b = 2," \
180 " c = 3" \
181 "}"]
182
183 test_gdb_complete_unique \
184 "${prefix}print xxx" \
185 "${prefix}print xxx1"
186 test_gdb_complete_unique \
187 "${prefix}print -- xxx" \
188 "${prefix}print -- xxx1"
189
190 # Error messages when testing with "compile" are different from
191 # the error messages gdb's internal parser throws. This procedure
192 # hides the difference. EXPECTED_RE is only considered when not
193 # testing with "compile".
194 proc test_invalid_expression {cmd expected_re} {
195 upvar prefix prefix
196
197 if {$prefix != "compile "} {
198 gdb_test $cmd $expected_re
199 } else {
200 # Error messages depend on compiler version, so we just
201 # look for the last line indicating a failure.
202 gdb_test $cmd "Compilation failed\\."
203 }
204 }
205
206 # Check that '-XXX' without a "--" is handled as an
207 # expression.
208 gdb_test "${prefix}print -1" " = -1"
209 test_invalid_expression \
210 "${prefix}print --1" \
211 "Left operand of assignment is not an lvalue\\."
212 test_invalid_expression \
213 "${prefix}print -object" \
214 "No symbol \"object\".*"
215
216 # Test printing with options and no expression.
217 set test "${prefix}print -object --"
218 if {$prefix != "compile "} {
219 # Regular "print" repeats the last history value.
220 gdb_test $test " = -1"
221 } else {
222 # "compile print" starts a multiline expression.
223 gdb_test_multiple $test $test {
224 -re ">$" {
225 gdb_test "-1\nend" " = -1" \
226 $test
227 }
228 }
229 }
230
231 # Check that everything after "-- " is treated as an
232 # expression, not confused with an option.
233 test_invalid_expression \
234 "${prefix}print -- -address" \
235 "No symbol.*"
236 gdb_test "${prefix}print -- -1" " = -1"
237 test_invalid_expression \
238 "${prefix}print -- --1" \
239 "Left operand of assignment is not an lvalue\\."
240 }
241
242 # Basic option-machinery + "backtrace" command integration tests.
243 proc_with_prefix test-backtrace {} {
244 clean_restart
245
246 test_gdb_complete_unique "backtrace" "backtrace"
247 test_gdb_complete_none "backtrace "
248
249 gdb_test "backtrace -" "Ambiguous option at: -"
250 gdb_test "backtrace --" "No stack\\."
251 gdb_test "backtrace -- -" "No stack\\."
252
253 test_gdb_complete_multiple "backtrace " "-" "" {
254 "-entry-values"
255 "-frame-arguments"
256 "-full"
257 "-hide"
258 "-no-filters"
259 "-past-entry"
260 "-past-main"
261 "-raw-frame-arguments"
262 }
263
264 # Test that we complete the qualifiers, if there's any.
265 test_gdb_complete_unique \
266 "backtrace ful" \
267 "backtrace full"
268 test_gdb_complete_unique \
269 "backtrace hid" \
270 "backtrace hide"
271 test_gdb_complete_unique \
272 "backtrace no-fil" \
273 "backtrace no-filters"
274
275 global binfile
276 clean_restart $binfile
277
278 if ![runto_main] {
279 fail "cannot run to main"
280 return
281 }
282
283 # COUNT in "backtrace COUNT" is parsed as an expression. Check
284 # that we complete expressions.
285
286 test_gdb_complete_unique \
287 "backtrace xxx" \
288 "backtrace xxx1"
289
290 test_gdb_complete_unique \
291 "backtrace -xxx" \
292 "backtrace -xxx1"
293
294 test_gdb_complete_unique \
295 "backtrace 1 + xxx" \
296 "backtrace 1 + xxx1"
297
298 test_gdb_complete_unique \
299 "backtrace (1 + xxx" \
300 "backtrace (1 + xxx1"
301 }
302
303 # Basic option-machinery + "frame apply" command integration tests.
304 proc_with_prefix test-frame-apply {} {
305 test_gdb_complete_unique "frame apply all" "frame apply all"
306
307 gdb_test "frame apply level 0-" \
308 "Please specify a command to apply on the selected frames"
309 test_gdb_complete_none "frame apply level 0-"
310
311 foreach cmd {
312 "frame apply all"
313 "frame apply 1"
314 "frame apply level 0"
315 "faas"
316 "tfaas"
317 } {
318 test_gdb_completion_offers_commands "$cmd "
319
320 # tfaas is silent on command error by design. This procedure
321 # hides that aspect. EXPECTED_RE is only considered when not
322 # testing with "faas"/"tfaas".
323 proc test_error_cmd {cmd arg expected_re} {
324 if {$cmd == "tfaas"} {
325 gdb_test_no_output "$cmd$arg"
326 } else {
327 gdb_test "$cmd$arg" $expected_re
328 }
329 }
330 # Same, but for tests where both "faas" and "tfaas" are
331 # expected to be silent.
332 proc test_error_cmd2 {cmd arg expected_re} {
333 if {$cmd == "tfaas" || $cmd == "faas"} {
334 gdb_test_no_output "$cmd$arg"
335 } else {
336 gdb_test "$cmd$arg" $expected_re
337 }
338 }
339
340 test_error_cmd $cmd " -" "Ambiguous option at: -"
341 test_gdb_complete_multiple "$cmd " "-" "" {
342 "-c"
343 "-past-entry"
344 "-past-main"
345 "-q"
346 "-s"
347 }
348
349 with_test_prefix "no-trailing-space" {
350 test_error_cmd $cmd " --" \
351 "Please specify a command to apply on the selected frames"
352 test_gdb_complete_unique "$cmd --" "$cmd --"
353 }
354
355 with_test_prefix "trailing-space" {
356 test_error_cmd $cmd " -- " \
357 "Please specify a command to apply on the selected frames"
358 test_gdb_completion_offers_commands "$cmd -- "
359 }
360
361 # '-' is a valid TUI command.
362 test_error_cmd2 $cmd " -- -" \
363 "Cannot enable the TUI when output is not a terminal"
364 test_gdb_complete_unique \
365 "$cmd -- -" \
366 "$cmd -- -"
367
368 test_error_cmd2 $cmd " -foo" \
369 "Undefined command: \"-foo\". Try \"help\"\\."
370 test_gdb_complete_none "$cmd -foo"
371
372 test_gdb_completion_offers_commands "$cmd -s "
373 }
374 }
375
376 # Basic option-machinery + "thread apply" command integration tests.
377 proc_with_prefix test-thread-apply {} {
378
379 test_gdb_complete_unique "thread apply all" "thread apply all"
380 test_gdb_complete_unique "taas" "taas"
381
382 gdb_test "thread apply 1-" \
383 "inverted range"
384 test_gdb_complete_none "frame apply level 1-"
385
386 foreach cmd {
387 "thread apply all"
388 "thread apply 1"
389 "taas"
390 } {
391 test_gdb_completion_offers_commands "$cmd "
392
393 # taas is silent on command error by design. This procedure
394 # hides the difference. EXPECTED_RE is only considered when
395 # not testing with "taas".
396 proc test_invalid_cmd {cmd arg expected_re} {
397 if {$cmd != "taas"} {
398 gdb_test "$cmd$arg" $expected_re
399 } else {
400 gdb_test_no_output "$cmd$arg"
401 }
402 }
403
404 gdb_test "$cmd -" "Ambiguous option at: -"
405
406 if {$cmd != "thread apply 1"} {
407 test_gdb_complete_multiple "$cmd " "-" "" {
408 "-ascending"
409 "-c"
410 "-q"
411 "-s"
412 }
413 } else {
414 # "-ascending" only works with "all".
415 test_gdb_complete_multiple "$cmd " "-" "" {
416 "-c"
417 "-q"
418 "-s"
419 }
420 }
421
422 if {$cmd == "thread apply all" || $cmd == "taas"} {
423 set errmsg \
424 "Please specify a command at the end of 'thread apply all'"
425 } elseif {$cmd == "thread apply 1"} {
426 set errmsg \
427 "Please specify a command following the thread ID list"
428 } else {
429 error "unexpected cmd: $cmd"
430 }
431
432 with_test_prefix "no-trailing-space" {
433 gdb_test "$cmd --" $errmsg
434 test_gdb_complete_unique "$cmd --" "$cmd --"
435 }
436
437 with_test_prefix "trailing-space" {
438 gdb_test "$cmd -- " $errmsg
439 test_gdb_completion_offers_commands "$cmd -- "
440 }
441
442 # '-' is a valid TUI command.
443 test_invalid_cmd "$cmd" " -- -" \
444 "Cannot enable the TUI when output is not a terminal"
445 test_gdb_complete_unique \
446 "$cmd -- -" \
447 "$cmd -- -"
448
449 test_invalid_cmd $cmd " -foo" \
450 "Undefined command: \"-foo\". Try \"help\"\\."
451 test_gdb_complete_none "$cmd -foo"
452
453 test_gdb_completion_offers_commands "$cmd -c "
454 }
455 }
456
457 # Miscellaneous tests.
458 proc_with_prefix test-misc {variant} {
459 global all_options
460
461 set cmd [make_cmd $variant]
462
463 # Call test command with no arguments at all.
464 gdb_test "$cmd" [expect_none ""]
465
466 # Now with a single dash.
467 if {$variant == "require-delimiter"} {
468 gdb_test "$cmd -" [expect_none "-"]
469 } else {
470 gdb_test "$cmd -" "Ambiguous option at: -"
471 }
472
473 # Completing at "-" should list all options.
474 res_test_gdb_complete_multiple "1" "$cmd " "-" "" $all_options
475
476 # Now with a double dash.
477 gdb_test "$cmd --" [expect_none ""]
478
479 # "--" is recognized by options completer, gdb auto-appends a
480 # space.
481 test_completer_recognizes 1 "$cmd --"
482
483 # Now with a double dash, plus a dash as operand.
484 gdb_test "$cmd -- -" [expect_none "-"]
485 res_test_gdb_complete_none "0 -" "$cmd -- -"
486
487 # Completing an unambiguous option just appends an empty space.
488 test_completer_recognizes 1 "$cmd -flag"
489
490 # Try running an ambiguous option.
491 if {$variant == "require-delimiter"} {
492 gdb_test "$cmd -xx" [expect_none "-xx"]
493 } else {
494 gdb_test "$cmd -xx" "Ambiguous option at: -xx"
495 }
496
497 # Check that options are not case insensitive.
498 gdb_test "$cmd -flag --" [expect_flag ""]
499
500 # Check how the different modes behave on unknown option, with a
501 # delimiter.
502 gdb_test "$cmd -FLAG --" \
503 "Unrecognized option at: -FLAG --"
504
505 # Check how the different modes behave on unknown option, without
506 # a delimiter.
507 if {$variant == "unknown-is-error"} {
508 gdb_test "$cmd -FLAG" \
509 "Unrecognized option at: -FLAG"
510 } else {
511 gdb_test "$cmd -FLAG" [expect_none "-FLAG"]
512 }
513
514 # Test parsing stops at a negative integer.
515 gdb_test "$cmd -1 --" \
516 "Unrecognized option at: -1 --"
517 gdb_test "$cmd -2 --" \
518 "Unrecognized option at: -2 --"
519 }
520
521 # Flag option tests.
522 proc_with_prefix test-flag {variant} {
523 global all_options
524
525 set cmd [make_cmd $variant]
526
527 # Completing a flag just appends a space.
528 test_completer_recognizes 1 "$cmd -flag"
529
530 # Add a dash, and all options should be shown.
531 test_gdb_complete_multiple "$cmd -flag " "-" "" $all_options
532
533 # Basic smoke tests of accepted / not accepted values.
534
535 # Check all the different variants a bool option may be specified.
536 if {$variant == "require-delimiter"} {
537 gdb_test "$cmd -flag 999" [expect_none "-flag 999"]
538 } else {
539 gdb_test "$cmd -flag 999" [expect_flag "999"]
540 }
541 gdb_test "$cmd -flag -- 999" [expect_flag "999"]
542
543 # If the "--" separator is present, then GDB errors out if the
544 # flag option is passed some value -- check that too.
545 gdb_test "$cmd -flag xxx 999 --" "Unrecognized option at: xxx 999 --"
546 gdb_test "$cmd -flag o 999 --" "Unrecognized option at: o 999 --"
547 gdb_test "$cmd -flag 1 999 --" "Unrecognized option at: 1 999 --"
548
549 # Extract twice the same flag, separated by one space.
550 gdb_test "$cmd -flag -flag -- non flags args" \
551 [expect_flag "non flags args"]
552
553 # Extract twice the same flag, separated by one space.
554 gdb_test "$cmd -xx1 -xx2 -xx1 -xx2 -xx1 -- non flags args" \
555 "-flag 0 -xx1 1 -xx2 1 -bool 0 -enum xxx -uint 0 -zuint-unl 0 -- non flags args"
556
557 # Extract 2 known flags in front of unknown flags.
558 gdb_test "$cmd -xx1 -xx2 -a -b -c -xx1 --" \
559 "Unrecognized option at: -a -b -c -xx1 --"
560
561 # Check that combined flags are not recognised.
562 gdb_test "$cmd -xx1 -xx1xx2 -xx1 --" \
563 "Unrecognized option at: -xx1xx2 -xx1 --"
564
565 # Make sure the completer don't confuse a flag option with a
566 # boolean option. Specifically, "o" should not complete to
567 # "on/off".
568
569 if {$variant == "require-delimiter"} {
570 res_test_gdb_complete_none "1" "$cmd -flag o"
571
572 gdb_test "$cmd -flag o" [expect_none "-flag o"]
573 } else {
574 res_test_gdb_complete_none "0 o" "$cmd -flag o"
575
576 gdb_test "$cmd -flag o" [expect_flag "o"]
577 }
578 }
579
580 # Boolean option tests.
581 proc_with_prefix test-boolean {variant} {
582 global all_options
583
584 set cmd [make_cmd $variant]
585
586 # Boolean option's values are optional -- "on" is implied. Check
587 # that:
588 #
589 # - For require-delimiter commands, completing after a boolean
590 # option lists all other options, plus "on/off". This is
591 # because operands won't be processed until we see a "--"
592 # delimiter.
593 #
594 # - For !require-delimiter commands, completing after a boolean
595 # option completes as an operand, since that will tend to be
596 # more common than typing "on/off".
597 # E.g., "frame apply all -past-main COMMAND".
598
599 if {$variant == "require-delimiter"} {
600 res_test_gdb_complete_multiple 1 "$cmd -bool " "" "" {
601 "-bool"
602 "-enum"
603 "-flag"
604 "-uinteger"
605 "-xx1"
606 "-xx2"
607 "-zuinteger-unlimited"
608 "off"
609 "on"
610 }
611 } else {
612 res_test_gdb_complete_none "0 " "$cmd -bool "
613 }
614
615 # Add another dash, and "on/off" are no longer offered:
616 res_test_gdb_complete_multiple 1 "$cmd -bool " "-" "" $all_options
617
618 # Basic smoke tests of accepted / not accepted values.
619
620 # The command accepts all of "1/0/enable/disable/yes/no" too, even
621 # though like the "set" command, we don't offer those as
622 # completion candidates if you complete right after the boolean
623 # command's name, like:
624 #
625 # (gdb) maint test-options require-delimiter -bool [TAB]
626 # off on
627 #
628 # However, the completer does recognize them if you start typing
629 # the boolean value.
630 foreach value {"0" "1"} {
631 test_completer_recognizes 1 "$cmd -bool $value"
632 }
633 foreach value {"of" "off"} {
634 res_test_gdb_complete_unique 1 \
635 "$cmd -bool $value" \
636 "$cmd -bool off"
637 }
638 foreach value {"y" "ye" "yes"} {
639 res_test_gdb_complete_unique 1 \
640 "$cmd -bool $value" \
641 "$cmd -bool yes"
642 }
643 foreach value {"n" "no"} {
644 res_test_gdb_complete_unique 1 \
645 "$cmd -bool $value" \
646 "$cmd -bool no"
647 }
648 foreach value {
649 "e"
650 "en"
651 "ena"
652 "enab"
653 "enabl"
654 "enable"
655 } {
656 res_test_gdb_complete_unique 1 \
657 "$cmd -bool $value" \
658 "$cmd -bool enable"
659 }
660 foreach value {
661 "d"
662 "di"
663 "dis"
664 "disa"
665 "disab"
666 "disabl"
667 "disable"
668 } {
669 res_test_gdb_complete_unique 1 \
670 "$cmd -bool $value" \
671 "$cmd -bool disable"
672 }
673
674 if {$variant == "require-delimiter"} {
675 res_test_gdb_complete_none "1" "$cmd -bool xxx"
676 } else {
677 res_test_gdb_complete_none "0 xxx" "$cmd -bool xxx"
678 }
679
680 # The command accepts abbreviations of "enable/disable/yes/no",
681 # even though we don't offer those for completion.
682 foreach value {
683 "1"
684 "y" "ye" "yes"
685 "e"
686 "en"
687 "ena"
688 "enab"
689 "enabl"
690 "enable"} {
691 gdb_test "$cmd -bool $value --" [expect_bool ""]
692 }
693 foreach value {
694 "0"
695 "of" "off"
696 "n" "no"
697 "d"
698 "di"
699 "dis"
700 "disa"
701 "disab"
702 "disabl"
703 "disable"} {
704 gdb_test "$cmd -bool $value --" [expect_none ""]
705 }
706
707 if {$variant == "require-delimiter"} {
708 gdb_test "$cmd -bool 999" [expect_none "-bool 999"]
709 } else {
710 gdb_test "$cmd -bool 999" [expect_bool "999"]
711 }
712 gdb_test "$cmd -bool -- 999" [expect_bool "999"]
713
714 # Since "on" is implied after a boolean option, for
715 # !require-delimiter commands, anything that is not
716 # yes/no/1/0/on/off/enable/disable should be considered as the raw
717 # input after the last option. Also check "o", which might look
718 # like "on" or "off", but it's treated the same.
719
720 foreach arg {"xxx" "o"} {
721 if {$variant == "require-delimiter"} {
722 gdb_test "$cmd -bool $arg" [expect_none "-bool $arg"]
723 } else {
724 gdb_test "$cmd -bool $arg" [expect_bool "$arg"]
725 }
726 }
727 # Also try -1. "unknown-is-error" commands error out saying that
728 # that's not a valid option.
729 if {$variant == "require-delimiter"} {
730 gdb_test "$cmd -bool -1" \
731 [expect_none "-bool -1"]
732 } elseif {$variant == "unknown-is-error"} {
733 gdb_test "$cmd -bool -1" \
734 "Unrecognized option at: -1"
735 } else {
736 gdb_test "$cmd -bool -1" [expect_bool "-1"]
737 }
738
739 # OTOH, if the "--" separator is present, then GDB errors out if
740 # the boolean option is passed an invalid value -- check that too.
741 gdb_test "$cmd -bool -1 999 --" \
742 "Unrecognized option at: -1 999 --"
743 gdb_test "$cmd -bool xxx 999 --" \
744 "Value given for `-bool' is not a boolean: xxx"
745 gdb_test "$cmd -bool o 999 --" \
746 "Value given for `-bool' is not a boolean: o"
747
748 # Completing after a boolean option + "o" does list "on/off",
749 # though.
750 if {$variant == "require-delimiter"} {
751 res_test_gdb_complete_multiple 1 "$cmd -bool " "o" "" {
752 "off"
753 "on"
754 }
755 } else {
756 res_test_gdb_complete_multiple "0 o" "$cmd -bool " "o" "" {
757 "off"
758 "on"
759 }
760 }
761 }
762
763 # Uinteger option tests. OPTION is which integer option we're
764 # testing. Can be "uinteger" or "zuinteger-unlimited".
765 proc_with_prefix test-uinteger {variant option} {
766 global all_options
767
768 set cmd "[make_cmd $variant] -$option"
769
770 # Test completing a uinteger option:
771 res_test_gdb_complete_multiple 1 "$cmd " "" "" {
772 "NUMBER"
773 "unlimited"
774 }
775
776 # NUMBER above is just a placeholder, make sure we don't complete
777 # it as a valid option.
778 res_test_gdb_complete_none 1 "$cmd NU"
779
780 # "unlimited" is valid though.
781 res_test_gdb_complete_unique 1 \
782 "$cmd u" \
783 "$cmd unlimited"
784
785 # Basic smoke test of accepted / not accepted values.
786 gdb_test "$cmd 1 -- 999" [expect_integer $option "1" "999"]
787 gdb_test "$cmd unlimited -- 999" \
788 [expect_integer $option "unlimited" "999"]
789 if {$option == "zuinteger-unlimited"} {
790 gdb_test "$cmd -1 --" [expect_integer $option "unlimited" ""]
791 gdb_test "$cmd 0 --" [expect_integer $option "0" ""]
792 } else {
793 gdb_test "$cmd -1 --" "integer -1 out of range"
794 gdb_test "$cmd 0 --" [expect_integer $option "unlimited" ""]
795 }
796 gdb_test "$cmd xxx --" \
797 "Expected integer at: xxx --"
798 gdb_test "$cmd unlimitedx --" \
799 "Expected integer at: unlimitedx --"
800
801 # Don't offer completions until we're past the
802 # -uinteger/-zuinteger-unlimited argument.
803 res_test_gdb_complete_none 1 "$cmd 1"
804
805 # A number of invalid values.
806 foreach value {"x" "x " "1a" "1a " "1-" "1- " "unlimitedx"} {
807 res_test_gdb_complete_none 1 "$cmd $value"
808 }
809
810 # Try "-1".
811 if {$option == "uinteger"} {
812 # -1 is invalid uinteger.
813 foreach value {"-1" "-1 "} {
814 res_test_gdb_complete_none 1 "$cmd $value"
815 }
816 } else {
817 # -1 is valid for zuinteger-unlimited.
818 res_test_gdb_complete_none 1 "$cmd -1"
819 if {$variant == "require-delimiter"} {
820 res_test_gdb_complete_multiple 1 "$cmd -1 " "" "-" $all_options
821 } else {
822 res_test_gdb_complete_none "0 " "$cmd -1 "
823 }
824 }
825
826 # Check that after a fully parsed option:
827 #
828 # - for require-delimiter commands, completion offers all
829 # options.
830 #
831 # - for !require-delimiter commands, completion offers nothing
832 # and returns false.
833 if {$variant == "require-delimiter"} {
834 res_test_gdb_complete_multiple 1 "$cmd 1 " "" "-" $all_options
835 } else {
836 res_test_gdb_complete_none "0 " "$cmd 1 "
837 }
838
839 # Test completing non-option arguments after "-uinteger 1 ".
840 foreach operand {"x" "x " "1a" "1a " "1-" "1- "} {
841 if {$variant == "require-delimiter"} {
842 res_test_gdb_complete_none 1 "$cmd 1 $operand"
843 } else {
844 res_test_gdb_complete_none "0 $operand" "$cmd 1 $operand"
845 }
846 }
847 # These look like options, but they aren't.
848 foreach operand {"-1" "-1 "} {
849 if {$variant == "unknown-is-operand"} {
850 res_test_gdb_complete_none "0 $operand" "$cmd 1 $operand"
851 } else {
852 res_test_gdb_complete_none 1 "$cmd 1 $operand"
853 }
854 }
855 }
856
857 # Enum option tests.
858 proc_with_prefix test-enum {variant} {
859 set cmd [make_cmd $variant]
860
861 res_test_gdb_complete_multiple 1 "$cmd -enum " "" "" {
862 "xxx"
863 "yyy"
864 "zzz"
865 }
866
867 # Check that "-" where a value is expected does not show the
868 # command's options. I.e., an enum's value is not optional.
869 # Check both completion and running the command.
870 res_test_gdb_complete_none 1 "$cmd -enum -"
871 gdb_test "$cmd -enum --"\
872 "Requires an argument. Valid arguments are xxx, yyy, zzz\\."
873
874 # Try passing an undefined item to an enum option.
875 gdb_test "$cmd -enum www --" "Undefined item: \"www\"."
876 }
877
878 # Run the options framework tests first.
879 foreach_with_prefix cmd {
880 "require-delimiter"
881 "unknown-is-error"
882 "unknown-is-operand"
883 } {
884 test-misc $cmd
885 test-flag $cmd
886 test-boolean $cmd
887 foreach subcmd {"uinteger" "zuinteger-unlimited" } {
888 test-uinteger $cmd $subcmd
889 }
890 test-enum $cmd
891 }
892
893 # Run the print integration tests, both as "standalone", and under
894 # "frame/thread apply". The latter checks that the "frame/thread
895 # apply ... COMMAND" commands recurse the completion machinery for
896 # COMMAND completion correctly.
897 foreach prefix {
898 ""
899 "frame apply all "
900 "frame apply 1 "
901 "frame apply level 0 "
902 "thread apply all "
903 "thread apply 1 "
904 "thread apply 1 frame apply 1 "
905 } {
906 test-print $prefix
907 }
908
909 # Same for "compile print". Not really a wrapper prefix command like
910 # "frame apply", but similar enough that we test pretty much the same
911 # things.
912 if ![skip_compile_feature_tests] {
913 test-print "compile "
914 }
915
916 # Basic "backtrace" integration tests.
917 test-backtrace
918
919 # Basic "frame apply" integration tests.
920 test-frame-apply
921
922 # Basic "thread apply" integration tests.
923 test-thread-apply
This page took 0.0519269999999999 seconds and 4 git commands to generate.