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