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

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