1# Copyright 1992, 1994, 1995, 1996, 1997, 1998, 1999, 2001, 2002, 2003, 2004 2# 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 2 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, write to the Free Software 16# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 18# This file was written by Fred Fish. (fnf@cygnus.com) 19# And rewritten by Michael Chastain <mec.gnu@mindspring.com>. 20 21set nl "\[\r\n\]+" 22 23if $tracelevel then { 24 strace $tracelevel 25} 26 27if { [skip_cplus_tests] } { continue } 28 29load_lib "cp-support.exp" 30 31set testfile "virtfunc" 32set srcfile ${testfile}.cc 33set binfile ${objdir}/${subdir}/${testfile} 34 35if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {c++ debug}] != "" } { 36 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail." 37} 38 39proc 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 183proc 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 "Attempt to take address of value not located in memory.$nl$gdb_prompt $" { 220 kfail "gdb/1064" "print pEe->D::vg()" 221 } 222 } 223} 224 225proc do_tests {} { 226 global prms_id 227 global bug_id 228 global srcdir subdir binfile 229 global gdb_prompt 230 231 set prms_id 0 232 set bug_id 0 233 234 gdb_exit 235 gdb_start 236 gdb_reinitialize_dir $srcdir/$subdir 237 gdb_load $binfile 238 239 gdb_test "set language c++" "" "" 240 gdb_test "set width 0" "" "" 241 242 runto_main 243 test_ptype_of_classes 244 245 gdb_breakpoint test_calls 246 gdb_test "continue" ".*Breakpoint .* test_calls.*" "" 247 test_virtual_calls 248} 249 250do_tests 251