1 # Copyright 2008-2023 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 3 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, see <http://www.gnu.org/licenses/>.
18 if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug c++}]} {
22 ############################################
23 # Test printing of namespace imported within the function.
29 gdb_test "print _a" "= 1"
31 ############################################
32 # Test printing of namespace imported into a scope containing the pc.
34 gdb_breakpoint [gdb_get_line_number "marker1 stop"]
35 gdb_continue_to_breakpoint "marker1 stop"
37 gdb_test "print _a" "= 1" "print _a in a nested scope"
39 ############################################
40 # Test printing of namespace aliases.
42 gdb_breakpoint marker2
43 gdb_continue_to_breakpoint "marker2"
45 gdb_test "print B::_a" "= 1"
47 gdb_test "print _a" "No symbol \"_a\" in current context." \
48 "print _a in namespace alias scope"
50 gdb_test "print x" "No symbol \"x\" in current context." \
51 "print x in namespace alias scope"
53 ############################################
54 # Test that names are not printed when they
57 gdb_breakpoint marker3
58 gdb_continue_to_breakpoint "marker3"
60 # gcc-4-3 puts import statements for aliases in
61 # the global scope instead of the corresponding
62 # function scope. These wrong import statements throw
63 # this test off. This is fixed in gcc-4-4.
64 if {[test_compiler_info gcc-4-3-*]} { setup_xfail *-*-* }
66 gdb_test "print _a" "No symbol \"_a\" in current context." \
67 "Print _a without import at marker3"
69 ############################################
70 # Test printing of individually imported elements.
72 gdb_breakpoint marker4
73 gdb_continue_to_breakpoint "marker4"
75 gdb_test "print dx" "= 4"
77 ############################################
78 # Test printing of namespace imported into file scope.
80 gdb_breakpoint marker5
81 gdb_continue_to_breakpoint "marker5"
83 gdb_test "print cc" "= 3"
85 # Also test printing of namespace aliases
87 gdb_test "print efx" "= 5"
89 ############################################
90 # Test printing of variables imported from nested namespaces.
92 gdb_breakpoint I::marker7
93 gdb_continue_to_breakpoint "I::marker7"
95 gdb_test "print ghx" "= 6"
97 ############################################
98 # Test that variables are not printed in a namespace that is sibling
99 # to the namespace containing an import.
101 gdb_breakpoint L::marker8
102 gdb_continue_to_breakpoint "L::marker8"
104 gdb_test "print jx" "= 44" \
105 "print jx when the symbol is available"
107 gdb_breakpoint "K::marker9"
108 gdb_continue_to_breakpoint "K::marker9"
110 gdb_test "print jx" "No symbol \"jx\" in current context." \
111 "print jx when the symbol is not available"
113 ############################################
114 # Test that variables are only printed after the line containing the
117 gdb_breakpoint [gdb_get_line_number "marker10 stop"]
118 gdb_continue_to_breakpoint "marker10 stop"
120 if { [test_compiler_info {gcc-[0-3]-*}] ||
121 [test_compiler_info {gcc-4-[0-3]-*}]} {
125 # Xfail for incorrect decl_line on DW_TAG_imported_module,
126 # gcc PR debug/108716.
127 set have_gcc108716_xfail \
128 [expr [test_compiler_info gcc-*] && [gcc_major_version] < 13]
130 gdb_test_multiple "print x" "print x, before using statement" {
131 -re -wrap "No symbol .x. in current context.*" {
134 -re -wrap "Reference to .x. is ambiguous.*" {
135 if { $have_gcc108716_xfail } {
136 # GCC doesn't properly set the decl_line for namespaces, so GDB
137 # believes that the "using namespace M" line has already passed at
139 setup_xfail *-*-* gcc/108716
144 gdb_test "next" ".*" "using namespace M"
145 gdb_test_multiple "print x" "print x, only using M" {
146 -re -wrap "= 911.*" {
149 -re -wrap "Reference to .x. is ambiguous.*" {
150 if { $have_gcc108716_xfail } {
151 setup_xfail *-*-* gcc/108716
156 gdb_test "next" ".*" "using namespace N"
157 gdb_test "print x" "Reference to .x. is ambiguous.*" "print x, with M and N"