gdb/
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.cp / cpexprs.exp
CommitLineData
cec808ec
KS
1# cpexprs.exp - C++ expressions tests
2#
7b6bb8da 3# Copyright 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
cec808ec
KS
4#
5# Contributed by Red Hat, originally written by Keith Seitz.
6#
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 3 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20# This file is part of the gdb testsuite.
21
22# A helper proc which sets a breakpoint at FUNC and attempts to
23# run to the breakpoint.
24proc test_breakpoint {func} {
25 global DEC
26
640617ad
DJ
27 # Return to the top of the test function every time.
28 delete_breakpoints
29 if { ! [gdb_breakpoint test_function] } {
30 fail "set test_function breakpoint for $func"
31 } elseif { [gdb_test "continue" \
32 "Continuing.\r\n\r\nBreakpoint $DEC+,.*test_function.*" \
33 ""] != 0 } {
34 fail "continue to test_function for $func"
cec808ec
KS
35 } else {
36 gdb_breakpoint "$func"
37 set i [expr {[string last : $func] + 1}]
38 set efunc [string_to_regexp [string range $func $i end]]
39 gdb_test "continue" \
40 "Continuing.\r\n\r\nBreakpoint $DEC+,.*$efunc.*" \
41 "continue to $func"
42 }
43}
44
45# Add a function to the list of tested functions
46# FUNC is the name of the function (which will be passed to gdb commands)
47# TYPE is the type of the function, as expected from the "print" command
48# PRINT is the name of the function, as expected result of the print command
49# *OR* "-", indicating that FUNC should be used (needed for virtual/inherited
50# funcs)
51# LST is either the expected result of the list command (the comment from
52# the source code) *OR* "-", in which case FUNC will be used
53#
54# Usage:
55# add NAME TYPE PRINT LST
56# add NAME TYPE PRINT -
57proc add {func type print lst} {
58 global all_functions CONVAR ADDR
59
60 set all_functions($func,type) $type
61 if {$print == "-"} {
62 set print $func
63 }
64
65 # An exception: since gdb canonicalizes C++ output,
66 # "(void)" must be mutated to "()".
67 regsub {\(void\)} $print {()} print
68
69 set all_functions($func,print) \
70 "$CONVAR = {[string_to_regexp $type]} $ADDR <[string_to_regexp $print].*>"
71 if {$lst == "-"} {
72 set lst "$func"
73 }
74 set all_functions($func,list) ".*// [string_to_regexp $lst]"
75}
76
77proc get {func cmd} {
78 global all_functions
79 return $all_functions($func,$cmd)
80}
81
82# Returns a list of function names for a given command
83proc get_functions {cmd} {
84 global all_functions
85 set result {}
86 foreach i [array names all_functions *,$cmd] {
87 if {$all_functions($i) != ""} {
88 set idx [string last , $i]
89 if {$idx != -1} {
90 lappend result [string range $i 0 [expr {$idx - 1}]]
91 }
92 }
93 }
94
95 return [lsort $result]
96}
97
98# Some convenience variables for this test
99set DEC {[0-9]}; # a decimal number
100set HEX {[0-9a-fA-F]}; # a hexidecimal number
101set CONVAR "\\\$$DEC+"; # convenience variable regexp
102set ADDR "0x$HEX+"; # address
103
104# An array of functions/methods that we are testing...
105# Each element consists is indexed by NAME,COMMAND, where
106# NAME is the function name and COMMAND is the gdb command that
107# we are testing. The value of the array for any index pair is
108# the expected result of running COMMAND with the NAME as argument.
109
110# The array holding all functions/methods to test. Valid subindexes
111# are (none need character escaping -- "add" will take care of that):
112
113# add name type print_name list
114# NAME,type: value is type of function
115# NAME,print: value is print name of function (careful w/inherited/virtual!)
116# NAME,list: value is comment in source code on first line of function
117# (without the leading "//")
118array set all_functions {}
119
120# "Normal" functions/methods
640617ad 121add {test_function} \
cec808ec
KS
122 {int (int, char **)} \
123 - \
124 -
125add {derived::a_function} \
126 {void (const derived * const)} \
127 - \
128 -
129add {base1::a_function} \
130 {void (const base1 * const)} \
131 - \
132 -
133add {base2::a_function} \
134 {void (const base2 * const)} \
135 - \
136 -
137
138# Constructors
139
140# On targets using the ARM EABI, the constructor is expected to return
141# "this".
142proc ctor { type arglist } {
143 if { [istarget arm*-*eabi*] } {
144 set ret "$type *"
145 } else {
146 set ret "void "
147 }
148 if { $arglist != "" } {
149 set arglist ", $arglist"
150 }
151 return "${ret}($type * const$arglist)"
152}
153
154add {derived::derived} \
155 [ctor derived ""] \
156 - \
157 -
158add {base1::base1(void)} \
159 [ctor base1 "const void ** const"] \
160 - \
161 -
162add {base1::base1(int)} \
163 [ctor base1 "int"] \
164 - \
165 -
166add {base2::base2} \
167 [ctor base2 "const void ** const"] \
168 - \
169 -
170add {base::base(void)} \
171 [ctor base ""] \
172 - \
173 -
174add {base::base(int)} \
175 [ctor base "int"] \
176 - \
177 -
178
179# Destructors
180
181# On targets using the ARM EABI, some destructors are expected
182# to return "this". Others are void. For internal reasons,
183# GCC returns void * instead of $type *; RealView appears to do
184# the same.
185proc dtor { type } {
186 if { [istarget arm*-*eabi*] } {
187 set ret "void *"
188 } else {
189 set ret "void "
190 }
191 return "${ret}($type * const)"
192}
193
194add {base::~base} \
195 [dtor base] \
196 - \
197 -
198
199# Overloaded methods (all are const -- we try to use the void
200# method with and without specifying "const")
201add {base::overload(void)} \
202 {int (const base * const)} \
203 - \
204 {base::overload(void) const}
205add {base::overload(void) const} \
206 {int (const base * const)} \
207 - \
208 {base::overload(void) const}
209add {base::overload(int) const} \
210 {int (const base * const, int)} \
211 - \
212 -
213add {base::overload(short) const} \
214 {int (const base * const, short)} \
215 - \
216 -
217add {base::overload(long) const} \
218 {int (const base * const, long)} \
219 - \
220 -
221add {base::overload(char*) const} \
222 {int (const base * const, char *)} \
223 - \
224 -
225add {base::overload(base&) const} \
226 {int (const base * const, base &)} \
227 - \
228 -
229
230# Operators
231add {base::operator+} \
232 {int (const base * const, const base &)} \
233 - \
234 -
235add {base::operator++} \
236 {base (base * const)} \
237 - \
238 -
239add {base::operator+=} \
240 {base (base * const, const base &)} \
241 - \
242 -
243add {base::operator-} \
244 {int (const base * const, const base &)} \
245 - \
246 -
247add {base::operator--} \
248 {base (base * const)} \
249 - \
250 -
251add {base::operator-=} \
252 {base (base * const, const base &)} \
253 - \
254 -
255add {base::operator*} \
256 {int (const base * const, const base &)} \
257 - \
258 -
259add {base::operator*=} \
260 {base (base * const, const base &)} \
261 - \
262 -
263add {base::operator/} \
264 {int (const base * const, const base &)} \
265 - \
266 -
267add {base::operator/=} \
268 {base (base * const, const base &)} \
269 - \
270 -
271add {base::operator%} \
272 {int (const base * const, const base &)} \
273 - \
274 -
275add {base::operator%=} \
276 {base (base * const, const base &)} \
277 - \
278 -
279add {base::operator<} \
280 {bool (const base * const, const base &)} \
281 - \
282 -
283add {base::operator<=} \
284 {bool (const base * const, const base &)} \
285 - \
286 -
287add {base::operator>} \
288 {bool (const base * const, const base &)} \
289 - \
290 -
291add {base::operator>=} \
292 {bool (const base * const, const base &)} \
293 - \
294 -
295add {base::operator!=} \
296 {bool (const base * const, const base &)} \
297 - \
298 -
299add {base::operator==} \
300 {bool (const base * const, const base &)} \
301 - \
302 -
303add {base::operator!} \
304 {bool (const base * const)} \
305 - \
306 -
307add {base::operator&&} \
308 {bool (const base * const, const base &)} \
309 - \
310 -
311add {base::operator||} \
312 {bool (const base * const, const base &)} \
313 - \
314 -
315add {base::operator<<} \
316 {int (const base * const, int)} \
317 - \
318 -
319add {base::operator<<=} \
320 {base (base * const, int)} \
321 - \
322 -
323add {base::operator>>} \
324 {int (const base * const, int)} \
325 - \
326 -
327add {base::operator>>=} \
328 {base (base * const, int)} \
329 - \
330 -
331add {base::operator~} \
332 {int (const base * const)} \
333 - \
334 -
335add {base::operator&} \
336 {int (const base * const, const base &)} \
337 - \
338 -
339add {base::operator&=} \
340 {base (base * const, const base &)} \
341 - \
342 -
343add {base::operator|} \
344 {int (const base * const, const base &)} \
345 - \
346 -
347add {base::operator|=} \
348 {base (base * const, const base &)} \
349 - \
350 -
351add {base::operator^} \
352 {int (const base * const, const base &)} \
353 - \
354 -
355add {base::operator^=} \
356 {base (base * const, const base &)} \
357 - \
358 -
359add {base::operator=} \
360 {base (base * const, const base &)} \
361 - \
362 -
363add {base::operator()} \
364 {void (const base * const)} \
365 - \
366 -
367add {base::operator[]} \
368 {int (const base * const, int)} \
369 - \
370 -
371add {base::operator new} \
372 {void *(size_t)} \
373 - \
374 -
375add {base::operator delete} \
376 {void (void *)} \
377 - \
378 -
379add {base::operator new[]} \
380 {void *(size_t)} \
381 - \
382 -
383add {base::operator delete[]} \
384 {void (void *)} \
385 - \
386 -
387add {base::operator char*} \
388 {char *(const base * const)} \
389 - \
390 -
391add {base::operator fluff*} \
392 {fluff *(const base * const)} \
393 - \
394 -
395add {base::operator fluff**} \
396 {fluff **(const base * const)} \
397 - \
398 -
399add {base::operator int} \
400 {int (const base * const)} \
401 - \
402 -
403
404# Templates
405add {tclass<char>::do_something} \
406 {void (tclass<char> * const)} \
407 - \
408 -
409add {tclass<int>::do_something} \
410 {void (tclass<int> * const)} \
411 - \
412 -
413add {tclass<long>::do_something} \
414 {void (tclass<long> * const)} \
415 - \
416 -
417add {tclass<short>::do_something} \
418 {void (tclass<short> * const)} \
419 - \
420 -
421add {tclass<base>::do_something} \
422 {void (tclass<base> * const)} \
423 - \
424 -
425add {flubber<int, int, int, int, int>} \
426 {void (void)} \
427 - \
428 flubber
429add {flubber<int, int, int, int, short>} \
430 {void (void)} \
431 - \
432 flubber
433add {flubber<int, int, int, int, long>} \
434 {void (void)} \
435 - \
436 flubber
437add {flubber<int, int, int, int, char>} \
438 {void (void)} \
439 - \
440 flubber
441add {flubber<int, int, int, short, int>} \
442 {void (void)} \
443 - \
444 flubber
445add {flubber<int, int, int, short, short>} \
446 {void (void)} \
447 - \
448 flubber
449add {flubber<int, int, int, short, long>} \
450 {void (void)} \
451 - \
452 flubber
453add {flubber<int, int, int, short, char>} \
454 {void (void)} \
455 - \
456 flubber
457add {flubber<int, int, int, long, int>} \
458 {void (void)} \
459 - \
460 flubber
461add {flubber<int, int, int, long, short>} \
462 {void (void)} \
463 - \
464 flubber
465add {flubber<int, int, int, long, long>} \
466 {void (void)} \
467 - \
468 flubber
469add {flubber<int, int, int, long, char>} \
470 {void (void)} \
471 - \
472 flubber
473add {flubber<int, int, int, char, int>} \
474 {void (void)} \
475 - \
476 flubber
477add {flubber<int, int, int, char, short>} \
478 {void (void)} \
479 - \
480 flubber
481add {flubber<int, int, int, char, long>} \
482 {void (void)} \
483 - \
484 flubber
485add {flubber<int, int, int, char, char>} \
486 {void (void)} \
487 - \
488 flubber
489add {flubber<int, int, short, int, int>} \
490 {void (void)} \
491 - \
492 flubber
493add {flubber<int, int, short, int, short>} \
494 {void (void)} \
495 - \
496 flubber
497add {flubber<int, int, short, int, long>} \
498 {void (void)} \
499 - \
500 flubber
501add {flubber<int, int, short, int, char>} \
502 {void (void)} \
503 - \
504 flubber
505add {flubber<int, int, short, short, int>} \
506 {void (void)} \
507 - \
508 flubber
509add {flubber<short, int, short, int, short>} \
510 {void (void)} \
511 - \
512 flubber
513add {flubber<long, short, long, short, long>} \
514 {void (void)} \
515 - \
516 flubber
517add {tclass<base>::do_something} \
518 {void (tclass<base> * const)} \
519 - \
520 {tclass<T>::do_something}
521add {policy1::policy} \
522 [ctor "policy<int, operation_1<void*> >" "int"] \
523 {policy<int, operation_1<void*> >::policy} \
524 {policy<T, Policy>::policy}
525add {policy2::policy} \
526 [ctor "policy<int, operation_2<void*> >" int] \
527 {policy<int, operation_2<void*> >::policy} \
528 {policy<T, Policy>::policy}
529add {policy3::policy} \
530 [ctor "policy<int, operation_3<void*> >" "int"] \
531 {policy<int, operation_3<void*> >::policy} \
532 {policy<T, Policy>::policy}
533add {policy4::policy} \
534 [ctor "policy<int, operation_4<void*> >" "int"] \
535 {policy<int, operation_4<void*> >::policy} \
536 {policy<T, Policy>::policy}
537add {policy1::function} \
538 {void (void)} \
539 {operation_1<void*>::function} \
540 {operation_1<T>::function}
541add {policy2::function} \
542 {void (void)} \
543 {operation_2<void*>::function} \
544 {operation_2<T>::function}
545add {policy3::function} \
546 {void (void)} \
547 {operation_3<void*>::function} \
548 {operation_3<T>::function}
549add {policy4::function} \
550 {void (void)} \
551 {operation_4<void*>::function} \
552 {operation_4<T>::function}
553add {policyd<int, operation_1<int> >::policyd} \
554 [ctor "policyd<int, operation_1<int> >" "int"] \
555 - \
556 {policyd<T, Policy>::policyd}
557add {policyd1::policyd} \
558 [ctor "policyd<int, operation_1<int> >" "int"] \
559 {policyd<int, operation_1<int> >::policyd} \
560 {policyd<T, Policy>::policyd}
561add {policyd<int, operation_1<int> >::~policyd} \
562 [dtor "policyd<int, operation_1<int> >"] \
563 - \
564 {policyd<T, Policy>::~policyd}
565add {policyd1::~policyd} \
566 [dtor "policyd<int, operation_1<int> >"] \
567 {policyd<int, operation_1<int> >::~policyd} \
568 {policyd<T, Policy>::~policyd}
569add {policyd<long, operation_1<long> >::policyd} \
570 [ctor "policyd<long, operation_1<long> >" "long"] \
571 - \
572 {policyd<T, Policy>::policyd}
573add {policyd2::policyd} \
574 [ctor "policyd<long, operation_1<long> >" "long"] \
575 {policyd<long, operation_1<long> >::policyd} \
576 {policyd<T, Policy>::policyd}
577add {policyd<long, operation_1<long> >::~policyd} \
578 [dtor "policyd<long, operation_1<long> >"] \
579 - \
580 {policyd<T, Policy>::~policyd}
581add {policyd2::~policyd} \
582 [dtor "policyd<long, operation_1<long> >"] \
583 {policyd<long, operation_1<long> >::~policyd} \
584 {policyd<T, Policy>::~policyd}
585add {policyd<char, operation_1<char> >::policyd} \
586 [ctor "policyd<char, operation_1<char> >" "char"] \
587 - \
588 {policyd<T, Policy>::policyd}
589add {policyd3::policyd} \
590 [ctor "policyd<char, operation_1<char> >" "char"] \
591 {policyd<char, operation_1<char> >::policyd} \
592 {policyd<T, Policy>::policyd}
593add {policyd<char, operation_1<char> >::~policyd} \
594 [dtor "policyd<char, operation_1<char> >"] \
595 - \
596 {policyd<T, Policy>::~policyd}
597add {policyd3::~policyd} \
598 [dtor "policyd<char, operation_1<char> >"] \
599 {policyd<char, operation_1<char> >::~policyd} \
600 {policyd<T, Policy>::~policyd}
601add {policyd<base, operation_1<base> >::policyd} \
602 [ctor "policyd<base, operation_1<base> >" "base"] \
603 - \
604 {policyd<T, Policy>::policyd}
605add {policyd4::policyd} \
606 [ctor "policyd<base, operation_1<base> >" "base"] \
607 {policyd<base, operation_1<base> >::policyd} \
608 {policyd<T, Policy>::policyd}
609add {policyd<base, operation_1<base> >::~policyd} \
610 [dtor "policyd<base, operation_1<base> >"] \
611 - \
612 {policyd<T, Policy>::~policyd}
613add {policyd4::~policyd} \
614 [dtor "policyd<base, operation_1<base> >"] \
615 {policyd<base, operation_1<base> >::~policyd} \
616 {policyd<T, Policy>::~policyd}
617add {policyd<tclass<int>, operation_1<tclass<int> > >::policyd} \
618 [ctor "policyd<tclass<int>, operation_1<tclass<int> > >" "tclass<int>"] \
619 - \
620 {policyd<T, Policy>::policyd}
621add {policyd5::policyd} \
622 [ctor "policyd<tclass<int>, operation_1<tclass<int> > >" "tclass<int>"] \
623 {policyd<tclass<int>, operation_1<tclass<int> > >::policyd} \
624 {policyd<T, Policy>::policyd}
625add {policyd<tclass<int>, operation_1<tclass<int> > >::~policyd} \
626 [dtor "policyd<tclass<int>, operation_1<tclass<int> > >"] \
627 - \
628 {policyd<T, Policy>::~policyd}
629add {policyd5::~policyd} \
630 [dtor "policyd<tclass<int>, operation_1<tclass<int> > >"] \
631 {policyd<tclass<int>, operation_1<tclass<int> > >::~policyd} \
632 {policyd<T, Policy>::~policyd}
633add {policyd<int, operation_1<int> >::function} \
634 {void (void)} \
635 {operation_1<int>::function}\
636 {operation_1<T>::function}
637add {policyd1::function} \
638 {void (void)} \
639 {operation_1<int>::function} \
640 {operation_1<T>::function}
641add {policyd2::function} \
642 {void (void)} \
643 {operation_1<long>::function} \
644 {operation_1<T>::function}
645add {policyd<char, operation_1<char> >::function} \
646 {void (void)} \
647 {operation_1<char>::function} \
648 {operation_1<T>::function}
649add {policyd3::function} \
650 {void (void)} \
651 {operation_1<char>::function} \
652 {operation_1<T>::function}
653add {policyd<base, operation_1<base> >::function} \
654 {void (void)} \
655 {operation_1<base>::function} \
656 {operation_1<T>::function}
657add {policyd4::function} \
658 {void (void)} \
659 {operation_1<base>::function} \
660 {operation_1<T>::function}
661add {policyd<tclass<int>, operation_1<tclass<int> > >::function} \
662 {void (void)} \
663 {operation_1<tclass<int> >::function} \
664 {operation_1<T>::function}
665add {policyd5::function} \
666 {void (void)} \
667 {operation_1<tclass<int> >::function} \
668 {operation_1<T>::function}
669
670# Start the test
671if {$tracelevel} {
672 strace $tracelevel
673}
674
675if {[skip_cplus_tests]} { continue }
676
caddefa4
UW
677# On SPU this test fails because the executable exceeds local storage size.
678if { [istarget "spu*-*-*"] } {
679 return 0
680}
681
cec808ec
KS
682#
683# test running programs
684#
cec808ec
KS
685
686set testfile "cpexprs"
687set srcfile "${testfile}.cc"
688set binfile [file join $objdir $subdir $testfile]
689
690if {[gdb_compile [file join $srcdir $subdir $srcfile] $binfile \
691 executable {debug c++}] != "" } {
692 untested "$testfile.exp"
693 return -1
694}
695
696if {[get_compiler_info $binfile "c++"]} {
697 return -1
698}
699
700gdb_exit
701gdb_start
702gdb_reinitialize_dir [file join $srcdir $subdir]
703gdb_load $binfile
704
705if {![runto_main]} {
706 perror "couldn't run to breakpoint"
707 continue
708}
709
710# Set the listsize to one. This will help with testing "list".
711gdb_test "set listsize 1"
712
713# "print METHOD"
714foreach name [get_functions print] {
715 gdb_test "print $name" [get $name print] "print $name"
716}
717
718# "list METHOD"
719foreach name [get_functions list] {
720 gdb_test "list $name" [get $name list] "list $name"
721}
722
723# Running to breakpoint -- use any function we can "list"
724foreach name [get_functions list] {
640617ad
DJ
725 # Skip "test_function", since test_breakpoint uses it
726 if {[string compare $name "test_function"] != 0} {
cec808ec
KS
727 test_breakpoint $name
728 }
729}
730
731gdb_exit
732return 0
This page took 0.228345 seconds and 4 git commands to generate.