]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.linespec/cpls-ops.exp
Update copyright year range in all GDB files
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.linespec / cpls-ops.exp
CommitLineData
e2882c85 1# Copyright 2017-2018 Free Software Foundation, Inc.
6a3c6ee4
PA
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
5# the Free Software Foundation; either version 3 of the License, or
6# (at your option) any later version.
7#
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.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16# This file is part of the gdb testsuite.
17
18load_lib completion-support.exp
19
20standard_testfile cpls-ops.cc
21
22if {[prepare_for_testing "failed to prepare" $testfile \
23 [list $srcfile] {debug}]} {
24 return -1
25}
26
27gdb_test_no_output "set max-completions unlimited"
28
29# Check that the explicit location completer manages to find the next
30# option name after a "-function function" option. A useful test when
31# the -function options's argument is a C++ operator, which can
32# include characters like '-'.
33
34proc check_explicit_skips_function_argument {function} {
35 test_gdb_complete_unique \
36 "b -function $function -sour" \
37 "b -function $function -source"
38}
39
40# Helper function for the operator new/new[] tests. CLASS_NAME is the
41# name of the class that contains the operator we're testing.
42# BRACKETS is set to [] if testing operator new[], and to empty if
43# testing operator new.
44
45proc test_operator_new {class_name brackets} {
e3919f3e
PA
46 global gdb_prompt
47
48 # Extract the type size_t is typedef-ed to.
49 set size_t ""
50 set test "get size_t underlying type"
51 gdb_test_multiple "ptype size_t" $test {
52 -re " = (\[ a-z\]*)\r\n$gdb_prompt $" {
53 set size_t $expect_out(1,string)
54 pass "$test"
55 }
56 }
6a3c6ee4
PA
57
58 # Complete all prefixes between "operato" and the full prototype.
59 foreach cmd_prefix {"b" "b -function"} {
60 set location "${class_name}::operator new${brackets}($size_t)"
61 set line "$cmd_prefix $location"
62 set start [index_after "operato" $line]
63 test_complete_prefix_range $line $start
64 check_bp_locations_match_list "$cmd_prefix $location" [list $location]
65
66 # Same, but with extra spaces. Note that the original spaces in
67 # the input line are preserved after completion.
68
69 test_gdb_complete_unique \
70 "$cmd_prefix ${class_name}::operator new " \
71 "$cmd_prefix ${class_name}::operator new ${brackets}($size_t)"
72 test_gdb_complete_unique \
73 "$cmd_prefix ${class_name}::operator new ${brackets} (" \
74 "$cmd_prefix ${class_name}::operator new ${brackets} ($size_t)"
75 test_gdb_complete_unique \
76 "$cmd_prefix ${class_name}::operator new ${brackets} ( $size_t " \
77 "$cmd_prefix ${class_name}::operator new ${brackets} ( $size_t )"
78
79 check_setting_bp_fails "$cmd_prefix ${class_name}::operator"
80
81 set location_list \
82 [list \
83 "${class_name}::operator new${brackets}" \
84 "${class_name}::operator new${brackets} ($size_t)" \
85 "${class_name}::operator new ${brackets} ( $size_t )"]
86 foreach linespec $location_list {
87 check_bp_locations_match_list \
88 "$cmd_prefix $linespec" [list $location]
89 }
90 }
91
92 # Check that the explicit location completer manages to find the
93 # option name after -function, when the -function's argument is a
94 # C++ operator new / new[].
95 check_explicit_skips_function_argument \
96 "${class_name}::operator new ${brackets} ( $size_t )"
97}
98
99proc_with_prefix operator-new {} {
100 test_operator_new test_op_new ""
101}
102
103proc_with_prefix operator-new\[\] {} {
104 test_operator_new test_op_new_array "\[\]"
105}
106
107# Helper function for the operator delete/delete[] tests. CLASS_NAME
108# is the name of the class that contains the operator we're testing.
109# BRACKETS is set to "[]" if testing operator delete[], and to empty
110# if testing operator delete.
111
112proc test_operator_delete {class_name brackets} {
113 # Complete all prefixes between "operato" and the full prototype.
114 foreach cmd_prefix {"b" "b -function"} {
115 set location "${class_name}::operator delete${brackets}(void*)"
116 set line "$cmd_prefix $location"
117 set start [index_after "operato" $line]
118 test_complete_prefix_range $line $start
119 check_bp_locations_match_list "$cmd_prefix $location" [list $location]
120
121 # Same, but with extra spaces. Note that the original spaces in
122 # the input line are preserved after completion.
123
124 test_gdb_complete_unique \
125 "$cmd_prefix ${class_name}::operator delete " \
126 "$cmd_prefix ${class_name}::operator delete ${brackets}(void*)"
127 test_gdb_complete_unique \
128 "$cmd_prefix ${class_name}::operator delete ${brackets} (" \
129 "$cmd_prefix ${class_name}::operator delete ${brackets} (void*)"
130 test_gdb_complete_unique \
131 "$cmd_prefix ${class_name}::operator delete ${brackets} ( void* " \
132 "$cmd_prefix ${class_name}::operator delete ${brackets} ( void* )"
133 test_gdb_complete_unique \
134 "$cmd_prefix ${class_name}::operator delete ${brackets} ( void * " \
135 "$cmd_prefix ${class_name}::operator delete ${brackets} ( void * )"
136
137 check_setting_bp_fails "$cmd_prefix ${class_name}::operator"
138
139 set location_list \
140 [list \
141 "${class_name}::operator delete${brackets}" \
142 "${class_name}::operator delete${brackets}(void *)" \
143 "${class_name}::operator delete ${brackets} ( void * )"]
144 foreach linespec $location_list {
145 check_bp_locations_match_list \
146 "$cmd_prefix $linespec" [list $location]
147 }
148 }
149
150 # Check that the explicit location completer manages to find the
151 # option name after -function, when the -function's argument is a
152 # C++ operator delete / delete[].
153 check_explicit_skips_function_argument \
154 "${class_name}::operator delete ${brackets} ( void * )"
155}
156
157proc_with_prefix operator-delete {} {
158 test_operator_delete test_op_delete ""
159}
160
161proc_with_prefix operator-delete\[\] {} {
162 test_operator_delete test_op_delete_array "\[\]"
163}
164
165# Helper for testing both operator() and operator[]. Tests completion
166# when the operator match is unique. CLASS_NAME is the class that
167# holds the operator to test. OPN and CLS are the open and close
168# characters ("()" or "[]").
169
170proc test_operator_unique {class_name opn cls} {
171 # Complete all prefixes between "oper" and the full prototype.
172 foreach cmd_prefix {"b" "b -function"} {
173 set location "${class_name}::operator${opn}${cls}(int)"
174 set line "$cmd_prefix $location"
175 set start [index_after "${class_name}" $line]
176 test_complete_prefix_range $line $start
177 check_bp_locations_match_list "$cmd_prefix $location" [list $location]
178
179 # Same, but with extra spaces. Note that the original spaces in
180 # the input line are preserved after completion.
181
182 test_gdb_complete_unique \
183 "$cmd_prefix ${class_name}::operator ${opn} ${cls} ( int " \
184 "$cmd_prefix ${class_name}::operator ${opn} ${cls} ( int )"
185 test_gdb_complete_unique \
186 "$cmd_prefix ${class_name}::operator ${opn} ${cls}" \
187 "$cmd_prefix ${class_name}::operator ${opn} ${cls}(int)"
188 test_gdb_complete_unique \
189 "$cmd_prefix ${class_name}::operator ${opn}${cls}" \
190 "$cmd_prefix ${class_name}::operator ${opn}${cls}(int)"
191 test_gdb_complete_unique \
192 "$cmd_prefix ${class_name}::operator ${opn}" \
193 "$cmd_prefix ${class_name}::operator ${opn}${cls}(int)"
194
195 check_setting_bp_fails "$cmd_prefix ${class_name}::operator"
196
197 set location_list \
198 [list \
199 "${class_name}::operator${opn}${cls}" \
200 "${class_name}::operator ${opn}${cls}" \
201 "${class_name}::operator ${opn}${cls}(int)" \
202 "${class_name}::operator ${opn} ${cls} ( int )"]
203 foreach linespec $location_list {
204 check_bp_locations_match_list \
205 "$cmd_prefix $linespec" [list $location]
206 }
207 }
208
209 # Check that the explicit location completer manages to find the
210 # option name after -function, when the -function's argument is a
211 # C++ operator().
212 check_explicit_skips_function_argument \
213 "${class_name}::operator ${opn} ${cls} ( int )"
214}
215
216# Helper for testing both operator() and operator[]. Tests completion
217# when the operator match is ambiguous. CLASS_NAME is the class that
218# holds the operator to test. OPN and CLS are the open and close
219# characters ("()" or "[]").
220
221proc test_operator_ambiguous {class_name opn cls} {
222 foreach cmd_prefix {"b" "b -function"} {
223 check_setting_bp_fails "$cmd_prefix ${class_name}::operator"
224
225 set linespec_noparams "${class_name}::operator${opn}${cls}"
226
227 set location_list \
228 [list \
229 "${class_name}::operator${opn}${cls}(int)" \
230 "${class_name}::operator${opn}${cls}(long)" \
231 "${class_name}::operator${opn}${cls}<int>(int*)"]
232 # The operator[] test can't have a "()" overload, since that
233 # wouldn't compile.
234 if {$opn == "("} {
235 set location_list \
236 [concat \
237 [list "${class_name}::operator${opn}${cls}()"] \
238 $location_list]
239 }
240 test_gdb_complete_multiple \
241 "$cmd_prefix " "$linespec_noparams" "" $location_list
242
243 # Setting the breakpoint doesn't create a breakpoint location
244 # for the template, because immediately after
245 # "operator()/operator[]" we have the template parameters, not
246 # the parameter list.
247 set location_list \
248 [list \
249 "${class_name}::operator${opn}${cls}(int)" \
250 "${class_name}::operator${opn}${cls}(long)"]
251 if {$opn == "("} {
252 set location_list \
253 [concat \
254 [list "${class_name}::operator${opn}${cls}()"] \
255 $location_list]
256 }
257 check_bp_locations_match_list "$cmd_prefix $linespec_noparams" \
258 $location_list
259 check_bp_locations_match_list "$cmd_prefix $linespec_noparams<int>" \
260 [list "${class_name}::operator${opn}${cls}<int>(int*)"]
261
262 # Test the template version. Test both with and without
263 # return type.
264 test_gdb_complete_unique \
265 "$cmd_prefix ${class_name}::operator${opn}${cls}<int>(in" \
266 "$cmd_prefix ${class_name}::operator${opn}${cls}<int>(int*)"
267 check_bp_locations_match_list \
268 "$cmd_prefix ${class_name}::operator${opn}${cls}<int>(int*)" \
269 [list "${class_name}::operator${opn}${cls}<int>(int*)"]
270 test_gdb_complete_unique \
271 "$cmd_prefix void ${class_name}::operator${opn}${cls}<int>(in" \
272 "$cmd_prefix void ${class_name}::operator${opn}${cls}<int>(int*)"
273 check_bp_locations_match_list \
274 "$cmd_prefix void ${class_name}::operator${opn}${cls}<int>(int*)" \
275 [list "${class_name}::operator${opn}${cls}<int>(int*)"]
276
277 # Add extra spaces.
278 test_gdb_complete_unique \
279 "$cmd_prefix ${class_name}::operator ${opn} ${cls} ( in" \
280 "$cmd_prefix ${class_name}::operator ${opn} ${cls} ( int)"
281 check_bp_locations_match_list \
282 "$cmd_prefix ${class_name}::operator ${opn} ${cls} ( int )" \
283 [list "${class_name}::operator${opn}${cls}(int)"]
284 }
285}
286
287proc_with_prefix operator()-unique {} {
288 test_operator_unique test_unique_op_call "(" ")"
289}
290
291proc_with_prefix operator\[\]-unique {} {
292 test_operator_unique test_unique_op_array "\[" "\]"
293}
294
295proc_with_prefix operator()-ambiguous {} {
296 test_operator_ambiguous test_op_call "(" ")"
297}
298
299proc_with_prefix operator\[\]-ambiguous {} {
300 test_operator_ambiguous test_op_array "\[" "\]"
301}
302
303# Test arithmetic/logical operators. Test completing all C++
304# arithmetic/logical operators, when all the operators are in the same
305# class.
306
307proc_with_prefix ops-valid-ambiguous {} {
308 set locations {
309 "test_ops::operator!(E)"
310 "test_ops::operator!=(E, E)"
311 "test_ops::operator%(E, E)"
312 "test_ops::operator%=(E, E)"
313 "test_ops::operator&&(E, E)"
314 "test_ops::operator&(E, E)"
315 "test_ops::operator&=(E, E)"
316 "test_ops::operator*(E, E)"
317 "test_ops::operator*=(E, E)"
318 "test_ops::operator+(E, E)"
319 "test_ops::operator++(E)"
320 "test_ops::operator++(E, int)"
321 "test_ops::operator+=(E, E)"
322 "test_ops::operator,(E, E)"
323 "test_ops::operator-(E, E)"
324 "test_ops::operator--(E)"
325 "test_ops::operator--(E, int)"
326 "test_ops::operator-=(E, E)"
327 "test_ops::operator/(E, E)"
328 "test_ops::operator/=(E, E)"
329 "test_ops::operator<(E, E)"
330 "test_ops::operator<<(E, E)"
331 "test_ops::operator<<=(E, E)"
332 "test_ops::operator<=(E, E)"
333 "test_ops::operator==(E, E)"
334 "test_ops::operator>(E, E)"
335 "test_ops::operator>=(E, E)"
336 "test_ops::operator>>(E, E)"
337 "test_ops::operator>>=(E, E)"
338 "test_ops::operator^(E, E)"
339 "test_ops::operator^=(E, E)"
340 "test_ops::operator|(E, E)"
341 "test_ops::operator|=(E, E)"
342 "test_ops::operator||(E, E)"
343 "test_ops::operator~(E)"
344 }
345 foreach linespec $locations {
346 foreach cmd_prefix {"b" "b -function"} {
347 test_gdb_complete_unique \
348 "$cmd_prefix $linespec" \
349 "$cmd_prefix $linespec"
350
351 }
352
353 check_explicit_skips_function_argument "$linespec"
354 }
355
356 foreach cmd_prefix {"b" "b -function"} {
357 test_gdb_complete_multiple \
358 "$cmd_prefix " "test_ops::operator" "" $locations
359 }
360}
361
362# Test completing all C++ operators, with and without spaces. The
363# test without spaces makes sure the completion matches exactly the
364# expected prototype. The version with whitespace is a bit more lax
365# for simplicity. In that case, we only make sure we get back the
366# terminating ')'. Each operator is defined in a separate class so
367# that we can exercise unique completion matches.
368
369proc_with_prefix ops-valid-unique {} {
370 set locations {
371 "test_op_BIT_AND::operator&(E, E)"
372 "test_op_BIT_AND_A::operator&=(E, E)"
373 "test_op_BIT_O::operator|(E, E)"
374 "test_op_COMMA::operator,(E, E)"
375 "test_op_DIV::operator/(E, E)"
376 "test_op_DIV_A::operator/=(E, E)"
377 "test_op_EQ::operator==(E, E)"
378 "test_op_GT::operator>(E, E)"
379 "test_op_GTE::operator>=(E, E)"
380 "test_op_LAND::operator&&(E, E)"
381 "test_op_LOR::operator||(E, E)"
382 "test_op_LT::operator<(E, E)"
383 "test_op_LTE::operator<=(E, E)"
384 "test_op_MINUS::operator-(E, E)"
385 "test_op_MINUS_A::operator-=(E, E)"
386 "test_op_MOD::operator%(E, E)"
387 "test_op_MOD_A::operator%=(E, E)"
388 "test_op_MUL::operator*(E, E)"
389 "test_op_MUL_A::operator*=(E, E)"
390 "test_op_NEG::operator~(E)"
391 "test_op_NEQ::operator!=(E, E)"
392 "test_op_NOT::operator!(E)"
393 "test_op_OE::operator|=(E, E)"
394 "test_op_PLUS::operator+(E, E)"
395 "test_op_PLUS_A::operator+=(E, E)"
396 "test_op_POST_DEC::operator--(E, int)"
397 "test_op_POST_INC::operator++(E, int)"
398 "test_op_PRE_DEC::operator--(E)"
399 "test_op_PRE_INC::operator++(E)"
400 "test_op_SL::operator<<(E, E)"
401 "test_op_SL_A::operator<<=(E, E)"
402 "test_op_SR::operator>>(E, E)"
403 "test_op_SR_A::operator>>=(E, E)"
404 "test_op_XOR::operator^(E, E)"
405 "test_op_XOR_A::operator^=(E, E)"
406 }
407 set linespecs_ws {
408 "test_op_BIT_AND::operator & ( E , E )"
409 "test_op_BIT_AND_A::operator &= ( E , E )"
410 "test_op_BIT_O::operator | (E , E )"
411 "test_op_COMMA::operator , ( E , E )"
412 "test_op_DIV::operator / (E , E )"
413 "test_op_DIV_A::operator /= ( E , E )"
414 "test_op_EQ::operator == ( E , E )"
415 "test_op_GT::operator > ( E , E )"
416 "test_op_GTE::operator >= ( E , E )"
417 "test_op_LAND::operator && ( E , E )"
418 "test_op_LOR::operator || ( E , E )"
419 "test_op_LT::operator < ( E , E )"
420 "test_op_LTE::operator <= ( E , E )"
421 "test_op_MINUS::operator - ( E , E )"
422 "test_op_MINUS_A::operator -= ( E , E )"
423 "test_op_MOD::operator % ( E , E )"
424 "test_op_MOD_A::operator %= ( E , E )"
425 "test_op_MUL::operator * ( E , E )"
426 "test_op_MUL_A::operator *= ( E , E )"
427 "test_op_NEG::operator ~ ( E )"
428 "test_op_NEQ::operator != ( E , E )"
429 "test_op_NOT::operator ! ( E )"
430 "test_op_OE::operator |= ( E , E )"
431 "test_op_PLUS::operator + ( E , E )"
432 "test_op_PLUS_A::operator += ( E , E )"
433 "test_op_POST_DEC::operator -- ( E , int )"
434 "test_op_POST_INC::operator ++ ( E , int )"
435 "test_op_PRE_DEC::operator -- ( E )"
436 "test_op_PRE_INC::operator ++ ( E )"
437 "test_op_SL::operator << ( E , E )"
438 "test_op_SL_A::operator <<= ( E , E )"
439 "test_op_SR::operator >> ( E , E )"
440 "test_op_SR_A::operator >>= ( E , E )"
441 "test_op_XOR::operator ^ ( E , E )"
442 "test_op_XOR_A::operator ^= ( E , E )"
443 }
444 foreach linespec $locations linespec_ws $linespecs_ws {
445 foreach cmd_prefix {"b" "b -function"} {
446 with_test_prefix "no-whitespace" {
447 set line "$cmd_prefix $linespec"
448 set start [index_after "::operato" $line]
449 test_complete_prefix_range $line $start
450 }
451
452 with_test_prefix "whitespace" {
453 set line_ws "$cmd_prefix $linespec_ws"
454 set start_ws [index_after "::operator " $line_ws]
455 test_complete_prefix_range_re \
456 $line_ws "$cmd_prefix test_op_.*::operator .*\\\)" $start_ws
457 }
458 }
459
460 check_explicit_skips_function_argument "$linespec"
461 check_explicit_skips_function_argument "$linespec_ws"
462 }
463}
464
465# Test completing an invalid (whitespace at the wrong place) operator
466# name.
467
468proc_with_prefix ops-invalid {} {
469 foreach linespec {
470 "test_op_BIT_AND_A::operator& =(E, E)"
471 "test_op_DIV_A::operator/ =(E, E)"
472 "test_op_EQ::operator= =(E, E)"
473 "test_op_GTE::operator> =(E, E)"
474 "test_op_LAND::operator& &(E, E)"
475 "test_op_LOR::operator| |(E, E)"
476 "test_op_LTE::operator< =(E, E)"
477 "test_op_MINUS_A::operator- =(E, E)"
478 "test_op_MOD_A::operator% =(E, E)"
479 "test_op_MUL_A::operator* =(E, E)"
480 "test_op_NEQ::operator! =(E, E)"
481 "test_op_OE::operator| =(E, E)"
482 "test_op_PLUS_A::operator+ =(E, E)"
483 "test_op_POST_DEC::operator- -(E, int)"
484 "test_op_POST_INC::operator+ +(E, int)"
485 "test_op_PRE_DEC::operator- -(E)"
486 "test_op_PRE_INC::operator+ +(E)"
487 "test_op_SL::operator< <(E, E)"
488 "test_op_SL_A::operator< < =(E, E)"
489 "test_op_SR::operator> >(E, E)"
490 "test_op_SR_A::operator> > =(E, E)"
491 "test_op_XOR_A::operator^ =(E, E)"
492 } {
493 foreach cmd_prefix {"b" "b -function"} {
494 test_gdb_complete_tab_none "$cmd_prefix $linespec"
495 check_setting_bp_fails "$cmd_prefix $linespec"
496 }
497 }
498}
499
500# Test completing function/method FUNCTION. Completion is tested at
501# every point starting after START_AFTER. FUNCTION_WS is a version of
502# FUNCTION with extra (but valid) whitespace. FUNCTION_INVALID is a
503# version of FUNCTION with invalid whitespace. Tests that completion
504# of FUNCTION_WS completes to self, and that a completion of
505# FUNCTION_INVALID fails.
506
507proc test_function {function start_after function_ws {function_invalid ""}} {
508 foreach cmd_prefix {"b" "b -function"} {
509 set line "$cmd_prefix $function"
510 set start [index_after $start_after $line]
511 test_complete_prefix_range $line $start
512 }
513
514 check_explicit_skips_function_argument $function
515 check_explicit_skips_function_argument $function_ws
516
517 foreach cmd_prefix {"b" "b -function"} {
518 test_gdb_complete_unique \
519 "$cmd_prefix $function_ws" \
520 "$cmd_prefix $function_ws"
521 if {$function_invalid != ""} {
522 test_gdb_complete_tab_none "$cmd_prefix $function_invalid"
523 check_setting_bp_fails "$cmd_prefix $function_invalid"
524 }
525 }
526}
527
528# Test completing a user-defined conversion operator.
529
530proc_with_prefix conversion-operator {} {
531 test_function \
532 "test_op_conversion::operator test_op_conversion_res const volatile**() const volatile" \
533 "test_op_conversio" \
534 "test_op_conversion::operator test_op_conversion_res const volatile * * ( ) const volatile"}
535
536# Test completing an assignment operator.
537
538proc_with_prefix assignment-operator {} {
539 test_function \
540 "test_op_assign::operator=(test_op_assign const&)" \
541 "test_op_assig" \
542 "test_op_assign::operator = ( test_op_assign const & )" \
543}
544
545# Test completing an arrow operator.
546
547proc_with_prefix arrow-operator {} {
548 test_function \
549 "test_op_arrow::operator->()" \
550 "test_op_arro" \
551 "test_op_arrow::operator -> ( )" \
552 "test_op_arrow::operator - > ( )"
553}
554
555# The testcase driver. Calls all test procedures.
556
557proc test_driver {} {
558 operator-delete
559 operator-delete\[\]
560 operator-new
561 operator-new\[\]
562 operator()-unique
563 operator()-ambiguous
564 operator\[\]-unique
565 operator\[\]-ambiguous
566 ops-valid-ambiguous
567 ops-valid-unique
568 ops-invalid
569 conversion-operator
570 assignment-operator
571 arrow-operator
572}
573
574test_driver