[gdbserver] Move malloc.h include to server.h.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.cp / userdef.exp
CommitLineData
d4f3574e 1# Tests of overloaded operators resolution.
4c38e0a4 2# Copyright 1998, 1999, 2002, 2004, 2005, 2006, 2007, 2008, 2009, 2010
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
e22f8b7c 7# the Free Software Foundation; either version 3 of the License, or
c906108c 8# (at your option) any later version.
e22f8b7c 9#
c906108c
SS
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.
e22f8b7c 14#
c906108c 15# You should have received a copy of the GNU General Public License
e22f8b7c 16# along with this program. If not, see <http://www.gnu.org/licenses/>.
c906108c 17
c906108c
SS
18# written by Elena Zannoni (ezannoni@cygnus.com)
19#
c906108c
SS
20# source file "userdef.cc"
21#
22
c906108c
SS
23if $tracelevel then {
24 strace $tracelevel
25}
26
759f0f0b 27if { [skip_stl_tests] } { continue }
c906108c 28
c1d88655
UW
29# On SPU this test fails because the executable exceeds local storage size.
30if { [istarget "spu*-*-*"] } {
31 return 0
32}
33
c906108c
SS
34set testfile "userdef"
35set srcfile ${testfile}.cc
36set binfile ${objdir}/${subdir}/${testfile}
37
38if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
b60f0898
JB
39 untested userdef.exp
40 return -1
c906108c
SS
41}
42
43
44gdb_exit
45gdb_start
46gdb_reinitialize_dir $srcdir/$subdir
47gdb_load ${binfile}
48
49
50if ![runto_main] then {
51 perror "couldn't run to breakpoint"
52 continue
53}
54
f8d3bf8f
MS
55gdb_test "break marker1" \
56 "Breakpoint .*${srcfile}.*"
c906108c 57
f8d3bf8f
MS
58gdb_test "cont" \
59 "Break.* marker1(\\(\\)|) \\(\\) at .*:$decimal.*" \
60 "continue to marker1"
61
62gdb_test "up" " in main .*" "up from marker1"
c906108c 63
fb8acdcc
DJ
64gdb_test "print one + two" "\\\$\[0-9\]* = {x = 6, y = 8}"
65
5624293a
JB
66# If GDB fails to restore the selected frame properly after the
67# inferior function call above (see GDB PR 1155 for an explanation of
68# why this might happen), all the subsequent tests will fail. We
69# should detect report that failure, but let the marker call finish so
70# that the rest of the tests can run undisturbed.
71gdb_test_multiple "frame" "re-selected 'main' frame after inferior call" {
72 -re "#0 marker1.*$gdb_prompt $" {
73 setup_kfail "gdb/1155" s390-*-linux-gnu
74 fail "re-selected 'main' frame after inferior call"
93201743 75 gdb_test "finish" ".*main.*at .*userdef.cc:.*// marker1-returns-here.*" \
5624293a
JB
76 "finish call to marker1"
77 }
78 -re "#1 ($hex in )?main.*$gdb_prompt $" {
79 pass "re-selected 'main' frame after inferior call"
80 }
81}
82
fb8acdcc
DJ
83gdb_test "print one - two" "\\\$\[0-9\]* = {x = -2, y = -2}"
84
85gdb_test "print one * two" "\\\$\[0-9\]* = {x = 8, y = 15}"
86
87gdb_test "print one / two" "\\\$\[0-9\]* = {x = 0, y = 0}"
88
89gdb_test "print one % two" "\\\$\[0-9\]* = {x = 2, y = 3}"
90
91gdb_test "print one && two" "\\\$\[0-9\]* = 1\[\r\n\]"
92
93gdb_test "print one || two" "\\\$\[0-9\]* = 1\[\r\n\]"
94
95gdb_test "print one & two" "\\\$\[0-9\]* = {x = 0, y = 1}"
96
97gdb_test "print one | two" "\\\$\[0-9\]* = {x = 6, y = 7}"
98
99gdb_test "print one ^ two" "\\\$\[0-9\]* = {x = 6, y = 6}"
100
101gdb_test "print one < two" "\\\$\[0-9\]* = 1\[\r\n\]"
102
103gdb_test "print one <= two" "\\\$\[0-9\]* = 1\[\r\n\]"
104
105gdb_test "print one > two" "\\\$\[0-9\]* = 0\[\r\n\]"
106
107gdb_test "print one >= two" "\\\$\[0-9\]* = 0\[\r\n\]"
108
109gdb_test "print one == two" "\\\$\[0-9\]* = 0\[\r\n\]"
6e31430b 110gdb_test "print one.operator== (two)" "\\\$\[0-9\]* = 0\[\r\n\]"
fb8acdcc
DJ
111
112gdb_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.
117gdb_test "print one << 31" "\\\$\[0-9\]* = {x = -?\[0-9\]*, y = -?\[0-9\]*}"
118
119# Should be fine even on < 32-bit targets.
120gdb_test "print one >> 31" "\\\$\[0-9\]* = {x = 0, y = 0}"
121
122gdb_test "print !one" "\\\$\[0-9\]* = 0\[\r\n\]"
123
124# Assumes 2's complement. So does everything...
36e9969c
NS
125gdb_test "print +one" "\\\$\[0-9\]* = {x = 2, y = 3}"
126
fb8acdcc
DJ
127gdb_test "print ~one" "\\\$\[0-9\]* = {x = -3, y = -4}"
128
129gdb_test "print -one" "\\\$\[0-9\]* = {x = -2, y = -3}"
130
131gdb_test "print one++" "\\\$\[0-9\]* = {x = 2, y = 4}"
132
133gdb_test "print ++one" "\\\$\[0-9\]* = {x = 3, y = 4}"
134
135gdb_test "print one--" "\\\$\[0-9\]* = {x = 3, y = 3}"
136
137gdb_test "print --one" "\\\$\[0-9\]* = {x = 2, y = 3}"
138
139gdb_test "print one += 7" "\\\$\[0-9\]* = {x = 9, y = 10}"
140
141gdb_test "print two = one" "\\\$\[0-9\]* = {x = 9, y = 10}"
c906108c 142
13b57657 143# Check that GDB tolerates whitespace in operator names.
36e9969c
NS
144gdb_test "break A2::'operator+'" ".*Breakpoint $decimal at.*"
145gdb_test "break A2::'operator +'" ".*Breakpoint $decimal at.*"
13b57657 146
ab5c9f60
DJ
147# Check that GDB handles operator* correctly.
148gdb_test "print c" "\\\$\[0-9\]* = {m = {z = .*}}"
149gdb_test "print *c" "\\\$\[0-9\]* = \\(Member &\\) @$hex: {z = .*}"
150gdb_test "print &*c" "\\\$\[0-9\]* = \\(Member \\*\\) $hex"
98751a41 151gdb_test "ptype &*c" "type = (struct|class) Member {(\[\r\n \]+public:)?\[\r\n \]+int z;\[\r\n\].*} &\\*"
ab5c9f60 152
6e31430b
TT
153gdb_test "print operator== (mem1, mem2)" " = false"
154gdb_test "print operator== (mem1, mem1)" " = true"
155
c906108c
SS
156gdb_exit
157return 0
This page took 0.978646 seconds and 4 git commands to generate.