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

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