1 # Copyright
1992-2024 Free Software Foundation
, Inc.
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
3 of the License
, or
6 #
(at your option
) any later version.
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.
13 # You should have received a copy of the GNU General Public License
14 # along with this
program.
If not
, see
<http
://www.gnu.org
/licenses
/>.
16 # This file was written by Fred Fish.
(fnf@cygnus.com
)
20 require allow_cplus_tests
24 set flags
[list debug c
++]
25 lappend flags additional_flags
=-std
=c
++11
27 if { [test_compiler_info gcc
-*] && [gcc_major_version
] >= 10 } {
28 # Work around PR gcc
/101452.
29 lappend flags additional_flags
=-DGCC_BUG
32 if {[prepare_for_testing
"failed to prepare" $testfile $srcfile $flags]} {
37 # Test printing of the types of templates.
40 proc test_ptype_of_templates
{} {
44 gdb_test_multiple
"ptype/r T5<int>" "ptype T5<int>" {
45 -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 $" {
46 xfail
"ptype T5<int> -- new without size_t"
48 -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 $" {
49 xfail
"ptype T5<int> -- new without size_t"
51 -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 $" {
52 xfail
"ptype T5<int> -- new with unsigned int"
54 -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 $" {
55 xfail
"ptype T5<int> -- new with unsigned long"
57 -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 $" {
58 xfail
"ptype T5<int> (obsolescent gcc or gdb)"
60 -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 $" {
61 # This also triggers gdb
/1113...
62 kfail
"gdb/1111" "ptype T5<int>"
63 # Add here a PASS case when PR gdb
/1111 gets fixed.
65 # http
://sourceware.org
/bugzilla
/show_bug.cgi?id
=8216
66 # http
://sourceware.org
/bugzilla
/show_bug.cgi?id
=8218
68 -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 $" {
69 # http
://sourceware.org
/bugzilla
/show_bug.cgi?id
=8218
70 # The destructor has an
argument type.
71 kfail
"gdb/8218" "ptype T5<int>"
73 -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\\((size_t|unsigned( int| long|))\\);${ws}static void operator delete\\(void ?\\*\\);${ws}int value\\((void|)\\);${ws}\}\r\n$gdb_prompt $" {
78 gdb_test_multiple
"ptype/r t5i" "ptype t5i" {
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\\(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 $" {
80 xfail
"ptype T5<int> -- with several fixes from 4.17 -- without size_t"
82 -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 $" {
83 xfail
"ptype t5i<int> -- new with unsigned int -- without size_t"
85 -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 $" {
86 xfail
"ptype t5i<int> -- new with unsigned long -- without size_t"
88 -re
"type = class T5<int> \{.*public:.*static int X;.*int x;.*int val;.*.*T5 \\(int\\);.*.*void ~T5 \\(\\).*.*.*int value \\((void|)\\);.*\}.*$gdb_prompt $" {
89 xfail
"ptype t5i -- without size_t"
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|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 $" {
92 xfail
"ptype t5i -- without size_t"
94 -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 $" {
95 xfail
"ptype t5i -- without size_t"
97 -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 $" {
98 xfail
"ptype t5i (obsolescent gcc or gdb) -- without size_t"
100 -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 $" {
101 # This also triggers gdb
/1113...
102 kfail
"gdb/1111" "ptype t5i"
103 # Add here a PASS case when PR gdb
/1111 gets fixed.
105 # http
://sourceware.org
/bugzilla
/show_bug.cgi?id
=8216
106 # http
://sourceware.org
/bugzilla
/show_bug.cgi?id
=8218
108 -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 $" {
109 # http
://sourceware.org
/bugzilla
/show_bug.cgi?id
=8218
110 # The destructor has an
argument type.
111 kfail
"gdb/8218" "ptype t5i"
113 -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\\((size_t|unsigned( int| long|))\\);${ws}static void operator delete\\(void ?\\*\\);${ws}int value\\((void|)\\);${ws}\}\r\n$gdb_prompt $" {
120 # Test breakpoint setting
on template methods.
123 proc test_template_breakpoints
{} {
128 gdb_test_multiple
"break T5<int>::T5" "constructor breakpoint" {
129 -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\]*> $" {
132 "constructor breakpoint"
134 -re
"0. cancel.*\[\r\n\]*.1. all.*\[\r\n\]*.2. T5 at .*\[\r\n\]*.3. T5 at .*\[\r\n\]*> $" {
135 setup_kfail
"gdb/1062" "*-*-*"
137 "nonsense intended to insure that this test fails" \
138 "constructor breakpoint"
142 "nonsense intended to insure that this test fails" \
143 "constructor breakpoint (bad menu choices)"
147 gdb_test_multiple
"break T5<int>::~T5" "destructor_breakpoint" {
148 -re
"Breakpoint.*at.* file .*${testfile}.cc, line.*$gdb_prompt $"
150 pass
"destructor breakpoint"
152 -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 $"
154 kfail
"gdb/1112" "destructor breakpoint"
158 gdb_test
"break T5<int>::value" \
159 "Breakpoint.*at.* file .*${testfile}.cc, line.*" \
160 "value method breakpoint"
162 set bp_location
[gdb_get_line_number \
163 "set breakpoint on a line with no real code"]
165 gdb_test_multiple
"break ${testfile}.cc:${bp_location}" \
166 "breakpoint on a line with no real code" {
167 -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\]*> $" {
170 "breakpoint on a line with no real code"
172 -re
"0. cancel.*\[\r\n\]*.1. all.*\[\r\n\]*.2.*\[\r\n\]*.3.*\[\r\n\]*> $" {
174 "nonsense intended to insure that this test fails" \
175 "breakpoint on a line with no real code"
179 "nonsense intended to insure that this test fails" \
180 "breakpoint on a line with no real code"
188 # Test calling of template methods.
191 proc test_template_calls
{} {
194 if [target_info
exists gdb
,cannot_call_functions
] {
195 unsupported
"this target can not call functions"
199 setup_xfail hppa
*-*-*
200 gdb_test_multiple
"print t5i.value()" "print t5i.value()" {
201 -re
".* = 2\[\r\n\]*$gdb_prompt $" {
202 pass
"print t5i.value()"
204 -re
"Cannot invoke functions on this machine.*$gdb_prompt $" {
205 fail
"print t5i.value()"
207 -re
"Cannot resolve .* to any overloaded instance.*$gdb_prompt $" {
208 setup_xfail hppa
*-*-* CLLbs16899
209 xfail
"print t5i.value"
214 proc test_template_typedef
{} {
217 gdb_test
"print intBazOne::baz" ".*baz\\(int, int\\)>" \
218 "print method of template typedef"
220 set test
"print destructor of template typedef"
221 gdb_test_multiple
"print intBazOne::~Baz" $test {
222 -re
"~Baz(\\(\\))?>\r\n$gdb_prompt $" {
225 -re
"There is no field named ~Baz\r\n$gdb_prompt $" {
226 set test2
"verify GCC PR debug/51668"
227 gdb_test_multiple
"whatis intBazOne" $test2 {
228 -re
"type = Baz<int, \\(char\\)'\\\\001'>\r\n$gdb_prompt $" {
229 setup_xfail gcc
/51668 "*-*-*"
233 -re
"\r\n$gdb_prompt $" {
234 # Some unexpected response.
243 proc test_template_args
{} {
245 set empty_re
"Empty *<void *\\(FunctionArg *<int>\\)>"
246 gdb_test
"ptype/r empty" \
247 "type = (struct|class) $empty_re {.*<no data fields>.*}" \
250 gdb_test
"ptype/r arg" \
251 "type = (struct|class) FunctionArg<int> {.*int method\\($empty_re \\&\\);.*}" \
256 # Change multiple
-symbols to
"ask" in order to get the multiple-choice
257 # menu when breaking
on overloaded methods.
258 gdb_test_no_output
"set multiple-symbols ask"
262 test_ptype_of_templates
263 test_template_breakpoints
264 test_template_typedef
275 # More tests
for different kinds of template parameters
,
276 # templates with partial specializations
, nested templates
, etc.
278 gdb_breakpoint
[gdb_get_line_number
"Final breakpoint"]
279 gdb_continue_to_breakpoint
"Final breakpoint"
281 gdb_test
"print fint" \
282 "\\$\[0-9\]* = \\{x = 0, t = 0\\}"
284 # Prevent symbol
on address
0x0 being printed.
285 gdb_test_no_output
"set print symbol off"
286 gdb_test
"print fvpchar" \
287 "\\$\[0-9\]* = \\{x = 0, t = 0x0\\}"
291 # Neither stabs nor DWARF
-2 contains type information about templates
292 #
(as opposed to instantiations of templates
), so in those
293 # circumstances we expect GDB to not find a symbol. HP has a debug
294 # format that contains more
info, though
, so it
's also correct to
295 # print out template info. (This affects several subsequent tests as
298 # NOTE: carlton/2003-02-26: However, because of a bug in the way GDB
299 # handles nested types, we don't
get this right in the DWARF
-2 case.
301 gdb_test_multiple
"ptype/r Foo" "ptype Foo" {
302 -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 $" {
305 -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 $" {
308 -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 $" {
309 # GCC
3.1, DWARF
-2 output.
310 kfail
"gdb/57" "ptype Foo"
312 -re
"No symbol \"Foo\" in current context.\r\n$gdb_prompt $" {
313 # GCC
2.95.3, stabs
+ output.
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 $"
322 gdb_test_multiple
"ptype/r fint" "ptype fint" {
323 -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 $" {
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 $" {
333 gdb_test_multiple
"ptype/r fchar" "ptype fchar" {
334 -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 $" {
337 -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 $" {
342 # ptype Foo
<volatile char
*>
344 gdb_test_multiple
"ptype/r fvpchar" "ptype fvpchar" {
345 -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 $" {
348 -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 $" {
351 -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 $" {
352 kfail
"gdb/1512" "ptype fvpchar"
356 # print a function from Foo
<volatile char
*>
358 # This test is sensitive to whitespace matching
, so we
'll do it twice,
359 # varying the spacing, because of PR gdb/33.
361 gdb_test_multiple "print Foo<volatile char *>::foo" "print Foo<volatile char *>::foo" {
362 -re "\\$\[0-9\]* = \\{.*char \\*\\((class |)Foo<(volatile char|char volatile) ?\\*> \\*(| const), int, .*char \\*\\)\\} $hex <Foo<.*char.*\\*>::foo\\(int, .*char.*\\*\\)>\r\n$gdb_prompt $" {
363 pass "print Foo<volatile char *>::foo"
365 -re "No symbol \"Foo<volatile char \\*>\" in current context.\r\n$gdb_prompt $" {
366 # This used to be a kfail gdb/33 and then kfail gdb/931.
367 fail "print Foo<volatile char *>::foo"
371 gdb_test_multiple "print Foo<volatile char*>::foo" "print Foo<volatile char*>::foo" {
372 -re "\\$\[0-9\]* = \\{.*char \\*\\((class |)Foo<(volatile char|char volatile) ?\\*> \\*(| const), int, .*char \\*\\)\\} $hex <Foo<.*char.*\\*>::foo\\(int, .*char.*\\*\\)>\r\n$gdb_prompt $" {
373 pass "print Foo<volatile char*>::foo"
375 -re "No symbol \"Foo<volatile char\\*>\" in current context.\r\n$gdb_prompt $" {
376 # This used to be a kfail gdb/33 and then kfail gdb/931.
377 fail "print Foo<volatile char*>::foo"
381 # Template Bar<T, int>
383 # same as Foo for g++
384 gdb_test_multiple "ptype/r Bar" "ptype Bar" {
385 -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 $" {
388 -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 $" {
391 -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 $" {
392 # GCC 3.1, DWARF-2 output.
393 kfail "gdb/57" "ptype Bar"
395 -re "No symbol \"Bar\" in current context.\r\n$gdb_prompt $" {
396 # GCC 2.95.3, stabs+ output.
404 gdb_test_multiple "ptype/r bint" "ptype bint" {
405 -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 $" {
408 -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 $" {
413 # ptype Bar<int, (4>3)>
415 gdb_test_multiple "ptype/r bint2" "ptype bint2" {
416 -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 $" {
419 -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 $" {
424 # Template Baz<T, char>
426 # Same as Foo, for g++
427 gdb_test_multiple "ptype/r Baz" "ptype Baz" {
428 -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 $" {
431 -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 $" {
434 -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 $" {
435 # GCC 3.1, DWARF-2 output.
436 kfail "gdb/57" "ptype Baz"
438 -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 $" {
439 # GCC 3.x, DWARF-2 output, running into gdb/57 and gdb/1512.
440 kfail "gdb/57" "ptype Baz"
442 -re "No symbol \"Baz\" in current context.\r\n$gdb_prompt $" {
443 # GCC 2.95.3, stabs+ output.
449 # ptype Baz<int, 's
'>
451 gdb_test_multiple "ptype/r bazint" "ptype bazint" {
452 -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 $" {
455 -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 $" {
460 # ptype Baz<char, 'a
'>
462 gdb_test_multiple "ptype/r bazint2" "ptype bazint2" {
463 -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 $" {
466 -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 $" {
471 # Template Qux<T, int (*f)(int) >
472 # Same as Foo for g++
473 gdb_test_multiple "ptype/r Qux" "ptype Qux" {
474 -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 $" {
477 -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 $" {
480 -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 $" {
481 # GCC 3.1, DWARF-2 output.
482 kfail "gdb/57" "ptype Qux"
484 -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 $" {
485 # GCC 3.x, DWARF-2 output; gdb/57 + gdb/1512.
486 kfail "gdb/57" "ptype Qux"
488 -re "No symbol \"Qux\" in current context.\r\n$gdb_prompt $" {
489 # GCC 2.95.3, stabs+ output.
494 # pt Qux<int,&string>
496 gdb_test_multiple "ptype/r quxint" "ptype quxint" {
497 -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 $" {
500 -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 $" {
503 -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 $" {
506 -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 $" {
509 -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 $" {
510 kfail "gdb/1512" "ptype quxint"
515 # Template Spec<T1, T2>
517 # Same as Foo for g++
518 gdb_test_multiple "ptype/r Spec" "ptype Spec" {
519 -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 $" {
522 -re "type = <(class |)T1, (class |)T2> (class |)Spec \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\\}\r\n$gdb_prompt $" {
525 -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 $" {
526 # GCC 3.1, DWARF-2 output.
527 kfail "gdb/57" "ptype Spec"
529 -re "No symbol \"Spec\" in current context.\r\n$gdb_prompt $" {
530 # GCC 2.95.3, stabs+ output.
537 gdb_test_multiple "ptype/r siip" "ptype siip" {
538 -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 $" {
541 -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 $" {
546 # Check cv qualifiers and substitute parameters.
548 if {[test_compiler_info {clang-*}]} {
549 setup_kfail "llvm/52262 " "*-*-*"
551 gdb_test "ptype cfoo" [multi_line \
552 "type = (class |)Cfoo<double> \\\[with DataT = double\\\] \\{" \
554 "\[ \t\]*DataT me0;" \
555 "\[ \t\]*const DataT me1;" \
556 "\[ \t\]*const myfloat me2;" \
557 "\[ \t\]*const int me3;" \
560 "\[ \t\]*typedef float myfloat;" \
562 ] "print type of cfoo"
564 # Check cv qualifiers and do not substitute.
566 if {[test_compiler_info {clang-*}]} {
567 setup_kfail "llvm/52262 " "*-*-*"
569 gdb_test "ptype/r cfoo" [multi_line \
570 "type = (class |)Cfoo<double> \\{" \
572 "\[ \t\]*double me0;" \
573 "\[ \t\]*const double me1;" \
574 "\[ \t\]*const Cfoo<double>::myfloat me2;" \
575 "\[ \t\]*const int me3;" \
578 "\[ \t\]*typedef float myfloat;" \
580 ] "print raw type of cfoo"
584 gdb_test_multiple "ptype/r Garply<int>" "ptype Garply<int>" {
585 -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 $" {
586 pass "ptype Garply<int>"
588 -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 $" {
589 pass "ptype Garply<int>"
593 # ptype of nested template name
595 gdb_test_multiple "ptype/r Garply<Garply<char> >" "ptype Garply<Garply<char> >" {
596 -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 $" {
597 pass "ptype Garply<Garply<char> >"
599 -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 $" {
600 pass "ptype Garply<Garply<char> >"
604 # print out a function from a nested template name
606 gdb_test "print Garply<Garply<char> >::garply" \
607 "\\$\[0-9\]* = \\{(class |)Garply<char> \\((class |)Garply<Garply<char> > \\*(| const), int, (class |)Garply<char>\\)\\} $hex <Garply<Garply<char>\[ \t\]*>::garply\\(int, (class |)Garply<char>\\)>"
610 # Now should work fine
611 gdb_test "break Garply<Garply<char> >::garply" \
612 "Breakpoint \[0-9\]* at $hex: file .*templates.cc, line.*"
615 # Template wild-matching tests
618 # Turn off "ask" when multiple symbols are seen.
619 gdb_test_no_output "set multiple-symbols all"
621 # Test setting breakpoints in a method of all class template instantiations,
622 # including overloads.
623 gdb_test "break Foo::foo" "Breakpoint.*at.* \\(3 locations\\)"
624 foreach t [list "int" "char" "volatile char *"] {
625 gdb_breakpoint "Foo<$t>::foo (int, $t)"
626 gdb_breakpoint "Foo::foo (int, $t)"
629 gdb_test "break Bar::bar" "Breakpoint.*at.* \\(2 locations\\)"
630 gdb_test "break Bar::bar (int, int)" "Breakpoint.*at.* \\(2 locations\\)"
631 foreach val [list 1 33] {
632 gdb_breakpoint "Bar<int, $val>::bar (int, int)"
635 # Test setting breakpoints in a member function template of a class template,
636 # including overloads.
637 gdb_test "break Foozle::fogey" "Breakpoint.*at.* \\(9 locations\\)" \
638 "break at template method fogey"
639 foreach t [list "int" "char" "Empty<int>"] {
640 gdb_test "break Foozle::fogey ($t)" "Breakpoint.*at.* \\(3 locations\\)"
641 gdb_test "break Foozle::fogey<$t>" "Breakpoint.*at.* \\(3 locations\\)"
642 foreach u [list "int" "char" "Empty<int>"] {
643 gdb_breakpoint "Foozle<$t>::fogey<$u>" message
644 gdb_assert { [gdb_breakpoint "Foozle<$t>::fogey<$u> ($u)" no-message] } \
645 "break Foozle<$t>::fogey<$u> ($u), success"
649 # Test templated operators < and <<. Restrict results to only the test
652 # 1. operator< (const T2&, const T2&)
653 # 2. operator< (const T2&, char)
654 # 3. operator< <Empty<int>>
655 # 4. operator< <Foozle<in>>
658 # 1. operator<< <Empty<int>>
659 # 2. operator<< <Foozle<int>>
660 gdb_test "break -source $srcfile -func operator<" \
661 "Breakpoint.*at.* \\(4 locations\\)"
662 gdb_test "break -source $srcfile -func operator<<" \
663 "Breakpoint.*at.* \\(2 locations\\)"
664 foreach t [list "Empty" "Foozle"] {
666 gdb_breakpoint "operator< <$tt>" message
667 gdb_breakpoint "operator<< <$tt>" message
669 # Try a specific instance, both with and without whitespace
670 # after the template-template parameter.
671 set loc "operator< <$tt> ($tt&, $tt&)"
672 gdb_assert { [gdb_breakpoint $loc no-message] } "break $loc, success"
673 set loc "operator< <$tt > ($tt&, $tt&)"
674 gdb_assert { [gdb_breakpoint $loc no-message] } "break $loc, success"
675 set loc "operator<< <$tt> ($tt&, $tt&)"
676 gdb_assert { [gdb_breakpoint $loc no-message] } "break $loc, success"
677 set loc "operator<< <$tt > ($tt&, $tt&)"
678 gdb_assert { [gdb_breakpoint $loc no-message] } "break $loc, success"
681 # Test that "-qualified" finds no matching locations.
682 gdb_test_no_output "set breakpoint pending off"
683 gdb_test "break -qualified Foozle::fogey" \
684 "Function \"Foozle::fogey\" not defined."