This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
[rfa/c++-testsuite]: printing out methods
- From: David Carlton <carlton at math dot stanford dot edu>
- To: gdb-patches at sources dot redhat dot com
- Cc: carlton at math dot stanford dot edu, mec at shout dot net
- Date: 16 Aug 2002 16:53:41 -0700
- Subject: [rfa/c++-testsuite]: printing out methods
While creating other testsuite cases today, I managed to get GDB to
segfault; see PR gdb/653 for details. I haven't looked for the bug
(though older versions of GDB don't exhibit the problem for me), but
in the mean time I figured I might as well put together a testsuite
case for it.
David Carlton
carlton@math.stanford.edu
2002-08-16 David Carlton <carlton@math.stanford.edu>
* gdb.c++/printmethod.exp: New file.
* gdb.c++/printmethod.cc: New file.
--- /dev/null Thu Apr 11 07:25:15 2002
+++ printmethod.exp Fri Aug 16 16:39:51 2002
@@ -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. See PR gdb/653
+
+# 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
+}
+
+# One.
+gdb_test "break 12" "Breakpoint \[0-9\]*.*line 12\\."
+gdb_test "continue" "Continuing\\.\r\n\r\nBreakpoint.*at.*${testfile}\\.cc:12\r\n.*" "continue to 12"
+
+# On CVS GDB as of 2002-08-15, the first of these seg faults. It
+# worked fine in GDB 5.2, though.
+
+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
--- /dev/null Thu Apr 11 07:25:15 2002
+++ printmethod.cc Fri Aug 16 16:27:50 2002
@@ -0,0 +1,12 @@
+/* Create some objects, and try to print out their methods. */
+
+class A {
+public:
+ virtual void virt() {};
+ void nonvirt() {};
+};
+
+int main()
+{
+ A *theA = new A;
+}