1 # Copyright 1998-2004, 2007-2012 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 3 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, see <http://www.gnu.org/licenses/>.
16 # tests for local variables
17 # Written by Satish Pai <pai@apollo.hp.com> 1997-07-08
18 # Cleaned by Michael Chastain <mec@shout.net> 2002-04-08
21 # This file is part of the gdb testsuite
31 # test running programs
34 if { [skip_cplus_tests] } { continue }
37 set srcfile ${testfile}.cc
38 set binfile ${objdir}/${subdir}/${testfile}
40 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
45 if [get_compiler_info $binfile "c++"] {
51 gdb_reinitialize_dir $srcdir/$subdir
56 # set it up at a breakpoint so we can play with the variable values
58 if ![runto_main] then {
59 perror "couldn't run to breakpoint"
63 if ![runto 'marker1'] then {
64 perror "couldn't run to marker1"
68 gdb_test "up" ".*foobar.*" "up from marker1"
70 set sep "(\[.\]|___)\[0-9\]"
72 # ptype on a local variable.
74 # This test has six arms. The first three arms accept normal output:
75 # no synthetic methods; synthetic methods before user methods;
76 # synthetic methods after user methods.
78 # The next two arms accept "foobar__Fi.0::Local" instead of "Local".
79 # This is a bug. It happens in various places with various versions of
80 # gcc and gdb and various debugging types.
82 # The last arm accepts the user methods in duplicate. This bug happens
83 # with gcc 3.3.2 -gdwarf-2, and has been fixed in gcc HEAD 2004-01-22.
85 # -- chastain 2004-01-24
87 set re_class "((struct|class) Local \{${ws}public:|struct Local \{)"
88 set re_fields "int loc1;"
89 set re_methods "char loc_foo\\(char\\);"
90 set re_synth_gcc_23 "Local & operator=\\(Local const ?&\\);${ws}Local\\(Local const ?&\\);${ws}Local\\((void|)\\);"
92 set XX_class "((struct|class) foobar__Fi.0::Local \{${ws}public:|struct foobar__Fi.0:Local \{)"
93 set XX_synth_gcc_2 "Local & operator=\\(foobar__Fi.0::Local const ?&\\);${ws}Local\\(foobar__Fi.0::Local const ?&\\);${ws}Local\\((void|)\\);"
94 set YY_methods "$re_methods${ws}$re_methods"
97 gdb_test_multiple "ptype l" $name {
98 -re "type = $re_class${ws}$re_fields${ws}$re_methods$nl\}$nl$gdb_prompt $" {
99 # gdb 6.0, gcc 2.95.3, dwarf-2
100 # gdb 6.0, gcc HEAD 2004-01-22, dwarf-2
101 # gdb HEAD 2004-01-23, gcc HEAD 2004-01,22, dwarf-2
104 -re "type = $re_class${ws}$re_fields${ws}$re_synth_gcc_23${ws}$re_methods$nl\}$nl$gdb_prompt $" {
105 # gdb 6.0, gcc 3.3.2, stabs+
106 # gdb HEAD 2004-01-23, gcc 3.3.2, stabs+
109 -re "type = $re_class${ws}$re_fields${ws}$re_methods${ws}$re_synth_gcc_23${ws}$nl\}$nl$gdb_prompt $" {
110 # gdb 6.0, gcc HEAD 2004-01-22, stabs+
111 # gdb HEAD 2004-01-23, gcc HEAD 2004-01-22, stabs+
114 -re "type = $XX_class${ws}$re_fields${ws}$re_methods$nl\}$nl$gdb_prompt $" {
115 # gdb HEAD 2004-01-23, gcc 2.95.3, dwarf-2
116 kfail "gdb/1516" "$name"
118 -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 $" {
119 # gdb 6.0, gcc 2.95.3, stabs+
120 # gdb HEAD 2004-01-23, gcc 2.95.3, stabs+
121 kfail "gdb/1516" "$name"
123 -re "type = ($re_class|$XX_class)${ws}$re_fields${ws}$YY_methods$nl\}$nl$gdb_prompt $" {
124 # gdb 6.0, gcc 3.3.2, dwarf-2
125 # gdb HEAD 2004-01-23, gcc 3.2.2, dwarf-2
126 kfail "gdb/483" "$name"
130 # This is the same test with "ptype Local" (the type name)
131 # instead of "ptype l" (the variable name).
133 set name "ptype Local"
134 gdb_test_multiple "ptype Local" $name {
135 -re "type = $re_class${ws}$re_fields${ws}$re_methods$nl\}$nl$gdb_prompt $" {
136 # gdb 6.0, gcc 2.95.3, dwarf-2
137 # gdb 6.0, gcc HEAD 2004-01-22, dwarf-2
138 # gdb HEAD 2004-01-23, gcc HEAD 2004-01-22, dwarf-2
141 -re "type = $re_class${ws}$re_fields${ws}$re_synth_gcc_23${ws}$re_methods$nl\}$nl$gdb_prompt $" {
142 # gdb 6.0, gcc 3.3.2, stabs+
143 # gdb HEAD 2004-01-23, gcc 3.3.2, stabs+
146 -re "type = $re_class${ws}$re_fields${ws}$re_methods${ws}$re_synth_gcc_23${ws}$nl\}$nl$gdb_prompt $" {
147 # gdb 6.0, gcc HEAD 2004-01-22, stabs+
148 # gdb HEAD 2004-01-23, gcc HEAD 2004-01-22, stabs+
151 -re "type = $XX_class${ws}$re_fields${ws}$re_methods$nl\}$nl$gdb_prompt $" {
152 kfail "gdb/1516" "$name"
154 -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 $" {
155 # gdb 6.0, gcc 2.95.3, stabs+
156 # gdb HEAD 2004-01-23, gcc 2.95.3, stabs+
157 kfail "gdb/1516" "$name"
159 -re "type = ($re_class|$XX_class)${ws}$re_fields${ws}$YY_methods$nl\}$nl$gdb_prompt $" {
160 # gdb 6.0, gcc 3.3.2, dwarf-2
161 # gdb HEAD 2004-01-23, gcc 3.2.2, dwarf-2
162 kfail "gdb/483" "$name"
164 -re "No symbol \"Local\" in current context.$nl$gdb_prompt $" {
165 # gdb HEAD 2004-01-23, gcc 2.95.3, dwarf-2
170 gdb_test "break marker2"
171 gdb_test "continue" "Continuing\\..*Breakpoint \[0-9\]+, marker2.*" \
172 "continuing to marker2"
174 gdb_test "up" ".*main.*" "up from marker2"
176 # Make sure that `Local' isn't in scope here; it's local to foobar.
177 # setup_kfail "gdb/825"
179 set eol "\[\t \]*\[\r\n\]+\[\t \]*"
180 gdb_test_multiple "ptype Local" "Local out of scope" {
181 -re "No symbol \"Local\" in current context.*${gdb_prompt} $" {
182 pass "Local out of scope"
184 -re "ptype Local${eol}type = class Local {${eol} public:${eol} int loc1;${eol}.*${eol} char loc_foo\\(char\\);${eol}}${eol}${gdb_prompt} " {
185 # GCC emits STABS debugging information in a way that doesn't
186 # properly preserve the scoping of local classes. I think
187 # we'd need to start using Sun's extensions to stabs to get
189 kfail gdb/825 "Local out of scope"
191 -re "ptype Local${eol}type = class Local {${eol} public:${eol} int loc1;${eol} char loc_foo\\(char\\);${eol}.*${eol}}${eol}${gdb_prompt} " {
192 # gcc 3.X abi-2 -gstabs+
193 kfail gdb/825 "Local out of scope"
198 # DTS CLLbs14316 and CLLbs17058
199 # coulter - I added a clause for HP's aCC compiler. We print out the type
200 # as xx instead of const unsigned char, but we still have an expected failure
201 # because of two reasons:
202 # There is a number at the end of InnerLocal4 which should not be there,
204 # The line number for the class
205 # setup_xfail "hppa*-*-*" CLLbs14316
211 # 2.95.3, 2.96-rh, 3.0.4, 3.1, gcc-3_1-branch, HEAD
216 # 2.95.3, 2.96-rh, 3.0.4, 3.1, gcc-3_1-branch, HEAD
224 # chastain 2002-05-27
231 # chastain 2004-01-02
233 gdb_test_multiple "ptype InnerLocal" "ptype InnerLocal" {
234 -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 $" {
235 pass "ptype InnerLocal (pattern 1)"
237 -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 $" {
238 pass "ptype InnerLocal (pattern 2)"
240 -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 $" {
241 pass "ptype InnerLocal (old HP aCC)"
243 -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 $" {
244 pass "ptype InnerLocal (old HP aCC)"
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\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 $" {
247 pass "ptype InnerLocal (pattern 5)"
255 # gcc 2.95.3, 2.96-rh, 3.0.4, gcc-3_1-branch, HEAD
260 # gcc 2.95.3, 2.96-rh, 3.0.4, gcc-3_1-branch, HEAD
262 # chastain 2002-04-08
264 # NOTE (2004-02-24, carlton): This test really is invalid -
265 # 'NestedInnerLocal' shouldn't be visible, so only the third
266 # expression should count as a pass. I'm leaving in the earlier
267 # passes, however, given the current problematic state of our local
268 # class support, but once we fix PR gdb/482, we should delete this
271 gdb_test_multiple "ptype NestedInnerLocal" "ptype NestedInnerLocal" {
272 -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 $" {
273 pass "ptype NestedInnerLocal"
275 -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 $" {
276 pass "ptype NestedInnerLocal"
278 -re "No symbol \"NestedInnerLocal\" in current context\.\r\n$gdb_prompt $" {
279 pass "ptype NestedInnerLocal"
283 set re_class "((struct|class) InnerLocal::NestedInnerLocal \{${ws}public:|struct InnerLocal::NestedInnerLocal \{)"
284 set re_fields "int nil;"
285 set re_methods "int nil_foo\\(int\\);"
286 set re_synth_gcc_23 "InnerLocal::NestedInnerLocal & operator=\\(InnerLocal::NestedInnerLocal const ?&\\);${ws}NestedInnerLocal\\(InnerLocal::NestedInnerLocal const ?&\\);${ws}NestedInnerLocal\\(\\);"
288 set name "ptype InnerLocal::NestedInnerLocal"
289 gdb_test_multiple "ptype InnerLocal::NestedInnerLocal" $name {
290 -re "type = $re_class${ws}$re_fields${ws}$re_methods$nl\}$nl$gdb_prompt $" {
291 # gcc -gdwarf-2 should produce this but does not yet
294 -re "type = $re_class${ws}$re_fields${ws}$re_synth_gcc_23${ws}$re_methods${ws}$nl\}$nl$gdb_prompt $" {
295 # gcc 2.95.3 -gstabs+
296 # gcc v3 -gstabs+, abi 1
299 -re "type = $re_class${ws}$re_fields${ws}$re_methods${ws}$re_synth_gcc_23${ws}$nl\}$nl$gdb_prompt $" {
300 # gcc v3 -gstabs+, abi 2
303 -re "There is no field named NestedInnerLocal.*$gdb_prompt $" {
305 kfail "gdb/482" $name