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
6 +/* This testcase is part of GDB, the GNU debugger.
8 + Copyright 2005 Free Software Foundation, Inc.
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.
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.
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. */
43 +/* C and D are for the $delete destructor. */
62 +int main(int argc, char *argv[])
73 +A::A() /* Constructor A */
75 + x = 1; /* First line A */
76 + k = 4; /* Second line A */
79 +A::~A() /* Destructor A */
81 + x = 3; /* First line ~A */
82 + k = 6; /* Second line ~A */
87 + y = 2; /* First line B */
91 +C::C() /* Constructor C */
93 + x = 1; /* First line C */
96 +C::~C() /* Destructor C */
98 + x = 3; /* First line ~C */
103 + y = 2; /* First line D */
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
110 +# This testcase is part of GDB, the GNU debugger.
112 +# Copyright 2005, 2007 Free Software Foundation, Inc.
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.
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.
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.
128 +# Check that GDB can break at multiple forms of constructors.
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
135 +if {[gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++ "additional_flags=-fpie -pie"}] != "" } {
141 +gdb_reinitialize_dir $srcdir/$subdir
145 +# Run to `main' where we begin our tests.
148 +if ![runto_main] then {
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"
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"
163 +# Now do the same for destructors
164 +gdb_test "break 'A::~A()'" ""
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"
174 +# Verify that we can break by line number in a constructor and find
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"]
180 +# " (2 locations)" is displayed depending on G++ version.
181 +gdb_test "break $second_line" "Breakpoint .*, line $second_line\\..*" "break by line in constructor"
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"
187 +# Verify that we can break by line number in a destructor and find
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"]
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"
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"
203 +# Test now the $delete destructors.
208 +set first_line_dtor [gdb_get_line_number "First line ~C"]
209 +set define_line_dtor [gdb_get_line_number "Destructor C"]
210 +# Break on the various forms of the C::~C destructor
211 +# " ([23] locations)" is displayed depending on G++ version.
212 +gdb_test "break C\:\:~C" "Breakpoint .*: C::~C\\. \\(2 locations\\)" "breaking on C::~C"
213 +gdb_continue_to_breakpoint "First line ~C"
215 +# Verify that we can break by line number in a destructor and find
216 +# the $delete occurence
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"
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.
228 +if ![gdb_breakpoint main] {
232 +set test "running to main"
233 +gdb_test_multiple "" $test {
234 + -re "Breakpoint \[0-9\]*, main .*$gdb_prompt $" {
239 +gdb_continue_to_breakpoint "First line ~C"