2011-12-23 Tristan Gingold <gingold@adacore.com>
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.cp / templates.exp
CommitLineData
9b254dd1 1# Copyright 1992, 1994, 1995, 1996, 1997, 1999, 2000, 2002, 2003, 2004, 2007,
7b6bb8da 2# 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
c906108c
SS
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
e22f8b7c 6# the Free Software Foundation; either version 3 of the License, or
c906108c 7# (at your option) any later version.
e22f8b7c 8#
c906108c
SS
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.
e22f8b7c 13#
c906108c 14# You should have received a copy of the GNU General Public License
e22f8b7c 15# along with this program. If not, see <http://www.gnu.org/licenses/>.
c906108c 16
c906108c
SS
17# This file was written by Fred Fish. (fnf@cygnus.com)
18
19set ws "\[\r\n\t \]+"
20
21if $tracelevel then {
22 strace $tracelevel
23}
24
d4f3574e
SS
25if { [skip_cplus_tests] } { continue }
26
c906108c
SS
27set testfile "templates"
28set srcfile ${testfile}.cc
29set binfile ${objdir}/${subdir}/${testfile}
30
31# Create and source the file that provides information about the compiler
32# used to compile the test case.
33if [get_compiler_info ${binfile} "c++"] {
34 return -1
35}
c906108c 36
c906108c 37if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
b60f0898
JB
38 untested templates.exp
39 return -1
c906108c
SS
40}
41
c906108c
SS
42#
43# Test printing of the types of templates.
44#
45
46proc test_ptype_of_templates {} {
47 global gdb_prompt
48 global ws
49
f8d3bf8f 50 gdb_test_multiple "ptype T5<int>" "ptype T5<int>" {
1bc05c3a 51 -re "type = class T5<int> \{${ws}public:${ws}static int X;${ws}int x;${ws}int val;${ws}T5<int> & operator=\\(T5<int> const ?&\\);${ws}T5\\(int\\);${ws}T5\\((T5<int> const|const T5<int>) ?&\\);${ws}~T5\\((void|)\\);${ws}static void \\* operator new\\(unsigned( int| long)?\\);${ws}static void operator delete\\(void ?\\*\\);${ws}int value\\((void|)\\);${ws}\}\r\n$gdb_prompt $" {
c906108c
SS
52 pass "ptype T5<int>"
53 }
3b0cb202
MC
54 -re "type = class T5<int> \{${ws}public:${ws}static int X;${ws}int x;${ws}int val;${ws}T5\\(int\\);${ws}T5\\((T5<int> const|const T5<int>) ?&\\);${ws}~T5\\((void|)\\);${ws}static void \\* operator new\\(unsigned( int| long)?\\);${ws}static void operator delete\\(void ?\\*\\);${ws}int value\\((void|)\\);${ws}T5<int> & operator=\\(T5<int> const ?&\\);${ws}\}\r\n$gdb_prompt $" {
55 pass "ptype T5<int>"
56 }
f8d3bf8f
MS
57 -re "type = class T5<int> \\{${ws}public:${ws}static int X;${ws}int x;${ws}int val;${ws}${ws}T5 \\(int\\);${ws}T5 \\(const class T5<int> &\\);${ws}void ~T5 \\(int\\);${ws}static void \\* new \\(unsigned int\\);${ws}static void delete \\(void ?\\*\\);${ws}int value \\((void|)\\);${ws}\\}${ws}$gdb_prompt $" {
58 pass "ptype T5<int> -- new with unsigned int"
59 }
60 -re "type = class T5<int> \\{.*public:.*static int X;.*int x;.*int val;.*T5 \\(int\\);.*T5 \\(const class T5<int> &\\);.*void ~T5 \\(int\\);.*static void \\* new \\(unsigned long\\);.*static void delete \\(void ?\\*\\);.*int value \\((void|)\\);.*\\}\r\n$gdb_prompt $" {
61 pass "ptype T5<int> -- new with unsigned long"
62 }
1bc05c3a 63 -re "type = class T5<int> \{${ws}public:${ws}static int X;${ws}int x;${ws}int val;((${ws}T5<int> & operator=\\(T5<int> const ?&\\);)|(${ws}T5\\(int\\);)|(${ws}T5\\((T5<int> const|const T5<int>) ?&\\);)|(${ws}~T5\\((void|)\\);)|(${ws}static void \\* operator new\\(unsigned( int| long)?\\);)|(${ws}static void operator delete\\(void ?\\*\\);)|(${ws}int value\\((void|)\\);))*${ws}\}\r\n$gdb_prompt $" {
c906108c
SS
64 pass "ptype T5<int> (obsolescent gcc or gdb)"
65 }
3c00b570 66 -re "type = class T5<int> \{${ws}public:${ws}static int X;${ws}int x;${ws}int val;${ws}void T5\\(int\\);${ws}void T5\\((T5<int> const|const T5<int>) ?&\\);${ws}~T5\\(int\\);${ws}static void \\* operator new\\(unsigned( int| long|)\\);${ws}static void operator delete\\(void ?\\*\\);${ws}int value\\((void|)\\);${ws}\}\r\n$gdb_prompt $" {
5330f2db
DC
67 # This also triggers gdb/1113...
68 kfail "gdb/1111" "ptype T5<int>"
69 }
c906108c
SS
70 }
71
f8d3bf8f
MS
72 gdb_test_multiple "ptype t5i" "ptype t5i" {
73 -re "type = class T5<int> \\{${ws}public:${ws}static int X;${ws}int x;${ws}int val;\r\n${ws}T5\\(int\\);${ws}T5\\(T5<int> const ?&\\);${ws}~T5\\((void|)\\);${ws}static void \\* operator new\\(unsigned( int| long)?\\);${ws}static void operator delete\\(void ?\\*\\);${ws}int value\\((void|)\\);${ws}\\}\r\n$gdb_prompt $" {
74 pass "ptype T5<int> -- with several fixes from 4.17"
75 }
76 -re "type = class T5<int> \\{${ws}public:${ws}static int X;${ws}int x;${ws}int val;\r\n${ws}T5 \\(int\\);${ws}T5 \\(const class T5<int> &\\);${ws}void ~T5 \\(int\\);${ws}static void \\* new \\(unsigned int\\);${ws}static void delete \\(void ?\\*\\);${ws}int value \\((void|)\\);${ws}\\}\r\n$gdb_prompt $" {
77 pass "ptype t5i<int> -- new with unsigned int"
78 }
79 -re "type = class T5<int> \\{${ws}public:${ws}static int X;${ws}int x;${ws}int val;\r\n${ws}T5 \\(int\\);${ws}T5 \\(const class T5<int> &\\);${ws}void ~T5 \\(int\\);${ws}static void \\* new \\(unsigned long\\);${ws}static void delete \\(void ?\\*\\);${ws}int value \\((void|)\\);${ws}\\}\r\n$gdb_prompt $" {
80 pass "ptype t5i<int> -- new with unsigned long"
81 }
eef747c0 82 -re "type = class T5<int> \{.*public:.*static int X;.*int x;.*int val;.*.*T5 \\(int\\);.*.*void ~T5 \\(int\\).*.*.*int value \\((void|)\\);.*\}.*$gdb_prompt $" {
a0b3c4fd
JM
83 pass "ptype t5i"
84 }
1bc05c3a 85 -re "type = class T5<int> \{${ws}public:${ws}static int X;${ws}int x;${ws}int val;${ws}T5<int> & operator=\\(T5<int> const ?&\\);${ws}T5\\(int\\);${ws}T5\\((T5<int> const|const T5<int>) ?&\\);${ws}~T5\\((void|)\\);${ws}static void \\* operator new\\(unsigned( int| long)?\\);${ws}static void operator delete\\(void ?\\*\\);${ws}int value\\((void|)\\);${ws}\}\r\n$gdb_prompt $" {
c906108c
SS
86 pass "ptype t5i"
87 }
3b0cb202
MC
88 -re "type = class T5<int> \{${ws}public:${ws}static int X;${ws}int x;${ws}int val;${ws}T5\\(int\\);${ws}T5\\((T5<int> const|const T5<int>) ?&\\);${ws}~T5\\((void|)\\);${ws}static void \\* operator new\\(unsigned( int| long)?\\);${ws}static void operator delete\\(void ?\\*\\);${ws}int value\\((void|)\\);${ws}T5<int> & operator=\\(T5<int> const ?&\\);${ws}\}\r\n$gdb_prompt $" {
89 pass "ptype t5i"
90 }
3b2a7ae5 91 -re "type = class T5<int> \{${ws}public:${ws}static int X;${ws}int x;${ws}int val;((${ws}T5<int> & operator=\\(T5<int> const ?&\\);)|(${ws}T5\\(int\\);)|(${ws}T5\\(T5<int> const ?&\\);)|(${ws}~T5\\((void|)\\);)|(${ws}static void \\* operator new\\(unsigned( int| long)?\\);)|(${ws}static void operator delete\\(void ?\\*\\);)|(${ws}int value\\((void|)\\);))*${ws}\}\r\n$gdb_prompt $" {
c906108c
SS
92 pass "ptype t5i (obsolescent gcc or gdb)"
93 }
3c00b570 94 -re "type = class T5<int> \{${ws}public:${ws}static int X;${ws}int x;${ws}int val;${ws}void T5\\(int\\);${ws}void T5\\((T5<int> const|const T5<int>) ?&\\);${ws}~T5\\(int\\);${ws}static void \\* operator new\\(unsigned( int| long|)\\);${ws}static void operator delete\\(void ?\\*\\);${ws}int value\\((void|)\\);${ws}\}\r\n$gdb_prompt $" {
5330f2db
DC
95 # This also triggers gdb/1113...
96 kfail "gdb/1111" "ptype T5<int>"
97 }
c906108c
SS
98 }
99}
100
101#
102# Test breakpoint setting on template methods.
103#
104
105proc test_template_breakpoints {} {
106 global gdb_prompt
107 global testfile
108 global srcdir
a0b3c4fd 109 global hp_aCC_compiler
c906108c 110
b598bfda 111 gdb_test_multiple "break T5<int>::T5" "constructor breakpoint" {
f8eba3c6 112 -re "0. cancel.*\[\r\n\]*.1. all.*\[\r\n\]*.2.*templates.cc:T5<int>::T5\\((T5<int> const|const T5<int>) ?&\\)\[\r\n\]*.3.*templates.cc:T5<int>::T5\\(int\\)\[\r\n\]*> $" {
c906108c 113 gdb_test "0" \
a9e2e984 114 "canceled" \
c906108c
SS
115 "constructor breakpoint"
116 }
5330f2db
DC
117 -re "0. cancel.*\[\r\n\]*.1. all.*\[\r\n\]*.2. T5 at .*\[\r\n\]*.3. T5 at .*\[\r\n\]*> $" {
118 setup_kfail "gdb/1062" "*-*-*"
119 gdb_test "0" \
120 "nonsense intended to insure that this test fails" \
121 "constructor breakpoint"
122 }
760f6330
MS
123 -re ".*\n> $" {
124 gdb_test "0" \
125 "nonsense intended to insure that this test fails" \
126 "constructor breakpoint (bad menu choices)"
127 }
c906108c
SS
128 }
129
a0b3c4fd
JM
130# See CLLbs14792
131 if {$hp_aCC_compiler} {setup_xfail hppa*-*-* CLLbs14792}
5330f2db
DC
132
133 gdb_test_multiple "break T5<int>::~T5" "destructor_breakpoint" {
134 -re "Breakpoint.*at.* file .*${testfile}.cc, line.*$gdb_prompt $"
135 {
136 pass "destructor breakpoint"
137 }
138 -re "the class `T5<int>' does not have destructor defined\r\nHint: try 'T5<int>::~T5<TAB> or 'T5<int>::~T5<ESC-\\?>\r\n\\(Note leading single quote.\\)\r\n$gdb_prompt $"
139 {
140 kfail "gdb/1112" "destructor breakpoint"
141 }
142 }
c906108c
SS
143
144 gdb_test "break T5<int>::value" \
145 "Breakpoint.*at.* file .*${testfile}.cc, line.*" \
146 "value method breakpoint"
147
945a118d
JG
148 set bp_location [gdb_get_line_number \
149 "set breakpoint on a line with no real code"]
f8eba3c6
TT
150
151 gdb_test_multiple "break ${testfile}.cc:${bp_location}" \
152 "breakpoint on a line with no real code" {
153 -re "0. cancel.*\[\r\n\]*.1. all.*\[\r\n\]*.2.*templates.cc:GetMax<int>\\(int, int\\)\[\r\n\]*.3.*templates.cc:GetMax<long>\\(long, long\\)\[\r\n\]*> $" {
154 gdb_test "0" \
155 "canceled" \
156 "breakpoint on a line with no real code"
157 }
158 -re "0. cancel.*\[\r\n\]*.1. all.*\[\r\n\]*.2.*\[\r\n\]*.3.*\[\r\n\]*> $" {
159 gdb_test "0" \
160 "nonsense intended to insure that this test fails" \
161 "breakpoint on a line with no real code"
162 }
163 -re ".*\n> $" {
164 gdb_test "0" \
165 "nonsense intended to insure that this test fails" \
166 "breakpoint on a line with no real code"
167 }
168 }
169
c906108c
SS
170 delete_breakpoints
171}
172
173#
174# Test calling of template methods.
175#
176
177proc test_template_calls {} {
178 global gdb_prompt
a0b3c4fd 179 global hp_aCC_compiler
c906108c
SS
180
181 if [target_info exists gdb,cannot_call_functions] {
182 setup_xfail "*-*-*" 2416
183 fail "This target can not call functions"
184 return
185 }
186
a0b3c4fd 187 if {!$hp_aCC_compiler} {setup_xfail hppa*-*-*}
f8d3bf8f
MS
188 gdb_test_multiple "print t5i.value()" "print t5i.value()" {
189 -re ".* = 2\[\r\n\]*$gdb_prompt $" {
190 pass "print t5i.value()"
191 }
c906108c
SS
192 -re "Cannot invoke functions on this machine.*$gdb_prompt $" {
193 fail "print t5i.value()"
194 }
a0b3c4fd
JM
195 -re "Cannot resolve .* to any overloaded instance.*$gdb_prompt $" {
196 setup_xfail hppa*-*-* CLLbs16899
197 xfail "print t5i.value"
198 }
c906108c
SS
199 }
200}
201
3fe8f3b3
KS
202proc test_template_typedef {} {
203
204 gdb_test "print intBazOne::baz" ".*baz\\(int, int\\)>" \
205 "print method of template typedef"
206
207 gdb_test "print intBazOne::~Baz" ".*~Baz(\\(\\))?>" \
208 "print destructor of template typedef"
209}
c906108c 210
c767944b
DJ
211proc test_template_args {} {
212
213 set empty_re "Empty *<void *\\(FunctionArg *<int>\\)>"
214 gdb_test "ptype empty" \
5e1617b1 215 "type = (struct|class) $empty_re {.*<no data fields>.*}"
c767944b
DJ
216
217 gdb_test "ptype arg" \
5e1617b1 218 "type = (struct|class) FunctionArg<int> {.*int method\\($empty_re \\&\\);.*}"
c767944b
DJ
219}
220
c906108c 221proc do_tests {} {
c906108c
SS
222 global subdir
223 global objdir
224 global srcdir
225 global binfile
226 global gdb_prompt
c906108c 227
c906108c
SS
228
229 # Start with a fresh gdb.
230
231 gdb_exit
232 gdb_start
233 gdb_reinitialize_dir $srcdir/$subdir
234 gdb_load $binfile
235
eae06beb
JB
236 # Change multiple-symbols to "ask" in order to get the multiple-choice
237 # menu when breaking on overloaded methods.
a8d52276 238 gdb_test_no_output "set multiple-symbols ask"
eae06beb 239
40f235b7 240 runto_main
c906108c
SS
241
242 test_ptype_of_templates
243 test_template_breakpoints
3fe8f3b3 244 test_template_typedef
c767944b 245 test_template_args
c906108c
SS
246
247 if [ runto_main] {
248 test_template_calls
249 }
250}
251
252do_tests
253
a0b3c4fd
JM
254
255# More tests for different kinds of template parameters,
256# templates with partial specializations, nested templates, etc.
257# These have been tested only with HP aCC. They probably won't
258# work with other compilers because of differences in mangling
259# schemes.
260# Added by Satish Pai <pai@apollo.hp.com> 1997-09-25
e6d71bf3
DB
261# As of 2000-06-03, C++ support has been improved to the point that g++ can
262# pass all of theses, excluding what appears to be one that exposes a stabs bug. - djb
a0b3c4fd 263
e6d71bf3
DB
264# I don't know how HP could be passing these tests without this. They
265# weren't breakpointing past a point where the below expressions were
266# initialized in the actual source. - djb
267
f8d3bf8f
MS
268gdb_test "b 770" \
269 "Breakpoint .* at .*, line 770."
a0b3c4fd 270
f8d3bf8f
MS
271gdb_test "c" \
272 "Continuing.*Breakpoint .*" \
273 "continue to line 770"
274
275gdb_test "print fint" \
276 "\\$\[0-9\]* = \\{x = 0, t = 0\\}"
277
278gdb_test "print fvpchar" \
279 "\\$\[0-9\]* = \\{x = 0, t = 0x0\\}"
a0b3c4fd
JM
280
281# Template Foo<T>
282
dd14ab43
DC
283# Neither stabs nor DWARF-2 contains type information about templates
284# (as opposed to instantiations of templates), so in those
285# circumstances we expect GDB to not find a symbol. HP has a debug
286# format that contains more info, though, so it's also correct to
287# print out template info. (This affects several subsequent tests as
288# well.)
289
290# NOTE: carlton/2003-02-26: However, because of a bug in the way GDB
291# handles nested types, we don't get this right in the DWARF-2 case.
292
f8d3bf8f
MS
293gdb_test_multiple "ptype Foo" "ptype Foo" {
294 -re "type = template <(class |)T> (class |)Foo \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*T t;\r\n\\}\r\ntemplate instantiations:\r\n\[ \t\]*(class |)Foo<volatile char \\*>\r\n\[ \t\]*(class |)Foo<char>\r\n\[ \t\]*(class |)Foo<int>\r\n$gdb_prompt $" {
295 pass "ptype Foo"
296 }
297 -re "type = template <(class |)T> (class |)Foo \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*T t;\r\n\\}\r\n$gdb_prompt $" {
298 xfail "ptype Foo"
299 }
300 -re "type = class Foo<int> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*int t;\r\n\r\n\[ \t\]*int foo\\(int, int\\);\r\n\\}\r\n$gdb_prompt $" {
301 # GCC 3.1, DWARF-2 output.
302 kfail "gdb/57" "ptype Foo"
303 }
304 -re "No symbol \"Foo\" in current context.\r\n$gdb_prompt $" {
305 # GCC 2.95.3, stabs+ output.
306 pass "ptype Foo"
307 }
a0b3c4fd 308}
f8d3bf8f 309
dd14ab43 310# -re "type = class Foo<int> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*int t;\r\n\r\n\[ \t\]*int foo(int, int);\r\n\\}\r\n$gdb_prompt $"
a0b3c4fd
JM
311
312# ptype Foo<int>
313
f8d3bf8f
MS
314gdb_test_multiple "ptype fint" "ptype fint" {
315 -re "type = (class |)Foo<int> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*int t;\r\n\r\n\[ \t\]*.*int foo\\(int, int\\);\r\n\\}\r\n$gdb_prompt $" {
316 pass "ptype fint"
317 }
318 -re "type = (class |)Foo<int> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*int t;\r\n\r\n\[ \t\]*int foo\\(int, int\\);.*\r\n\\}\r\n$gdb_prompt $" {
319 pass "ptype fint"
320 }
a0b3c4fd
JM
321}
322
323# ptype Foo<char>
324
f8d3bf8f
MS
325gdb_test_multiple "ptype fchar" "ptype fchar" {
326 -re "type = (class |)Foo<char> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*char t;\r\n\r\n\[ \t\]*.*char foo\\(int, char\\);\r\n\\}\r\n$gdb_prompt $" {
327 pass "ptype fchar"
328 }
329 -re "type = (class |)Foo<char> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*char t;\r\n\r\n\[ \t\]*char foo\\(int, char\\);.*\r\n\\}\r\n$gdb_prompt $" {
330 pass "ptype fchar"
331 }
a0b3c4fd
JM
332}
333
334# ptype Foo<volatile char *>
335
f8d3bf8f
MS
336gdb_test_multiple "ptype fvpchar" "ptype fvpchar" {
337 -re "type = (class |)Foo<volatile char ?\\*> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*.*char.*\\*t;\r\n\r\n\[ \t\]*.*char \\* foo\\(int,.*char.*\\*\\);\r\n\\}\r\n$gdb_prompt $" {
338 pass "ptype fvpchar"
339 }
340 -re "type = (class |)Foo<volatile char ?\\*> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*.*char.*\\*t;\r\n\r\n\[ \t\]*.*char \\* foo\\(int,.*char.*\\*\\);.*\r\n\\}\r\n$gdb_prompt $" {
341 pass "ptype fvpchar"
342 }
343 -re "type = (class |)Foo<char volatile ?\\*> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*.*char.*\\*t;\r\n\r\n\[ \t\]*.*char \\* foo\\(int,.*char.*\\*\\);\r\n\\}\r\n$gdb_prompt $" {
344 kfail "gdb/1512" "ptype fvpchar"
345 }
a0b3c4fd
JM
346}
347
348# print a function from Foo<volatile char *>
349
0b71dc91
DC
350# This test is sensitive to whitespace matching, so we'll do it twice,
351# varying the spacing, because of PR gdb/33.
352
f8d3bf8f
MS
353gdb_test_multiple "print Foo<volatile char *>::foo" "print Foo<volatile char *>::foo" {
354 -re "\\$\[0-9\]* = \\{.*char \\*\\((class |)Foo<(volatile char|char volatile) ?\\*> \\*(| const), int, .*char \\*\\)\\} $hex <Foo<.*char.*\\*>::foo\\(int, .*char.*\\*\\)>\r\n$gdb_prompt $" {
355 pass "print Foo<volatile char *>::foo"
356 }
357 -re "No symbol \"Foo<volatile char \\*>\" in current context.\r\n$gdb_prompt $" {
71c25dea
TT
358 # This used to be a kfail gdb/33 and then kfail gdb/931.
359 fail "print Foo<volatile char *>::foo"
85ca1584 360 }
0b71dc91
DC
361}
362
f8d3bf8f
MS
363gdb_test_multiple "print Foo<volatile char*>::foo" "print Foo<volatile char*>::foo" {
364 -re "\\$\[0-9\]* = \\{.*char \\*\\((class |)Foo<(volatile char|char volatile) ?\\*> \\*(| const), int, .*char \\*\\)\\} $hex <Foo<.*char.*\\*>::foo\\(int, .*char.*\\*\\)>\r\n$gdb_prompt $" {
365 pass "print Foo<volatile char*>::foo"
366 }
367 -re "No symbol \"Foo<volatile char\\*>\" in current context.\r\n$gdb_prompt $" {
71c25dea
TT
368 # This used to be a kfail gdb/33 and then kfail gdb/931.
369 fail "print Foo<volatile char*>::foo"
85ca1584 370 }
a0b3c4fd
JM
371}
372
373# Template Bar<T, int>
374
e6d71bf3 375# same as Foo for g++
f8d3bf8f
MS
376gdb_test_multiple "ptype Bar" "ptype Bar" {
377 -re "type = template <(class |)T, (class |)sz> (class |)Bar \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*T t;\r\n\\}\r\ntemplate instantiations:\r\n\[ \t\]*(class |)Bar<int,(\\(int\\)|)1>\r\n\[ \t\]*(class |)Bar<int,(\\(int\\)|)33>\r\n$gdb_prompt $" {
378 pass "ptype Bar"
379 }
380 -re "type = <(class |)T, (class |)sz> (class |)Bar \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*T t;\r\n\\}\r\n$gdb_prompt $" {
381 xfail "ptype Bar"
382 }
383 -re "ptype Bar\r\ntype = class Bar<int, ?33> {\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*int t;\r\n\r\n\[ \t\]*int bar\\(int, int\\);\r\n}\r\n$gdb_prompt $" {
384 # GCC 3.1, DWARF-2 output.
385 kfail "gdb/57" "ptype Bar"
386 }
387 -re "No symbol \"Bar\" in current context.\r\n$gdb_prompt $" {
388 # GCC 2.95.3, stabs+ output.
389 pass "ptype Bar"
390 }
a0b3c4fd
JM
391}
392
393
394# ptype Bar<int,33>
5a2a0a20 395
f8d3bf8f
MS
396gdb_test_multiple "ptype bint" "ptype bint" {
397 -re "type = (class |)Bar<int, ?(\\(int\\)|)33> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*int t;\r\n\r\n\[ \t\]*.*int bar\\(int, int\\);\r\n\\}\r\n$gdb_prompt $" {
398 pass "ptype bint"
399 }
400 -re "type = (class |)Bar<int,(\\(int\\)|)33> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*int t;\r\n\r\n\[ \t\]*int bar\\(int, int\\);.*\r\n\\}\r\n$gdb_prompt $" {
401 pass "ptype bint"
402 }
a0b3c4fd
JM
403}
404
405# ptype Bar<int, (4>3)>
406
f8d3bf8f
MS
407gdb_test_multiple "ptype bint2" "ptype bint2" {
408 -re "type = (class |)Bar<int, ?(\\(int\\)|)1> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*int t;\r\n\r\n\[ \t\]*.*int bar\\(int, int\\);\r\n\\}\r\n$gdb_prompt $" {
409 pass "ptype bint2"
410 }
411 -re "type = (class |)Bar<int,(\\(int\\)|)1> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*int t;\r\n\r\n\[ \t\]*int bar\\(int, int\\);.*\r\n\\}\r\n$gdb_prompt $" {
412 pass "ptype bint2"
413 }
a0b3c4fd
JM
414}
415
416# Template Baz<T, char>
417
e6d71bf3 418# Same as Foo, for g++
f8d3bf8f
MS
419gdb_test_multiple "ptype Baz" "ptype Baz" {
420 -re "type = template <(class |)T, ?(class |)sz> (class |)Baz \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*T t;\r\n\\}\r\ntemplate instantiations:\r\n\[ \t\]*(class |)Baz<char,(\\(char\\)|)97>\r\n\[ \t\]*(class |)Baz<int,(\\(char\\)|)115>\r\n$gdb_prompt $" {
421 pass "ptype Baz"
422 }
423 -re "type = <(class |)T, ?(class |)sz> (class |)Baz \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*T t;\r\n\\}\r\n$gdb_prompt $" {
424 xfail "ptype Baz"
425 }
426 -re "type = class Baz<int, ?'s'> {\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*int t;\r\n\r\n\[ \t\]*int baz\\(int, int\\);\r\n}\r\n$gdb_prompt $" {
427 # GCC 3.1, DWARF-2 output.
428 kfail "gdb/57" "ptype Baz"
429 }
430 -re "type = class Baz<int, ?(\\(char\\))?115> {\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*int t;\r\n\r\n\[ \t\]*int baz\\(int, int\\);\r\n}\r\n$gdb_prompt $" {
431 # GCC 3.x, DWARF-2 output, running into gdb/57 and gdb/1512.
432 kfail "gdb/57" "ptype Baz"
433 }
434 -re "No symbol \"Baz\" in current context.\r\n$gdb_prompt $" {
435 # GCC 2.95.3, stabs+ output.
436 pass "ptype Baz"
437 }
a0b3c4fd
JM
438}
439
440
441# ptype Baz<int, 's'>
442
f8d3bf8f
MS
443gdb_test_multiple "ptype bazint" "ptype bazint" {
444 -re "type = (class |)Baz<int, ?(\\(char\\)|)(115|\\'s\\')> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*int t;\r\n\r\n\[ \t\]*.*int baz\\(int, int\\);\r\n\\}\r\n$gdb_prompt $" {
445 pass "ptype bazint"
446 }
447 -re "type = (class |)Baz<int,(\\(char\\)|)(115|\\'s\\')> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*int t;\r\n\r\n\[ \t\]*int baz\\(int, int\\).*;\r\n\\}\r\n$gdb_prompt $" {
448 pass "ptype bazint"
449 }
a0b3c4fd
JM
450}
451
452# ptype Baz<char, 'a'>
453
f8d3bf8f
MS
454gdb_test_multiple "ptype bazint2" "ptype bazint2" {
455 -re "type = (class |)Baz<char, ?(\\(char\\)|)(97|\\'a\\')> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*char t;\r\n\r\n\[ \t\]*.*char baz\\(int, char\\);\r\n\\}\r\n$gdb_prompt $" {
456 pass "ptype bazint2"
457 }
458 -re "type = (class |)Baz<char,(\\(char\\)|)(97|\\'a\\')> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*char t;\r\n\r\n\[ \t\]*char baz\\(int, char\\);.*\r\n\\}\r\n$gdb_prompt $" {
459 pass "ptype bazint2"
460 }
a0b3c4fd
JM
461}
462
463# Template Qux<T, int (*f)(int) >
e6d71bf3 464# Same as Foo for g++
f8d3bf8f
MS
465gdb_test_multiple "ptype Qux" "ptype Qux" {
466 -re "type = template <(class |)T, ?(class |)sz> (class |)Qux \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*T t;\r\n\\}\r\ntemplate instantiations:\r\n\[ \t\]*(class |)Qux<int,&string>\r\n\[ \t\]*(class |)Qux<char,&string>\r\n$gdb_prompt $" {
467 pass "ptype Qux"
468 }
469 -re ".*type = template <(class |)T.*, ?(class |)sz> (class |)Qux \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*T t;\r\n\\}.*$gdb_prompt $" {
470 pass "ptype Qux"
471 }
472 -re "type = class Qux<char, ?&string> {\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*char t;\r\n\r\n\[ \t\]*char qux\\(int, char\\);\r\n}\r\n$gdb_prompt $" {
473 # GCC 3.1, DWARF-2 output.
474 kfail "gdb/57" "ptype Qux"
475 }
476 -re "type = class Qux<char, ?&\\(string\\)> {\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*char t;\r\n\r\n\[ \t\]*char qux\\(int, char\\);\r\n}\r\n$gdb_prompt $" {
477 # GCC 3.x, DWARF-2 output; gdb/57 + gdb/1512.
478 kfail "gdb/57" "ptype Qux"
479 }
480 -re "No symbol \"Qux\" in current context.\r\n$gdb_prompt $" {
481 # GCC 2.95.3, stabs+ output.
482 pass "ptype Qux"
483 }
a0b3c4fd
JM
484}
485
486# pt Qux<int,&string>
487
f8d3bf8f
MS
488gdb_test_multiple "ptype quxint" "ptype quxint" {
489 -re "type = class Qux<int, ?& ?string> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*int t;\r\n\r\n\[ \t\]*.*int qux\\(int, int\\);\r\n\\}\r\n$gdb_prompt $" {
490 pass "ptype quxint"
491 }
492 -re "type = class Qux<int, ?& ?string> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*int t;\r\n\r\n\[ \t\]*int qux\\(int, int\\);.*\r\n\\}\r\n$gdb_prompt $" {
493 pass "ptype quxint"
494 }
495 -re "type = class Qux<int, ?\\(char ?\\*\\)\\(& ?\\(?string\\)?\\)> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*int t;\r\n\r\n\[ \t\]*int qux\\(int, int\\);.*\r\n\\}\r\n$gdb_prompt $" {
496 pass "ptype quxint"
497 }
498 -re "type = class Qux<int, ?& ?\\(string\\)> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*int t;\r\n\r\n\[ \t\]*int qux\\(int, int\\);.*\r\n\\}\r\n$gdb_prompt $" {
499 kfail "gdb/1512" "ptype quxint"
500 }
a0b3c4fd
JM
501}
502
a0b3c4fd
JM
503
504# Template Spec<T1, T2>
505
e6d71bf3 506# Same as Foo for g++
f8d3bf8f
MS
507gdb_test_multiple "ptype Spec" "ptype Spec" {
508 -re "type = template <(class |)T1, (class |)T2> (class |)Spec \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\\}\r\ntemplate instantiations:\r\n\[ \t\]*(class |)Spec<int,int \\*>\r\n\[ \t\]*(class |)Spec<int,char>\r\n$gdb_prompt $" {
509 pass "ptype Spec"
510 }
511 -re "type = <(class |)T1, (class |)T2> (class |)Spec \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\\}\r\n$gdb_prompt $" {
512 xfail "ptype Spec"
513 }
514 -re "type = class Spec<int, ?char> {\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\r\n\[ \t\]*int spec\\(char\\);\r\n}\r\n$gdb_prompt $" {
515 # GCC 3.1, DWARF-2 output.
516 kfail "gdb/57" "ptype Spec"
517 }
518 -re "No symbol \"Spec\" in current context.\r\n$gdb_prompt $" {
519 # GCC 2.95.3, stabs+ output.
520 pass "ptype Spec"
521 }
a0b3c4fd
JM
522}
523
524# pt Spec<char,0>
525
f8d3bf8f
MS
526gdb_test_multiple "ptype siip" "ptype siip" {
527 -re "type = class Spec<int, ?int ?\\*> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\r\n\[ \t\]*.*int spec\\(int ?\\*\\);\r\n\\}\r\n$gdb_prompt $" {
528 pass "ptype siip"
529 }
530 -re "type = class Spec<int,int ?\\*> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\r\n\[ \t\]*int spec\\(int ?\\*\\);.*\r\n\\}\r\n$gdb_prompt $" {
531 pass "ptype siip"
532 }
a0b3c4fd
JM
533}
534
535# pt Garply<int>
536
f8d3bf8f
MS
537gdb_test_multiple "ptype Garply<int>" "ptype Garply<int>" {
538 -re "type = class Garply<int> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*int t;\r\n\r\n\[ \t\]*.*int garply\\(int, int\\);\r\n\\}\r\n$gdb_prompt $" {
539 pass "ptype Garply<int>"
540 }
541 -re "type = class Garply<int> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*int t;\r\n\r\n\[ \t\]*int garply\\(int, int\\);.*\r\n\\}\r\n$gdb_prompt $" {
542 pass "ptype Garply<int>"
543 }
a0b3c4fd
JM
544}
545
546# ptype of nested template name
547
f8d3bf8f
MS
548gdb_test_multiple "ptype Garply<Garply<char> >" "ptype Garply<Garply<char> >" {
549 -re "type = (class |)Garply<Garply<char> > \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*.*(class |)Garply<char> t;\r\n\r\n\[ \t\]*.*(class |)Garply<char> garply\\(int, (class |)Garply<char>\\);\r\n\\}\r\n$gdb_prompt $" {
550 pass "ptype Garply<Garply<char> >"
551 }
552 -re "type = (class |)Garply<Garply<char> > \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*.*(class |)Garply<char> t;\r\n\r\n\[ \t\]*(class |)Garply<char> garply\\(int, (class |)Garply<char>\\);.*\r\n\\}\r\n$gdb_prompt $" {
553 pass "ptype Garply<Garply<char> >"
554 }
a0b3c4fd
JM
555}
556
557# print out a function from a nested template name
558
f8d3bf8f
MS
559gdb_test "print Garply<Garply<char> >::garply" \
560 "\\$\[0-9\]* = \\{(class |)Garply<char> \\((class |)Garply<Garply<char> > \\*(| const), int, (class |)Garply<char>\\)\\} $hex <Garply<Garply<char>\[ \t\]*>::garply\\(int, (class |)Garply<char>\\)>" \
561 "print Garply<Garply<char> >::garply"
a0b3c4fd 562
e6d71bf3
DB
563# djb - 06-03-2000
564# Now should work fine
b598bfda
DJ
565gdb_test "break Garply<Garply<char> >::garply" \
566 "Breakpoint \[0-9\]* at $hex: file .*templates.cc, line.*"
This page took 1.205743 seconds and 4 git commands to generate.