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

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