Fix "maint print" error messages
[binutils-gdb.git] / gdb / testsuite / gdb.cp / userdef.exp
blob869f4bccdce01bf508dab79c83fb4aee27a5a62c
1 # Tests of overloaded operators resolution.
2 # Copyright 1998-2024 Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 # written by Elena Zannoni (ezannoni@cygnus.com)
19 # source file "userdef.cc"
22 require allow_stl_tests
24 standard_testfile .cc
26 if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug c++}]} {
27 return -1
30 if {![runto_main]} {
31 return
34 gdb_test "break marker1" \
35 "Breakpoint .*${srcfile}.*"
37 gdb_test "cont" \
38 "Break.* marker1(\\(\\)|) \\(\\) at .*:$decimal.*" \
39 "continue to marker1"
41 gdb_test "up" " in main .*" "up from marker1"
43 gdb_test "print one + two" "\\\$\[0-9\]* = {x = 6, y = 8}"
45 # If GDB fails to restore the selected frame properly after the
46 # inferior function call above (see GDB PR 1155 for an explanation of
47 # why this might happen), all the subsequent tests will fail. We
48 # should detect report that failure, but let the marker call finish so
49 # that the rest of the tests can run undisturbed.
50 gdb_test_multiple "frame" "re-selected 'main' frame after inferior call" {
51 -re "#0 marker1.*$gdb_prompt $" {
52 setup_kfail "gdb/1155" s390-*-linux-gnu
53 fail "re-selected 'main' frame after inferior call"
54 gdb_test "finish" ".*main.*at .*userdef.cc:.*// marker1-returns-here.*" \
55 "finish call to marker1"
57 -re "#1 ($hex in )?main.*$gdb_prompt $" {
58 pass "re-selected 'main' frame after inferior call"
62 gdb_test "print one - two" "\\\$\[0-9\]* = {x = -2, y = -2}"
64 gdb_test "print one * two" "\\\$\[0-9\]* = {x = 8, y = 15}"
66 gdb_test "print one / two" "\\\$\[0-9\]* = {x = 0, y = 0}"
68 gdb_test "print one % two" "\\\$\[0-9\]* = {x = 2, y = 3}"
70 gdb_test "print one && two" "\\\$\[0-9\]* = 1"
72 gdb_test "print one || two" "\\\$\[0-9\]* = 1"
74 gdb_test "print one & two" "\\\$\[0-9\]* = {x = 0, y = 1}"
76 gdb_test "print one | two" "\\\$\[0-9\]* = {x = 6, y = 7}"
78 gdb_test "print one ^ two" "\\\$\[0-9\]* = {x = 6, y = 6}"
80 gdb_test "print one < two" "\\\$\[0-9\]* = 1"
82 gdb_test "print one <= two" "\\\$\[0-9\]* = 1"
84 gdb_test "print one > two" "\\\$\[0-9\]* = 0"
86 gdb_test "print one >= two" "\\\$\[0-9\]* = 0"
88 gdb_test "print one == two" "\\\$\[0-9\]* = 0"
89 gdb_test "print one.operator== (two)" "\\\$\[0-9\]* = 0"
91 gdb_test "print one != two" "\\\$\[0-9\]* = 1"
93 # Can't really check the output of this one without knowing
94 # target integer width. Make sure we don't try to call
95 # the iostreams operator instead, though.
96 gdb_test "print one << 31" "\\\$\[0-9\]* = {x = -?\[0-9\]*, y = -?\[0-9\]*}"
98 # Should be fine even on < 32-bit targets.
99 gdb_test "print one >> 31" "\\\$\[0-9\]* = {x = 0, y = 0}"
101 gdb_test "print !one" "\\\$\[0-9\]* = 0"
103 # Assumes 2's complement. So does everything...
104 gdb_test "print +one" "\\\$\[0-9\]* = {x = 2, y = 3}"
106 gdb_test "print ~one" "\\\$\[0-9\]* = {x = -3, y = -4}"
108 gdb_test "print -one" "\\\$\[0-9\]* = {x = -2, y = -3}"
110 gdb_test "print one++" "\\\$\[0-9\]* = {x = 2, y = 4}"
112 gdb_test "print ++one" "\\\$\[0-9\]* = {x = 3, y = 4}"
114 gdb_test "print one--" "\\\$\[0-9\]* = {x = 3, y = 3}"
116 gdb_test "print --one" "\\\$\[0-9\]* = {x = 2, y = 3}"
118 gdb_test "print one += 7" "\\\$\[0-9\]* = {x = 9, y = 10}"
120 gdb_test "print two = one" "\\\$\[0-9\]* = {x = 9, y = 10}"
122 # Check that GDB tolerates whitespace in operator names.
123 gdb_test "break A2::operator+" ".*Breakpoint $decimal at.*"
124 gdb_test "break A2::operator +" ".*Breakpoint $decimal at.*"
126 # Check that GDB handles operator* correctly.
127 gdb_test "print c" "\\\$\[0-9\]* = {m = {z = .*}}"
128 gdb_test "print *c" "\\\$\[0-9\]* = \\(Member &\\) @$hex: {z = .*}"
129 gdb_test "print &*c" "\\\$\[0-9\]* = \\(Member \\*\\) $hex"
130 gdb_test "ptype &*c" "type = (struct|class) Member {(\[\r\n \]+public:)?\[\r\n \]+int z;\[\r\n\].*} \\*"
132 gdb_test "print operator== (mem1, mem2)" " = false"
133 gdb_test "print operator== (mem1, mem1)" " = true"
135 gdb_test "print mem1()" " = 5"
136 gdb_test "print mem1(10)" " = 50"
137 gdb_test "print (*&mem1)(2)" " = 10"
138 gdb_test "print (c.*mptr)(3)" " = 24"
139 gdb_test "print (&c)->m(4)" " = 32"
140 gdb_test "print c.m(5)" " = 40"
141 gdb_test "print sizeof(mem1(0))/sizeof(int)" " = 1"
142 gdb_test "ptype mem1(0)" "type = int"
143 gdb_test "print one()" "Couldn't find method A1::operator\\(\\)"
145 gdb_exit