2003-09-25 David Carlton <carlton@kealia.com>
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.cp / namespace.exp
1 # Copyright 1997, 1998, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
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
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
7 #
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.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
19
20 # tests for namespaces
21 # Originally written by Satish Pai <pai@apollo.hp.com> 1997-07-23
22
23 # This file is part of the gdb testsuite
24
25 # Note: The original tests were geared to the HP aCC compiler,
26 # which has an idiosyncratic way of emitting debug info
27 # for namespaces.
28 # Note: As of 2000-06-03, these pass under g++ - djb
29
30
31 if $tracelevel then {
32 strace $tracelevel
33 }
34
35 set prms_id 0
36 set bug_id 0
37
38 if { [skip_cplus_tests] } { continue }
39
40 set testfile "namespace"
41 set srcfile ${testfile}.cc
42 set objfile ${objdir}/${subdir}/${testfile}.o
43 set srcfile1 ${testfile}1.cc
44 set objfile1 ${objdir}/${subdir}/${testfile}1.o
45 set binfile ${objdir}/${subdir}/${testfile}
46
47 if [get_compiler_info ${binfile}] {
48 return -1;
49 }
50
51 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${objfile}" object {debug c++}] != "" } {
52 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
53 }
54
55 if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${objfile1}" object {debug c++}] != "" } {
56 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
57 }
58
59 if { [gdb_compile "${objfile} ${objfile1}" "${binfile}" executable {debug c++}] != "" } {
60 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
61 }
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
77 if ![runto 'marker1'] then {
78 perror "couldn't run to marker1"
79 continue
80 }
81
82 gdb_test "up" ".*main.*" "up from marker1"
83
84 # Access a data item inside a namespace using colons and
85 # single quotes :-(
86
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
92 send_gdb "print 'AAA::c'\n"
93 gdb_expect {
94 -re "\\$\[0-9\]* = 0 '\\\\(0|000)'\r\n$gdb_prompt $" { pass "print 'AAA::c'" }
95 -re ".*$gdb_prompt $" { fail "print 'AAA::c'" }
96 timeout { fail "(timeout) print 'AAA::c'" }
97 }
98
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
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 }
122 -re ".*$gdb_prompt $" { fail "ptype ina" }
123 timeout { fail "(timeout) ptype ina" }
124 }
125
126 # Check all functions are known to GDB
127
128 setup_xfail hppa*-*-*11* CLLbs14869
129 send_gdb "info func xyzq\n"
130 gdb_expect {
131 -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 $" {
132 pass "info func xyzq"
133 }
134 -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 $" {
135 pass "info func xyzq"
136 }
137 -re ".*$gdb_prompt $" { fail "info func xyzq" }
138 timeout { fail "(timeout) info func xyzq" }
139 }
140
141 # Call a function in a namespace
142
143 send_gdb "print 'AAA::xyzq'('x')\n"
144 gdb_expect {
145 -re "\\$\[0-9\]* = 97 'a'\r\n$gdb_prompt $" {
146 pass "print 'AAA::xyzq'('x')"
147 }
148 -re ".*$gdb_prompt $" { fail "print 'AAA::xyzq'('x')" }
149 timeout { fail "(timeout) print 'AAA::xyzq'('x')" }
150 }
151
152 send_gdb "print AAA::xyzq('x')\n"
153 gdb_expect {
154 -re "\\$\[0-9\]* = 97 'a'\r\n$gdb_prompt $" {
155 pass "print AAA::xyzq('x')"
156 }
157 -re ".*$gdb_prompt $" { fail "print AAA::xyzq('x')" }
158 timeout { fail "(timeout) print AAA::xyzq('x')" }
159 }
160
161 # Break on a function in a namespace
162
163 send_gdb "break AAA::xyzq\n"
164 gdb_expect {
165 -re "Breakpoint.*at $hex: file.*namespace.cc, line 42\\.\r\n$gdb_prompt $" {
166 pass "break AAA::xyzq"
167 }
168 -re ".*$gdb_prompt $" { fail "break AAA::xyzq" }
169 timeout { fail "(timeout) break AAA::xyzq" }
170 }
171
172 # Call a function in a nested namespace
173
174 send_gdb "print 'BBB::CCC::xyzq'('x')\n"
175 gdb_expect {
176 -re "\\$\[0-9\]* = 122 'z'\r\n$gdb_prompt $" {
177 pass "print 'BBB::CCC::xyzq'('x')"
178 }
179 -re ".*$gdb_prompt $" { fail "print 'BBB::CCC::xyzq'('x')" }
180 timeout { fail "(timeout) print 'BBB::CCC::xyzq'('x')" }
181 }
182
183 send_gdb "print BBB::CCC::xyzq('x')\n"
184 gdb_expect {
185 -re "\\$\[0-9\]* = 122 'z'\r\n$gdb_prompt $" {
186 pass "print BBB::CCC::xyzq('x')"
187 }
188 -re ".*$gdb_prompt $" { fail "print BBB::CCC::xyzq('x')" }
189 timeout { fail "(timeout) print BBB::CCC::xyzq('x')" }
190 }
191
192 # Break on a function in a nested namespace
193
194 send_gdb "break BBB::CCC::xyzq\n"
195 gdb_expect {
196 -re "Breakpoint.*at $hex: file.*namespace.cc, line 58\\.\r\n$gdb_prompt $" {
197 pass "break BBB::CCC::xyzq"
198 }
199 -re ".*$gdb_prompt $" { fail "break BBB::CCC::xyzq" }
200 timeout { fail "(timeout) break BBB::CCC::xyzq" }
201 }
202
203 # Print address of a function in a class in a namespace
204
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
214 # Break on a function in a class in a namespace
215
216 send_gdb "break BBB::Class::xyzq\n"
217 gdb_expect {
218 -re "Breakpoint.*at $hex: file.*namespace.cc, line 63\\.\r\n$gdb_prompt $" {
219 pass "break BBB::Class::xyzq"
220 }
221 -re ".*$gdb_prompt $" { fail "break BBB::Class::xyzq" }
222 timeout { fail "(timeout) break BBB::Class::xyzq" }
223 }
224
225 # Test to see if the appropriate namespaces are in scope when trying
226 # to print out stuff from within a function defined within a
227 # namespace.
228
229 if ![runto "C::D::marker2"] then {
230 perror "couldn't run to marker2"
231 continue
232 }
233
234 gdb_test "print c" "\\$\[0-9\].* = 1"
235 gdb_test "print cc" "No symbol \"cc\" in current context."
236 gdb_test "print 'C::cc'" "\\$\[0-9\].* = 2"
237 gdb_test "print C::cc" "\\$\[0-9\].* = 2"
238 gdb_test "print cd" "\\$\[0-9\].* = 3"
239 gdb_test "print C::D::cd" "No type \"D\" in namespace \"C::C\"."
240 gdb_test "print 'E::cde'" "\\$\[0-9\].* = 5"
241 gdb_test "print E::cde" "\\$\[0-9\].* = 5"
242 gdb_test "print shadow" "\\$\[0-9\].* = 13"
243 gdb_test "print E::ce" "No symbol \"ce\" in namespace \"C::D::E\"."
244 gdb_test "print cOtherFile" "\\$\[0-9\].* = 316"
245 gdb_test "ptype C" "type = namespace C::C"
246 gdb_test "ptype E" "type = namespace C::D::E"
247
248 # Some anonymous namespace tests.
249
250 gdb_test "print cX" "\\$\[0-9\].* = 6"
251 gdb_test "print 'F::cXf'" "\\$\[0-9\].* = 7"
252 gdb_test "print F::cXf" "\\$\[0-9\].* = 7"
253 gdb_test "print F::cXfX" "\\$\[0-9\].* = 8"
254 gdb_test "print X" "\\$\[0-9\].* = 9"
255 gdb_test "print 'G::Xg'" "\\$\[0-9\].* = 10"
256 gdb_test "print G::Xg" "\\$\[0-9\].* = 10"
257 gdb_test "print G::XgX" "\\$\[0-9\].* = 11"
258 gdb_test "print cXOtherFile" "No symbol \"cXOtherFile\" in current context."
259 gdb_test "print XOtherFile" "No symbol \"XOtherFile\" in current context."
This page took 0.034853 seconds and 4 git commands to generate.