2004-01-14 Elena Zannoni <ezannoni@redhat.com>
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.cp / namespace.exp
CommitLineData
d231d0b1
MC
1# Copyright 1997, 1998, 2000, 2001, 2002, 2003, 2004
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
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
79c2c32d 22# Originally written by Satish Pai <pai@apollo.hp.com> 1997-07-23
e6d71bf3
DB
23
24# This file is part of the gdb testsuite
25
79c2c32d 26# Note: The original tests were geared to the HP aCC compiler,
e6d71bf3
DB
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
32if $tracelevel then {
33 strace $tracelevel
34 }
35
36set prms_id 0
37set bug_id 0
38
fc33412a 39if { [skip_cplus_tests] } { continue }
e6d71bf3
DB
40
41set testfile "namespace"
42set srcfile ${testfile}.cc
1fcb5155
DC
43set objfile ${objdir}/${subdir}/${testfile}.o
44set srcfile1 ${testfile}1.cc
45set objfile1 ${objdir}/${subdir}/${testfile}1.o
e6d71bf3
DB
46set binfile ${objdir}/${subdir}/${testfile}
47
753ccc7a 48if [get_compiler_info ${binfile} c++] {
e6d71bf3
DB
49 return -1;
50}
51
1fcb5155
DC
52if { [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."
e6d71bf3
DB
54}
55
1fcb5155
DC
56if { [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}
e6d71bf3 59
1fcb5155
DC
60if { [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}
e6d71bf3
DB
63
64gdb_exit
65gdb_start
66gdb_reinitialize_dir $srcdir/$subdir
67gdb_load ${binfile}
68
69
70#
71# set it up at a breakpoint so we can play with the variable values
72#
73if ![runto_main] then {
74 perror "couldn't run to breakpoint"
75 continue
76}
77
db144853
MC
78if ![runto 'marker1'] then {
79 perror "couldn't run to marker1"
80 continue
81}
82
83gdb_test "up" ".*main.*" "up from marker1"
e6d71bf3
DB
84
85# Access a data item inside a namespace using colons and
86# single quotes :-(
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
e6d71bf3
DB
93send_gdb "print 'AAA::c'\n"
94gdb_expect {
7b2ac63b 95 -re "\\$\[0-9\]* = 0 '\\\\(0|000)'\r\n$gdb_prompt $" { pass "print 'AAA::c'" }
e6d71bf3
DB
96 -re ".*$gdb_prompt $" { fail "print 'AAA::c'" }
97 timeout { fail "(timeout) print 'AAA::c'" }
98}
99
79c2c32d
DC
100send_gdb "print AAA::c\n"
101gdb_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
e6d71bf3
DB
107# An object declared using "using".
108
109send_gdb "print ina\n"
110gdb_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
118send_gdb "ptype ina\n"
119gdb_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 }
d231d0b1
MC
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 }
e6d71bf3
DB
126 -re ".*$gdb_prompt $" { fail "ptype ina" }
127 timeout { fail "(timeout) ptype ina" }
128}
129
130# Check all functions are known to GDB
131
132setup_xfail hppa*-*-*11* CLLbs14869
133send_gdb "info func xyzq\n"
134gdb_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 }
5178b9d6
DJ
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 }
e6d71bf3
DB
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
147send_gdb "print 'AAA::xyzq'('x')\n"
148gdb_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
79c2c32d
DC
156send_gdb "print AAA::xyzq('x')\n"
157gdb_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
e6d71bf3
DB
165# Break on a function in a namespace
166
167send_gdb "break AAA::xyzq\n"
168gdb_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
178send_gdb "print 'BBB::CCC::xyzq'('x')\n"
179gdb_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
79c2c32d
DC
187send_gdb "print BBB::CCC::xyzq('x')\n"
188gdb_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
e6d71bf3
DB
196# Break on a function in a nested namespace
197
198send_gdb "break BBB::CCC::xyzq\n"
199gdb_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
209send_gdb "print 'BBB::Class::xyzq'\n"
210gdb_expect {
1bc05c3a 211 -re "\\$\[0-9\]* = \{char \\((BBB::|)Class \\*( const|), (char|int)\\)\} $hex <BBB::Class::xyzq\\(char\\)>\r\n$gdb_prompt $" {
a773d1cd 212 pass "print 'BBB::Class::xyzq'"
e6d71bf3 213 }
a773d1cd
MS
214 -re ".*$gdb_prompt $" { fail "print 'BBB::Class::xyzq'" }
215 timeout { fail "(timeout) print 'BBB::Class::xyzq'" }
e6d71bf3
DB
216}
217
218# Break on a function in a class in a namespace
219
220send_gdb "break BBB::Class::xyzq\n"
221gdb_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
1fcb5155
DC
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
233if ![runto "C::D::marker2"] then {
234 perror "couldn't run to marker2"
235 continue
236}
237
238gdb_test "print c" "\\$\[0-9\].* = 1"
239gdb_test "print cc" "No symbol \"cc\" in current context."
240gdb_test "print 'C::cc'" "\\$\[0-9\].* = 2"
79c2c32d 241gdb_test "print C::cc" "\\$\[0-9\].* = 2"
1fcb5155 242gdb_test "print cd" "\\$\[0-9\].* = 3"
79c2c32d 243gdb_test "print C::D::cd" "No type \"D\" in namespace \"C::C\"."
1fcb5155 244gdb_test "print 'E::cde'" "\\$\[0-9\].* = 5"
79c2c32d 245gdb_test "print E::cde" "\\$\[0-9\].* = 5"
1fcb5155 246gdb_test "print shadow" "\\$\[0-9\].* = 13"
79c2c32d 247gdb_test "print E::ce" "No symbol \"ce\" in namespace \"C::D::E\"."
1fcb5155 248gdb_test "print cOtherFile" "\\$\[0-9\].* = 316"
5c4e30ca
DC
249gdb_test "ptype C" "type = namespace C::C"
250gdb_test "ptype E" "type = namespace C::D::E"
1fcb5155
DC
251
252# Some anonymous namespace tests.
253
254gdb_test "print cX" "\\$\[0-9\].* = 6"
255gdb_test "print 'F::cXf'" "\\$\[0-9\].* = 7"
79c2c32d
DC
256gdb_test "print F::cXf" "\\$\[0-9\].* = 7"
257gdb_test "print F::cXfX" "\\$\[0-9\].* = 8"
1fcb5155
DC
258gdb_test "print X" "\\$\[0-9\].* = 9"
259gdb_test "print 'G::Xg'" "\\$\[0-9\].* = 10"
79c2c32d
DC
260gdb_test "print G::Xg" "\\$\[0-9\].* = 10"
261gdb_test "print G::XgX" "\\$\[0-9\].* = 11"
1fcb5155
DC
262gdb_test "print cXOtherFile" "No symbol \"cXOtherFile\" in current context."
263gdb_test "print XOtherFile" "No symbol \"XOtherFile\" in current context."
This page took 0.358097 seconds and 4 git commands to generate.