| 1 | # Copyright 2008, 2010 Free Software Foundation, Inc. |
| 2 | |
| 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 3 of the License, or |
| 6 | # (at your option) any later version. |
| 7 | # |
| 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. |
| 12 | # |
| 13 | # You should have received a copy of the GNU General Public License |
| 14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 | |
| 16 | if $tracelevel then { |
| 17 | strace $tracelevel |
| 18 | } |
| 19 | |
| 20 | set prms_id 0 |
| 21 | set bug_id 0 |
| 22 | |
| 23 | set testfile nsusing |
| 24 | set srcfile ${testfile}.cc |
| 25 | set binfile ${objdir}/${subdir}/${testfile} |
| 26 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable \ |
| 27 | {debug c++}] != "" } { |
| 28 | untested "Couldn't compile test program" |
| 29 | return -1 |
| 30 | } |
| 31 | |
| 32 | if [get_compiler_info ${binfile}] { |
| 33 | return -1 |
| 34 | } |
| 35 | |
| 36 | |
| 37 | # Get things started. |
| 38 | |
| 39 | gdb_exit |
| 40 | gdb_start |
| 41 | gdb_reinitialize_dir $srcdir/$subdir |
| 42 | gdb_load ${binfile} |
| 43 | |
| 44 | ############################################ |
| 45 | # test printing of namespace imported within |
| 46 | # the function. |
| 47 | |
| 48 | if ![runto_main] then { |
| 49 | perror "couldn't run to breakpoint main" |
| 50 | continue |
| 51 | } |
| 52 | |
| 53 | gdb_test "print _a" "= 1" |
| 54 | |
| 55 | # Test that names are not printed when they |
| 56 | # are not imported |
| 57 | |
| 58 | gdb_breakpoint marker3 |
| 59 | gdb_continue_to_breakpoint "marker3" |
| 60 | |
| 61 | #send_gdb "break marker3\n" |
| 62 | #send_gdb "continue\n" |
| 63 | |
| 64 | gdb_test "print _a" "No symbol \"_a\" in current context." \ |
| 65 | "Print _a without import" |
| 66 | |
| 67 | gdb_exit |
| 68 | gdb_start |
| 69 | gdb_reinitialize_dir $srcdir/$subdir |
| 70 | gdb_load ${binfile} |
| 71 | |
| 72 | |
| 73 | ############################################ |
| 74 | # test printing of namespace imported into |
| 75 | # a scope containing the pc. |
| 76 | |
| 77 | if ![runto_main] then { |
| 78 | perror "couldn't run to breakpoint main" |
| 79 | continue |
| 80 | } |
| 81 | |
| 82 | gdb_breakpoint [gdb_get_line_number "marker1 stop"] |
| 83 | gdb_continue_to_breakpoint "marker1 stop" |
| 84 | |
| 85 | gdb_test "print _a" "= 1" "print _a in a nested scope" |
| 86 | |
| 87 | |
| 88 | gdb_exit |
| 89 | gdb_start |
| 90 | gdb_reinitialize_dir $srcdir/$subdir |
| 91 | gdb_load ${binfile} |
| 92 | |
| 93 | ############################################ |
| 94 | # test printing of namespace imported into |
| 95 | # file scope. |
| 96 | |
| 97 | |
| 98 | if ![runto marker5] then { |
| 99 | perror "couldn't run to breakpoint marker5" |
| 100 | continue |
| 101 | } |
| 102 | |
| 103 | gdb_test "print cc" "= 3" |
| 104 | |
| 105 | gdb_exit |
| 106 | gdb_start |
| 107 | gdb_reinitialize_dir $srcdir/$subdir |
| 108 | gdb_load ${binfile} |
| 109 | |
| 110 | |
| 111 | ############################################ |
| 112 | # Test printing of namespace aliases |
| 113 | |
| 114 | if ![runto marker2] then { |
| 115 | perror "couldn't run to breakpoint marker2" |
| 116 | continue |
| 117 | } |
| 118 | |
| 119 | gdb_test "print B::_a" "= 1" |
| 120 | |
| 121 | gdb_test "print _a" "No symbol \"_a\" in current context." \ |
| 122 | "print _a in namespace alias scope" |
| 123 | |
| 124 | gdb_test "print x" "No symbol \"x\" in current context." \ |
| 125 | "print x in namespace alias scope" |
| 126 | |
| 127 | gdb_exit |
| 128 | gdb_start |
| 129 | gdb_reinitialize_dir $srcdir/$subdir |
| 130 | gdb_load ${binfile} |
| 131 | |
| 132 | |
| 133 | ############################################ |
| 134 | # Test that names are not printed when they |
| 135 | # are not imported |
| 136 | |
| 137 | if {![runto marker3]} { |
| 138 | perror "couldn't run to breakpoint marker3" |
| 139 | } |
| 140 | |
| 141 | # gcc-4-3 puts import statements for aliases in |
| 142 | # the global scope instead of the corresponding |
| 143 | # function scope. These wrong import statements throw |
| 144 | # this test off. This is fixed in gcc-4-4. |
| 145 | if [test_compiler_info gcc-4-3-*] then { setup_xfail *-*-* } |
| 146 | |
| 147 | gdb_test "print _a" "No symbol \"_a\" in current context." \ |
| 148 | "Print _a without import" |
| 149 | |
| 150 | ############################################ |
| 151 | # Test printing of individually imported elements |
| 152 | |
| 153 | if ![runto marker4] then { |
| 154 | perror "couldn't run to breakpoint marker4" |
| 155 | continue |
| 156 | } |
| 157 | setup_kfail "gdb/7936" "*-*-*" |
| 158 | gdb_test "print dx" "= 4" |
| 159 | |
| 160 | ############################################ |
| 161 | # Test printing of namespace aliases |
| 162 | |
| 163 | if ![runto marker5] then { |
| 164 | perror "couldn't run to marker5" |
| 165 | continue |
| 166 | } |
| 167 | |
| 168 | gdb_test "print efx" "= 5" |
| 169 | |
| 170 | ############################################ |
| 171 | # Test printing of variables imported from |
| 172 | # nested namespaces |
| 173 | |
| 174 | if ![runto I::marker7] then { |
| 175 | perror "couldn't run to breakpoint I::marker7" |
| 176 | continue |
| 177 | } |
| 178 | |
| 179 | gdb_test "print ghx" "= 6" |
| 180 | |
| 181 | ############################################ |
| 182 | # Test that variables are not printed in a namespace |
| 183 | # that is sibling to the namespace containing an import |
| 184 | |
| 185 | if ![runto L::marker8] then { |
| 186 | perror "couldn't run to breakpoint L::marker8" |
| 187 | continue |
| 188 | } |
| 189 | |
| 190 | gdb_test "print jx" "= 44" |
| 191 | |
| 192 | gdb_breakpoint "K::marker9" |
| 193 | gdb_continue_to_breakpoint "K::marker9" |
| 194 | |
| 195 | gdb_test "print jx" "No symbol \"jx\" in current context." |
| 196 | |
| 197 | ############################################ |
| 198 | # Test that variables are only printed after the line |
| 199 | # containing the import |
| 200 | |
| 201 | if ![runto_main] then { |
| 202 | perror "couldn't run to breakpoint main" |
| 203 | continue |
| 204 | } |
| 205 | |
| 206 | gdb_breakpoint [gdb_get_line_number "marker10 stop"] |
| 207 | gdb_continue_to_breakpoint "marker10 stop" |
| 208 | |
| 209 | # Assert that M::x is printed and not N::x |
| 210 | gdb_test "print x" "= 911" "print x (from M::x)" |