Fix https://bugzilla.redhat.com/show_bug.cgi?id=849357
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.cp / derivation.exp
1 # Copyright 1998-2004, 2007-2012 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 3 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, see <http://www.gnu.org/licenses/>.
15
16 # This file was written by Elena Zannoni (ezannoni@cygnus.com)
17 # And rewritten by Michael Chastain <mec.gnu@mindspring.com>
18
19 # This file is part of the gdb testsuite
20
21 # tests for inheritance, with several derivations types combinations
22 # (private, public, protected)
23 # classes have simple members and member functions.
24
25 set ws "\[\r\n\t \]+"
26 set nl "\[\r\n\]+"
27
28 # Start program.
29
30
31 if { [skip_cplus_tests] } { continue }
32
33 load_lib "cp-support.exp"
34
35 standard_testfile .cc
36
37 if {[prepare_for_testing $testfile.exp $testfile $srcfile {debug c++}]} {
38 return -1
39 }
40
41 # Set it up at a breakpoint so we can play with the variable values.
42
43 if ![runto 'marker1'] then {
44 perror "couldn't run to marker1"
45 continue
46 }
47
48 gdb_test "up" ".*main.*" "up from marker1"
49
50 # Print class types and values.
51
52 # class A
53
54 gdb_test "print a_instance" "\\$\[0-9\]+ = \{a = 1, aa = 2\}" "print value of a_instance"
55
56 cp_test_ptype_class \
57 "ptype a_instance" "" "class" "A" \
58 {
59 { field public "int a;" }
60 { field public "int aa;" }
61 { method public "A();" }
62 { method public "int afoo();" }
63 { method public "int foo();" }
64 }
65
66 # class D
67
68 gdb_test_multiple "print d_instance" "print value of d_instance" {
69 -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 $" {
70 pass "print value of d_instance"
71 }
72 }
73
74 cp_test_ptype_class \
75 "ptype d_instance" "" "class" "D" \
76 {
77 { base "private A" }
78 { base "public B" }
79 { base "protected C" }
80 { field public "int d;" }
81 { field public "int dd;" }
82 { method public "D();" }
83 { method public "int dfoo();" }
84 { method public "int foo();" }
85 } \
86 "" \
87 {
88 { "protected C" "private C" { setup_xfail "*-*-*" "gcc/13539" } }
89 }
90
91 # class E
92
93 gdb_test_multiple "print e_instance" "print value of e_instance" {
94 -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 $" {
95 pass "print value of e_instance"
96 }
97 }
98
99 cp_test_ptype_class \
100 "ptype e_instance" "" "class" "E" \
101 {
102 { base "public A" }
103 { base "private B" }
104 { base "protected C" }
105 { field public "int e;" }
106 { field public "int ee;" }
107 { method public "E();" }
108 { method public "int efoo();" }
109 { method public "int foo();" }
110 } \
111 "" \
112 {
113 { "protected C" "private C" { setup_xfail "*-*-*" "gcc/13539" } }
114 }
115
116 # class F
117
118 gdb_test_multiple "print f_instance" "print value of f_instance" {
119 -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 $" {
120 pass "print value of f_instance"
121 }
122 }
123
124 cp_test_ptype_class \
125 "ptype f_instance" "" "class" "F" \
126 {
127 { base "private A" }
128 { base "public B" }
129 { base "private C" }
130 { field public "int f;" }
131 { field public "int ff;" }
132 { method public "F();" }
133 { method public "int ffoo();" }
134 { method public "int foo();" }
135 }
136
137 # Print individual fields.
138
139 gdb_test "print d_instance.a" "\\$\[0-9\]+ = 1" "print value of d_instance.a"
140 gdb_test "print d_instance.aa" "\\$\[0-9\]+ = 2" "print value of d_instance.aa"
141 gdb_test "print d_instance.b" "\\$\[0-9\]+ = 3" "print value of d_instance.b"
142 gdb_test "print d_instance.bb" "\\$\[0-9\]+ = 4" "print value of d_instance.bb"
143 gdb_test "print d_instance.c" "\\$\[0-9\]+ = 5" "print value of d_instance.c"
144 gdb_test "print d_instance.cc" "\\$\[0-9\]+ = 6" "print value of d_instance.cc"
145 gdb_test "print d_instance.d" "\\$\[0-9\]+ = 7" "print value of d_instance.d"
146 gdb_test "print d_instance.dd" "\\$\[0-9\]+ = 8" "print value of d_instance.dd"
147
148 # Print some fields which are defined in the top of class G
149 # and in its base classes. This is not be ambiguous.
150
151 gdb_test "print g_instance.a" "\\$\[0-9\]+ = 15" "print value of g_instance.a"
152 gdb_test "print g_instance.b" "\\$\[0-9\]+ = 16" "print value of g_instance.b"
153 gdb_test "print g_instance.c" "\\$\[0-9\]+ = 17" "print value of g_instance.c"
154
155 # Print a function call.
156
157 gdb_test "print g_instance.afoo()" "\\$\[0-9\]+ = 1" "print value of g_instance.afoo()"
158
159 # If GDB fails to restore the selected frame properly after the
160 # inferior function call above (see GDB PR 1155 for an explanation of
161 # why this might happen), all the subsequent tests will fail. We
162 # should detect report that failure, but let the marker call finish so
163 # that the rest of the tests can run undisturbed.
164
165 gdb_test_multiple "frame" "re-selected 'main' frame after inferior call" {
166 -re "#0 marker1.*$gdb_prompt $" {
167 setup_kfail "gdb/1155" s390-*-linux-gnu
168 fail "re-selected 'main' frame after inferior call"
169 gdb_test "finish" ".*main.*at .*derivation.cc:.*// marker1-returns-here.*" \
170 "finish call to marker1"
171 }
172 -re "#1 ($hex in )?main.*$gdb_prompt $" {
173 pass "re-selected 'main' frame after inferior call"
174 }
175 }
176
177 gdb_test "print g_instance.bfoo()" "\\$\[0-9\]+ = 2" "print value of g_instance.bfoo()"
178 gdb_test "print g_instance.cfoo()" "\\$\[0-9\]+ = 3" "print value of g_instance.cfoo()"
179
180 # This is a regression test for a bug that caused a crash when trying
181 # to print the vtbl pointer. We don't care about the output so much
182 # here (it is tested elsewhere), just that gdb doesn't crash. We test
183 # "ptype" first because, before the gdb fix, that was the only code
184 # path calling get_vptr_fieldno.
185 gdb_test "ptype vderived" "type = .*"
186 gdb_test "print vderived" " = {.* inter = 0.*x = 0}"
This page took 0.036957 seconds and 4 git commands to generate.