Commit | Line | Data |
---|---|---|
6aba47ca | 1 | # Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2007 |
06846494 | 2 | # Free Software Foundation, Inc. |
c906108c SS |
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 | ||
c906108c SS |
18 | # tests for local variables |
19 | # Written by Satish Pai <pai@apollo.hp.com> 1997-07-08 | |
34af4875 | 20 | # Cleaned by Michael Chastain <mec@shout.net> 2002-04-08 |
c906108c SS |
21 | |
22 | ||
23 | # This file is part of the gdb testsuite | |
24 | ||
997b0952 MC |
25 | set ws "\[\r\n\t \]+" |
26 | set nl "\[\r\n\]+" | |
27 | ||
c906108c SS |
28 | if $tracelevel then { |
29 | strace $tracelevel | |
30 | } | |
31 | ||
32 | # | |
33 | # test running programs | |
34 | # | |
35 | set prms_id 0 | |
36 | set bug_id 0 | |
37 | ||
d4f3574e SS |
38 | if { [skip_cplus_tests] } { continue } |
39 | ||
c906108c SS |
40 | set testfile "local" |
41 | set srcfile ${testfile}.cc | |
42 | set binfile ${objdir}/${subdir}/${testfile} | |
43 | ||
44 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } { | |
b60f0898 JB |
45 | untested local.exp |
46 | return -1 | |
c906108c SS |
47 | } |
48 | ||
a0b3c4fd JM |
49 | if [get_compiler_info $binfile "c++"] { |
50 | return -1 | |
51 | } | |
c906108c SS |
52 | |
53 | gdb_exit | |
54 | gdb_start | |
55 | gdb_reinitialize_dir $srcdir/$subdir | |
56 | gdb_load ${binfile} | |
57 | ||
58 | ||
59 | # | |
60 | # set it up at a breakpoint so we can play with the variable values | |
61 | # | |
62 | if ![runto_main] then { | |
63 | perror "couldn't run to breakpoint" | |
64 | continue | |
65 | } | |
66 | ||
db144853 MC |
67 | if ![runto 'marker1'] then { |
68 | perror "couldn't run to marker1" | |
69 | continue | |
70 | } | |
71 | ||
6b549786 | 72 | gdb_test "up" ".*foobar.*" "up from marker1" |
db144853 | 73 | |
0a55bc22 MC |
74 | set sep "(\[.\]|___)\[0-9\]" |
75 | ||
76 | # ptype on a local variable. | |
34af4875 | 77 | # |
0a55bc22 MC |
78 | # This test has six arms. The first three arms accept normal output: |
79 | # no synthetic methods; synthetic methods before user methods; | |
80 | # synthetic methods after user methods. | |
34af4875 | 81 | # |
0a55bc22 MC |
82 | # The next two arms accept "foobar__Fi.0::Local" instead of "Local". |
83 | # This is a bug. It happens in various places with various versions of | |
84 | # gcc and gdb and various debugging types. | |
34af4875 | 85 | # |
0a55bc22 MC |
86 | # The last arm accepts the user methods in duplicate. This bug happens |
87 | # with gcc 3.3.2 -gdwarf-2, and has been fixed in gcc HEAD 2004-01-22. | |
34af4875 | 88 | # |
0a55bc22 MC |
89 | # -- chastain 2004-01-24 |
90 | ||
91 | set re_class "((struct|class) Local \{${ws}public:|struct Local \{)" | |
92 | set re_fields "int loc1;" | |
93 | set re_methods "char loc_foo\\(char\\);" | |
94 | set re_synth_gcc_23 "Local & operator=\\(Local const ?&\\);${ws}Local\\(Local const ?&\\);${ws}Local\\((void|)\\);" | |
95 | ||
96 | set XX_class "((struct|class) foobar__Fi.0::Local \{${ws}public:|struct foobar__Fi.0:Local \{)" | |
97 | set XX_synth_gcc_2 "Local & operator=\\(foobar__Fi.0::Local const ?&\\);${ws}Local\\(foobar__Fi.0::Local const ?&\\);${ws}Local\\((void|)\\);" | |
98 | set YY_methods "$re_methods${ws}$re_methods" | |
99 | ||
100 | set name "ptype l" | |
101 | gdb_test_multiple "ptype l" $name { | |
102 | -re "type = $re_class${ws}$re_fields${ws}$re_methods$nl\}$nl$gdb_prompt $" { | |
103 | # gdb 6.0, gcc 2.95.3, dwarf-2 | |
104 | # gdb 6.0, gcc HEAD 2004-01-22, dwarf-2 | |
105 | # gdb HEAD 2004-01-23, gcc HEAD 2004-01,22, dwarf-2 | |
106 | pass "$name" | |
107 | } | |
108 | -re "type = $re_class${ws}$re_fields${ws}$re_synth_gcc_23${ws}$re_methods$nl\}$nl$gdb_prompt $" { | |
109 | # gdb 6.0, gcc 3.3.2, stabs+ | |
110 | # gdb HEAD 2004-01-23, gcc 3.3.2, stabs+ | |
111 | pass "$name" | |
112 | } | |
113 | -re "type = $re_class${ws}$re_fields${ws}$re_methods${ws}$re_synth_gcc_23${ws}$nl\}$nl$gdb_prompt $" { | |
114 | # gdb 6.0, gcc HEAD 2004-01-22, stabs+ | |
115 | # gdb HEAD 2004-01-23, gcc HEAD 2004-01-22, stabs+ | |
116 | pass "$name" | |
117 | } | |
118 | -re "type = $XX_class${ws}$re_fields${ws}$re_methods$nl\}$nl$gdb_prompt $" { | |
119 | # gdb HEAD 2004-01-23, gcc 2.95.3, dwarf-2 | |
120 | kfail "gdb/1516" "$name" | |
121 | } | |
122 | -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 $" { | |
123 | # gdb 6.0, gcc 2.95.3, stabs+ | |
124 | # gdb HEAD 2004-01-23, gcc 2.95.3, stabs+ | |
125 | kfail "gdb/1516" "$name" | |
126 | } | |
127 | -re "type = ($re_class|$XX_class)${ws}$re_fields${ws}$YY_methods$nl\}$nl$gdb_prompt $" { | |
128 | # gdb 6.0, gcc 3.3.2, dwarf-2 | |
129 | # gdb HEAD 2004-01-23, gcc 3.2.2, dwarf-2 | |
130 | kfail "gdb/483" "$name" | |
131 | } | |
132 | } | |
34af4875 | 133 | |
0a55bc22 MC |
134 | # This is the same test with "ptype Local" (the type name) |
135 | # instead of "ptype l" (the variable name). | |
06846494 | 136 | |
0a55bc22 MC |
137 | set name "ptype Local" |
138 | gdb_test_multiple "ptype Local" $name { | |
139 | -re "type = $re_class${ws}$re_fields${ws}$re_methods$nl\}$nl$gdb_prompt $" { | |
140 | # gdb 6.0, gcc 2.95.3, dwarf-2 | |
141 | # gdb 6.0, gcc HEAD 2004-01-22, dwarf-2 | |
142 | # gdb HEAD 2004-01-23, gcc HEAD 2004-01-22, dwarf-2 | |
143 | pass "$name" | |
144 | } | |
145 | -re "type = $re_class${ws}$re_fields${ws}$re_synth_gcc_23${ws}$re_methods$nl\}$nl$gdb_prompt $" { | |
146 | # gdb 6.0, gcc 3.3.2, stabs+ | |
147 | # gdb HEAD 2004-01-23, gcc 3.3.2, stabs+ | |
148 | pass "$name" | |
149 | } | |
150 | -re "type = $re_class${ws}$re_fields${ws}$re_methods${ws}$re_synth_gcc_23${ws}$nl\}$nl$gdb_prompt $" { | |
151 | # gdb 6.0, gcc HEAD 2004-01-22, stabs+ | |
152 | # gdb HEAD 2004-01-23, gcc HEAD 2004-01-22, stabs+ | |
153 | pass "$name" | |
154 | } | |
155 | -re "type = $XX_class${ws}$re_fields${ws}$re_methods$nl\}$nl$gdb_prompt $" { | |
156 | kfail "gdb/1516" "$name" | |
157 | } | |
158 | -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 $" { | |
159 | # gdb 6.0, gcc 2.95.3, stabs+ | |
160 | # gdb HEAD 2004-01-23, gcc 2.95.3, stabs+ | |
161 | kfail "gdb/1516" "$name" | |
162 | } | |
163 | -re "type = ($re_class|$XX_class)${ws}$re_fields${ws}$YY_methods$nl\}$nl$gdb_prompt $" { | |
164 | # gdb 6.0, gcc 3.3.2, dwarf-2 | |
165 | # gdb HEAD 2004-01-23, gcc 3.2.2, dwarf-2 | |
166 | kfail "gdb/483" "$name" | |
167 | } | |
168 | -re "No symbol \"Local\" in current context.$nl$gdb_prompt $" { | |
169 | # gdb HEAD 2004-01-23, gcc 2.95.3, dwarf-2 | |
170 | fail "$name" | |
171 | } | |
c906108c SS |
172 | } |
173 | ||
6b549786 JB |
174 | gdb_test "break marker2" |
175 | gdb_test "continue" "Continuing\\..*Breakpoint \[0-9\]+, marker2.*" \ | |
176 | "continuing to marker2" | |
177 | ||
178 | gdb_test "up" ".*main.*" "up from marker2" | |
179 | ||
180 | # Make sure that `Local' isn't in scope here; it's local to foobar. | |
181 | # setup_kfail "gdb/825" | |
182 | send_gdb "ptype Local\n" | |
183 | set eol "\[\t \]*\[\r\n\]+\[\t \]*" | |
184 | gdb_expect { | |
185 | -re "No symbol \"Local\" in current context.*${gdb_prompt} $" { | |
186 | pass "Local out of scope" | |
187 | } | |
8b8d7525 | 188 | -re "ptype Local${eol}type = class Local {${eol} public:${eol} int loc1;${eol}.*${eol} char loc_foo\\(char\\);${eol}}${eol}${gdb_prompt} " { |
6b549786 JB |
189 | # GCC emits STABS debugging information in a way that doesn't |
190 | # properly preserve the scoping of local classes. I think | |
191 | # we'd need to start using Sun's extensions to stabs to get | |
192 | # this right. | |
193 | kfail gdb/825 "Local out of scope" | |
194 | } | |
06846494 MC |
195 | -re "ptype Local${eol}type = class Local {${eol} public:${eol} int loc1;${eol} char loc_foo\\(char\\);${eol}.*${eol}}${eol}${gdb_prompt} " { |
196 | # gcc 3.X abi-2 -gstabs+ | |
197 | kfail gdb/825 "Local out of scope" | |
198 | } | |
6b549786 JB |
199 | -re ".*${gdb_prompt} $" { |
200 | fail "Local out of scope" | |
201 | } | |
202 | timeout { | |
203 | fail "Local out of scope (timeout)" | |
204 | } | |
205 | } | |
206 | ||
207 | ||
a0b3c4fd JM |
208 | # DTS CLLbs14316 and CLLbs17058 |
209 | # coulter - I added a clause for HP's aCC compiler. We print out the type | |
210 | # as xx instead of const unsigned char, but we still have an expected failure | |
211 | # because of two reasons: | |
212 | # There is a number at the end of InnerLocal4 which should not be there, | |
213 | # DTS CLLbs14316 | |
214 | # The line number for the class | |
34af4875 MC |
215 | # setup_xfail "hppa*-*-*" CLLbs14316 |
216 | ||
217 | # --- | |
218 | # Pattern 1: | |
219 | # PASS | |
220 | # dwarf-2 | |
def1b996 | 221 | # 2.95.3, 2.96-rh, 3.0.4, 3.1, gcc-3_1-branch, HEAD |
34af4875 MC |
222 | # |
223 | # Pattern 2: | |
224 | # PASS | |
225 | # stabs+ | |
def1b996 | 226 | # 2.95.3, 2.96-rh, 3.0.4, 3.1, gcc-3_1-branch, HEAD |
34af4875 MC |
227 | # |
228 | # Pattern 3: | |
229 | # Old hppa pattern. | |
230 | # | |
231 | # Pattern 4: | |
232 | # Old hppa pattern. | |
233 | # | |
def1b996 | 234 | # chastain 2002-05-27 |
34af4875 | 235 | |
06846494 MC |
236 | # Pattern 5: |
237 | # PASS | |
238 | # stabs+ | |
239 | # HEAD | |
240 | # | |
241 | # chastain 2004-01-02 | |
242 | ||
c906108c SS |
243 | send_gdb "ptype InnerLocal\n" |
244 | gdb_expect { | |
def1b996 MC |
245 | -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 $" { pass "ptype InnerLocal (pattern 1)" } |
246 | -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 $" { pass "ptype InnerLocal (pattern 2)" } | |
34af4875 MC |
247 | -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\r\n\[\t \]*.int il_foo\\(unsigned char const &\\);\r\n\[\t \]*\}\[\t \]*\\(Local at.*local\\.cc:36\\).*$gdb_prompt $" { pass "ptype InnerLocal (old HP aCC)" } |
248 | -re "type = class InnerLocal \{\r\n\[\t \]*public:\r\n\[\t \]*char ilc;\r\n\[\t \]*int \\*ip;\r\n\[\t \]*class InnerLocal4::NestedInnerLocal nest1;\r\n\r\n\[\t \]*int il_foo\\(unsigned char const &\\);\r\n\[\t \]*\\(Local at.*local\.cc:\[0-9\]+\\)\r\n\}.*$gdb_prompt $" { pass "ptype InnerLocal (old HP aCC)" } | |
06846494 | 249 | -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 $" { pass "ptype InnerLocal (pattern 5)" } |
34af4875 MC |
250 | -re ".*$gdb_prompt $" { fail "ptype InnerLocal" } |
251 | timeout { fail "(timeout) ptype InnerLocal" } | |
c906108c SS |
252 | } |
253 | ||
34af4875 MC |
254 | #--- |
255 | # Pattern 1: | |
256 | # PASS | |
257 | # dwarf-2 | |
258 | # gcc 2.95.3, 2.96-rh, 3.0.4, gcc-3_1-branch, HEAD | |
259 | # | |
260 | # Pattern 2: | |
261 | # PASS | |
262 | # stabs+ | |
263 | # gcc 2.95.3, 2.96-rh, 3.0.4, gcc-3_1-branch, HEAD | |
264 | # | |
265 | # chastain 2002-04-08 | |
266 | ||
0e02aa50 DC |
267 | # NOTE (2004-02-24, carlton): This test really is invalid - |
268 | # 'NestedInnerLocal' shouldn't be visible, so only the third | |
269 | # expression should count as a pass. I'm leaving in the earlier | |
270 | # passes, however, given the current problematic state of our local | |
271 | # class support, but once we fix PR gdb/482, we should delete this | |
272 | # test. | |
273 | ||
c906108c SS |
274 | send_gdb "ptype NestedInnerLocal\n" |
275 | gdb_expect { | |
34af4875 MC |
276 | -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 $" { pass "ptype NestedInnerLocal" } |
277 | -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 $" { pass "ptype NestedInnerLocal" } | |
0e02aa50 DC |
278 | -re "No symbol \"NestedInnerLocal\" in current context\.\r\n$gdb_prompt $" { |
279 | pass "ptype NestedInnerLocal" | |
280 | } | |
34af4875 MC |
281 | -re ".*$gdb_prompt $" { fail "ptype NestedInnerLocal" } |
282 | timeout { fail "(timeout) ptype NestedInnerLocal" } | |
e5f9ba7b MS |
283 | } |
284 | ||
997b0952 MC |
285 | set re_class "((struct|class) InnerLocal::NestedInnerLocal \{${ws}public:|struct InnerLocal::NestedInnerLocal \{)" |
286 | set re_fields "int nil;" | |
287 | set re_methods "int nil_foo\\(int\\);" | |
288 | set re_synth_gcc_23 "InnerLocal::NestedInnerLocal & operator=\\(InnerLocal::NestedInnerLocal const ?&\\);${ws}NestedInnerLocal\\(InnerLocal::NestedInnerLocal const ?&\\);${ws}NestedInnerLocal\\(\\);" | |
34af4875 | 289 | |
997b0952 MC |
290 | set name "ptype InnerLocal::NestedInnerLocal" |
291 | gdb_test_multiple "ptype InnerLocal::NestedInnerLocal" $name { | |
292 | -re "type = $re_class${ws}$re_fields${ws}$re_methods$nl\}$nl$gdb_prompt $" { | |
293 | # gcc -gdwarf-2 should produce this but does not yet | |
294 | pass $name | |
295 | } | |
296 | -re "type = $re_class${ws}$re_fields${ws}$re_synth_gcc_23${ws}$re_methods${ws}$nl\}$nl$gdb_prompt $" { | |
297 | # gcc 2.95.3 -gstabs+ | |
298 | # gcc v3 -gstabs+, abi 1 | |
299 | pass $name | |
300 | } | |
301 | -re "type = $re_class${ws}$re_fields${ws}$re_methods${ws}$re_synth_gcc_23${ws}$nl\}$nl$gdb_prompt $" { | |
302 | # gcc v3 -gstabs+, abi 2 | |
303 | pass $name | |
304 | } | |
305 | -re "There is no field named NestedInnerLocal.*$gdb_prompt $" { | |
306 | # gcc v3 -gdwarf-2 | |
307 | kfail "gdb/482" $name | |
308 | } | |
c906108c | 309 | } |