OSDN Git Service

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