| 1 |
330 |
jeremybenn |
# Copyright 1992, 1994, 1995, 1996, 1997, 1998, 1999, 2001, 2002, 2003, 2004,
|
| 2 |
|
|
# 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
|
| 3 |
|
|
|
| 4 |
|
|
# This program is free software; you can redistribute it and/or modify
|
| 5 |
|
|
# it under the terms of the GNU General Public License as published by
|
| 6 |
|
|
# the Free Software Foundation; either version 3 of the License, or
|
| 7 |
|
|
# (at your option) any later version.
|
| 8 |
|
|
#
|
| 9 |
|
|
# This program is distributed in the hope that it will be useful,
|
| 10 |
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 11 |
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 12 |
|
|
# GNU General Public License for more details.
|
| 13 |
|
|
#
|
| 14 |
|
|
# You should have received a copy of the GNU General Public License
|
| 15 |
|
|
# along with this program. If not, see .
|
| 16 |
|
|
|
| 17 |
|
|
# This file was written by Fred Fish. (fnf@cygnus.com)
|
| 18 |
|
|
# And rewritten by Michael Chastain .
|
| 19 |
|
|
|
| 20 |
|
|
set nl "\[\r\n\]+"
|
| 21 |
|
|
|
| 22 |
|
|
if $tracelevel then {
|
| 23 |
|
|
strace $tracelevel
|
| 24 |
|
|
}
|
| 25 |
|
|
|
| 26 |
|
|
if { [skip_cplus_tests] } { continue }
|
| 27 |
|
|
|
| 28 |
|
|
load_lib "cp-support.exp"
|
| 29 |
|
|
|
| 30 |
|
|
set testfile "virtfunc"
|
| 31 |
|
|
set srcfile ${testfile}.cc
|
| 32 |
|
|
set binfile ${objdir}/${subdir}/${testfile}
|
| 33 |
|
|
|
| 34 |
|
|
if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {c++ debug}] != "" } {
|
| 35 |
|
|
untested virtfunc.exp
|
| 36 |
|
|
return -1
|
| 37 |
|
|
}
|
| 38 |
|
|
|
| 39 |
|
|
proc test_ptype_of_classes {} {
|
| 40 |
|
|
|
| 41 |
|
|
# class VA
|
| 42 |
|
|
|
| 43 |
|
|
cp_test_ptype_class \
|
| 44 |
|
|
"ptype VA" "" "class" "VA" \
|
| 45 |
|
|
{
|
| 46 |
|
|
{ field public "int va;" }
|
| 47 |
|
|
}
|
| 48 |
|
|
|
| 49 |
|
|
# class VB
|
| 50 |
|
|
|
| 51 |
|
|
cp_test_ptype_class \
|
| 52 |
|
|
"ptype VB" "" "class" "VB" \
|
| 53 |
|
|
{
|
| 54 |
|
|
{ field public "int vb;" }
|
| 55 |
|
|
{ method public "int fvb();" }
|
| 56 |
|
|
{ method public "virtual int vvb();" }
|
| 57 |
|
|
}
|
| 58 |
|
|
|
| 59 |
|
|
# class V
|
| 60 |
|
|
|
| 61 |
|
|
cp_test_ptype_class \
|
| 62 |
|
|
"ptype V" "" "class" "V" \
|
| 63 |
|
|
{
|
| 64 |
|
|
{ base "public VA" }
|
| 65 |
|
|
{ base "public VB" }
|
| 66 |
|
|
{ field public "int w;" }
|
| 67 |
|
|
{ method public "int f();" }
|
| 68 |
|
|
{ method public "virtual int vv();" }
|
| 69 |
|
|
}
|
| 70 |
|
|
|
| 71 |
|
|
# class A
|
| 72 |
|
|
|
| 73 |
|
|
cp_test_ptype_class \
|
| 74 |
|
|
"ptype A" "" "class" "A" \
|
| 75 |
|
|
{
|
| 76 |
|
|
{ base "public virtual V" }
|
| 77 |
|
|
{ vbase "V" }
|
| 78 |
|
|
{ field private "int a;" }
|
| 79 |
|
|
{ method public "virtual int f();" }
|
| 80 |
|
|
}
|
| 81 |
|
|
|
| 82 |
|
|
# class B
|
| 83 |
|
|
|
| 84 |
|
|
cp_test_ptype_class \
|
| 85 |
|
|
"ptype B" "" "class" "B" \
|
| 86 |
|
|
{
|
| 87 |
|
|
{ base "public A" }
|
| 88 |
|
|
{ field private "int b;" }
|
| 89 |
|
|
{ method public "virtual int f();" }
|
| 90 |
|
|
}
|
| 91 |
|
|
|
| 92 |
|
|
# class C
|
| 93 |
|
|
|
| 94 |
|
|
cp_test_ptype_class \
|
| 95 |
|
|
"ptype C" "" "class" "C" \
|
| 96 |
|
|
{
|
| 97 |
|
|
{ base "public virtual V" }
|
| 98 |
|
|
{ vbase "V" }
|
| 99 |
|
|
{ field public "int c;" }
|
| 100 |
|
|
}
|
| 101 |
|
|
|
| 102 |
|
|
# class AD
|
| 103 |
|
|
|
| 104 |
|
|
cp_test_ptype_class \
|
| 105 |
|
|
"ptype AD" "" "class" "AD" \
|
| 106 |
|
|
{
|
| 107 |
|
|
{ method public "virtual int vg();" }
|
| 108 |
|
|
}
|
| 109 |
|
|
|
| 110 |
|
|
# class D
|
| 111 |
|
|
|
| 112 |
|
|
cp_test_ptype_class \
|
| 113 |
|
|
"ptype D" "" "class" "D" \
|
| 114 |
|
|
{
|
| 115 |
|
|
{ base "public AD" }
|
| 116 |
|
|
{ base "public virtual V" }
|
| 117 |
|
|
{ vbase "V" }
|
| 118 |
|
|
{ method public "static void s();" }
|
| 119 |
|
|
{ method public "virtual int vg();" }
|
| 120 |
|
|
{ method public "virtual int vd();" }
|
| 121 |
|
|
{ method public "int fd();" }
|
| 122 |
|
|
{ field public "int d;" }
|
| 123 |
|
|
}
|
| 124 |
|
|
|
| 125 |
|
|
# class E
|
| 126 |
|
|
|
| 127 |
|
|
cp_test_ptype_class \
|
| 128 |
|
|
"ptype E" "" "class" "E" \
|
| 129 |
|
|
{
|
| 130 |
|
|
{ base "public B" }
|
| 131 |
|
|
{ base "public virtual V" }
|
| 132 |
|
|
{ base "public D" }
|
| 133 |
|
|
{ base "public C" }
|
| 134 |
|
|
{ vbase "V" }
|
| 135 |
|
|
{ method public "virtual int f();" }
|
| 136 |
|
|
{ method public "virtual int vg();" }
|
| 137 |
|
|
{ method public "virtual int vv();" }
|
| 138 |
|
|
{ field public "int e;" }
|
| 139 |
|
|
}
|
| 140 |
|
|
|
| 141 |
|
|
# An instance of D
|
| 142 |
|
|
|
| 143 |
|
|
cp_test_ptype_class "ptype dd" "" "class" "D" ibid
|
| 144 |
|
|
|
| 145 |
|
|
# An instance of D *
|
| 146 |
|
|
|
| 147 |
|
|
cp_test_ptype_class "ptype ppd" "" "class" "D" ibid "*"
|
| 148 |
|
|
|
| 149 |
|
|
# An instance of AD *
|
| 150 |
|
|
# TODO: this should be named pADd, not pAd.
|
| 151 |
|
|
|
| 152 |
|
|
cp_test_ptype_class "ptype pAd" "" "class" "AD" ibid "*"
|
| 153 |
|
|
|
| 154 |
|
|
# Instances of these classes.
|
| 155 |
|
|
|
| 156 |
|
|
cp_test_ptype_class "ptype a" "" "class" "A" ibid
|
| 157 |
|
|
cp_test_ptype_class "ptype b" "" "class" "B" ibid
|
| 158 |
|
|
cp_test_ptype_class "ptype c" "" "class" "C" ibid
|
| 159 |
|
|
cp_test_ptype_class "ptype d" "" "class" "D" ibid
|
| 160 |
|
|
cp_test_ptype_class "ptype e" "" "class" "E" ibid
|
| 161 |
|
|
cp_test_ptype_class "ptype v" "" "class" "V" ibid
|
| 162 |
|
|
cp_test_ptype_class "ptype vb" "" "class" "VB" ibid
|
| 163 |
|
|
|
| 164 |
|
|
# Instances of pointers to these classes.
|
| 165 |
|
|
|
| 166 |
|
|
cp_test_ptype_class "ptype pAa" "" "class" "A" ibid "*"
|
| 167 |
|
|
cp_test_ptype_class "ptype pAe" "" "class" "A" ibid "*"
|
| 168 |
|
|
cp_test_ptype_class "ptype pBe" "" "class" "B" ibid "*"
|
| 169 |
|
|
cp_test_ptype_class "ptype pDd" "" "class" "D" ibid "*"
|
| 170 |
|
|
cp_test_ptype_class "ptype pDe" "" "class" "D" ibid "*"
|
| 171 |
|
|
cp_test_ptype_class "ptype pVa" "" "class" "V" ibid "*"
|
| 172 |
|
|
cp_test_ptype_class "ptype pVv" "" "class" "V" ibid "*"
|
| 173 |
|
|
cp_test_ptype_class "ptype pVe" "" "class" "V" ibid "*"
|
| 174 |
|
|
cp_test_ptype_class "ptype pVd" "" "class" "V" ibid "*"
|
| 175 |
|
|
cp_test_ptype_class "ptype pADe" "" "class" "AD" ibid "*"
|
| 176 |
|
|
cp_test_ptype_class "ptype pEe" "" "class" "E" ibid "*"
|
| 177 |
|
|
cp_test_ptype_class "ptype pVB" "" "class" "VB" ibid "*"
|
| 178 |
|
|
|
| 179 |
|
|
}
|
| 180 |
|
|
|
| 181 |
|
|
# Call virtual functions.
|
| 182 |
|
|
|
| 183 |
|
|
proc test_virtual_calls {} {
|
| 184 |
|
|
global gdb_prompt
|
| 185 |
|
|
global nl
|
| 186 |
|
|
|
| 187 |
|
|
if [target_info exists gdb,cannot_call_functions] {
|
| 188 |
|
|
setup_xfail "*-*-*" 2416
|
| 189 |
|
|
fail "This target can not call functions"
|
| 190 |
|
|
return 0
|
| 191 |
|
|
}
|
| 192 |
|
|
|
| 193 |
|
|
gdb_test "print pAe->f()" "\\$\[0-9\]+ = 20"
|
| 194 |
|
|
gdb_test "print pAa->f()" "\\$\[0-9\]+ = 1"
|
| 195 |
|
|
gdb_test "print pDe->vg()" "\\$\[0-9\]+ = 202"
|
| 196 |
|
|
gdb_test "print pADe->vg()" "\\$\[0-9\]+ = 202"
|
| 197 |
|
|
gdb_test "print pDd->vg()" "\\$\[0-9\]+ = 101"
|
| 198 |
|
|
gdb_test "print pEe->vvb()" "\\$\[0-9\]+ = 411"
|
| 199 |
|
|
gdb_test "print pVB->vvb()" "\\$\[0-9\]+ = 407"
|
| 200 |
|
|
gdb_test "print pBe->vvb()" "\\$\[0-9\]+ = 411"
|
| 201 |
|
|
gdb_test "print pDe->vvb()" "\\$\[0-9\]+ = 411"
|
| 202 |
|
|
gdb_test "print pEe->vd()" "\\$\[0-9\]+ = 282"
|
| 203 |
|
|
gdb_test "print pEe->fvb()" "\\$\[0-9\]+ = 311"
|
| 204 |
|
|
|
| 205 |
|
|
# more recent results:
|
| 206 |
|
|
# wrong value "202"
|
| 207 |
|
|
# gcc 2.95.3 -gdwarf-2
|
| 208 |
|
|
# gcc 2.95.3 -gstabs+
|
| 209 |
|
|
# attempt to take addres of value not located in memory
|
| 210 |
|
|
# gcc 3.3.2 -gdwarf-2
|
| 211 |
|
|
# gcc 3.3.2 -gstabs+
|
| 212 |
|
|
#
|
| 213 |
|
|
# -- chastain 2003-12-31
|
| 214 |
|
|
|
| 215 |
|
|
gdb_test_multiple "print pEe->D::vg()" "print pEe->D::vg()" {
|
| 216 |
|
|
-re "\\$\[0-9]+ = 102$nl$gdb_prompt $" {
|
| 217 |
|
|
pass "print pEe->D::vg()"
|
| 218 |
|
|
}
|
| 219 |
|
|
-re "\\$\[0-9]+ = 202$nl$gdb_prompt $" {
|
| 220 |
|
|
# To get this result, we have called pEe->*(&D::vg) ().
|
| 221 |
|
|
# That's how GDB interprets this, but it's wrong; in fact
|
| 222 |
|
|
# the explicit D:: means to bypass virtual function lookup,
|
| 223 |
|
|
# and call D::vg as if it were non-virtual. We still have
|
| 224 |
|
|
# to e.g. adjust "this", though.
|
| 225 |
|
|
kfail "gdb/1064" "print pEe->D::vg()"
|
| 226 |
|
|
}
|
| 227 |
|
|
-re "Attempt to take address of value not located in memory.$nl$gdb_prompt $" {
|
| 228 |
|
|
kfail "gdb/1064" "print pEe->D::vg()"
|
| 229 |
|
|
}
|
| 230 |
|
|
}
|
| 231 |
|
|
}
|
| 232 |
|
|
|
| 233 |
|
|
proc do_tests {} {
|
| 234 |
|
|
global srcdir subdir binfile
|
| 235 |
|
|
global gdb_prompt
|
| 236 |
|
|
|
| 237 |
|
|
|
| 238 |
|
|
gdb_exit
|
| 239 |
|
|
gdb_start
|
| 240 |
|
|
gdb_reinitialize_dir $srcdir/$subdir
|
| 241 |
|
|
gdb_load $binfile
|
| 242 |
|
|
|
| 243 |
|
|
gdb_test_no_output "set language c++" ""
|
| 244 |
|
|
gdb_test_no_output "set width 0" ""
|
| 245 |
|
|
|
| 246 |
|
|
if ![runto_main] then {
|
| 247 |
|
|
perror "couldn't run to breakpoint"
|
| 248 |
|
|
return
|
| 249 |
|
|
}
|
| 250 |
|
|
test_ptype_of_classes
|
| 251 |
|
|
|
| 252 |
|
|
gdb_breakpoint test_calls
|
| 253 |
|
|
gdb_test "continue" ".*Breakpoint .* test_calls.*" ""
|
| 254 |
|
|
test_virtual_calls
|
| 255 |
|
|
|
| 256 |
|
|
gdb_test "next" ".*pAa->f.*" "next to pAa->f call"
|
| 257 |
|
|
gdb_test "next" ".*pDe->vg.*" "next to pDe->vg call"
|
| 258 |
|
|
gdb_test "step" ".*E::vg.*" "step through thunk into E::vg"
|
| 259 |
|
|
}
|
| 260 |
|
|
|
| 261 |
|
|
do_tests
|