]>
Commit | Line | Data |
---|---|---|
c906108c SS |
1 | # Copyright (C) 1992, 1996, 1997 Free Software Foundation, Inc. |
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 | |
5 | # the Free Software Foundation; either version 2 of the License, or | |
6 | # (at your option) any later version. | |
7 | # | |
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. | |
12 | # | |
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. | |
16 | ||
17 | # Please email any bugs, comments, and/or additions to this file to: | |
18 | # bug-gdb@prep.ai.mit.edu | |
19 | ||
20 | ||
21 | ||
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 | |
26 | # schemes. | |
27 | # Added by Satish Pai <pai@apollo.hp.com> 1997-09-25 | |
28 | ||
29 | ||
30 | set ws "\[\r\n\t \]+" | |
31 | ||
32 | if $tracelevel then { | |
33 | strace $tracelevel | |
34 | } | |
35 | ||
7a292a7a SS |
36 | if { [skip_hp_tests] } then { continue } |
37 | ||
c906108c SS |
38 | set testfile "templ-hp" |
39 | set srcfile ${testfile}.cc | |
40 | set binfile ${objdir}/${subdir}/${testfile} | |
41 | ||
42 | ||
43 | ||
44 | # Create and source the file that provides information about the compiler | |
45 | # used to compile the test case. | |
46 | ||
47 | if [get_compiler_info ${binfile} "c++"] { | |
48 | return -1; | |
49 | } | |
50 | ||
7a292a7a | 51 | if { $gcc_compiled } then { continue } |
c906108c SS |
52 | |
53 | ||
54 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } { | |
55 | gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail." | |
56 | ||
57 | } | |
58 | ||
59 | # | |
60 | # Test printing of the types of templates. | |
61 | # | |
62 | ||
63 | proc test_ptype_of_templates {} { | |
64 | global gdb_prompt | |
65 | ||
66 | send_gdb "ptype T5<int>\n" | |
67 | gdb_expect { | |
68 | -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>" } | |
69 | -re ".*$gdb_prompt $" { fail "ptype T5<int>" } | |
70 | timeout { fail "ptype T5<int> (timeout)" } | |
71 | } | |
72 | ||
73 | send_gdb "ptype t5i\n" | |
74 | gdb_expect { | |
75 | -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" } | |
76 | -re "type = class T5<int> \{.*public:.*static int X;.*int x;.*int val;.*.*T5 \\(int\\);.*.*void ~T5 \\(int\\).*.*.*int value \\(void\\);.*\}.*$gdb_prompt $" { | |
77 | pass "ptype t5i" | |
78 | } | |
79 | -re ".*$gdb_prompt $" { fail "ptype t5i" } | |
80 | timeout { fail "ptype t5i (timeout)" } | |
81 | } | |
82 | } | |
83 | ||
84 | # | |
85 | # Test breakpoint setting on template methods. | |
86 | # | |
87 | ||
88 | proc test_template_breakpoints {} { | |
89 | global gdb_prompt | |
90 | global testfile | |
91 | global srcdir | |
92 | ||
93 | send_gdb "break T5<int>::T5\n" | |
94 | gdb_expect { | |
95 | -re "0. cancel.*\r\n.1. all.*\r\n.2. *.*\r\n.3. *.*\r\n> $" { | |
96 | gdb_test "0" \ | |
97 | "cancelled" \ | |
98 | "constructor breakpoint" | |
99 | } | |
100 | -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 | gdb_test "0" \ | |
102 | "cancelled" \ | |
103 | "constructor breakpoint" | |
104 | } | |
105 | -re ".*$gdb_prompt $" { fail "constructor breakpoint" } | |
106 | default { fail "constructor breakpoint (timeout)" } | |
107 | } | |
108 | ||
109 | gdb_test "break T5<int>::~T5" \ | |
110 | "Breakpoint.*at.* file .*${testfile}.cc, line.*" \ | |
111 | "destructor breakpoint" | |
112 | ||
113 | gdb_test "break T5<int>::value" \ | |
114 | "Breakpoint.*at.* file .*${testfile}.cc, line.*" \ | |
115 | "value method breakpoint" | |
116 | ||
117 | delete_breakpoints | |
118 | } | |
119 | ||
120 | # | |
121 | # Test calling of template methods. | |
122 | # | |
123 | ||
124 | proc test_template_calls {} { | |
125 | global gdb_prompt | |
126 | ||
127 | send_gdb "print t5i.value()\n" | |
128 | gdb_expect { | |
129 | -re ".* = 2\r\n$gdb_prompt $" { pass "print t5i.value()" } | |
130 | -re "Cannot invoke functions on this machine.*$gdb_prompt $" { | |
131 | fail "print t5i.value()" | |
132 | } | |
133 | -re ".*$gdb_prompt $" { fail "print t5i.value()" } | |
134 | timeout { fail "print t5i.value() (timeout)" } | |
135 | } | |
136 | } | |
137 | ||
138 | ||
139 | proc do_tests {} { | |
140 | global prms_id | |
141 | global bug_id | |
142 | global subdir | |
143 | global objdir | |
144 | global srcdir | |
145 | global binfile | |
146 | global prompt | |
147 | global supports_template_debugging | |
148 | ||
149 | set prms_id 0 | |
150 | set bug_id 0 | |
151 | ||
152 | # Start with a fresh gdb. | |
153 | ||
154 | gdb_exit | |
155 | gdb_start | |
156 | gdb_reinitialize_dir $srcdir/$subdir | |
157 | gdb_load $binfile | |
158 | ||
159 | source ${binfile}.ci | |
160 | ||
161 | if { !$supports_template_debugging } { | |
162 | warning "compiler lacks debugging info for templates; tests suppressed." 0 | |
163 | return | |
164 | } | |
165 | ||
166 | test_ptype_of_templates | |
167 | test_template_breakpoints | |
168 | ||
169 | if [ runto_main ] { | |
170 | test_template_calls | |
171 | } | |
172 | } | |
173 | ||
174 | do_tests | |
175 | ||
176 | ||
177 | gdb_exit | |
178 | gdb_start | |
179 | gdb_reinitialize_dir $srcdir/$subdir | |
180 | gdb_load $binfile | |
181 | ||
182 | # set it up at a breakpoint so we can play with the variable values | |
183 | # | |
184 | if ![runto_main] then { | |
185 | perror "couldn't run to breakpoint" | |
186 | continue | |
187 | } | |
188 | ||
189 | send_gdb "print fint\n" | |
190 | gdb_expect { | |
191 | -re "\\$\[0-9\]* = \\{x = 0, t = 0\\}\r\n$gdb_prompt $" { pass "print fint" } | |
192 | -re "$gdb_prompt $" { fail "print fint" } | |
193 | timeout { fail "(timeout) print fint" } | |
194 | } | |
195 | ||
196 | send_gdb "print fvpchar\n" | |
197 | gdb_expect { | |
198 | -re "\\$\[0-9\]* = \\{x = 0, t = 0x0\\}\r\n$gdb_prompt $" { pass "print fvpchar" } | |
199 | -re "$gdb_prompt $" { fail "print fvpchar" } | |
200 | timeout { fail "(timeout) print fvpchar" } | |
201 | } | |
202 | ||
203 | # Template Foo<T> | |
204 | ||
205 | send_gdb "ptype Foo\n" | |
206 | gdb_expect { | |
207 | -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" } | |
208 | -re "$gdb_prompt $" { fail "ptype Foo" } | |
209 | timeout { fail "(timeout) ptype Foo" } | |
210 | } | |
211 | ||
212 | # ptype Foo<int> | |
213 | ||
214 | send_gdb "ptype fint\n" | |
215 | gdb_expect { | |
216 | -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" } | |
217 | -re "$gdb_prompt $" { fail "ptype fint" } | |
218 | timeout { fail "(timeout) ptype fint" } | |
219 | } | |
220 | ||
221 | # ptype Foo<char> | |
222 | ||
223 | send_gdb "ptype fchar\n" | |
224 | gdb_expect { | |
225 | -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" } | |
226 | -re "$gdb_prompt $" { fail "ptype fchar" } | |
227 | timeout { fail "(timeout) ptype fchar" } | |
228 | } | |
229 | ||
230 | # ptype Foo<volatile char *> | |
231 | ||
232 | send_gdb "ptype fvpchar\n" | |
233 | gdb_expect { | |
234 | -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" } | |
235 | -re "$gdb_prompt $" { fail "ptype fvpchar" } | |
236 | timeout { fail "(timeout) ptype fvpchar" } | |
237 | } | |
238 | ||
239 | # print a function from Foo<volatile char *> | |
240 | ||
241 | send_gdb "print Foo<volatile char *>::foo\n" | |
242 | gdb_expect { | |
243 | -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" } | |
244 | -re "$gdb_prompt $" { fail "print Foo<volatile char *>::foo" } | |
245 | timeout { fail "(timeout) print Foo<volatile char *>::foo" } | |
246 | } | |
247 | ||
248 | # Template Bar<T, int> | |
249 | ||
250 | send_gdb "ptype Bar\n" | |
251 | gdb_expect { | |
252 | -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" } | |
253 | -re "$gdb_prompt $" { fail "ptype Bar" } | |
254 | timeout { fail "(timeout) ptype Bar" } | |
255 | } | |
256 | ||
257 | ||
258 | # ptype Bar<int,33> | |
259 | ||
260 | send_gdb "ptype bint\n" | |
261 | gdb_expect { | |
262 | -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" } | |
263 | -re "$gdb_prompt $" { fail "ptype bint" } | |
264 | timeout { fail "(timeout) ptype bint" } | |
265 | } | |
266 | ||
267 | # ptype Bar<int, (4>3)> | |
268 | ||
269 | send_gdb "ptype bint2\n" | |
270 | gdb_expect { | |
271 | -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" } | |
272 | -re "$gdb_prompt $" { fail "ptype bint2" } | |
273 | timeout { fail "(timeout) ptype bint2" } | |
274 | } | |
275 | ||
276 | # Template Baz<T, char> | |
277 | ||
278 | send_gdb "ptype Baz\n" | |
279 | gdb_expect { | |
280 | -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" } | |
281 | -re "$gdb_prompt $" { fail "ptype Baz" } | |
282 | timeout { fail "(timeout) ptype Baz" } | |
283 | } | |
284 | ||
285 | ||
286 | # ptype Baz<int, 's'> | |
287 | ||
288 | send_gdb "ptype bazint\n" | |
289 | gdb_expect { | |
290 | -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" } | |
291 | -re "$gdb_prompt $" { fail "ptype bazint" } | |
292 | timeout { fail "(timeout) ptype bazint" } | |
293 | } | |
294 | ||
295 | # ptype Baz<char, 'a'> | |
296 | ||
297 | send_gdb "ptype bazint2\n" | |
298 | gdb_expect { | |
299 | -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" } | |
300 | -re "$gdb_prompt $" { fail "ptype bazint2" } | |
301 | timeout { fail "(timeout) ptype bazint2" } | |
302 | } | |
303 | ||
304 | # Template Qux<T, int (*f)(int) > | |
305 | ||
306 | send_gdb "ptype Qux\n" | |
307 | gdb_expect { | |
308 | -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" } | |
309 | -re "$gdb_prompt $" { fail "ptype Qux" } | |
310 | timeout { fail "(timeout) ptype Qux" } | |
311 | } | |
312 | ||
313 | # pt Qux<int,&string> | |
314 | ||
315 | send_gdb "ptype quxint\n" | |
316 | gdb_expect { | |
317 | -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" } | |
318 | -re "$gdb_prompt $" { fail "ptype quxint" } | |
319 | timeout { fail "(timeout) ptype quxint" } | |
320 | } | |
321 | ||
322 | # pt Qux<char,0> | |
323 | ||
324 | send_gdb "ptype quxint2\n" | |
325 | gdb_expect { | |
326 | -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" } | |
327 | -re "$gdb_prompt $" { fail "ptype quxint2" } | |
328 | timeout { fail "(timeout) ptype quxint2" } | |
329 | } | |
330 | ||
331 | # Template Spec<T1, T2> | |
332 | ||
333 | send_gdb "ptype Spec\n" | |
334 | gdb_expect { | |
335 | -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" } | |
336 | -re "$gdb_prompt $" { fail "ptype Spec" } | |
337 | timeout { fail "(timeout) ptype Spec" } | |
338 | } | |
339 | ||
340 | # pt Spec<char,0> | |
341 | ||
342 | send_gdb "ptype siip\n" | |
343 | gdb_expect { | |
344 | -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" } | |
345 | -re "$gdb_prompt $" { fail "ptype siip" } | |
346 | timeout { fail "(timeout) ptype siip" } | |
347 | } | |
348 | ||
349 | # pt Garply<int> | |
350 | ||
351 | send_gdb "ptype Garply<int>\n" | |
352 | gdb_expect { | |
353 | -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>" } | |
354 | -re "$gdb_prompt $" { fail "ptype Garply<int>" } | |
355 | timeout { fail "(timeout) ptype Garply<int>" } | |
356 | } | |
357 | ||
358 | # ptype of nested template name | |
359 | ||
360 | send_gdb "ptype Garply<Garply<char> >\n" | |
361 | gdb_expect { | |
362 | -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> >" } | |
363 | -re "$gdb_prompt $" { fail "ptype Garply<Garply<char> >" } | |
364 | timeout { fail "(timeout) ptype Garply<Garply<char> >" } | |
365 | } | |
366 | ||
367 | # print out a function from a nested template name | |
368 | ||
369 | send_gdb "print Garply<Garply<char> >::garply\n" | |
370 | gdb_expect { | |
371 | -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" } | |
372 | -re ".*$gdb_prompt $" { fail "print Garply<Garply<char> >::garply" } | |
373 | timeout { fail "print Garply<Garply<char> >::garply (timeout)" } | |
374 | } | |
375 | ||
376 | # UNFORTUNATELY, "break Garply<Garply<char> >::garply" doesn't yet work. | |
377 | ||
378 | #send_gdb "break Garply<Garply<char> >::garply | |
379 | #gdb_expect { | |
380 | # -re "Breakpoint \[0-9\]* at $hex: file .*templates.cc, line.*\r\n$gdb_prompt $" { pass "break Garply<Garply<char> >::garply" } | |
381 | # -re ".*$gdb_prompt $" { fail "break Garply<Garply<char> >::garply" } | |
382 | # timeout { fail "break Garply<Garply<char> >::garply (timeout)" } | |
383 | #} |