1 # Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004
2 # Free Software Foundation, Inc.
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.
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.
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.
18 # Please email any bugs, comments, and/or additions to this file to:
19 # bug-gdb@prep.ai.mit.edu
21 # tests for local variables
22 # Written by Satish Pai <pai@apollo.hp.com> 1997-07-08
23 # Cleaned by Michael Chastain <mec@shout.net> 2002-04-08
26 # This file is part of the gdb testsuite
36 # test running programs
41 if { [skip_cplus_tests] } { continue }
44 set srcfile ${testfile}.cc
45 set binfile ${objdir}/${subdir}/${testfile}
47 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
48 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
51 if [get_compiler_info $binfile "c++"] {
57 gdb_reinitialize_dir $srcdir/$subdir
62 # set it up at a breakpoint so we can play with the variable values
64 if ![runto_main] then {
65 perror "couldn't run to breakpoint"
69 if ![runto 'marker1'] then {
70 perror "couldn't run to marker1"
74 gdb_test "up" ".*foobar.*" "up from marker1"
76 set sep "(\[.\]|___)\[0-9\]"
78 # ptype on a local variable.
80 # This test has six arms. The first three arms accept normal output:
81 # no synthetic methods; synthetic methods before user methods;
82 # synthetic methods after user methods.
84 # The next two arms accept "foobar__Fi.0::Local" instead of "Local".
85 # This is a bug. It happens in various places with various versions of
86 # gcc and gdb and various debugging types.
88 # The last arm accepts the user methods in duplicate. This bug happens
89 # with gcc 3.3.2 -gdwarf-2, and has been fixed in gcc HEAD 2004-01-22.
91 # -- chastain 2004-01-24
93 set re_class "((struct|class) Local \{${ws}public:|struct Local \{)"
94 set re_fields "int loc1;"
95 set re_methods "char loc_foo\\(char\\);"
96 set re_synth_gcc_23 "Local & operator=\\(Local const ?&\\);${ws}Local\\(Local const ?&\\);${ws}Local\\((void|)\\);"
98 set XX_class "((struct|class) foobar__Fi.0::Local \{${ws}public:|struct foobar__Fi.0:Local \{)"
99 set XX_synth_gcc_2 "Local & operator=\\(foobar__Fi.0::Local const ?&\\);${ws}Local\\(foobar__Fi.0::Local const ?&\\);${ws}Local\\((void|)\\);"
100 set YY_methods "$re_methods${ws}$re_methods"
103 gdb_test_multiple "ptype l" $name {
104 -re "type = $re_class${ws}$re_fields${ws}$re_methods$nl\}$nl$gdb_prompt $" {
105 # gdb 6.0, gcc 2.95.3, dwarf-2
106 # gdb 6.0, gcc HEAD 2004-01-22, dwarf-2
107 # gdb HEAD 2004-01-23, gcc HEAD 2004-01,22, dwarf-2
110 -re "type = $re_class${ws}$re_fields${ws}$re_synth_gcc_23${ws}$re_methods$nl\}$nl$gdb_prompt $" {
111 # gdb 6.0, gcc 3.3.2, stabs+
112 # gdb HEAD 2004-01-23, gcc 3.3.2, stabs+
115 -re "type = $re_class${ws}$re_fields${ws}$re_methods${ws}$re_synth_gcc_23${ws}$nl\}$nl$gdb_prompt $" {
116 # gdb 6.0, gcc HEAD 2004-01-22, stabs+
117 # gdb HEAD 2004-01-23, gcc HEAD 2004-01-22, stabs+
120 -re "type = $XX_class${ws}$re_fields${ws}$re_methods$nl\}$nl$gdb_prompt $" {
121 # gdb HEAD 2004-01-23, gcc 2.95.3, dwarf-2
122 kfail "gdb/1516" "$name"
124 -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 $" {
125 # gdb 6.0, gcc 2.95.3, stabs+
126 # gdb HEAD 2004-01-23, gcc 2.95.3, stabs+
127 kfail "gdb/1516" "$name"
129 -re "type = ($re_class|$XX_class)${ws}$re_fields${ws}$YY_methods$nl\}$nl$gdb_prompt $" {
130 # gdb 6.0, gcc 3.3.2, dwarf-2
131 # gdb HEAD 2004-01-23, gcc 3.2.2, dwarf-2
132 kfail "gdb/483" "$name"
136 # This is the same test with "ptype Local" (the type name)
137 # instead of "ptype l" (the variable name).
139 set name "ptype Local"
140 gdb_test_multiple "ptype Local" $name {
141 -re "type = $re_class${ws}$re_fields${ws}$re_methods$nl\}$nl$gdb_prompt $" {
142 # gdb 6.0, gcc 2.95.3, dwarf-2
143 # gdb 6.0, gcc HEAD 2004-01-22, dwarf-2
144 # gdb HEAD 2004-01-23, gcc HEAD 2004-01-22, dwarf-2
147 -re "type = $re_class${ws}$re_fields${ws}$re_synth_gcc_23${ws}$re_methods$nl\}$nl$gdb_prompt $" {
148 # gdb 6.0, gcc 3.3.2, stabs+
149 # gdb HEAD 2004-01-23, gcc 3.3.2, stabs+
152 -re "type = $re_class${ws}$re_fields${ws}$re_methods${ws}$re_synth_gcc_23${ws}$nl\}$nl$gdb_prompt $" {
153 # gdb 6.0, gcc HEAD 2004-01-22, stabs+
154 # gdb HEAD 2004-01-23, gcc HEAD 2004-01-22, stabs+
157 -re "type = $XX_class${ws}$re_fields${ws}$re_methods$nl\}$nl$gdb_prompt $" {
158 kfail "gdb/1516" "$name"
160 -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 $" {
161 # gdb 6.0, gcc 2.95.3, stabs+
162 # gdb HEAD 2004-01-23, gcc 2.95.3, stabs+
163 kfail "gdb/1516" "$name"
165 -re "type = ($re_class|$XX_class)${ws}$re_fields${ws}$YY_methods$nl\}$nl$gdb_prompt $" {
166 # gdb 6.0, gcc 3.3.2, dwarf-2
167 # gdb HEAD 2004-01-23, gcc 3.2.2, dwarf-2
168 kfail "gdb/483" "$name"
170 -re "No symbol \"Local\" in current context.$nl$gdb_prompt $" {
171 # gdb HEAD 2004-01-23, gcc 2.95.3, dwarf-2
176 gdb_test "break marker2"
177 gdb_test "continue" "Continuing\\..*Breakpoint \[0-9\]+, marker2.*" \
178 "continuing to marker2"
180 gdb_test "up" ".*main.*" "up from marker2"
182 # Make sure that `Local' isn't in scope here; it's local to foobar.
183 # setup_kfail "gdb/825"
184 send_gdb "ptype Local\n"
185 set eol "\[\t \]*\[\r\n\]+\[\t \]*"
187 -re "No symbol \"Local\" in current context.*${gdb_prompt} $" {
188 pass "Local out of scope"
190 -re "ptype Local${eol}type = class Local {${eol} public:${eol} int loc1;${eol}.*${eol} char loc_foo\\(char\\);${eol}}${eol}${gdb_prompt} " {
191 # GCC emits STABS debugging information in a way that doesn't
192 # properly preserve the scoping of local classes. I think
193 # we'd need to start using Sun's extensions to stabs to get
195 kfail gdb/825 "Local out of scope"
197 -re "ptype Local${eol}type = class Local {${eol} public:${eol} int loc1;${eol} char loc_foo\\(char\\);${eol}.*${eol}}${eol}${gdb_prompt} " {
198 # gcc 3.X abi-2 -gstabs+
199 kfail gdb/825 "Local out of scope"
201 -re ".*${gdb_prompt} $" {
202 fail "Local out of scope"
205 fail "Local out of scope (timeout)"
210 # DTS CLLbs14316 and CLLbs17058
211 # coulter - I added a clause for HP's aCC compiler. We print out the type
212 # as xx instead of const unsigned char, but we still have an expected failure
213 # because of two reasons:
214 # There is a number at the end of InnerLocal4 which should not be there,
216 # The line number for the class
217 # setup_xfail "hppa*-*-*" CLLbs14316
223 # 2.95.3, 2.96-rh, 3.0.4, 3.1, gcc-3_1-branch, HEAD
228 # 2.95.3, 2.96-rh, 3.0.4, 3.1, gcc-3_1-branch, HEAD
236 # chastain 2002-05-27
243 # chastain 2004-01-02
245 send_gdb "ptype InnerLocal\n"
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|const unsigned char) *&\\);\[\r\n\t \]*\}.*$gdb_prompt $" { pass "ptype InnerLocal (pattern 1)" }
248 -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)" }
249 -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)" }
250 -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)" }
251 -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)" }
252 -re ".*$gdb_prompt $" { fail "ptype InnerLocal" }
253 timeout { fail "(timeout) ptype InnerLocal" }
260 # gcc 2.95.3, 2.96-rh, 3.0.4, gcc-3_1-branch, HEAD
265 # gcc 2.95.3, 2.96-rh, 3.0.4, gcc-3_1-branch, HEAD
267 # chastain 2002-04-08
269 send_gdb "ptype NestedInnerLocal\n"
271 -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" }
272 -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" }
273 -re ".*$gdb_prompt $" { fail "ptype NestedInnerLocal" }
274 timeout { fail "(timeout) ptype NestedInnerLocal" }
277 set re_class "((struct|class) InnerLocal::NestedInnerLocal \{${ws}public:|struct InnerLocal::NestedInnerLocal \{)"
278 set re_fields "int nil;"
279 set re_methods "int nil_foo\\(int\\);"
280 set re_synth_gcc_23 "InnerLocal::NestedInnerLocal & operator=\\(InnerLocal::NestedInnerLocal const ?&\\);${ws}NestedInnerLocal\\(InnerLocal::NestedInnerLocal const ?&\\);${ws}NestedInnerLocal\\(\\);"
282 set name "ptype InnerLocal::NestedInnerLocal"
283 gdb_test_multiple "ptype InnerLocal::NestedInnerLocal" $name {
284 -re "type = $re_class${ws}$re_fields${ws}$re_methods$nl\}$nl$gdb_prompt $" {
285 # gcc -gdwarf-2 should produce this but does not yet
288 -re "type = $re_class${ws}$re_fields${ws}$re_synth_gcc_23${ws}$re_methods${ws}$nl\}$nl$gdb_prompt $" {
289 # gcc 2.95.3 -gstabs+
290 # gcc v3 -gstabs+, abi 1
293 -re "type = $re_class${ws}$re_fields${ws}$re_methods${ws}$re_synth_gcc_23${ws}$nl\}$nl$gdb_prompt $" {
294 # gcc v3 -gstabs+, abi 2
297 -re "There is no field named NestedInnerLocal.*$gdb_prompt $" {
299 kfail "gdb/482" $name