Commit | Line | Data |
---|---|---|
88b9d363 | 1 | # Copyright 2008-2022 Free Software Foundation, Inc. |
27aa8d6a SW |
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 | ||
f5f3a911 | 16 | standard_testfile .cc |
27aa8d6a | 17 | |
4c93b1db | 18 | if [get_compiler_info] { |
8540c487 SW |
19 | return -1 |
20 | } | |
21 | ||
5b362f04 | 22 | if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug c++}]} { |
f5f3a911 TT |
23 | return -1 |
24 | } | |
27aa8d6a SW |
25 | |
26 | ############################################ | |
ac45a6ca | 27 | # Test printing of namespace imported within the function. |
27aa8d6a SW |
28 | |
29 | if ![runto_main] then { | |
30 | perror "couldn't run to breakpoint main" | |
31 | continue | |
32 | } | |
33 | ||
34 | gdb_test "print _a" "= 1" | |
35 | ||
36 | ############################################ | |
ac45a6ca | 37 | # Test printing of namespace imported into a scope containing the pc. |
df83a9bf | 38 | |
27aa8d6a SW |
39 | gdb_breakpoint [gdb_get_line_number "marker1 stop"] |
40 | gdb_continue_to_breakpoint "marker1 stop" | |
41 | ||
42 | gdb_test "print _a" "= 1" "print _a in a nested scope" | |
43 | ||
df83a9bf | 44 | ############################################ |
ac45a6ca | 45 | # Test printing of namespace aliases. |
df83a9bf | 46 | |
ac45a6ca AB |
47 | gdb_breakpoint marker2 |
48 | gdb_continue_to_breakpoint "marker2" | |
27aa8d6a | 49 | |
df83a9bf SW |
50 | gdb_test "print B::_a" "= 1" |
51 | ||
df83a9bf SW |
52 | gdb_test "print _a" "No symbol \"_a\" in current context." \ |
53 | "print _a in namespace alias scope" | |
54 | ||
df83a9bf SW |
55 | gdb_test "print x" "No symbol \"x\" in current context." \ |
56 | "print x in namespace alias scope" | |
57 | ||
27aa8d6a | 58 | ############################################ |
df83a9bf | 59 | # Test that names are not printed when they |
ac45a6ca | 60 | # are not imported. |
27aa8d6a | 61 | |
ac45a6ca AB |
62 | gdb_breakpoint marker3 |
63 | gdb_continue_to_breakpoint "marker3" | |
27aa8d6a | 64 | |
8540c487 SW |
65 | # gcc-4-3 puts import statements for aliases in |
66 | # the global scope instead of the corresponding | |
67 | # function scope. These wrong import statements throw | |
68 | # this test off. This is fixed in gcc-4-4. | |
69 | if [test_compiler_info gcc-4-3-*] then { setup_xfail *-*-* } | |
70 | ||
df83a9bf | 71 | gdb_test "print _a" "No symbol \"_a\" in current context." \ |
ac45a6ca | 72 | "Print _a without import at marker3" |
27aa8d6a SW |
73 | |
74 | ############################################ | |
ac45a6ca | 75 | # Test printing of individually imported elements. |
27aa8d6a | 76 | |
ac45a6ca AB |
77 | gdb_breakpoint marker4 |
78 | gdb_continue_to_breakpoint "marker4" | |
13387711 | 79 | |
df83a9bf | 80 | gdb_test "print dx" "= 4" |
8540c487 SW |
81 | |
82 | ############################################ | |
ac45a6ca | 83 | # Test printing of namespace imported into file scope. |
8540c487 | 84 | |
ac45a6ca AB |
85 | gdb_breakpoint marker5 |
86 | gdb_continue_to_breakpoint "marker5" | |
87 | ||
88 | gdb_test "print cc" "= 3" | |
89 | ||
90 | # Also test printing of namespace aliases | |
8540c487 | 91 | |
df83a9bf | 92 | gdb_test "print efx" "= 5" |
8540c487 SW |
93 | |
94 | ############################################ | |
ac45a6ca | 95 | # Test printing of variables imported from nested namespaces. |
df83a9bf | 96 | |
ac45a6ca AB |
97 | gdb_breakpoint I::marker7 |
98 | gdb_continue_to_breakpoint "I::marker7" | |
df83a9bf SW |
99 | |
100 | gdb_test "print ghx" "= 6" | |
101 | ||
102 | ############################################ | |
ac45a6ca AB |
103 | # Test that variables are not printed in a namespace that is sibling |
104 | # to the namespace containing an import. | |
df83a9bf | 105 | |
ac45a6ca AB |
106 | gdb_breakpoint L::marker8 |
107 | gdb_continue_to_breakpoint "L::marker8" | |
df83a9bf | 108 | |
ac45a6ca AB |
109 | gdb_test "print jx" "= 44" \ |
110 | "print jx when the symbol is available" | |
df83a9bf SW |
111 | |
112 | gdb_breakpoint "K::marker9" | |
113 | gdb_continue_to_breakpoint "K::marker9" | |
114 | ||
ac45a6ca AB |
115 | gdb_test "print jx" "No symbol \"jx\" in current context." \ |
116 | "print jx when the symbol is not available" | |
8540c487 | 117 | |
df83a9bf | 118 | ############################################ |
ac45a6ca AB |
119 | # Test that variables are only printed after the line containing the |
120 | # import. | |
8540c487 | 121 | |
df83a9bf SW |
122 | gdb_breakpoint [gdb_get_line_number "marker10 stop"] |
123 | gdb_continue_to_breakpoint "marker10 stop" | |
124 | ||
1da644f0 SW |
125 | if { [test_compiler_info {gcc-[0-3]-*}] || |
126 | [test_compiler_info {gcc-4-[0-3]-*}]} { | |
ac45a6ca | 127 | setup_xfail *-*-* |
1da644f0 SW |
128 | } |
129 | ||
df83a9bf SW |
130 | # Assert that M::x is printed and not N::x |
131 | gdb_test "print x" "= 911" "print x (from M::x)" |