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