gdb/
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.cp / namespace.exp
CommitLineData
4c38e0a4 1# Copyright 1997, 1998, 2000, 2001, 2002, 2003, 2004, 2007, 2008, 2009, 2010
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
e22f8b7c 6# the Free Software Foundation; either version 3 of the License, or
e6d71bf3 7# (at your option) any later version.
e22f8b7c 8#
e6d71bf3
DB
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.
e22f8b7c 13#
e6d71bf3 14# You should have received a copy of the GNU General Public License
e22f8b7c 15# along with this program. If not, see <http://www.gnu.org/licenses/>.
e6d71bf3 16
e6d71bf3 17# tests for namespaces
79c2c32d 18# Originally written by Satish Pai <pai@apollo.hp.com> 1997-07-23
e6d71bf3
DB
19
20# This file is part of the gdb testsuite
21
79c2c32d 22# Note: The original tests were geared to the HP aCC compiler,
e6d71bf3
DB
23# which has an idiosyncratic way of emitting debug info
24# for namespaces.
63d06c5c 25# Note: As of 2000-06-03, they passed under g++ - djb
e6d71bf3
DB
26
27
28if $tracelevel then {
29 strace $tracelevel
30 }
31
e6d71bf3 32
fc33412a 33if { [skip_cplus_tests] } { continue }
e6d71bf3
DB
34
35set testfile "namespace"
36set srcfile ${testfile}.cc
1fcb5155
DC
37set objfile ${objdir}/${subdir}/${testfile}.o
38set srcfile1 ${testfile}1.cc
39set objfile1 ${objdir}/${subdir}/${testfile}1.o
e6d71bf3
DB
40set binfile ${objdir}/${subdir}/${testfile}
41
753ccc7a 42if [get_compiler_info ${binfile} c++] {
e6d71bf3
DB
43 return -1;
44}
45
1fcb5155 46if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${objfile}" object {debug c++}] != "" } {
b60f0898
JB
47 untested namespace.exp
48 return -1
e6d71bf3
DB
49}
50
1fcb5155 51if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${objfile1}" object {debug c++}] != "" } {
b60f0898
JB
52 untested namespace.exp
53 return -1
1fcb5155 54}
e6d71bf3 55
1fcb5155 56if { [gdb_compile "${objfile} ${objfile1}" "${binfile}" executable {debug c++}] != "" } {
b60f0898
JB
57 untested namespace.exp
58 return -1
1fcb5155 59}
e6d71bf3
DB
60
61gdb_exit
62gdb_start
63gdb_reinitialize_dir $srcdir/$subdir
64gdb_load ${binfile}
65
66
67#
68# set it up at a breakpoint so we can play with the variable values
69#
70if ![runto_main] then {
71 perror "couldn't run to breakpoint"
72 continue
73}
74
db144853
MC
75if ![runto 'marker1'] then {
76 perror "couldn't run to marker1"
77 continue
78}
79
80gdb_test "up" ".*main.*" "up from marker1"
e6d71bf3
DB
81
82# Access a data item inside a namespace using colons and
63d06c5c 83# single quotes. :-(
e6d71bf3 84
79c2c32d
DC
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.
89
f8d3bf8f
MS
90gdb_test "print 'AAA::c'" \
91 "\\$\[0-9\]* = 0 '\\\\(0|000)'" \
92 "print 'AAA::c'"
e6d71bf3 93
f8d3bf8f
MS
94gdb_test "print AAA::c" \
95 "\\$\[0-9\]* = 0 '\\\\(0|000)'" \
96 "print AAA::c"
79c2c32d 97
e6d71bf3
DB
98# An object declared using "using".
99
f8d3bf8f 100gdb_test "print ina" "\\$\[0-9\]+ = {xx = 33}"
e6d71bf3 101
f8d3bf8f
MS
102gdb_test_multiple "ptype ina" "ptype ina" {
103 -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 $" {
104 pass "ptype ina"
105 }
106 -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 $" {
107 pass "ptype ina"
108 }
e6d71bf3
DB
109}
110
111# Check all functions are known to GDB
112
113setup_xfail hppa*-*-*11* CLLbs14869
f8d3bf8f
MS
114gdb_test_multiple "info func xyzq" "info func xyzq" {
115 -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 $" {
116 pass "info func xyzq"
117 }
118 -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 $" {
119 pass "info func xyzq"
120 }
e6d71bf3
DB
121}
122
123# Call a function in a namespace
124
f8d3bf8f
MS
125gdb_test "print 'AAA::xyzq'('x')" \
126 "\\$\[0-9\]* = 97 'a'" \
127 "print 'AAA::xyzq'('x')"
128
129gdb_test "print AAA::xyzq('x')" \
130 "\\$\[0-9\]* = 97 'a'" \
131 "print AAA::xyzq('x')"
79c2c32d 132
e6d71bf3
DB
133# Break on a function in a namespace
134
b598bfda 135gdb_test "break AAA::xyzq" \
ceeb3d5a 136 "Breakpoint.*at $hex: file.*namespace.cc, line 47\\."
e6d71bf3
DB
137
138# Call a function in a nested namespace
139
f8d3bf8f
MS
140gdb_test "print 'BBB::CCC::xyzq'('x')" \
141 "\\$\[0-9\]* = 122 'z'" \
142 "print 'BBB::CCC::xyzq'('x')"
143
144gdb_test "print BBB::CCC::xyzq('x')" \
145 "\\$\[0-9\]* = 122 'z'" \
146 "print BBB::CCC::xyzq('x')"
79c2c32d 147
e6d71bf3
DB
148# Break on a function in a nested namespace
149
b598bfda 150gdb_test "break BBB::CCC::xyzq" \
ceeb3d5a 151 "Breakpoint.*at $hex: file.*namespace.cc, line 63\\."
e6d71bf3
DB
152
153# Print address of a function in a class in a namespace
154
f8d3bf8f
MS
155gdb_test "print 'BBB::Class::xyzq'" \
156 "\\$\[0-9\]* = \{char \\((BBB::|)Class \\*( const|), (char|int)\\)\} $hex <BBB::Class::xyzq\\(char\\)>" \
157 "print 'BBB::Class::xyzq'"
e6d71bf3 158
f8d3bf8f
MS
159gdb_test "print BBB::Class::xyzq" \
160 "\\$\[0-9\]* = \{char \\((BBB::|)Class \\*( const|), (char|int)\\)\} $hex <BBB::Class::xyzq\\(char\\)>" \
161 "print BBB::Class::xyzq"
63d06c5c 162
e6d71bf3
DB
163# Break on a function in a class in a namespace
164
b598bfda 165gdb_test "break BBB::Class::xyzq" \
ceeb3d5a 166 "Breakpoint.*at $hex: file.*namespace.cc, line 68\\."
e6d71bf3 167
41f62f39
JK
168# Tests accessing static elements in namespace of other file.
169
170gdb_test "whatis C::cOtherFileType" "type = short"
171gdb_test "whatis ::C::cOtherFileType" "type = short"
172gdb_test "whatis C::cOtherFileVar" "type = const C::cOtherFileType"
173gdb_test "whatis ::C::cOtherFileVar" "type = const C::cOtherFileType"
174gdb_test "print C::cOtherFileVar" "\\$\[0-9\].* = 319"
175gdb_test "print ::C::cOtherFileVar" "\\$\[0-9\].* = 319"
176
177if {[test_compiler_info {gcc-[0-3]-*}]
178 || [test_compiler_info {gcc-4-[0-4]-*}]} {
179 # The type in class is missing in older GCCs.
180 setup_xfail *-*-*
181}
182gdb_test "whatis C::OtherFileClass::cOtherFileClassType" "type = short"
183if {[test_compiler_info {gcc-[0-3]-*}]
184 || [test_compiler_info {gcc-4-[0-4]-*}]} {
185 # The type in class is missing in older GCCs.
186 setup_xfail *-*-*
187}
188gdb_test "whatis ::C::OtherFileClass::cOtherFileClassType" "type = short"
189
190set test "print C::OtherFileClass::cOtherFileClassVar"
191gdb_test_multiple $test $test {
192 -re "\\$\[0-9\].* = 318\r\n$gdb_prompt $" {
193 pass $test
194 }
195 -re "static field cOtherFileClassVar has been optimized out\r\n$gdb_prompt $" {
196 setup_kfail "c++/11702" "*-*-*"
197 fail $test
198 }
199}
200
201# FSF GCC <=4.4 creates unqualified DIE "cOtherFileClassVar" ignoring the
202# namespace the same way older GDB did.
203set test "print ::cOtherFileClassVar"
204set test2 "print ::C::OtherFileClass::cOtherFileClassVar"
205gdb_test_multiple $test $test {
206 -re "No symbol \"cOtherFileClassVar\" in current context\\.\r\n$gdb_prompt $" {
207 pass $test
208
209 gdb_test_multiple $test2 $test2 {
210 -re "\\$\[0-9\].* = 318\r\n$gdb_prompt $" {
211 pass $test2
212 }
213 -re "static field cOtherFileClassVar has been optimized out\r\n$gdb_prompt $" {
214 setup_kfail "c++/11702" "*-*-*"
215 fail $test2
216 }
217 }
218
219 }
220 -re "\\$\[0-9\].* = 318\r\n$gdb_prompt $" {
221 if {[test_compiler_info {gcc-[0-3]-*}]
222 || [test_compiler_info {gcc-4-[0-4]-*}]} {
223 # Do not permit to XFAIL on recent GCCs.
224 setup_xfail *-*-*
225 }
226 fail $test
227
228 unresolved $test2
229 }
230}
231
1fcb5155
DC
232# Test to see if the appropriate namespaces are in scope when trying
233# to print out stuff from within a function defined within a
234# namespace.
235
236if ![runto "C::D::marker2"] then {
237 perror "couldn't run to marker2"
238 continue
239}
240
241gdb_test "print c" "\\$\[0-9\].* = 1"
242gdb_test "print cc" "No symbol \"cc\" in current context."
243gdb_test "print 'C::cc'" "\\$\[0-9\].* = 2"
79c2c32d 244gdb_test "print C::cc" "\\$\[0-9\].* = 2"
1fcb5155 245gdb_test "print cd" "\\$\[0-9\].* = 3"
63d06c5c 246gdb_test "print C::D::cd" "No type \"D\" within class or namespace \"C::C\"."
1fcb5155 247gdb_test "print 'E::cde'" "\\$\[0-9\].* = 5"
79c2c32d 248gdb_test "print E::cde" "\\$\[0-9\].* = 5"
1fcb5155 249gdb_test "print shadow" "\\$\[0-9\].* = 13"
79c2c32d 250gdb_test "print E::ce" "No symbol \"ce\" in namespace \"C::D::E\"."
5c4e30ca
DC
251gdb_test "ptype C" "type = namespace C::C"
252gdb_test "ptype E" "type = namespace C::D::E"
1fcb5155 253
c203e0ca
MC
254gdb_test "ptype CClass" "type = (class C::CClass \{\r\n public:|struct C::CClass \{)\r\n int x;\r\n\}"
255gdb_test "ptype CClass::NestedClass" "type = (class C::CClass::NestedClass \{\r\n public:|struct C::CClass::NestedClass \{)\r\n int y;\r\n\}"
63d06c5c 256gdb_test "ptype NestedClass" "No symbol \"NestedClass\" in current context."
63d06c5c 257gdb_test "ptype ::C::CClass" "type = class C::CClass \{\r\n public:\r\n int x;\r\n\}"
63d06c5c 258gdb_test "ptype ::C::CClass::NestedClass" "type = class C::CClass::NestedClass \{\r\n public:\r\n int y;\r\n\}"
63d06c5c
DC
259gdb_test "ptype ::C::NestedClass" "No symbol \"NestedClass\" in namespace \"C\"."
260gdb_test "ptype C::CClass" "No symbol \"CClass\" in namespace \"C::C\"."
261gdb_test "ptype C::CClass::NestedClass" "No type \"CClass\" within class or namespace \"C::C\"."
262gdb_test "ptype C::NestedClass" "No symbol \"NestedClass\" in namespace \"C::C\"."
263
264# Tests involving multiple files
265
266gdb_test "print cOtherFile" "\\$\[0-9\].* = 316"
41f62f39
JK
267gdb_test "ptype OtherFileClass" "type = (class C::OtherFileClass \{\r\n public:|struct C::OtherFileClass \{)\r\n int z;\r\n.*\}"
268gdb_test "ptype ::C::OtherFileClass" "type = class C::OtherFileClass \{\r\n public:\r\n int z;\r\n.*\}"
63d06c5c
DC
269gdb_test "ptype C::OtherFileClass" "No symbol \"OtherFileClass\" in namespace \"C::C\"."
270
98751a41
JK
271# Test class typedefs printing.
272set expect "type = class C::OtherFileClass \{\r\n.*\r\n *typedef short cOtherFileClassType;\r\n *typedef long cOtherFileClassType2;\r\n\}"
273if {[test_compiler_info {gcc-[0-3]-*}]
274 || [test_compiler_info {gcc-4-[0-4]-*}]} {
275 # The type in class is missing in older GCCs.
276 setup_xfail *-*-*
277}
278gdb_test "ptype OtherFileClass" $expect "ptype OtherFileClass typedefs"
279if {[test_compiler_info {gcc-[0-3]-*}]
280 || [test_compiler_info {gcc-4-[0-4]-*}]} {
281 # The type in class is missing in older GCCs.
282 setup_xfail *-*-*
283}
284gdb_test "ptype ::C::OtherFileClass" $expect "ptype ::C::OtherFileClass typedefs"
285
1fcb5155
DC
286# Some anonymous namespace tests.
287
288gdb_test "print cX" "\\$\[0-9\].* = 6"
289gdb_test "print 'F::cXf'" "\\$\[0-9\].* = 7"
79c2c32d
DC
290gdb_test "print F::cXf" "\\$\[0-9\].* = 7"
291gdb_test "print F::cXfX" "\\$\[0-9\].* = 8"
1fcb5155
DC
292gdb_test "print X" "\\$\[0-9\].* = 9"
293gdb_test "print 'G::Xg'" "\\$\[0-9\].* = 10"
79c2c32d
DC
294gdb_test "print G::Xg" "\\$\[0-9\].* = 10"
295gdb_test "print G::XgX" "\\$\[0-9\].* = 11"
1fcb5155
DC
296gdb_test "print cXOtherFile" "No symbol \"cXOtherFile\" in current context."
297gdb_test "print XOtherFile" "No symbol \"XOtherFile\" in current context."
ceeb3d5a
TT
298
299# Enum tests.
300gdb_test "print AAA::ALPHA" "\\$\[0-9\].* = AAA::ALPHA"
48e32051
TT
301
302# Regression tests for PR 9496.
303gdb_test "whatis ::C::CClass::NestedClass" "type = C::CClass::NestedClass"
304gdb_test "whatis ::C::CClass::NestedClass *" "type = C::CClass::NestedClass \\*"
This page took 1.016146 seconds and 4 git commands to generate.