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