]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.hp/templ-hp.exp
Initial creation of sourceware repository
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.hp / templ-hp.exp
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
36 set testfile "templ-hp"
37 set srcfile ${testfile}.cc
38 set binfile ${objdir}/${subdir}/${testfile}
39
40
41
42 # Create and source the file that provides information about the compiler
43 # used to compile the test case.
44
45 if [get_compiler_info ${binfile} "c++"] {
46 return -1;
47 }
48
49 if {[skip_hp_tests $gcc_compiled]} then { continue }
50
51
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."
54
55 }
56
57 #
58 # Test printing of the types of templates.
59 #
60
61 proc test_ptype_of_templates {} {
62 global gdb_prompt
63
64 send_gdb "ptype T5<int>\n"
65 gdb_expect {
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)" }
69 }
70
71 send_gdb "ptype t5i\n"
72 gdb_expect {
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 $" {
75 pass "ptype t5i"
76 }
77 -re ".*$gdb_prompt $" { fail "ptype t5i" }
78 timeout { fail "ptype t5i (timeout)" }
79 }
80 }
81
82 #
83 # Test breakpoint setting on template methods.
84 #
85
86 proc test_template_breakpoints {} {
87 global gdb_prompt
88 global testfile
89 global srcdir
90
91 send_gdb "break T5<int>::T5\n"
92 gdb_expect {
93 -re "0. cancel.*\r\n.1. all.*\r\n.2. *.*\r\n.3. *.*\r\n> $" {
94 gdb_test "0" \
95 "cancelled" \
96 "constructor breakpoint"
97 }
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> $" {
99 gdb_test "0" \
100 "cancelled" \
101 "constructor breakpoint"
102 }
103 -re ".*$gdb_prompt $" { fail "constructor breakpoint" }
104 default { fail "constructor breakpoint (timeout)" }
105 }
106
107 gdb_test "break T5<int>::~T5" \
108 "Breakpoint.*at.* file .*${testfile}.cc, line.*" \
109 "destructor breakpoint"
110
111 gdb_test "break T5<int>::value" \
112 "Breakpoint.*at.* file .*${testfile}.cc, line.*" \
113 "value method breakpoint"
114
115 delete_breakpoints
116 }
117
118 #
119 # Test calling of template methods.
120 #
121
122 proc test_template_calls {} {
123 global gdb_prompt
124
125 send_gdb "print t5i.value()\n"
126 gdb_expect {
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()"
130 }
131 -re ".*$gdb_prompt $" { fail "print t5i.value()" }
132 timeout { fail "print t5i.value() (timeout)" }
133 }
134 }
135
136
137 proc do_tests {} {
138 global prms_id
139 global bug_id
140 global subdir
141 global objdir
142 global srcdir
143 global binfile
144 global prompt
145 global supports_template_debugging
146
147 set prms_id 0
148 set bug_id 0
149
150 # Start with a fresh gdb.
151
152 gdb_exit
153 gdb_start
154 gdb_reinitialize_dir $srcdir/$subdir
155 gdb_load $binfile
156
157 source ${binfile}.ci
158
159 if { !$supports_template_debugging } {
160 warning "compiler lacks debugging info for templates; tests suppressed." 0
161 return
162 }
163
164 test_ptype_of_templates
165 test_template_breakpoints
166
167 if [ runto_main ] {
168 test_template_calls
169 }
170 }
171
172 do_tests
173
174
175 gdb_exit
176 gdb_start
177 gdb_reinitialize_dir $srcdir/$subdir
178 gdb_load $binfile
179
180 # set it up at a breakpoint so we can play with the variable values
181 #
182 if ![runto_main] then {
183 perror "couldn't run to breakpoint"
184 continue
185 }
186
187 send_gdb "print fint\n"
188 gdb_expect {
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" }
192 }
193
194 send_gdb "print fvpchar\n"
195 gdb_expect {
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" }
199 }
200
201 # Template Foo<T>
202
203 send_gdb "ptype Foo\n"
204 gdb_expect {
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" }
208 }
209
210 # ptype Foo<int>
211
212 send_gdb "ptype fint\n"
213 gdb_expect {
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" }
217 }
218
219 # ptype Foo<char>
220
221 send_gdb "ptype fchar\n"
222 gdb_expect {
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" }
226 }
227
228 # ptype Foo<volatile char *>
229
230 send_gdb "ptype fvpchar\n"
231 gdb_expect {
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" }
235 }
236
237 # print a function from Foo<volatile char *>
238
239 send_gdb "print Foo<volatile char *>::foo\n"
240 gdb_expect {
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" }
244 }
245
246 # Template Bar<T, int>
247
248 send_gdb "ptype Bar\n"
249 gdb_expect {
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" }
253 }
254
255
256 # ptype Bar<int,33>
257
258 send_gdb "ptype bint\n"
259 gdb_expect {
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" }
263 }
264
265 # ptype Bar<int, (4>3)>
266
267 send_gdb "ptype bint2\n"
268 gdb_expect {
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" }
272 }
273
274 # Template Baz<T, char>
275
276 send_gdb "ptype Baz\n"
277 gdb_expect {
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" }
281 }
282
283
284 # ptype Baz<int, 's'>
285
286 send_gdb "ptype bazint\n"
287 gdb_expect {
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" }
291 }
292
293 # ptype Baz<char, 'a'>
294
295 send_gdb "ptype bazint2\n"
296 gdb_expect {
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" }
300 }
301
302 # Template Qux<T, int (*f)(int) >
303
304 send_gdb "ptype Qux\n"
305 gdb_expect {
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" }
309 }
310
311 # pt Qux<int,&string>
312
313 send_gdb "ptype quxint\n"
314 gdb_expect {
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" }
318 }
319
320 # pt Qux<char,0>
321
322 send_gdb "ptype quxint2\n"
323 gdb_expect {
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" }
327 }
328
329 # Template Spec<T1, T2>
330
331 send_gdb "ptype Spec\n"
332 gdb_expect {
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" }
336 }
337
338 # pt Spec<char,0>
339
340 send_gdb "ptype siip\n"
341 gdb_expect {
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" }
345 }
346
347 # pt Garply<int>
348
349 send_gdb "ptype Garply<int>\n"
350 gdb_expect {
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>" }
354 }
355
356 # ptype of nested template name
357
358 send_gdb "ptype Garply<Garply<char> >\n"
359 gdb_expect {
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> >" }
363 }
364
365 # print out a function from a nested template name
366
367 send_gdb "print Garply<Garply<char> >::garply\n"
368 gdb_expect {
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)" }
372 }
373
374 # UNFORTUNATELY, "break Garply<Garply<char> >::garply" doesn't yet work.
375
376 #send_gdb "break Garply<Garply<char> >::garply
377 #gdb_expect {
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)" }
381 #}