]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.cp/userdef.exp
2003-08-22 Michael Chastain <mec@shout.net>
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.cp / userdef.exp
1 # Tests of overloaded operators resolution.
2 # Copyright 1998, 1999, 2002 Free Software Foundation, Inc.
3
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18 # Please email any bugs, comments, and/or additions to this file to:
19 # bug-gdb@prep.ai.mit.edu
20
21 # written by Elena Zannoni (ezannoni@cygnus.com)
22 #
23 # source file "userdef.cc"
24 #
25
26 if $tracelevel then {
27 strace $tracelevel
28 }
29
30 if { [skip_cplus_tests] } { continue }
31
32 set testfile "userdef"
33 set srcfile ${testfile}.cc
34 set binfile ${objdir}/${subdir}/${testfile}
35
36 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
37 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
38 }
39
40
41 gdb_exit
42 gdb_start
43 gdb_reinitialize_dir $srcdir/$subdir
44 gdb_load ${binfile}
45
46
47 if ![runto_main] then {
48 perror "couldn't run to breakpoint"
49 continue
50 }
51
52 send_gdb "break marker1\n" ; gdb_expect -re ".*$gdb_prompt $"
53 send_gdb "cont\n"
54 gdb_expect {
55 -re "Break.* marker1(\\(\\)|) \\(\\) at .*:$decimal.*$gdb_prompt $" {
56 send_gdb "up\n"
57 gdb_expect {
58 -re ".*$gdb_prompt $" { pass "up from marker1" }
59 timeout { fail "up from marker1" }
60 }
61 }
62 -re "$gdb_prompt $" { fail "continue to marker1" }
63 timeout { fail "(timeout) continue to marker1" }
64 }
65
66
67 gdb_test "print one + two" "\\\$\[0-9\]* = {x = 6, y = 8}"
68
69 # If GDB fails to restore the selected frame properly after the
70 # inferior function call above (see GDB PR 1155 for an explanation of
71 # why this might happen), all the subsequent tests will fail. We
72 # should detect report that failure, but let the marker call finish so
73 # that the rest of the tests can run undisturbed.
74 gdb_test_multiple "frame" "re-selected 'main' frame after inferior call" {
75 -re "#0 marker1.*$gdb_prompt $" {
76 setup_kfail "gdb/1155" s390-*-linux-gnu
77 fail "re-selected 'main' frame after inferior call"
78 gdb_test "finish" ".*main.*at .*userdef.cc:.*// marker1-returns-here.*" \
79 "finish call to marker1"
80 }
81 -re "#1 ($hex in )?main.*$gdb_prompt $" {
82 pass "re-selected 'main' frame after inferior call"
83 }
84 }
85
86 gdb_test "print one - two" "\\\$\[0-9\]* = {x = -2, y = -2}"
87
88 gdb_test "print one * two" "\\\$\[0-9\]* = {x = 8, y = 15}"
89
90 gdb_test "print one / two" "\\\$\[0-9\]* = {x = 0, y = 0}"
91
92 gdb_test "print one % two" "\\\$\[0-9\]* = {x = 2, y = 3}"
93
94 gdb_test "print one && two" "\\\$\[0-9\]* = 1\[\r\n\]"
95
96 gdb_test "print one || two" "\\\$\[0-9\]* = 1\[\r\n\]"
97
98 gdb_test "print one & two" "\\\$\[0-9\]* = {x = 0, y = 1}"
99
100 gdb_test "print one | two" "\\\$\[0-9\]* = {x = 6, y = 7}"
101
102 gdb_test "print one ^ two" "\\\$\[0-9\]* = {x = 6, y = 6}"
103
104 gdb_test "print one < two" "\\\$\[0-9\]* = 1\[\r\n\]"
105
106 gdb_test "print one <= two" "\\\$\[0-9\]* = 1\[\r\n\]"
107
108 gdb_test "print one > two" "\\\$\[0-9\]* = 0\[\r\n\]"
109
110 gdb_test "print one >= two" "\\\$\[0-9\]* = 0\[\r\n\]"
111
112 gdb_test "print one == two" "\\\$\[0-9\]* = 0\[\r\n\]"
113
114 gdb_test "print one != two" "\\\$\[0-9\]* = 1\[\r\n\]"
115
116 # Can't really check the output of this one without knowing
117 # target integer width. Make sure we don't try to call
118 # the iostreams operator instead, though.
119 gdb_test "print one << 31" "\\\$\[0-9\]* = {x = -?\[0-9\]*, y = -?\[0-9\]*}"
120
121 # Should be fine even on < 32-bit targets.
122 gdb_test "print one >> 31" "\\\$\[0-9\]* = {x = 0, y = 0}"
123
124 gdb_test "print !one" "\\\$\[0-9\]* = 0\[\r\n\]"
125
126 # Assumes 2's complement. So does everything...
127 gdb_test "print ~one" "\\\$\[0-9\]* = {x = -3, y = -4}"
128
129 gdb_test "print -one" "\\\$\[0-9\]* = {x = -2, y = -3}"
130
131 gdb_test "print one++" "\\\$\[0-9\]* = {x = 2, y = 4}"
132
133 gdb_test "print ++one" "\\\$\[0-9\]* = {x = 3, y = 4}"
134
135 gdb_test "print one--" "\\\$\[0-9\]* = {x = 3, y = 3}"
136
137 gdb_test "print --one" "\\\$\[0-9\]* = {x = 2, y = 3}"
138
139 gdb_test "print one += 7" "\\\$\[0-9\]* = {x = 9, y = 10}"
140
141 gdb_test "print two = one" "\\\$\[0-9\]* = {x = 9, y = 10}"
142
143 # Check that GDB tolerates whitespace in operator names.
144 gdb_test "break A1::'operator+'" ".*Breakpoint $decimal at.*"
145 gdb_test "break A1::'operator +'" ".*Breakpoint $decimal at.*"
146
147 gdb_exit
148 return 0