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

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