2004-01-18 Andrew Cagney <cagney@redhat.com>
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.cp / local.exp
CommitLineData
06846494
MC
1# Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004
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
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
34af4875 23# Cleaned by Michael Chastain <mec@shout.net> 2002-04-08
c906108c
SS
24
25
26# This file is part of the gdb testsuite
27
28if $tracelevel then {
29 strace $tracelevel
30 }
31
32#
33# test running programs
34#
35set prms_id 0
36set bug_id 0
37
d4f3574e
SS
38if { [skip_cplus_tests] } { continue }
39
c906108c
SS
40set testfile "local"
41set srcfile ${testfile}.cc
42set binfile ${objdir}/${subdir}/${testfile}
43
44if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
45 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
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
c2d11a7d
JM
73# Local classes in g++ get names like "main.1::InnerLocal", just like local
74# static variables. Some targets use "___" instead of ".".
34af4875
MC
75
76# ---
77# Pattern 1:
78# PASS
79# dwarf-2
80# gcc 2.95.3
81#
82# Pattern 2:
83# FAIL
84# This has a duplicate "char loc_foo" line. This is a bug.
85# Historically this has been an XFAIL.
86# dwarf-2
87# gcc 2.96-rh, 3.0.4, gcc-3_1-branch, HEAD
88#
89# Pattern 3:
90# PASS
91# stabs+
92# gcc 2.95.3, 2.96-rh, 3.0.4, gcc-3_1-branch, HEAD
93#
94# Pattern 4:
95# This an old pattern from the hppa aCC version of this file.
96# I left it alone.
97#
98# chastain 2002-04-08
99
06846494
MC
100# pattern #5
101# PASS
102# stabs+
103# gcc HEAD abi-2
104#
105# chastain 2004-01-02
106
c2d11a7d
JM
107set sep "(\[.\]|___)\[0-9\]"
108
c906108c
SS
109send_gdb "ptype Local\n"
110gdb_expect {
34af4875 111 -re "type = class Local \{\[\r\n\t \]*public:\[\r\n\t \]*int loc1;\[\r\n\t \]*char loc_foo\\((const *|)char\\);\[\r\n\t \]*\}.*$gdb_prompt $" { pass "ptype Local" }
5019bb54 112 -re "type = class Local \{\[\r\n\t \]*public:\[\r\n\t \]*int loc1;\[\r\n\t \]*char loc_foo\\((const *|)char\\);\[\r\n\t \]*char loc_foo\\((const *|)char\\);\[\r\n\t \]*\}.*$gdb_prompt $" {
6b549786 113 kfail "gdb/483" "ptype Local"
5019bb54 114 }
34af4875
MC
115 -re "type = class Local \{\[\r\n\t \]*public:\[\r\n\t \]*int loc1;\[\r\n\t \]*Local & operator *=\\((foobar__Fi${sep}::|)Local const *&\\);\[\r\n\t \]*Local\\((foobar__Fi${sep}::|)Local const *&\\);\[\r\n\t \]*Local\\((void|)\\);\[\r\n\t \]*char loc_foo\\(char\\);\[\r\n\t \]*\}.*$gdb_prompt $" { pass "ptype Local" }
116 -re "type = class Local \{\r\n\[\t \]*public:\r\n\[\t \]*int loc1;\r\n\r\n\[\t \]*char loc_foo\\(char\\);\r\n\[\t \]*\\(Local at.*local\\.cc:\[0-9\]*\\)\r\n\}.*$gdb_prompt $" { xpass "ptype Local (old aCC)" }
06846494 117 -re "type = class Local \{\[\r\n\t \]*public:\[\r\n\t \]*int loc1;\[\r\n\t \]*char loc_foo\\(char\\);\[\r\n\t \]*Local & operator *=\\((foobar__Fi${sep}::|)Local const *&\\);\[\r\n\t \]*Local\\((foobar__Fi${sep}::|)Local const *&\\);\[\r\n\t \]*Local\\((void|)\\);\[\r\n\t \]*\}.*$gdb_prompt $" { pass "ptype Local" }
34af4875
MC
118 -re ".*$gdb_prompt $" { fail "ptype Local" }
119 timeout { fail "(timeout) ptype Local" }
c906108c
SS
120}
121
6b549786
JB
122gdb_test "break marker2"
123gdb_test "continue" "Continuing\\..*Breakpoint \[0-9\]+, marker2.*" \
124 "continuing to marker2"
125
126gdb_test "up" ".*main.*" "up from marker2"
127
128# Make sure that `Local' isn't in scope here; it's local to foobar.
129# setup_kfail "gdb/825"
130send_gdb "ptype Local\n"
131set eol "\[\t \]*\[\r\n\]+\[\t \]*"
132gdb_expect {
133 -re "No symbol \"Local\" in current context.*${gdb_prompt} $" {
134 pass "Local out of scope"
135 }
8b8d7525 136 -re "ptype Local${eol}type = class Local {${eol} public:${eol} int loc1;${eol}.*${eol} char loc_foo\\(char\\);${eol}}${eol}${gdb_prompt} " {
6b549786
JB
137 # GCC emits STABS debugging information in a way that doesn't
138 # properly preserve the scoping of local classes. I think
139 # we'd need to start using Sun's extensions to stabs to get
140 # this right.
141 kfail gdb/825 "Local out of scope"
142 }
06846494
MC
143 -re "ptype Local${eol}type = class Local {${eol} public:${eol} int loc1;${eol} char loc_foo\\(char\\);${eol}.*${eol}}${eol}${gdb_prompt} " {
144 # gcc 3.X abi-2 -gstabs+
145 kfail gdb/825 "Local out of scope"
146 }
6b549786
JB
147 -re ".*${gdb_prompt} $" {
148 fail "Local out of scope"
149 }
150 timeout {
151 fail "Local out of scope (timeout)"
152 }
153}
154
155
a0b3c4fd
JM
156# DTS CLLbs14316 and CLLbs17058
157# coulter - I added a clause for HP's aCC compiler. We print out the type
158# as xx instead of const unsigned char, but we still have an expected failure
159# because of two reasons:
160# There is a number at the end of InnerLocal4 which should not be there,
161# DTS CLLbs14316
162# The line number for the class
34af4875
MC
163# setup_xfail "hppa*-*-*" CLLbs14316
164
165# ---
166# Pattern 1:
167# PASS
168# dwarf-2
def1b996 169# 2.95.3, 2.96-rh, 3.0.4, 3.1, gcc-3_1-branch, HEAD
34af4875
MC
170#
171# Pattern 2:
172# PASS
173# stabs+
def1b996 174# 2.95.3, 2.96-rh, 3.0.4, 3.1, gcc-3_1-branch, HEAD
34af4875
MC
175#
176# Pattern 3:
177# Old hppa pattern.
178#
179# Pattern 4:
180# Old hppa pattern.
181#
def1b996 182# chastain 2002-05-27
34af4875 183
06846494
MC
184# Pattern 5:
185# PASS
186# stabs+
187# HEAD
188#
189# chastain 2004-01-02
190
c906108c
SS
191send_gdb "ptype InnerLocal\n"
192gdb_expect {
def1b996
MC
193 -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)" }
194 -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
195 -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)" }
196 -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 197 -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
198 -re ".*$gdb_prompt $" { fail "ptype InnerLocal" }
199 timeout { fail "(timeout) ptype InnerLocal" }
c906108c
SS
200}
201
34af4875
MC
202#---
203# Pattern 1:
204# PASS
205# dwarf-2
206# gcc 2.95.3, 2.96-rh, 3.0.4, gcc-3_1-branch, HEAD
207#
208# Pattern 2:
209# PASS
210# stabs+
211# gcc 2.95.3, 2.96-rh, 3.0.4, gcc-3_1-branch, HEAD
212#
213# chastain 2002-04-08
214
c906108c
SS
215send_gdb "ptype NestedInnerLocal\n"
216gdb_expect {
34af4875
MC
217 -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" }
218 -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" }
219 -re ".*$gdb_prompt $" { fail "ptype NestedInnerLocal" }
220 timeout { fail "(timeout) ptype NestedInnerLocal" }
e5f9ba7b
MS
221}
222
a0b3c4fd
JM
223# gdb incorrectly interprets the NestedInnerLocal in
224# InnerLocal::NestedInnerLocal as field name instead of a type name;
225# See CLLbs14784.
34af4875
MC
226
227#---
228# Pattern 3:
229# FAIL
230# The comment above, about CLLbs14784, is still correct.
231# dwarf-2
232# gcc 2.95.3, 2.96-rh, 3.0.4, gcc-3_1-branch, HEAD
233# stabs+
234# gcc 2.95.3, 2.96-rh, 3.0.4, gcc-3_1-branch, HEAD
235#
236# chastain 2002-04-08
237
c906108c
SS
238send_gdb "ptype InnerLocal::NestedInnerLocal\n"
239gdb_expect {
34af4875
MC
240 -re "type = class InnerLocal::NestedInnerLocal \{\[\r\n\t \]*public:\[\r\n\t \]*int nil;\[\r\n\t \]*int nil_foo\\(int\\);\[\r\n\t \]*\}.*$gdb_prompt $" { pass "ptype InnerLocal::NestedInnerLocal" }
241 -re "type = class InnerLocal::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 InnerLocal::NestedInnerLocal" }
5019bb54 242 -re "There is no field named NestedInnerLocal.*$gdb_prompt $" {
b0023472
DJ
243 setup_kfail "gdb/482" *-*-*
244 fail "ptype InnerLocal::NestedInnerLocal"
5019bb54 245 }
34af4875
MC
246 -re "No symbol .*NestedInnerLocal.* in current context.*$gdb_prompt $" { fail "ptype InnerLocal::NestedInnerLocal (bogus symbol lookup)" }
247 -re ".*$gdb_prompt $" { fail "ptype InnerLocal::NestedInnerLocal" }
248 timeout { fail "(timeout) ptype InnerLocal::NestedInnerLocal" }
c906108c 249}
This page took 0.402945 seconds and 4 git commands to generate.