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