1 # Copyright (C) 1992, 1996, 1997 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 2 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, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
22 # More tests for different kinds of template parameters,
23 # templates with partial specializations, nested templates, etc.
24 # These have been tested only with HP aCC. They probably won't
25 # work with other compilers because of differences in mangling
27 # Added by Satish Pai <pai@apollo.hp.com> 1997-09-25
36 set testfile "templ-hp"
37 set srcfile ${testfile}.cc
38 set binfile ${objdir}/${subdir}/${testfile}
42 # Create and source the file that provides information about the compiler
43 # used to compile the test case.
45 if [get_compiler_info ${binfile} "c++"] {
49 if {[skip_hp_tests $gcc_compiled]} then { continue }
52 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
53 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
58 # Test printing of the types of templates.
61 proc test_ptype_of_templates {} {
64 send_gdb "ptype T5<int>\n"
66 -re "type = class T5<int> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*static int X;\r\n\[ \t\]*int x;\r\n\[ \t\]*int val;\r\n\r\n\[ \t\]*T5\\(int\\);\r\n\[ \t\]*T5\\(class T5<int> const &\\);\r\n\[ \t\]*void ~T5\\(int\\);\r\n\[ \t\]*static void \\* new\\(unsigned int\\);\r\n\[ \t\]*static void delete\\(void \\*\\);\r\n\[ \t\]*int value\\(void\\);\r\n\[ \t\]*\\}\r\n$gdb_prompt $" { pass "ptype T5<int>" }
67 -re ".*$gdb_prompt $" { fail "ptype T5<int>" }
68 timeout { fail "ptype T5<int> (timeout)" }
71 send_gdb "ptype t5i\n"
73 -re "type = class T5<int> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*static int X;\r\n\[ \t\]*int x;\r\n\[ \t\]*int val;\r\n\r\n\[ \t\]*T5\\(int\\);\r\n\[ \t\]*T5\\(class T5<int> const &\\);\r\n\[ \t\]*void ~T5\\(int\\);\r\n\[ \t\]*static void \\* new\\(unsigned int\\);\r\n\[ \t\]*static void delete\\(void \\*\\);\r\n\[ \t\]*int value\\(void\\);\r\n\[ \t\]*\\}\r\n$gdb_prompt $" { pass "ptype t5i<int> 1" }
74 -re "type = class T5<int> \{.*public:.*static int X;.*int x;.*int val;.*.*T5 \\(int\\);.*.*void ~T5 \\(int\\).*.*.*int value \\(void\\);.*\}.*$gdb_prompt $" {
77 -re ".*$gdb_prompt $" { fail "ptype t5i" }
78 timeout { fail "ptype t5i (timeout)" }
83 # Test breakpoint setting on template methods.
86 proc test_template_breakpoints {} {
91 send_gdb "break T5<int>::T5\n"
93 -re "0. cancel.*\r\n.1. all.*\r\n.2. *.*\r\n.3. *.*\r\n> $" {
96 "constructor breakpoint"
98 -re ".0. cancel\r\n.1. all\r\n.2. T5<int>::T5\\(T5<int> const &\\) at .*/templates.cc:.*\r\n.3. T5<int>::T5\\(int\\) at .*/templates-hp.cc:.*\r\n> $" {
101 "constructor breakpoint"
103 -re ".*$gdb_prompt $" { fail "constructor breakpoint" }
104 default { fail "constructor breakpoint (timeout)" }
107 gdb_test "break T5<int>::~T5" \
108 "Breakpoint.*at.* file .*${testfile}.cc, line.*" \
109 "destructor breakpoint"
111 gdb_test "break T5<int>::value" \
112 "Breakpoint.*at.* file .*${testfile}.cc, line.*" \
113 "value method breakpoint"
119 # Test calling of template methods.
122 proc test_template_calls {} {
125 send_gdb "print t5i.value()\n"
127 -re ".* = 2\r\n$gdb_prompt $" { pass "print t5i.value()" }
128 -re "Cannot invoke functions on this machine.*$gdb_prompt $" {
129 fail "print t5i.value()"
131 -re ".*$gdb_prompt $" { fail "print t5i.value()" }
132 timeout { fail "print t5i.value() (timeout)" }
145 global supports_template_debugging
150 # Start with a fresh gdb.
154 gdb_reinitialize_dir $srcdir/$subdir
159 if { !$supports_template_debugging } {
160 warning "compiler lacks debugging info for templates; tests suppressed." 0
164 test_ptype_of_templates
165 test_template_breakpoints
177 gdb_reinitialize_dir $srcdir/$subdir
180 # set it up at a breakpoint so we can play with the variable values
182 if ![runto_main] then {
183 perror "couldn't run to breakpoint"
187 send_gdb "print fint\n"
189 -re "\\$\[0-9\]* = \\{x = 0, t = 0\\}\r\n$gdb_prompt $" { pass "print fint" }
190 -re "$gdb_prompt $" { fail "print fint" }
191 timeout { fail "(timeout) print fint" }
194 send_gdb "print fvpchar\n"
196 -re "\\$\[0-9\]* = \\{x = 0, t = 0x0\\}\r\n$gdb_prompt $" { pass "print fvpchar" }
197 -re "$gdb_prompt $" { fail "print fvpchar" }
198 timeout { fail "(timeout) print fvpchar" }
203 send_gdb "ptype Foo\n"
205 -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 $" { pass "ptype Foo" }
206 -re "$gdb_prompt $" { fail "ptype Foo" }
207 timeout { fail "(timeout) ptype Foo" }
212 send_gdb "ptype fint\n"
214 -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 $" { pass "ptype fint" }
215 -re "$gdb_prompt $" { fail "ptype fint" }
216 timeout { fail "(timeout) ptype fint" }
221 send_gdb "ptype fchar\n"
223 -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 $" { pass "ptype fchar" }
224 -re "$gdb_prompt $" { fail "ptype fchar" }
225 timeout { fail "(timeout) ptype fchar" }
228 # ptype Foo<volatile char *>
230 send_gdb "ptype fvpchar\n"
232 -re "type = (class |)Foo<volatile char \\*> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*volatile char \\*t;\r\n\r\n\[ \t\]*volatile char \\* foo\\(int, volatile char \\*\\);\r\n\\}\r\n$gdb_prompt $" { pass "ptype fvpchar" }
233 -re "$gdb_prompt $" { fail "ptype fvpchar" }
234 timeout { fail "(timeout) ptype fvpchar" }
237 # print a function from Foo<volatile char *>
239 send_gdb "print Foo<volatile char *>::foo\n"
241 -re "\\$\[0-9\]* = \\{volatile char \\*\\((class |)Foo<volatile char \\*> \\*, int, volatile char \\*\\)\\} $hex <Foo<volatile char \\*>::foo\\(int, volatile char \\*\\)>\r\n$gdb_prompt $" { pass "print Foo<volatile char *>::foo" }
242 -re "$gdb_prompt $" { fail "print Foo<volatile char *>::foo" }
243 timeout { fail "(timeout) print Foo<volatile char *>::foo" }
246 # Template Bar<T, int>
248 send_gdb "ptype Bar\n"
250 -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,1>\r\n\[ \t\]*(class |)Bar<int,33>\r\n$gdb_prompt $" { pass "ptype Bar" }
251 -re "$gdb_prompt $" { fail "ptype Bar" }
252 timeout { fail "(timeout) ptype Bar" }
258 send_gdb "ptype bint\n"
260 -re "type = (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 $" { pass "ptype bint" }
261 -re "$gdb_prompt $" { fail "ptype bint" }
262 timeout { fail "(timeout) ptype bint" }
265 # ptype Bar<int, (4>3)>
267 send_gdb "ptype bint2\n"
269 -re "type = (class |)Bar<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 $" { pass "ptype bint2" }
270 -re "$gdb_prompt $" { fail "ptype bint2" }
271 timeout { fail "(timeout) ptype bint2" }
274 # Template Baz<T, char>
276 send_gdb "ptype Baz\n"
278 -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,97>\r\n\[ \t\]*(class |)Baz<int,115>\r\n$gdb_prompt $" { pass "ptype Baz" }
279 -re "$gdb_prompt $" { fail "ptype Baz" }
280 timeout { fail "(timeout) ptype Baz" }
284 # ptype Baz<int, 's'>
286 send_gdb "ptype bazint\n"
288 -re "type = (class |)Baz<int,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 $" { pass "ptype bazint" }
289 -re "$gdb_prompt $" { fail "ptype bazint" }
290 timeout { fail "(timeout) ptype bazint" }
293 # ptype Baz<char, 'a'>
295 send_gdb "ptype bazint2\n"
297 -re "type = (class |)Baz<char,97> \\{\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 $" { pass "ptype bazint2" }
298 -re "$gdb_prompt $" { fail "ptype bazint2" }
299 timeout { fail "(timeout) ptype bazint2" }
302 # Template Qux<T, int (*f)(int) >
304 send_gdb "ptype Qux\n"
306 -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 $" { pass "ptype Qux" }
307 -re "$gdb_prompt $" { fail "ptype Qux" }
308 timeout { fail "(timeout) ptype Qux" }
311 # pt Qux<int,&string>
313 send_gdb "ptype quxint\n"
315 -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 $" { pass "ptype quxint" }
316 -re "$gdb_prompt $" { fail "ptype quxint" }
317 timeout { fail "(timeout) ptype quxint" }
322 send_gdb "ptype quxint2\n"
324 -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 $" { pass "ptype quxint2" }
325 -re "$gdb_prompt $" { fail "ptype quxint2" }
326 timeout { fail "(timeout) ptype quxint2" }
329 # Template Spec<T1, T2>
331 send_gdb "ptype Spec\n"
333 -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 $" { pass "ptype Spec" }
334 -re "$gdb_prompt $" { fail "ptype Spec" }
335 timeout { fail "(timeout) ptype Spec" }
340 send_gdb "ptype siip\n"
342 -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 $" { pass "ptype siip" }
343 -re "$gdb_prompt $" { fail "ptype siip" }
344 timeout { fail "(timeout) ptype siip" }
349 send_gdb "ptype Garply<int>\n"
351 -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 $" { pass "ptype Garply<int>" }
352 -re "$gdb_prompt $" { fail "ptype Garply<int>" }
353 timeout { fail "(timeout) ptype Garply<int>" }
356 # ptype of nested template name
358 send_gdb "ptype Garply<Garply<char> >\n"
360 -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 $" { pass "ptype Garply<Garply<char> >" }
361 -re "$gdb_prompt $" { fail "ptype Garply<Garply<char> >" }
362 timeout { fail "(timeout) ptype Garply<Garply<char> >" }
365 # print out a function from a nested template name
367 send_gdb "print Garply<Garply<char> >::garply\n"
369 -re "\\$\[0-9\]* = \\{(class |)Garply<char> \\((class |)Garply<Garply<char> > \\*, int, (class |)Garply<char>\\)\\} $hex <Garply<Garply<char>>::garply\\(int, (class |)Garply<char>\\)>\r\n$gdb_prompt $" { pass "print Garply<Garply<char> >::garply" }
370 -re ".*$gdb_prompt $" { fail "print Garply<Garply<char> >::garply" }
371 timeout { fail "print Garply<Garply<char> >::garply (timeout)" }
374 # UNFORTUNATELY, "break Garply<Garply<char> >::garply" doesn't yet work.
376 #send_gdb "break Garply<Garply<char> >::garply
378 # -re "Breakpoint \[0-9\]* at $hex: file .*templates.cc, line.*\r\n$gdb_prompt $" { pass "break Garply<Garply<char> >::garply" }
379 # -re ".*$gdb_prompt $" { fail "break Garply<Garply<char> >::garply" }
380 # timeout { fail "break Garply<Garply<char> >::garply (timeout)" }