6cc37db
Index: gdb/testsuite/ChangeLog
6cc37db
2005-01-21  Jeff Johnston  <jjohnstn@redhat.com>
6cc37db
6cc37db
	* gdb.cp/constructortest.exp: New test.
6cc37db
	* gdb.cp/constructortest.cc: Ditto.
6cc37db
	* gdb.cp/templates.exp: Change break of dtor to	be fully quoted.
6cc37db
6cc37db
--- gdb-6.3/gdb/testsuite/gdb.cp/constructortest.cc.fix	Fri Jan 21 17:06:56 2005
6cc37db
+++ gdb-6.3/gdb/testsuite/gdb.cp/constructortest.cc	Fri Jan 21 17:05:18 2005
6cc37db
@@ -0,0 +1,64 @@
6cc37db
+/* This testcase is part of GDB, the GNU debugger.
6cc37db
+
6cc37db
+   Copyright 2005 Free Software Foundation, Inc.
6cc37db
+
6cc37db
+   This program is free software; you can redistribute it and/or modify
6cc37db
+   it under the terms of the GNU General Public License as published by
6cc37db
+   the Free Software Foundation; either version 2 of the License, or
6cc37db
+   (at your option) any later version.
6cc37db
+
6cc37db
+   This program is distributed in the hope that it will be useful,
6cc37db
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
6cc37db
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
6cc37db
+   GNU General Public License for more details.
6cc37db
+
6cc37db
+   You should have received a copy of the GNU General Public License
6cc37db
+   along with this program; if not, write to the Free Software
6cc37db
+   Foundation, Inc., 59 Temple Place - Suite 330,
6cc37db
+   Boston, MA 02111-1307, USA.  */
6cc37db
+
6cc37db
+class A
6cc37db
+{
6cc37db
+  public:
6cc37db
+    A();
6cc37db
+    ~A();
6cc37db
+    int  k;
6cc37db
+  private:
6cc37db
+    int  x;
6cc37db
+};
6cc37db
+
6cc37db
+class B: public A
6cc37db
+{
6cc37db
+  public:
6cc37db
+    B();
6cc37db
+  private:
6cc37db
+    int  y;
6cc37db
+};
6cc37db
+
6cc37db
+int main(int argc, char *argv[])
6cc37db
+{
6cc37db
+  A* a = new A;
6cc37db
+  B* b = new B;
6cc37db
+  delete a;
6cc37db
+  delete b;
6cc37db
+  return 0;
6cc37db
+}
6cc37db
+
6cc37db
+A::A() /* Constructor A */
6cc37db
+{
6cc37db
+   x = 1; /* First line A */
6cc37db
+   k = 4; /* Second line A */
6cc37db
+}
6cc37db
+
6cc37db
+A::~A() /* Destructor A */
6cc37db
+{
6cc37db
+   x = 3; /* First line ~A */
6cc37db
+   k = 6; /* Second line ~A */
6cc37db
+}
6cc37db
+
6cc37db
+B::B()
6cc37db
+{
6cc37db
+   y = 2; /* First line B */
6cc37db
+   k = 5;
6cc37db
+}
6cc37db
+
6cc37db
--- gdb-6.3/gdb/testsuite/gdb.cp/constructortest.exp.fix	Fri Jan 21 17:07:02 2005
6cc37db
+++ gdb-6.3/gdb/testsuite/gdb.cp/constructortest.exp	Fri Jan 21 17:05:29 2005
6cc37db
@@ -0,0 +1,98 @@
6cc37db
+# This testcase is part of GDB, the GNU debugger.
6cc37db
+
6cc37db
+# Copyright 2005 Free Software Foundation, Inc.
6cc37db
+
6cc37db
+# This program is free software; you can redistribute it and/or modify
6cc37db
+# it under the terms of the GNU General Public License as published by
6cc37db
+# the Free Software Foundation; either version 2 of the License, or
6cc37db
+# (at your option) any later version.
6cc37db
+#
6cc37db
+# This program is distributed in the hope that it will be useful,
6cc37db
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
6cc37db
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
6cc37db
+# GNU General Public License for more details.
6cc37db
+#
6cc37db
+# You should have received a copy of the GNU General Public License
6cc37db
+# along with this program; if not, write to the Free Software
6cc37db
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
6cc37db
+
6cc37db
+# Check that GDB can break at multiple forms of constructors.
6cc37db
+
6cc37db
+if $tracelevel {
6cc37db
+    strace $tracelevel
6cc37db
+}
6cc37db
+
6cc37db
+set prms_id 0
6cc37db
+set bug_id 0
6cc37db
+
6cc37db
+set testfile "constructortest"
6cc37db
+set srcfile ${testfile}.cc
6cc37db
+set binfile ${objdir}/${subdir}/${testfile}
6cc37db
+if {[gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
6cc37db
+    return -1
6cc37db
+}
6cc37db
+
6cc37db
+gdb_exit
6cc37db
+gdb_start
6cc37db
+gdb_reinitialize_dir $srcdir/$subdir
6cc37db
+gdb_load ${binfile}
6cc37db
+
6cc37db
+#
6cc37db
+# Run to `main' where we begin our tests.
6cc37db
+#
6cc37db
+
6cc37db
+if ![runto_main] then {
6cc37db
+    gdb_suppress_tests
6cc37db
+}
6cc37db
+
6cc37db
+# Break on the various forms of the A::A constructor
6cc37db
+gdb_test_multiple "break A\:\:A" "breaking on A::A" {
6cc37db
+  -re "0. cancel.*\[\r\n\]*.1. all.*\[\r\n\]*.2. A::A\\(\\) at .*\[\r\n\]*.3. A::A\\\$base\\(\\) at .*\[\r\n\]*> $" {
6cc37db
+            gdb_test "1" \
6cc37db
+                ".*Multiple breakpoints were set.*" \
6cc37db
+                "break on multiple constructors"
6cc37db
+  }
6cc37db
+}
6cc37db
+        
6cc37db
+# Verify that we break for the A constructor two times
6cc37db
+# Once for new A and once for new B
6cc37db
+gdb_continue_to_breakpoint "First line A"
6cc37db
+gdb_test "bt" "#0.*A.*#1.*main.*" "Verify in in-charge A::A"
6cc37db
+gdb_continue_to_breakpoint "First line A"
6cc37db
+gdb_test "bt" "#0.*A.*#1.*B.*#2.*main.*" "Verify in not-in-charge A::A"
6cc37db
+
6cc37db
+# Now do the same for destructors
6cc37db
+gdb_test "break 'A::~A()'" ""
6cc37db
+gdb_test "break 'A::~A\$base()'" ""
6cc37db
+
6cc37db
+# Verify that we break for the A destructor two times
6cc37db
+# Once for delete a and once for delete b
6cc37db
+gdb_continue_to_breakpoint "First line ~A"
6cc37db
+gdb_test "bt" "#0.*~A.*#1.*main.*" "Verify in in-charge A::~A"
6cc37db
+gdb_continue_to_breakpoint "First line ~A"
6cc37db
+gdb_test "bt" "#0.*~A.*#1.*~B.*#2.*main.*" "Verify in not-in-charge A::~A"
6cc37db
+
6cc37db
+
6cc37db
+# Verify that we can break by line number in a constructor and find
6cc37db
+# both occurrences
6cc37db
+runto_main
6cc37db
+gdb_test "break 'A::A()'" "" "break in constructor A 2"
6cc37db
+gdb_continue_to_breakpoint "First line A"
6cc37db
+set second_line [gdb_get_line_number "Second line A"]
6cc37db
+gdb_test "break $second_line" ".*$second_line.*$second_line.*Multiple breakpoints were set.*" "break by line in constructor"
6cc37db
+gdb_continue_to_breakpoint "Second line A"
6cc37db
+gdb_test "bt" "#0.*A.*#1.*main.*" "Verify in in-charge A::A second line"
6cc37db
+gdb_continue_to_breakpoint "Second line A"
6cc37db
+gdb_test "bt" "#0.*A.*#1.*B.*#2.*main.*" "Verify in not-in-charge A::A second line"
6cc37db
+
6cc37db
+# Verify that we can break by line number in a destructor and find
6cc37db
+# both occurrences
6cc37db
+gdb_test "break 'A::~A()'" "" "break in constructor ~A 2"
6cc37db
+gdb_continue_to_breakpoint "First line ~A"
6cc37db
+set second_line_dtor [gdb_get_line_number "Second line ~A"]
6cc37db
+gdb_test "break $second_line_dtor" ".*$second_line_dtor.*$second_line_dtor.*Multiple breakpoints were set.*" "break by line in destructor"
6cc37db
+gdb_continue_to_breakpoint "Second line ~A"
6cc37db
+gdb_test "bt" "#0.*A.*#1.*main.*" "Verify in in-charge A::~A second line"
6cc37db
+gdb_continue_to_breakpoint "Second line ~A"
6cc37db
+gdb_test "bt" "#0.*A.*#1.*B.*#2.*main.*" "Verify in not-in-charge A::~A second line"
6cc37db
+
6cc37db
--- gdb-6.3/gdb/testsuite/gdb.cp/templates.exp.fix	Fri Jan 21 17:07:10 2005
6cc37db
+++ gdb-6.3/gdb/testsuite/gdb.cp/templates.exp	Fri Jan 21 17:09:09 2005
6cc37db
@@ -1,4 +1,4 @@
6cc37db
-# Copyright 1992, 1994, 1995, 1996, 1997, 1999, 2000, 2002, 2003, 2004
6cc37db
+# Copyright 1992, 1994, 1995, 1996, 1997, 1999, 2000, 2002, 2003, 2004, 2005
6cc37db
 # Free Software Foundation, Inc.
6cc37db
 
6cc37db
 # This program is free software; you can redistribute it and/or modify
6cc37db
@@ -142,7 +142,7 @@ proc test_template_breakpoints {} {
6cc37db
 # See CLLbs14792
6cc37db
     if {$hp_aCC_compiler} {setup_xfail hppa*-*-* CLLbs14792}
6cc37db
 
6cc37db
-    gdb_test_multiple "break T5<int>::~T5" "destructor_breakpoint" {
6cc37db
+    gdb_test_multiple "break 'T5<int>::~T5()'" "destructor_breakpoint" {
6cc37db
 	-re "Breakpoint.*at.* file .*${testfile}.cc, line.*$gdb_prompt $"
6cc37db
 	{
6cc37db
 	    pass "destructor breakpoint"