| 1 | # Copyright (C) 1998, 1999 Free Software Foundation, Inc. |
| 2 | |
| 3 | # This program is free software; you can redistribute it and/or modify |
| 4 | # it under the terms of the GNU General Public License as published by |
| 5 | # the Free Software Foundation; either version 2 of the License, or |
| 6 | # (at your option) any later version. |
| 7 | # |
| 8 | # This program is distributed in the hope that it will be useful, |
| 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | # GNU General Public License for more details. |
| 12 | # |
| 13 | # You should have received a copy of the GNU General Public License |
| 14 | # along with this program; if not, write to the Free Software |
| 15 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 16 | |
| 17 | # Please email any bugs, comments, and/or additions to this file to: |
| 18 | # bug-gdb@prep.ai.mit.edu |
| 19 | |
| 20 | # written by Elena Zannoni (ezannoni@cygnus.com) |
| 21 | |
| 22 | # This file is part of the gdb testsuite |
| 23 | # |
| 24 | # tests for overloaded member functions. Command Line calls |
| 25 | # |
| 26 | |
| 27 | |
| 28 | if $tracelevel then { |
| 29 | strace $tracelevel |
| 30 | } |
| 31 | |
| 32 | # |
| 33 | # test running programs |
| 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 | if [get_compiler_info ${binfile} "c++"] { |
| 49 | return -1 |
| 50 | } |
| 51 | |
| 52 | gdb_exit |
| 53 | gdb_start |
| 54 | gdb_reinitialize_dir $srcdir/$subdir |
| 55 | gdb_load ${binfile} |
| 56 | |
| 57 | # set it up at a breakpoint so we can play with the variable values |
| 58 | # |
| 59 | if ![runto_main] then { |
| 60 | perror "couldn't run to breakpoint" |
| 61 | continue |
| 62 | } |
| 63 | |
| 64 | send_gdb "break marker1\n" ; gdb_expect -re ".*$gdb_prompt $" |
| 65 | |
| 66 | send_gdb "cont\n" |
| 67 | gdb_expect { |
| 68 | -re "Break.* marker1 \\(\\) at .*:$decimal.*$gdb_prompt $" { |
| 69 | send_gdb "up\n" |
| 70 | gdb_expect { |
| 71 | -re ".*main.*$gdb_prompt $" { |
| 72 | pass "up from marker1" |
| 73 | } |
| 74 | -re ".*$gdb_prompt $" { |
| 75 | fail "up from marker1" |
| 76 | } |
| 77 | timeout { fail "up from marker1 (timeout)" } |
| 78 | } |
| 79 | } |
| 80 | -re "$gdb_prompt $" { fail "continue to marker1" } |
| 81 | timeout { fail "(timeout) continue to marker1" } |
| 82 | } |
| 83 | |
| 84 | |
| 85 | send_gdb "print foo_instance1\n" |
| 86 | gdb_expect { |
| 87 | -re ".\[0-9\]* = \{ifoo = 111, ccpfoo = 0x0\}\r\n$gdb_prompt $" { |
| 88 | pass "print foo_instance1" |
| 89 | } |
| 90 | -re ".*$gdb_prompt $" { fail "print foo_instance1" } |
| 91 | timeout { fail "(timeout) print foo_instance1" } |
| 92 | } |
| 93 | |
| 94 | |
| 95 | setup_xfail "hppa*-*-*" CLLbs16901 |
| 96 | send_gdb "ptype foo_instance1\n" |
| 97 | gdb_expect { |
| 98 | -re "type = class foo \{.*public:.*int ifoo;.*const char \\*ccpfoo;.*foo\\(int\\);.*foo\\(int, (const char|char const) \\*\\);.*foo\\(foo &\\);.*~foo\\(void\\);.*void foofunc\\(int\\);.*void foofunc\\(int, signed char \\*\\);.*int overload1arg\\(void\\);.*int overload1arg\\(char\\);.*int overload1arg\\(signed char\\);.*int overload1arg\\(unsigned char\\);.*int overload1arg\\(short\\);.*int overload1arg\\(unsigned short\\);.*int overload1arg\\(int\\);.*int overload1arg\\(unsigned int\\);.*int overload1arg\\(long\\);.*int overload1arg\\(unsigned long\\);.*int overload1arg\\(float\\);.*int overload1arg\\(double\\);.*int overloadargs\\(int\\);.*int overloadargs\\(int, int\\);.*int overloadargs\\(int, int, int\\);.*int overloadargs\\(int, int, int, int\\);.*int overloadargs\\(int, int, int, int, int\\);.*int overloadargs\\(int, int, int, int, int, int\\);.*int overloadargs\\(int, int, int, int, int, int, int\\);.*int overloadargs\\(int, int, int, int, int, int, int, int\\);.*int overloadargs\\(int, int, int, int, int, int, int, int, int\\);.*int overloadargs\\(int, int, int, int, int, int, int, int, int, int\\);.*int overloadargs\\(int, int, int, int, int, int, int, int, int, int, int\\);\r\n\}\r\n$gdb_prompt $" { |
| 99 | pass "ptype foo_instance1 (HP aCC -- known quirk with ~foo parameter list)" |
| 100 | } |
| 101 | -re "type = class foo .*int overloadargs\\(int, int, int, int, int, int, int, int, int, int, int\\);\r\n\}\r\n$gdb_prompt $" { |
| 102 | pass "ptype foo_instance1 (shorter match)" |
| 103 | } |
| 104 | -re ".*$gdb_prompt $" { fail "ptype foo_instance1" } |
| 105 | timeout { fail "(timeout) ptype foo_instance1" } |
| 106 | } |
| 107 | |
| 108 | send_gdb "print foo_instance2\n" |
| 109 | gdb_expect { |
| 110 | -re ".\[0-9\]* = \{ifoo = 222, ccpfoo = $hex \"A\"\}\r\n$gdb_prompt $" { |
| 111 | pass "print foo_instance2" |
| 112 | } |
| 113 | -re ".*$gdb_prompt $" { fail "print foo_instance2" } |
| 114 | timeout { fail "(timeout) print foo_instance2" } |
| 115 | } |
| 116 | |
| 117 | send_gdb "print foo_instance3\n" |
| 118 | gdb_expect { |
| 119 | -re ".\[0-9\]* = \{ifoo = 222, ccpfoo = $hex \"A\"\}\r\n$gdb_prompt $" { |
| 120 | pass "print foo_instance3" |
| 121 | } |
| 122 | -re ".*$gdb_prompt $" { fail "print foo_instance3" } |
| 123 | timeout { fail "(timeout) print foo_instance3" } |
| 124 | } |
| 125 | |
| 126 | |
| 127 | # The overload resolver added by HP (valops.c:find_overload_match) doesn't |
| 128 | # work right for G++ output, since the list of parameters seems not to |
| 129 | # be filled in correctly. Until this gets fixed, don't expect to pass |
| 130 | # these tests. |
| 131 | |
| 132 | setup_xfail "*-*-*" CLLbs16901 |
| 133 | send_gdb "print foo_instance1.overloadargs(1)\n" |
| 134 | gdb_expect { |
| 135 | -re ".\[0-9\]* = 1\r\n$gdb_prompt $" { |
| 136 | pass "print call overloaded func 1 arg" |
| 137 | } |
| 138 | -re ".*$gdb_prompt $" { fail "print call overloaded func 1 arg" } |
| 139 | timeout { fail "(timeout) print call overloaded func 1 arg" } |
| 140 | } |
| 141 | |
| 142 | |
| 143 | setup_xfail "*-*-*" CLLbs16901 |
| 144 | |
| 145 | send_gdb "print foo_instance1.overloadargs(1, 2)\n" |
| 146 | gdb_expect { |
| 147 | -re ".\[0-9\]* = 2\r\n$gdb_prompt $" { |
| 148 | pass "print call overloaded func 2 args" |
| 149 | } |
| 150 | -re ".*$gdb_prompt $" { fail "print call overloaded func 2 args" } |
| 151 | timeout { fail "(timeout) print call overloaded func 2 args" } |
| 152 | } |
| 153 | |
| 154 | |
| 155 | setup_xfail "*-*-*" CLLbs16901 |
| 156 | |
| 157 | send_gdb "print foo_instance1.overloadargs(1, 2, 3)\n" |
| 158 | gdb_expect { |
| 159 | -re ".\[0-9\]* = 3\r\n$gdb_prompt $" { |
| 160 | pass "print call overloaded func 3 args" |
| 161 | } |
| 162 | -re ".*$gdb_prompt $" { fail "print call overloaded func 3 args" } |
| 163 | timeout { fail "(timeout) print call overloaded func 3 args" } |
| 164 | } |
| 165 | |
| 166 | |
| 167 | setup_xfail "*-*-*" CLLbs16901 |
| 168 | |
| 169 | send_gdb "print foo_instance1.overloadargs(1, 2, 3, 4)\n" |
| 170 | gdb_expect { |
| 171 | -re ".\[0-9\]* = 4\r\n$gdb_prompt $" { |
| 172 | pass "print call overloaded func 4 args" |
| 173 | } |
| 174 | -re ".*$gdb_prompt $" { fail "print call overloaded func 4 args" } |
| 175 | timeout { fail "(timeout) print call overloaded func 4 args" } |
| 176 | } |
| 177 | |
| 178 | |
| 179 | setup_xfail "*-*-*" CLLbs16901 |
| 180 | |
| 181 | send_gdb "print foo_instance1.overloadargs(1, 2, 3, 4, 5)\n" |
| 182 | gdb_expect { |
| 183 | -re ".\[0-9\]* = 5\r\n$gdb_prompt $" { |
| 184 | pass "print call overloaded func 5 args" |
| 185 | } |
| 186 | -re ".*$gdb_prompt $" { fail "print call overloaded func 5 args" } |
| 187 | timeout { fail "(timeout) print call overloaded func 5 args" } |
| 188 | } |
| 189 | |
| 190 | |
| 191 | setup_xfail "*-*-*" CLLbs16901 |
| 192 | |
| 193 | send_gdb "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6)\n" |
| 194 | gdb_expect { |
| 195 | -re ".\[0-9\]* = 6\r\n$gdb_prompt $" { |
| 196 | pass "print call overloaded func 6 args" |
| 197 | } |
| 198 | -re ".*$gdb_prompt $" { fail "print call overloaded func 6 args" } |
| 199 | timeout { fail "(timeout) print call overloaded func 6 args" } |
| 200 | } |
| 201 | |
| 202 | |
| 203 | setup_xfail "*-*-*" CLLbs16901 |
| 204 | |
| 205 | send_gdb "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6, 7)\n" |
| 206 | gdb_expect { |
| 207 | -re ".\[0-9\]* = 7\r\n$gdb_prompt $" { |
| 208 | pass "print call overloaded func 7 args" |
| 209 | } |
| 210 | -re ".*$gdb_prompt $" { fail "print call overloaded func 7 args" } |
| 211 | timeout { fail "(timeout) print call overloaded func 7 args" } |
| 212 | } |
| 213 | |
| 214 | |
| 215 | setup_xfail "*-*-*" CLLbs16901 |
| 216 | |
| 217 | send_gdb "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6, 7, 8)\n" |
| 218 | gdb_expect { |
| 219 | -re ".\[0-9\]* = 8\r\n$gdb_prompt $" { |
| 220 | pass "print call overloaded func 8 args" |
| 221 | } |
| 222 | -re ".*$gdb_prompt $" { fail "print call overloaded func 8 args" } |
| 223 | timeout { fail "(timeout) print call overloaded func 8 args" } |
| 224 | } |
| 225 | |
| 226 | |
| 227 | setup_xfail "*-*-*" CLLbs16901 |
| 228 | |
| 229 | send_gdb "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6, 7, 8, 9)\n" |
| 230 | gdb_expect { |
| 231 | -re ".\[0-9\]* = 9\r\n$gdb_prompt $" { |
| 232 | pass "print call overloaded func 9 args" |
| 233 | } |
| 234 | -re ".*$gdb_prompt $" { fail "print call overloaded func 9 args" } |
| 235 | timeout { fail "(timeout) print call overloaded func 9 args" } |
| 236 | } |
| 237 | |
| 238 | |
| 239 | setup_xfail "*-*-*" CLLbs16901 |
| 240 | |
| 241 | send_gdb "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)\n" |
| 242 | gdb_expect { |
| 243 | -re ".\[0-9\]* = 10\r\n$gdb_prompt $" { |
| 244 | pass "print call overloaded func 10 args" |
| 245 | } |
| 246 | -re ".*$gdb_prompt $" { fail "print call overloaded func 10 args" } |
| 247 | timeout { fail "(timeout) print call overloaded func 10 args" } |
| 248 | } |
| 249 | |
| 250 | |
| 251 | setup_xfail "*-*-*" CLLbs16901 |
| 252 | |
| 253 | send_gdb "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)\n" |
| 254 | gdb_expect { |
| 255 | -re ".\[0-9\]* = 11\r\n$gdb_prompt $" { |
| 256 | pass "print call overloaded func 11 args" |
| 257 | } |
| 258 | -re ".*$gdb_prompt $" { fail "print call overloaded func 11 args" } |
| 259 | timeout { fail "(timeout) print call overloaded func 11 args" } |
| 260 | } |
| 261 | |
| 262 | |
| 263 | setup_xfail "*-*-*" CLLbs16901 |
| 264 | |
| 265 | send_gdb "print foo_instance1.overload1arg()\n" |
| 266 | gdb_expect { |
| 267 | -re ".\[0-9\]* = 1\r\n$gdb_prompt $" { |
| 268 | pass "print call overloaded func void arg" |
| 269 | } |
| 270 | -re ".*$gdb_prompt $" { fail "print call overloaded func void arg" } |
| 271 | timeout { fail "(timeout) print call overloaded func void arg" } |
| 272 | } |
| 273 | |
| 274 | |
| 275 | setup_xfail "*-*-*" CLLbs16901 |
| 276 | |
| 277 | send_gdb "print foo_instance1.overload1arg((char)arg2)\n" |
| 278 | gdb_expect { |
| 279 | -re ".\[0-9\]* = 2\r\n$gdb_prompt $" { |
| 280 | pass "print call overloaded func char arg" |
| 281 | } |
| 282 | -re ".*$gdb_prompt $" { fail "print call overloaded func char arg" } |
| 283 | timeout { fail "(timeout) print call overloaded func char arg" } |
| 284 | } |
| 285 | |
| 286 | |
| 287 | setup_xfail "*-*-*" CLLbs16901 |
| 288 | |
| 289 | send_gdb "print foo_instance1.overload1arg((signed char)arg3)\n" |
| 290 | gdb_expect { |
| 291 | -re ".\[0-9\]* = 3\r\n$gdb_prompt $" { |
| 292 | pass "print call overloaded func signed char arg" |
| 293 | } |
| 294 | -re ".*$gdb_prompt $" { fail "print call overloaded func signed char arg" } |
| 295 | timeout { fail "(timeout) print call overloaded func signed char arg" } |
| 296 | } |
| 297 | |
| 298 | |
| 299 | setup_xfail "*-*-*" CLLbs16901 |
| 300 | |
| 301 | send_gdb "print foo_instance1.overload1arg((unsigned char)arg4)\n" |
| 302 | gdb_expect { |
| 303 | -re ".\[0-9\]* = 4\r\n$gdb_prompt $" { |
| 304 | pass "print call overloaded func unsigned char arg" |
| 305 | } |
| 306 | -re ".*$gdb_prompt $" { fail "print call overloaded func unsigned char arg" } |
| 307 | timeout { fail "(timeout) print call overloaded func unsigned char arg" } |
| 308 | } |
| 309 | |
| 310 | |
| 311 | setup_xfail "*-*-*" CLLbs16901 |
| 312 | |
| 313 | send_gdb "print foo_instance1.overload1arg((short)arg5)\n" |
| 314 | gdb_expect { |
| 315 | -re ".\[0-9\]* = 5\r\n$gdb_prompt $" { |
| 316 | pass "print call overloaded func short arg" |
| 317 | } |
| 318 | -re ".*$gdb_prompt $" { fail "print call overloaded func short arg" } |
| 319 | timeout { fail "(timeout) print call overloaded func short arg" } |
| 320 | } |
| 321 | |
| 322 | |
| 323 | setup_xfail "*-*-*" CLLbs16901 |
| 324 | |
| 325 | send_gdb "print foo_instance1.overload1arg((unsigned short)arg6)\n" |
| 326 | gdb_expect { |
| 327 | -re ".\[0-9\]* = 6\r\n$gdb_prompt $" { |
| 328 | pass "print call overloaded func unsigned short arg" |
| 329 | } |
| 330 | -re ".*$gdb_prompt $" { fail "print call overloaded func unsigned short arg" } |
| 331 | timeout { fail "(timeout) print call overloaded func unsigned short arg" } |
| 332 | } |
| 333 | |
| 334 | |
| 335 | setup_xfail "*-*-*" CLLbs16901 |
| 336 | |
| 337 | send_gdb "print foo_instance1.overload1arg((int)arg7)\n" |
| 338 | gdb_expect { |
| 339 | -re ".\[0-9\]* = 7\r\n$gdb_prompt $" { |
| 340 | pass "print call overloaded func int arg" |
| 341 | } |
| 342 | -re ".*$gdb_prompt $" { fail "print call overloaded func int arg" } |
| 343 | timeout { fail "(timeout) print call overloaded func int arg" } |
| 344 | } |
| 345 | |
| 346 | |
| 347 | setup_xfail "*-*-*" CLLbs16901 |
| 348 | |
| 349 | send_gdb "print foo_instance1.overload1arg((unsigned int)arg8)\n" |
| 350 | gdb_expect { |
| 351 | -re ".\[0-9\]* = 8\r\n$gdb_prompt $" { |
| 352 | pass "print call overloaded func unsigned int arg" |
| 353 | } |
| 354 | -re ".*$gdb_prompt $" { fail "print call overloaded func unsigned int arg" } |
| 355 | timeout { fail "(timeout) print call overloaded func unsigned int arg" } |
| 356 | } |
| 357 | |
| 358 | |
| 359 | setup_xfail "*-*-*" CLLbs16901 |
| 360 | |
| 361 | send_gdb "print foo_instance1.overload1arg((long)arg9)\n" |
| 362 | gdb_expect { |
| 363 | -re ".\[0-9\]* = 9\r\n$gdb_prompt $" { |
| 364 | pass "print call overloaded func long arg" |
| 365 | } |
| 366 | -re ".*$gdb_prompt $" { fail "print call overloaded func long arg" } |
| 367 | timeout { fail "(timeout) print call overloaded func long arg" } |
| 368 | } |
| 369 | |
| 370 | |
| 371 | setup_xfail "*-*-*" CLLbs16901 |
| 372 | |
| 373 | send_gdb "print foo_instance1.overload1arg((unsigned long)arg10)\n" |
| 374 | gdb_expect { |
| 375 | -re ".\[0-9\]* = 10\r\n$gdb_prompt $" { |
| 376 | pass "print call overloaded func unsigned long arg" |
| 377 | } |
| 378 | -re ".*$gdb_prompt $" { fail "print call overloaded func unsigned long arg" } |
| 379 | timeout { fail "(timeout) print call overloaded func unsigned long arg" } |
| 380 | } |
| 381 | |
| 382 | |
| 383 | setup_xfail "*-*-*" CLLbs16901 |
| 384 | |
| 385 | send_gdb "print foo_instance1.overload1arg((float)arg11)\n" |
| 386 | gdb_expect { |
| 387 | -re ".\[0-9\]* = 11\r\n$gdb_prompt $" { |
| 388 | pass "print call overloaded func float arg" |
| 389 | } |
| 390 | -re ".*$gdb_prompt $" { fail "print call overloaded func float arg" } |
| 391 | timeout { fail "(timeout) print call overloaded func float arg" } |
| 392 | } |
| 393 | |
| 394 | |
| 395 | setup_xfail "*-*-*" CLLbs16901 |
| 396 | |
| 397 | send_gdb "print foo_instance1.overload1arg((double)arg12)\n" |
| 398 | gdb_expect { |
| 399 | -re ".\[0-9\]* = 12\r\n$gdb_prompt $" { |
| 400 | pass "print call overloaded func double arg" |
| 401 | } |
| 402 | -re ".*$gdb_prompt $" { fail "print call overloaded func double arg" } |
| 403 | timeout { fail "(timeout) print call overloaded func double arg" } |
| 404 | } |
| 405 | |
| 406 | # Now some tests to see if we can list overloaded functions properly: |
| 407 | |
| 408 | send_gdb "set listsize 1\n" |
| 409 | gdb_expect -re ".*$gdb_prompt $" |
| 410 | |
| 411 | gdb_test "list foo::overloadfnarg(void)"\ |
| 412 | ".*int foo::overloadfnarg.*\\(void\\).*" \ |
| 413 | "print overloaded function with no args" |
| 414 | |
| 415 | gdb_test "list foo::overloadfnarg(int)"\ |
| 416 | "int foo::overloadfnarg.*\\(int arg\\).*" \ |
| 417 | "print overloaded function with int arg" |
| 418 | |
| 419 | gdb_test "list foo::overloadfnarg(int, int (*)(int))" \ |
| 420 | "int foo::overloadfnarg.*\\(int arg, int \\(\\*foo\\) \\(int\\)\\).*" \ |
| 421 | "print overloaded function with function ptr args" |
| 422 | |
| 423 | # This one crashes GDB. Don't know why yet. |
| 424 | gdb_test "list \"foo::overloadfnarg(int, int (*)(int))\"" \ |
| 425 | "int foo::overloadfnarg.*\\(int arg, int \\(\\*foo\\) \\(int\\)\\).*" \ |
| 426 | "print overloaded function with function ptr args - quotes around argument" |