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