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