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