OSDN Git Service

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