OLD | NEW |
1 # Copyright 1998-2004, 2007-2012 Free Software Foundation, Inc. | 1 # Copyright 1998-2013 Free Software Foundation, Inc. |
2 | 2 |
3 # This program is free software; you can redistribute it and/or modify | 3 # This program is free software; you can redistribute it and/or modify |
4 # it under the terms of the GNU General Public License as published by | 4 # it under the terms of the GNU General Public License as published by |
5 # the Free Software Foundation; either version 3 of the License, or | 5 # the Free Software Foundation; either version 3 of the License, or |
6 # (at your option) any later version. | 6 # (at your option) any later version. |
7 # | 7 # |
8 # This program is distributed in the hope that it will be useful, | 8 # This program is distributed in the hope that it will be useful, |
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 # GNU General Public License for more details. | 11 # GNU General Public License for more details. |
(...skipping 13 matching lines...) Expand all Loading... |
25 set ws "\[\r\n\t \]+" | 25 set ws "\[\r\n\t \]+" |
26 set nl "\[\r\n\]+" | 26 set nl "\[\r\n\]+" |
27 | 27 |
28 # Start program. | 28 # Start program. |
29 | 29 |
30 | 30 |
31 if { [skip_cplus_tests] } { continue } | 31 if { [skip_cplus_tests] } { continue } |
32 | 32 |
33 load_lib "cp-support.exp" | 33 load_lib "cp-support.exp" |
34 | 34 |
35 standard_testfile .cc | 35 standard_testfile derivation.cc derivation2.cc |
36 | 36 |
37 if {[prepare_for_testing $testfile.exp $testfile $srcfile {debug c++}]} { | 37 if {[prepare_for_testing $testfile.exp $testfile \ |
| 38 » [list $srcfile $srcfile2] {debug c++}]} { |
38 return -1 | 39 return -1 |
39 } | 40 } |
40 | 41 |
| 42 # Check inheritance of typedefs. |
| 43 with_test_prefix "before run" { |
| 44 foreach klass {"A" "D" "E" "F" "A2" "D2"} { |
| 45 gdb_test "ptype ${klass}::value_type" "type = int" |
| 46 gdb_test "whatis ${klass}::value_type" "type = int" |
| 47 gdb_test "p (${klass}::value_type) 0" " = 0" |
| 48 } |
| 49 foreach klass {"Z" "ZZ"} { |
| 50 gdb_test "ptype ${klass}::value_type" "type = float" |
| 51 gdb_test "whatis ${klass}::value_type" "type = float" |
| 52 gdb_test "p (${klass}::value_type) 0" " = 0" |
| 53 } |
| 54 } |
| 55 |
41 # Set it up at a breakpoint so we can play with the variable values. | 56 # Set it up at a breakpoint so we can play with the variable values. |
42 | 57 |
43 if ![runto 'marker1'] then { | 58 if ![runto 'marker1'] then { |
44 perror "couldn't run to marker1" | 59 perror "couldn't run to marker1" |
45 continue | 60 continue |
46 } | 61 } |
47 | 62 |
| 63 # Check inheritance of typedefs again, but this time with an active block. |
| 64 with_test_prefix "at marker1" { |
| 65 foreach klass {"A" "D" "A2" "D2"} { |
| 66 gdb_test "ptype ${klass}::value_type" "type = int" |
| 67 gdb_test "whatis ${klass}::value_type" "type = int" |
| 68 gdb_test "p (${klass}::value_type) 0" " = 0" |
| 69 } |
| 70 } |
| 71 |
48 gdb_test "up" ".*main.*" "up from marker1" | 72 gdb_test "up" ".*main.*" "up from marker1" |
49 | 73 |
50 # Print class types and values. | 74 # Print class types and values. |
51 | 75 |
52 # class A | 76 # class A |
53 | 77 |
54 gdb_test "print a_instance" "\\$\[0-9\]+ = \{a = 1, aa = 2\}" "print value of a_
instance" | 78 gdb_test "print a_instance" "\\$\[0-9\]+ = \{a = 1, aa = 2\}" "print value of a_
instance" |
55 | 79 |
56 cp_test_ptype_class \ | 80 cp_test_ptype_class \ |
57 "ptype a_instance" "" "class" "A" \ | 81 "a_instance" "" "class" "A" \ |
58 { | 82 { |
59 » { field public "int a;" } | 83 » { field public "A::value_type a;" } |
60 » { field public "int aa;" } | 84 » { field public "A::value_type aa;" } |
61 { method public "A();" } | 85 { method public "A();" } |
62 » { method public "int afoo();" } | 86 » { method public "A::value_type afoo();" } |
63 » { method public "int foo();" } | 87 » { method public "A::value_type foo();" } |
| 88 » { typedef public "typedef int value_type;" } |
64 } | 89 } |
65 | 90 |
66 # class D | 91 # class D |
67 | 92 |
68 gdb_test_multiple "print d_instance" "print value of d_instance" { | 93 gdb_test_multiple "print d_instance" "print value of d_instance" { |
69 -re "\\$\[0-9\]+ = \{<(class A|A)> = \{a = 1, aa = 2\}, <(class B|B)> = \{b
= 3, bb = 4\}, <(class C|C)> = \{c = 5, cc = 6\}, d = 7, dd = 8\}$nl$gdb_prompt
$" { | 94 -re "\\$\[0-9\]+ = \{<(class A|A)> = \{a = 1, aa = 2\}, <(class B|B)> = \{b
= 3, bb = 4\}, <(class C|C)> = \{c = 5, cc = 6\}, d = 7, dd = 8\}$nl$gdb_prompt
$" { |
70 pass "print value of d_instance" | 95 pass "print value of d_instance" |
71 } | 96 } |
72 } | 97 } |
73 | 98 |
74 cp_test_ptype_class \ | 99 cp_test_ptype_class \ |
75 "ptype d_instance" "" "class" "D" \ | 100 "d_instance" "" "class" "D" \ |
76 { | 101 { |
77 { base "private A" } | 102 { base "private A" } |
78 { base "public B" } | 103 { base "public B" } |
79 { base "protected C" } | 104 { base "protected C" } |
80 » { field public "int d;" } | 105 » { field public "A::value_type d;" } |
81 » { field public "int dd;" } | 106 » { field public "A::value_type dd;" } |
82 { method public "D();" } | 107 { method public "D();" } |
83 » { method public "int dfoo();" } | 108 » { method public "A::value_type dfoo();" } |
84 » { method public "int foo();" } | 109 » { method public "A::value_type foo();" } |
85 } \ | 110 } \ |
86 "" \ | 111 "" \ |
87 { | 112 { |
88 { "protected C" "private C" { setup_xfail "*-*-*" "gcc/13539" } } | 113 { "protected C" "private C" { setup_xfail "*-*-*" "gcc/13539" } } |
89 } | 114 } |
90 | 115 |
91 # class E | 116 # class E |
92 | 117 |
93 gdb_test_multiple "print e_instance" "print value of e_instance" { | 118 gdb_test_multiple "print e_instance" "print value of e_instance" { |
94 -re "\\$\[0-9\]+ = \{<(class A|A)> = \{a = 1, aa = 2\}, <(class B|B)> = \{b
= 3, bb = 4\}, <(class C|C)> = \{c = 5, cc = 6\}, e = 9, ee = 10\}$nl$gdb_prompt
$" { | 119 -re "\\$\[0-9\]+ = \{<(class A|A)> = \{a = 1, aa = 2\}, <(class B|B)> = \{b
= 3, bb = 4\}, <(class C|C)> = \{c = 5, cc = 6\}, e = 9, ee = 10\}$nl$gdb_prompt
$" { |
95 pass "print value of e_instance" | 120 pass "print value of e_instance" |
96 } | 121 } |
97 } | 122 } |
98 | 123 |
99 cp_test_ptype_class \ | 124 cp_test_ptype_class \ |
100 "ptype e_instance" "" "class" "E" \ | 125 "e_instance" "" "class" "E" \ |
101 { | 126 { |
102 { base "public A" } | 127 { base "public A" } |
103 { base "private B" } | 128 { base "private B" } |
104 { base "protected C" } | 129 { base "protected C" } |
105 » { field public "int e;" } | 130 » { field public "A::value_type e;" } |
106 » { field public "int ee;" } | 131 » { field public "A::value_type ee;" } |
107 { method public "E();" } | 132 { method public "E();" } |
108 » { method public "int efoo();" } | 133 » { method public "A::value_type efoo();" } |
109 » { method public "int foo();" } | 134 » { method public "A::value_type foo();" } |
110 } \ | 135 } \ |
111 "" \ | 136 "" \ |
112 { | 137 { |
113 { "protected C" "private C" { setup_xfail "*-*-*" "gcc/13539" } } | 138 { "protected C" "private C" { setup_xfail "*-*-*" "gcc/13539" } } |
114 } | 139 } |
115 | 140 |
116 # class F | 141 # class F |
117 | 142 |
118 gdb_test_multiple "print f_instance" "print value of f_instance" { | 143 gdb_test_multiple "print f_instance" "print value of f_instance" { |
119 -re "\\$\[0-9\]+ = \{<(class A|A)> = \{a = 1, aa = 2\}, <(class B|B)> = \{b
= 3, bb = 4\}, <(class C|C)> = \{c = 5, cc = 6\}, f = 11, ff = 12\}$nl$gdb_promp
t $" { | 144 -re "\\$\[0-9\]+ = \{<(class A|A)> = \{a = 1, aa = 2\}, <(class B|B)> = \{b
= 3, bb = 4\}, <(class C|C)> = \{c = 5, cc = 6\}, f = 11, ff = 12\}$nl$gdb_promp
t $" { |
120 pass "print value of f_instance" | 145 pass "print value of f_instance" |
121 } | 146 } |
122 } | 147 } |
123 | 148 |
124 cp_test_ptype_class \ | 149 cp_test_ptype_class \ |
125 "ptype f_instance" "" "class" "F" \ | 150 "f_instance" "" "class" "F" \ |
126 { | 151 { |
127 { base "private A" } | 152 { base "private A" } |
128 { base "public B" } | 153 { base "public B" } |
129 { base "private C" } | 154 { base "private C" } |
130 » { field public "int f;" } | 155 » { field public "A::value_type f;" } |
131 » { field public "int ff;" } | 156 » { field public "A::value_type ff;" } |
132 { method public "F();" } | 157 { method public "F();" } |
133 » { method public "int ffoo();" } | 158 » { method public "A::value_type ffoo();" } |
| 159 » { method public "A::value_type foo();" } |
| 160 } |
| 161 |
| 162 # class G |
| 163 cp_test_ptype_class \ |
| 164 "g_instance" "" "class" "G" \ |
| 165 { |
| 166 » { base "private A" } |
| 167 » { base "public B" } |
| 168 » { base "protected C" } |
| 169 » { field public "int g;" } |
| 170 » { field public "int gg;" } |
| 171 » { field public "int a;" } |
| 172 » { field public "int b;" } |
| 173 » { field public "int c;" } |
| 174 » { method public "int gfoo();" } |
134 { method public "int foo();" } | 175 { method public "int foo();" } |
135 } | 176 } |
136 | 177 |
137 # Print individual fields. | 178 # Print individual fields. |
138 | 179 |
139 gdb_test "print d_instance.a" "\\$\[0-9\]+ = 1" "print value of d_instance.a" | 180 gdb_test "print d_instance.a" "\\$\[0-9\]+ = 1" "print value of d_instance.a" |
140 gdb_test "print d_instance.aa" "\\$\[0-9\]+ = 2" "print value of d_instance.aa" | 181 gdb_test "print d_instance.aa" "\\$\[0-9\]+ = 2" "print value of d_instance.aa" |
141 gdb_test "print d_instance.b" "\\$\[0-9\]+ = 3" "print value of d_instance.b" | 182 gdb_test "print d_instance.b" "\\$\[0-9\]+ = 3" "print value of d_instance.b" |
142 gdb_test "print d_instance.bb" "\\$\[0-9\]+ = 4" "print value of d_instance.bb" | 183 gdb_test "print d_instance.bb" "\\$\[0-9\]+ = 4" "print value of d_instance.bb" |
143 gdb_test "print d_instance.c" "\\$\[0-9\]+ = 5" "print value of d_instance.c" | 184 gdb_test "print d_instance.c" "\\$\[0-9\]+ = 5" "print value of d_instance.c" |
(...skipping 25 matching lines...) Expand all Loading... |
169 gdb_test "finish" ".*main.*at .*derivation.cc:.*// marker1-returns-here.
*" \ | 210 gdb_test "finish" ".*main.*at .*derivation.cc:.*// marker1-returns-here.
*" \ |
170 "finish call to marker1" | 211 "finish call to marker1" |
171 } | 212 } |
172 -re "#1 ($hex in )?main.*$gdb_prompt $" { | 213 -re "#1 ($hex in )?main.*$gdb_prompt $" { |
173 pass "re-selected 'main' frame after inferior call" | 214 pass "re-selected 'main' frame after inferior call" |
174 } | 215 } |
175 } | 216 } |
176 | 217 |
177 gdb_test "print g_instance.bfoo()" "\\$\[0-9\]+ = 2" "print value of g_instance.
bfoo()" | 218 gdb_test "print g_instance.bfoo()" "\\$\[0-9\]+ = 2" "print value of g_instance.
bfoo()" |
178 gdb_test "print g_instance.cfoo()" "\\$\[0-9\]+ = 3" "print value of g_instance.
cfoo()" | 219 gdb_test "print g_instance.cfoo()" "\\$\[0-9\]+ = 3" "print value of g_instance.
cfoo()" |
| 220 |
| 221 # Check typedefs of fields |
| 222 foreach Klass {"C" "G"} { |
| 223 set klass [string tolower $Klass] |
| 224 set instance "${klass}_instance" |
| 225 set var "${instance}.$klass" |
| 226 gdb_test "whatis $var" "int" |
| 227 gdb_test "ptype $var" "int" |
| 228 } |
| 229 |
| 230 foreach Klass {"A" "B" "D" "E" "F"} { |
| 231 set klass [string tolower $Klass] |
| 232 set instance "${klass}_instance" |
| 233 set var "${instance}.$klass" |
| 234 gdb_test "whatis $var" "A::value_type" |
| 235 gdb_test "ptype $var" "int" |
| 236 if {![string equal $Klass "B"]} { |
| 237 gdb_test "p (${Klass}::value_type) 0" " = 0" |
| 238 } |
| 239 } |
| 240 |
| 241 foreach Klass {"Z" "ZZ"} { |
| 242 set klass [string tolower $Klass] |
| 243 set instance "${klass}_instance" |
| 244 set var "${instance}.$klass" |
| 245 gdb_test "whatis $var" "Z::value_type" |
| 246 gdb_test "ptype $var" "float" |
| 247 gdb_test "p (${Klass}::value_type) 0" " = 0" |
| 248 } |
| 249 |
| 250 # This is a regression test for a bug that caused a crash when trying |
| 251 # to print the vtbl pointer. We don't care about the output so much |
| 252 # here (it is tested elsewhere), just that gdb doesn't crash. We test |
| 253 # "ptype" first because, before the gdb fix, that was the only code |
| 254 # path calling get_vptr_fieldno. |
| 255 gdb_test "ptype vderived" "type = .*" |
| 256 gdb_test "print vderived" " = {.* inter = 0.*x = 0}" |
| 257 |
| 258 # Test whether inheritance of typedefs is properly |
| 259 # reported when stopped. |
| 260 gdb_test "ptype N::value_type" "type = double" |
| 261 gdb_test "ptype N::Derived::value_type" "type = int" |
| 262 |
| 263 # Now run to N::Derived::doit and get the type of "value_type" |
| 264 if {![runto "N::Derived::doit"]} { |
| 265 perror "couldn't run to N::Derived::doit" |
| 266 continue |
| 267 } |
| 268 |
| 269 gdb_test "ptype value_type" "type = int" |
OLD | NEW |