Blame SOURCES/gdb-6.3-test-dtorfix-20050121.patch

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