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