aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.c++/overload.exp
blob: e889273d7b445d5f29ee93e0e374a14dcf795a4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
# Copyright (C) 1998, 1999 Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  

# Please email any bugs, comments, and/or additions to this file to:
# bug-gdb@prep.ai.mit.edu

# written by Elena Zannoni (ezannoni@cygnus.com)

# This file is part of the gdb testsuite
#
# tests for overloaded member functions. Command Line calls
#


if $tracelevel then {
        strace $tracelevel
        }

#
# test running programs
#
set prms_id 0
set bug_id 0

if { [skip_cplus_tests] } { continue }

set testfile "overload"
set srcfile ${testfile}.cc
set binfile ${objdir}/${subdir}/${testfile}

if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
     gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
}

if [get_compiler_info ${binfile} "c++"] {
    return -1
}

gdb_exit
gdb_start
gdb_reinitialize_dir $srcdir/$subdir
gdb_load ${binfile}

# set it up at a breakpoint so we can play with the variable values
#
if ![runto_main] then {
    perror "couldn't run to breakpoint"
    continue
}

send_gdb "break marker1\n" ; gdb_expect -re ".*$gdb_prompt $"

    send_gdb "cont\n"
    gdb_expect {
        -re "Break.* marker1 \\(\\) at .*:$decimal.*$gdb_prompt $" {
            send_gdb "up\n"
            gdb_expect {
                -re ".*$gdb_prompt $" {}
                timeout { fail "up from marker1" }
            }
        }
        -re "$gdb_prompt $" { fail "continue to marker1"  }
        timeout { fail "(timeout) continue to marker1"  }
    }


send_gdb "print foo_instance1\n"
gdb_expect {
    -re ".\[0-9\]* = \{ifoo = 111, ccpfoo = 0x0\}\r\n$gdb_prompt $" {
        pass "print foo_instance1"
      }
    -re ".*$gdb_prompt $" { fail "print foo_instance1" }
    timeout           { fail "(timeout) print foo_instance1" }
  }


setup_xfail "hppa*-*-*" CLLbs16901
send_gdb "ptype foo_instance1\n"
gdb_expect {
  -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 $" {
        pass "ptype foo_instance1 (HP aCC -- known quirk with ~foo parameter list)"
      }
    -re "type = class foo .*int overloadargs\\(int, int, int, int, int, int, int, int, int, int, int\\);\r\n\}\r\n$gdb_prompt $" {
	pass "ptype foo_instance1 (shorter match)"
    }
    -re ".*$gdb_prompt $" { fail "ptype foo_instance1" }
    timeout           { fail "(timeout) ptype foo_instance1" }
  }

send_gdb "print foo_instance2\n"
gdb_expect {
    -re ".\[0-9\]* = \{ifoo = 222, ccpfoo = $hex \"A\"\}\r\n$gdb_prompt $" {
        pass "print foo_instance2"
      }
    -re ".*$gdb_prompt $" { fail "print foo_instance2" }
    timeout           { fail "(timeout) print foo_instance2" }
  }

send_gdb "print foo_instance3\n"
gdb_expect {
    -re ".\[0-9\]* = \{ifoo = 222, ccpfoo = $hex \"A\"\}\r\n$gdb_prompt $" {
        pass "print foo_instance3"
      }
    -re ".*$gdb_prompt $" { fail "print foo_instance3" }
    timeout           { fail "(timeout) print foo_instance3" }
  }


# The overload resolver added by HP (valops.c:find_overload_match) doesn't
# work right for G++ output, since the list of parameters seems not to
# be filled in correctly.  Until this gets fixed, don't expect to pass
# these tests.

setup_xfail "*-*-*" CLLbs16901
send_gdb "print foo_instance1.overloadargs(1)\n"
gdb_expect {
    -re ".\[0-9\]* = 1\r\n$gdb_prompt $" {
        pass "print call overloaded func 1 arg"
      }
    -re ".*$gdb_prompt $" { fail "print call overloaded func 1 arg" }
    timeout           { fail "(timeout) print call overloaded func 1 arg" }
  }


setup_xfail "*-*-*" CLLbs16901

send_gdb "print foo_instance1.overloadargs(1, 2)\n"
gdb_expect {
    -re ".\[0-9\]* = 2\r\n$gdb_prompt $" {
        pass "print call overloaded func 2 args"
      }
    -re ".*$gdb_prompt $" { fail "print call overloaded func 2 args" }
    timeout           { fail "(timeout) print call overloaded func 2  args" }
  }


setup_xfail "*-*-*" CLLbs16901

send_gdb "print foo_instance1.overloadargs(1, 2, 3)\n"
gdb_expect {
    -re ".\[0-9\]* = 3\r\n$gdb_prompt $" {
        pass "print call overloaded func 3 args"
      }
    -re ".*$gdb_prompt $" { fail "print call overloaded func 3 args" }
    timeout           { fail "(timeout) print call overloaded func 3 args" }
  }


