No empty .Rs/.Re
[netbsd-mini2440.git] / gnu / dist / gdb6 / gdb / testsuite / gdb.cp / namespace.exp
blob4d295894986d49a974545eb8caa2103eb0d565fe
1 # Copyright 1997, 1998, 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.
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.
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 # tests for namespaces
19 # Originally written by Satish Pai <pai@apollo.hp.com> 1997-07-23
21 # This file is part of the gdb testsuite
23 # Note: The original tests were geared to the HP aCC compiler,
24 # which has an idiosyncratic way of emitting debug info
25 # for namespaces.
26 # Note: As of 2000-06-03, they passed under g++ - djb
29 if $tracelevel then {
30 strace $tracelevel
33 set prms_id 0
34 set bug_id 0
36 if { [skip_cplus_tests] } { continue }
38 set testfile "namespace"
39 set srcfile ${testfile}.cc
40 set objfile ${objdir}/${subdir}/${testfile}.o
41 set srcfile1 ${testfile}1.cc
42 set objfile1 ${objdir}/${subdir}/${testfile}1.o
43 set binfile ${objdir}/${subdir}/${testfile}
45 if [get_compiler_info ${binfile} c++] {
46 return -1;
49 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${objfile}" object {debug c++}] != "" } {
50 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
53 if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${objfile1}" object {debug c++}] != "" } {
54 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
57 if { [gdb_compile "${objfile} ${objfile1}" "${binfile}" executable {debug c++}] != "" } {
58 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
61 gdb_exit
62 gdb_start
63 gdb_reinitialize_dir $srcdir/$subdir
64 gdb_load ${binfile}
68 # set it up at a breakpoint so we can play with the variable values
70 if ![runto_main] then {
71 perror "couldn't run to breakpoint"
72 continue
75 if ![runto 'marker1'] then {
76 perror "couldn't run to marker1"
77 continue
80 gdb_test "up" ".*main.*" "up from marker1"
82 # Access a data item inside a namespace using colons and
83 # single quotes. :-(
85 # NOTE: carlton/2003-09-24: the quotes are becoming less necessary (or
86 # even desirable.) For tests where it should still work with quotes,
87 # I'm including versions both with and without quotes; for tests that
88 # shouldn't work with quotes, I'm only including one version.
90 send_gdb "print 'AAA::c'\n"
91 gdb_expect {
92 -re "\\$\[0-9\]* = 0 '\\\\(0|000)'\r\n$gdb_prompt $" { pass "print 'AAA::c'" }
93 -re ".*$gdb_prompt $" { fail "print 'AAA::c'" }
94 timeout { fail "(timeout) print 'AAA::c'" }
97 send_gdb "print AAA::c\n"
98 gdb_expect {
99 -re "\\$\[0-9\]* = 0 '\\\\(0|000)'\r\n$gdb_prompt $" { pass "print AAA::c" }
100 -re ".*$gdb_prompt $" { fail "print AAA::c" }
101 timeout { fail "(timeout) print AAA::c" }
104 # An object declared using "using".
106 send_gdb "print ina\n"
107 gdb_expect {
108 -re "\\$\[0-9\]+ = {xx = 33}.*$gdb_prompt $" {
109 pass "print ina"
111 -re ".*$gdb_prompt $" { fail "print ina" }
112 timeout { fail "(timeout) print ina" }
115 send_gdb "ptype ina\n"
116 gdb_expect {
117 -re "type = class (AAA::|)inA \{\r\n\[ \]*public:\r\n\[ \]*int xx;\r\n\[ \]*\r\n\[ \]*.*int fum\\(int\\);\r\n\}\r\n$gdb_prompt $" {
118 pass "ptype ina"
120 -re "type = class (AAA::|)inA \{\r\n\[ \]*public:\r\n\[ \]*int xx;\r\n\[ \]*\r\n\[ \]*int fum\\(int\\);\r\n.*\}\r\n$gdb_prompt $" {
121 pass "ptype ina"
123 -re ".*$gdb_prompt $" { fail "ptype ina" }
124 timeout { fail "(timeout) ptype ina" }
127 # Check all functions are known to GDB
129 setup_xfail hppa*-*-*11* CLLbs14869
130 send_gdb "info func xyzq\n"
131 gdb_expect {
132 -re "All functions.*File.*namespace.cc:\r\nint AAA::A_xyzq\\(int\\);\r\nint BBB::B_xyzq\\(int\\);\r\nchar AAA::xyzq\\(char\\);\r\nchar BBB::xyzq\\(char\\);\r\nchar BBB::CCC::xyzq\\(char\\);\r\nchar BBB::Class::xyzq\\(char\\);\r\n$gdb_prompt $" {
133 pass "info func xyzq"
135 -re "All functions.*File.*namespace.cc:\r\nint AAA::A_xyzq\\(int\\);\r\nchar AAA::xyzq\\(char\\);\r\nint BBB::B_xyzq\\(int\\);\r\nchar BBB::CCC::xyzq\\(char\\);\r\nchar BBB::Class::xyzq\\(char\\);\r\nchar BBB::xyzq\\(char\\);\r\n$gdb_prompt $" {
136 pass "info func xyzq"
138 -re ".*$gdb_prompt $" { fail "info func xyzq" }
139 timeout { fail "(timeout) info func xyzq" }
142 # Call a function in a namespace
144 send_gdb "print 'AAA::xyzq'('x')\n"
145 gdb_expect {
146 -re "\\$\[0-9\]* = 97 'a'\r\n$gdb_prompt $" {
147 pass "print 'AAA::xyzq'('x')"
149 -re ".*$gdb_prompt $" { fail "print 'AAA::xyzq'('x')" }
150 timeout { fail "(timeout) print 'AAA::xyzq'('x')" }
153 send_gdb "print AAA::xyzq('x')\n"
154 gdb_expect {
155 -re "\\$\[0-9\]* = 97 'a'\r\n$gdb_prompt $" {
156 pass "print AAA::xyzq('x')"
158 -re ".*$gdb_prompt $" { fail "print AAA::xyzq('x')" }
159 timeout { fail "(timeout) print AAA::xyzq('x')" }
162 # Break on a function in a namespace
164 send_gdb "break AAA::xyzq\n"
165 gdb_expect {
166 -re "Breakpoint.*at $hex: file.*namespace.cc, line 42\\.\r\n$gdb_prompt $" {
167 pass "break AAA::xyzq"
169 -re ".*$gdb_prompt $" { fail "break AAA::xyzq" }
170 timeout { fail "(timeout) break AAA::xyzq" }
173 # Call a function in a nested namespace
175 send_gdb "print 'BBB::CCC::xyzq'('x')\n"
176 gdb_expect {
177 -re "\\$\[0-9\]* = 122 'z'\r\n$gdb_prompt $" {
178 pass "print 'BBB::CCC::xyzq'('x')"
180 -re ".*$gdb_prompt $" { fail "print 'BBB::CCC::xyzq'('x')" }
181 timeout { fail "(timeout) print 'BBB::CCC::xyzq'('x')" }
184 send_gdb "print BBB::CCC::xyzq('x')\n"
185 gdb_expect {
186 -re "\\$\[0-9\]* = 122 'z'\r\n$gdb_prompt $" {
187 pass "print BBB::CCC::xyzq('x')"
189 -re ".*$gdb_prompt $" { fail "print BBB::CCC::xyzq('x')" }
190 timeout { fail "(timeout) print BBB::CCC::xyzq('x')" }
193 # Break on a function in a nested namespace
195 send_gdb "break BBB::CCC::xyzq\n"
196 gdb_expect {
197 -re "Breakpoint.*at $hex: file.*namespace.cc, line 58\\.\r\n$gdb_prompt $" {
198 pass "break BBB::CCC::xyzq"
200 -re ".*$gdb_prompt $" { fail "break BBB::CCC::xyzq" }
201 timeout { fail "(timeout) break BBB::CCC::xyzq" }
204 # Print address of a function in a class in a namespace
206 send_gdb "print 'BBB::Class::xyzq'\n"
207 gdb_expect {
208 -re "\\$\[0-9\]* = \{char \\((BBB::|)Class \\*( const|), (char|int)\\)\} $hex <BBB::Class::xyzq\\(char\\)>\r\n$gdb_prompt $" {
209 pass "print 'BBB::Class::xyzq'"
211 -re ".*$gdb_prompt $" { fail "print 'BBB::Class::xyzq'" }
212 timeout { fail "(timeout) print 'BBB::Class::xyzq'" }
215 send_gdb "print BBB::Class::xyzq\n"
216 gdb_expect {
217 -re "\\$\[0-9\]* = \{char \\((BBB::|)Class \\*( const|), (char|int)\\)\} $hex <BBB::Class::xyzq\\(char\\)>\r\n$gdb_prompt $" {
218 pass "print BBB::Class::xyzq"
220 -re ".*$gdb_prompt $" { fail "print BBB::Class::xyzq" }
221 timeout { fail "(timeout) print BBB::Class::xyzq" }
224 # Break on a function in a class in a namespace
226 send_gdb "break BBB::Class::xyzq\n"
227 gdb_expect {
228 -re "Breakpoint.*at $hex: file.*namespace.cc, line 63\\.\r\n$gdb_prompt $" {
229 pass "break BBB::Class::xyzq"
231 -re ".*$gdb_prompt $" { fail "break BBB::Class::xyzq" }
232 timeout { fail "(timeout) break BBB::Class::xyzq" }
235 # Test to see if the appropriate namespaces are in scope when trying
236 # to print out stuff from within a function defined within a
237 # namespace.
239 if ![runto "C::D::marker2"] then {
240 perror "couldn't run to marker2"
241 continue
244 gdb_test "print c" "\\$\[0-9\].* = 1"
245 gdb_test "print cc" "No symbol \"cc\" in current context."
246 gdb_test "print 'C::cc'" "\\$\[0-9\].* = 2"
247 gdb_test "print C::cc" "\\$\[0-9\].* = 2"
248 gdb_test "print cd" "\\$\[0-9\].* = 3"
249 gdb_test "print C::D::cd" "No type \"D\" within class or namespace \"C::C\"."
250 gdb_test "print 'E::cde'" "\\$\[0-9\].* = 5"
251 gdb_test "print E::cde" "\\$\[0-9\].* = 5"
252 gdb_test "print shadow" "\\$\[0-9\].* = 13"
253 gdb_test "print E::ce" "No symbol \"ce\" in namespace \"C::D::E\"."
254 gdb_test "ptype C" "type = namespace C::C"
255 gdb_test "ptype E" "type = namespace C::D::E"
257 gdb_test "ptype CClass" "type = (class C::CClass \{\r\n public:|struct C::CClass \{)\r\n int x;\r\n\}"
258 gdb_test "ptype CClass::NestedClass" "type = (class C::CClass::NestedClass \{\r\n public:|struct C::CClass::NestedClass \{)\r\n int y;\r\n\}"
259 gdb_test "ptype NestedClass" "No symbol \"NestedClass\" in current context."
260 setup_kfail "gdb/1448" "*-*-*"
261 gdb_test "ptype ::C::CClass" "type = class C::CClass \{\r\n public:\r\n int x;\r\n\}"
262 setup_kfail "gdb/1448" "*-*-*"
263 gdb_test "ptype ::C::CClass::NestedClass" "type = class C::CClass::NestedClass \{\r\n public:\r\n int y;\r\n\}"
264 setup_kfail "gdb/1448" "*-*-*"
265 gdb_test "ptype ::C::NestedClass" "No symbol \"NestedClass\" in namespace \"C\"."
266 gdb_test "ptype C::CClass" "No symbol \"CClass\" in namespace \"C::C\"."
267 gdb_test "ptype C::CClass::NestedClass" "No type \"CClass\" within class or namespace \"C::C\"."
268 gdb_test "ptype C::NestedClass" "No symbol \"NestedClass\" in namespace \"C::C\"."
270 # Tests involving multiple files
272 gdb_test "print cOtherFile" "\\$\[0-9\].* = 316"
273 gdb_test "ptype OtherFileClass" "type = (class C::OtherFileClass \{\r\n public:|struct C::OtherFileClass \{)\r\n int z;\r\n\}"
274 setup_kfail "gdb/1448" "*-*-*"
275 gdb_test "ptype ::C::OtherFileClass" "type = class C::OtherFileClass \{\r\n public:\r\n int z;\r\n\}"
276 gdb_test "ptype C::OtherFileClass" "No symbol \"OtherFileClass\" in namespace \"C::C\"."
278 # Some anonymous namespace tests.
280 gdb_test "print cX" "\\$\[0-9\].* = 6"
281 gdb_test "print 'F::cXf'" "\\$\[0-9\].* = 7"
282 gdb_test "print F::cXf" "\\$\[0-9\].* = 7"
283 gdb_test "print F::cXfX" "\\$\[0-9\].* = 8"
284 gdb_test "print X" "\\$\[0-9\].* = 9"
285 gdb_test "print 'G::Xg'" "\\$\[0-9\].* = 10"
286 gdb_test "print G::Xg" "\\$\[0-9\].* = 10"
287 gdb_test "print G::XgX" "\\$\[0-9\].* = 11"
288 gdb_test "print cXOtherFile" "No symbol \"cXOtherFile\" in current context."
289 gdb_test "print XOtherFile" "No symbol \"XOtherFile\" in current context."