|
|
e1d87d |
Index: gdb-7.10.90.20160211/gdb/testsuite/gdb.cp/constructortest.cc
|
|
|
e1d87d |
===================================================================
|
|
|
e1d87d |
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
|
|
|
e1d87d |
+++ gdb-7.10.90.20160211/gdb/testsuite/gdb.cp/constructortest.cc 2016-02-16 09:49:08.681886201 +0100
|
|
|
e1d87d |
@@ -0,0 +1,99 @@
|
|
|
e1d87d |
+/* This testcase is part of GDB, the GNU debugger.
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+ Copyright 2005 Free Software Foundation, Inc.
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+ This program is free software; you can redistribute it and/or modify
|
|
|
e1d87d |
+ it under the terms of the GNU General Public License as published by
|
|
|
e1d87d |
+ the Free Software Foundation; either version 2 of the License, or
|
|
|
e1d87d |
+ (at your option) any later version.
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+ This program is distributed in the hope that it will be useful,
|
|
|
e1d87d |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
e1d87d |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
e1d87d |
+ GNU General Public License for more details.
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+ You should have received a copy of the GNU General Public License
|
|
|
e1d87d |
+ along with this program; if not, write to the Free Software
|
|
|
e1d87d |
+ Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
e1d87d |
+ Boston, MA 02111-1307, USA. */
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+class A
|
|
|
e1d87d |
+{
|
|
|
e1d87d |
+ public:
|
|
|
e1d87d |
+ A();
|
|
|
e1d87d |
+ ~A();
|
|
|
e1d87d |
+ int k;
|
|
|
e1d87d |
+ private:
|
|
|
e1d87d |
+ int x;
|
|
|
e1d87d |
+};
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+class B: public A
|
|
|
e1d87d |
+{
|
|
|
e1d87d |
+ public:
|
|
|
e1d87d |
+ B();
|
|
|
e1d87d |
+ private:
|
|
|
e1d87d |
+ int y;
|
|
|
e1d87d |
+};
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+/* C and D are for the $delete destructor. */
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+class C
|
|
|
e1d87d |
+{
|
|
|
e1d87d |
+ public:
|
|
|
e1d87d |
+ C();
|
|
|
e1d87d |
+ virtual ~C();
|
|
|
e1d87d |
+ private:
|
|
|
e1d87d |
+ int x;
|
|
|
e1d87d |
+};
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+class D: public C
|
|
|
e1d87d |
+{
|
|
|
e1d87d |
+ public:
|
|
|
e1d87d |
+ D();
|
|
|
e1d87d |
+ private:
|
|
|
e1d87d |
+ int y;
|
|
|
e1d87d |
+};
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+int main(int argc, char *argv[])
|
|
|
e1d87d |
+{
|
|
|
e1d87d |
+ A* a = new A;
|
|
|
e1d87d |
+ B* b = new B;
|
|
|
e1d87d |
+ D* d = new D;
|
|
|
e1d87d |
+ delete a;
|
|
|
e1d87d |
+ delete b;
|
|
|
e1d87d |
+ delete d;
|
|
|
e1d87d |
+ return 0;
|
|
|
e1d87d |
+}
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+A::A() /* Constructor A */
|
|
|
e1d87d |
+{
|
|
|
e1d87d |
+ x = 1; /* First line A */
|
|
|
e1d87d |
+ k = 4; /* Second line A */
|
|
|
e1d87d |
+}
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+A::~A() /* Destructor A */
|
|
|
e1d87d |
+{
|
|
|
e1d87d |
+ x = 3; /* First line ~A */
|
|
|
e1d87d |
+ k = 6; /* Second line ~A */
|
|
|
e1d87d |
+}
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+B::B()
|
|
|
e1d87d |
+{
|
|
|
e1d87d |
+ y = 2; /* First line B */
|
|
|
e1d87d |
+ k = 5;
|
|
|
e1d87d |
+}
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+C::C() /* Constructor C */
|
|
|
e1d87d |
+{
|
|
|
e1d87d |
+ x = 1; /* First line C */
|
|
|
e1d87d |
+}
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+C::~C() /* Destructor C */
|
|
|
e1d87d |
+{
|
|
|
e1d87d |
+ x = 3; /* First line ~C */
|
|
|
e1d87d |
+}
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+D::D()
|
|
|
e1d87d |
+{
|
|
|
e1d87d |
+ y = 2; /* First line D */
|
|
|
e1d87d |
+}
|
|
|
e1d87d |
Index: gdb-7.10.90.20160211/gdb/testsuite/gdb.cp/constructortest.exp
|
|
|
e1d87d |
===================================================================
|
|
|
e1d87d |
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
|
|
|
e1d87d |
+++ gdb-7.10.90.20160211/gdb/testsuite/gdb.cp/constructortest.exp 2016-02-16 09:52:12.609130779 +0100
|
|
|
e1d87d |
@@ -0,0 +1,130 @@
|
|
|
e1d87d |
+# This testcase is part of GDB, the GNU debugger.
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+# Copyright 2005, 2007 Free Software Foundation, Inc.
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+# This program is free software; you can redistribute it and/or modify
|
|
|
e1d87d |
+# it under the terms of the GNU General Public License as published by
|
|
|
e1d87d |
+# the Free Software Foundation; either version 2 of the License, or
|
|
|
e1d87d |
+# (at your option) any later version.
|
|
|
e1d87d |
+#
|
|
|
e1d87d |
+# This program is distributed in the hope that it will be useful,
|
|
|
e1d87d |
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
e1d87d |
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
e1d87d |
+# GNU General Public License for more details.
|
|
|
e1d87d |
+#
|
|
|
e1d87d |
+# You should have received a copy of the GNU General Public License
|
|
|
e1d87d |
+# along with this program; if not, write to the Free Software
|
|
|
e1d87d |
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+# Check that GDB can break at multiple forms of constructors.
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+set testfile "constructortest"
|
|
|
e1d87d |
+set srcfile ${testfile}.cc
|
|
|
e1d87d |
+set binfile [standard_output_file ${testfile}]
|
|
|
e1d87d |
+# PIE is required for testing proper BREAKPOINT_RE_SET of the multiple-PC
|
|
|
e1d87d |
+# breakpoints.
|
|
|
e1d87d |
+if {[gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++ "additional_flags=-fpie -pie"}] != "" } {
|
|
|
e1d87d |
+ return -1
|
|
|
e1d87d |
+}
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+gdb_exit
|
|
|
e1d87d |
+gdb_start
|
|
|
e1d87d |
+gdb_reinitialize_dir $srcdir/$subdir
|
|
|
e1d87d |
+gdb_load ${binfile}
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+#
|
|
|
e1d87d |
+# Run to `main' where we begin our tests.
|
|
|
e1d87d |
+#
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+if ![runto_main] then {
|
|
|
e1d87d |
+ gdb_suppress_tests
|
|
|
e1d87d |
+}
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+# Break on the various forms of the A::A constructor.
|
|
|
e1d87d |
+# " (2 locations)" is displayed depending on G++ version.
|
|
|
e1d87d |
+gdb_test "break A\:\:A" "Breakpoint 2 at .*" "breaking on A::A"
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+# Verify that we break for the A constructor two times
|
|
|
e1d87d |
+# Once for new A and once for new B
|
|
|
e1d87d |
+gdb_continue_to_breakpoint "First line A"
|
|
|
e1d87d |
+gdb_test "bt" "#0.*A.*#1.*main.*" "Verify in in-charge A::A"
|
|
|
e1d87d |
+gdb_continue_to_breakpoint "First line A"
|
|
|
e1d87d |
+gdb_test "bt" "#0.*A.*#1.*B.*#2.*main.*" "Verify in not-in-charge A::A"
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+# Now do the same for destructors
|
|
|
e1d87d |
+gdb_test "break 'A::~A()'" ""
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+# Verify that we break for the A destructor two times
|
|
|
e1d87d |
+# Once for delete a and once for delete b
|
|
|
e1d87d |
+gdb_continue_to_breakpoint "First line ~A"
|
|
|
e1d87d |
+gdb_test "bt" "#0.*~A.*#1.*main.*" "Verify in in-charge A::~A"
|
|
|
e1d87d |
+gdb_continue_to_breakpoint "First line ~A"
|
|
|
e1d87d |
+gdb_test "bt" "#0.*~A.*#1.*~B.*#2.*main.*" "Verify in not-in-charge A::~A"
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+# Verify that we can break by line number in a constructor and find
|
|
|
e1d87d |
+# both occurrences
|
|
|
e1d87d |
+runto_main
|
|
|
e1d87d |
+gdb_test "break 'A::A()'" "" "break in constructor A 2"
|
|
|
e1d87d |
+gdb_continue_to_breakpoint "First line A"
|
|
|
e1d87d |
+set second_line [gdb_get_line_number "Second line A"]
|
|
|
e1d87d |
+# " (2 locations)" is displayed depending on G++ version.
|
|
|
e1d87d |
+gdb_test "break $second_line" "Breakpoint .*, line $second_line\\..*" "break by line in constructor"
|
|
|
e1d87d |
+gdb_continue_to_breakpoint "Second line A"
|
|
|
e1d87d |
+gdb_test "bt" "#0.*A.*#1.*main.*" "Verify in in-charge A::A second line"
|
|
|
e1d87d |
+gdb_continue_to_breakpoint "Second line A"
|
|
|
e1d87d |
+gdb_test "bt" "#0.*A.*#1.*B.*#2.*main.*" "Verify in not-in-charge A::A second line"
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+# Verify that we can break by line number in a destructor and find
|
|
|
e1d87d |
+# both occurrences
|
|
|
e1d87d |
+gdb_test "break 'A::~A()'" "" "break in constructor ~A 2"
|
|
|
e1d87d |
+gdb_continue_to_breakpoint "First line ~A"
|
|
|
e1d87d |
+set second_line_dtor [gdb_get_line_number "Second line ~A"]
|
|
|
e1d87d |
+# " (2 locations)" is displayed depending on G++ version.
|
|
|
e1d87d |
+gdb_test "break $second_line_dtor" "Breakpoint .*, line $second_line_dtor\\..*" "break by line in destructor"
|
|
|
e1d87d |
+gdb_continue_to_breakpoint "Second line ~A"
|
|
|
e1d87d |
+gdb_test "bt" "#0.*A.*#1.*main.*" "Verify in in-charge A::~A second line"
|
|
|
e1d87d |
+# FIXME: Analyse this case better.
|
|
|
e1d87d |
+gdb_continue_to_breakpoint "Second line ~A"
|
|
|
e1d87d |
+gdb_test "bt" "#0.*A.*#1.*main.*" "Verify in A::~A second line #2"
|
|
|
e1d87d |
+gdb_continue_to_breakpoint "Second line ~A"
|
|
|
e1d87d |
+gdb_test "bt" "#0.*A.*#1.*B.*#2.*main.*" "Verify in not-in-charge A::~A second line"
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+# Test now the $delete destructors.
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+gdb_load ${binfile}
|
|
|
e1d87d |
+runto_main
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+set first_line_dtor [gdb_get_line_number "First line ~C"]
|
|
|
e1d87d |
+set define_line_dtor [gdb_get_line_number "Destructor C"]
|
|
|
e1d87d |
+# Break on the various forms of the C::~C destructor
|
|
|
e1d87d |
+# " ([23] locations)" is displayed depending on G++ version.
|
|
|
e1d87d |
+gdb_test "break C\:\:~C" "Breakpoint .*: C::~C\\. \\(2 locations\\)" "breaking on C::~C"
|
|
|
e1d87d |
+gdb_continue_to_breakpoint "First line ~C"
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+# Verify that we can break by line number in a destructor and find
|
|
|
e1d87d |
+# the $delete occurence
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+gdb_load ${binfile}
|
|
|
e1d87d |
+delete_breakpoints
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+# " (3 locations)" is displayed depending on G++ version.
|
|
|
e1d87d |
+gdb_test "break $first_line_dtor" "Breakpoint .*, line $first_line_dtor\\..*" "break by line in destructor"
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+# Run to `main' where we begin our tests.
|
|
|
e1d87d |
+# Set the breakpoints first to test PIE multiple-PC BREAKPOINT_RE_SET.
|
|
|
e1d87d |
+# RUNTO_MAIN or RUNTO MAIN are not usable here as it runs DELETE_BREAKPOINTS.
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+if ![gdb_breakpoint main] {
|
|
|
e1d87d |
+ gdb_suppress_tests
|
|
|
e1d87d |
+}
|
|
|
e1d87d |
+gdb_run_cmd
|
|
|
e1d87d |
+set test "running to main"
|
|
|
e1d87d |
+gdb_test_multiple "" $test {
|
|
|
e1d87d |
+ -re "Breakpoint \[0-9\]*, main .*$gdb_prompt $" {
|
|
|
e1d87d |
+ pass $test
|
|
|
e1d87d |
+ }
|
|
|
e1d87d |
+}
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+gdb_continue_to_breakpoint "First line ~C"
|