]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.cp/namespace.exp
Update year range in copyright notice of all files owned by the GDB project.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.cp / namespace.exp
CommitLineData
32d0add0 1# Copyright 1997-2015 Free Software Foundation, Inc.
e6d71bf3
DB
2
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
e22f8b7c 5# the Free Software Foundation; either version 3 of the License, or
e6d71bf3 6# (at your option) any later version.
e22f8b7c 7#
e6d71bf3
DB
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
e22f8b7c 12#
e6d71bf3 13# You should have received a copy of the GNU General Public License
e22f8b7c 14# along with this program. If not, see <http://www.gnu.org/licenses/>.
e6d71bf3 15
e6d71bf3 16# tests for namespaces
79c2c32d 17# Originally written by Satish Pai <pai@apollo.hp.com> 1997-07-23
e6d71bf3
DB
18
19# This file is part of the gdb testsuite
20
79c2c32d 21# Note: The original tests were geared to the HP aCC compiler,
e6d71bf3
DB
22# which has an idiosyncratic way of emitting debug info
23# for namespaces.
63d06c5c 24# Note: As of 2000-06-03, they passed under g++ - djb
e6d71bf3
DB
25
26
e6d71bf3 27
fc33412a 28if { [skip_cplus_tests] } { continue }
e6d71bf3 29
f5f3a911 30standard_testfile .cc namespace1.cc
e6d71bf3 31
4c93b1db 32if [get_compiler_info c++] {
ae59b1da 33 return -1
e6d71bf3
DB
34}
35
e9ea2662
JK
36set xfail_class_types 0
37if {[test_compiler_info {gcc-[0-3]-*}]
38 || [test_compiler_info {gcc-4-[0-4]-*}]} {
39 # The type in class is missing in older GCCs.
40 set xfail_class_types 1
41}
42
f5f3a911
TT
43if {[prepare_for_testing $testfile.exp $testfile \
44 [list $srcfile $srcfile2] {debug c++}]} {
45 return -1
e6d71bf3
DB
46}
47
663b969e 48gdb_test "show lang" "auto; currently c\\+\\+.*"
e6d71bf3
DB
49
50#
51# set it up at a breakpoint so we can play with the variable values
52#
53if ![runto_main] then {
54 perror "couldn't run to breakpoint"
55 continue
56}
57
db144853
MC
58if ![runto 'marker1'] then {
59 perror "couldn't run to marker1"
60 continue
61}
62
63gdb_test "up" ".*main.*" "up from marker1"
e6d71bf3
DB
64
65# Access a data item inside a namespace using colons and
63d06c5c 66# single quotes. :-(
e6d71bf3 67
79c2c32d
DC
68# NOTE: carlton/2003-09-24: the quotes are becoming less necessary (or
69# even desirable.) For tests where it should still work with quotes,
70# I'm including versions both with and without quotes; for tests that
71# shouldn't work with quotes, I'm only including one version.
72
f8d3bf8f
MS
73gdb_test "print 'AAA::c'" \
74 "\\$\[0-9\]* = 0 '\\\\(0|000)'" \
75 "print 'AAA::c'"
e6d71bf3 76
f8d3bf8f
MS
77gdb_test "print AAA::c" \
78 "\\$\[0-9\]* = 0 '\\\\(0|000)'" \
79 "print AAA::c"
79c2c32d 80
e6d71bf3
DB
81# An object declared using "using".
82
f8d3bf8f 83gdb_test "print ina" "\\$\[0-9\]+ = {xx = 33}"
e6d71bf3 84
f8d3bf8f
MS
85gdb_test_multiple "ptype ina" "ptype ina" {
86 -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 $" {
87 pass "ptype ina"
88 }
89 -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 $" {
90 pass "ptype ina"
91 }
e6d71bf3
DB
92}
93
94# Check all functions are known to GDB
95
96setup_xfail hppa*-*-*11* CLLbs14869
f8d3bf8f
MS
97gdb_test_multiple "info func xyzq" "info func xyzq" {
98 -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 $" {
99 pass "info func xyzq"
100 }
101 -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 $" {
102 pass "info func xyzq"
103 }
e6d71bf3
DB
104}
105
106# Call a function in a namespace
107
f8d3bf8f
MS
108gdb_test "print 'AAA::xyzq'('x')" \
109 "\\$\[0-9\]* = 97 'a'" \
110 "print 'AAA::xyzq'('x')"
111
112gdb_test "print AAA::xyzq('x')" \
113 "\\$\[0-9\]* = 97 'a'" \
114 "print AAA::xyzq('x')"
79c2c32d 115
e6d71bf3
DB
116# Break on a function in a namespace
117
b598bfda 118gdb_test "break AAA::xyzq" \
ceeb3d5a 119 "Breakpoint.*at $hex: file.*namespace.cc, line 47\\."
e6d71bf3 120
0e4acfcc
KS
121# Break on a function in the global namespace.
122
123gdb_test "break ::ensureOtherRefs" \
f5f3a911 124 "Breakpoint.*at $hex: file.*$srcfile2, line $decimal\\."
0e4acfcc 125
e6d71bf3
DB
126# Call a function in a nested namespace
127
f8d3bf8f
MS
128gdb_test "print 'BBB::CCC::xyzq'('x')" \
129 "\\$\[0-9\]* = 122 'z'" \
130 "print 'BBB::CCC::xyzq'('x')"
131
132gdb_test "print BBB::CCC::xyzq('x')" \
133 "\\$\[0-9\]* = 122 'z'" \
134 "print BBB::CCC::xyzq('x')"
79c2c32d 135
e6d71bf3
DB
136# Break on a function in a nested namespace
137
b598bfda 138gdb_test "break BBB::CCC::xyzq" \
ceeb3d5a 139 "Breakpoint.*at $hex: file.*namespace.cc, line 63\\."
e6d71bf3 140
0e4acfcc
KS
141# Break on the same function, starting with the global namespace.
142
143gdb_test "break ::BBB::CCC::xyzq" \
144 ".*Breakpoint.*at $hex: file.*$srcfile, line 63\\."
145
e6d71bf3
DB
146# Print address of a function in a class in a namespace
147
f8d3bf8f
MS
148gdb_test "print 'BBB::Class::xyzq'" \
149 "\\$\[0-9\]* = \{char \\((BBB::|)Class \\*( const|), (char|int)\\)\} $hex <BBB::Class::xyzq\\(char\\)>" \
150 "print 'BBB::Class::xyzq'"
e6d71bf3 151
f8d3bf8f
MS
152gdb_test "print BBB::Class::xyzq" \
153 "\\$\[0-9\]* = \{char \\((BBB::|)Class \\*( const|), (char|int)\\)\} $hex <BBB::Class::xyzq\\(char\\)>" \
154 "print BBB::Class::xyzq"
63d06c5c 155
e6d71bf3
DB
156# Break on a function in a class in a namespace
157
b598bfda 158gdb_test "break BBB::Class::xyzq" \
ceeb3d5a 159 "Breakpoint.*at $hex: file.*namespace.cc, line 68\\."
e6d71bf3 160
41f62f39
JK
161# Tests accessing static elements in namespace of other file.
162
163gdb_test "whatis C::cOtherFileType" "type = short"
164gdb_test "whatis ::C::cOtherFileType" "type = short"
165gdb_test "whatis C::cOtherFileVar" "type = const C::cOtherFileType"
166gdb_test "whatis ::C::cOtherFileVar" "type = const C::cOtherFileType"
167gdb_test "print C::cOtherFileVar" "\\$\[0-9\].* = 319"
168gdb_test "print ::C::cOtherFileVar" "\\$\[0-9\].* = 319"
169
e9ea2662 170if $xfail_class_types { setup_xfail *-*-* }
41f62f39 171gdb_test "whatis C::OtherFileClass::cOtherFileClassType" "type = short"
e9ea2662 172if $xfail_class_types { setup_xfail *-*-* }
41f62f39 173gdb_test "whatis ::C::OtherFileClass::cOtherFileClassType" "type = short"
0a600c36 174gdb_test "print C::OtherFileClass::cOtherFileClassVar" " = 318"
41f62f39
JK
175
176# FSF GCC <=4.4 creates unqualified DIE "cOtherFileClassVar" ignoring the
177# namespace the same way older GDB did.
178set test "print ::cOtherFileClassVar"
179set test2 "print ::C::OtherFileClass::cOtherFileClassVar"
180gdb_test_multiple $test $test {
181 -re "No symbol \"cOtherFileClassVar\" in current context\\.\r\n$gdb_prompt $" {
182 pass $test
183
0a600c36 184 gdb_test $test2 " = 318"
41f62f39
JK
185 }
186 -re "\\$\[0-9\].* = 318\r\n$gdb_prompt $" {
49c3ccf7 187 # Do not permit to XFAIL on recent GCCs.
e9ea2662 188 if $xfail_class_types {
41f62f39 189 setup_xfail *-*-*
49c3ccf7
DE
190 fail $test
191 # Unresolved means human intervention is required to determine
192 # whether the test passed or failed. Since the previous test
193 # xfailed (not failed) human intervention isn't going to help here.
194 # Thus test2 is marked as unsupported instead of unresolved.
195 unsupported $test2
196 } else {
197 fail $test
198 unresolved $test2
41f62f39 199 }
41f62f39
JK
200 }
201}
202
1fcb5155
DC
203# Test to see if the appropriate namespaces are in scope when trying
204# to print out stuff from within a function defined within a
205# namespace.
206
207if ![runto "C::D::marker2"] then {
208 perror "couldn't run to marker2"
209 continue
210}
211
212gdb_test "print c" "\\$\[0-9\].* = 1"
213gdb_test "print cc" "No symbol \"cc\" in current context."
214gdb_test "print 'C::cc'" "\\$\[0-9\].* = 2"
79c2c32d 215gdb_test "print C::cc" "\\$\[0-9\].* = 2"
1fcb5155 216gdb_test "print cd" "\\$\[0-9\].* = 3"
63d06c5c 217gdb_test "print C::D::cd" "No type \"D\" within class or namespace \"C::C\"."
1fcb5155 218gdb_test "print 'E::cde'" "\\$\[0-9\].* = 5"
79c2c32d 219gdb_test "print E::cde" "\\$\[0-9\].* = 5"
1fcb5155 220gdb_test "print shadow" "\\$\[0-9\].* = 13"
79c2c32d 221gdb_test "print E::ce" "No symbol \"ce\" in namespace \"C::D::E\"."
5c4e30ca
DC
222gdb_test "ptype C" "type = namespace C::C"
223gdb_test "ptype E" "type = namespace C::D::E"
1fcb5155 224
c203e0ca
MC
225gdb_test "ptype CClass" "type = (class C::CClass \{\r\n public:|struct C::CClass \{)\r\n int x;\r\n\}"
226gdb_test "ptype CClass::NestedClass" "type = (class C::CClass::NestedClass \{\r\n public:|struct C::CClass::NestedClass \{)\r\n int y;\r\n\}"
63d06c5c 227gdb_test "ptype NestedClass" "No symbol \"NestedClass\" in current context."
63d06c5c 228gdb_test "ptype ::C::CClass" "type = class C::CClass \{\r\n public:\r\n int x;\r\n\}"
63d06c5c 229gdb_test "ptype ::C::CClass::NestedClass" "type = class C::CClass::NestedClass \{\r\n public:\r\n int y;\r\n\}"
63d06c5c
DC
230gdb_test "ptype ::C::NestedClass" "No symbol \"NestedClass\" in namespace \"C\"."
231gdb_test "ptype C::CClass" "No symbol \"CClass\" in namespace \"C::C\"."
232gdb_test "ptype C::CClass::NestedClass" "No type \"CClass\" within class or namespace \"C::C\"."
233gdb_test "ptype C::NestedClass" "No symbol \"NestedClass\" in namespace \"C::C\"."
234
235# Tests involving multiple files
236
237gdb_test "print cOtherFile" "\\$\[0-9\].* = 316"
41f62f39
JK
238gdb_test "ptype OtherFileClass" "type = (class C::OtherFileClass \{\r\n public:|struct C::OtherFileClass \{)\r\n int z;\r\n.*\}"
239gdb_test "ptype ::C::OtherFileClass" "type = class C::OtherFileClass \{\r\n public:\r\n int z;\r\n.*\}"
63d06c5c
DC
240gdb_test "ptype C::OtherFileClass" "No symbol \"OtherFileClass\" in namespace \"C::C\"."
241
98751a41
JK
242# Test class typedefs printing.
243set expect "type = class C::OtherFileClass \{\r\n.*\r\n *typedef short cOtherFileClassType;\r\n *typedef long cOtherFileClassType2;\r\n\}"
e9ea2662 244if $xfail_class_types { setup_xfail *-*-* }
98751a41 245gdb_test "ptype OtherFileClass" $expect "ptype OtherFileClass typedefs"
e9ea2662 246if $xfail_class_types { setup_xfail *-*-* }
98751a41
JK
247gdb_test "ptype ::C::OtherFileClass" $expect "ptype ::C::OtherFileClass typedefs"
248
1fcb5155
DC
249# Some anonymous namespace tests.
250
251gdb_test "print cX" "\\$\[0-9\].* = 6"
252gdb_test "print 'F::cXf'" "\\$\[0-9\].* = 7"
79c2c32d
DC
253gdb_test "print F::cXf" "\\$\[0-9\].* = 7"
254gdb_test "print F::cXfX" "\\$\[0-9\].* = 8"
1fcb5155
DC
255gdb_test "print X" "\\$\[0-9\].* = 9"
256gdb_test "print 'G::Xg'" "\\$\[0-9\].* = 10"
79c2c32d
DC
257gdb_test "print G::Xg" "\\$\[0-9\].* = 10"
258gdb_test "print G::XgX" "\\$\[0-9\].* = 11"
1fcb5155
DC
259gdb_test "print cXOtherFile" "No symbol \"cXOtherFile\" in current context."
260gdb_test "print XOtherFile" "No symbol \"XOtherFile\" in current context."
ceeb3d5a
TT
261
262# Enum tests.
263gdb_test "print AAA::ALPHA" "\\$\[0-9\].* = AAA::ALPHA"
48e32051
TT
264
265# Regression tests for PR 9496.
266gdb_test "whatis ::C::CClass::NestedClass" "type = C::CClass::NestedClass"
267gdb_test "whatis ::C::CClass::NestedClass *" "type = C::CClass::NestedClass \\*"