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

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