]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.cp/namespace.exp
Copyright updates for 2007.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.cp / namespace.exp
CommitLineData
6aba47ca 1# Copyright 1997, 1998, 2000, 2001, 2002, 2003, 2004, 2007
d231d0b1 2# Free Software Foundation, Inc.
e6d71bf3
DB
3
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.
13#
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.
17
e6d71bf3 18# tests for namespaces
79c2c32d 19# Originally written by Satish Pai <pai@apollo.hp.com> 1997-07-23
e6d71bf3
DB
20
21# This file is part of the gdb testsuite
22
79c2c32d 23# Note: The original tests were geared to the HP aCC compiler,
e6d71bf3
DB
24# which has an idiosyncratic way of emitting debug info
25# for namespaces.
63d06c5c 26# Note: As of 2000-06-03, they passed under g++ - djb
e6d71bf3
DB
27
28
29if $tracelevel then {
30 strace $tracelevel
31 }
32
33set prms_id 0
34set bug_id 0
35
fc33412a 36if { [skip_cplus_tests] } { continue }
e6d71bf3
DB
37
38set testfile "namespace"
39set srcfile ${testfile}.cc
1fcb5155
DC
40set objfile ${objdir}/${subdir}/${testfile}.o
41set srcfile1 ${testfile}1.cc
42set objfile1 ${objdir}/${subdir}/${testfile}1.o
e6d71bf3
DB
43set binfile ${objdir}/${subdir}/${testfile}
44
753ccc7a 45if [get_compiler_info ${binfile} c++] {
e6d71bf3
DB
46 return -1;
47}
48
1fcb5155 49if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${objfile}" object {debug c++}] != "" } {
b60f0898
JB
50 untested namespace.exp
51 return -1
e6d71bf3
DB
52}
53
1fcb5155 54if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${objfile1}" object {debug c++}] != "" } {
b60f0898
JB
55 untested namespace.exp
56 return -1
1fcb5155 57}
e6d71bf3 58
1fcb5155 59if { [gdb_compile "${objfile} ${objfile1}" "${binfile}" executable {debug c++}] != "" } {
b60f0898
JB
60 untested namespace.exp
61 return -1
1fcb5155 62}
e6d71bf3
DB
63
64gdb_exit
65gdb_start
66gdb_reinitialize_dir $srcdir/$subdir
67gdb_load ${binfile}
68
69
70#
71# set it up at a breakpoint so we can play with the variable values
72#
73if ![runto_main] then {
74 perror "couldn't run to breakpoint"
75 continue
76}
77
db144853
MC
78if ![runto 'marker1'] then {
79 perror "couldn't run to marker1"
80 continue
81}
82
83gdb_test "up" ".*main.*" "up from marker1"
e6d71bf3
DB
84
85# Access a data item inside a namespace using colons and
63d06c5c 86# single quotes. :-(
e6d71bf3 87
79c2c32d
DC
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.
92
e6d71bf3
DB
93send_gdb "print 'AAA::c'\n"
94gdb_expect {
7b2ac63b 95 -re "\\$\[0-9\]* = 0 '\\\\(0|000)'\r\n$gdb_prompt $" { pass "print 'AAA::c'" }
e6d71bf3
DB
96 -re ".*$gdb_prompt $" { fail "print 'AAA::c'" }
97 timeout { fail "(timeout) print 'AAA::c'" }
98}
99
79c2c32d
DC
100send_gdb "print AAA::c\n"
101gdb_expect {
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" }
105}
106
e6d71bf3
DB
107# An object declared using "using".
108
109send_gdb "print ina\n"
110gdb_expect {
111 -re "\\$\[0-9\]+ = {xx = 33}.*$gdb_prompt $" {
112 pass "print ina"
113 }
114 -re ".*$gdb_prompt $" { fail "print ina" }
115 timeout { fail "(timeout) print ina" }
116}
117
118send_gdb "ptype ina\n"
119gdb_expect {
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"
122 }
d231d0b1
MC
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 $" {
124 pass "ptype ina"
125 }
e6d71bf3
DB
126 -re ".*$gdb_prompt $" { fail "ptype ina" }
127 timeout { fail "(timeout) ptype ina" }
128}
129
130# Check all functions are known to GDB
131
132setup_xfail hppa*-*-*11* CLLbs14869
133send_gdb "info func xyzq\n"
134gdb_expect {
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"
137 }
5178b9d6
DJ
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"
140 }
e6d71bf3
DB
141 -re ".*$gdb_prompt $" { fail "info func xyzq" }
142 timeout { fail "(timeout) info func xyzq" }
143}
144
145# Call a function in a namespace
146
147send_gdb "print 'AAA::xyzq'('x')\n"
148gdb_expect {
149 -re "\\$\[0-9\]* = 97 'a'\r\n$gdb_prompt $" {
150 pass "print 'AAA::xyzq'('x')"
151 }
152 -re ".*$gdb_prompt $" { fail "print 'AAA::xyzq'('x')" }
153 timeout { fail "(timeout) print 'AAA::xyzq'('x')" }
154}
155
79c2c32d
DC
156send_gdb "print AAA::xyzq('x')\n"
157gdb_expect {
158 -re "\\$\[0-9\]* = 97 'a'\r\n$gdb_prompt $" {
159 pass "print AAA::xyzq('x')"
160 }
161 -re ".*$gdb_prompt $" { fail "print AAA::xyzq('x')" }
162 timeout { fail "(timeout) print AAA::xyzq('x')" }
163}
164
e6d71bf3
DB
165# Break on a function in a namespace
166
167send_gdb "break AAA::xyzq\n"
168gdb_expect {
169 -re "Breakpoint.*at $hex: file.*namespace.cc, line 42\\.\r\n$gdb_prompt $" {
170 pass "break AAA::xyzq"
171 }
172 -re ".*$gdb_prompt $" { fail "break AAA::xyzq" }
173 timeout { fail "(timeout) break AAA::xyzq" }
174}
175
176# Call a function in a nested namespace
177
178send_gdb "print 'BBB::CCC::xyzq'('x')\n"
179gdb_expect {
180 -re "\\$\[0-9\]* = 122 'z'\r\n$gdb_prompt $" {
181 pass "print 'BBB::CCC::xyzq'('x')"
182 }
183 -re ".*$gdb_prompt $" { fail "print 'BBB::CCC::xyzq'('x')" }
184 timeout { fail "(timeout) print 'BBB::CCC::xyzq'('x')" }
185}
186
79c2c32d
DC
187send_gdb "print BBB::CCC::xyzq('x')\n"
188gdb_expect {
189 -re "\\$\[0-9\]* = 122 'z'\r\n$gdb_prompt $" {
190 pass "print BBB::CCC::xyzq('x')"
191 }
192 -re ".*$gdb_prompt $" { fail "print BBB::CCC::xyzq('x')" }
193 timeout { fail "(timeout) print BBB::CCC::xyzq('x')" }
194}
195
e6d71bf3
DB
196# Break on a function in a nested namespace
197
198send_gdb "break BBB::CCC::xyzq\n"
199gdb_expect {
200 -re "Breakpoint.*at $hex: file.*namespace.cc, line 58\\.\r\n$gdb_prompt $" {
201 pass "break BBB::CCC::xyzq"
202 }
203 -re ".*$gdb_prompt $" { fail "break BBB::CCC::xyzq" }
204 timeout { fail "(timeout) break BBB::CCC::xyzq" }
205}
206
207# Print address of a function in a class in a namespace
208
209send_gdb "print 'BBB::Class::xyzq'\n"
210gdb_expect {
1bc05c3a 211 -re "\\$\[0-9\]* = \{char \\((BBB::|)Class \\*( const|), (char|int)\\)\} $hex <BBB::Class::xyzq\\(char\\)>\r\n$gdb_prompt $" {
a773d1cd 212 pass "print 'BBB::Class::xyzq'"
e6d71bf3 213 }
a773d1cd
MS
214 -re ".*$gdb_prompt $" { fail "print 'BBB::Class::xyzq'" }
215 timeout { fail "(timeout) print 'BBB::Class::xyzq'" }
e6d71bf3
DB
216}
217
63d06c5c
DC
218send_gdb "print BBB::Class::xyzq\n"
219gdb_expect {
220 -re "\\$\[0-9\]* = \{char \\((BBB::|)Class \\*( const|), (char|int)\\)\} $hex <BBB::Class::xyzq\\(char\\)>\r\n$gdb_prompt $" {
221 pass "print BBB::Class::xyzq"
222 }
223 -re ".*$gdb_prompt $" { fail "print BBB::Class::xyzq" }
224 timeout { fail "(timeout) print BBB::Class::xyzq" }
225}
226
e6d71bf3
DB
227# Break on a function in a class in a namespace
228
229send_gdb "break BBB::Class::xyzq\n"
230gdb_expect {
231 -re "Breakpoint.*at $hex: file.*namespace.cc, line 63\\.\r\n$gdb_prompt $" {
232 pass "break BBB::Class::xyzq"
233 }
234 -re ".*$gdb_prompt $" { fail "break BBB::Class::xyzq" }
235 timeout { fail "(timeout) break BBB::Class::xyzq" }
236}
237
1fcb5155
DC
238# Test to see if the appropriate namespaces are in scope when trying
239# to print out stuff from within a function defined within a
240# namespace.
241
242if ![runto "C::D::marker2"] then {
243 perror "couldn't run to marker2"
244 continue
245}
246
247gdb_test "print c" "\\$\[0-9\].* = 1"
248gdb_test "print cc" "No symbol \"cc\" in current context."
249gdb_test "print 'C::cc'" "\\$\[0-9\].* = 2"
79c2c32d 250gdb_test "print C::cc" "\\$\[0-9\].* = 2"
1fcb5155 251gdb_test "print cd" "\\$\[0-9\].* = 3"
63d06c5c 252gdb_test "print C::D::cd" "No type \"D\" within class or namespace \"C::C\"."
1fcb5155 253gdb_test "print 'E::cde'" "\\$\[0-9\].* = 5"
79c2c32d 254gdb_test "print E::cde" "\\$\[0-9\].* = 5"
1fcb5155 255gdb_test "print shadow" "\\$\[0-9\].* = 13"
79c2c32d 256gdb_test "print E::ce" "No symbol \"ce\" in namespace \"C::D::E\"."
5c4e30ca
DC
257gdb_test "ptype C" "type = namespace C::C"
258gdb_test "ptype E" "type = namespace C::D::E"
1fcb5155 259
c203e0ca
MC
260gdb_test "ptype CClass" "type = (class C::CClass \{\r\n public:|struct C::CClass \{)\r\n int x;\r\n\}"
261gdb_test "ptype CClass::NestedClass" "type = (class C::CClass::NestedClass \{\r\n public:|struct C::CClass::NestedClass \{)\r\n int y;\r\n\}"
63d06c5c
DC
262gdb_test "ptype NestedClass" "No symbol \"NestedClass\" in current context."
263setup_kfail "gdb/1448" "*-*-*"
264gdb_test "ptype ::C::CClass" "type = class C::CClass \{\r\n public:\r\n int x;\r\n\}"
265setup_kfail "gdb/1448" "*-*-*"
266gdb_test "ptype ::C::CClass::NestedClass" "type = class C::CClass::NestedClass \{\r\n public:\r\n int y;\r\n\}"
267setup_kfail "gdb/1448" "*-*-*"
268gdb_test "ptype ::C::NestedClass" "No symbol \"NestedClass\" in namespace \"C\"."
269gdb_test "ptype C::CClass" "No symbol \"CClass\" in namespace \"C::C\"."
270gdb_test "ptype C::CClass::NestedClass" "No type \"CClass\" within class or namespace \"C::C\"."
271gdb_test "ptype C::NestedClass" "No symbol \"NestedClass\" in namespace \"C::C\"."
272
273# Tests involving multiple files
274
275gdb_test "print cOtherFile" "\\$\[0-9\].* = 316"
c203e0ca 276gdb_test "ptype OtherFileClass" "type = (class C::OtherFileClass \{\r\n public:|struct C::OtherFileClass \{)\r\n int z;\r\n\}"
63d06c5c
DC
277setup_kfail "gdb/1448" "*-*-*"
278gdb_test "ptype ::C::OtherFileClass" "type = class C::OtherFileClass \{\r\n public:\r\n int z;\r\n\}"
279gdb_test "ptype C::OtherFileClass" "No symbol \"OtherFileClass\" in namespace \"C::C\"."
280
1fcb5155
DC
281# Some anonymous namespace tests.
282
283gdb_test "print cX" "\\$\[0-9\].* = 6"
284gdb_test "print 'F::cXf'" "\\$\[0-9\].* = 7"
79c2c32d
DC
285gdb_test "print F::cXf" "\\$\[0-9\].* = 7"
286gdb_test "print F::cXfX" "\\$\[0-9\].* = 8"
1fcb5155
DC
287gdb_test "print X" "\\$\[0-9\].* = 9"
288gdb_test "print 'G::Xg'" "\\$\[0-9\].* = 10"
79c2c32d
DC
289gdb_test "print G::Xg" "\\$\[0-9\].* = 10"
290gdb_test "print G::XgX" "\\$\[0-9\].* = 11"
1fcb5155
DC
291gdb_test "print cXOtherFile" "No symbol \"cXOtherFile\" in current context."
292gdb_test "print XOtherFile" "No symbol \"XOtherFile\" in current context."