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

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