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.
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 namespaces
22 # Originally written by Satish Pai <pai@apollo.hp.com> 1997-07-23
24 # This file is part of the gdb testsuite
26 # Note: The original tests were geared to the HP aCC compiler,
27 # which has an idiosyncratic way of emitting debug info
29 # Note: As of 2000-06-03, these pass under g++ - djb
39 if { [skip_cplus_tests] } { continue }
41 set testfile "namespace"
42 set srcfile ${testfile}.cc
43 set objfile ${objdir}/${subdir}/${testfile}.o
44 set srcfile1 ${testfile}1.cc
45 set objfile1 ${objdir}/${subdir}/${testfile}1.o
46 set binfile ${objdir}/${subdir}/${testfile}
48 if [get_compiler_info ${binfile} c++] {
52 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${objfile}" object {debug c++}] != "" } {
53 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
56 if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${objfile1}" object {debug c++}] != "" } {
57 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
60 if { [gdb_compile "${objfile} ${objfile1}" "${binfile}" executable {debug c++}] != "" } {
61 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
66 gdb_reinitialize_dir $srcdir/$subdir
71 # set it up at a breakpoint so we can play with the variable values
73 if ![runto_main] then {
74 perror "couldn't run to breakpoint"
78 if ![runto 'marker1'] then {
79 perror "couldn't run to marker1"
83 gdb_test "up" ".*main.*" "up from marker1"
85 # Access a data item inside a namespace using colons and
88 # NOTE: carlton/2003-09-24: the quotes are becoming less necessary (or
89 # even desirable.) For tests where it should still work with quotes,
90 # I'm including versions both with and without quotes; for tests that
91 # shouldn't work with quotes, I'm only including one version.
93 send_gdb "print 'AAA::c'\n"
95 -re "\\$\[0-9\]* = 0 '\\\\(0|000)'\r\n$gdb_prompt $" { pass "print 'AAA::c'" }
96 -re ".*$gdb_prompt $" { fail "print 'AAA::c'" }
97 timeout { fail "(timeout) print 'AAA::c'" }
100 send_gdb "print AAA::c\n"
102 -re "\\$\[0-9\]* = 0 '\\\\(0|000)'\r\n$gdb_prompt $" { pass "print AAA::c" }
103 -re ".*$gdb_prompt $" { fail "print AAA::c" }
104 timeout { fail "(timeout) print AAA::c" }
107 # An object declared using "using".
109 send_gdb "print ina\n"
111 -re "\\$\[0-9\]+ = {xx = 33}.*$gdb_prompt $" {
114 -re ".*$gdb_prompt $" { fail "print ina" }
115 timeout { fail "(timeout) print ina" }
118 send_gdb "ptype ina\n"
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 $" {
123 -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 $" {
126 -re ".*$gdb_prompt $" { fail "ptype ina" }
127 timeout { fail "(timeout) ptype ina" }
130 # Check all functions are known to GDB
132 setup_xfail hppa*-*-*11* CLLbs14869
133 send_gdb "info func xyzq\n"
135 -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 $" {
136 pass "info func xyzq"
138 -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 $" {
139 pass "info func xyzq"
141 -re ".*$gdb_prompt $" { fail "info func xyzq" }
142 timeout { fail "(timeout) info func xyzq" }
145 # Call a function in a namespace
147 send_gdb "print 'AAA::xyzq'('x')\n"
149 -re "\\$\[0-9\]* = 97 'a'\r\n$gdb_prompt $" {
150 pass "print 'AAA::xyzq'('x')"
152 -re ".*$gdb_prompt $" { fail "print 'AAA::xyzq'('x')" }
153 timeout { fail "(timeout) print 'AAA::xyzq'('x')" }
156 send_gdb "print AAA::xyzq('x')\n"
158 -re "\\$\[0-9\]* = 97 'a'\r\n$gdb_prompt $" {
159 pass "print AAA::xyzq('x')"
161 -re ".*$gdb_prompt $" { fail "print AAA::xyzq('x')" }
162 timeout { fail "(timeout) print AAA::xyzq('x')" }
165 # Break on a function in a namespace
167 send_gdb "break AAA::xyzq\n"
169 -re "Breakpoint.*at $hex: file.*namespace.cc, line 42\\.\r\n$gdb_prompt $" {
170 pass "break AAA::xyzq"
172 -re ".*$gdb_prompt $" { fail "break AAA::xyzq" }
173 timeout { fail "(timeout) break AAA::xyzq" }
176 # Call a function in a nested namespace
178 send_gdb "print 'BBB::CCC::xyzq'('x')\n"
180 -re "\\$\[0-9\]* = 122 'z'\r\n$gdb_prompt $" {
181 pass "print 'BBB::CCC::xyzq'('x')"
183 -re ".*$gdb_prompt $" { fail "print 'BBB::CCC::xyzq'('x')" }
184 timeout { fail "(timeout) print 'BBB::CCC::xyzq'('x')" }
187 send_gdb "print BBB::CCC::xyzq('x')\n"
189 -re "\\$\[0-9\]* = 122 'z'\r\n$gdb_prompt $" {
190 pass "print BBB::CCC::xyzq('x')"
192 -re ".*$gdb_prompt $" { fail "print BBB::CCC::xyzq('x')" }
193 timeout { fail "(timeout) print BBB::CCC::xyzq('x')" }
196 # Break on a function in a nested namespace
198 send_gdb "break BBB::CCC::xyzq\n"
200 -re "Breakpoint.*at $hex: file.*namespace.cc, line 58\\.\r\n$gdb_prompt $" {
201 pass "break BBB::CCC::xyzq"
203 -re ".*$gdb_prompt $" { fail "break BBB::CCC::xyzq" }
204 timeout { fail "(timeout) break BBB::CCC::xyzq" }
207 # Print address of a function in a class in a namespace
209 send_gdb "print 'BBB::Class::xyzq'\n"
211 -re "\\$\[0-9\]* = \{char \\((BBB::|)Class \\*( const|), (char|int)\\)\} $hex <BBB::Class::xyzq\\(char\\)>\r\n$gdb_prompt $" {
212 pass "print 'BBB::Class::xyzq'"
214 -re ".*$gdb_prompt $" { fail "print 'BBB::Class::xyzq'" }
215 timeout { fail "(timeout) print 'BBB::Class::xyzq'" }
218 # Break on a function in a class in a namespace
220 send_gdb "break BBB::Class::xyzq\n"
222 -re "Breakpoint.*at $hex: file.*namespace.cc, line 63\\.\r\n$gdb_prompt $" {
223 pass "break BBB::Class::xyzq"
225 -re ".*$gdb_prompt $" { fail "break BBB::Class::xyzq" }
226 timeout { fail "(timeout) break BBB::Class::xyzq" }
229 # Test to see if the appropriate namespaces are in scope when trying
230 # to print out stuff from within a function defined within a
233 if ![runto "C::D::marker2"] then {
234 perror "couldn't run to marker2"
238 gdb_test "print c" "\\$\[0-9\].* = 1"
239 gdb_test "print cc" "No symbol \"cc\" in current context."
240 gdb_test "print 'C::cc'" "\\$\[0-9\].* = 2"
241 gdb_test "print C::cc" "\\$\[0-9\].* = 2"
242 gdb_test "print cd" "\\$\[0-9\].* = 3"
243 gdb_test "print C::D::cd" "No type \"D\" in namespace \"C::C\"."
244 gdb_test "print 'E::cde'" "\\$\[0-9\].* = 5"
245 gdb_test "print E::cde" "\\$\[0-9\].* = 5"
246 gdb_test "print shadow" "\\$\[0-9\].* = 13"
247 gdb_test "print E::ce" "No symbol \"ce\" in namespace \"C::D::E\"."
248 gdb_test "print cOtherFile" "\\$\[0-9\].* = 316"
249 gdb_test "ptype C" "type = namespace C::C"
250 gdb_test "ptype E" "type = namespace C::D::E"
252 # Some anonymous namespace tests.
254 gdb_test "print cX" "\\$\[0-9\].* = 6"
255 gdb_test "print 'F::cXf'" "\\$\[0-9\].* = 7"
256 gdb_test "print F::cXf" "\\$\[0-9\].* = 7"
257 gdb_test "print F::cXfX" "\\$\[0-9\].* = 8"
258 gdb_test "print X" "\\$\[0-9\].* = 9"
259 gdb_test "print 'G::Xg'" "\\$\[0-9\].* = 10"
260 gdb_test "print G::Xg" "\\$\[0-9\].* = 10"
261 gdb_test "print G::XgX" "\\$\[0-9\].* = 11"
262 gdb_test "print cXOtherFile" "No symbol \"cXOtherFile\" in current context."
263 gdb_test "print XOtherFile" "No symbol \"XOtherFile\" in current context."