]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.cp/derivation.exp
Copyright updates for 2007.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.cp / derivation.exp
CommitLineData
6aba47ca 1# Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2007
6b7a4c0e 2# Free Software Foundation, Inc.
c906108c
SS
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
c906108c 18# This file was written by Elena Zannoni (ezannoni@cygnus.com)
6b7a4c0e 19# And rewritten by Michael Chastain <mec.gnu@mindspring.com>
c906108c
SS
20
21# This file is part of the gdb testsuite
c906108c 22
6b7a4c0e
MC
23# tests for inheritance, with several derivations types combinations
24# (private, public, protected)
c906108c 25# classes have simple members and member functions.
c906108c 26
6b7a4c0e
MC
27set ws "\[\r\n\t \]+"
28set nl "\[\r\n\]+"
c906108c
SS
29
30if $tracelevel then {
6b7a4c0e
MC
31 strace $tracelevel
32}
33
34# Start program.
c906108c 35
c906108c
SS
36set prms_id 0
37set bug_id 0
38
d4f3574e
SS
39if { [skip_cplus_tests] } { continue }
40
78c90502
MC
41load_lib "cp-support.exp"
42
c906108c
SS
43set testfile "derivation"
44set srcfile ${testfile}.cc
45set binfile ${objdir}/${subdir}/${testfile}
46
47if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
b60f0898
JB
48 untested derivation.exp
49 return -1
c906108c
SS
50}
51
52gdb_exit
53gdb_start
54gdb_reinitialize_dir $srcdir/$subdir
55gdb_load ${binfile}
c906108c 56
6b7a4c0e 57# Set it up at a breakpoint so we can play with the variable values.
c906108c 58
f266096b
MC
59if ![runto 'marker1'] then {
60 perror "couldn't run to marker1"
61 continue
62}
63
64gdb_test "up" ".*main.*" "up from marker1"
c906108c 65
6b7a4c0e 66# Print class types and values.
c906108c 67
6b7a4c0e 68# class A
c906108c 69
184ad485
MC
70gdb_test "print a_instance" "\\$\[0-9\]+ = \{a = 1, aa = 2\}" "print value of a_instance"
71
78c90502
MC
72cp_test_ptype_class \
73 "ptype a_instance" "" "class" "A" \
74 {
75 { field public "int a;" }
76 { field public "int aa;" }
77 { method public "A();" }
78 { method public "int afoo();" }
79 { method public "int foo();" }
184ad485 80 }
c906108c 81
6b7a4c0e
MC
82# class D
83
184ad485
MC
84gdb_test_multiple "print d_instance" "print value of d_instance" {
85 -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 $" {
86 pass "print value of d_instance"
87 }
88}
89
78c90502
MC
90cp_test_ptype_class \
91 "ptype d_instance" "" "class" "D" \
92 {
93 { base "private A" }
94 { base "public B" }
95 { base "protected C" }
96 { field public "int d;" }
97 { field public "int dd;" }
98 { method public "D();" }
99 { method public "int dfoo();" }
100 { method public "int foo();" }
101 } \
102 "" \
103 {
104 { "protected C" "private C" { setup_xfail "*-*-*" "gcc/13539" } }
6b7a4c0e 105 }
c906108c 106
6b7a4c0e 107# class E
c906108c 108
184ad485
MC
109gdb_test_multiple "print e_instance" "print value of e_instance" {
110 -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 $" {
111 pass "print value of e_instance"
112 }
113}
114
78c90502
MC
115cp_test_ptype_class \
116 "ptype e_instance" "" "class" "E" \
117 {
118 { base "public A" }
119 { base "private B" }
120 { base "protected C" }
121 { field public "int e;" }
122 { field public "int ee;" }
123 { method public "E();" }
124 { method public "int efoo();" }
125 { method public "int foo();" }
126 } \
127 "" \
128 {
129 { "protected C" "private C" { setup_xfail "*-*-*" "gcc/13539" } }
adf40b2e 130 }
6b7a4c0e
MC
131
132# class F
c906108c 133
6b7a4c0e
MC
134gdb_test_multiple "print f_instance" "print value of f_instance" {
135 -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 $" {
136 pass "print value of f_instance"
137 }
138}
139
78c90502
MC
140cp_test_ptype_class \
141 "ptype f_instance" "" "class" "F" \
142 {
143 { base "private A" }
144 { base "public B" }
145 { base "private C" }
146 { field public "int f;" }
147 { field public "int ff;" }
148 { method public "F();" }
149 { method public "int ffoo();" }
150 { method public "int foo();" }
184ad485 151 }
184ad485 152
6b7a4c0e
MC
153# Print individual fields.
154
155gdb_test "print d_instance.a" "\\$\[0-9\]+ = 1" "print value of d_instance.a"
156gdb_test "print d_instance.aa" "\\$\[0-9\]+ = 2" "print value of d_instance.aa"
157gdb_test "print d_instance.b" "\\$\[0-9\]+ = 3" "print value of d_instance.b"
158gdb_test "print d_instance.bb" "\\$\[0-9\]+ = 4" "print value of d_instance.bb"
159gdb_test "print d_instance.c" "\\$\[0-9\]+ = 5" "print value of d_instance.c"
160gdb_test "print d_instance.cc" "\\$\[0-9\]+ = 6" "print value of d_instance.cc"
161gdb_test "print d_instance.d" "\\$\[0-9\]+ = 7" "print value of d_instance.d"
162gdb_test "print d_instance.dd" "\\$\[0-9\]+ = 8" "print value of d_instance.dd"
163
164# Print some fields which are defined in the top of class G
165# and in its base classes. This is not be ambiguous.
166
167gdb_test "print g_instance.a" "\\$\[0-9\]+ = 15" "print value of g_instance.a"
168gdb_test "print g_instance.b" "\\$\[0-9\]+ = 16" "print value of g_instance.b"
169gdb_test "print g_instance.c" "\\$\[0-9\]+ = 17" "print value of g_instance.c"
170
171# Print a function call.
172
173gdb_test "print g_instance.afoo()" "\\$\[0-9\]+ = 1" "print value of g_instance.afoo()"
5624293a
JB
174
175# If GDB fails to restore the selected frame properly after the
176# inferior function call above (see GDB PR 1155 for an explanation of
177# why this might happen), all the subsequent tests will fail. We
178# should detect report that failure, but let the marker call finish so
179# that the rest of the tests can run undisturbed.
6b7a4c0e 180
5624293a
JB
181gdb_test_multiple "frame" "re-selected 'main' frame after inferior call" {
182 -re "#0 marker1.*$gdb_prompt $" {
183 setup_kfail "gdb/1155" s390-*-linux-gnu
184 fail "re-selected 'main' frame after inferior call"
93201743 185 gdb_test "finish" ".*main.*at .*derivation.cc:.*// marker1-returns-here.*" \
5624293a
JB
186 "finish call to marker1"
187 }
188 -re "#1 ($hex in )?main.*$gdb_prompt $" {
189 pass "re-selected 'main' frame after inferior call"
190 }
191}
6b7a4c0e
MC
192
193gdb_test "print g_instance.bfoo()" "\\$\[0-9\]+ = 2" "print value of g_instance.bfoo()"
194gdb_test "print g_instance.cfoo()" "\\$\[0-9\]+ = 3" "print value of g_instance.cfoo()"