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