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