]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.cp/local.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.cp / local.exp
1 # Copyright 1998-2023 Free Software Foundation, Inc.
2
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
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16 # tests for local variables
17 # Written by Satish Pai <pai@apollo.hp.com> 1997-07-08
18 # Cleaned by Michael Chastain <mec@shout.net> 2002-04-08
19
20
21 # This file is part of the gdb testsuite
22
23 set ws "\[\r\n\t \]+"
24 set nl "\[\r\n\]+"
25
26 #
27 # test running programs
28 #
29
30 if { [skip_cplus_tests] } { return }
31
32 standard_testfile .cc
33
34 if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug c++}]} {
35 return -1
36 }
37
38 #
39 # set it up at a breakpoint so we can play with the variable values
40 #
41 if {![runto_main]} {
42 return
43 }
44
45 if {![runto 'marker1']} {
46 return
47 }
48
49 gdb_test "up" ".*foobar.*" "up from marker1"
50
51 set sep "(\[.\]|___)\[0-9\]"
52
53 # ptype on a local variable.
54 #
55 # This test has six arms. The first three arms accept normal output:
56 # no synthetic methods; synthetic methods before user methods;
57 # synthetic methods after user methods.
58 #
59 # The next two arms accept "foobar__Fi.0::Local" instead of "Local".
60 # This is a bug. It happens in various places with various versions of
61 # gcc and gdb and various debugging types.
62 #
63 # The last arm accepts the user methods in duplicate. This bug happens
64 # with gcc 3.3.2 -gdwarf-2, and has been fixed in gcc HEAD 2004-01-22.
65 #
66 # -- chastain 2004-01-24
67
68 set re_class "((struct|class) Local \{${ws}public:|struct Local \{)"
69 set re_fields "int loc1;"
70 set re_methods "char loc_foo\\(char\\);"
71 set re_synth_gcc_23 "Local & operator=\\(Local const ?&\\);${ws}Local\\(Local const ?&\\);${ws}Local\\((void|)\\);"
72
73 set XX_class "((struct|class) foobar__Fi.0::Local \{${ws}public:|struct foobar__Fi.0:Local \{)"
74 set XX_synth_gcc_2 "Local & operator=\\(foobar__Fi.0::Local const ?&\\);${ws}Local\\(foobar__Fi.0::Local const ?&\\);${ws}Local\\((void|)\\);"
75 set YY_methods "$re_methods${ws}$re_methods"
76
77 set name "ptype l"
78 gdb_test_multiple "ptype l" $name {
79 -re "type = $re_class${ws}$re_fields${ws}$re_methods$nl\}$nl$gdb_prompt $" {
80 # gdb 6.0, gcc 2.95.3, dwarf-2
81 # gdb 6.0, gcc HEAD 2004-01-22, dwarf-2
82 # gdb HEAD 2004-01-23, gcc HEAD 2004-01,22, dwarf-2
83 pass "$name"
84 }
85 -re "type = $re_class${ws}$re_fields${ws}$re_synth_gcc_23${ws}$re_methods$nl\}$nl$gdb_prompt $" {
86 # gdb 6.0, gcc 3.3.2, stabs+
87 # gdb HEAD 2004-01-23, gcc 3.3.2, stabs+
88 pass "$name"
89 }
90 -re "type = $re_class${ws}$re_fields${ws}$re_methods${ws}$re_synth_gcc_23${ws}$nl\}$nl$gdb_prompt $" {
91 # gdb 6.0, gcc HEAD 2004-01-22, stabs+
92 # gdb HEAD 2004-01-23, gcc HEAD 2004-01-22, stabs+
93 pass "$name"
94 }
95 -re "type = $XX_class${ws}$re_fields${ws}$re_methods$nl\}$nl$gdb_prompt $" {
96 # gdb HEAD 2004-01-23, gcc 2.95.3, dwarf-2
97 kfail "gdb/1516" "$name"
98 }
99 -re "type = ($re_class|$XX_class)${ws}$re_fields${ws}($re_synth_gcc_23|$XX_synth_gcc_2)${ws}$re_methods$nl\}$nl$gdb_prompt $" {
100 # gdb 6.0, gcc 2.95.3, stabs+
101 # gdb HEAD 2004-01-23, gcc 2.95.3, stabs+
102 kfail "gdb/1516" "$name"
103 }
104 -re "type = ($re_class|$XX_class)${ws}$re_fields${ws}$YY_methods$nl\}$nl$gdb_prompt $" {
105 # gdb 6.0, gcc 3.3.2, dwarf-2
106 # gdb HEAD 2004-01-23, gcc 3.2.2, dwarf-2
107 kfail "gdb/483" "$name"
108 }
109 }
110
111 # This is the same test with "ptype Local" (the type name)
112 # instead of "ptype l" (the variable name).
113
114 set name "ptype Local"
115 gdb_test_multiple "ptype Local" $name {
116 -re "type = $re_class${ws}$re_fields${ws}$re_methods$nl\}$nl$gdb_prompt $" {
117 # gdb 6.0, gcc 2.95.3, dwarf-2
118 # gdb 6.0, gcc HEAD 2004-01-22, dwarf-2
119 # gdb HEAD 2004-01-23, gcc HEAD 2004-01-22, dwarf-2
120 pass "$name"
121 }
122 -re "type = $re_class${ws}$re_fields${ws}$re_synth_gcc_23${ws}$re_methods$nl\}$nl$gdb_prompt $" {
123 # gdb 6.0, gcc 3.3.2, stabs+
124 # gdb HEAD 2004-01-23, gcc 3.3.2, stabs+
125 pass "$name"
126 }
127 -re "type = $re_class${ws}$re_fields${ws}$re_methods${ws}$re_synth_gcc_23${ws}$nl\}$nl$gdb_prompt $" {
128 # gdb 6.0, gcc HEAD 2004-01-22, stabs+
129 # gdb HEAD 2004-01-23, gcc HEAD 2004-01-22, stabs+
130 pass "$name"
131 }
132 -re "type = $XX_class${ws}$re_fields${ws}$re_methods$nl\}$nl$gdb_prompt $" {
133 kfail "gdb/1516" "$name"
134 }
135 -re "type = ($re_class|$XX_class)${ws}$re_fields${ws}($re_synth_gcc_23|$XX_synth_gcc_2)${ws}$re_methods$nl\}$nl$gdb_prompt $" {
136 # gdb 6.0, gcc 2.95.3, stabs+
137 # gdb HEAD 2004-01-23, gcc 2.95.3, stabs+
138 kfail "gdb/1516" "$name"
139 }
140 -re "type = ($re_class|$XX_class)${ws}$re_fields${ws}$YY_methods$nl\}$nl$gdb_prompt $" {
141 # gdb 6.0, gcc 3.3.2, dwarf-2
142 # gdb HEAD 2004-01-23, gcc 3.2.2, dwarf-2
143 kfail "gdb/483" "$name"
144 }
145 -re "No symbol \"Local\" in current context.$nl$gdb_prompt $" {
146 # gdb HEAD 2004-01-23, gcc 2.95.3, dwarf-2
147 fail "$name"
148 }
149 }
150
151 gdb_test "break marker2"
152 gdb_test "continue" "Continuing\\..*Breakpoint \[0-9\]+, marker2.*" \
153 "continuing to marker2"
154
155 gdb_test "up" ".*main.*" "up from marker2"
156
157 # Make sure that `Local' isn't in scope here; it's local to foobar.
158 # setup_kfail "gdb/825"
159
160 set eol "\[\t \]*\[\r\n\]+\[\t \]*"
161 gdb_test_multiple "ptype Local" "local out of scope" {
162 -re "No symbol \"Local\" in current context.*${gdb_prompt} $" {
163 pass "local out of scope"
164 }
165 -re "ptype Local${eol}type = class Local {${eol} public:${eol} int loc1;${eol}.*${eol} char loc_foo\\(char\\);${eol}}${eol}${gdb_prompt} " {
166 # GCC emits STABS debugging information in a way that doesn't
167 # properly preserve the scoping of local classes. I think
168 # we'd need to start using Sun's extensions to stabs to get
169 # this right.
170 kfail gdb/825 "Local out of scope"
171 }
172 -re "ptype Local${eol}type = class Local {${eol} public:${eol} int loc1;${eol} char loc_foo\\(char\\);${eol}.*${eol}}${eol}${gdb_prompt} " {
173 # gcc 3.X abi-2 -gstabs+
174 kfail gdb/825 "Local out of scope"
175 }
176 }
177
178
179 # DTS CLLbs14316 and CLLbs17058
180 # coulter - I added a clause for HP's aCC compiler. We print out the type
181 # as xx instead of const unsigned char, but we still have an expected failure
182 # because of two reasons:
183 # There is a number at the end of InnerLocal4 which should not be there,
184 # DTS CLLbs14316
185 # The line number for the class
186 # setup_xfail "hppa*-*-*" CLLbs14316
187
188 # ---
189 # Pattern 1:
190 # PASS
191 # dwarf-2
192 # 2.95.3, 2.96-rh, 3.0.4, 3.1, gcc-3_1-branch, HEAD
193 #
194 # Pattern 2:
195 # PASS
196 # stabs+
197 # 2.95.3, 2.96-rh, 3.0.4, 3.1, gcc-3_1-branch, HEAD
198 #
199 # Pattern 3:
200 # Old hppa pattern.
201 #
202 # Pattern 4:
203 # Old hppa pattern.
204 #
205 # chastain 2002-05-27
206
207 # Pattern 5:
208 # PASS
209 # stabs+
210 # HEAD
211 #
212 # chastain 2004-01-02
213
214 gdb_test_multiple "ptype InnerLocal" "ptype InnerLocal" {
215 -re "type = class InnerLocal \{\[\r\n\t \]*public:\[\r\n\t \]*char ilc;\[\r\n\t \]*int \\* *ip;\[\r\n\t \]*(InnerLocal::|)NestedInnerLocal nest1;\[\r\n\t \]*int il_foo\\((unsigned char const|const unsigned char) *&\\);\[\r\n\t \]*\}.*$gdb_prompt $" {
216 pass "ptype InnerLocal (pattern 1)"
217 }
218 -re "type = class InnerLocal \{\[\r\n\t \]*public:\[\r\n\t \]*char ilc;\[\r\n\t \]*int \\* *ip;\[\r\n\t \]*(InnerLocal::|)NestedInnerLocal nest1;\[\r\n\t \]*InnerLocal *& operator *=\\((main${sep}::|)InnerLocal const *&\\);\[\r\n\t \]*InnerLocal\\((main${sep}::|)InnerLocal const *&\\);\[\r\n\t \]*InnerLocal\\((void|)\\);\[\r\n\t \]*int il_foo\\(unsigned char const *&\\);\[\r\n\t \]*\}.*$gdb_prompt $" {
219 pass "ptype InnerLocal (pattern 2)"
220 }
221 -re "type = class InnerLocal \{\[\r\n\t \]*public:\[\r\n\t \]*char ilc;\[\r\n\t \]*int \\* *ip;\[\r\n\t \]*(InnerLocal::|)NestedInnerLocal nest1;\[\r\n\t \]* int il_foo\\(unsigned char const *&\\);\[\r\n\t \]*InnerLocal *& operator *=\\((main${sep}::|)InnerLocal const *&\\);\[\r\n\t \]*InnerLocal\\((main${sep}::|)InnerLocal const *&\\);\[\r\n\t \]*InnerLocal\\((void|)\\);\[\r\n\t \]*\}.*$gdb_prompt $" {
222 pass "ptype InnerLocal (pattern 5)"
223 }
224 }
225
226 #---
227 # Pattern 1:
228 # PASS
229 # dwarf-2
230 # gcc 2.95.3, 2.96-rh, 3.0.4, gcc-3_1-branch, HEAD
231 #
232 # Pattern 2:
233 # PASS
234 # stabs+
235 # gcc 2.95.3, 2.96-rh, 3.0.4, gcc-3_1-branch, HEAD
236 #
237 # chastain 2002-04-08
238
239 # NOTE (2004-02-24, carlton): This test really is invalid -
240 # 'NestedInnerLocal' shouldn't be visible, so only the third
241 # expression should count as a pass. I'm leaving in the earlier
242 # passes, however, given the current problematic state of our local
243 # class support, but once we fix PR gdb/482, we should delete this
244 # test.
245
246 gdb_test_multiple "ptype NestedInnerLocal" "ptype NestedInnerLocal" {
247 -re "type = class NestedInnerLocal \{\[\r\n\t \]*public:\[\r\n\t \]*int nil;\[\r\n\t \]*int nil_foo\\(int\\);\[\r\n\t \]*\}.*$gdb_prompt $" {
248 pass "ptype NestedInnerLocal"
249 }
250 -re "type = class NestedInnerLocal \{\[\r\n\t \]*public:\[\r\n\t \]*int nil;\[\r\n\t \]*NestedInnerLocal *& *operator *= *\\((main${sep}::|)InnerLocal::NestedInnerLocal const *&\\);\[\r\n\t \]*NestedInnerLocal\\((main${sep}::|)InnerLocal::NestedInnerLocal const *&\\);\[\r\n\t \]*NestedInnerLocal\\((void|)\\);\[\r\n\t \]*int nil_foo\\(int\\);\[\r\n\t \]*\}.*$gdb_prompt $" {
251 pass "ptype NestedInnerLocal"
252 }
253 -re "No symbol \"NestedInnerLocal\" in current context\.\r\n$gdb_prompt $" {
254 pass "ptype NestedInnerLocal"
255 }
256 }
257
258 set re_class "((struct|class) InnerLocal::NestedInnerLocal \{${ws}public:|struct InnerLocal::NestedInnerLocal \{)"
259 set re_fields "int nil;"
260 set re_methods "int nil_foo\\(int\\);"
261 set re_synth_gcc_23 "InnerLocal::NestedInnerLocal & operator=\\(InnerLocal::NestedInnerLocal const ?&\\);${ws}NestedInnerLocal\\(InnerLocal::NestedInnerLocal const ?&\\);${ws}NestedInnerLocal\\(\\);"
262
263 set name "ptype InnerLocal::NestedInnerLocal"
264 gdb_test_multiple "ptype InnerLocal::NestedInnerLocal" $name {
265 -re "type = $re_class${ws}$re_fields${ws}$re_methods$nl\}$nl$gdb_prompt $" {
266 # gcc -gdwarf-2 should produce this but does not yet
267 pass $name
268 }
269 -re "type = $re_class${ws}$re_fields${ws}$re_synth_gcc_23${ws}$re_methods${ws}$nl\}$nl$gdb_prompt $" {
270 # gcc 2.95.3 -gstabs+
271 # gcc v3 -gstabs+, abi 1
272 pass $name
273 }
274 -re "type = $re_class${ws}$re_fields${ws}$re_methods${ws}$re_synth_gcc_23${ws}$nl\}$nl$gdb_prompt $" {
275 # gcc v3 -gstabs+, abi 2
276 pass $name
277 }
278 -re "There is no field named NestedInnerLocal.*$gdb_prompt $" {
279 # gcc v3 -gdwarf-2
280 kfail "gdb/482" $name
281 }
282 }