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