]>
Commit | Line | Data |
---|---|---|
f412e1b4 PS |
1 | Index: gdb-7.4.50.20111219/gdb/testsuite/gdb.cp/constructortest.cc |
2 | =================================================================== | |
3 | --- /dev/null 1970-01-01 00:00:00.000000000 +0000 | |
4 | +++ gdb-7.4.50.20111219/gdb/testsuite/gdb.cp/constructortest.cc 2011-12-19 22:05:02.825431735 +0100 | |
3a58abaf AM |
5 | @@ -0,0 +1,99 @@ |
6 | +/* This testcase is part of GDB, the GNU debugger. | |
7 | + | |
8 | + Copyright 2005 Free Software Foundation, Inc. | |
9 | + | |
10 | + This program is free software; you can redistribute it and/or modify | |
11 | + it under the terms of the GNU General Public License as published by | |
12 | + the Free Software Foundation; either version 2 of the License, or | |
13 | + (at your option) any later version. | |
14 | + | |
15 | + This program is distributed in the hope that it will be useful, | |
16 | + but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | + GNU General Public License for more details. | |
19 | + | |
20 | + You should have received a copy of the GNU General Public License | |
21 | + along with this program; if not, write to the Free Software | |
22 | + Foundation, Inc., 59 Temple Place - Suite 330, | |
23 | + Boston, MA 02111-1307, USA. */ | |
24 | + | |
25 | +class A | |
26 | +{ | |
27 | + public: | |
28 | + A(); | |
29 | + ~A(); | |
30 | + int k; | |
31 | + private: | |
32 | + int x; | |
33 | +}; | |
34 | + | |
35 | +class B: public A | |
36 | +{ | |
37 | + public: | |
38 | + B(); | |
39 | + private: | |
40 | + int y; | |
41 | +}; | |
42 | + | |
43 | +/* C and D are for the $delete destructor. */ | |
44 | + | |
45 | +class C | |
46 | +{ | |
47 | + public: | |
48 | + C(); | |
49 | + virtual ~C(); | |
50 | + private: | |
51 | + int x; | |
52 | +}; | |
53 | + | |
54 | +class D: public C | |
55 | +{ | |
56 | + public: | |
57 | + D(); | |
58 | + private: | |
59 | + int y; | |
60 | +}; | |
61 | + | |
62 | +int main(int argc, char *argv[]) | |
63 | +{ | |
64 | + A* a = new A; | |
65 | + B* b = new B; | |
66 | + D* d = new D; | |
67 | + delete a; | |
68 | + delete b; | |
69 | + delete d; | |
70 | + return 0; | |
71 | +} | |
72 | + | |
73 | +A::A() /* Constructor A */ | |
74 | +{ | |
75 | + x = 1; /* First line A */ | |
76 | + k = 4; /* Second line A */ | |
77 | +} | |
78 | + | |
79 | +A::~A() /* Destructor A */ | |
80 | +{ | |
81 | + x = 3; /* First line ~A */ | |
82 | + k = 6; /* Second line ~A */ | |
83 | +} | |
84 | + | |
85 | +B::B() | |
86 | +{ | |
87 | + y = 2; /* First line B */ | |
88 | + k = 5; | |
89 | +} | |
90 | + | |
91 | +C::C() /* Constructor C */ | |
92 | +{ | |
93 | + x = 1; /* First line C */ | |
94 | +} | |
95 | + | |
96 | +C::~C() /* Destructor C */ | |
97 | +{ | |
98 | + x = 3; /* First line ~C */ | |
99 | +} | |
100 | + | |
101 | +D::D() | |
102 | +{ | |
103 | + y = 2; /* First line D */ | |
104 | +} | |
f412e1b4 PS |
105 | Index: gdb-7.4.50.20111219/gdb/testsuite/gdb.cp/constructortest.exp |
106 | =================================================================== | |
107 | --- /dev/null 1970-01-01 00:00:00.000000000 +0000 | |
108 | +++ gdb-7.4.50.20111219/gdb/testsuite/gdb.cp/constructortest.exp 2011-12-19 23:07:24.148290893 +0100 | |
51a5ef0f | 109 | @@ -0,0 +1,130 @@ |
3a58abaf AM |
110 | +# This testcase is part of GDB, the GNU debugger. |
111 | + | |
112 | +# Copyright 2005, 2007 Free Software Foundation, Inc. | |
113 | + | |
114 | +# This program is free software; you can redistribute it and/or modify | |
115 | +# it under the terms of the GNU General Public License as published by | |
116 | +# the Free Software Foundation; either version 2 of the License, or | |
117 | +# (at your option) any later version. | |
118 | +# | |
119 | +# This program is distributed in the hope that it will be useful, | |
120 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
121 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
122 | +# GNU General Public License for more details. | |
123 | +# | |
124 | +# You should have received a copy of the GNU General Public License | |
125 | +# along with this program; if not, write to the Free Software | |
126 | +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
127 | + | |
128 | +# Check that GDB can break at multiple forms of constructors. | |
129 | + | |
3a58abaf AM |
130 | +set testfile "constructortest" |
131 | +set srcfile ${testfile}.cc | |
132 | +set binfile ${objdir}/${subdir}/${testfile} | |
133 | +# PIE is required for testing proper BREAKPOINT_RE_SET of the multiple-PC | |
134 | +# breakpoints. | |
135 | +if {[gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++ "additional_flags=-fpie -pie"}] != "" } { | |
136 | + return -1 | |
137 | +} | |
138 | + | |
139 | +gdb_exit | |
140 | +gdb_start | |
141 | +gdb_reinitialize_dir $srcdir/$subdir | |
142 | +gdb_load ${binfile} | |
143 | + | |
144 | +# | |
145 | +# Run to `main' where we begin our tests. | |
146 | +# | |
147 | + | |
148 | +if ![runto_main] then { | |
149 | + gdb_suppress_tests | |
150 | +} | |
151 | + | |
51a5ef0f PS |
152 | +# Break on the various forms of the A::A constructor. |
153 | +# " (2 locations)" is displayed depending on G++ version. | |
154 | +gdb_test "break A\:\:A" "Breakpoint 2 at .*" "breaking on A::A" | |
3a58abaf AM |
155 | + |
156 | +# Verify that we break for the A constructor two times | |
157 | +# Once for new A and once for new B | |
158 | +gdb_continue_to_breakpoint "First line A" | |
159 | +gdb_test "bt" "#0.*A.*#1.*main.*" "Verify in in-charge A::A" | |
160 | +gdb_continue_to_breakpoint "First line A" | |
161 | +gdb_test "bt" "#0.*A.*#1.*B.*#2.*main.*" "Verify in not-in-charge A::A" | |
162 | + | |
163 | +# Now do the same for destructors | |
164 | +gdb_test "break 'A::~A()'" "" | |
165 | + | |
166 | +# Verify that we break for the A destructor two times | |
167 | +# Once for delete a and once for delete b | |
168 | +gdb_continue_to_breakpoint "First line ~A" | |
169 | +gdb_test "bt" "#0.*~A.*#1.*main.*" "Verify in in-charge A::~A" | |
170 | +gdb_continue_to_breakpoint "First line ~A" | |
171 | +gdb_test "bt" "#0.*~A.*#1.*~B.*#2.*main.*" "Verify in not-in-charge A::~A" | |
172 | + | |
173 | + | |
174 | +# Verify that we can break by line number in a constructor and find | |
175 | +# both occurrences | |
176 | +runto_main | |
177 | +gdb_test "break 'A::A()'" "" "break in constructor A 2" | |
178 | +gdb_continue_to_breakpoint "First line A" | |
179 | +set second_line [gdb_get_line_number "Second line A"] | |
51a5ef0f PS |
180 | +# " (2 locations)" is displayed depending on G++ version. |
181 | +gdb_test "break $second_line" "Breakpoint .*, line $second_line\\..*" "break by line in constructor" | |
3a58abaf AM |
182 | +gdb_continue_to_breakpoint "Second line A" |
183 | +gdb_test "bt" "#0.*A.*#1.*main.*" "Verify in in-charge A::A second line" | |
184 | +gdb_continue_to_breakpoint "Second line A" | |
185 | +gdb_test "bt" "#0.*A.*#1.*B.*#2.*main.*" "Verify in not-in-charge A::A second line" | |
186 | + | |
187 | +# Verify that we can break by line number in a destructor and find | |
188 | +# both occurrences | |
189 | +gdb_test "break 'A::~A()'" "" "break in constructor ~A 2" | |
190 | +gdb_continue_to_breakpoint "First line ~A" | |
191 | +set second_line_dtor [gdb_get_line_number "Second line ~A"] | |
51a5ef0f PS |
192 | +# " (2 locations)" is displayed depending on G++ version. |
193 | +gdb_test "break $second_line_dtor" "Breakpoint .*, line $second_line_dtor\\..*" "break by line in destructor" | |
3a58abaf AM |
194 | +gdb_continue_to_breakpoint "Second line ~A" |
195 | +gdb_test "bt" "#0.*A.*#1.*main.*" "Verify in in-charge A::~A second line" | |
196 | +# FIXME: Analyse this case better. | |
197 | +gdb_continue_to_breakpoint "Second line ~A" | |
198 | +gdb_test "bt" "#0.*A.*#1.*main.*" "Verify in A::~A second line #2" | |
199 | +gdb_continue_to_breakpoint "Second line ~A" | |
200 | +gdb_test "bt" "#0.*A.*#1.*B.*#2.*main.*" "Verify in not-in-charge A::~A second line" | |
201 | + | |
202 | + | |
203 | +# Test now the $delete destructors. | |
204 | + | |
205 | +gdb_load ${binfile} | |
206 | +runto_main | |
207 | + | |
51a5ef0f PS |
208 | +set first_line_dtor [gdb_get_line_number "First line ~C"] |
209 | +set define_line_dtor [gdb_get_line_number "Destructor C"] | |
3a58abaf | 210 | +# Break on the various forms of the C::~C destructor |
51a5ef0f | 211 | +# " ([23] locations)" is displayed depending on G++ version. |
f412e1b4 | 212 | +gdb_test "break C\:\:~C" "Breakpoint .*: C::~C\\. \\(2 locations\\)" "breaking on C::~C" |
3a58abaf AM |
213 | +gdb_continue_to_breakpoint "First line ~C" |
214 | + | |
215 | +# Verify that we can break by line number in a destructor and find | |
216 | +# the $delete occurence | |
217 | + | |
218 | +gdb_load ${binfile} | |
219 | +delete_breakpoints | |
220 | + | |
51a5ef0f PS |
221 | +# " (3 locations)" is displayed depending on G++ version. |
222 | +gdb_test "break $first_line_dtor" "Breakpoint .*, line $first_line_dtor\\..*" "break by line in destructor" | |
3a58abaf AM |
223 | + |
224 | +# Run to `main' where we begin our tests. | |
225 | +# Set the breakpoints first to test PIE multiple-PC BREAKPOINT_RE_SET. | |
226 | +# RUNTO_MAIN or RUNTO MAIN are not usable here as it runs DELETE_BREAKPOINTS. | |
227 | + | |
228 | +if ![gdb_breakpoint main] { | |
229 | + gdb_suppress_tests | |
230 | +} | |
231 | +gdb_run_cmd | |
232 | +set test "running to main" | |
233 | +gdb_test_multiple "" $test { | |
234 | + -re "Breakpoint \[0-9\]*, main .*$gdb_prompt $" { | |
235 | + pass $test | |
236 | + } | |
237 | +} | |
238 | + | |
239 | +gdb_continue_to_breakpoint "First line ~C" |