Commit | Line | Data |
---|---|---|
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 | ||
28 | if $tracelevel then { | |
29 | strace $tracelevel | |
30 | } | |
31 | ||
32 | set prms_id 0 | |
33 | set bug_id 0 | |
34 | ||
fc33412a | 35 | if { [skip_cplus_tests] } { continue } |
e6d71bf3 DB |
36 | |
37 | set testfile "namespace" | |
38 | set srcfile ${testfile}.cc | |
1fcb5155 DC |
39 | set objfile ${objdir}/${subdir}/${testfile}.o |
40 | set srcfile1 ${testfile}1.cc | |
41 | set objfile1 ${objdir}/${subdir}/${testfile}1.o | |
e6d71bf3 DB |
42 | set binfile ${objdir}/${subdir}/${testfile} |
43 | ||
753ccc7a | 44 | if [get_compiler_info ${binfile} c++] { |
e6d71bf3 DB |
45 | return -1; |
46 | } | |
47 | ||
1fcb5155 | 48 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${objfile}" object {debug c++}] != "" } { |
b60f0898 JB |
49 | untested namespace.exp |
50 | return -1 | |
e6d71bf3 DB |
51 | } |
52 | ||
1fcb5155 | 53 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${objfile1}" object {debug c++}] != "" } { |
b60f0898 JB |
54 | untested namespace.exp |
55 | return -1 | |
1fcb5155 | 56 | } |
e6d71bf3 | 57 | |
1fcb5155 | 58 | if { [gdb_compile "${objfile} ${objfile1}" "${binfile}" executable {debug c++}] != "" } { |
b60f0898 JB |
59 | untested namespace.exp |
60 | return -1 | |
1fcb5155 | 61 | } |
e6d71bf3 DB |
62 | |
63 | gdb_exit | |
64 | gdb_start | |
65 | gdb_reinitialize_dir $srcdir/$subdir | |
66 | gdb_load ${binfile} | |
67 | ||
68 | ||
69 | # | |
70 | # set it up at a breakpoint so we can play with the variable values | |
71 | # | |
72 | if ![runto_main] then { | |
73 | perror "couldn't run to breakpoint" | |
74 | continue | |
75 | } | |
76 | ||
db144853 MC |
77 | if ![runto 'marker1'] then { |
78 | perror "couldn't run to marker1" | |
79 | continue | |
80 | } | |
81 | ||
82 | gdb_test "up" ".*main.*" "up from marker1" | |
e6d71bf3 DB |
83 | |
84 | # Access a data item inside a namespace using colons and | |
63d06c5c | 85 | # single quotes. :-( |
e6d71bf3 | 86 | |
79c2c32d DC |
87 | # NOTE: carlton/2003-09-24: the quotes are becoming less necessary (or |
88 | # even desirable.) For tests where it should still work with quotes, | |
89 | # I'm including versions both with and without quotes; for tests that | |
90 | # shouldn't work with quotes, I'm only including one version. | |
91 | ||
e6d71bf3 DB |
92 | send_gdb "print 'AAA::c'\n" |
93 | gdb_expect { | |
7b2ac63b | 94 | -re "\\$\[0-9\]* = 0 '\\\\(0|000)'\r\n$gdb_prompt $" { pass "print 'AAA::c'" } |
e6d71bf3 DB |
95 | -re ".*$gdb_prompt $" { fail "print 'AAA::c'" } |
96 | timeout { fail "(timeout) print 'AAA::c'" } | |
97 | } | |
98 | ||
79c2c32d DC |
99 | send_gdb "print AAA::c\n" |
100 | gdb_expect { | |
101 | -re "\\$\[0-9\]* = 0 '\\\\(0|000)'\r\n$gdb_prompt $" { pass "print AAA::c" } | |
102 | -re ".*$gdb_prompt $" { fail "print AAA::c" } | |
103 | timeout { fail "(timeout) print AAA::c" } | |
104 | } | |
105 | ||
e6d71bf3 DB |
106 | # An object declared using "using". |
107 | ||
108 | send_gdb "print ina\n" | |
109 | gdb_expect { | |
110 | -re "\\$\[0-9\]+ = {xx = 33}.*$gdb_prompt $" { | |
111 | pass "print ina" | |
112 | } | |
113 | -re ".*$gdb_prompt $" { fail "print ina" } | |
114 | timeout { fail "(timeout) print ina" } | |
115 | } | |
116 | ||
117 | send_gdb "ptype ina\n" | |
118 | gdb_expect { | |
119 | -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 $" { | |
120 | pass "ptype ina" | |
121 | } | |
d231d0b1 MC |
122 | -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 $" { |
123 | pass "ptype ina" | |
124 | } | |
e6d71bf3 DB |
125 | -re ".*$gdb_prompt $" { fail "ptype ina" } |
126 | timeout { fail "(timeout) ptype ina" } | |
127 | } | |
128 | ||
129 | # Check all functions are known to GDB | |
130 | ||
131 | setup_xfail hppa*-*-*11* CLLbs14869 | |
132 | send_gdb "info func xyzq\n" | |
133 | gdb_expect { | |
134 | -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 $" { | |
135 | pass "info func xyzq" | |
136 | } | |
5178b9d6 DJ |
137 | -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 $" { |
138 | pass "info func xyzq" | |
139 | } | |
e6d71bf3 DB |
140 | -re ".*$gdb_prompt $" { fail "info func xyzq" } |
141 | timeout { fail "(timeout) info func xyzq" } | |
142 | } | |
143 | ||
144 | # Call a function in a namespace | |
145 | ||
146 | send_gdb "print 'AAA::xyzq'('x')\n" | |
147 | gdb_expect { | |
148 | -re "\\$\[0-9\]* = 97 'a'\r\n$gdb_prompt $" { | |
149 | pass "print 'AAA::xyzq'('x')" | |
150 | } | |
151 | -re ".*$gdb_prompt $" { fail "print 'AAA::xyzq'('x')" } | |
152 | timeout { fail "(timeout) print 'AAA::xyzq'('x')" } | |
153 | } | |
154 | ||
79c2c32d DC |
155 | send_gdb "print AAA::xyzq('x')\n" |
156 | gdb_expect { | |
157 | -re "\\$\[0-9\]* = 97 'a'\r\n$gdb_prompt $" { | |
158 | pass "print AAA::xyzq('x')" | |
159 | } | |
160 | -re ".*$gdb_prompt $" { fail "print AAA::xyzq('x')" } | |
161 | timeout { fail "(timeout) print AAA::xyzq('x')" } | |
162 | } | |
163 | ||
e6d71bf3 DB |
164 | # Break on a function in a namespace |
165 | ||
b598bfda | 166 | gdb_test "break AAA::xyzq" \ |
ceeb3d5a | 167 | "Breakpoint.*at $hex: file.*namespace.cc, line 47\\." |
e6d71bf3 DB |
168 | |
169 | # Call a function in a nested namespace | |
170 | ||
171 | send_gdb "print 'BBB::CCC::xyzq'('x')\n" | |
172 | gdb_expect { | |
173 | -re "\\$\[0-9\]* = 122 'z'\r\n$gdb_prompt $" { | |
174 | pass "print 'BBB::CCC::xyzq'('x')" | |
175 | } | |
176 | -re ".*$gdb_prompt $" { fail "print 'BBB::CCC::xyzq'('x')" } | |
177 | timeout { fail "(timeout) print 'BBB::CCC::xyzq'('x')" } | |
178 | } | |
179 | ||
79c2c32d DC |
180 | send_gdb "print BBB::CCC::xyzq('x')\n" |
181 | gdb_expect { | |
182 | -re "\\$\[0-9\]* = 122 'z'\r\n$gdb_prompt $" { | |
183 | pass "print BBB::CCC::xyzq('x')" | |
184 | } | |
185 | -re ".*$gdb_prompt $" { fail "print BBB::CCC::xyzq('x')" } | |
186 | timeout { fail "(timeout) print BBB::CCC::xyzq('x')" } | |
187 | } | |
188 | ||
e6d71bf3 DB |
189 | # Break on a function in a nested namespace |
190 | ||
b598bfda | 191 | gdb_test "break BBB::CCC::xyzq" \ |
ceeb3d5a | 192 | "Breakpoint.*at $hex: file.*namespace.cc, line 63\\." |
e6d71bf3 DB |
193 | |
194 | # Print address of a function in a class in a namespace | |
195 | ||
196 | send_gdb "print 'BBB::Class::xyzq'\n" | |
197 | gdb_expect { | |
1bc05c3a | 198 | -re "\\$\[0-9\]* = \{char \\((BBB::|)Class \\*( const|), (char|int)\\)\} $hex <BBB::Class::xyzq\\(char\\)>\r\n$gdb_prompt $" { |
a773d1cd | 199 | pass "print 'BBB::Class::xyzq'" |
e6d71bf3 | 200 | } |
a773d1cd MS |
201 | -re ".*$gdb_prompt $" { fail "print 'BBB::Class::xyzq'" } |
202 | timeout { fail "(timeout) print 'BBB::Class::xyzq'" } | |
e6d71bf3 DB |
203 | } |
204 | ||
63d06c5c DC |
205 | send_gdb "print BBB::Class::xyzq\n" |
206 | gdb_expect { | |
207 | -re "\\$\[0-9\]* = \{char \\((BBB::|)Class \\*( const|), (char|int)\\)\} $hex <BBB::Class::xyzq\\(char\\)>\r\n$gdb_prompt $" { | |
208 | pass "print BBB::Class::xyzq" | |
209 | } | |
210 | -re ".*$gdb_prompt $" { fail "print BBB::Class::xyzq" } | |
211 | timeout { fail "(timeout) print BBB::Class::xyzq" } | |
212 | } | |
213 | ||
e6d71bf3 DB |
214 | # Break on a function in a class in a namespace |
215 | ||
b598bfda | 216 | gdb_test "break BBB::Class::xyzq" \ |
ceeb3d5a | 217 | "Breakpoint.*at $hex: file.*namespace.cc, line 68\\." |
e6d71bf3 | 218 | |
1fcb5155 DC |
219 | # Test to see if the appropriate namespaces are in scope when trying |
220 | # to print out stuff from within a function defined within a | |
221 | # namespace. | |
222 | ||
223 | if ![runto "C::D::marker2"] then { | |
224 | perror "couldn't run to marker2" | |
225 | continue | |
226 | } | |
227 | ||
228 | gdb_test "print c" "\\$\[0-9\].* = 1" | |
229 | gdb_test "print cc" "No symbol \"cc\" in current context." | |
230 | gdb_test "print 'C::cc'" "\\$\[0-9\].* = 2" | |
79c2c32d | 231 | gdb_test "print C::cc" "\\$\[0-9\].* = 2" |
1fcb5155 | 232 | gdb_test "print cd" "\\$\[0-9\].* = 3" |
63d06c5c | 233 | gdb_test "print C::D::cd" "No type \"D\" within class or namespace \"C::C\"." |
1fcb5155 | 234 | gdb_test "print 'E::cde'" "\\$\[0-9\].* = 5" |
79c2c32d | 235 | gdb_test "print E::cde" "\\$\[0-9\].* = 5" |
1fcb5155 | 236 | gdb_test "print shadow" "\\$\[0-9\].* = 13" |
79c2c32d | 237 | gdb_test "print E::ce" "No symbol \"ce\" in namespace \"C::D::E\"." |
5c4e30ca DC |
238 | gdb_test "ptype C" "type = namespace C::C" |
239 | gdb_test "ptype E" "type = namespace C::D::E" | |
1fcb5155 | 240 | |
c203e0ca MC |
241 | gdb_test "ptype CClass" "type = (class C::CClass \{\r\n public:|struct C::CClass \{)\r\n int x;\r\n\}" |
242 | gdb_test "ptype CClass::NestedClass" "type = (class C::CClass::NestedClass \{\r\n public:|struct C::CClass::NestedClass \{)\r\n int y;\r\n\}" | |
63d06c5c DC |
243 | gdb_test "ptype NestedClass" "No symbol \"NestedClass\" in current context." |
244 | setup_kfail "gdb/1448" "*-*-*" | |
245 | gdb_test "ptype ::C::CClass" "type = class C::CClass \{\r\n public:\r\n int x;\r\n\}" | |
246 | setup_kfail "gdb/1448" "*-*-*" | |
247 | gdb_test "ptype ::C::CClass::NestedClass" "type = class C::CClass::NestedClass \{\r\n public:\r\n int y;\r\n\}" | |
248 | setup_kfail "gdb/1448" "*-*-*" | |
249 | gdb_test "ptype ::C::NestedClass" "No symbol \"NestedClass\" in namespace \"C\"." | |
250 | gdb_test "ptype C::CClass" "No symbol \"CClass\" in namespace \"C::C\"." | |
251 | gdb_test "ptype C::CClass::NestedClass" "No type \"CClass\" within class or namespace \"C::C\"." | |
252 | gdb_test "ptype C::NestedClass" "No symbol \"NestedClass\" in namespace \"C::C\"." | |
253 | ||
254 | # Tests involving multiple files | |
255 | ||
256 | gdb_test "print cOtherFile" "\\$\[0-9\].* = 316" | |
c203e0ca | 257 | gdb_test "ptype OtherFileClass" "type = (class C::OtherFileClass \{\r\n public:|struct C::OtherFileClass \{)\r\n int z;\r\n\}" |
63d06c5c DC |
258 | setup_kfail "gdb/1448" "*-*-*" |
259 | gdb_test "ptype ::C::OtherFileClass" "type = class C::OtherFileClass \{\r\n public:\r\n int z;\r\n\}" | |
260 | gdb_test "ptype C::OtherFileClass" "No symbol \"OtherFileClass\" in namespace \"C::C\"." | |
261 | ||
1fcb5155 DC |
262 | # Some anonymous namespace tests. |
263 | ||
264 | gdb_test "print cX" "\\$\[0-9\].* = 6" | |
265 | gdb_test "print 'F::cXf'" "\\$\[0-9\].* = 7" | |
79c2c32d DC |
266 | gdb_test "print F::cXf" "\\$\[0-9\].* = 7" |
267 | gdb_test "print F::cXfX" "\\$\[0-9\].* = 8" | |
1fcb5155 DC |
268 | gdb_test "print X" "\\$\[0-9\].* = 9" |
269 | gdb_test "print 'G::Xg'" "\\$\[0-9\].* = 10" | |
79c2c32d DC |
270 | gdb_test "print G::Xg" "\\$\[0-9\].* = 10" |
271 | gdb_test "print G::XgX" "\\$\[0-9\].* = 11" | |
1fcb5155 DC |
272 | gdb_test "print cXOtherFile" "No symbol \"cXOtherFile\" in current context." |
273 | gdb_test "print XOtherFile" "No symbol \"XOtherFile\" in current context." | |
ceeb3d5a TT |
274 | |
275 | # Enum tests. | |
276 | gdb_test "print AAA::ALPHA" "\\$\[0-9\].* = AAA::ALPHA" |