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