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