| 1 | # Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004 |
| 2 | # Free Software Foundation, Inc. |
| 3 | |
| 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 2 of the License, or |
| 7 | # (at your option) any later version. |
| 8 | # |
| 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. |
| 13 | # |
| 14 | # You should have received a copy of the GNU General Public License |
| 15 | # along with this program; if not, write to the Free Software |
| 16 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 17 | |
| 18 | # Please email any bugs, comments, and/or additions to this file to: |
| 19 | # bug-gdb@prep.ai.mit.edu |
| 20 | |
| 21 | # written by Elena Zannoni (ezannoni@cygnus.com) |
| 22 | # Rewritten by Michael Chastain <mec.gnu@mindspring.com> |
| 23 | |
| 24 | # This file is part of the gdb testsuite |
| 25 | |
| 26 | # Tests for overloaded member functions. |
| 27 | |
| 28 | if $tracelevel then { |
| 29 | strace $tracelevel |
| 30 | } |
| 31 | |
| 32 | set ws "\[\r\n\t \]+" |
| 33 | set nl "\[\r\n\]+" |
| 34 | |
| 35 | set prms_id 0 |
| 36 | set bug_id 0 |
| 37 | |
| 38 | if { [skip_cplus_tests] } { continue } |
| 39 | |
| 40 | set testfile "overload" |
| 41 | set srcfile ${testfile}.cc |
| 42 | set binfile ${objdir}/${subdir}/${testfile} |
| 43 | |
| 44 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } { |
| 45 | gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail." |
| 46 | } |
| 47 | |
| 48 | gdb_exit |
| 49 | gdb_start |
| 50 | gdb_reinitialize_dir $srcdir/$subdir |
| 51 | gdb_load ${binfile} |
| 52 | |
| 53 | # Set it up at a breakpoint so we can play with the variable values. |
| 54 | |
| 55 | if ![runto 'marker1'] then { |
| 56 | perror "couldn't run to marker1" |
| 57 | continue |
| 58 | } |
| 59 | |
| 60 | gdb_test "up" ".*main.*" "up from marker1" |
| 61 | |
| 62 | # Print the monster class type. |
| 63 | # See virtfunc.exp for a discussion of ptype. |
| 64 | # |
| 65 | # This is hairy to begin with. It is even more hairy because of the |
| 66 | # XX_* alternate patterns to catch the KFAIL and XFAIL cases. |
| 67 | # TODO: And then hair^3 to reutrn the same results as the old tests. |
| 68 | |
| 69 | set re_class "((struct|class) foo \{${ws}public:|struct foo \{)" |
| 70 | set re_fields "int ifoo;${ws}const char ?\\* ?ccpfoo;" |
| 71 | set XX_fields "int ifoo;${ws}char ?\\* ?ccpfoo;" |
| 72 | set re_ctor "foo\\(int\\);${ws}foo\\(int, (char const|const char) ?\\*\\);${ws}foo\\(foo ?&\\);" |
| 73 | set re_dtor "~foo\\((void|)\\);" |
| 74 | set XX_dtor "~foo\\(int\\);" |
| 75 | set re_methods "void foofunc\\(int\\);" |
| 76 | set re_methods "${re_methods}${ws}void foofunc\\(int, signed char ?\\*\\);" |
| 77 | set re_methods "${re_methods}${ws}int overload1arg\\((void|)\\);" |
| 78 | set re_methods "${re_methods}${ws}int overload1arg\\(char\\);" |
| 79 | set re_methods "${re_methods}${ws}int overload1arg\\(signed char\\);" |
| 80 | set re_methods "${re_methods}${ws}int overload1arg\\(unsigned char\\);" |
| 81 | set re_methods "${re_methods}${ws}int overload1arg\\(short\\);" |
| 82 | set re_methods "${re_methods}${ws}int overload1arg\\(unsigned short\\);" |
| 83 | set re_methods "${re_methods}${ws}int overload1arg\\(int\\);" |
| 84 | set re_methods "${re_methods}${ws}int overload1arg\\(unsigned int\\);" |
| 85 | set re_methods "${re_methods}${ws}int overload1arg\\(long\\);" |
| 86 | set re_methods "${re_methods}${ws}int overload1arg\\(unsigned long\\);" |
| 87 | set re_methods "${re_methods}${ws}int overload1arg\\(float\\);" |
| 88 | set re_methods "${re_methods}${ws}int overload1arg\\(double\\);" |
| 89 | set re_methods "${re_methods}${ws}int overloadfnarg\\((void|)\\);" |
| 90 | set re_methods "${re_methods}${ws}int overloadfnarg\\(int\\);" |
| 91 | set re_methods "${re_methods}${ws}int overloadfnarg\\(int, int ?\\(\\*\\) ?\\(int\\)\\);" |
| 92 | set re_methods "${re_methods}${ws}int overloadargs\\(int\\);" |
| 93 | set re_methods "${re_methods}${ws}int overloadargs\\(int, int\\);" |
| 94 | set re_methods "${re_methods}${ws}int overloadargs\\(int, int, int\\);" |
| 95 | set re_methods "${re_methods}${ws}int overloadargs\\(int, int, int, int\\);" |
| 96 | set re_methods "${re_methods}${ws}int overloadargs\\(int, int, int, int, int\\);" |
| 97 | set re_methods "${re_methods}${ws}int overloadargs\\(int, int, int, int, int, int\\);" |
| 98 | set re_methods "${re_methods}${ws}int overloadargs\\(int, int, int, int, int, int, int\\);" |
| 99 | set re_methods "${re_methods}${ws}int overloadargs\\(int, int, int, int, int, int, int, int\\);" |
| 100 | set re_methods "${re_methods}${ws}int overloadargs\\(int, int, int, int, int, int, int, int, int\\);" |
| 101 | set re_methods "${re_methods}${ws}int overloadargs\\(int, int, int, int, int, int, int, int, int, int\\);" |
| 102 | set re_methods "${re_methods}${ws}int overloadargs\\(int, int, int, int, int, int, int, int, int, int, int\\);" |
| 103 | set re_synth "foo & operator=\\(foo const ?&\\);" |
| 104 | |
| 105 | gdb_test "print foo_instance1" "\\$\[0-9\]+ = \{ifoo = 111, ccpfoo = 0x0\}" |
| 106 | |
| 107 | gdb_test_multiple "ptype foo_instance1" "ptype foo_instance1" { |
| 108 | -re "type = $re_class${ws}$re_fields${ws}$re_ctor${ws}$re_dtor${ws}$re_methods$nl\}$nl$gdb_prompt $" { |
| 109 | # gcc 2.95.3 -gdwarf-2 |
| 110 | # TODO: this is not a quirk! |
| 111 | pass "ptype foo_instance1 (HP aCC -- known quirk with ~foo parameter list)" |
| 112 | } |
| 113 | -re "type = $re_class${ws}$XX_fields${ws}$re_synth${ws}$re_dtor${ws}$re_ctor${ws}$re_methods$nl\}$nl$gdb_prompt $" { |
| 114 | # gcc 2.95.3 -gstabs+, no "const" on "const char *" |
| 115 | # TODO: gdb.base/constvar.exp has XFAILed this kind of problem for a |
| 116 | # long time, but an XFAIL really needs an external bug report. |
| 117 | # -- chastain 2003-12-31 |
| 118 | # setup_xfail "*-*-*" |
| 119 | # fail "ptype foo_instance1" |
| 120 | # TODO: this should be a KFAIL. |
| 121 | pass "ptype foo_instance1 (shorter match)" |
| 122 | } |
| 123 | -re "type = $re_class${ws}$re_fields${ws}$re_synth${ws}$re_dtor${ws}$re_ctor${ws}$re_methods$nl\}$nl$gdb_prompt $" { |
| 124 | # gcc 2.95.3 -gstabs+ if "const char *" ever gets fixed |
| 125 | pass "ptype foo_instance1" |
| 126 | } |
| 127 | -re "type = $re_class${ws}$re_fields${ws}$re_ctor${ws}$XX_dtor${ws}$re_methods$nl\}$nl$gdb_prompt $" { |
| 128 | # gcc 3.3.2 -gdwarf-2, "~foo(int)" |
| 129 | # TODO: kfail this |
| 130 | # kfail "gdb/1113" "ptype foo_instance1" |
| 131 | pass "ptype foo_instance1 (shorter match)" |
| 132 | } |
| 133 | -re "type = $re_class${ws}$re_fields${ws}$re_ctor${ws}$re_dtor${ws}$re_methods$nl\}$nl$gdb_prompt $" { |
| 134 | # gcc 3.3.2 -gdwarf-2, if the dtor bug gets fixed |
| 135 | # gcc HEAD -gdwarf-2 (abi-2) |
| 136 | # TODO: just pass this |
| 137 | pass "ptype foo_instance1 (shorter match)" |
| 138 | } |
| 139 | -re "type = $re_class${ws}$re_fields${ws}$re_synth${ws}$re_ctor${ws}$re_dtor${ws}$re_methods$nl\}$nl$gdb_prompt $" { |
| 140 | # gcc 3.3.2 -gstabs+ |
| 141 | # TODO: enough with the "shorter match" |
| 142 | pass "ptype foo_instance1 (shorter match)" |
| 143 | } |
| 144 | -re "type = $re_class${ws}$re_fields${ws}$re_ctor${ws}$re_dtor${ws}$re_methods${ws}$re_synth$nl\}$nl$gdb_prompt $" { |
| 145 | # gcc HEAD -gstabs+ (abi-2) |
| 146 | # TODO: just pass this |
| 147 | # pass "ptype foo_instance1" |
| 148 | fail "ptype foo_instance1" |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | # Print variables and method calls. |
| 153 | # This is a walk in the park. |
| 154 | |
| 155 | gdb_test "print foo_instance2" "\\$\[0-9\]+ = \{ifoo = 222, ccpfoo = $hex \"A\"\}" |
| 156 | gdb_test "print foo_instance3" "\\$\[0-9\]+ = \{ifoo = 222, ccpfoo = $hex \"A\"\}" |
| 157 | |
| 158 | gdb_test "print foo_instance1.overloadargs(1)" "\\$\[0-9\]+ = 1" \ |
| 159 | "print call overloaded func 1 arg" |
| 160 | |
| 161 | # If GDB fails to restore the selected frame properly after the |
| 162 | # inferior function call above (see GDB PR 1155 for an explanation of |
| 163 | # why this might happen), all the subsequent tests will fail. We |
| 164 | # should detect and report that failure, but let the marker call |
| 165 | # finish so that the rest of the tests can run undisturbed. |
| 166 | |
| 167 | gdb_test_multiple "frame" "re-selected 'main' frame after inferior call" { |
| 168 | -re "#0 marker1.*$gdb_prompt $" { |
| 169 | setup_kfail "gdb/1155" s390-*-linux-gnu |
| 170 | fail "re-selected 'main' frame after inferior call" |
| 171 | gdb_test "finish" ".*main.*at .*overload.cc:.*// marker1-returns-here.*" \ |
| 172 | "finish call to marker1" |
| 173 | } |
| 174 | -re "#1 ($hex in )?main.*$gdb_prompt $" { |
| 175 | pass "re-selected 'main' frame after inferior call" |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | gdb_test "print foo_instance1.overloadargs(1, 2)" \ |
| 180 | "\\$\[0-9\]+ = 2" \ |
| 181 | "print call overloaded func 2 args" |
| 182 | |
| 183 | gdb_test "print foo_instance1.overloadargs(1, 2, 3)" \ |
| 184 | "\\$\[0-9\]+ = 3" \ |
| 185 | "print call overloaded func 3 args" |
| 186 | |
| 187 | gdb_test "print foo_instance1.overloadargs(1, 2, 3, 4)" \ |
| 188 | "\\$\[0-9\]+ = 4" \ |
| 189 | "print call overloaded func 4 args" |
| 190 | |
| 191 | gdb_test "print foo_instance1.overloadargs(1, 2, 3, 4, 5)" \ |
| 192 | "\\$\[0-9\]+ = 5" \ |
| 193 | "print call overloaded func 5 args" |
| 194 | |
| 195 | gdb_test "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6)" \ |
| 196 | "\\$\[0-9\]+ = 6" \ |
| 197 | "print call overloaded func 6 args" |
| 198 | |
| 199 | gdb_test "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6, 7)" \ |
| 200 | "\\$\[0-9\]+ = 7" \ |
| 201 | "print call overloaded func 7 args" |
| 202 | |
| 203 | gdb_test "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6, 7, 8)" \ |
| 204 | "\\$\[0-9\]+ = 8" \ |
| 205 | "print call overloaded func 8 args" |
| 206 | |
| 207 | gdb_test "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6, 7, 8, 9)" \ |
| 208 | "\\$\[0-9\]+ = 9" \ |
| 209 | "print call overloaded func 9 args" |
| 210 | |
| 211 | gdb_test "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)" \ |
| 212 | "\\$\[0-9\]+ = 10" \ |
| 213 | "print call overloaded func 10 args" |
| 214 | |
| 215 | gdb_test "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)" \ |
| 216 | "\\$\[0-9\]+ = 11" \ |
| 217 | "print call overloaded func 11 args" |
| 218 | |
| 219 | gdb_test "print foo_instance1.overload1arg()" \ |
| 220 | "\\$\[0-9\]+ = 1" \ |
| 221 | "print call overloaded func void arg" |
| 222 | |
| 223 | gdb_test "print foo_instance1.overload1arg((char)arg2)" \ |
| 224 | "\\$\[0-9\]+ = 2" \ |
| 225 | "print call overloaded func char arg" |
| 226 | |
| 227 | gdb_test "print foo_instance1.overload1arg((signed char)arg3)" \ |
| 228 | "\\$\[0-9\]+ = 3" \ |
| 229 | "print call overloaded func signed char arg" |
| 230 | |
| 231 | gdb_test "print foo_instance1.overload1arg((unsigned char)arg4)" \ |
| 232 | "\\$\[0-9\]+ = 4" \ |
| 233 | "print call overloaded func unsigned char arg" |
| 234 | |
| 235 | gdb_test "print foo_instance1.overload1arg((short)arg5)" \ |
| 236 | "\\$\[0-9\]+ = 5" \ |
| 237 | "print call overloaded func short arg" |
| 238 | |
| 239 | gdb_test "print foo_instance1.overload1arg((unsigned short)arg6)" \ |
| 240 | "\\$\[0-9\]+ = 6" \ |
| 241 | "print call overloaded func unsigned short arg" |
| 242 | |
| 243 | gdb_test "print foo_instance1.overload1arg((int)arg7)" \ |
| 244 | "\\$\[0-9\]+ = 7" \ |
| 245 | "print call overloaded func int arg" |
| 246 | |
| 247 | gdb_test "print foo_instance1.overload1arg((unsigned int)arg8)" \ |
| 248 | "\\$\[0-9\]+ = 8" \ |
| 249 | "print call overloaded func unsigned int arg" |
| 250 | |
| 251 | gdb_test "print foo_instance1.overload1arg((long)arg9)" \ |
| 252 | "\\$\[0-9\]+ = 9" \ |
| 253 | "print call overloaded func long arg" |
| 254 | |
| 255 | gdb_test "print foo_instance1.overload1arg((unsigned long)arg10)" \ |
| 256 | "\\$\[0-9\]+ = 10" \ |
| 257 | "print call overloaded func unsigned long arg" |
| 258 | |
| 259 | gdb_test "print foo_instance1.overload1arg((float)arg11)" \ |
| 260 | "\\$\[0-9\]+ = 11" \ |
| 261 | "print call overloaded func float arg" |
| 262 | |
| 263 | gdb_test "print foo_instance1.overload1arg((double)arg12)" \ |
| 264 | "\\$\[0-9\]+ = 12" \ |
| 265 | "print call overloaded func double arg" |
| 266 | |
| 267 | # --- |
| 268 | |
| 269 | # List overloaded functions. |
| 270 | |
| 271 | # The void case is tricky because some compilers say "(void)" |
| 272 | # and some compilers say "()". |
| 273 | |
| 274 | gdb_test "set listsize 1" "" "" |
| 275 | gdb_test_multiple "info func overloadfnarg" "list overloaded function with no args" { |
| 276 | -re ".*overloadfnarg\\(void\\).*$gdb_prompt $" { |
| 277 | # gcc 2 |
| 278 | gdb_test "list foo::overloadfnarg(void)"\ |
| 279 | ".*int foo::overloadfnarg.*\\(void\\).*" \ |
| 280 | "list overloaded function with no args" |
| 281 | } |
| 282 | -re ".*overloadfnarg\\(\\).*$gdb_prompt $" { |
| 283 | # gcc 3 |
| 284 | gdb_test "list foo::overloadfnarg()"\ |
| 285 | ".*int foo::overloadfnarg.*\\(void\\).*" \ |
| 286 | "list overloaded function with no args" |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | gdb_test "list foo::overloadfnarg(int)" \ |
| 291 | "int foo::overloadfnarg.*\\(int arg\\).*" \ |
| 292 | "list overloaded function with int arg" |
| 293 | |
| 294 | gdb_test "list foo::overloadfnarg(int, int (*)(int))" \ |
| 295 | "int foo::overloadfnarg.*\\(int arg, int \\(\\*foo\\) \\(int\\)\\).*" \ |
| 296 | "list overloaded function with function ptr args" |
| 297 | |
| 298 | gdb_test "list \"foo::overloadfnarg(int, int (*)(int))\"" \ |
| 299 | "int foo::overloadfnarg.*\\(int arg, int \\(\\*foo\\) \\(int\\)\\).*" \ |
| 300 | "list overloaded function with function ptr args - quotes around argument" |
| 301 | |
| 302 | # One last mysterious test. |
| 303 | # I wonder what this is for? |
| 304 | |
| 305 | gdb_test "print intToChar(1)" "\\$\[0-9\]+ = 297" |