Remove path name from test case
[binutils-gdb.git] / gdb / testsuite / gdb.cp / nsusing.exp
1 # Copyright 2008-2023 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 standard_testfile .cc
17
18 if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug c++}]} {
19 return -1
20 }
21
22 ############################################
23 # Test printing of namespace imported within the function.
24
25 if {![runto_main]} {
26 continue
27 }
28
29 gdb_test "print _a" "= 1"
30
31 ############################################
32 # Test printing of namespace imported into a scope containing the pc.
33
34 gdb_breakpoint [gdb_get_line_number "marker1 stop"]
35 gdb_continue_to_breakpoint "marker1 stop"
36
37 gdb_test "print _a" "= 1" "print _a in a nested scope"
38
39 ############################################
40 # Test printing of namespace aliases.
41
42 gdb_breakpoint marker2
43 gdb_continue_to_breakpoint "marker2"
44
45 gdb_test "print B::_a" "= 1"
46
47 gdb_test "print _a" "No symbol \"_a\" in current context." \
48 "print _a in namespace alias scope"
49
50 gdb_test "print x" "No symbol \"x\" in current context." \
51 "print x in namespace alias scope"
52
53 ############################################
54 # Test that names are not printed when they
55 # are not imported.
56
57 gdb_breakpoint marker3
58 gdb_continue_to_breakpoint "marker3"
59
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 *-*-* }
65
66 gdb_test "print _a" "No symbol \"_a\" in current context." \
67 "Print _a without import at marker3"
68
69 ############################################
70 # Test printing of individually imported elements.
71
72 gdb_breakpoint marker4
73 gdb_continue_to_breakpoint "marker4"
74
75 gdb_test "print dx" "= 4"
76
77 ############################################
78 # Test printing of namespace imported into file scope.
79
80 gdb_breakpoint marker5
81 gdb_continue_to_breakpoint "marker5"
82
83 gdb_test "print cc" "= 3"
84
85 # Also test printing of namespace aliases
86
87 gdb_test "print efx" "= 5"
88
89 ############################################
90 # Test printing of variables imported from nested namespaces.
91
92 gdb_breakpoint I::marker7
93 gdb_continue_to_breakpoint "I::marker7"
94
95 gdb_test "print ghx" "= 6"
96
97 ############################################
98 # Test that variables are not printed in a namespace that is sibling
99 # to the namespace containing an import.
100
101 gdb_breakpoint L::marker8
102 gdb_continue_to_breakpoint "L::marker8"
103
104 gdb_test "print jx" "= 44" \
105 "print jx when the symbol is available"
106
107 gdb_breakpoint "K::marker9"
108 gdb_continue_to_breakpoint "K::marker9"
109
110 gdb_test "print jx" "No symbol \"jx\" in current context." \
111 "print jx when the symbol is not available"
112
113 ############################################
114 # Test that variables are only printed after the line containing the
115 # import.
116
117 gdb_breakpoint [gdb_get_line_number "marker10 stop"]
118 gdb_continue_to_breakpoint "marker10 stop"
119
120 if { [test_compiler_info {gcc-[0-3]-*}] ||
121 [test_compiler_info {gcc-4-[0-3]-*}]} {
122 return
123 }
124
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]
129
130 gdb_test_multiple "print x" "print x, before using statement" {
131 -re -wrap "No symbol .x. in current context.*" {
132 pass $gdb_test_name
133 }
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
138 # this point.
139 setup_xfail *-*-* gcc/108716
140 }
141 fail $gdb_test_name
142 }
143 }
144 gdb_test "next" ".*" "using namespace M"
145 gdb_test_multiple "print x" "print x, only using M" {
146 -re -wrap "= 911.*" {
147 pass $gdb_test_name
148 }
149 -re -wrap "Reference to .x. is ambiguous.*" {
150 if { $have_gcc108716_xfail } {
151 setup_xfail *-*-* gcc/108716
152 }
153 fail $gdb_test_name
154 }
155 }
156 gdb_test "next" ".*" "using namespace N"
157 gdb_test "print x" "Reference to .x. is ambiguous.*" "print x, with M and N"