1 # Copyright (C) 1998 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
19 # Tests for pointer-to-member support
20 # Written by Satish Pai <pai@apollo.hp.com> 1997-08-19
22 # This file is part of the gdb testsuite
30 # test running programs
33 # Start with a fresh gdb
36 gdb_reinitialize_dir $srcdir/$subdir
41 set testfile "member-ptr"
42 set srcfile ${testfile}.cc
43 set binfile ${objdir}/${subdir}/${testfile}
45 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
46 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
52 gdb_reinitialize_dir $srcdir/$subdir
56 if ![runto_main] then {
57 perror "couldn't run to breakpoint"
63 -re "Breakpoint \[0-9\]*.*line 83\\.\r\n$gdb_prompt $" {
64 pass "set break at 83"
66 -re ".*$gdb_prompt $" { fail "set break at 83" }
67 timeout { fail "(timeout) set break at 83" }
72 -re "Continuing\\.\r\n\r\nBreakpoint.*at.*member-ptr\\.cc:83\r\n83\[ \t]*pmi = NULL;\r\n$gdb_prompt $" {
75 -re ".*$gdb_prompt $" { fail "continue to 83" }
76 timeout { fail "(timeout) continue to 83" }
79 # ptype on pointer to data member
81 send_gdb "ptype pmi\n"
83 -re "type = int \\( A::\\*\\)\r\n$gdb_prompt $" {
86 -re ".*$gdb_prompt $" { fail "ptype pmi" }
87 timeout { fail "(timeout) ptype pmi" }
90 # print pointer to data member
92 send_gdb "print pmi\n"
94 -re "\\$\[0-9\]* = \\(int \\( A::\\*\\)\\) &A::j\r\n$gdb_prompt $" {
97 -re ".*$gdb_prompt $" { fail "print pmi" }
98 timeout { fail "(timeout) print pmi" }
102 # print dereferenced pointer to data member
104 send_gdb "print a.*pmi\n"
106 -re "\\$\[0-9\]* = 121\r\n$gdb_prompt $" {
109 -re ".*$gdb_prompt $" { fail "print a.*pmi" }
110 timeout { fail "(timeout) print a.*pmi" }
113 # print dereferenced pointer to data member
114 # this time, dereferenced through a pointer
116 send_gdb "print a_p->*pmi\n"
118 -re "\\$\[0-9\]* = 121\r\n$gdb_prompt $" {
121 -re ".*$gdb_prompt $" { fail "print a->*pmi" }
122 timeout { fail "(timeout) print a->*pmi" }
126 # set the pointer to data member
128 send_gdb "set var pmi = &A::jj\n"
130 -re "$gdb_prompt $" {
131 pass "set var (not really a pass)"
133 timeout { fail "(timeout) " }
136 # Now print the pointer again
138 send_gdb "print pmi\n"
140 -re "\\$\[0-9\]* = \\(int \\( A::\\*\\)\\) &A::jj\r\n$gdb_prompt $" {
141 pass "print pmi after setting"
143 -re ".*$gdb_prompt $" { fail "print pmi after setting" }
144 timeout { fail "(timeout) print pmi after setting" }
147 # print dereferenced pointer to data member again
149 send_gdb "print a.*pmi\n"
151 -re "\\$\[0-9\]* = 1331\r\n$gdb_prompt $" {
152 pass "print a.*pmi after setting"
154 -re ".*$gdb_prompt $" { fail "print a.*pmi after setting" }
155 timeout { fail "(timeout) print a.*pmi after setting" }
158 # set the pointer to data member back to A::j
160 send_gdb "set var pmi = &A::j\n"
162 -re "$gdb_prompt $" {
163 pass "set var back to A::j (not really a pass)"
165 timeout { fail "(timeout) set var pmi" }
168 # print dereferenced pointer to data member yet again (extra check, why not)
170 send_gdb "print a.*pmi\n"
172 -re "\\$\[0-9\]* = 121\r\n$gdb_prompt $" {
173 pass "print a.*pmi after resetting"
175 -re ".*$gdb_prompt $" { fail "print a.*pmi after resetting" }
176 timeout { fail "(timeout) print a.*pmi after resetting" }
179 # Set the data member pointed to.
181 send_gdb "print a.*pmi = 33\n"
183 -re "\\$\[0-9\]* = 33\r\n$gdb_prompt $" {
184 pass "print command to set"
186 -re ".*$gdb_prompt $" { fail "print command to set" }
187 timeout { fail "(timeout) print command to set" }
190 # Now check that the data really was changed
191 send_gdb "print a.*pmi\n"
193 -re "\\$\[0-9\]* = 33\r\n$gdb_prompt $" {
194 pass "print a.*pmi after setting member pointed to"
196 -re ".*$gdb_prompt $" { fail "print a.*pmi after setting member pointed to" }
197 timeout { fail "(timeout) print a.*pmi after setting member pointed to" }
200 # Double-check by printing a.
203 -re "\\$\[0-9\]* = \{c = 120 'x', j = 33, jj = 1331, static s = 10, Virtual table at $hex\}\r\n$gdb_prompt $" {
204 pass "print a after setting member pointed to by pmi"
206 -re ".*$gdb_prompt $" { fail "print a after setting member pointed to by pmi" }
207 timeout { fail "(timeout) print a after setting member pointed to by pmi" }
211 # Set the data member pointed to, using ->*
213 send_gdb "print a_p->*pmi = 44\n"
215 -re "\\$\[0-9\]* = 44\r\n$gdb_prompt $" {
216 pass "print command to set (->)"
218 -re ".*$gdb_prompt $" { fail "print command to set (->)" }
219 timeout { fail "(timeout) print command to set (->)" }
222 # Now check that the data really was changed
223 send_gdb "print a_p->*pmi\n"
225 -re "\\$\[0-9\]* = 44\r\n$gdb_prompt $" {
226 pass "print a_p->*pmi after setting member pointed to"
228 -re ".*$gdb_prompt $" { fail "print a_p->*pmi after setting member pointed to" }
229 timeout { fail "(timeout) print a_p->*pmi after setting member pointed to" }
232 # Double-check by printing a.
235 -re "\\$\[0-9\]* = \{c = 120 'x', j = 44, jj = 1331, static s = 10, Virtual table at $hex\}\r\n$gdb_prompt $" {
236 pass "print a after setting member pointed to by pmi (->) "
238 -re ".*$gdb_prompt $" { fail "print a after setting member pointed to by pmi (->) " }
239 timeout { fail "(timeout) print a after setting member pointed to by pmi (->) " }
243 # Do a ptype on the dereferenced pointer to member
244 # pai/1997-08-20 Doesn't work
246 # send_gdb "ptype a.*pmi\n"
248 # -re "type = int\r\n$gdb_prompt $" {
249 # pass "ptype a.*pmi"
251 # -re ".*$gdb_prompt $" { fail "ptype a.*pmi" }
252 # timeout { fail "(timeout) ptype a.*pmi" }
255 # Try to dereference the pointer to data member without any object
257 send_gdb "print *pmi\n"
259 -re "Attempt to dereference pointer to member without an object\r\n$gdb_prompt $" {
260 pass "attempt to print ptr to member without object"
262 -re ".*$gdb_prompt $" { fail "attempt to print ptr to member without object" }
263 timeout { fail "(timeout) attempt to print ptr to member without object" }
266 # Try to ptype a dereference of the pointer to data member without any object
268 send_gdb "ptype *pmi\n"
270 -re "Attempt to dereference pointer to member without an object\r\n$gdb_prompt $" {
271 pass "attempt to ptype ptr to member without object"
273 -re ".*$gdb_prompt $" { fail "attempt to ptype ptr to member without object" }
274 timeout { fail "(timeout) attempt to ptype ptr to member without object" }
277 # Ptype a pointer to a method.
279 send_gdb "ptype pmf\n"
281 -re "type = int \\( A::\\*\\)\\(\\.\\.\\.\\)\r\n$gdb_prompt $" {
284 -re ".*$gdb_prompt $" { fail "ptype pmf" }
285 timeout { fail "(timeout) ptype pmf" }
288 # print a pointer to a method
290 send_gdb "print pmf\n"
292 -re "\\$\[0-9\]* = \\(int \\( A::\\*\\)\\(\\.\\.\\.\\)\\) \\?\\? <not supported with HP aCC>\r\n$gdb_prompt $" {
295 -re ".*$gdb_prompt $" { fail "print pmf" }
296 timeout { fail "(timeout) print pmf" }
300 # Ptype a pointer to a pointer to a method
302 send_gdb "ptype pmf_p\n"
304 -re "type = int \\( A::\\*\\*\\)\\(\\.\\.\\.\\)\r\n$gdb_prompt $" {
307 -re ".*$gdb_prompt $" { fail "ptype pmf_p" }
308 timeout { fail "(timeout) ptype pmf_p" }
311 # print a pointer to a pointer to a method
313 send_gdb "print pmf_p\n"
315 -re "\\$\[0-9\]* = \\(int \\( A::\\*\\*\\)\\(\\.\\.\\.\\)\\) $hex\r\n$gdb_prompt $" {
318 -re ".*$gdb_prompt $" { fail "print pmf_p" }
319 timeout { fail "(timeout) print pmf_p" }
322 # print dereferenced pointer to method
324 send_gdb "print a.*pmf\n"
326 -re "Pointers to methods not supported with HP aCC\r\n$gdb_prompt $" {
327 pass "print a.*pmf (known aCC limitation)"
329 -re ".*$gdb_prompt $" { fail "print a.*pmf -- ??" }
330 timeout { fail "(timeout) print a.*pmf" }
333 # print dereferenced pointer to method, using ->*
335 send_gdb "print a_p->*pmf\n"
337 -re "Pointers to methods not supported with HP aCC\r\n$gdb_prompt $" {
338 pass "print a_p->*pmf (known aCC limitation)"
340 -re ".*$gdb_prompt $" { fail "print a_p->*pmf -- ??" }
341 timeout { fail "(timeout) print a_p->*pmf" }
344 # set the pointer to data member
346 send_gdb "set var pmf = &A::foo\n"
348 -re "Assignment to pointers to methods not implemented with HP aCC\r\n$gdb_prompt $" {
349 pass "set var pmf (known aCC limitation)"
351 -re ".*$gdb_prompt $" { fail "set var pmf -- ??" }
352 timeout { fail "(timeout) set var pmf" }
355 # Try to dereference the pointer to method without any object
357 send_gdb "print *pmf\n"
359 -re "Attempt to dereference pointer to member without an object\r\n$gdb_prompt $" {
360 pass "attempt to print ptr to method without object"
362 -re ".*$gdb_prompt $" { fail "attempt to print ptr to method without object" }
363 timeout { fail "(timeout) attempt to print ptr to method without object" }
366 # Try to ptype a dereference of the pointer to method without any object
368 send_gdb "ptype *pmi\n"
370 -re "Attempt to dereference pointer to member without an object\r\n$gdb_prompt $" {
371 pass "attempt to ptype ptr to member without object"
373 -re ".*$gdb_prompt $" { fail "attempt to ptype ptr to member without object" }
374 timeout { fail "(timeout) attempt to ptype ptr to member without object" }
377 # Check cast of pointer to member to integer
378 send_gdb "print (int) pmi\n"
380 -re "\\$\[0-9\]* = 8\r\n$gdb_prompt $" {
381 pass "casting pmi to int"
383 -re ".*$gdb_prompt $" { fail "casting pmi to int" }
384 timeout { fail "(timeout) casting pmi to int" }
387 # Check cast of pointer to method to integer
388 send_gdb "print (int) pmf\n"
390 -re "Pointers to methods not supported with HP aCC\r\n$gdb_prompt $" {
391 pass "casting pmf to int (known aCC limitation)"
393 -re ".*$gdb_prompt $" { fail "casting pmf to int -- ??" }
394 timeout { fail "(timeout) casting pmf to int" }
397 # Try to invoke a function through a pointer to data member
398 send_gdb "print (a.*pmi)(3)\n"
400 -re "Not implemented: function invocation through pointer to method with HP aCC\r\n$gdb_prompt $" {
401 pass "print (a.*pmi)(3) -- error message should be different"
403 -re ".*$gdb_prompt $" { fail "print (a.*pmi)(3) -- ???" }
404 timeout { fail "(timeout) print (a.*pmi)(3)" }
407 # Try to invoke a function through a pointer to a method
408 send_gdb "print (a.*pmf)(3)\n"
410 -re "Not implemented: function invocation through pointer to method with HP aCC\r\n$gdb_prompt $" {
411 pass "print (a.*pmi)(3) -- known aCC limitation"
413 -re ".*$gdb_prompt $" { fail "print (a.*pmf)(3) -- ???" }
414 timeout { fail "(timeout) print (a.*pmf)(3)" }
418 # Go past assignment of NULL to pmi
421 -re "\r\n85\[ \t\]*k = \\(a.\\*pmf\\)\\(3\\);\r\n$gdb_prompt $" {
424 -re ".*$gdb_prompt $" { fail "next past 83" }
425 timeout { fail "(timeout) next past 83" }
428 #send_gdb "print pmi\n"
430 # -re "Attempted dereference of null pointer-to-member\r\n$gdb_prompt $" {
433 # -re ".*$gdb_prompt $" { fail "" }
434 # timeout { fail "(timeout) " }
437 # Dereference the null pointer to member
438 send_gdb "print a.*pmi\n"
440 -re "Attempted dereference of null pointer-to-member\r\n$gdb_prompt $" {
443 -re ".*$gdb_prompt $" { fail "print a.*NULL" }
444 timeout { fail "(timeout) print a.*NULL" }
448 # Go to another part of the program
449 send_gdb "break 91\n"
451 -re "Breakpoint \[0-9\]*.*line 91\\.\r\n$gdb_prompt $" {
452 pass "set break at 91"
454 -re ".*$gdb_prompt $" { fail "set break at 91" }
455 timeout { fail "(timeout) set break at 91" }
458 send_gdb "continue\n"
460 -re "Continuing\\.\r\n\r\nBreakpoint.*at.*member-ptr\\.cc:91\r\n91\[ \t]*k = \\(a.\\*pmf\\)\\(4\\);\r\n$gdb_prompt $" {
461 pass "continue to 91"
463 -re ".*$gdb_prompt $" { fail "continue to 91" }
464 timeout { fail "(timeout) continue to 91" }
468 # Now check again that pmi works even when not set to
469 # something that's at the beginning of the object
471 send_gdb "print pmi\n"
473 -re "\\$\[0-9\]* = \\(int \\( A::\\*\\)\\) &A::jj\r\n$gdb_prompt $" {
476 -re ".*$gdb_prompt $" { fail "print pmi (2)" }
477 timeout { fail "(timeout) print pmi (2)" }
481 # print dereferenced pointer to data member
483 send_gdb "print a.*pmi\n"
485 -re "\\$\[0-9\]* = 1331\r\n$gdb_prompt $" {
486 pass "print a.*pmi (2)"
488 -re ".*$gdb_prompt $" { fail "print a.*pmi (2)" }
489 timeout { fail "(timeout) print a.*pmi (2)" }
492 # print dereferenced pointer to data member
493 # this time, dereferenced through a pointer
495 send_gdb "print a_p->*pmi\n"
497 -re "\\$\[0-9\]* = 1331\r\n$gdb_prompt $" {
500 -re ".*$gdb_prompt $" { fail "print a->*pmi (2)" }
501 timeout { fail "(timeout) print a->*pmi (2)" }