Commit | Line | Data |
---|---|---|
0b302171 JB |
1 | # Copyright 1997-1998, 2000-2004, 2007-2012 Free Software Foundation, |
2 | # 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 | ||
e6d71bf3 | 28 | |
fc33412a | 29 | if { [skip_cplus_tests] } { continue } |
e6d71bf3 DB |
30 | |
31 | set testfile "namespace" | |
32 | set srcfile ${testfile}.cc | |
1fcb5155 DC |
33 | set objfile ${objdir}/${subdir}/${testfile}.o |
34 | set srcfile1 ${testfile}1.cc | |
35 | set objfile1 ${objdir}/${subdir}/${testfile}1.o | |
e6d71bf3 DB |
36 | set binfile ${objdir}/${subdir}/${testfile} |
37 | ||
753ccc7a | 38 | if [get_compiler_info ${binfile} c++] { |
e6d71bf3 DB |
39 | return -1; |
40 | } | |
41 | ||
e9ea2662 JK |
42 | set xfail_class_types 0 |
43 | if {[test_compiler_info {gcc-[0-3]-*}] | |
44 | || [test_compiler_info {gcc-4-[0-4]-*}]} { | |
45 | # The type in class is missing in older GCCs. | |
46 | set xfail_class_types 1 | |
47 | } | |
48 | ||
1fcb5155 | 49 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${objfile}" object {debug c++}] != "" } { |
b60f0898 JB |
50 | untested namespace.exp |
51 | return -1 | |
e6d71bf3 DB |
52 | } |
53 | ||
1fcb5155 | 54 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${objfile1}" object {debug c++}] != "" } { |
b60f0898 JB |
55 | untested namespace.exp |
56 | return -1 | |
1fcb5155 | 57 | } |
e6d71bf3 | 58 | |
1fcb5155 | 59 | if { [gdb_compile "${objfile} ${objfile1}" "${binfile}" executable {debug c++}] != "" } { |
b60f0898 JB |
60 | untested namespace.exp |
61 | return -1 | |
1fcb5155 | 62 | } |
e6d71bf3 DB |
63 | |
64 | gdb_exit | |
65 | gdb_start | |
66 | gdb_reinitialize_dir $srcdir/$subdir | |
67 | gdb_load ${binfile} | |
68 | ||
69 | ||
70 | # | |
71 | # set it up at a breakpoint so we can play with the variable values | |
72 | # | |
73 | if ![runto_main] then { | |
74 | perror "couldn't run to breakpoint" | |
75 | continue | |
76 | } | |
77 | ||
db144853 MC |
78 | if ![runto 'marker1'] then { |
79 | perror "couldn't run to marker1" | |
80 | continue | |
81 | } | |
82 | ||
83 | gdb_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 | ||
f8d3bf8f MS |
93 | gdb_test "print 'AAA::c'" \ |
94 | "\\$\[0-9\]* = 0 '\\\\(0|000)'" \ | |
95 | "print 'AAA::c'" | |
e6d71bf3 | 96 | |
f8d3bf8f MS |
97 | gdb_test "print AAA::c" \ |
98 | "\\$\[0-9\]* = 0 '\\\\(0|000)'" \ | |
99 | "print AAA::c" | |
79c2c32d | 100 | |
e6d71bf3 DB |
101 | # An object declared using "using". |
102 | ||
f8d3bf8f | 103 | gdb_test "print ina" "\\$\[0-9\]+ = {xx = 33}" |
e6d71bf3 | 104 | |
f8d3bf8f MS |
105 | gdb_test_multiple "ptype ina" "ptype ina" { |
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 | } | |
109 | -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 $" { | |
110 | pass "ptype ina" | |
111 | } | |
e6d71bf3 DB |
112 | } |
113 | ||
114 | # Check all functions are known to GDB | |
115 | ||
116 | setup_xfail hppa*-*-*11* CLLbs14869 | |
f8d3bf8f MS |
117 | gdb_test_multiple "info func xyzq" "info func xyzq" { |
118 | -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 $" { | |
119 | pass "info func xyzq" | |
120 | } | |
121 | -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 $" { | |
122 | pass "info func xyzq" | |
123 | } | |
e6d71bf3 DB |
124 | } |
125 | ||
126 | # Call a function in a namespace | |
127 | ||
f8d3bf8f MS |
128 | gdb_test "print 'AAA::xyzq'('x')" \ |
129 | "\\$\[0-9\]* = 97 'a'" \ | |
130 | "print 'AAA::xyzq'('x')" | |
131 | ||
132 | gdb_test "print AAA::xyzq('x')" \ | |
133 | "\\$\[0-9\]* = 97 'a'" \ | |
134 | "print AAA::xyzq('x')" | |
79c2c32d | 135 | |
e6d71bf3 DB |
136 | # Break on a function in a namespace |
137 | ||
b598bfda | 138 | gdb_test "break AAA::xyzq" \ |
ceeb3d5a | 139 | "Breakpoint.*at $hex: file.*namespace.cc, line 47\\." |
e6d71bf3 | 140 | |
0e4acfcc KS |
141 | # Break on a function in the global namespace. |
142 | ||
143 | gdb_test "break ::ensureOtherRefs" \ | |
144 | "Breakpoint.*at $hex: file.*$srcfile1, line $decimal\\." | |
145 | ||
e6d71bf3 DB |
146 | # Call a function in a nested namespace |
147 | ||
f8d3bf8f MS |
148 | gdb_test "print 'BBB::CCC::xyzq'('x')" \ |
149 | "\\$\[0-9\]* = 122 'z'" \ | |
150 | "print 'BBB::CCC::xyzq'('x')" | |
151 | ||
152 | gdb_test "print BBB::CCC::xyzq('x')" \ | |
153 | "\\$\[0-9\]* = 122 'z'" \ | |
154 | "print BBB::CCC::xyzq('x')" | |
79c2c32d | 155 | |
e6d71bf3 DB |
156 | # Break on a function in a nested namespace |
157 | ||
b598bfda | 158 | gdb_test "break BBB::CCC::xyzq" \ |
ceeb3d5a | 159 | "Breakpoint.*at $hex: file.*namespace.cc, line 63\\." |
e6d71bf3 | 160 | |
0e4acfcc KS |
161 | # Break on the same function, starting with the global namespace. |
162 | ||
163 | gdb_test "break ::BBB::CCC::xyzq" \ | |
164 | ".*Breakpoint.*at $hex: file.*$srcfile, line 63\\." | |
165 | ||
e6d71bf3 DB |
166 | # Print address of a function in a class in a namespace |
167 | ||
f8d3bf8f MS |
168 | gdb_test "print 'BBB::Class::xyzq'" \ |
169 | "\\$\[0-9\]* = \{char \\((BBB::|)Class \\*( const|), (char|int)\\)\} $hex <BBB::Class::xyzq\\(char\\)>" \ | |
170 | "print 'BBB::Class::xyzq'" | |
e6d71bf3 | 171 | |
f8d3bf8f MS |
172 | gdb_test "print BBB::Class::xyzq" \ |
173 | "\\$\[0-9\]* = \{char \\((BBB::|)Class \\*( const|), (char|int)\\)\} $hex <BBB::Class::xyzq\\(char\\)>" \ | |
174 | "print BBB::Class::xyzq" | |
63d06c5c | 175 | |
e6d71bf3 DB |
176 | # Break on a function in a class in a namespace |
177 | ||
b598bfda | 178 | gdb_test "break BBB::Class::xyzq" \ |
ceeb3d5a | 179 | "Breakpoint.*at $hex: file.*namespace.cc, line 68\\." |
e6d71bf3 | 180 | |
41f62f39 JK |
181 | # Tests accessing static elements in namespace of other file. |
182 | ||
183 | gdb_test "whatis C::cOtherFileType" "type = short" | |
184 | gdb_test "whatis ::C::cOtherFileType" "type = short" | |
185 | gdb_test "whatis C::cOtherFileVar" "type = const C::cOtherFileType" | |
186 | gdb_test "whatis ::C::cOtherFileVar" "type = const C::cOtherFileType" | |
187 | gdb_test "print C::cOtherFileVar" "\\$\[0-9\].* = 319" | |
188 | gdb_test "print ::C::cOtherFileVar" "\\$\[0-9\].* = 319" | |
189 | ||
e9ea2662 | 190 | if $xfail_class_types { setup_xfail *-*-* } |
41f62f39 | 191 | gdb_test "whatis C::OtherFileClass::cOtherFileClassType" "type = short" |
e9ea2662 | 192 | if $xfail_class_types { setup_xfail *-*-* } |
41f62f39 | 193 | gdb_test "whatis ::C::OtherFileClass::cOtherFileClassType" "type = short" |
0a600c36 | 194 | gdb_test "print C::OtherFileClass::cOtherFileClassVar" " = 318" |
41f62f39 JK |
195 | |
196 | # FSF GCC <=4.4 creates unqualified DIE "cOtherFileClassVar" ignoring the | |
197 | # namespace the same way older GDB did. | |
198 | set test "print ::cOtherFileClassVar" | |
199 | set test2 "print ::C::OtherFileClass::cOtherFileClassVar" | |
200 | gdb_test_multiple $test $test { | |
201 | -re "No symbol \"cOtherFileClassVar\" in current context\\.\r\n$gdb_prompt $" { | |
202 | pass $test | |
203 | ||
0a600c36 | 204 | gdb_test $test2 " = 318" |
41f62f39 JK |
205 | } |
206 | -re "\\$\[0-9\].* = 318\r\n$gdb_prompt $" { | |
49c3ccf7 | 207 | # Do not permit to XFAIL on recent GCCs. |
e9ea2662 | 208 | if $xfail_class_types { |
41f62f39 | 209 | setup_xfail *-*-* |
49c3ccf7 DE |
210 | fail $test |
211 | # Unresolved means human intervention is required to determine | |
212 | # whether the test passed or failed. Since the previous test | |
213 | # xfailed (not failed) human intervention isn't going to help here. | |
214 | # Thus test2 is marked as unsupported instead of unresolved. | |
215 | unsupported $test2 | |
216 | } else { | |
217 | fail $test | |
218 | unresolved $test2 | |
41f62f39 | 219 | } |
41f62f39 JK |
220 | } |
221 | } | |
222 | ||
1fcb5155 DC |
223 | # Test to see if the appropriate namespaces are in scope when trying |
224 | # to print out stuff from within a function defined within a | |
225 | # namespace. | |
226 | ||
227 | if ![runto "C::D::marker2"] then { | |
228 | perror "couldn't run to marker2" | |
229 | continue | |
230 | } | |
231 | ||
232 | gdb_test "print c" "\\$\[0-9\].* = 1" | |
233 | gdb_test "print cc" "No symbol \"cc\" in current context." | |
234 | gdb_test "print 'C::cc'" "\\$\[0-9\].* = 2" | |
79c2c32d | 235 | gdb_test "print C::cc" "\\$\[0-9\].* = 2" |
1fcb5155 | 236 | gdb_test "print cd" "\\$\[0-9\].* = 3" |
63d06c5c | 237 | gdb_test "print C::D::cd" "No type \"D\" within class or namespace \"C::C\"." |
1fcb5155 | 238 | gdb_test "print 'E::cde'" "\\$\[0-9\].* = 5" |
79c2c32d | 239 | gdb_test "print E::cde" "\\$\[0-9\].* = 5" |
1fcb5155 | 240 | gdb_test "print shadow" "\\$\[0-9\].* = 13" |
79c2c32d | 241 | gdb_test "print E::ce" "No symbol \"ce\" in namespace \"C::D::E\"." |
5c4e30ca DC |
242 | gdb_test "ptype C" "type = namespace C::C" |
243 | gdb_test "ptype E" "type = namespace C::D::E" | |
1fcb5155 | 244 | |
c203e0ca MC |
245 | gdb_test "ptype CClass" "type = (class C::CClass \{\r\n public:|struct C::CClass \{)\r\n int x;\r\n\}" |
246 | gdb_test "ptype CClass::NestedClass" "type = (class C::CClass::NestedClass \{\r\n public:|struct C::CClass::NestedClass \{)\r\n int y;\r\n\}" | |
63d06c5c | 247 | gdb_test "ptype NestedClass" "No symbol \"NestedClass\" in current context." |
63d06c5c | 248 | gdb_test "ptype ::C::CClass" "type = class C::CClass \{\r\n public:\r\n int x;\r\n\}" |
63d06c5c | 249 | gdb_test "ptype ::C::CClass::NestedClass" "type = class C::CClass::NestedClass \{\r\n public:\r\n int y;\r\n\}" |
63d06c5c DC |
250 | gdb_test "ptype ::C::NestedClass" "No symbol \"NestedClass\" in namespace \"C\"." |
251 | gdb_test "ptype C::CClass" "No symbol \"CClass\" in namespace \"C::C\"." | |
252 | gdb_test "ptype C::CClass::NestedClass" "No type \"CClass\" within class or namespace \"C::C\"." | |
253 | gdb_test "ptype C::NestedClass" "No symbol \"NestedClass\" in namespace \"C::C\"." | |
254 | ||
255 | # Tests involving multiple files | |
256 | ||
257 | gdb_test "print cOtherFile" "\\$\[0-9\].* = 316" | |
41f62f39 JK |
258 | gdb_test "ptype OtherFileClass" "type = (class C::OtherFileClass \{\r\n public:|struct C::OtherFileClass \{)\r\n int z;\r\n.*\}" |
259 | gdb_test "ptype ::C::OtherFileClass" "type = class C::OtherFileClass \{\r\n public:\r\n int z;\r\n.*\}" | |
63d06c5c DC |
260 | gdb_test "ptype C::OtherFileClass" "No symbol \"OtherFileClass\" in namespace \"C::C\"." |
261 | ||
98751a41 JK |
262 | # Test class typedefs printing. |
263 | set expect "type = class C::OtherFileClass \{\r\n.*\r\n *typedef short cOtherFileClassType;\r\n *typedef long cOtherFileClassType2;\r\n\}" | |
e9ea2662 | 264 | if $xfail_class_types { setup_xfail *-*-* } |
98751a41 | 265 | gdb_test "ptype OtherFileClass" $expect "ptype OtherFileClass typedefs" |
e9ea2662 | 266 | if $xfail_class_types { setup_xfail *-*-* } |
98751a41 JK |
267 | gdb_test "ptype ::C::OtherFileClass" $expect "ptype ::C::OtherFileClass typedefs" |
268 | ||
1fcb5155 DC |
269 | # Some anonymous namespace tests. |
270 | ||
271 | gdb_test "print cX" "\\$\[0-9\].* = 6" | |
272 | gdb_test "print 'F::cXf'" "\\$\[0-9\].* = 7" | |
79c2c32d DC |
273 | gdb_test "print F::cXf" "\\$\[0-9\].* = 7" |
274 | gdb_test "print F::cXfX" "\\$\[0-9\].* = 8" | |
1fcb5155 DC |
275 | gdb_test "print X" "\\$\[0-9\].* = 9" |
276 | gdb_test "print 'G::Xg'" "\\$\[0-9\].* = 10" | |
79c2c32d DC |
277 | gdb_test "print G::Xg" "\\$\[0-9\].* = 10" |
278 | gdb_test "print G::XgX" "\\$\[0-9\].* = 11" | |
1fcb5155 DC |
279 | gdb_test "print cXOtherFile" "No symbol \"cXOtherFile\" in current context." |
280 | gdb_test "print XOtherFile" "No symbol \"XOtherFile\" in current context." | |
ceeb3d5a TT |
281 | |
282 | # Enum tests. | |
283 | gdb_test "print AAA::ALPHA" "\\$\[0-9\].* = AAA::ALPHA" | |
48e32051 TT |
284 | |
285 | # Regression tests for PR 9496. | |
286 | gdb_test "whatis ::C::CClass::NestedClass" "type = C::CClass::NestedClass" | |
287 | gdb_test "whatis ::C::CClass::NestedClass *" "type = C::CClass::NestedClass \\*" |