1 # Copyright 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
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
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
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.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
20 # tests for local variables
21 # Written by Satish Pai <pai@apollo.hp.com> 1997-07-08
22 # Cleaned by Michael Chastain <mec@shout.net> 2002-04-08
25 # This file is part of the gdb testsuite
32 # test running programs
37 if { [skip_cplus_tests] } { continue }
40 set srcfile ${testfile}.cc
41 set binfile ${objdir}/${subdir}/${testfile}
43 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
44 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
47 if [get_compiler_info $binfile "c++"] {
53 gdb_reinitialize_dir $srcdir/$subdir
58 # set it up at a breakpoint so we can play with the variable values
60 if ![runto_main] then {
61 perror "couldn't run to breakpoint"
65 if ![runto 'marker1'] then {
66 perror "couldn't run to marker1"
70 gdb_test "up" ".*foobar.*" "up from marker1"
72 # Local classes in g++ get names like "main.1::InnerLocal", just like local
73 # static variables. Some targets use "___" instead of ".".
83 # This has a duplicate "char loc_foo" line. This is a bug.
84 # Historically this has been an XFAIL.
86 # gcc 2.96-rh, 3.0.4, gcc-3_1-branch, HEAD
91 # gcc 2.95.3, 2.96-rh, 3.0.4, gcc-3_1-branch, HEAD
94 # This an old pattern from the hppa aCC version of this file.
99 set sep "(\[.\]|___)\[0-9\]"
101 send_gdb "ptype Local\n"
103 -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" }
104 -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 $" {
105 kfail "gdb/483" "ptype Local"
107 -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" }
108 -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)" }
109 -re ".*$gdb_prompt $" { fail "ptype Local" }
110 timeout { fail "(timeout) ptype Local" }
113 gdb_test "break marker2"
114 gdb_test "continue" "Continuing\\..*Breakpoint \[0-9\]+, marker2.*" \
115 "continuing to marker2"
117 gdb_test "up" ".*main.*" "up from marker2"
119 # Make sure that `Local' isn't in scope here; it's local to foobar.
120 # setup_kfail "gdb/825"
121 send_gdb "ptype Local\n"
122 set eol "\[\t \]*\[\r\n\]+\[\t \]*"
124 -re "No symbol \"Local\" in current context.*${gdb_prompt} $" {
125 pass "Local out of scope"
127 -re "ptype Local${eol}type = class Local {${eol} public:${eol} int loc1;${eol}.*${eol} char loc_foo\\(char\\);${eol}}${eol}${gdb_prompt} " {
128 # GCC emits STABS debugging information in a way that doesn't
129 # properly preserve the scoping of local classes. I think
130 # we'd need to start using Sun's extensions to stabs to get
132 kfail gdb/825 "Local out of scope"
134 -re ".*${gdb_prompt} $" {
135 fail "Local out of scope"
138 fail "Local out of scope (timeout)"
143 # DTS CLLbs14316 and CLLbs17058
144 # coulter - I added a clause for HP's aCC compiler. We print out the type
145 # as xx instead of const unsigned char, but we still have an expected failure
146 # because of two reasons:
147 # There is a number at the end of InnerLocal4 which should not be there,
149 # The line number for the class
150 # setup_xfail "hppa*-*-*" CLLbs14316
156 # 2.95.3, 2.96-rh, 3.0.4, 3.1, gcc-3_1-branch, HEAD
161 # 2.95.3, 2.96-rh, 3.0.4, 3.1, gcc-3_1-branch, HEAD
169 # chastain 2002-05-27
171 send_gdb "ptype InnerLocal\n"
173 -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)" }
174 -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)" }
175 -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)" }
176 -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)" }
177 -re ".*$gdb_prompt $" { fail "ptype InnerLocal" }
178 timeout { fail "(timeout) ptype InnerLocal" }
185 # gcc 2.95.3, 2.96-rh, 3.0.4, gcc-3_1-branch, HEAD
190 # gcc 2.95.3, 2.96-rh, 3.0.4, gcc-3_1-branch, HEAD
192 # chastain 2002-04-08
194 send_gdb "ptype NestedInnerLocal\n"
196 -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" }
197 -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" }
198 -re ".*$gdb_prompt $" { fail "ptype NestedInnerLocal" }
199 timeout { fail "(timeout) ptype NestedInnerLocal" }
202 # gdb incorrectly interprets the NestedInnerLocal in
203 # InnerLocal::NestedInnerLocal as field name instead of a type name;
209 # The comment above, about CLLbs14784, is still correct.
211 # gcc 2.95.3, 2.96-rh, 3.0.4, gcc-3_1-branch, HEAD
213 # gcc 2.95.3, 2.96-rh, 3.0.4, gcc-3_1-branch, HEAD
215 # chastain 2002-04-08
217 send_gdb "ptype InnerLocal::NestedInnerLocal\n"
219 -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" }
220 -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" }
221 -re "There is no field named NestedInnerLocal.*$gdb_prompt $" {
222 setup_kfail "gdb/482" *-*-*
223 fail "ptype InnerLocal::NestedInnerLocal"
225 -re "No symbol .*NestedInnerLocal.* in current context.*$gdb_prompt $" { fail "ptype InnerLocal::NestedInnerLocal (bogus symbol lookup)" }
226 -re ".*$gdb_prompt $" { fail "ptype InnerLocal::NestedInnerLocal" }
227 timeout { fail "(timeout) ptype InnerLocal::NestedInnerLocal" }