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