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