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

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