setup_xfail "*-*-*" CLLbs16901

send_gdb "print foo_instance1.overloadargs(1, 2, 3, 4)\n"
gdb_expect {
    -re ".\[0-9\]* = 4\r\n$gdb_prompt $" {
        pass "print call overloaded func 4 args"
      }
    -re ".*$gdb_prompt $" { fail "print call overloaded func 4 args" }
    timeout           { fail "(timeout) print call overloaded func 4 args" }
  }


setup_xfail "*-*-*" CLLbs16901

send_gdb "print foo_instance1.overloadargs(1, 2, 3, 4, 5)\n"
gdb_expect {
    -re ".\[0-9\]* = 5\r\n$gdb_prompt $" {
        pass "print call overloaded func 5 args"
      }
    -re ".*$gdb_prompt $" { fail "print call overloaded func 5 args" }
    timeout           { fail "(timeout) print call overloaded func 5 args" }
  }


setup_xfail "*-*-*" CLLbs16901

send_gdb "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6)\n"
gdb_expect {
    -re ".\[0-9\]* = 6\r\n$gdb_prompt $" {
        pass "print call overloaded func 6 args"
      }
    -re ".*$gdb_prompt $" { fail "print call overloaded func 6 args" }
    timeout           { fail "(timeout) print call overloaded func 6 args" }
  }


setup_xfail "*-*-*" CLLbs16901

send_gdb "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6, 7)\n"
gdb_expect {
    -re ".\[0-9\]* = 7\r\n$gdb_prompt $" {
        pass "print call overloaded func 7 args"
      }
    -re ".*$gdb_prompt $" { fail "print call overloaded func 7 args" }
    timeout           { fail "(timeout) print call overloaded func 7 args" }
  }


setup_xfail "*-*-*" CLLbs16901

send_gdb "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6, 7, 8)\n"
gdb_expect {
    -re ".\[0-9\]* = 8\r\n$gdb_prompt $" {
        pass "print call overloaded func 8 args"
      }
    -re ".*$gdb_prompt $" { fail "print call overloaded func 8 args" }
    timeout           { fail "(timeout) print call overloaded func 8 args" }
  }


setup_xfail "*-*-*" CLLbs16901

send_gdb "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6, 7, 8, 9)\n"
gdb_expect {
    -re ".\[0-9\]* = 9\r\n$gdb_prompt $" {
        pass "print call overloaded func 9 args"
      }
    -re ".*$gdb_prompt $" { fail "print call overloaded func 9 args" }
    timeout           { fail "(timeout) print call overloaded func 9 args" }
  }


setup_xfail "*-*-*" CLLbs16901

send_gdb "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)\n"
gdb_expect {
    -re ".\[0-9\]* = 10\r\n$gdb_prompt $" {
        pass "print call overloaded func 10 args"
      }
    -re ".*$gdb_prompt $" { fail "print call overloaded func 10 args" }
    timeout           { fail "(timeout) print call overloaded func 10 args" }
  }


setup_xfail "*-*-*" CLLbs16901

send_gdb "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)\n"
gdb_expect {
    -re ".\[0-9\]* = 11\r\n$gdb_prompt $" {
        pass "print call overloaded func 11 args"
      }
    -re ".*$gdb_prompt $" { fail "print call overloaded func 11 args" }
    timeout           { fail "(timeout) print call overloaded func 11 args" }
  }


setup_xfail "*-*-*" CLLbs16901

send_gdb "print foo_instance1.overload1arg()\n"
gdb_expect {
    -re ".\[0-9\]* = 1\r\n$gdb_prompt $" {
        pass "print call overloaded func void arg"
      }
    -re ".*$gdb_prompt $" { fail "print call overloaded func void arg" }
    timeout           { fail "(timeout) print call overloaded func void arg" }
  }


setup_xfail "*-*-*" CLLbs16901

send_gdb "print foo_instance1.overload1arg((char)arg2)\n"
gdb_expect {
    -re ".\[0-9\]* = 2\r\n$gdb_prompt $" {
        pass "print call overloaded func char arg"
      }
    -re ".*$gdb_prompt $" { fail "print call overloaded func char arg" }
    timeout           { fail "(timeout) print call overloaded func char arg" }
  }


setup_xfail "*-*-*" CLLbs16901

send_gdb "print foo_instance1.overload1arg((signed char)arg3)\n"
gdb_expect {
    -re ".\[0-9\]* = 3\r\n$gdb_prompt $" {
        pass "print call overloaded func signed char arg"
      }
    -re ".*$gdb_prompt $" { fail "print call overloaded func signed char arg" }
    timeout           { fail "(timeout) print call overloaded func signed char arg" }
  }


setup_xfail "*-*-*" CLLbs16901

