aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Carlton <carlton@bactrian.org>2002-09-18 18:48:43 +0000
committerDavid Carlton <carlton@bactrian.org>2002-09-18 18:48:43 +0000
commite70d6e3ff58b9c8a2d72aaa64d7c4e09f8a3a445 (patch)
treed2d0ecc5d9f673f062dd4d57cb73f4a6beaa4bd7
parenteb9443807ab7d604076d06ce5cf902f0fdf21a7e (diff)
downloadgdb-e70d6e3ff58b9c8a2d72aaa64d7c4e09f8a3a445.zip
gdb-e70d6e3ff58b9c8a2d72aaa64d7c4e09f8a3a445.tar.gz
gdb-e70d6e3ff58b9c8a2d72aaa64d7c4e09f8a3a445.tar.bz2
2002-09-18 David Carlton <carlton@math.stanford.edu>
* gdb.c++/m-static.exp: Remove breakpoints depending on line numbers, and replace them by a single breakpoint after the constructors are all finished. Add test 4. * gdb.c++/m-static.cc: Add test 4. * gdb.c++/m-static.h: New file. * gdb.c++/m-static1.cc: New file. * gdb.c++/printmethod.exp: New file. * gdb.c++/printmethod.cc: New file. * gdb.c++/pr-574.exp: New file. * gdb.c++/pr-574.cc: New file.
-rw-r--r--gdb/testsuite/ChangeLog16
-rw-r--r--gdb/testsuite/gdb.c++/m-static.cc7
-rw-r--r--gdb/testsuite/gdb.c++/m-static.exp30
-rw-r--r--gdb/testsuite/gdb.c++/m-static.h11
-rw-r--r--gdb/testsuite/gdb.c++/m-static1.cc9
-rw-r--r--gdb/testsuite/gdb.c++/pr-574.cc22
-rw-r--r--gdb/testsuite/gdb.c++/pr-574.exp72
-rw-r--r--gdb/testsuite/gdb.c++/printmethod.cc14
-rw-r--r--gdb/testsuite/gdb.c++/printmethod.exp69
9 files changed, 242 insertions, 8 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 0eed7b2..0d8884a 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,19 @@
+2002-09-18 David Carlton <carlton@math.stanford.edu>
+
+ * gdb.c++/m-static.exp: Remove breakpoints depending on line
+ numbers, and replace them by a single breakpoint after the
+ constructors are all finished.
+ Add test 4.
+ * gdb.c++/m-static.cc: Add test 4.
+ * gdb.c++/m-static.h: New file.
+ * gdb.c++/m-static1.cc: New file.
+
+ * gdb.c++/printmethod.exp: New file.
+ * gdb.c++/printmethod.cc: New file.
+
+ * gdb.c++/pr-574.exp: New file.
+ * gdb.c++/pr-574.cc: New file.
+
2002-09-18 Corinna Vinschen <vinschen@redhat.com>
* gdb.base/ending-run.exp: Add handling of "step to end of run" for
diff --git a/gdb/testsuite/gdb.c++/m-static.cc b/gdb/testsuite/gdb.c++/m-static.cc
index 2433801..ae14848 100644
--- a/gdb/testsuite/gdb.c++/m-static.cc
+++ b/gdb/testsuite/gdb.c++/m-static.cc
@@ -53,6 +53,10 @@ namespace __gnu_test
template<typename T>
gnu_obj_2<int> gnu_obj_3<T>::data(etruscan);
+
+ // 2002-08-16
+ // Test four.
+#include "m-static.h"
}
// instantiate templates explicitly so their static members will exist
@@ -67,6 +71,7 @@ int main()
gnu_obj_1 test1(egyptian, 4589);
gnu_obj_2<long> test2(roman);
gnu_obj_3<long> test3(greek);
+ gnu_obj_4 test4;
- return 0;
+ return 0; // breakpoint: constructs-done
}
diff --git a/gdb/testsuite/gdb.c++/m-static.exp b/gdb/testsuite/gdb.c++/m-static.exp
index c05983b..d291135 100644
--- a/gdb/testsuite/gdb.c++/m-static.exp
+++ b/gdb/testsuite/gdb.c++/m-static.exp
@@ -16,6 +16,7 @@
# Tests for member static data
# 2002-05-13 Benjamin Kosnik <bkoz@redhat.com>
+# 2002-08-22 David Carlton <carlton@math.stanford.edu>
# This file is part of the gdb testsuite
@@ -33,9 +34,10 @@ set bug_id 0
set testfile "m-static"
set srcfile ${testfile}.cc
+set srcfile1 ${testfile}1.cc
set binfile ${objdir}/${subdir}/${testfile}
-if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
+if { [gdb_compile "${srcdir}/${subdir}/${srcfile} ${srcdir}/${subdir}/${srcfile1}" "${binfile}" executable {debug c++}] != "" } {
gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
}
@@ -54,9 +56,13 @@ if ![runto_main] then {
continue
}
+# First, run to after we've constructed all the objects:
+
+gdb_breakpoint [gdb_get_line_number "constructs-done"]
+gdb_continue_to_breakpoint "end of constructors"
+
+
# One.
-gdb_test "break 68" "Breakpoint \[0-9\]*.*line 68\\."
-gdb_test "continue" "Continuing\\.\r\n\r\nBreakpoint.*at.*m-static\\.cc:68\r\n.*" "continue to 68"
# simple object, static const bool
gdb_test "print test1.test" "\\$\[0-9\]* = true" "simple object, static const bool"
@@ -71,8 +77,6 @@ gdb_test "print test1.key2" "\\$\[0-9\]* = 77" "simple object, static long"
gdb_test "print test1.value" "\\$\[0-9\]* = oriental" "simple object, static enum"
# Two.
-gdb_test "break 69" "Breakpoint \[0-9\]*.*line 69\\."
-gdb_test "continue" "Continuing\\.\r\n\r\nBreakpoint.*at.*m-static\\.cc:69\r\n.*" "continue to 69"
# derived template object, base static const bool
gdb_test "print test2.test" "\\$\[0-9\]* = true" "derived template object, base static const bool"
@@ -90,8 +94,6 @@ gdb_test "print test2.value" "\\$\[0-9\].* = oriental" "derived template object,
gdb_test "print test2.value_derived" "\\$\[0-9\].* = etruscan" "derived template object, static enum"
# Three.
-gdb_test "break 71" "Breakpoint \[0-9\]*.*line 71\\."
-gdb_test "continue" "Continuing\\.\r\n\r\nBreakpoint.*at.*m-static\\.cc:71\r\n.*" "continue to 71"
# template object, static derived template data member's base static const bool
gdb_test "print test3.data.test" "\\$\[0-9\].* = true" "template object, static const bool"
@@ -108,5 +110,19 @@ gdb_test "print test3.data.value" "\\$\[0-9\].* = oriental" "template object, st
# template object, static derived template data member's static enum
gdb_test "print test3.data.value_derived" "\\$\[0-9\].* = etruscan" "template object, static derived enum"
+# 2002-08-16
+# Four.
+
+# static const int initialized in another file.
+gdb_test "print test4.elsewhere" "\\$\[0-9\].* = 221" "static const int initialized elsewhere"
+
+# static const int that nobody initializes. From PR gdb/635.
+gdb_test "print test4.nowhere" "field nowhere is nonexistent or has been optimised out" "static const int initialized nowhere"
+
+# Perhaps at some point test4 should also include a test for a static
+# const int that was initialized in the header file. But I'm not sure
+# that GDB's current behavior in such situations is either consistent
+# across platforms or optimal, so I'm not including one now.
+
gdb_exit
return 0
diff --git a/gdb/testsuite/gdb.c++/m-static.h b/gdb/testsuite/gdb.c++/m-static.h
new file mode 100644
index 0000000..137d3b7
--- /dev/null
+++ b/gdb/testsuite/gdb.c++/m-static.h
@@ -0,0 +1,11 @@
+// 2002-08-16
+
+class gnu_obj_4
+{
+ public:
+ static const int elsewhere;
+ static const int nowhere;
+ // At some point, perhaps:
+ // static const int everywhere = 317;
+};
+
diff --git a/gdb/testsuite/gdb.c++/m-static1.cc b/gdb/testsuite/gdb.c++/m-static1.cc
new file mode 100644
index 0000000..f88c9ce
--- /dev/null
+++ b/gdb/testsuite/gdb.c++/m-static1.cc
@@ -0,0 +1,9 @@
+// 2002-08-16
+
+namespace __gnu_test {
+#include "m-static.h"
+}
+
+using namespace __gnu_test;
+
+const int gnu_obj_4::elsewhere = 221;
diff --git a/gdb/testsuite/gdb.c++/pr-574.cc b/gdb/testsuite/gdb.c++/pr-574.cc
new file mode 100644
index 0000000..eb06b61
--- /dev/null
+++ b/gdb/testsuite/gdb.c++/pr-574.cc
@@ -0,0 +1,22 @@
+/*
+ An attempt to replicate PR gdb/574 with a shorter program.
+
+ Printing out *theB failed if the program was compiled with GCC 2.95.
+*/
+
+class A {
+public:
+ virtual void foo() {}; // Stick in a virtual function.
+ int a; // Stick in a data member.
+};
+
+class B : public A {
+ static int b; // Stick in a static data member.
+};
+
+int main()
+{
+ B *theB = new B;
+
+ return 0; // breakpoint: constructs-done
+}
diff --git a/gdb/testsuite/gdb.c++/pr-574.exp b/gdb/testsuite/gdb.c++/pr-574.exp
new file mode 100644
index 0000000..5beacd1
--- /dev/null
+++ b/gdb/testsuite/gdb.c++/pr-574.exp
@@ -0,0 +1,72 @@
+# Copyright 2002 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+# Tests for the bug mentioned in PR gdb/574. It's a bit
+# idiosyncratic, so I gave it its own file.
+
+# 2002-08-16 David Carlton <carlton@math.stanford.edu>
+
+# This file is part of the gdb testsuite
+
+if $tracelevel then {
+ strace $tracelevel
+ }
+
+if { [skip_cplus_tests] } { continue }
+
+#
+# test running programs
+#
+set prms_id 0
+set bug_id 0
+
+set testfile "pr-574"
+set srcfile ${testfile}.cc
+set binfile ${objdir}/${subdir}/${testfile}
+
+if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
+ gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
+}
+
+if [get_compiler_info ${binfile} "c++"] {
+ return -1
+}
+
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+gdb_load ${binfile}
+
+
+if ![runto_main] then {
+ perror "couldn't run to breakpoint"
+ continue
+}
+
+# First, run to after we've constructed the object:
+
+gdb_breakpoint [gdb_get_line_number "constructs-done"]
+gdb_continue_to_breakpoint "end of constructors"
+
+# This failed, as long as the code was compiled with GCC v. 2.
+
+# Different compilers order the data for <A> differently, so I'm not
+# matching the result exactly.
+
+gdb_test "print *theB" "\\$\[0-9\]* = {<A> = {\[^}\]*}, static b = <optimized out>}" "PR gdb/574"
+
+gdb_exit
+return 0
diff --git a/gdb/testsuite/gdb.c++/printmethod.cc b/gdb/testsuite/gdb.c++/printmethod.cc
new file mode 100644
index 0000000..d32e1b1
--- /dev/null
+++ b/gdb/testsuite/gdb.c++/printmethod.cc
@@ -0,0 +1,14 @@
+/* Create some objects, and try to print out their methods. */
+
+class A {
+public:
+ virtual void virt() {};
+ void nonvirt() {};
+};
+
+int main()
+{
+ A *theA = new A;
+
+ return 0; // breakpoint: constructs-done
+}
diff --git a/gdb/testsuite/gdb.c++/printmethod.exp b/gdb/testsuite/gdb.c++/printmethod.exp
new file mode 100644
index 0000000..9b96cbf
--- /dev/null
+++ b/gdb/testsuite/gdb.c++/printmethod.exp
@@ -0,0 +1,69 @@
+# Copyright 2002 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+# This tries to print out methods of classes.
+
+# 2002-08-16 David Carlton <carlton@math.stanford.edu>
+
+# This file is part of the gdb testsuite
+
+if $tracelevel then {
+ strace $tracelevel
+ }
+
+if { [skip_cplus_tests] } { continue }
+
+#
+# test running programs
+#
+set prms_id 0
+set bug_id 0
+
+set testfile "printmethod"
+set srcfile ${testfile}.cc
+set binfile ${objdir}/${subdir}/${testfile}
+
+if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
+ gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
+}
+
+if [get_compiler_info ${binfile} "c++"] {
+ return -1
+}
+
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+gdb_load ${binfile}
+
+
+if ![runto_main] then {
+ perror "couldn't run to breakpoint"
+ continue
+}
+
+# First, run to after we've constructed the object:
+
+gdb_breakpoint [gdb_get_line_number "constructs-done"]
+gdb_continue_to_breakpoint "end of constructors"
+
+# The first of these is for PR gdb/653.
+
+gdb_test "print theA->virt" "\\$\[0-9\]* = &A::virt\\(\\)" "print virtual method."
+gdb_test "print theA->nonvirt" "Cannot take address of a method" "print nonvirtual method."
+
+gdb_exit
+return 0