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