Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / completion.exp
CommitLineData
88b9d363 1# Copyright 1998-2022 Free Software Foundation, Inc.
c906108c
SS
2
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
e22f8b7c 5# the Free Software Foundation; either version 3 of the License, or
c906108c 6# (at your option) any later version.
e22f8b7c 7#
c906108c
SS
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
e22f8b7c 12#
c906108c 13# You should have received a copy of the GNU General Public License
e22f8b7c 14# along with this program. If not, see <http://www.gnu.org/licenses/>.
c906108c 15
c906108c
SS
16# This file was written by Elena Zannoni (ezannoni@cygnus.com)
17
18# This file is part of the gdb testsuite.
19
20#
21# tests for command completion
22#
23# Here are some useful test cases for completion.
24# They should be tested with both M-? and TAB.
25#
26# "show output-" "radix"
27# "show output" "-radix"
28# "p" ambiguous (commands starting with p--path, print, printf, etc.)
29# "p " ambiguous (all symbols)
30# "info t foo" no completions
31# "info t " no completions
32# "info t" ambiguous ("info target", "info terminal", etc.)
33# "info ajksdlfk" no completions
34# "info ajksdlfk " no completions
35# "info" " "
36# "info " ambiguous (all info commands)
a1dea79a
FF
37# "p \"break1" unambiguous (completes to filename "break1.c")
38# "p \"break1." unambiguous (should complete to "break1.c" but does not,
9b284272 39# due to readline limitations)
5ac01682
DJ
40# "p 'arg" ambiguous (all symbols starting with arg)
41# "p b-arg" ambiguous (all symbols starting with arg)
c906108c
SS
42# "p b-" ambiguous (all symbols)
43# "file Make" "file" (word break hard to screw up here)
44# "file ../gdb.stabs/we" "ird" (needs to not break word at slash)
45#
46
47
c906108c 48
c906108c
SS
49#
50# test running programs
51#
c906108c 52
f76495c8 53standard_testfile break.c break1.c
c906108c 54
4c93b1db 55if [get_compiler_info] {
ae59b1da 56 return -1
085dd6e6
JM
57}
58
5b362f04 59if {[prepare_for_testing "failed to prepare" $testfile \
f76495c8 60 [list $srcfile $srcfile2] {debug nowarnings}]} {
f76495c8
TT
61 return -1
62}
c906108c
SS
63
64if ![runto_main] then {
65 perror "tests suppressed"
66}
67
085dd6e6 68set timeout 30
ef0b411a 69gdb_test_no_output "set max-completions unlimited"
c906108c 70
0d4d0e77
YQ
71gdb_test_no_output "complete print values\[0\].x." \
72 "field completion with invalid field"
73
74# If there is a non-deprecated completion, it should be returned.
75gdb_test "complete sav" "save" "test non-deprecated completion"
76# If there is only a deprecated completion, then it should be returned.
77gdb_test "complete save-t" "save-tracepoints" "test deprecated completion"
78
79
80#
81# Tag name completion.
82#
83
84gdb_test "complete ptype struct some_" "ptype struct some_struct"
85gdb_test "complete ptype enum some_" "ptype enum some_enum"
86gdb_test "complete ptype union some_" "ptype union some_union"
87
88
89gdb_test "complete set gnutarget aut" "set gnutarget auto"
90
91
92gdb_test "complete set cp-abi aut" "set cp-abi auto"
93
94# Test that completion of commands 'target FOO' works well.
95set targets [list "core" "tfile" "exec"]
96
97# Test that completion of command 'target ctf' if GDB supports ctf
98# target.
99gdb_test_multiple "target ctf" "" {
100 -re "Undefined target command: \"ctf\"\. Try \"help target\"\.\r\n$gdb_prompt $" {
101 }
102 -re "No CTF directory specified.*\r\n$gdb_prompt $" {
103 lappend targets "ctf"
104 }
105}
106
322f9c21
YQ
107# Test artifacts are put in different locations depending on test
108# is a parallel run or not. Firstly check file exists, and then
109# do the test on file completion.
110
111foreach dir1 [ list "./gdb.base" "./outputs/gdb.base/completion" ] {
d7761c2c
DE
112 if { [remote_file host exists ${dir1}/completion]
113 && [remote_file host exists ${dir1}/completion0.o]
114 && [remote_file host exists ${dir1}/completion1.o] } {
322f9c21
YQ
115 foreach target_name ${targets} {
116 gdb_test "complete target ${target_name} ${dir1}/completion" \
f9579b99
TT
117 "target ${target_name} ${dir1}/completion.*${dir1}/completion0\\.o.*${dir1}/completion1\\.o.*" \
118 "complete target ${target_name}"
322f9c21
YQ
119 }
120 break
121 }
0d4d0e77
YQ
122}
123
124#
125# "set foo unlimited" completion.
126#
127
128# A var_uinteger command.
129gdb_test "complete set height " "set height unlimited"
130gdb_test "complete set height u" "set height unlimited"
131
132# A var_integer command.
133gdb_test "complete set listsize " "set listsize unlimited"
134gdb_test "complete set listsize unl" "set listsize unlimited"
135
136# A var_zuinteger_unlimited command.
137gdb_test "complete set trace-buffer-size " "set trace-buffer-size unlimited"
138gdb_test "complete set trace-buffer-size unl" "set trace-buffer-size unlimited"
139
71c24708
AA
140# Test "info registers" completion: First determine this
141# architecture's registers and reggroups...
142
143set regs_output [capture_command_output "mt print registers" \
144 ".*Name.*Nr.*Rel.*Offset.*Size.*Type.\[^\n\]*\n"]
145append regs_output "\n"
146append regs_output [capture_command_output "mt print reggroups" \
147 ".*Group.*Type\[^\n]*\n"]
25dda427
AA
148append regs_output "\n"
149append regs_output [capture_command_output "mt print user-registers" \
150 ".*Name.*Nr\[^\n]*\n"]
71c24708
AA
151set all_regs {}
152foreach {- reg} [regexp -all -inline -line {^\s+(\w+)} $regs_output] {
153 lappend all_regs $reg
154}
155
71c24708
AA
156set all_regs [join [lsort -unique $all_regs]]
157
158# ... and then compare them to the completion of "info registers".
159
160set regs_output [capture_command_output "complete info registers " ""]
161set completed_regs {}
162foreach {-> reg} [regexp -all -inline -line {^info registers (\w+\S*)} $regs_output] {
163 lappend completed_regs $reg
164}
165set completed_regs [join [lsort $completed_regs]]
166gdb_assert {{$all_regs eq $completed_regs}} "complete 'info registers '"
167
0d4d0e77
YQ
168# Tests below are about tab-completion, which doesn't work if readline
169# library isn't used. Check it first.
170
171if { ![readline_is_used] } {
172 return -1
173}
174
037d7135
AB
175# The bulk of this test script pre-dates the completion-support
176# library, and should probably (where possible) be converted.
177# However, for now, new tests are being added using this library.
178load_lib completion-support.exp
179
8e28d804 180set test "complete 'hfgfh'"
c906108c 181send_gdb "hfgfh\t"
8e28d804
PA
182gdb_test_multiple "" "$test" {
183 -re "^hfgfh\\\x07$" {
184 send_gdb "\n"
185 gdb_test_multiple "" $test {
186 -re "Undefined command: \"hfgfh\"\\. Try \"help\"\\..*$gdb_prompt $" {
187 pass "$test"
188 }
189 }
190 }
191}
c906108c
SS
192
193#exp_internal 0
194
8e28d804 195set test "complete 'show output'"
c906108c 196send_gdb "show output\t"
8e28d804
PA
197gdb_test_multiple "" "$test" {
198 -re "^show output-radix $" {
199 send_gdb "\n"
200 gdb_test_multiple "" "$test" {
201 -re "Default output radix for printing of values is 10\\..*$gdb_prompt $" {
202 pass "$test"
203 }
204 }
205 }
206}
c906108c 207
8e28d804 208set test "complete 'show output-'"
c906108c 209send_gdb "show output-\t"
8e28d804
PA
210gdb_test_multiple "" "$test" {
211 -re "^show output-radix $" {
212 send_gdb "\n"
213 gdb_test_multiple "" "$test" {
214 -re "Default output radix for printing of values is 10\\..*$gdb_prompt $" {
215 pass "$test"
216 }
c906108c 217 }
8e28d804
PA
218 }
219}
c906108c 220
8e28d804 221set test "complete 'p'"
c906108c 222send_gdb "p\t"
8e28d804
PA
223gdb_test_multiple "" "$test" {
224 -re "^p\\\x07$" {
225 send_gdb "\n"
226 gdb_test_multiple "" "$test" {
227 -re "The history is empty\\..*$gdb_prompt $" {
228 pass "$test"
229 }
c906108c 230 }
8e28d804
PA
231 }
232}
c906108c 233
8e28d804 234set test "complete 'p '"
c906108c 235send_gdb "p \t"
8e28d804
PA
236gdb_test_multiple "" "$test" {
237 -re "^p \\\x07$" {
238 send_gdb "\n"
239 gdb_test_multiple "" "$test" {
240 -re "The history is empty\\..*$gdb_prompt $" {
241 pass "$test"
242 }
243 }
244 }
245}
c906108c 246
8e28d804 247set test "complete 'info t foo'"
c906108c 248send_gdb "info t foo\t"
8e28d804
PA
249gdb_test_multiple "" "$test" {
250 -re "^info t foo\\\x07$" {
251 send_gdb "\n"
252 gdb_test_multiple "" "$test" {
18a9fc12 253 -re "Ambiguous info command \"t foo\": target, tasks, terminal, threads, tp, tracepoints, tvariables, (type-printers, )?types\\..*$gdb_prompt $" {
8e28d804
PA
254 pass "$test"
255 }
256 }
257 }
258}
c906108c 259
8e28d804 260set test "complete 'info t'"
c906108c 261send_gdb "info t\t"
8e28d804
PA
262gdb_test_multiple "" "$test" {
263 -re "^info t\\\x07$" {
264 send_gdb "\n"
265 gdb_test_multiple "" "$test" {
18a9fc12 266 -re "Ambiguous info command \"t\": target, tasks, terminal, threads, tp, tracepoints, tvariables, (type-printers, )?types\\..*$gdb_prompt $" {
8e28d804
PA
267 pass "$test"
268 }
269 }
270 }
271}
c906108c 272
8e28d804 273set test "complete 'info t '"
c906108c 274send_gdb "info t \t"
8e28d804
PA
275gdb_test_multiple "" "$test" {
276 -re "^info t \\\x07$" {
277 send_gdb "\n"
278 gdb_test_multiple "" "$test" {
18a9fc12 279 -re "Ambiguous info command \"t \": target, tasks, terminal, threads, tp, tracepoints, tvariables, (type-printers, )?types\\..*$gdb_prompt $" {
8e28d804
PA
280 pass "$test"
281 }
282 }
283 }
284}
c906108c 285
8e28d804 286set test "complete 'info asdfgh'"
c906108c 287send_gdb "info asdfgh\t"
8e28d804
PA
288gdb_test_multiple "" "$test" {
289 -re "^info asdfgh\\\x07$" {
290 send_gdb "\n"
291 gdb_test_multiple "" "$test" {
292 -re "Undefined info command: \"asdfgh\". Try \"help info\"\\..*$gdb_prompt $" {
293 pass "$test"
294 }
295 }
296 }
297}
c906108c 298
8e28d804 299set test "complete 'info asdfgh '"
c906108c 300send_gdb "info asdfgh \t"
8e28d804
PA
301gdb_test_multiple "" "$test" {
302 -re "^info asdfgh \\\x07$" {
303 send_gdb "\n"
304 gdb_test_multiple "" "$test" {
305 -re "Undefined info command: \"asdfgh \". Try \"help info\"\\..*$gdb_prompt $" {
306 pass "$test"
307 }
308 }
309 }
310}
c906108c 311
8e28d804 312set test "complete 'info'"
c906108c 313send_gdb "info\t"
8e28d804
PA
314gdb_test_multiple "" "$test" {
315 -re "^info $" {
316 send_gdb "\n"
317 gdb_test_multiple "" "$test" {
0743fc83 318 -re "List of info subcommands.*$gdb_prompt $" {
8e28d804
PA
319 pass "$test"
320 }
321 }
322 }
323}
c906108c 324
8e28d804 325set test "complete 'info '"
c906108c 326send_gdb "info \t"
8e28d804
PA
327gdb_test_multiple "" "$test" {
328 -re "^info \\\x07$" {
329 send_gdb "\n"
330 gdb_test_multiple "" "$test" {
0743fc83 331 -re "List of info subcommands:\r\n\r\n.*$gdb_prompt $" {
8e28d804
PA
332 pass "$test"
333 }
334 }
335 }
336}
c906108c 337
8e28d804 338set test "complete (2) 'info '"
c906108c 339send_gdb "info \t"
8e28d804
PA
340gdb_test_multiple "" "$test" {
341 -re "^info \\\x07$" {
342 send_gdb "\t"
343 gdb_test_multiple "" "$test" {
344 -re "address.*types.*$gdb_prompt " {
345 send_gdb "\n"
346 gdb_test_multiple "" "$test" {
0743fc83 347 -re "allowed if unambiguous\\..*$gdb_prompt $" {
8e28d804
PA
348 pass "$test"
349 }
350 }
351 }
352 }
353 }
354}
c906108c 355
8ffd0459 356set test "complete 'help info wat'"
14032a66 357send_gdb "help info wat\t"
8e28d804
PA
358gdb_test_multiple "" "$test" {
359 -re "^help info watchpoints $" {
360 send_gdb "\n"
361 gdb_test_multiple "" "$test" {
362 -re "Status of specified watchpoints.*\r\n.*$gdb_prompt $" {
363 pass "$test"
364 }
365 }
366 }
367 -re "^help info wat\\\x07$" {
368 fail "$test"
369 }
370}
14032a66 371
8e28d804 372set test "complete 'p \"break1'"
a1dea79a 373send_gdb "p \"break1\t"
8e28d804
PA
374gdb_test_multiple "" "$test" {
375 -re "^p \"break1\\\x07$" {
376 send_gdb "\n"
377 gdb_test_multiple "" "$test" {}
378 }
379 -re "^p \"break1\\.c\"$" {
380 send_gdb "\n"
381 gdb_test_multiple "" "$test" {
8ffd0459 382 -re "$gdb_prompt $" {
8e28d804 383 pass "$test"
9b284272 384 }
8e28d804
PA
385 }
386 }
387}
9b284272
DJ
388
389setup_xfail "*-*-*"
8e28d804 390set test "complete 'p \"break1.'"
a1dea79a 391send_gdb "p \"break1.\t"
8e28d804
PA
392gdb_test_multiple "" "$test" {
393 -re "^p \"break1\\.\\\x07$" {
394 send_gdb "\n"
395 gdb_test_multiple "" "$test" {}
396 }
397 -re "^p \"break1\\.c\"$" {
398 send_gdb "\n"
399 gdb_test_multiple "" "$test" {
8ffd0459 400 -re "$gdb_prompt $" {
8e28d804 401 pass "$test"
9b284272 402 }
8e28d804
PA
403 }
404 }
405 -re "^p \"break1\\..*$" {
406 send_gdb "\n"
407 gdb_test_multiple "" "$test" {}
408 }
409}
c906108c 410
8ffd0459 411set test "complete 'p 'arg'"
5ac01682 412send_gdb "p 'arg\t"
8e28d804
PA
413gdb_test_multiple "" "$test" {
414 -re "^p 'arg\\\x07$" {
415 send_gdb "\n"
416 gdb_test_multiple "" "$test" {
417 -re "(Invalid character constant\\.|Unmatched single quote\\.).*$gdb_prompt $" {
418 pass "$test"
419 }
420 }
421 }
422}
c906108c 423
8ffd0459 424set test "complete (2) 'p 'arg'"
5ac01682 425send_gdb "p 'arg\t"
8e28d804 426gdb_test_multiple "" "$test" {
5ac01682 427 -re "^p 'arg\\\x07$" {
085dd6e6 428 send_gdb "\t"
8e28d804 429 gdb_test_multiple "" "$test" {
8ffd0459 430 -re "argv.*$gdb_prompt " {
085dd6e6 431 send_gdb "\n"
8e28d804 432 gdb_test_multiple "" "$test" {
f617d2b6 433 -re "(Invalid character constant\\.|Unmatched single quote\\.).*$gdb_prompt $" {
8e28d804 434 pass "$test"
085dd6e6 435 }
085dd6e6
JM
436 }
437 }
438 -re "(There are $decimal possibilities\\. Do you really\r\nwish to see them all.|Display all $decimal possibilities.) \\(y or n\\)$" {
439 send_gdb "n"
8e28d804 440 gdb_test_multiple "" "$test" {
5ac01682 441 -re "\\(gdb\\) p 'arg$" {
085dd6e6 442 send_gdb "\n"
8e28d804 443 gdb_test_multiple "" "$test" {
f617d2b6 444 -re "(Invalid character constant\\.|Unmatched single quote\\.).*$gdb_prompt $" {
8e28d804 445 pass "$test"
085dd6e6 446 }
085dd6e6
JM
447 }
448 }
085dd6e6
JM
449 }
450 }
085dd6e6
JM
451 }
452 }
085dd6e6 453}
c906108c 454
de0bea00
MF
455set test "complete 'handle signal'"
456send_gdb "handle sigq\t"
457gdb_test_multiple "" "$test" {
458 -re "^handle sigq\b\b\b\bSIGQUIT $" {
459 send_gdb "\n"
460 gdb_test_multiple "" "$test" {
461 -re "SIGQUIT.*Quit.*$gdb_prompt $" {
462 pass "$test"
463 }
464 }
465 }
466}
467
468set test "complete 'handle keyword'"
469send_gdb "handle nos\t"
470gdb_test_multiple "" "$test" {
471 -re "^handle nostop $" {
472 send_gdb "\n"
473 gdb_test_multiple "" "$test" {
474 -re "$gdb_prompt $" {
475 pass "$test"
476 }
477 }
478 }
479}
480
ace21957
MF
481set test "complete help aliases"
482send_gdb "help user-define\t"
483gdb_test_multiple "" "$test" {
484 -re "^help user-defined $" {
485 send_gdb "\n"
486 gdb_test_multiple "" "$test" {
487 -re "$gdb_prompt $" {
488 pass "$test"
489 }
490 }
491 }
492}
493
c906108c 494
6970b5b1
JB
495# These tests used to try completing the shorter "p b-a".
496# Unfortunately, on some systems, there are .o files in system
497# libraries which declare static variables named `b'. Of course,
498# those variables aren't really in scope, as far as the compiler is
499# concerned. But GDB deliberately tries to be more liberal: if you
500# enter an identifier that doesn't have any binding in scope, GDB will
501# search all the program's compilation units for a static variable of
502# the given name.
503#
504# This behavior can help avoid a lot of pedantry, so it's usually a
505# good thing. But in this test case, it causes GDB to print the value
506# of some random variable, instead of giving us the "No symbol..."
507# error we were expecting.
508#
509# For example, on S/390 linux, the file s_atan.c in libm.a declares a
510# `b', which is a structure containing an int and a float, so GDB says
511# ``Argument to arithmetic operation not a number or boolean'' instead
512# of ``No symbol ...''.
513#
514# So, I'm hoping that there is no system with a static library variable named
515# `no_var_by_this_name'.
8e28d804
PA
516
517set test "complete 'p no_var_named_this-arg'"
5ac01682 518send_gdb "p no_var_named_this-arg\t"
8e28d804 519gdb_test_multiple "" "$test" {
5ac01682 520 -re "^p no_var_named_this-arg\\\x07$" {
2d842f13 521 send_gdb "\n"
8e28d804 522 gdb_test_multiple "" "$test" {
6970b5b1 523 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
8e28d804 524 pass "$test"
c906108c 525 }
c906108c 526 }
2d842f13 527 }
2d842f13 528}
c906108c 529
8e28d804 530set test "complete (2) 'p no_var_named_this-arg'"
5ac01682 531send_gdb "p no_var_named_this-arg\t"
8e28d804 532gdb_test_multiple "" "$test" {
5ac01682 533 -re "^p no_var_named_this-arg\\\x07$" {
085dd6e6 534 send_gdb "\t"
8e28d804 535 gdb_test_multiple "" "$test" {
8ffd0459 536 -re "argv.*$gdb_prompt " {
085dd6e6 537 send_gdb "\n"
8e28d804 538 gdb_test_multiple "" "$test" {
6970b5b1 539 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
8e28d804 540 pass "$test"
085dd6e6 541 }
085dd6e6
JM
542 }
543 }
544 -re "(There are $decimal possibilities\\. Do you really\r\nwish to see them all.|Display all $decimal possibilities.) \\(y or n\\)$" {
c4cbc0df
PA
545 send_gdb "n\n"
546
547 # Eat the prompt
085dd6e6 548 gdb_expect {
c4cbc0df 549 -re "$gdb_prompt " {
8e28d804
PA
550 pass "$test (eat prompt)"
551 }
552 timeout {
553 fail "(timeout) $test (eat prompt)"
c4cbc0df 554 }
c4cbc0df
PA
555 }
556
8e28d804 557 gdb_test_multiple "" "$test" {
c4cbc0df 558 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
8e28d804 559 pass "$test"
c4cbc0df 560 }
085dd6e6
JM
561 }
562 }
c906108c 563 }
085dd6e6 564 }
085dd6e6 565}
c906108c 566
8e28d804 567set test "complete (2) 'p no_var_named_this-'"
6970b5b1 568send_gdb "p no_var_named_this-\t"
8e28d804 569gdb_test_multiple "" "$test" {
6970b5b1 570 -re "^p no_var_named_this-\\\x07$" {
085dd6e6 571 send_gdb "\t"
8e28d804 572 gdb_test_multiple "" "$test" {
085dd6e6 573 -re "(There are $decimal possibilities\\. Do you really\r\nwish to see them all.|Display all $decimal possibilities.) \\(y or n\\)$" {
c4cbc0df
PA
574 send_gdb "n\n"
575
576 # Eat the prompt
085dd6e6 577 gdb_expect {
c4cbc0df 578 -re "$gdb_prompt " {
8e28d804
PA
579 pass "$test (eat prompt)"
580 }
581 timeout {
582 fail "(timeout) $test (eat prompt)"
c4cbc0df 583 }
c4cbc0df
PA
584 }
585
8e28d804 586 gdb_test_multiple "" "$test" {
c4cbc0df 587 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
8e28d804 588 pass "$test"
c4cbc0df 589 }
085dd6e6
JM
590 }
591 }
8ffd0459 592 -re "argv.*$gdb_prompt $" {
5ac01682 593 send_gdb "\n"
8e28d804 594 gdb_test_multiple "" "$test" {
5ac01682 595 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
8e28d804 596 pass "$test"
5ac01682
DJ
597 }
598 }
599 }
085dd6e6
JM
600 }
601 }
085dd6e6 602}
c906108c 603
8e28d804 604set test "complete 'p values\[0\].a'"
65d12d83 605send_gdb "p values\[0\].a\t"
8e28d804
PA
606gdb_test_multiple "" "$test" {
607 -re "^p values.0..a_field $" {
608 send_gdb "\n"
609 gdb_test_multiple "" "$test" {
8ffd0459 610 -re " = 0.*$gdb_prompt $" {
8e28d804
PA
611 pass "$test"
612 }
613 }
614 }
615}
0eba65ab 616
8e28d804 617set test "complete 'p values\[0\] . a'"
37cd5d19 618send_gdb "p values\[0\] . a\t"
8e28d804
PA
619gdb_test_multiple "" "$test" {
620 -re "^p values.0. . a_field $" {
621 send_gdb "\n"
622 gdb_test_multiple "" "$test" {
8ffd0459 623 -re " = 0.*$gdb_prompt $" {
8e28d804
PA
624 pass "$test"
625 }
626 }
627 }
628}
37cd5d19 629
8e28d804 630set test "complete 'p &values\[0\] -> a'"
37cd5d19 631send_gdb "p &values\[0\] -> a\t"
8e28d804
PA
632gdb_test_multiple "" "$test" {
633 -re "^p &values.0. -> a_field $" {
634 send_gdb "\n"
635 gdb_test_multiple "" "$test" {
8ffd0459 636 -re " = .*0x\[0-9a-fA-F\]*.*$gdb_prompt $" {
8e28d804
PA
637 pass "$test"
638 }
639 }
640 }
641}
37cd5d19 642
9ae8282d
TT
643gdb_test "complete p &values\[0\]->z" \
644 "p &values.0.->z_field" \
8e28d804 645 "completion of field in anonymous union"
9ae8282d 646
4fc5d43e
TT
647gdb_test "complete ptype &values\[0\]->z" \
648 "ptype &values.0.->z_field" \
649 "ptype completion of field in anonymous union"
650
651gdb_test "complete whatis &values\[0\]->z" \
652 "whatis &values.0.->z_field" \
653 "whatis completion of field in anonymous union"
654
1a371f2e 655# The following tests used to simply try to complete `${objdir}/file',
0eba65ab
JB
656# and so on. The problem is that ${objdir} can be very long; the
657# completed filename may be more than eighty characters wide. When
658# this happens, readline tries to manage things, producing output that
659# may make sense on the screen, but is rather hard for our script to
660# recognize.
661#
662# In the case that motivated this change, the (gdb) prompt occupied
1a371f2e 663# the leftmost six columns, and `${objdir}/' was seventy-four
0eba65ab
JB
664# characters long --- eighty in all. After printing the slash,
665# readline emitted a space, a carriage return, and then `Makefile'
666# (the tab character being received as input after `Make'.
667#
668# Basically, you have to let readline do whatever it's going to do to
669# make the screen look right. If it happens to use a different
670# strategy on Tuesdays to get the cursor in the right place, that's
671# not something the testsuite should care about.
672#
ccf46844 673# So, we avoid long lines. We `cd' to ${srcdir} first, and then do
0eba65ab 674# the completion relative to the current directory.
c906108c 675
37ab3bf8
DJ
676# ${srcdir} may be a relative path. We want to make sure we end up
677# in the right directory - so make sure we know where it is.
678set mydir [pwd]
679cd ${srcdir}
680set fullsrcdir [pwd]
681cd ${mydir}
682
68ab8fc5
EZ
683# If the directory name contains a '+' we must escape it, adding a backslash.
684# If not, the test below will fail because it will interpret the '+' as a
685# regexp operator. We use string_to_regexp for this purpose.
686
687gdb_test "cd ${fullsrcdir}" \
688 "Working directory [string_to_regexp ${fullsrcdir}].*" \
689 "cd to \${srcdir}"
690
cc1d7add 691
40974f91 692# GDB used to fail adding / on directories, on the first try only.
fdc498b8 693set uniquedir ../testsuite/gdb.base/comp-dir
40974f91
JK
694set escapeduniquedir [string_to_regexp ${uniquedir}]
695set uniquesu subdi
696set uniquesub ${uniquesu}r
697set escapeuniquesub [string_to_regexp ${uniquesub}]
40974f91 698send_gdb "dir ${uniquedir}\t"
cc1d7add 699gdb_expect {
40974f91 700 -re "${escapeduniquedir}/" {
cc1d7add 701 pass "directory completion"
40974f91 702 send_gdb "${uniquesu}\t"
cc1d7add 703 }
40974f91 704 -re "${escapeduniquedir} $" {
cc1d7add 705 fail "directory completion (old gdb bug)"
40974f91 706 send_gdb "\b/${uniquesu}\t"
cc1d7add
PM
707 }
708 default {
709 fail "directory completion (timeout)"
40974f91 710 send_gdb "\ndir ${uniquedir}/${uniquesu}\t"
cc1d7add
PM
711 }
712}
713
714gdb_expect {
40974f91 715 -re "${escapeuniquesub}/$" {
cc1d7add
PM
716 pass "directory completion 2"
717 }
718 timeout {
719 fail "directory completion 2"
720 }
721}
722
40974f91 723# Empty COMMAND sends no newline while " " sends the newline we need.
cdc7edd7 724gdb_test " " "Source directories searched: .*" "glob remaining of directory test"
cc1d7add 725
8e28d804
PA
726gdb_test "complete file ./gdb.base/compl" \
727 "file ./gdb.base/completion\\.exp.*" \
728 "complete-command 'file ./gdb.base/compl'"
cc1d7add 729
a81aaca0
PA
730set test "complete 'file ./gdb.base/completi'"
731send_gdb "file ./gdb.base/completi\t"
8e28d804
PA
732gdb_test_multiple "" "$test" {
733 -re "^file ./gdb.base/completion\\.exp $" {
734 send_gdb "\n"
735 # Ignore the exact error message.
a81aaca0 736 gdb_test_multiple "" "complete 'file ./gdb.base/completi'" {
8e28d804
PA
737 -re "\r\nA program is being debugged already\\.\[\r\n\]+Are you sure you want to change the file\\? \\(y or n\\) $" {
738 send_gdb "n\n"
739 exp_continue
740 }
8ffd0459 741 -re "$gdb_prompt $" {
8e28d804
PA
742 pass "$test"
743 }
744 }
745 }
746}
c906108c 747
8e28d804 748set test "complete 'info func marke'"
3fe60e3c 749send_gdb "info func marke\t"
8e28d804
PA
750gdb_test_multiple "" "$test" {
751 -re "^info func marke.*r$" {
752 send_gdb "\t\t"
753 gdb_test_multiple "" "$test" {
754 -re "marker1.*$gdb_prompt " {
755 send_gdb "\n"
756 gdb_test_multiple "" "$test" {
b744723f 757 -re "All functions matching regular expression \"marker\":.*File.*break1.c:.*\tint marker1\\((void|)\\);\r\n.*:\tint marker2\\(int\\).*marker3\\(char.*char.*\\).*marker4\\(long( int)?\\);.*$gdb_prompt $" {
8e28d804
PA
758 pass "$test"
759 }
760 }
761 }
762 }
763 }
764}
c906108c
SS
765
766
8e28d804 767set test "complete 'set follow-fork-mode'"
c906108c 768send_gdb "set follow-fork-mode \t\t"
8e28d804
PA
769gdb_test_multiple "" "$test" {
770 -re "child.*parent.*$gdb_prompt " {
771 send_gdb "\n"
772 gdb_test_multiple "" "$test" {
773 -re "Requires an argument.*child.*parent.*$gdb_prompt $" {
774 pass "$test"
775 }
776 -re "Ambiguous item \"\"\\..*$gdb_prompt $" {
777 pass "$test"
778 }
779 }
780 }
781}
c906108c 782
e27852be
DE
783#
784# Tests for the location completer
785#
786
787# Turn off pending breakpoint support so that we don't get queried
788# all the time.
789gdb_test_no_output "set breakpoint pending off"
790
791set subsrc [string range $srcfile 0 [expr {[string length $srcfile] - 3}]]
792set test "tab complete break $subsrc"
793send_gdb "break $subsrc\t\t"
794gdb_test_multiple "" $test {
795 -re "break\.c.*break1\.c.*$gdb_prompt " {
796 send_gdb "1\t\n"
797 gdb_test_multiple "" $test {
c45ec17c 798 -re "malformed linespec error: unexpected end of input\r\n$gdb_prompt " {
e27852be
DE
799 pass $test
800 }
801 -re "$gdb_prompt p$" {
802 fail $test
803 }
804 }
805 }
806
807 -re "$gdb_prompt p$" {
808 fail $test
809 }
810}
811
812gdb_test "complete break $subsrc" "break\.c.*break1\.c"
813
814set test "tab complete break need"
815send_gdb "break need\t"
816gdb_test_multiple "" $test {
817 -re "break need_malloc " {
818 send_gdb "\n"
819 gdb_test_multiple "" $test {
820 -re ".*Breakpoint.*at .*/$srcfile, line .*$gdb_prompt " {
821 pass $test
822 gdb_test_no_output "delete breakpoint \$bpnum" \
823 "delete breakpoint for $test"
824 }
825 -re "$gdb_prompt p$" {
826 fail $test
827 }
828 }
829 }
830 -re "$gdb_prompt p$" {
831 fail $test
832 }
833}
834
835gdb_test "complete break need" "need_malloc"
836
837# gdb/17960
838# Enabling max-completions is necessary to trigger the bug.
839gdb_test_no_output "set max-completions 10"
840set test "tab complete break $srcfile:ma"
841send_gdb "break $srcfile:ma\t"
842gdb_test_multiple "" $test {
843 -re "break $srcfile:main " {
844 send_gdb "\n"
845 gdb_test_multiple "" $test {
846 -re ".*Breakpoint.*at .*/$srcfile, line .*$gdb_prompt " {
847 pass $test
848 gdb_test_no_output "delete breakpoint \$bpnum" \
849 "delete breakpoint for $test"
850 }
851 -re "$gdb_prompt p$" {
852 fail $test
853 }
854 }
855 }
856 -re "$gdb_prompt p$" {
857 fail $test
858 }
859}
860
861gdb_test "complete break $srcfile:ma" "break\.c:main"
862
863# End of gdb/17960 testing.
864
ef0b411a
GB
865#
866# Completion limiting.
867#
868
869gdb_test_no_output "set max-completions 5"
870
c7a38517
PA
871proc ignore_and_resync {cmd result test} {
872 global gdb_prompt
873
874 gdb_test_multiple "" "$test" {
875 -re "^${cmd}$" {
876 # Complete the command and ignore the output
877 # to resync gdb for the next test.
878 send_gdb "\n"
879 gdb_test_multiple "" "$test" {
880 -re "$gdb_prompt $" {
881 $result $test
ef0b411a
GB
882 }
883 }
c7a38517
PA
884 }
885 }
886}
887
888proc test_tab_complete {cmd test} {
889 global gdb_prompt
890
891 send_gdb "${cmd}\t"
892 gdb_test_multiple "" "$test" {
893 -re "^${cmd}\\\x07$" {
894 send_gdb "\t"
895 gdb_test_multiple "" "$test" {
896 -re "List may be truncated, max-completions reached.*\r\n$gdb_prompt " {
897 ignore_and_resync $cmd pass $test
898 }
899 -re "$gdb_prompt " {
900 ignore_and_resync $cmd fail $test
ef0b411a
GB
901 }
902 }
c7a38517 903 }
ef0b411a
GB
904 }
905}
906
c7a38517
PA
907test_tab_complete "p" \
908 "command-name completion limiting using tab character"
909
ef0b411a
GB
910set test "command-name completion limiting using complete command"
911send_gdb "complete p\n"
912gdb_test_multiple "" "$test" {
913 -re "List may be truncated, max-completions reached.*\r\n$gdb_prompt $" {
914 pass "$test"
915 }
916}
917
918gdb_test_no_output "set max-completions 3"
919
c7a38517
PA
920test_tab_complete "p marker" \
921 "symbol-name completion limiting using tab character"
ef0b411a
GB
922
923set test "symbol-name completion limiting using complete command"
924send_gdb "complete p mark\n"
925gdb_test_multiple "" "$test" {
926 -re "List may be truncated, max-completions reached.*\r\n$gdb_prompt $" {
927 pass "$test"
928 }
929}
037d7135
AB
930
931# Test completion of 'p', 'x', and 'display' all using a /FMT.
932foreach_with_prefix spc { " " "" } {
933 test_gdb_complete_multiple "p${spc}/d some_union_global." "" "f" {
934 "f1"
935 "f2"
936 }
937
938 test_gdb_complete_none "p${spc}/"
939 test_gdb_complete_unique "p${spc}/d" "p${spc}/d"
940
d00f0868
AB
941 # Try completion on an invalid /FMT string. GDB doesn't attempt
942 # to validate the /FMT string during completion, the string is
943 # just assumed to be complete when the user hits TAB.
944 test_gdb_complete_unique "p${spc}/@" "p${spc}/@"
945
037d7135
AB
946 test_gdb_complete_unique "x${spc}/1w values\[0\].b"\
947 "x${spc}/1w values\[0\].b_field"
948
949 test_gdb_complete_unique "display${spc}/x values\[0\].z"\
950 "display${spc}/x values\[0\].z_field"
951}
952
953# Test 'p' using both options and /FMT.
954test_gdb_complete_multiple "p -array on -- /d some_union_global." \
955 "" "f" {
956 "f1"
957 "f2"
958 }
a15a5258
AB
959
960# Check the watch commands can all complete, with and without flags.
961foreach_with_prefix cmd { "watch" "awatch" "rwatch" } {
962 foreach_with_prefix opt { "" "-l" "-location" } {
963 test_gdb_complete_multiple "${cmd} ${opt} some_union_global." \
964 "" "f" {
965 "f1"
966 "f2"
967 }
968 }
969}
1536146f
AB
970
971# Check that tab completion of a deprecated alias does not display the
972# warning about the alias being deprecated during tab completion.
973gdb_test_no_output "alias xxx_yyy_zzz=break"
974gdb_test_no_output "maint deprecate xxx_yyy_zzz"
975test_gdb_complete_unique "xxx_yyy_" "xxx_yyy_zzz"
9ef6d4a1
AB
976
977# Check that tab completion of a deprecated alias with a prefix does
978# not display the warning about the alias being deprecated during tab
979# completion.
980gdb_test_no_output "alias set aaa_bbb_ccc=set debug"
981gdb_test_no_output "maint deprecate set aaa_bbb_ccc"
982test_gdb_complete_unique "set aaa_bbb_" "set aaa_bbb_ccc"
This page took 2.720143 seconds and 4 git commands to generate.