send_gdb "print foo_instance1.overload1arg((unsigned char)arg4)\n"
gdb_expect {
    -re ".\[0-9\]* = 4\r\n$gdb_prompt $" {
        pass "print call overloaded func unsigned char arg"
      }
    -re ".*$gdb_prompt $" { fail "print call overloaded func unsigned char arg" }
    timeout           { fail "(timeout) print call overloaded func unsigned char arg" }
  }


setup_xfail "*-*-*" CLLbs16901

send_gdb "print foo_instance1.overload1arg((short)arg5)\n"
gdb_expect {
    -re ".\[0-9\]* = 5\r\n$gdb_prompt $" {
        pass "print call overloaded func short arg"
      }
    -re ".*$gdb_prompt $" { fail "print call overloaded func short arg" }
    timeout           { fail "(timeout) print call overloaded func short arg" }
  }


setup_xfail "*-*-*" CLLbs16901

send_gdb "print foo_instance1.overload1arg((unsigned short)arg6)\n"
gdb_expect {
    -re ".\[0-9\]* = 6\r\n$gdb_prompt $" {
        pass "print call overloaded func unsigned short arg"
      }
    -re ".*$gdb_prompt $" { fail "print call overloaded func unsigned short  arg" }
    timeout           { fail "(timeout) print call overloaded func unsigned short arg" }
  }


setup_xfail "*-*-*" CLLbs16901

send_gdb "print foo_instance1.overload1arg((int)arg7)\n"
gdb_expect {
    -re ".\[0-9\]* = 7\r\n$gdb_prompt $" {
        pass "print call overloaded func int arg"
      }
    -re ".*$gdb_prompt $" { fail "print call overloaded func int arg" }
    timeout           { fail "(timeout) print call overloaded func int arg" }
  }


setup_xfail "*-*-*" CLLbs16901

send_gdb "print foo_instance1.overload1arg((unsigned int)arg8)\n"
gdb_expect {
    -re ".\[0-9\]* = 8\r\n$gdb_prompt $" {
        pass "print call overloaded func unsigned int arg"
      }
    -re ".*$gdb_prompt $" { fail "print call overloaded func unsigned int arg" }
    timeout           { fail "(timeout) print call overloaded func unsigned int arg" }
  }


setup_xfail "*-*-*" CLLbs16901

send_gdb "print foo_instance1.overload1arg((long)arg9)\n"
gdb_expect {
    -re ".\[0-9\]* = 9\r\n$gdb_prompt $" {
        pass "print call overloaded func long arg"
      }
    -re ".*$gdb_prompt $" { fail "print call overloaded func long arg" }
    timeout           { fail "(timeout) print call overloaded func long arg" }
  }


setup_xfail "*-*-*" CLLbs16901

send_gdb "print foo_instance1.overload1arg((unsigned long)arg10)\n"
gdb_expect {
    -re ".\[0-9\]* = 10\r\n$gdb_prompt $" {
        pass "print call overloaded func unsigned long arg"
      }
    -re ".*$gdb_prompt $" { fail "print call overloaded func unsigned long arg" }
    timeout           { fail "(timeout) print call overloaded func unsigned long arg" }
  }


setup_xfail "*-*-*" CLLbs16901

send_gdb "print foo_instance1.overload1arg((float)arg11)\n"
gdb_expect {
    -re ".\[0-9\]* = 11\r\n$gdb_prompt $" {
        pass "print call overloaded func float arg"
      }
    -re ".*$gdb_prompt $" { fail "print call overloaded func float arg" }
    timeout           { fail "(timeout) print call overloaded func float arg" }
  }


setup_xfail "*-*-*" CLLbs16901

send_gdb "print foo_instance1.overload1arg((double)arg12)\n"
gdb_expect {
    -re ".\[0-9\]* = 12\r\n$gdb_prompt $" {
        pass "print call overloaded func double arg"
      }
    -re ".*$gdb_prompt $" { fail "print call overloaded func double arg" }
    timeout           { fail "(timeout) print call overloaded func double arg" }
  }

# Now some tests to see if we can list overloaded functions properly:

send_gdb "set listsize 1\n"
gdb_expect -re ".*$gdb_prompt $"

gdb_test "list foo::overloadfnarg(void)"\
   ".*int foo::overloadfnarg.*\\(void\\).*" \
   "print overloaded function with no args"

gdb_test "list foo::overloadfnarg(int)"\
    "int foo::overloadfnarg.*\\(int arg\\).*" \
   "print overloaded function with int arg"

gdb_test "list foo::overloadfnarg(int, int (*)(int))" \
   "int foo::overloadfnarg.*\\(int arg, int \\(\\*foo\\) \\(int\\)\\).*" \
   "print overloaded function with function ptr args"

# This one crashes GDB.  Don't know why yet.
gdb_test "list \"foo::overloadfnarg(int, int (*)(int))\"" \
   "int foo::overloadfnarg.*\\(int arg, int \\(\\*foo\\) \\(int\\)\\).*" \
   "print overloaded function with function ptr args - quotes around argument"