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

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