d82ab1f6cf994ea1a9c6f2de917fe6970247dc2d
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.cp / derivation.exp
1 # Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004
2 # Free Software Foundation, Inc.
3
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18 # This file was written by Elena Zannoni (ezannoni@cygnus.com)
19 # And rewritten by Michael Chastain <mec.gnu@mindspring.com>
20
21 # This file is part of the gdb testsuite
22
23 # tests for inheritance, with several derivations types combinations
24 # (private, public, protected)
25 # classes have simple members and member functions.
26
27 set ws "\[\r\n\t \]+"
28 set nl "\[\r\n\]+"
29
30 if $tracelevel then {
31 strace $tracelevel
32 }
33
34 # Start program.
35
36 set prms_id 0
37 set bug_id 0
38
39 if { [skip_cplus_tests] } { continue }
40
41 set testfile "derivation"
42 set srcfile ${testfile}.cc
43 set binfile ${objdir}/${subdir}/${testfile}
44
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."
47 }
48
49 gdb_exit
50 gdb_start
51 gdb_reinitialize_dir $srcdir/$subdir
52 gdb_load ${binfile}
53
54 # Set it up at a breakpoint so we can play with the variable values.
55
56 if ![runto 'marker1'] then {
57 perror "couldn't run to marker1"
58 continue
59 }
60
61 gdb_test "up" ".*main.*" "up from marker1"
62
63 # Print class types and values.
64 # See virtfunc.exp for a discussion of ptype.
65
66 # class A
67
68 set re_class "((struct|class) A \{${ws}public:|struct A \{)"
69 set re_fields "int a;${ws}int aa;"
70 set re_methods "A\\((void|)\\);${ws}int afoo\\((void|)\\);${ws}int foo\\((void|)\\);"
71 set re_synth_gcc_23 "A & operator=\\(A const ?&\\);${ws}A\\(A const ?&\\);"
72 set re_all_methods "($re_methods|$re_methods${ws}$re_synth_gcc_23|$re_synth_gcc_23${ws}$re_methods)"
73
74 gdb_test "print a_instance" "\\$\[0-9\]+ = \{a = 1, aa = 2\}" "print value of a_instance"
75
76 gdb_test_multiple "ptype a_instance" "ptype a_instance" {
77 -re "type = $re_class${ws}$re_fields${ws}$re_methods$nl\}$nl$gdb_prompt $" {
78 pass "ptype a_instance (no synth ops)"
79 }
80 -re "type = $re_class${ws}$re_fields${ws}$re_synth_gcc_23${ws}$re_methods${ws}$nl\}$nl$gdb_prompt $" {
81 pass "ptype a_instance (with synth ops)"
82 }
83 -re "type = $re_class${ws}$re_fields${ws}$re_methods${ws}$re_synth_gcc_23$nl\}$nl$gdb_prompt $" {
84 pass "ptype a_instance (with synth ops)"
85 }
86 }
87
88 # class D
89
90 set re_class "class D : private A, public B, protected C \{${ws}public:"
91 set XX_class "class D : private A, public B, private C \{${ws}public:"
92 set re_fields "int d;${ws}int dd;"
93 set re_methods "D\\((void|)\\);${ws}int dfoo\\((void|)\\);${ws}int foo\\((void|)\\);"
94 set re_synth_gcc_23 "D & operator=\\(D const ?&\\);${ws}D\\(D const ?&\\);"
95 set re_all_methods "($re_methods|$re_methods${ws}$re_synth_gcc_23|$re_synth_gcc_23${ws}$re_methods)"
96
97 gdb_test_multiple "print d_instance" "print value of d_instance" {
98 -re "\\$\[0-9\]+ = \{<(class A|A)> = \{a = 1, aa = 2\}, <(class B|B)> = \{b = 3, bb = 4\}, <(class C|C)> = \{c = 5, cc = 6\}, d = 7, dd = 8\}$nl$gdb_prompt $" {
99 pass "print value of d_instance"
100 }
101 }
102
103 gdb_test_multiple "ptype d_instance" "ptype d_instance" {
104 -re "type = $re_class${ws}$re_fields${ws}$re_methods${ws}$re_synth_gcc_23$nl\}$nl$gdb_prompt $" {
105 pass "ptype d_instance"
106 }
107 -re "type = $re_class${ws}$re_fields${ws}$re_all_methods$nl\}$nl$gdb_prompt $" {
108 pass "ptype d_instance"
109 }
110 -re "type = $XX_class${ws}$re_fields${ws}$re_methods${ws}$re_synth_gcc_23$nl\}$nl$gdb_prompt $" {
111 # This is a gcc bug, gcc/13539, gdb/1498.
112 # Fixed in gcc HEAD 2004-01-13
113 setup_xfail "*-*-*" "gcc/13539"
114 fail "ptype d_instance"
115 }
116 -re "type = $XX_class${ws}$re_fields${ws}$re_all_methods$nl\}$nl$gdb_prompt $" {
117 # This is a gcc bug, gcc/13539, gdb/1498.
118 # Fixed in gcc HEAD 2004-01-13
119 setup_xfail "*-*-*" "gcc/13539"
120 fail "ptype d_instance"
121 }
122 }
123
124 # class E
125
126 set re_class "class E : public A, private B, protected C \{${ws}public:"
127 set XX_class "class E : public A, private B, private C \{${ws}public:"
128 set re_fields "int e;${ws}int ee;"
129 set re_methods "E\\((void|)\\);${ws}int efoo\\((void|)\\);${ws}int foo\\((void|)\\);"
130 set re_synth_gcc_23 "E & operator=\\(E const ?&\\);${ws}E\\(E const ?&\\);"
131 set re_all_methods "($re_methods|$re_methods${ws}$re_synth_gcc_23|$re_synth_gcc_23${ws}$re_methods)"
132
133 gdb_test_multiple "print e_instance" "print value of e_instance" {
134 -re "\\$\[0-9\]+ = \{<(class A|A)> = \{a = 1, aa = 2\}, <(class B|B)> = \{b = 3, bb = 4\}, <(class C|C)> = \{c = 5, cc = 6\}, e = 9, ee = 10\}$nl$gdb_prompt $" {
135 pass "print value of e_instance"
136 }
137 }
138
139 gdb_test_multiple "ptype e_instance" "ptype e_instance" {
140 -re "type = $re_class${ws}$re_fields${ws}$re_methods${ws}$re_synth_gcc_23$nl\}$nl$gdb_prompt $" {
141 pass "ptype e_instance"
142 }
143 -re "type = $re_class${ws}$re_fields${ws}$re_all_methods$nl\}$nl$gdb_prompt $" {
144 pass "ptype e_instance"
145 }
146 -re "type = $XX_class${ws}$re_fields${ws}$re_methods${ws}$re_synth_gcc_23$nl\}$nl$gdb_prompt $" {
147 # This is a gcc bug, gcc/13539, gdb/1498.
148 # Fixed in gcc HEAD 2004-01-13
149 setup_xfail "*-*-*" "gcc/13539"
150 fail "ptype e_instance"
151 }
152 -re "type = $XX_class${ws}$re_fields${ws}$re_all_methods$nl\}$nl$gdb_prompt $" {
153 # This is a gcc bug, gcc/13539, gdb/1498.
154 # Fixed in gcc HEAD 2004-01-13
155 setup_xfail "*-*-*" "gcc/13539"
156 fail "ptype e_instance"
157 }
158 }
159
160 # class F
161
162 set re_class "class F : private A, public B, private C \{${ws}public:"
163 set re_fields "int f;${ws}int ff;"
164 set re_methods "F\\((void|)\\);${ws}int ffoo\\((void|)\\);${ws}int foo\\((void|)\\);"
165 set re_synth_gcc_23 "F & operator=\\(F const ?&\\);${ws}F\\(F const ?&\\);"
166 set re_all_methods "($re_methods|$re_methods${ws}$re_synth_gcc_23|$re_synth_gcc_23${ws}$re_methods)"
167
168 gdb_test_multiple "print f_instance" "print value of f_instance" {
169 -re "\\$\[0-9\]+ = \{<(class A|A)> = \{a = 1, aa = 2\}, <(class B|B)> = \{b = 3, bb = 4\}, <(class C|C)> = \{c = 5, cc = 6\}, f = 11, ff = 12\}$nl$gdb_prompt $" {
170 pass "print value of f_instance"
171 }
172 }
173
174 gdb_test_multiple "ptype f_instance" "ptype f_instance" {
175 -re "type = $re_class${ws}$re_fields${ws}$re_methods${ws}$re_synth_gcc_23$nl\}$nl$gdb_prompt $" {
176 pass "ptype f_instance"
177 }
178 -re "type = $re_class${ws}$re_fields${ws}$re_all_methods$nl\}$nl$gdb_prompt $" {
179 pass "ptype f_instance"
180 }
181 }
182
183 # Print individual fields.
184
185 gdb_test "print d_instance.a" "\\$\[0-9\]+ = 1" "print value of d_instance.a"
186 gdb_test "print d_instance.aa" "\\$\[0-9\]+ = 2" "print value of d_instance.aa"
187 gdb_test "print d_instance.b" "\\$\[0-9\]+ = 3" "print value of d_instance.b"
188 gdb_test "print d_instance.bb" "\\$\[0-9\]+ = 4" "print value of d_instance.bb"
189 gdb_test "print d_instance.c" "\\$\[0-9\]+ = 5" "print value of d_instance.c"
190 gdb_test "print d_instance.cc" "\\$\[0-9\]+ = 6" "print value of d_instance.cc"
191 gdb_test "print d_instance.d" "\\$\[0-9\]+ = 7" "print value of d_instance.d"
192 gdb_test "print d_instance.dd" "\\$\[0-9\]+ = 8" "print value of d_instance.dd"
193
194 # Print some fields which are defined in the top of class G
195 # and in its base classes. This is not be ambiguous.
196
197 gdb_test "print g_instance.a" "\\$\[0-9\]+ = 15" "print value of g_instance.a"
198 gdb_test "print g_instance.b" "\\$\[0-9\]+ = 16" "print value of g_instance.b"
199 gdb_test "print g_instance.c" "\\$\[0-9\]+ = 17" "print value of g_instance.c"
200
201 # Print a function call.
202
203 gdb_test "print g_instance.afoo()" "\\$\[0-9\]+ = 1" "print value of g_instance.afoo()"
204
205 # If GDB fails to restore the selected frame properly after the
206 # inferior function call above (see GDB PR 1155 for an explanation of
207 # why this might happen), all the subsequent tests will fail. We
208 # should detect report that failure, but let the marker call finish so
209 # that the rest of the tests can run undisturbed.
210
211 gdb_test_multiple "frame" "re-selected 'main' frame after inferior call" {
212 -re "#0 marker1.*$gdb_prompt $" {
213 setup_kfail "gdb/1155" s390-*-linux-gnu
214 fail "re-selected 'main' frame after inferior call"
215 gdb_test "finish" ".*main.*at .*derivation.cc:.*// marker1-returns-here.*" \
216 "finish call to marker1"
217 }
218 -re "#1 ($hex in )?main.*$gdb_prompt $" {
219 pass "re-selected 'main' frame after inferior call"
220 }
221 }
222
223 gdb_test "print g_instance.bfoo()" "\\$\[0-9\]+ = 2" "print value of g_instance.bfoo()"
224 gdb_test "print g_instance.cfoo()" "\\$\[0-9\]+ = 3" "print value of g_instance.cfoo()"
This page took 0.047683 seconds and 4 git commands to generate.