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