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

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