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