This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
Re: [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: mec at shout dot net
- Cc: carlton at math dot stanford dot edu
- Date: 22 Aug 2002 10:10:30 -0700
- Subject: Re: [rfa/c++-testsuite]: printing out methods
- References: <ro1y9b6uzqy.fsf@jackfruit.Stanford.EDU>
In article <ro1y9b6uzqy.fsf@jackfruit.Stanford.EDU>, David Carlton <carlton@math.Stanford.EDU> writes:
> 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.
Here's a slightly revised version.
David Carlton
carlton@math.stanford.edu
2002-08-22 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 Tue Aug 20 16:27:31 2002
@@ -0,0 +1,67 @@
+# 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
+}
+
+gdb_test "next" "" "next"
+
+# 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 Tue Aug 20 16:26:38 2002
@@ -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;
+}