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