-# Copyright 1992, 1994, 1995, 1996, 1997, 1998, 1999, 2001, 2002, 2003, 2004,
-# 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
+# Copyright 1992-2019 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
set nl "\[\r\n\]+"
-if $tracelevel then {
- strace $tracelevel
-}
-
if { [skip_cplus_tests] } { continue }
load_lib "cp-support.exp"
-set testfile "virtfunc"
-set srcfile ${testfile}.cc
-set binfile ${objdir}/${subdir}/${testfile}
+standard_testfile .cc
-if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {c++ debug}] != "" } {
- untested virtfunc.exp
- return -1
+if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug c++}]} {
+ return -1
}
proc test_ptype_of_classes {} {
# class VA
cp_test_ptype_class \
- "ptype VA" "" "class" "VA" \
+ "VA" "" "class" "VA" \
{
{ field public "int va;" }
}
# class VB
cp_test_ptype_class \
- "ptype VB" "" "class" "VB" \
+ "VB" "" "class" "VB" \
{
{ field public "int vb;" }
{ method public "int fvb();" }
# class V
cp_test_ptype_class \
- "ptype V" "" "class" "V" \
+ "V" "" "class" "V" \
{
{ base "public VA" }
{ base "public VB" }
# class A
cp_test_ptype_class \
- "ptype A" "" "class" "A" \
+ "A" "" "class" "A" \
{
{ base "public virtual V" }
{ vbase "V" }
# class B
cp_test_ptype_class \
- "ptype B" "" "class" "B" \
+ "B" "" "class" "B" \
{
{ base "public A" }
{ field private "int b;" }
# class C
cp_test_ptype_class \
- "ptype C" "" "class" "C" \
+ "C" "" "class" "C" \
{
{ base "public virtual V" }
{ vbase "V" }
# class AD
cp_test_ptype_class \
- "ptype AD" "" "class" "AD" \
+ "AD" "" "class" "AD" \
{
{ method public "virtual int vg();" }
}
# class D
cp_test_ptype_class \
- "ptype D" "" "class" "D" \
+ "D" "" "class" "D" \
{
{ base "public AD" }
{ base "public virtual V" }
# class E
cp_test_ptype_class \
- "ptype E" "" "class" "E" \
+ "E" "" "class" "E" \
{
{ base "public B" }
{ base "public virtual V" }
# An instance of D
- cp_test_ptype_class "ptype dd" "" "class" "D" ibid
+ cp_test_ptype_class "dd" "" "class" "D" ibid
# An instance of D *
- cp_test_ptype_class "ptype ppd" "" "class" "D" ibid "*"
+ cp_test_ptype_class "ppd" "" "class" "D" ibid "*"
# An instance of AD *
# TODO: this should be named pADd, not pAd.
- cp_test_ptype_class "ptype pAd" "" "class" "AD" ibid "*"
+ cp_test_ptype_class "pAd" "" "class" "AD" ibid "*"
# Instances of these classes.
- 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
+ cp_test_ptype_class "a" "" "class" "A" ibid
+ cp_test_ptype_class "b" "" "class" "B" ibid
+ cp_test_ptype_class "c" "" "class" "C" ibid
+ cp_test_ptype_class "d" "" "class" "D" ibid
+ cp_test_ptype_class "e" "" "class" "E" ibid
+ cp_test_ptype_class "v" "" "class" "V" ibid
+ cp_test_ptype_class "vb" "" "class" "VB" ibid
# Instances of pointers to these classes.
- 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 "*"
+ cp_test_ptype_class "pAa" "" "class" "A" ibid "*"
+ cp_test_ptype_class "pAe" "" "class" "A" ibid "*"
+ cp_test_ptype_class "pBe" "" "class" "B" ibid "*"
+ cp_test_ptype_class "pDd" "" "class" "D" ibid "*"
+ cp_test_ptype_class "pDe" "" "class" "D" ibid "*"
+ cp_test_ptype_class "pVa" "" "class" "V" ibid "*"
+ cp_test_ptype_class "pVv" "" "class" "V" ibid "*"
+ cp_test_ptype_class "pVe" "" "class" "V" ibid "*"
+ cp_test_ptype_class "pVd" "" "class" "V" ibid "*"
+ cp_test_ptype_class "pADe" "" "class" "AD" ibid "*"
+ cp_test_ptype_class "pEe" "" "class" "E" ibid "*"
+ cp_test_ptype_class "pVB" "" "class" "VB" ibid "*"
}
global nl
if [target_info exists gdb,cannot_call_functions] {
- setup_xfail "*-*-*" 2416
- fail "This target can not call functions"
+ unsupported "this target can not call functions"
return 0
}
}
}
-proc do_tests {} {
- global prms_id
- global bug_id
- global srcdir subdir binfile
- global gdb_prompt
+# 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.
+
+proc make_one_vtable_result {name args} {
+ global hex
+
+ set nls "\[\r\n\]+"
- set prms_id 0
- set bug_id 0
+ set result "vtable for '${name}' @ $hex .subobject @ $hex.:$nls"
+ set count 0
+ foreach func $args {
+ append result ".${count}.:( @$hex:)? $hex <(\.)?$func..>${nls}"
+ incr count
+ }
+
+ return $result
+}
- gdb_exit
- gdb_start
- gdb_reinitialize_dir $srcdir/$subdir
- gdb_load $binfile
+# 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.*"
+}
- gdb_test "set language c++" "" ""
- gdb_test "set width 0" "" ""
+proc do_tests {} {
+ gdb_test_no_output "set language c++" ""
+ gdb_test_no_output "set width 0" ""
- runto_main
+ if ![runto_main] then {
+ perror "couldn't run to breakpoint"
+ return
+ }
test_ptype_of_classes
+ test_info_vtbl
gdb_breakpoint test_calls
gdb_test "continue" ".*Breakpoint .* test_calls.*" ""