]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.cp/userdef.exp
Copyright updates for 2007.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.cp / userdef.exp
CommitLineData
d4f3574e 1# Tests of overloaded operators resolution.
6aba47ca 2# Copyright 1998, 1999, 2002, 2004, 2005, 2006, 2007
ab5c9f60 3# Free Software Foundation, Inc.
c906108c
SS
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
c906108c
SS
19# written by Elena Zannoni (ezannoni@cygnus.com)
20#
c906108c
SS
21# source file "userdef.cc"
22#
23
c906108c
SS
24if $tracelevel then {
25 strace $tracelevel
26}
27
d4f3574e 28if { [skip_cplus_tests] } { continue }
c906108c 29
c1d88655
UW
30# On SPU this test fails because the executable exceeds local storage size.
31if { [istarget "spu*-*-*"] } {
32 return 0
33}
34
c906108c
SS
35set testfile "userdef"
36set srcfile ${testfile}.cc
37set binfile ${objdir}/${subdir}/${testfile}
38
39if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
b60f0898
JB
40 untested userdef.exp
41 return -1
c906108c
SS
42}
43
44
45gdb_exit
46gdb_start
47gdb_reinitialize_dir $srcdir/$subdir
48gdb_load ${binfile}
49
50
51if ![runto_main] then {
52 perror "couldn't run to breakpoint"
53 continue
54}
55
56send_gdb "break marker1\n" ; gdb_expect -re ".*$gdb_prompt $"
57 send_gdb "cont\n"
58 gdb_expect {
5178b9d6 59 -re "Break.* marker1(\\(\\)|) \\(\\) at .*:$decimal.*$gdb_prompt $" {
c906108c
SS
60 send_gdb "up\n"
61 gdb_expect {
62 -re ".*$gdb_prompt $" { pass "up from marker1" }
63 timeout { fail "up from marker1" }
64 }
65 }
66 -re "$gdb_prompt $" { fail "continue to marker1" }
67 timeout { fail "(timeout) continue to marker1" }
68 }
69
70
fb8acdcc
DJ
71gdb_test "print one + two" "\\\$\[0-9\]* = {x = 6, y = 8}"
72
5624293a
JB
73# If GDB fails to restore the selected frame properly after the
74# inferior function call above (see GDB PR 1155 for an explanation of
75# why this might happen), all the subsequent tests will fail. We
76# should detect report that failure, but let the marker call finish so
77# that the rest of the tests can run undisturbed.
78gdb_test_multiple "frame" "re-selected 'main' frame after inferior call" {
79 -re "#0 marker1.*$gdb_prompt $" {
80 setup_kfail "gdb/1155" s390-*-linux-gnu
81 fail "re-selected 'main' frame after inferior call"
93201743 82 gdb_test "finish" ".*main.*at .*userdef.cc:.*// marker1-returns-here.*" \
5624293a
JB
83 "finish call to marker1"
84 }
85 -re "#1 ($hex in )?main.*$gdb_prompt $" {
86 pass "re-selected 'main' frame after inferior call"
87 }
88}
89
fb8acdcc
DJ
90gdb_test "print one - two" "\\\$\[0-9\]* = {x = -2, y = -2}"
91
92gdb_test "print one * two" "\\\$\[0-9\]* = {x = 8, y = 15}"
93
94gdb_test "print one / two" "\\\$\[0-9\]* = {x = 0, y = 0}"
95
96gdb_test "print one % two" "\\\$\[0-9\]* = {x = 2, y = 3}"
97
98gdb_test "print one && two" "\\\$\[0-9\]* = 1\[\r\n\]"
99
100gdb_test "print one || two" "\\\$\[0-9\]* = 1\[\r\n\]"
101
102gdb_test "print one & two" "\\\$\[0-9\]* = {x = 0, y = 1}"
103
104gdb_test "print one | two" "\\\$\[0-9\]* = {x = 6, y = 7}"
105
106gdb_test "print one ^ two" "\\\$\[0-9\]* = {x = 6, y = 6}"
107
108gdb_test "print one < two" "\\\$\[0-9\]* = 1\[\r\n\]"
109
110gdb_test "print one <= two" "\\\$\[0-9\]* = 1\[\r\n\]"
111
112gdb_test "print one > two" "\\\$\[0-9\]* = 0\[\r\n\]"
113
114gdb_test "print one >= two" "\\\$\[0-9\]* = 0\[\r\n\]"
115
116gdb_test "print one == two" "\\\$\[0-9\]* = 0\[\r\n\]"
117
118gdb_test "print one != two" "\\\$\[0-9\]* = 1\[\r\n\]"
119
120# Can't really check the output of this one without knowing
121# target integer width. Make sure we don't try to call
122# the iostreams operator instead, though.
123gdb_test "print one << 31" "\\\$\[0-9\]* = {x = -?\[0-9\]*, y = -?\[0-9\]*}"
124
125# Should be fine even on < 32-bit targets.
126gdb_test "print one >> 31" "\\\$\[0-9\]* = {x = 0, y = 0}"
127
128gdb_test "print !one" "\\\$\[0-9\]* = 0\[\r\n\]"
129
130# Assumes 2's complement. So does everything...
36e9969c
NS
131gdb_test "print +one" "\\\$\[0-9\]* = {x = 2, y = 3}"
132
fb8acdcc
DJ
133gdb_test "print ~one" "\\\$\[0-9\]* = {x = -3, y = -4}"
134
135gdb_test "print -one" "\\\$\[0-9\]* = {x = -2, y = -3}"
136
137gdb_test "print one++" "\\\$\[0-9\]* = {x = 2, y = 4}"
138
139gdb_test "print ++one" "\\\$\[0-9\]* = {x = 3, y = 4}"
140
141gdb_test "print one--" "\\\$\[0-9\]* = {x = 3, y = 3}"
142
143gdb_test "print --one" "\\\$\[0-9\]* = {x = 2, y = 3}"
144
145gdb_test "print one += 7" "\\\$\[0-9\]* = {x = 9, y = 10}"
146
147gdb_test "print two = one" "\\\$\[0-9\]* = {x = 9, y = 10}"
c906108c 148
13b57657 149# Check that GDB tolerates whitespace in operator names.
36e9969c
NS
150gdb_test "break A2::'operator+'" ".*Breakpoint $decimal at.*"
151gdb_test "break A2::'operator +'" ".*Breakpoint $decimal at.*"
13b57657 152
ab5c9f60
DJ
153# Check that GDB handles operator* correctly.
154gdb_test "print c" "\\\$\[0-9\]* = {m = {z = .*}}"
155gdb_test "print *c" "\\\$\[0-9\]* = \\(Member &\\) @$hex: {z = .*}"
156gdb_test "print &*c" "\\\$\[0-9\]* = \\(Member \\*\\) $hex"
157gdb_test "ptype &*c" "type = struct Member {\[\r\n \]+int z;\[\r\n\]+} &\\*"
158
c906108c
SS
159gdb_exit
160return 0