Support R_SPARC_WDISP10 and R_SPARC_H34.
[external/binutils.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 set testfile "derivation"
36 set srcfile ${testfile}.cc
37 set binfile ${objdir}/${subdir}/${testfile}
38
39 if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
40      untested derivation.exp
41      return -1
42 }
43
44 gdb_exit
45 gdb_start
46 gdb_reinitialize_dir $srcdir/$subdir
47 gdb_load ${binfile}
48
49 # Set it up at a breakpoint so we can play with the variable values.
50
51 if ![runto 'marker1'] then {
52     perror "couldn't run to marker1"
53     continue
54 }
55
56 gdb_test "up" ".*main.*" "up from marker1"
57
58 # Print class types and values.
59
60 # class A
61
62 gdb_test "print a_instance" "\\$\[0-9\]+ = \{a = 1, aa = 2\}" "print value of a_instance"
63
64 cp_test_ptype_class \
65     "ptype a_instance" "" "class" "A" \
66     {
67         { field  public "int a;" }
68         { field  public "int aa;" }
69         { method public "A();" }
70         { method public "int afoo();" }
71         { method public "int foo();" }
72     }
73
74 # class D
75
76 gdb_test_multiple "print d_instance" "print value of d_instance" {
77     -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 $" {
78         pass "print value of d_instance"
79     }
80 }
81
82 cp_test_ptype_class \
83     "ptype d_instance" "" "class" "D" \
84     {
85         { base          "private A" }
86         { base          "public B" }
87         { base          "protected C" }
88         { field  public "int d;" }
89         { field  public "int dd;" }
90         { method public "D();" }
91         { method public "int dfoo();" }
92         { method public "int foo();" }
93     } \
94     "" \
95     {
96         { "protected C" "private C" { setup_xfail "*-*-*" "gcc/13539" } }
97     }
98
99 # class E
100
101 gdb_test_multiple "print e_instance" "print value of e_instance" {
102     -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 $" {
103         pass "print value of e_instance"
104     }
105 }
106
107 cp_test_ptype_class \
108     "ptype e_instance" "" "class" "E" \
109     {
110         { base          "public A" }
111         { base          "private B" }
112         { base          "protected C" }
113         { field  public "int e;" }
114         { field  public "int ee;" }
115         { method public "E();" }
116         { method public "int efoo();" }
117         { method public "int foo();" }
118     } \
119     "" \
120     {
121         { "protected C" "private C" { setup_xfail "*-*-*" "gcc/13539" } }
122     }
123
124 # class F
125
126 gdb_test_multiple "print f_instance" "print value of f_instance" {
127     -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 $" {
128         pass "print value of f_instance"
129     }
130 }
131
132 cp_test_ptype_class \
133     "ptype f_instance" "" "class" "F" \
134     {
135         { base          "private A" }
136         { base          "public B" }
137         { base          "private C" }
138         { field  public "int f;" }
139         { field  public "int ff;" }
140         { method public "F();" }
141         { method public "int ffoo();" }
142         { method public "int foo();" }
143     }
144
145 # Print individual fields.
146
147 gdb_test "print d_instance.a"  "\\$\[0-9\]+ = 1" "print value of d_instance.a"
148 gdb_test "print d_instance.aa" "\\$\[0-9\]+ = 2" "print value of d_instance.aa"
149 gdb_test "print d_instance.b"  "\\$\[0-9\]+ = 3" "print value of d_instance.b"
150 gdb_test "print d_instance.bb" "\\$\[0-9\]+ = 4" "print value of d_instance.bb"
151 gdb_test "print d_instance.c"  "\\$\[0-9\]+ = 5" "print value of d_instance.c"
152 gdb_test "print d_instance.cc" "\\$\[0-9\]+ = 6" "print value of d_instance.cc"
153 gdb_test "print d_instance.d"  "\\$\[0-9\]+ = 7" "print value of d_instance.d"
154 gdb_test "print d_instance.dd" "\\$\[0-9\]+ = 8" "print value of d_instance.dd"
155
156 # Print some fields which are defined in the top of class G
157 # and in its base classes.  This is not be ambiguous.
158
159 gdb_test "print g_instance.a"  "\\$\[0-9\]+ = 15" "print value of g_instance.a"
160 gdb_test "print g_instance.b"  "\\$\[0-9\]+ = 16" "print value of g_instance.b"
161 gdb_test "print g_instance.c"  "\\$\[0-9\]+ = 17" "print value of g_instance.c"
162
163 # Print a function call.
164
165 gdb_test "print g_instance.afoo()" "\\$\[0-9\]+ = 1" "print value of g_instance.afoo()"
166
167 # If GDB fails to restore the selected frame properly after the
168 # inferior function call above (see GDB PR 1155 for an explanation of
169 # why this might happen), all the subsequent tests will fail.  We
170 # should detect report that failure, but let the marker call finish so
171 # that the rest of the tests can run undisturbed.
172
173 gdb_test_multiple "frame" "re-selected 'main' frame after inferior call" {
174     -re "#0  marker1.*$gdb_prompt $" {
175         setup_kfail "gdb/1155" s390-*-linux-gnu
176         fail "re-selected 'main' frame after inferior call"
177         gdb_test "finish" ".*main.*at .*derivation.cc:.*// marker1-returns-here.*" \
178             "finish call to marker1"
179     }
180     -re "#1  ($hex in )?main.*$gdb_prompt $" {
181         pass "re-selected 'main' frame after inferior call"
182     }
183 }
184
185 gdb_test "print g_instance.bfoo()" "\\$\[0-9\]+ = 2" "print value of g_instance.bfoo()"
186 gdb_test "print g_instance.cfoo()" "\\$\[0-9\]+ = 3" "print value of g_instance.cfoo()"