1 # Copyright 1997, 1998, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
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.
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.
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.
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
20 # tests for namespaces
21 # Written by Satish Pai <pai@apollo.hp.com> 1997-07-23
23 # This file is part of the gdb testsuite
25 # Note: These tests are geared to the HP aCC compiler,
26 # which has an idiosyncratic way of emitting debug info
28 # Note: As of 2000-06-03, these pass under g++ - djb
38 if { [skip_cplus_tests] } { continue }
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}
47 if [get_compiler_info ${binfile}] {
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."
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."
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."
65 gdb_reinitialize_dir $srcdir/$subdir
70 # set it up at a breakpoint so we can play with the variable values
72 if ![runto_main] then {
73 perror "couldn't run to breakpoint"
77 if ![runto 'marker1'] then {
78 perror "couldn't run to marker1"
82 gdb_test "up" ".*main.*" "up from marker1"
84 # Access a data item inside a namespace using colons and
87 send_gdb "print 'AAA::c'\n"
89 -re "\\$\[0-9\]* = 0 '\\\\(0|000)'\r\n$gdb_prompt $" { pass "print 'AAA::c'" }
90 -re ".*$gdb_prompt $" { fail "print 'AAA::c'" }
91 timeout { fail "(timeout) print 'AAA::c'" }
94 # An object declared using "using".
96 send_gdb "print ina\n"
98 -re "\\$\[0-9\]+ = {xx = 33}.*$gdb_prompt $" {
101 -re ".*$gdb_prompt $" { fail "print ina" }
102 timeout { fail "(timeout) print ina" }
105 send_gdb "ptype ina\n"
107 -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 $" {
110 -re ".*$gdb_prompt $" { fail "ptype ina" }
111 timeout { fail "(timeout) ptype ina" }
114 # Check all functions are known to GDB
116 setup_xfail hppa*-*-*11* CLLbs14869
117 send_gdb "info func xyzq\n"
119 -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 $" {
120 pass "info func xyzq"
122 -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 $" {
123 pass "info func xyzq"
125 -re ".*$gdb_prompt $" { fail "info func xyzq" }
126 timeout { fail "(timeout) info func xyzq" }
129 # Call a function in a namespace
131 send_gdb "print 'AAA::xyzq'('x')\n"
133 -re "\\$\[0-9\]* = 97 'a'\r\n$gdb_prompt $" {
134 pass "print 'AAA::xyzq'('x')"
136 -re ".*$gdb_prompt $" { fail "print 'AAA::xyzq'('x')" }
137 timeout { fail "(timeout) print 'AAA::xyzq'('x')" }
140 # Break on a function in a namespace
142 send_gdb "break AAA::xyzq\n"
144 -re "Breakpoint.*at $hex: file.*namespace.cc, line 42\\.\r\n$gdb_prompt $" {
145 pass "break AAA::xyzq"
147 -re ".*$gdb_prompt $" { fail "break AAA::xyzq" }
148 timeout { fail "(timeout) break AAA::xyzq" }
151 # Call a function in a nested namespace
153 send_gdb "print 'BBB::CCC::xyzq'('x')\n"
155 -re "\\$\[0-9\]* = 122 'z'\r\n$gdb_prompt $" {
156 pass "print 'BBB::CCC::xyzq'('x')"
158 -re ".*$gdb_prompt $" { fail "print 'BBB::CCC::xyzq'('x')" }
159 timeout { fail "(timeout) print 'BBB::CCC::xyzq'('x')" }
162 # Break on a function in a nested namespace
164 send_gdb "break BBB::CCC::xyzq\n"
166 -re "Breakpoint.*at $hex: file.*namespace.cc, line 58\\.\r\n$gdb_prompt $" {
167 pass "break BBB::CCC::xyzq"
169 -re ".*$gdb_prompt $" { fail "break BBB::CCC::xyzq" }
170 timeout { fail "(timeout) break BBB::CCC::xyzq" }
173 # Print address of a function in a class in a namespace
175 send_gdb "print 'BBB::Class::xyzq'\n"
177 -re "\\$\[0-9\]* = \{char \\((BBB::|)Class \\*( const|), (char|int)\\)\} $hex <BBB::Class::xyzq\\(char\\)>\r\n$gdb_prompt $" {
178 pass "print 'BBB::Class::xyzq'"
180 -re ".*$gdb_prompt $" { fail "print 'BBB::Class::xyzq'" }
181 timeout { fail "(timeout) print 'BBB::Class::xyzq'" }
184 # Break on a function in a class in a namespace
186 send_gdb "break BBB::Class::xyzq\n"
188 -re "Breakpoint.*at $hex: file.*namespace.cc, line 63\\.\r\n$gdb_prompt $" {
189 pass "break BBB::Class::xyzq"
191 -re ".*$gdb_prompt $" { fail "break BBB::Class::xyzq" }
192 timeout { fail "(timeout) break BBB::Class::xyzq" }
195 # Test to see if the appropriate namespaces are in scope when trying
196 # to print out stuff from within a function defined within a
199 if ![runto "C::D::marker2"] then {
200 perror "couldn't run to marker2"
204 gdb_test "print c" "\\$\[0-9\].* = 1"
205 gdb_test "print cc" "No symbol \"cc\" in current context."
206 gdb_test "print 'C::cc'" "\\$\[0-9\].* = 2"
207 gdb_test "print cd" "\\$\[0-9\].* = 3"
208 gdb_test "print 'E::cde'" "\\$\[0-9\].* = 5"
209 gdb_test "print shadow" "\\$\[0-9\].* = 13"
210 gdb_test "print cOtherFile" "\\$\[0-9\].* = 316"
212 # Some anonymous namespace tests.
214 gdb_test "print cX" "\\$\[0-9\].* = 6"
215 gdb_test "print 'F::cXf'" "\\$\[0-9\].* = 7"
216 gdb_test "print X" "\\$\[0-9\].* = 9"
217 gdb_test "print 'G::Xg'" "\\$\[0-9\].* = 10"
218 gdb_test "print cXOtherFile" "No symbol \"cXOtherFile\" in current context."
219 gdb_test "print XOtherFile" "No symbol \"XOtherFile\" in current context."