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# tests for namespaces 19# Originally written by Satish Pai <pai@apollo.hp.com> 1997-07-23 20 21# This file is part of the gdb testsuite 22 23# Note: The original tests were geared to the HP aCC compiler, 24# which has an idiosyncratic way of emitting debug info 25# for namespaces. 26# Note: As of 2000-06-03, they passed under g++ - djb 27 28 29if $tracelevel then { 30 strace $tracelevel 31 } 32 33set prms_id 0 34set bug_id 0 35 36if { [skip_cplus_tests] } { continue } 37 38set testfile "namespace" 39set srcfile ${testfile}.cc 40set objfile ${objdir}/${subdir}/${testfile}.o 41set srcfile1 ${testfile}1.cc 42set objfile1 ${objdir}/${subdir}/${testfile}1.o 43set binfile ${objdir}/${subdir}/${testfile} 44 45if [get_compiler_info ${binfile} c++] { 46 return -1; 47} 48 49if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${objfile}" object {debug c++}] != "" } { 50 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail." 51} 52 53if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${objfile1}" object {debug c++}] != "" } { 54 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail." 55} 56 57if { [gdb_compile "${objfile} ${objfile1}" "${binfile}" executable {debug c++}] != "" } { 58 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail." 59} 60 61gdb_exit 62gdb_start 63gdb_reinitialize_dir $srcdir/$subdir 64gdb_load ${binfile} 65 66 67# 68# set it up at a breakpoint so we can play with the variable values 69# 70if ![runto_main] then { 71 perror "couldn't run to breakpoint" 72 continue 73} 74 75if ![runto 'marker1'] then { 76 perror "couldn't run to marker1" 77 continue 78} 79 80gdb_test "up" ".*main.*" "up from marker1" 81 82# Access a data item inside a namespace using colons and 83# single quotes. :-( 84 85# NOTE: carlton/2003-09-24: the quotes are becoming less necessary (or 86# even desirable.) For tests where it should still work with quotes, 87# I'm including versions both with and without quotes; for tests that 88# shouldn't work with quotes, I'm only including one version. 89 90send_gdb "print 'AAA::c'\n" 91gdb_expect { 92 -re "\\$\[0-9\]* = 0 '\\\\(0|000)'\r\n$gdb_prompt $" { pass "print 'AAA::c'" } 93 -re ".*$gdb_prompt $" { fail "print 'AAA::c'" } 94 timeout { fail "(timeout) print 'AAA::c'" } 95} 96 97send_gdb "print AAA::c\n" 98gdb_expect { 99 -re "\\$\[0-9\]* = 0 '\\\\(0|000)'\r\n$gdb_prompt $" { pass "print AAA::c" } 100 -re ".*$gdb_prompt $" { fail "print AAA::c" } 101 timeout { fail "(timeout) print AAA::c" } 102} 103 104# An object declared using "using". 105 106send_gdb "print ina\n" 107gdb_expect { 108 -re "\\$\[0-9\]+ = {xx = 33}.*$gdb_prompt $" { 109 pass "print ina" 110 } 111 -re ".*$gdb_prompt $" { fail "print ina" } 112 timeout { fail "(timeout) print ina" } 113} 114 115send_gdb "ptype ina\n" 116gdb_expect { 117 -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 $" { 118 pass "ptype ina" 119 } 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 ".*$gdb_prompt $" { fail "ptype ina" } 124 timeout { fail "(timeout) ptype ina" } 125} 126 127# Check all functions are known to GDB 128 129setup_xfail hppa*-*-*11* CLLbs14869 130send_gdb "info func xyzq\n" 131gdb_expect { 132 -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 $" { 133 pass "info func xyzq" 134 } 135 -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 $" { 136 pass "info func xyzq" 137 } 138 -re ".*$gdb_prompt $" { fail "info func xyzq" } 139 timeout { fail "(timeout) info func xyzq" } 140} 141 142# Call a function in a namespace 143 144send_gdb "print 'AAA::xyzq'('x')\n" 145gdb_expect { 146 -re "\\$\[0-9\]* = 97 'a'\r\n$gdb_prompt $" { 147 pass "print 'AAA::xyzq'('x')" 148 } 149 -re ".*$gdb_prompt $" { fail "print 'AAA::xyzq'('x')" } 150 timeout { fail "(timeout) print 'AAA::xyzq'('x')" } 151} 152 153send_gdb "print AAA::xyzq('x')\n" 154gdb_expect { 155 -re "\\$\[0-9\]* = 97 'a'\r\n$gdb_prompt $" { 156 pass "print AAA::xyzq('x')" 157 } 158 -re ".*$gdb_prompt $" { fail "print AAA::xyzq('x')" } 159 timeout { fail "(timeout) print AAA::xyzq('x')" } 160} 161 162# Break on a function in a namespace 163 164send_gdb "break AAA::xyzq\n" 165gdb_expect { 166 -re "Breakpoint.*at $hex: file.*namespace.cc, line 42\\.\r\n$gdb_prompt $" { 167 pass "break AAA::xyzq" 168 } 169 -re ".*$gdb_prompt $" { fail "break AAA::xyzq" } 170 timeout { fail "(timeout) break AAA::xyzq" } 171} 172 173# Call a function in a nested namespace 174 175send_gdb "print 'BBB::CCC::xyzq'('x')\n" 176gdb_expect { 177 -re "\\$\[0-9\]* = 122 'z'\r\n$gdb_prompt $" { 178 pass "print 'BBB::CCC::xyzq'('x')" 179 } 180 -re ".*$gdb_prompt $" { fail "print 'BBB::CCC::xyzq'('x')" } 181 timeout { fail "(timeout) print 'BBB::CCC::xyzq'('x')" } 182} 183 184send_gdb "print BBB::CCC::xyzq('x')\n" 185gdb_expect { 186 -re "\\$\[0-9\]* = 122 'z'\r\n$gdb_prompt $" { 187 pass "print BBB::CCC::xyzq('x')" 188 } 189 -re ".*$gdb_prompt $" { fail "print BBB::CCC::xyzq('x')" } 190 timeout { fail "(timeout) print BBB::CCC::xyzq('x')" } 191} 192 193# Break on a function in a nested namespace 194 195send_gdb "break BBB::CCC::xyzq\n" 196gdb_expect { 197 -re "Breakpoint.*at $hex: file.*namespace.cc, line 58\\.\r\n$gdb_prompt $" { 198 pass "break BBB::CCC::xyzq" 199 } 200 -re ".*$gdb_prompt $" { fail "break BBB::CCC::xyzq" } 201 timeout { fail "(timeout) break BBB::CCC::xyzq" } 202} 203 204# Print address of a function in a class in a namespace 205 206send_gdb "print 'BBB::Class::xyzq'\n" 207gdb_expect { 208 -re "\\$\[0-9\]* = \{char \\((BBB::|)Class \\*( const|), (char|int)\\)\} $hex <BBB::Class::xyzq\\(char\\)>\r\n$gdb_prompt $" { 209 pass "print 'BBB::Class::xyzq'" 210 } 211 -re ".*$gdb_prompt $" { fail "print 'BBB::Class::xyzq'" } 212 timeout { fail "(timeout) print 'BBB::Class::xyzq'" } 213} 214 215send_gdb "print BBB::Class::xyzq\n" 216gdb_expect { 217 -re "\\$\[0-9\]* = \{char \\((BBB::|)Class \\*( const|), (char|int)\\)\} $hex <BBB::Class::xyzq\\(char\\)>\r\n$gdb_prompt $" { 218 pass "print BBB::Class::xyzq" 219 } 220 -re ".*$gdb_prompt $" { fail "print BBB::Class::xyzq" } 221 timeout { fail "(timeout) print BBB::Class::xyzq" } 222} 223 224# Break on a function in a class in a namespace 225 226send_gdb "break BBB::Class::xyzq\n" 227gdb_expect { 228 -re "Breakpoint.*at $hex: file.*namespace.cc, line 63\\.\r\n$gdb_prompt $" { 229 pass "break BBB::Class::xyzq" 230 } 231 -re ".*$gdb_prompt $" { fail "break BBB::Class::xyzq" } 232 timeout { fail "(timeout) break BBB::Class::xyzq" } 233} 234 235# Test to see if the appropriate namespaces are in scope when trying 236# to print out stuff from within a function defined within a 237# namespace. 238 239if ![runto "C::D::marker2"] then { 240 perror "couldn't run to marker2" 241 continue 242} 243 244gdb_test "print c" "\\$\[0-9\].* = 1" 245gdb_test "print cc" "No symbol \"cc\" in current context." 246gdb_test "print 'C::cc'" "\\$\[0-9\].* = 2" 247gdb_test "print C::cc" "\\$\[0-9\].* = 2" 248gdb_test "print cd" "\\$\[0-9\].* = 3" 249gdb_test "print C::D::cd" "No type \"D\" within class or namespace \"C::C\"." 250gdb_test "print 'E::cde'" "\\$\[0-9\].* = 5" 251gdb_test "print E::cde" "\\$\[0-9\].* = 5" 252gdb_test "print shadow" "\\$\[0-9\].* = 13" 253gdb_test "print E::ce" "No symbol \"ce\" in namespace \"C::D::E\"." 254gdb_test "ptype C" "type = namespace C::C" 255gdb_test "ptype E" "type = namespace C::D::E" 256 257gdb_test "ptype CClass" "type = (class C::CClass \{\r\n public:|struct C::CClass \{)\r\n int x;\r\n\}" 258gdb_test "ptype CClass::NestedClass" "type = (class C::CClass::NestedClass \{\r\n public:|struct C::CClass::NestedClass \{)\r\n int y;\r\n\}" 259gdb_test "ptype NestedClass" "No symbol \"NestedClass\" in current context." 260setup_kfail "gdb/1448" "*-*-*" 261gdb_test "ptype ::C::CClass" "type = class C::CClass \{\r\n public:\r\n int x;\r\n\}" 262setup_kfail "gdb/1448" "*-*-*" 263gdb_test "ptype ::C::CClass::NestedClass" "type = class C::CClass::NestedClass \{\r\n public:\r\n int y;\r\n\}" 264setup_kfail "gdb/1448" "*-*-*" 265gdb_test "ptype ::C::NestedClass" "No symbol \"NestedClass\" in namespace \"C\"." 266gdb_test "ptype C::CClass" "No symbol \"CClass\" in namespace \"C::C\"." 267gdb_test "ptype C::CClass::NestedClass" "No type \"CClass\" within class or namespace \"C::C\"." 268gdb_test "ptype C::NestedClass" "No symbol \"NestedClass\" in namespace \"C::C\"." 269 270# Tests involving multiple files 271 272gdb_test "print cOtherFile" "\\$\[0-9\].* = 316" 273gdb_test "ptype OtherFileClass" "type = (class C::OtherFileClass \{\r\n public:|struct C::OtherFileClass \{)\r\n int z;\r\n\}" 274setup_kfail "gdb/1448" "*-*-*" 275gdb_test "ptype ::C::OtherFileClass" "type = class C::OtherFileClass \{\r\n public:\r\n int z;\r\n\}" 276gdb_test "ptype C::OtherFileClass" "No symbol \"OtherFileClass\" in namespace \"C::C\"." 277 278# Some anonymous namespace tests. 279 280gdb_test "print cX" "\\$\[0-9\].* = 6" 281gdb_test "print 'F::cXf'" "\\$\[0-9\].* = 7" 282gdb_test "print F::cXf" "\\$\[0-9\].* = 7" 283gdb_test "print F::cXfX" "\\$\[0-9\].* = 8" 284gdb_test "print X" "\\$\[0-9\].* = 9" 285gdb_test "print 'G::Xg'" "\\$\[0-9\].* = 10" 286gdb_test "print G::Xg" "\\$\[0-9\].* = 10" 287gdb_test "print G::XgX" "\\$\[0-9\].* = 11" 288gdb_test "print cXOtherFile" "No symbol \"cXOtherFile\" in current context." 289gdb_test "print XOtherFile" "No symbol \"XOtherFile\" in current context." 290