* hppa.h (pa_opcodes): Use "cX" completer instead of "cx" in fstqx
[external/binutils.git] / gdb / testsuite / gdb.cp / virtfunc.exp
index ff36c27..4621a74 100644 (file)
-# Copyright 1992, 1994, 1995, 1996, 1997, 1998, 1999, 2001, 2002, 2003
-# Free Software Foundation, Inc.
+# Copyright 1992, 1994-1999, 2001-2004, 2006-2012 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
+# the Free Software Foundation; either version 3 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.  
-
-# Please email any bugs, comments, and/or additions to this file to:
-# bug-gdb@prep.ai.mit.edu
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 # This file was written by Fred Fish. (fnf@cygnus.com)
+# And rewritten by Michael Chastain <mec.gnu@mindspring.com>.
 
-set ws "\[\r\n\t \]+"
-set nl "\[\r\n\]+"
-
-if $tracelevel then {
-       strace $tracelevel
-}
+set nl         "\[\r\n\]+"
 
 if { [skip_cplus_tests] } { continue }
 
-set testfile "virtfunc"
-set srcfile ${testfile}.cc
-set binfile ${objdir}/${subdir}/${testfile}
-
-if [get_compiler_info ${binfile} "c++"] {
-    return -1
-}
-
-source ${binfile}.ci
-
-if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {c++ debug}] != "" } {
-     gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
-}
-
-proc gdb_virtfunc_init {} {
-    global srcdir subdir binfile
-    global gdb_prompt
-
-    gdb_reinitialize_dir $srcdir/$subdir
-    gdb_load $binfile
+load_lib "cp-support.exp"
 
-    send_gdb "set language c++\n"
-    gdb_expect -re "$gdb_prompt $"
-    send_gdb "set width 0\n"
-    gdb_expect -re "$gdb_prompt $"
-}
+standard_testfile .cc
 
