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

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