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

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