-proc gdb_virtfunc_restart {} {
-    gdb_exit;
-    gdb_start;
-    gdb_virtfunc_init;
-    runto 'test_calls';
+if {[prepare_for_testing $testfile.exp $testfile $srcfile {debug c++}]} {
+    return -1
 }
 
-#
-#  Test printing of the types of various classes.
-#
-
 proc test_ptype_of_classes {} {
-    global gdb_prompt
-    global ws
-    global nl
-
-    # This used to be a fail if it printed "struct" not "class".  But
-    # since this struct doesn't use any special C++ features, it is
-    # considered right for GDB to print it as "struct".
-    send_gdb "ptype VA\n"
-    gdb_expect {
-       -re "type = (struct|class) VA \{(${ws}public:|)${ws}int va;${ws}VA & operator=\\(VA const ?&\\);${ws}VA\\((VA const|const VA) ?&\\);${ws}VA\\((void|)\\);${ws}\}.*$gdb_prompt $" {
-           pass "ptype VA"
-       }
-       -re "type = (struct|class) VA \{(${ws}public:|)${ws}int va;((${ws}VA & operator=\\(VA const ?&\\);)|(${ws}VA\\(VA const ?&\\);)|(${ws}VA\\((void|)\\);))*${ws}\}.*$gdb_prompt $" {
-           pass "ptype VA (obsolescent gcc or gdb)"
-       }
-       -re ".*$gdb_prompt $" {
-           fail "ptype VA"
-       }
-       timeout {
-           fail "ptype VA (timeout)"
-       }
-    }
 
-    send_gdb "ptype VB\n"
-    gdb_expect {
-       -re "type = class VB \{${ws}public:${ws}int vb;${ws}VB & operator=\\(VB const ?&\\);${ws}VB\\((VB const|const VB) ?&\\);${ws}VB\\((void|)\\);${ws}int fvb\\((void|)\\);${ws}virtual int vvb\\((void|)\\);${ws}\}.*$gdb_prompt $" {
-           pass "ptype VB"
-       }
-       -re "type = class VB \{${ws}public:${ws}int vb;${ws}int fvb \\((void|)\\);${ws}virtual int vvb \\((void|)\\);${ws}\}.*$gdb_prompt $" {
-           pass "ptype VB (aCC)"
-       }
-       -re "type = class VB \{${ws}public:${ws}int vb;((${ws}VB & operator=\\(VB const ?&\\);)|(${ws}VB\\(VB const ?&\\);)|(${ws}VB\\((void|)\\);)|(${ws}int fvb\\((void|)\\);)|(${ws}virtual int vvb\\((void|)\\);))*${ws}\}.*$gdb_prompt $" {
-           pass "ptype VB (obsolescent gcc or gdb)"
-       }
-       -re ".*$gdb_prompt $" {
-           fail "ptype VB"
-       }
-       timeout {
-           fail "ptype VB (timeout)"
-       }
-    }
+    # class VA
 
-    send_gdb "ptype V\n"
-    gdb_expect {
-       -re "type = class V : public VA, public VB \{${ws}public:${ws}int w;${ws}V & operator=\\(V const ?&\\);${ws}V\\((V const|const V) ?&\\);${ws}V\\((void|)\\);${ws}int f\\((void|)\\);${ws}virtual int vv\\((void|)\\);${ws}\}$nl$gdb_prompt $" {
-           pass "ptype V"
-       }
-       -re "type = class V : public VA, public VB \{${ws}public:${ws}int w;${ws}int f \\((void|)\\);${ws}virtual int vv \\((void|)\\);${ws}\}$nl$gdb_prompt $" {
-           pass "ptype V (aCC)"
-       }
-       -re "type = class V : public VA, public VB \{${ws}public:${ws}int w;((${ws}V & operator=\\(V const ?&\\);)|(${ws}V\\(V const ?&\\);)|(${ws}V\\((void|)\\);)|(${ws}int f\\((void|)\\);)|(${ws}virtual int vv\\((void|)\\);))*${ws}\}$nl$gdb_prompt $" {
-           pass "ptype V (obsolescent gcc or gdb)"
-       }
-       -re ".*$gdb_prompt $" {
-           fail "ptype V"
+    cp_test_ptype_class \
+       "ptype VA" "" "class" "VA" \
+       {
+           { field public "int va;" }
        }
-       timeout {
-           fail "ptype V (timeout)"
-       }
-    }
 
-    # The format of a g++ virtual base pointer.
-    set vbptr "(_vb\[$.\]|__vb_)\[0-9\]?"
+    # class VB
 
-    send_gdb "ptype A\n"
-    gdb_expect {
-       -re "type = class A : public virtual V \{${ws}private:${ws}V \\*${vbptr}V;${ws}int a;${ws}public:${ws}A & operator=\\(A const ?&\\);${ws}A\\(int, A const ?&\\);${ws}A\\(int\\);${ws}virtual int f\\((void|)\\);${ws}\}$nl$gdb_prompt $" {
-           pass "ptype A"
-       }
-       -re "type = class A : public virtual V \{${ws}private:${ws}int a;${ws}public:${ws}A & operator=\\(A const ?&\\);${ws}A\\((A const|const A) ?&\\);${ws}A\\((void|)\\);${ws}virtual int f\\((void|)\\);${ws}\}$nl$gdb_prompt $" {
-           pass "ptype A"
-       }
-        -re "type = class A : public virtual V \{${ws}private:${ws}int a;${ws}public:${ws}virtual int f\\((void|)\\);${ws}\}$nl$gdb_prompt $" {
-            pass "ptype A (aCC)"
-        }
-       -re "type = class A : public virtual V \{${ws}private:${ws}V \\*${vbptr}V;${ws}int a;${ws}public:((${ws}A & operator=\\(A const ?&\\);)|(${ws}A\\(int, A const ?&\\);)|(${ws}A\\(int\\);)|(${ws}virtual int f\\((void|)\\);))*${ws}\}$nl$gdb_prompt $" {
-           pass "ptype A (obsolescent gcc or gdb)"
+    cp_test_ptype_class \
+       "ptype VB" "" "class" "VB" \
+       {
+           { field  public "int vb;" }
+           { method public "int fvb();" }
+           { method public "virtual int vvb();" }
        }
-       -re "type = class A : public virtual V \{${ws}private:${ws}V \\*${vbptr}FOO;${ws}int a;${ws}public:${ws}virtual int f.void.;${ws}\}$nl$gdb_prompt $" {
-           # This happens because the type is defined only after it is
-           # too late.
-           fail "ptype A (known failure with gcc cygnus-2.4.5-930417)"
-           # Many of the rest of these tests have the same problem.
-           return 0
-       }
-       -re ".*$gdb_prompt $" {
-           fail "ptype A"
-       }
-       timeout {
-           fail "ptype A (timeout)"
-       }
-    }
 
-    send_gdb "ptype B\n"
-    gdb_expect {
-       -re "type = class B : public A \{${ws}private:${ws}int b;${ws}public:${ws}B & operator=\\(B const ?&\\);${ws}B\\(int, B const ?&\\);${ws}B\\(int\\);${ws}virtual int f\\((void|)\\);${ws}\}$nl$gdb_prompt $" {
-           pass "ptype B"
-       }
-       -re "type = class B : public A \{${ws}private:${ws}int b;${ws}public:${ws}B & operator=\\(B const ?&\\);${ws}B\\((B const|const B) ?&\\);${ws}B\\((void|)\\);${ws}virtual int f\\((void|)\\);${ws}\}$nl$gdb_prompt $" {
-           pass "ptype B"
-       }
-       -re "type = class B : public A \{${ws}private:${ws}int b;${ws}public:${ws}virtual int f \\((void|)\\);${ws}\}$nl$gdb_prompt $" {
-           pass "ptype B (aCC)"
-       }
-       -re "type = class B : public A \{${ws}private:${ws}int b;${ws}public:((${ws}B & operator=\\(B const ?&\\);)|(${ws}B\\(int, B const ?&\\);)|(${ws}B\\(int\\);)|(${ws}virtual int f\\((void|)\\);))*${ws}\}$nl$gdb_prompt $" {
-           pass "ptype B (obsolescent gcc or gdb)"
-       }
-       -re ".*$gdb_prompt $" {
-           fail "ptype B"
-       }
-       timeout {
-           fail "ptype B (timeout)"
-       }
-    }
+    # class V
 
-    send_gdb "ptype C\n"
-    gdb_expect {
-       -re "type = class C : public virtual V \{${ws}private:${ws}V \\*${vbptr}V;${ws}public:${ws}int c;${ws}C & operator=\\(C const ?&\\);${ws}C\\(int, C const ?&\\);${ws}C\\(int\\);${ws}\}$nl$gdb_prompt $" {
-           pass "ptype C"
-       }
-       -re "type = class C : public virtual V \{${ws}public:${ws}int c;${ws}C & operator=\\(C const ?&\\);${ws}C\\((C const|const C) ?&\\);${ws}C\\((void|)\\);${ws}\}$nl$gdb_prompt $" {
-           pass "ptype C"
+    cp_test_ptype_class \
+       "ptype V" "" "class" "V" \
+       {
+           { base          "public VA" }
+           { base          "public VB" }
+           { field  public "int w;" }
+           { method public "int f();" }
+           { method public "virtual int vv();" }
        }
-        -re "type = class C : public virtual V \{${ws}public:${ws}int c;${ws}\}$nl$gdb_prompt $" {
-            pass "ptype C (aCC)"
-        }
-       -re "type = class C : public virtual V \{${ws}private:${ws}V \\*${vbptr}V;${ws}public:${ws}int c;((${ws}C & operator=\\(C const ?&\\);)|(${ws}C\\(int, C const ?&\\);)|(${ws}C\\(int\\);))*${ws}\}$nl$gdb_prompt $" {
-           pass "ptype C (obsolescent gcc or gdb)"
-       }
-       -re ".*$gdb_prompt $" {
-           fail "ptype C"
-       }
-       timeout {
-           fail "ptype C (timeout)"
-       }
-    }
 
-    send_gdb "ptype AD\n"
-    gdb_expect {
-       -re "type = class AD \{${ws}public:${ws}AD & operator=\\(AD const ?&\\);${ws}AD\\((AD const|const AD) ?&\\);${ws}AD\\((void|)\\);${ws}virtual int vg\\((void|)\\);${ws}\}$nl$gdb_prompt $" {
-           pass "ptype AD"
-       }
-       -re "type = class AD \{${ws}public:${ws}virtual int vg \\((void|)\\);${ws}\}$nl$gdb_prompt $" {
-           pass "ptype AD (aCC)"
-       }
-       -re "type = class AD \{${ws}public:((${ws}AD & operator=\\(AD const ?&\\);)|(${ws}AD\\(AD const ?&\\);)|(${ws}AD\\((void|)\\);)|(${ws}virtual int vg\\((void|)\\);))*${ws}\}$nl$gdb_prompt $" {
-           pass "ptype AD (obsolescent gcc or gdb)"
-       }
-       -re ".*$gdb_prompt $" {
-           fail "ptype AD"
-       }
-       timeout {
-           fail "ptype AD (timeout)"
-       }
-    }
+    # class A
 
-    send_gdb "ptype D\n"
-    gdb_expect {
-       -re "type = class D : public AD, public virtual V \{${ws}private:${ws}V \\*${vbptr}V;${ws}public:${ws}int d;${ws}D & operator=\\(D const ?&\\);${ws}D\\(int, D const ?&\\);${ws}D\\(int\\);${ws}static void s\\((void|)\\);${ws}virtual int vg\\((void|)\\);${ws}virtual int vd\\((void|)\\);${ws}int fd\\((void|)\\);${ws}\}$nl$gdb_prompt $" {
-           pass "ptype D"
-       }
-       -re "type = class D : public AD, public virtual V \{${ws}public:${ws}int d;${ws}D & operator=\\(D const ?&\\);${ws}D\\((D const|const D) ?&\\);${ws}D\\((void|)\\);${ws}static void s\\((void|)\\);${ws}virtual int vg\\((void|)\\);${ws}virtual int vd\\((void|)\\);${ws}int fd\\((void|)\\);${ws}\}$nl$gdb_prompt $" {
-           pass "ptype D"
-       }
-        -re "type = class D : public AD, public virtual V \{${ws}public:${ws}int d;${ws}static void s\\((void|)\\);${ws}virtual int vg\\((void|)\\);${ws}virtual int vd\\((void|)\\);${ws}int fd\\((void|)\\);${ws}\}$nl$gdb_prompt $" {
-            pass "ptype D (aCC)"
-        }
-       -re "type = class D : public AD, public virtual V \{${ws}private:${ws}V \\*${vbptr}V;${ws}public:${ws}int d;((${ws}D & operator=\\(D const ?&\\);)|(${ws}D\\(int, D const ?&\\);)|(${ws}D\\(int\\);)|(${ws}static void s\\((void|)\\);)|(${ws}virtual int vg\\((void|)\\);)|(${ws}virtual int vd\\((void|)\\);)|(${ws}int fd\\((void|)\\);))*${ws}\}$nl$gdb_prompt $" {
-           pass "ptype D (obsolescent gcc or gdb)"
+    cp_test_ptype_class \
+       "ptype A" "" "class" "A" \
+       {
+           { base           "public virtual V" }
+           { vbase          "V" }
+           { field  private "int a;" }
+           { method public  "virtual int f();" }
        }
-       -re ".*$gdb_prompt $" {
-           fail "ptype D"
-       }
-       timeout {
-           fail "ptype D (timeout)"
-       }
-    }
 
-    send_gdb "ptype E\n"
-    gdb_expect {
-       -re "type = class E : public B, public virtual V, public D, public C \{${ws}public:${ws}int e;${ws}E & operator=\\(E const ?&\\);${ws}E\\(int, E const ?&\\);${ws}E\\(int\\);${ws}virtual int f\\((void|)\\);${ws}virtual int vg\\((void|)\\);${ws}virtual int vv\\((void|)\\);${ws}\}$nl$gdb_prompt $" {
-           pass "ptype E"
-       }
-       -re "type = class E : public B, public virtual V, public D, public C \{${ws}public:${ws}int e;${ws}E & operator=\\(E const ?&\\);${ws}E\\((E const|const E) ?&\\);${ws}E\\((void|)\\);${ws}virtual int f\\((void|)\\);${ws}virtual int vg\\((void|)\\);${ws}virtual int vv\\((void|)\\);${ws}\}$nl$gdb_prompt $" {
-           pass "ptype E"
-       }
-       -re "type = class E : public B, public virtual V, public D, public C \{${ws}public:${ws}int e;${ws}virtual int f \\((void|)\\);${ws}virtual int vg \\((void|)\\);${ws}virtual int vv \\((void|)\\);${ws}\}$nl$gdb_prompt $" {
-           pass "ptype E (aCC)"
-       }
-       -re "type = class E : public B, public virtual V, public D, public C \{${ws}public:${ws}int e;((${ws}E & operator=\\(E const ?&\\);)|(${ws}E\\(int, E const ?&\\);)|(${ws}E\\(int\\);)|(${ws}virtual int f\\((void|)\\);)|(${ws}virtual int vg\\((void|)\\);)|(${ws}virtual int vv\\((void|)\\);))*${ws}\}$nl$gdb_prompt $" {
-           pass "ptype E (obsolescent gcc or gdb)"
-       }
-       -re ".*$gdb_prompt $" {
-           fail "ptype E"
-       }
-       timeout {
-           fail "ptype E (timeout)"
-       }
-    }
+    # class B
 
-    send_gdb "ptype dd\n"
-    gdb_expect {
-       -re "type = class D : public AD, public virtual V \{${ws}private:${ws}V \\*${vbptr}V;${ws}public:${ws}int d;${ws}D & operator=\\(D const ?&\\);${ws}D\\(int, D const ?&\\);${ws}D\\(int\\);${ws}static void s\\((void|)\\);${ws}virtual int vg\\((void|)\\);${ws}virtual int vd\\((void|)\\);${ws}int fd\\((void|)\\);${ws}\}$nl$gdb_prompt $" {
-           pass "ptype dd"
-       }
-       -re "type = class D : public AD, public virtual V \{${ws}public:${ws}int d;${ws}D & operator=\\(D const ?&\\);${ws}D\\((D const|const D) ?&\\);${ws}D\\((void|)\\);${ws}static void s\\((void|)\\);${ws}virtual int vg\\((void|)\\);${ws}virtual int vd\\((void|)\\);${ws}int fd\\((void|)\\);${ws}\}$nl$gdb_prompt $" {
-           pass "ptype dd"
-       }
-        -re "type = class D : public AD, public virtual V \{${ws}public:${ws}int d;${ws}static void s\\((void|)\\);${ws}virtual int vg\\((void|)\\);${ws}virtual int vd\\((void|)\\);${ws}int fd\\((void|)\\);${ws}\}$nl$gdb_prompt $" {
-            pass "ptype dd (aCC)"
-        }
-       -re "type = class D : public AD, public virtual V \{${ws}private:${ws}V \\*${vbptr}V;${ws}public:${ws}int d;((${ws}D & operator=\\(D const ?&\\);)|(${ws}D\\(int, D const ?&\\);)|(${ws}D\\(int\\);)|(${ws}static void s\\((void|)\\);)|(${ws}virtual int vg\\((void|)\\);)|(${ws}virtual int vd\\((void|)\\);)|(${ws}int fd\\((void|)\\);))*${ws}\}$nl$gdb_prompt $" {
-           pass "ptype dd (obsolescent gcc or gdb)"
+    cp_test_ptype_class \
+       "ptype B" "" "class" "B" \
+       {
+           { base           "public A" }
+           { field  private "int b;" }
+           { method public  "virtual int f();" }
        }
-       -re ".*$gdb_prompt $" {
-           fail "ptype dd"
-       }
-       timeout {
-           fail "ptype dd (timeout)"
-       }
-    }
 
-    send_gdb "ptype ppd\n"
-    gdb_expect {
-       -re "type = class D : public AD, public virtual V \{${ws}private:${ws}V \\*${vbptr}V;${ws}public:${ws}int d;${ws}D & operator=\\(D const ?&\\);${ws}D\\(int, D const ?&\\);${ws}D\\(int\\);${ws}static void s\\((void|)\\);${ws}virtual int vg\\((void|)\\);${ws}virtual int vd\\((void|)\\);${ws}int fd\\((void|)\\);${ws}\} \[*\]+$nl$gdb_prompt $" {
-           pass "ptype ppd"
-       }
-       -re "type = class D : public AD, public virtual V \{${ws}public:${ws}int d;${ws}D & operator=\\(D const ?&\\);${ws}D\\((D const|const D) ?&\\);${ws}D\\((void|)\\);${ws}static void s\\((void|)\\);${ws}virtual int vg\\((void|)\\);${ws}virtual int vd\\((void|)\\);${ws}int fd\\((void|)\\);${ws}\} \[*\]+$nl$gdb_prompt $" {
-           pass "ptype ppd"
-       }
-        -re "type = class D : public AD, public virtual V \{${ws}public:${ws}int d;${ws}static void s\\((void|)\\);${ws}virtual int vg\\((void|)\\);${ws}virtual int vd\\((void|)\\);${ws}int fd\\((void|)\\);${ws}\} \[*\]+$nl$gdb_prompt $" {
-            pass "ptype ppd (aCC)"
-        }
-       -re "type = class D : public AD, public virtual V \{${ws}private:${ws}V \\*${vbptr}V;${ws}public:${ws}int d;((${ws}D & operator=\\(D const ?&\\);)|(${ws}D\\(int, D const ?&\\);)|(${ws}D\\(int\\);)|(${ws}static void s\\((void|)\\);)|(${ws}virtual int vg\\((void|)\\);)|(${ws}virtual int vd\\((void|)\\);)|(${ws}int fd\\((void|)\\);))*${ws}\} \[*\]+$nl$gdb_prompt $" {
-           pass "ptype ppd (obsolescent gcc or gdb)"
-       }
-       -re ".*$gdb_prompt $" {
-           fail "ptype ppd"
-       }
-       timeout {
-           fail "ptype ppd (timeout)"
-       }
-    }
+    # class C
 
-    send_gdb "ptype pAd\n"
-    gdb_expect {
-       -re "type = class AD \{${ws}public:${ws}AD & operator=\\(AD const ?&\\);${ws}AD\\((AD const|const AD) ?&\\);${ws}AD\\((void|)\\);${ws}virtual int vg\\((void|)\\);${ws}\} \[*\]+$nl$gdb_prompt $" {
-           pass "ptype pAd"
-       }
-       -re "type = class AD \{${ws}public:${ws}virtual int vg \\((void|)\\);${ws}\} \[*\]+$nl$gdb_prompt $" {
-           pass "ptype pAd (aCC)"
-       }
-       -re "type = class AD \{${ws}public:((${ws}AD & operator=\\(AD const ?&\\);)|(${ws}AD\\(AD const ?&\\);)|(${ws}AD\\((void|)\\);)|(${ws}virtual int vg\\((void|)\\);))*${ws}\} \[*\]+$nl$gdb_prompt $" {
-           pass "ptype pAd (obsolescent gcc or gdb)"
-       }
-       -re ".*$gdb_prompt $" {
-           fail "ptype pAd"
+    cp_test_ptype_class \
+       "ptype C" "" "class" "C" \
+       {
+           { base         "public virtual V" }
+           { vbase        "V" }
+           { field public "int c;" }
        }
-       timeout {
-           fail "ptype pAd (timeout)"
-       }
-    }
 
-    send_gdb "ptype a\n"
-    gdb_expect {
-       -re "type = class A : public virtual V \{${ws}private:${ws}V \\*${vbptr}V;${ws}int a;${ws}public:${ws}A & operator=\\(A const ?&\\);${ws}A\\(int, A const ?&\\);${ws}A\\(int\\);${ws}virtual int f\\((void|)\\);${ws}\}$nl$gdb_prompt $" {
-           pass "ptype a"
-       }
-       -re "type = class A : public virtual V \{${ws}private:${ws}int a;${ws}public:${ws}A & operator=\\(A const ?&\\);${ws}A\\((A const|const A) ?&\\);${ws}A\\((void|)\\);${ws}virtual int f\\((void|)\\);${ws}\}$nl$gdb_prompt $" {
-           pass "ptype a"
-       }
-        -re "type = class A : public virtual V \{${ws}private:${ws}int a;${ws}public:${ws}virtual int f\\((void|)\\);${ws}\}$nl$gdb_prompt $" {
-            pass "ptype a (aCC)"
-        }
-       -re "type = class A : public virtual V \{${ws}private:${ws}V \\*${vbptr}V;${ws}int a;${ws}public:((${ws}A & operator=\\(A const ?&\\);)|(${ws}A\\(int, A const ?&\\);)|(${ws}A\\(int\\);)|(${ws}virtual int f\\((void|)\\);))*${ws}\}$nl$gdb_prompt $" {
-           pass "ptype a (obsolescent gcc or gdb)"
-       }
-       -re ".*$gdb_prompt $" {
-           fail "ptype a"
-       }
-       timeout {
-           fail "ptype a (timeout)"
-       }
-    }
+    # class AD
 
-    send_gdb "ptype b\n"
-    gdb_expect {
-       -re "type = class B : public A \{${ws}private:${ws}int b;${ws}public:${ws}B & operator=\\(B const ?&\\);${ws}B\\(int, B const ?&\\);${ws}B\\(int\\);${ws}virtual int f\\((void|)\\);${ws}\}$nl$gdb_prompt $" {
-           pass "ptype b"
+    cp_test_ptype_class \
+       "ptype AD" "" "class" "AD" \
+       {
+           { method public "virtual int vg();" }
        }
-       -re "type = class B : public A \{${ws}private:${ws}int b;${ws}public:${ws}B & operator=\\(B const ?&\\);${ws}B\\((B const|const B) ?&\\);${ws}B\\((void|)\\);${ws}virtual int f\\((void|)\\);${ws}\}$nl$gdb_prompt $" {
-           pass "ptype b"
-       }
-       -re "type = class B : public A \{${ws}private:${ws}int b;${ws}public:${ws}virtual int f \\((void|)\\);${ws}\}$nl$gdb_prompt $" {
-           pass "ptype b (aCC)"
-       }
-       -re "type = class B : public A \{${ws}private:${ws}int b;${ws}public:((${ws}B & operator=\\(B const ?&\\);)|(${ws}B\\(int, B const ?&\\);)|(${ws}B\\(int\\);)|(${ws}virtual int f\\((void|)\\);))*${ws}\}$nl$gdb_prompt $" {
-           pass "ptype b (obsolescent gcc or gdb)"
-       }
-       -re ".*$gdb_prompt $" {
-           fail "ptype b"
-       }
-       timeout {
-           fail "ptype b (timeout)"
-       }
-    }
 
-    send_gdb "ptype c\n"
-    gdb_expect {
-       -re "type = class C : public virtual V \{${ws}private:${ws}V \\*${vbptr}V;${ws}public:${ws}int c;${ws}C & operator=\\(C const ?&\\);${ws}C\\(int, C const ?&\\);${ws}C\\(int\\);${ws}\}$nl$gdb_prompt $" {
-           pass "ptype c"
-       }
-       -re "type = class C : public virtual V \{${ws}public:${ws}int c;${ws}C & operator=\\(C const ?&\\);${ws}C\\((C const|const C) ?&\\);${ws}C\\((void|)\\);${ws}\}$nl$gdb_prompt $" {
-           pass "ptype c"
-       }
-        -re "type = class C : public virtual V \{${ws}public:${ws}int c;${ws}\}$nl$gdb_prompt $" {
-            pass "ptype c (aCC)"
-        }
-       -re "type = class C : public virtual V \{${ws}private:${ws}V \\*${vbptr}V;${ws}public:${ws}int c;((${ws}C & operator=\\(C const ?&\\);)|(${ws}C\\(int, C const ?&\\);)|(${ws}C\\(int\\);))*${ws}\}$nl$gdb_prompt $" {
-           pass "ptype c (obsolescent gcc or gdb)"
-       }
-       -re ".*$gdb_prompt $" {
-           fail "ptype c"
-       }
-       timeout {
-           fail "ptype c (timeout)"
-       }
-    }
+    # class D
 
-    send_gdb "ptype d\n"
-    gdb_expect {
-       -re "type = class D : public AD, public virtual V \{${ws}private:${ws}V \\*${vbptr}V;${ws}public:${ws}int d;${ws}D & operator=\\(D const ?&\\);${ws}D\\(int, D const ?&\\);${ws}D\\(int\\);${ws}static void s\\((void|)\\);${ws}virtual int vg\\((void|)\\);${ws}virtual int vd\\((void|)\\);${ws}int fd\\((void|)\\);${ws}\}$nl$gdb_prompt $" {
-           pass "ptype d"
-       }
-       -re "type = class D : public AD, public virtual V \{${ws}public:${ws}int d;${ws}D & operator=\\(D const ?&\\);${ws}D\\((D const|const D) ?&\\);${ws}D\\((void|)\\);${ws}static void s\\((void|)\\);${ws}virtual int vg\\((void|)\\);${ws}virtual int vd\\((void|)\\);${ws}int fd\\((void|)\\);${ws}\}$nl$gdb_prompt $" {
-           pass "ptype d"
-       }
-        -re "type = class D : public AD, public virtual V \{${ws}public:${ws}int d;${ws}static void s\\((void|)\\);${ws}virtual int vg\\((void|)\\);${ws}virtual int vd\\((void|)\\);${ws}int fd\\((void|)\\);${ws}\}$nl$gdb_prompt $" {
-            pass "ptype d (aCC)"
-        }
-       -re "type = class D : public AD, public virtual V \{${ws}private:${ws}V \\*${vbptr}V;${ws}public:${ws}int d;((${ws}D & operator=\\(D const ?&\\);)|(${ws}D\\(int, D const ?&\\);)|(${ws}D\\(int\\);)|(${ws}static void s\\((void|)\\);)|(${ws}virtual int vg\\((void|)\\);)|(${ws}virtual int vd\\((void|)\\);)|(${ws}int fd\\((void|)\\);))*${ws}\}$nl$gdb_prompt $" {
-           pass "ptype d (obsolescent gcc or gdb)"
-       }
-       -re ".*$gdb_prompt $" {
-           fail "ptype d"
-       }
-       timeout {
-           fail "ptype d (timeout)"
+    cp_test_ptype_class \
+       "ptype D" "" "class" "D" \
+       {
+           { base          "public AD" }
+           { base          "public virtual V" }
+           { vbase         "V" }
+           { method public "static void s();" }
+           { method public "virtual int vg();" }
+           { method public "virtual int vd();" }
+           { method public "int fd();" }
+           { field  public "int d;" }
        }
-    }
 
-    send_gdb "ptype e\n"
-    gdb_expect {
-       -re "type = class E : public B, public virtual V, public D, public C \{${ws}public:${ws}int e;${ws}E & operator=\\(E const ?&\\);${ws}E\\(int, E const ?&\\);${ws}E\\(int\\);${ws}virtual int f\\((void|)\\);${ws}virtual int vg\\((void|)\\);${ws}virtual int vv\\((void|)\\);${ws}\}$nl$gdb_prompt $" {
-           pass "ptype e"
-       }
-       -re "type = class E : public B, public virtual V, public D, public C \{${ws}public:${ws}int e;${ws}E & operator=\\(E const ?&\\);${ws}E\\((E const|const E) ?&\\);${ws}E\\((void|)\\);${ws}virtual int f\\((void|)\\);${ws}virtual int vg\\((void|)\\);${ws}virtual int vv\\((void|)\\);${ws}\}$nl$gdb_prompt $" {
-           pass "ptype e"
-       }
-       -re "type = class E : public B, public virtual V, public D, public C \{${ws}public:${ws}int e;${ws}virtual int f \\((void|)\\);${ws}virtual int vg \\((void|)\\);${ws}virtual int vv \\((void|)\\);${ws}\}$nl$gdb_prompt $" {
-           pass "ptype e (aCC)"
-       }
-       -re "type = class E : public B, public virtual V, public D, public C \{${ws}public:${ws}int e;((${ws}E & operator=\\(E const ?&\\);)|(${ws}E\\(int, E const ?&\\);)|(${ws}E\\(int\\);)|(${ws}virtual int f\\((void|)\\);)|(${ws}virtual int vg\\((void|)\\);)|(${ws}virtual int vv\\((void|)\\);))*${ws}\}$nl$gdb_prompt $" {
-           pass "ptype e (obsolescent gcc or gdb)"
-       }
-       -re ".*$gdb_prompt $" {
-           fail "ptype e"
-       }
-       timeout {
-           fail "ptype e (timeout)"
-       }
-    }
+    # class E
 
-    send_gdb "ptype v\n"
-    gdb_expect {
-       -re "type = class V : public VA, public VB \{${ws}public:${ws}int w;${ws}V & operator=\\(V const ?&\\);${ws}V\\((V const|const V) ?&\\);${ws}V\\((void|)\\);${ws}int f\\((void|)\\);${ws}virtual int vv\\((void|)\\);${ws}\}$nl$gdb_prompt $" {
-           pass "ptype v"
+    cp_test_ptype_class \
+       "ptype E" "" "class" "E" \
+       {
+           { base          "public B" }
+           { base          "public virtual V" }
+           { base          "public D" }
+           { base          "public C" }
+           { vbase         "V" }
+           { method public "virtual int f();" }
+           { method public "virtual int vg();" }
+           { method public "virtual int vv();" }
+           { field  public "int e;" }
        }
-       -re "type = class V : public VA, public VB \{${ws}public:${ws}int w;${ws}int f \\((void|)\\);${ws}virtual int vv \\((void|)\\);${ws}\}$nl$gdb_prompt $" {
-           pass "ptype v (aCC)"
-       }
-       -re "type = class V : public VA, public VB \{${ws}public:${ws}int w;((${ws}V & operator=\\(V const ?&\\);)|(${ws}V\\(V const ?&\\);)|(${ws}V\\((void|)\\);)|(${ws}int f\\((void|)\\);)|(${ws}virtual int vv\\((void|)\\);))*${ws}\}$nl$gdb_prompt $" {
-           pass "ptype v (obsolescent gcc or gdb)"
-       }
-       -re ".*$gdb_prompt $" {
-           fail "ptype v"
-       }
-       timeout {
-           fail "ptype v (timeout)"
-       }
-    }
 
-    send_gdb "ptype vb\n"
-    gdb_expect {
-       -re "type = class VB \{${ws}public:${ws}int vb;${ws}VB & operator=\\(VB const ?&\\);${ws}VB\\((VB const|const VB) ?&\\);${ws}VB\\((void|)\\);${ws}int fvb\\((void|)\\);${ws}virtual int vvb\\((void|)\\);${ws}\}$nl$gdb_prompt $" {
-           pass "ptype vb"
-       }
-       -re "type = class VB \{${ws}public:${ws}int vb;${ws}int fvb \\((void|)\\);${ws}virtual int vvb \\((void|)\\);${ws}\}$nl$gdb_prompt $" {
-           pass "ptype vb (aCC)"
-       }
-       -re "type = class VB \{${ws}public:${ws}int vb;((${ws}VB & operator=\\(VB const ?&\\);)|(${ws}VB\\(VB const ?&\\);)|(${ws}VB\\((void|)\\);)|(${ws}int fvb\\((void|)\\);)|(${ws}virtual int vvb\\((void|)\\);))*${ws}\}$nl$gdb_prompt $" {
-           pass "ptype vb (obsolescent gcc or gdb)"
-       }
-       -re ".*$gdb_prompt $" {
-           fail "ptype vb"
-       }
-       timeout {
-           fail "ptype vb (timeout)"
-       }
-    }
+    # An instance of D
 
-    send_gdb "ptype pAa\n"
-    gdb_expect {
-       -re "type = class A : public virtual V \{${ws}private:${ws}V \\*${vbptr}V;${ws}int a;${ws}public:${ws}A & operator=\\(A const ?&\\);${ws}A\\(int, A const ?&\\);${ws}A\\(int\\);${ws}virtual int f\\((void|)\\);${ws}\} \[*\]+$nl$gdb_prompt $" {
-           pass "ptype pAa"
-       }
-       -re "type = class A : public virtual V \{${ws}private:${ws}int a;${ws}public:${ws}A & operator=\\(A const ?&\\);${ws}A\\((A const|const A) ?&\\);${ws}A\\((void|)\\);${ws}virtual int f\\((void|)\\);${ws}\} \[*\]+$nl$gdb_prompt $" {
-           pass "ptype pAa"
-       }
-        -re "type = class A : public virtual V \{${ws}private:${ws}int a;${ws}public:${ws}virtual int f\\((void|)\\);${ws}\} \[*\]+$nl$gdb_prompt $" {
-            pass "ptype pAa (aCC)"
-        }
-       -re "type = class A : public virtual V \{${ws}private:${ws}V \\*${vbptr}V;${ws}int a;${ws}public:((${ws}A & operator=\\(A const ?&\\);)|(${ws}A\\(int, A const ?&\\);)|(${ws}A\\(int\\);)|(${ws}virtual int f\\((void|)\\);))*${ws}\} \[*\]+$nl$gdb_prompt $" {
-           pass "ptype pAa (obsolescent gcc or gdb)"
-       }
-       -re ".*$gdb_prompt $" {
-           fail "ptype pAa"
-       }
-       timeout {
-           fail "ptype pAa (timeout)"
-       }
-    }
+    cp_test_ptype_class "ptype dd" "" "class" "D" ibid
 
-    send_gdb "ptype pAe\n"
-    gdb_expect {
-       -re "type = class A : public virtual V \{${ws}private:${ws}V \\*${vbptr}V;${ws}int a;${ws}public:${ws}A & operator=\\(A const ?&\\);${ws}A\\(int, A const ?&\\);${ws}A\\(int\\);${ws}virtual int f\\((void|)\\);${ws}\} \[*\]+$nl$gdb_prompt $" {
-           pass "ptype pAe"
-       }
-       -re "type = class A : public virtual V \{${ws}private:${ws}int a;${ws}public:${ws}A & operator=\\(A const ?&\\);${ws}A\\((A const|const A) ?&\\);${ws}A\\((void|)\\);${ws}virtual int f\\((void|)\\);${ws}\} \[*\]+$nl$gdb_prompt $" {
-           pass "ptype pAe"
-       }
-        -re "type = class A : public virtual V \{${ws}private:${ws}int a;${ws}public:${ws}virtual int f\\((void|)\\);${ws}\} \[*\]+$nl$gdb_prompt $" {
-            pass "ptype pAe (aCC)"
-       }
-       -re "type = class A : public virtual V \{${ws}private:${ws}V \\*${vbptr}V;${ws}int a;${ws}public:((${ws}A & operator=\\(A const ?&\\);)|(${ws}A\\(int, A const ?&\\);)|(${ws}A\\(int\\);)|(${ws}virtual int f\\((void|)\\);))*${ws}\} \[*\]+$nl$gdb_prompt $" {
-           pass "ptype pAe (obsolescent gcc or gdb)"
-       }
-       -re ".*$gdb_prompt $" {
-           fail "ptype pAe"
-       }
-       timeout {
-           fail "ptype pAe (timeout)"
-       }
-    }
+    # An instance of D *
 
-    send_gdb "ptype pBe\n"
-    gdb_expect {
-       -re "type = class B : public A \{${ws}private:${ws}int b;${ws}public:${ws}B & operator=\\(B const ?&\\);${ws}B\\(int, B const ?&\\);${ws}B\\(int\\);${ws}virtual int f\\((void|)\\);${ws}\} \[*\]+$nl$gdb_prompt $" {
-           pass "ptype pBe"
-       }
-       -re "type = class B : public A \{${ws}private:${ws}int b;${ws}public:${ws}B & operator=\\(B const ?&\\);${ws}B\\((B const|const B) ?&\\);${ws}B\\((void|)\\);${ws}virtual int f\\((void|)\\);${ws}\} \[*\]+$nl$gdb_prompt $" {
-           pass "ptype pBe"
-       }
-       -re "type = class B : public A \{${ws}private:${ws}int b;${ws}public:${ws}virtual int f \\((void|)\\);${ws}\} \[*\]+$nl$gdb_prompt $" {
-           pass "ptype pBe (aCC)"
-       }
-       -re "type = class B : public A \{${ws}private:${ws}int b;${ws}public:((${ws}B & operator=\\(B const ?&\\);)|(${ws}B\\(int, B const ?&\\);)|(${ws}B\\(int\\);)|(${ws}virtual int f\\((void|)\\);))*${ws}\} \[*\]+$nl$gdb_prompt $" {
-           pass "ptype pBe (obsolescent gcc or gdb)"
-       }
-       -re ".*$gdb_prompt $" {
-           fail "ptype pBe"
-       }
-       timeout {
-           fail "ptype pBe (timeout)"
-       }
-    }
+    cp_test_ptype_class "ptype ppd" "" "class" "D" ibid "*"
 
-    send_gdb "ptype pDd\n"
-    gdb_expect {
-       -re "type = class D : public AD, public virtual V \{${ws}private:${ws}V \\*${vbptr}V;${ws}public:${ws}int d;${ws}D & operator=\\(D const ?&\\);${ws}D\\(int, D const ?&\\);${ws}D\\(int\\);${ws}static void s\\((void|)\\);${ws}virtual int vg\\((void|)\\);${ws}virtual int vd\\((void|)\\);${ws}int fd\\((void|)\\);${ws}\} \[*\]+$nl$gdb_prompt $" {
-           pass "ptype pDd"
-       }
-       -re "type = class D : public AD, public virtual V \{${ws}public:${ws}int d;${ws}D & operator=\\(D const ?&\\);${ws}D\\((D const|const D) ?&\\);${ws}D\\((void|)\\);${ws}static void s\\((void|)\\);${ws}virtual int vg\\((void|)\\);${ws}virtual int vd\\((void|)\\);${ws}int fd\\((void|)\\);${ws}\} \[*\]+$nl$gdb_prompt $" {
-           pass "ptype pDd"
-       }
-        -re "type = class D : public AD, public virtual V \{${ws}public:${ws}int d;${ws}static void s\\((void|)\\);${ws}virtual int vg\\((void|)\\);${ws}virtual int vd\\((void|)\\);${ws}int fd\\((void|)\\);${ws}\} \[*\]+$nl$gdb_prompt $" {
-            pass "ptype pDd (aCC)"
-        }
-       -re "type = class D : public AD, public virtual V \{${ws}private:${ws}V \\*${vbptr}V;${ws}public:${ws}int d;((${ws}D & operator=\\(D const ?&\\);)|(${ws}D\\(int, D const ?&\\);)|(${ws}D\\(int\\);)|(${ws}static void s\\((void|)\\);)|(${ws}virtual int vg\\((void|)\\);)|(${ws}virtual int vd\\((void|)\\);)|(${ws}int fd\\((void|)\\);))*${ws}\} \[*\]+$nl$gdb_prompt $" {
-           pass "ptype pDd (obsolescent gcc or gdb)"
-       }
-       -re ".*$gdb_prompt $" {
-           fail "ptype pDd"
-       }
-       timeout {
-           fail "ptype pDd (timeout)"
-       }
-    }
+    # An instance of AD *
+    # TODO: this should be named pADd, not pAd.
 
-    send_gdb "ptype pDe\n"
-    gdb_expect {
-       -re "type = class D : public AD, public virtual V \{${ws}private:${ws}V \\*${vbptr}V;${ws}public:${ws}int d;${ws}D & operator=\\(D const ?&\\);${ws}D\\(int, D const ?&\\);${ws}D\\(int\\);${ws}static void s\\((void|)\\);${ws}virtual int vg\\((void|)\\);${ws}virtual int vd\\((void|)\\);${ws}int fd\\((void|)\\);${ws}\} \[*\]+$nl$gdb_prompt $" {
-           pass "ptype pDe"
-       }
-       -re "type = class D : public AD, public virtual V \{${ws}public:${ws}int d;${ws}D & operator=\\(D const ?&\\);${ws}D\\((D const|const D) ?&\\);${ws}D\\((void|)\\);${ws}static void s\\((void|)\\);${ws}virtual int vg\\((void|)\\);${ws}virtual int vd\\((void|)\\);${ws}int fd\\((void|)\\);${ws}\} \[*\]+$nl$gdb_prompt $" {
-           pass "ptype pDe"
-       }
-        -re "type = class D : public AD, public virtual V \{${ws}public:${ws}int d;${ws}static void s\\((void|)\\);${ws}virtual int vg\\((void|)\\);${ws}virtual int vd\\((void|)\\);${ws}int fd\\((void|)\\);${ws}\} \[*\]+$nl$gdb_prompt $" {
-            pass "ptype pDe (aCC)"
-        }
-       -re "type = class D : public AD, public virtual V \{${ws}private:${ws}V \\*${vbptr}V;${ws}public:${ws}int d;((${ws}D & operator=\\(D const ?&\\);)|(${ws}D\\(int, D const ?&\\);)|(${ws}D\\(int\\);)|(${ws}static void s\\((void|)\\);)|(${ws}virtual int vg\\((void|)\\);)|(${ws}virtual int vd\\((void|)\\);)|(${ws}int fd\\((void|)\\);))*${ws}\} \[*\]+$nl$gdb_prompt $" {
-           pass "ptype pDe (obsolescent gcc or gdb)"
-       }
-       -re ".*$gdb_prompt $" {
-           fail "ptype pDe"
-       }
-       timeout {
-           fail "ptype pDe (timeout)"
-       }
-    }
+    cp_test_ptype_class "ptype pAd" "" "class" "AD" ibid "*"
 
-    send_gdb "ptype pVa\n"
-    gdb_expect {
-       -re "type = class V : public VA, public VB \{${ws}public:${ws}int w;${ws}V & operator=\\(V const ?&\\);${ws}V\\((V const|const V) ?&\\);${ws}V\\((void|)\\);${ws}int f\\((void|)\\);${ws}virtual int vv\\((void|)\\);${ws}\} \[*\]+$nl$gdb_prompt $" {
-           pass "ptype pVa"
-       }
-       -re "type = class V : public VA, public VB \{${ws}public:${ws}int w;${ws}int f \\((void|)\\);${ws}virtual int vv \\((void|)\\);${ws}\} \[*\]+$nl$gdb_prompt $" {
-           pass "ptype pVa (aCC)"
-       }
-       -re "type = class V : public VA, public VB \{${ws}public:${ws}int w;((${ws}V & operator=\\(V const ?&\\);)|(${ws}V\\(V const ?&\\);)|(${ws}V\\((void|)\\);)|(${ws}int f\\((void|)\\);)|(${ws}virtual int vv\\((void|)\\);))*${ws}\} \[*\]+$nl$gdb_prompt $" {
-           pass "ptype pVa (obsolescent gcc or gdb)"
-       }
-       -re ".*$gdb_prompt $" {
-           fail "ptype pVa"
-       }
-       timeout {
-           fail "ptype pVa (timeout)"
-       }
-    }
+    # Instances of these classes.
 
-    send_gdb "ptype pVv\n"
-    gdb_expect {
-       -re "type = class V : public VA, public VB \{${ws}public:${ws}int w;${ws}V & operator=\\(V const ?&\\);${ws}V\\((V const|const V) ?&\\);${ws}V\\((void|)\\);${ws}int f\\((void|)\\);${ws}virtual int vv\\((void|)\\);${ws}\} \[*\]+$nl$gdb_prompt $" {
-           pass "ptype pVv"
-       }
-       -re "type = class V : public VA, public VB \{${ws}public:${ws}int w;${ws}int f \\((void|)\\);${ws}virtual int vv \\((void|)\\);${ws}\} \[*\]+$nl$gdb_prompt $" {
-           pass "ptype pVv (aCC)"
-       }
-       -re "type = class V : public VA, public VB \{${ws}public:${ws}int w;((${ws}V & operator=\\(V const ?&\\);)|(${ws}V\\(V const ?&\\);)|(${ws}V\\((void|)\\);)|(${ws}int f\\((void|)\\);)|(${ws}virtual int vv\\((void|)\\);))*${ws}\} \[*\]+$nl$gdb_prompt $" {
-           pass "ptype pVv (obsolescent gcc or gdb)"
-       }
-       -re ".*$gdb_prompt $" {
-           fail "ptype pVv"
-       }
-       timeout {
-           fail "ptype pVv (timeout)"
-       }
-    }
+    cp_test_ptype_class "ptype a" "" "class" "A" ibid
+    cp_test_ptype_class "ptype b" "" "class" "B" ibid
+    cp_test_ptype_class "ptype c" "" "class" "C" ibid
+    cp_test_ptype_class "ptype d" "" "class" "D" ibid
+    cp_test_ptype_class "ptype e" "" "class" "E" ibid
+    cp_test_ptype_class "ptype v" "" "class" "V" ibid
+    cp_test_ptype_class "ptype vb" "" "class" "VB" ibid
 
-    send_gdb "ptype pVe\n"
-    gdb_expect {
-       -re "type = class V : public VA, public VB \{${ws}public:${ws}int w;${ws}V & operator=\\(V const ?&\\);${ws}V\\((V const|const V) ?&\\);${ws}V\\((void|)\\);${ws}int f\\((void|)\\);${ws}virtual int vv\\((void|)\\);${ws}\} \[*\]+$nl$gdb_prompt $" {
-           pass "ptype pVe"
-       }
-       -re "type = class V : public VA, public VB \{${ws}public:${ws}int w;${ws}int f \\((void|)\\);${ws}virtual int vv \\((void|)\\);${ws}\} \[*\]+$nl$gdb_prompt $" {
-           pass "ptype pVe (aCC)"
-       }
-       -re "type = class V : public VA, public VB \{${ws}public:${ws}int w;((${ws}V & operator=\\(V const ?&\\);)|(${ws}V\\(V const ?&\\);)|(${ws}V\\((void|)\\);)|(${ws}int f\\((void|)\\);)|(${ws}virtual int vv\\((void|)\\);))*${ws}\} \[*\]+$nl$gdb_prompt $" {
-           pass "ptype pVe (obsolescent gcc or gdb)"
-       }
-       -re ".*$gdb_prompt $" {
-           fail "ptype pVe"
-       }
-       timeout {
-           fail "ptype pVe (timeout)"
-       }
-    }
-
-    send_gdb "ptype pVd\n"
-    gdb_expect {
-       -re "type = class V : public VA, public VB \{${ws}public:${ws}int w;${ws}V & operator=\\(V const ?&\\);${ws}V\\((V const|const V) ?&\\);${ws}V\\((void|)\\);${ws}int f\\((void|)\\);${ws}virtual int vv\\((void|)\\);${ws}\} \[*\]+$nl$gdb_prompt $" {
-           pass "ptype pVd"
-       }
-       -re "type = class V : public VA, public VB \{${ws}public:${ws}int w;${ws}int f \\((void|)\\);${ws}virtual int vv \\((void|)\\);${ws}\} \[*\]+$nl$gdb_prompt $" {
-           pass "ptype pVd (aCC)"
-       }
-       -re "type = class V : public VA, public VB \{${ws}public:${ws}int w;((${ws}V & operator=\\(V const ?&\\);)|(${ws}V\\(V const ?&\\);)|(${ws}V\\((void|)\\);)|(${ws}int f\\((void|)\\);)|(${ws}virtual int vv\\((void|)\\);))*${ws}\} \[*\]+$nl$gdb_prompt $" {
-           pass "ptype pVd (obsolescent gcc or gdb)"
-       }
-       -re ".*$gdb_prompt $" {
-           fail "ptype pVd"
-       }
-       timeout {
-           fail "ptype pVd (timeout)"
-       }
-    }
-
-    send_gdb "ptype pADe\n"
-    gdb_expect {
-       -re "type = class AD \{${ws}public:${ws}AD & operator=\\(AD const ?&\\);${ws}AD\\((AD const|const AD) ?&\\);${ws}AD\\((void|)\\);${ws}virtual int vg\\((void|)\\);${ws}\} \[*\]+$nl$gdb_prompt $" {
-           pass "ptype pADe"
-       }
-       -re "type = class AD \{${ws}public:${ws}virtual int vg \\((void|)\\);${ws}\} \[*\]+$nl$gdb_prompt $" {
-           pass "ptype pADe (aCC)"
-       }
-       -re "type = class AD \{${ws}public:((${ws}AD & operator=\\(AD const ?&\\);)|(${ws}AD\\(AD const ?&\\);)|(${ws}AD\\((void|)\\);)|(${ws}virtual int vg\\((void|)\\);))*${ws}\} \[*\]+$nl$gdb_prompt $" {
-           pass "ptype pADe (obsolescent gcc or gdb)"
-       }
-       -re ".*$gdb_prompt $" {
-           fail "ptype pADe"
-       }
-       timeout {
-           fail "ptype pADe (timeout)"
-       }
-    }
+    # Instances of pointers to these classes.
 
-    send_gdb "ptype pEe\n"
-    gdb_expect {
-       -re "type = class E : public B, public virtual V, public D, public C \{${ws}public:${ws}int e;${ws}E & operator=\\(E const ?&\\);${ws}E\\(int, E const ?&\\);${ws}E\\(int\\);${ws}virtual int f\\((void|)\\);${ws}virtual int vg\\((void|)\\);${ws}virtual int vv\\((void|)\\);${ws}\} \[*\]+$nl$gdb_prompt $" {
-           pass "ptype pEe"
-       }
-       -re "type = class E : public B, public virtual V, public D, public C \{${ws}public:${ws}int e;${ws}E & operator=\\(E const ?&\\);${ws}E\\((E const|const E) ?&\\);${ws}E\\((void|)\\);${ws}virtual int f\\((void|)\\);${ws}virtual int vg\\((void|)\\);${ws}virtual int vv\\((void|)\\);${ws}\} \[*\]+$nl$gdb_prompt $" {
-           pass "ptype pEe"
-       }
-       -re "type = class E : public B, public virtual V, public D, public C \{${ws}public:${ws}int e;${ws}virtual int f \\((void|)\\);${ws}virtual int vg \\((void|)\\);${ws}virtual int vv \\((void|)\\);${ws}\} \[*\]+$nl$gdb_prompt $" {
-           pass "ptype pEe (aCC)"
-       }
-       -re "type = class E : public B, public virtual V, public D, public C \{${ws}public:${ws}int e;((${ws}E & operator=\\(E const ?&\\);)|(${ws}E\\(int, E const ?&\\);)|(${ws}E\\(int\\);)|(${ws}virtual int f\\((void|)\\);)|(${ws}virtual int vg\\((void|)\\);)|(${ws}virtual int vv\\((void|)\\);))*${ws}\} \[*\]+$nl$gdb_prompt $" {
-           pass "ptype pEe (obsolescent gcc or gdb)"
-       }
-       -re ".*$gdb_prompt $" {
-           fail "ptype pEe"
-       }
-       timeout {
-           fail "ptype pEe (timeout)"
-       }
-    }
+    cp_test_ptype_class "ptype pAa" "" "class" "A" ibid "*"
+    cp_test_ptype_class "ptype pAe" "" "class" "A" ibid "*"
+    cp_test_ptype_class "ptype pBe" "" "class" "B" ibid "*"
+    cp_test_ptype_class "ptype pDd" "" "class" "D" ibid "*"
+    cp_test_ptype_class "ptype pDe" "" "class" "D" ibid "*"
+    cp_test_ptype_class "ptype pVa" "" "class" "V" ibid "*"
+    cp_test_ptype_class "ptype pVv" "" "class" "V" ibid "*"
+    cp_test_ptype_class "ptype pVe" "" "class" "V" ibid "*"
+    cp_test_ptype_class "ptype pVd" "" "class" "V" ibid "*"
+    cp_test_ptype_class "ptype pADe" "" "class" "AD" ibid "*"
+    cp_test_ptype_class "ptype pEe" "" "class" "E" ibid "*"
+    cp_test_ptype_class "ptype pVB" "" "class" "VB" ibid "*"
 
-    send_gdb "ptype pVB\n"
-    gdb_expect {
-       -re "type = class VB \{${ws}public:${ws}int vb;${ws}VB & operator=\\(VB const ?&\\);${ws}VB\\((VB const|const VB) ?&\\);${ws}VB\\((void|)\\);${ws}int fvb\\((void|)\\);${ws}virtual int vvb\\((void|)\\);${ws}\} \[*\]+$nl$gdb_prompt $" {
-           pass "ptype pVB"
-       }
-       -re "type = class VB \{${ws}public:${ws}int vb;${ws}int fvb \\((void|)\\);${ws}virtual int vvb \\((void|)\\);${ws}\} \[*\]+$nl$gdb_prompt $" {
-           pass "ptype pVB (aCC)"
-       }
-       -re "type = class VB \{${ws}public:${ws}int vb;((${ws}VB & operator=\\(VB const ?&\\);)|(${ws}VB\\(VB const ?&\\);)|(${ws}VB\\((void|)\\);)|(${ws}int fvb\\((void|)\\);)|(${ws}virtual int vvb\\((void|)\\);))*${ws}\} \[*\]+$nl$gdb_prompt $" {
-           pass "ptype pVB (obsolescent gcc or gdb)"
-       }
-       -re ".*$gdb_prompt $" {
-           fail "ptype pVB"
-       }
-       timeout {
-           fail "ptype pVB (timeout)"
-       }
-    }
 }
 
-#
-#  Test calling of virtual functions.
-#
+# Call virtual functions.
 
 proc test_virtual_calls {} {
     global gdb_prompt
-    global GDB
     global nl
 
     if [target_info exists gdb,cannot_call_functions] {
@@ -741,207 +183,112 @@ proc test_virtual_calls {} {
        return 0
     }
 
-    send_gdb "print pAe->f()\n"
-    gdb_expect {
-       -re ".* = 20$nl$gdb_prompt $" { pass "print pAe->f()" }
-       -re "Cannot invoke functions on this machine.*$gdb_prompt $" {
-           fail "print pAe->f() (cannot invoke functions, skipping virtual calls)"
-           return 0
-       }
-       -re ".*Cannot access memory at address 0x8.*$gdb_prompt $" {
-           fail "print pAe->f() \
-(known failure with gcc cygnus-2.4.5-930417, skipping virtual calls)"
-           return 0
-       }
-        -re "Cannot resolve .* to any overloaded instance.*$gdb_prompt $" {
-           setup_xfail hppa*-*-* CLLbs16899
-            fail "print pAe->f()"
-       }
-       -re ".*$gdb_prompt $" { fail "print pAe->f()" }
-       timeout { fail "print pAe->f() (timeout)" }
-       eof { fail "print pAe->f() ($GDB dumped core) (FIXME)" ; gdb_virtfunc_restart; return }
-    }
-
-    send_gdb "print pAa->f()\n"
-    gdb_expect {
-       -re ".* = 1$nl$gdb_prompt $" { pass "print pAa->f()" }
-        -re "Cannot resolve .* to any overloaded instance.*$gdb_prompt $" {
-           setup_xfail hppa*-*-*  CLLbs16899
-           fail "print pAa->f()"
-       }
-       -re ".*$gdb_prompt $" { fail "print pAa->f()" }
-       timeout { fail "print pAa->f() (timeout)" }
-       eof { fail "print pAa->f() ($GDB dumped core) (FIXME)" ; gdb_virtfunc_restart; return }
-    }
+    gdb_test "print pAe->f()"   "\\$\[0-9\]+ = 20"
+    gdb_test "print pAa->f()"   "\\$\[0-9\]+ = 1"
+    gdb_test "print pDe->vg()"  "\\$\[0-9\]+ = 202"
+    gdb_test "print pADe->vg()" "\\$\[0-9\]+ = 202"
+    gdb_test "print pDd->vg()"  "\\$\[0-9\]+ = 101"
+    gdb_test "print pEe->vvb()" "\\$\[0-9\]+ = 411"
+    gdb_test "print pVB->vvb()" "\\$\[0-9\]+ = 407"
+    gdb_test "print pBe->vvb()" "\\$\[0-9\]+ = 411"
+    gdb_test "print pDe->vvb()" "\\$\[0-9\]+ = 411"
+    gdb_test "print pEe->vd()"  "\\$\[0-9\]+ = 282"
+    gdb_test "print pEe->fvb()" "\\$\[0-9\]+ = 311"
+
+    # more recent results:
+    # wrong value "202"
+    #   gcc 2.95.3 -gdwarf-2
+    #   gcc 2.95.3 -gstabs+
+    # attempt to take addres of value not located in memory
+    #   gcc 3.3.2 -gdwarf-2
+    #   gcc 3.3.2 -gstabs+
+    #
+    # -- chastain 2003-12-31
 
-    send_gdb "print pDe->vg()\n"
-    gdb_expect {
-       -re ".* = 202$nl$gdb_prompt $" { pass "print pDe->vg()" }
-        -re "Cannot resolve .* to any overloaded instance.*$gdb_prompt $" {
-           setup_xfail hppa*-*-*  CLLbs16899
-           fail "print pDe->vg()"
+    gdb_test_multiple "print pEe->D::vg()" "print pEe->D::vg()" {
+       -re "\\$\[0-9]+ = 102$nl$gdb_prompt $" {
+           pass "print pEe->D::vg()"
        }
-       -re ".*$gdb_prompt $" { fail "print pDe->vg()" }
-       timeout { fail "print pDe->vg() (timeout)" }
-       eof { fail "print pDe->vg() ($GDB dumped core) (FIXME)" ; gdb_virtfunc_restart; return }
-    }
-
-    send_gdb "print pADe->vg()\n"
-    gdb_expect {
-       -re ".* = 202$nl$gdb_prompt $" { pass "print pADe->vg()" }
-        -re "Cannot resolve .* to any overloaded instance.*$gdb_prompt $" {
-           setup_xfail hppa*-*-*  CLLbs16899
-           fail "print pADe->vg()"
+       -re "\\$\[0-9]+ = 202$nl$gdb_prompt $" {
+           # To get this result, we have called pEe->*(&D::vg) ().
+           # That's how GDB interprets this, but it's wrong; in fact
+           # the explicit D:: means to bypass virtual function lookup,
+           # and call D::vg as if it were non-virtual.  We still have
+           # to e.g. adjust "this", though.
+           kfail "gdb/1064" "print pEe->D::vg()"
        }
-       -re ".*$gdb_prompt $" { fail "print pADe->vg()" }
-       timeout { fail "print pADe->vg() (timeout)" }
-       eof { fail "print pADe->vg() ($GDB dumped core) (FIXME)" ; gdb_virtfunc_restart; return }
-    }
-
-    send_gdb "print pDd->vg()\n"
-    gdb_expect {
-       -re ".* = 101$nl$gdb_prompt $" { pass "print pDd->vg()" }
-        -re "Cannot resolve .* to any overloaded instance.*$gdb_prompt $" {
-           setup_xfail hppa*-*-*  CLLbs16899
-           fail "print pDd->vg()"
+       -re "Attempt to take address of value not located in memory.$nl$gdb_prompt $" {
+           kfail "gdb/1064" "print pEe->D::vg()"
        }
-       -re ".*$gdb_prompt $" { fail "print pDd->vg()" }
-       timeout { fail "print pDd->vg() (timeout)" }
-       eof { fail "print pDd->vg() ($GDB dumped core) (FIXME)" ; gdb_virtfunc_restart; return }
-    }
-
-    send_gdb "print pEe->vvb()\n"
-    gdb_expect {
-       -re ".* = 411$nl$gdb_prompt $" { pass "print pEe->vvb()" }
-        -re "Cannot resolve .* to any overloaded instance.*$gdb_prompt $" {
-           setup_xfail hppa*-*-*  CLLbs16899
-           fail "print pEe->vvb()"
-       }
-       -re ".*$gdb_prompt $" { fail "print pEe->vvb()" }
-       timeout { fail "print pEe->vvb() (timeout)" }
-       eof { fail "print pEe->vvb() ($GDB dumped core) (FIXME)" ; gdb_virtfunc_restart; return }
     }
+}
 
-    send_gdb "print pVB->vvb()\n"
-    gdb_expect {
-       -re ".* = 407$nl$gdb_prompt $" { pass "print pVB->vvb()" }
-        -re "Cannot resolve .* to any overloaded instance.*$gdb_prompt $" {
-           setup_xfail hppa*-*-*  CLLbs16899
-           fail "print pVB->vvb()"
-       }
-       -re ".*$gdb_prompt $" { fail "print pVB->vvb()" }
-       timeout { fail "print pVB->vvb() (timeout)" }
-       eof { fail "print pVB->vvb() ($GDB dumped core) (FIXME)" ; gdb_virtfunc_restart; return }
-    }
+# A helper proc that creates a regular expression matching a
+# particular vtable.  NAME is the type name.  Each element of ARGS is
+# the name of a function in the vtable.
 
-    send_gdb "print pBe->vvb()\n"
-    gdb_expect {
-       -re ".* = 411$nl$gdb_prompt $" { pass "print pBe->vvb()" }
-        -re "Cannot resolve .* to any overloaded instance.*$gdb_prompt $" {
-           setup_xfail hppa*-*-*  CLLbs16899
-           fail "print pBe->vvb()"
-       }
-       -re ".*$gdb_prompt $" { fail "print pBe->vvb()" }
-       timeout { fail "print pBe->vvb() (timeout)" }
-       eof { fail "print pBe->vvb() ($GDB dumped core) (FIXME)" ; gdb_virtfunc_restart; return }
-    }
+proc make_one_vtable_result {name args} {
+    global hex
 
-    send_gdb "print pDe->vvb()\n"
-    gdb_expect {
-       -re ".* = 411$nl$gdb_prompt $" { pass "print pDe->vvb()" }
-        -re "Cannot resolve .* to any overloaded instance.*$gdb_prompt $" {
-           setup_xfail hppa*-*-*  CLLbs16899
-           fail "print pDe->vvb()"
-       }
-       -re ".*$gdb_prompt $" { fail "print pDe->vvb()" }
-       timeout { fail "print pDe->vvb() (timeout)" }
-       eof { fail "print pDe->vvb() ($GDB dumped core) (FIXME)" ; gdb_virtfunc_restart; return }
-    }
+    set nls "\[\r\n\]+"
 
-    send_gdb "print pEe->vd()\n"
-    gdb_expect {
-       -re ".* = 282$nl$gdb_prompt $" { pass "print pEe->vd()" }
-        -re "Cannot resolve .* to any overloaded instance.*$gdb_prompt $" {
-           setup_xfail hppa*-*-*  CLLbs16899
-           fail "print pEe->vd()"
-       }
-       -re ".*$gdb_prompt $" { fail "print pEe->vd()" }
-       timeout { fail "print pEe->vd() (timeout)" }
-       eof { fail "print pEe->vd() ($GDB dumped core) (FIXME)" ; gdb_virtfunc_restart; return }
+    set result "vtable for '${name}' @ $hex .subobject @ $hex.:$nls"
+    set count 0
+    foreach func $args {
+       append result ".${count}.: $hex <$func..>${nls}"
+       incr count
     }
 
-    send_gdb "print pEe->fvb()\n"
-    gdb_expect {
-       -re ".* = 311$nl$gdb_prompt $" { pass "print pEe->fvb()" }
-        -re "Cannot resolve .* to any overloaded instance.*$gdb_prompt $" {
-           setup_xfail hppa*-*-*  CLLbs16899
-           fail "print pEe->fvb()"
-       }
-       -re ".*$gdb_prompt $" { fail "print pEe->fvb()" }
-       timeout { fail "print pEe->fvb() (timeout)" }
-       eof { fail "print pEe->fvb() ($GDB dumped core) (FIXME)" ; gdb_virtfunc_restart; return }
-    }
+    return $result
+}
 
-    # fails on target=native, host=i686-pc-linux-gnu%rh-7.2,
-    # gdb=HEAD%2002-02-16, gcc=2.95.3, goption=-gdwarf-2.
-    #
-    # fails on target=native, host=i686-pc-linux-gnu%rh-7.2,
-    # gdb=HEAD%2002-02-16, gcc=2.95.3, goption=-gstabs+.
-    #
-    # fails on target=native, host=i686-pc-linux-gnu%rh-7.2,
-    # gdb=HEAD%2002-02-16, gcc=3.0.3, goption=-gdwarf-2.
-    #
-    # fails on target=native, host=i686-pc-linux-gnu%rh-7.2,
-    # gdb=HEAD%2002-02-16, gcc=3.0.3, goption=-gstabs+.
-    #
-    # fails on target=native, host=i686-pc-linux-gnu%rh-7.2,
-    # gdb=HEAD%2002-02-16, gcc=3.0.4-20020215, goption=-gdwarf-2.
-    #
-    # fails on target=native, host=i686-pc-linux-gnu%rh-7.2,
-    # gdb=HEAD%2002-02-16, gcc=3.0.4-20020215, goption=-gstabs+.
-    #
-    # fails on target=native, host=i686-pc-linux-gnu%rh-7.2,
-    # gdb=HEAD%2002-02-16, gcc=gcc-3_0-branch%2002-02-16, goption=-gdwarf-2.
-    #
-    # fails on target=native, host=i686-pc-linux-gnu%rh-7.2,
-    # gdb=HEAD%2002-02-16, gcc=gcc-3_0-branch%2002-02-16, goption=-gstabs+.
-    #
-    # fails on target=native, host=i686-pc-linux-gnu%rh-7.2,
-    # gdb=HEAD%2002-02-16, gcc=HEAD%2002-02-16, goption=-gdwarf-2.
-    #
-    # fails on target=native, host=i686-pc-linux-gnu%rh-7.2,
-    # gdb=HEAD%2002-02-16, gcc=HEAD%2002-02-16, goption=-gstabs+.
-    #
-    # -- chastain 2002-02-20
-
-    send_gdb "print pEe->D::vg()\n"
-    gdb_expect {
-       -re ".* = 102$nl$gdb_prompt $" { pass "print pEe->D::vg()" }
-       -re "Attempt to take address of value not located in memory.\r\n$gdb_prompt $"
-       { kfail "gdb/1064" "print pEe->D::vg()" }
-       -re ".*$gdb_prompt $" { fail "print pEe->D::vg()" }
-       timeout { fail "print pEe->D::vg() (timeout)" }
-       eof { fail "print pEe->D::vg() ($GDB dumped core) (FIXME)" ; gdb_virtfunc_restart; return }
-    }
+# Test "info vtbl".
+
+proc test_info_vtbl {} {
+    global hex
+
+    set nls "\[\r\n\]+"
+
+    set vt_A [make_one_vtable_result A A::f]
+    set vt_B [make_one_vtable_result B B::f]
+    set vt_V [make_one_vtable_result V VB::vvb V::vv]
+    set vt_V2 [make_one_vtable_result V VB::vvb "virtual thunk to E::vv"]
+    set vt_D [make_one_vtable_result D D::vg D::vd]
+    set vt_D2 [make_one_vtable_result D "non-virtual thunk to E::vg" D::vd]
+    set vt_E [make_one_vtable_result E E::f E::vg E::vv]
+
+    gdb_test "info vtbl a" "${vt_A}${vt_V}"
+    gdb_test "info vtbl b" "${vt_B}${vt_V}"
+    gdb_test "info vtbl c" "${vt_V}"
+    gdb_test "info vtbl d" "${vt_D}${vt_V}"
+    gdb_test "info vtbl e" "${vt_E}${vt_D2}${vt_V2}"
+    gdb_test "info vtbl pEe" "${vt_E}${vt_D2}${vt_V2}"
+
+    gdb_test "info vtbl" "Argument required.*"
+    gdb_test "info vtbl va" \
+       "This object does not have a virtual function table.*"
+    gdb_test "info vtbl all_count" \
+       "This object does not have a virtual function table.*"
 }
 
 proc do_tests {} {
-    global prms_id
-    global bug_id
-
-    set prms_id 0
-    set bug_id 0
-
-    gdb_start;
-    gdb_virtfunc_init;
-
-    runto_main
+    gdb_test_no_output "set language c++" ""
+    gdb_test_no_output "set width 0" ""
 
+    if ![runto_main] then {
+       perror "couldn't run to breakpoint"
+       return
+    }
     test_ptype_of_classes
+    test_info_vtbl
 
-    if [ runto 'test_calls' ] then {
-       test_virtual_calls
-    }
+    gdb_breakpoint test_calls
+    gdb_test "continue" ".*Breakpoint .* test_calls.*" ""
+    test_virtual_calls
+
+    gdb_test "next" ".*pAa->f.*" "next to pAa->f call"
+    gdb_test "next" ".*pDe->vg.*" "next to pDe->vg call"
+    gdb_test "step" ".*E::vg.*" "step through thunk into E::vg"
 }
 
 do_tests