update copyright year range in GDB files
[external/binutils.git] / gdb / testsuite / gdb.ada / complete.exp
1 # Copyright 2005-2017 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 load_lib "ada.exp"
17
18 standard_ada_testfile foo
19
20 if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug ]] != "" } {
21   return -1
22 }
23
24 clean_restart ${testfile}
25
26 set bp_location [gdb_get_line_number "START" ${testdir}/foo.adb]
27 runto "foo.adb:$bp_location"
28
29 set eol "\[\r\n\]*"
30
31 # A convenience function that verifies that the "complete EXPR" command
32 # returns the EXPECTED_OUTPUT.
33
34 proc test_gdb_complete { expr expected_output } {
35     gdb_test "complete p $expr" \
36              "$expected_output" \
37              "complete p $expr"
38 }
39
40 # A convenience function that verifies that the "complete EXPR" command
41 # does not generate any output.
42
43 proc test_gdb_no_completion { expr } {
44     gdb_test_no_output "complete p $expr"
45 }
46
47 # Try a global variable, only one match should be found:
48
49 test_gdb_complete "my_glob" \
50                   "p my_global_variable"
51
52 # A global variable, inside a nested package:
53
54 test_gdb_complete "insi" \
55                   "p inside_variable"
56
57 # A global variable inside a nested package, but only giving part of
58 # the fully qualified name (top level package name missing):
59
60 test_gdb_no_completion "inner.insi"
61
62 # An incomplete nested package name, were lies a single symbol:
63 test_gdb_complete "pck.inne" \
64                   "p pck.inner.inside_variable"
65
66 # A fully qualified symbol name, mangled...
67 test_gdb_complete "pck__inner__ins" \
68                   "p pck__inner__inside_variable"
69
70 # A fully qualified symbol name...
71 test_gdb_complete "pck.inner.ins" \
72                   "p pck.inner.inside_variable"
73
74 # Make sure that "inside" is not returned as a possible completion
75 # for "side"...
76 test_gdb_no_completion "side"
77
78 # Verify that "Exported_Capitalized" is not returned as a match for
79 # "exported", since its symbol name contains capital letters.
80 test_gdb_no_completion "exported"
81
82 # check the "<...>" notation.
83 test_gdb_complete "<Exported" \
84                   "p <Exported_Capitalized>"
85
86 # A global symbol, created by the binder, that starts with __gnat...
87 test_gdb_complete "__gnat_ada_main_progra" \
88                   "p __gnat_ada_main_program_name"
89
90 # A global symbol, created by the binder, that starts with __gnat,
91 # and using the '<' notation.
92 test_gdb_complete "<__gnat_ada_main_prog" \
93                   "p <__gnat_ada_main_program_name>"
94
95 # A local variable
96 test_gdb_complete "some" \
97                   "p some_local_variable"
98
99 # A local variable variable, but in a different procedure. No match
100 # should be returned.
101 test_gdb_no_completion "not_in_sco"
102
103 # A fully qualified variable name that doesn't exist...
104 test_gdb_no_completion "pck.ins"
105
106 # A fully qualified variable name that does exist...
107 test_gdb_complete "pck.my" \
108                   "p pck.my_global_variable"
109
110 # A fully qualified package name
111 test_gdb_complete "pck.inne" \
112                   "p pck.inner.inside_variable"
113
114 # A fully qualified package name, with a dot at the end
115 test_gdb_complete "pck.inner." \
116                   "p pck.inner.inside_variable"
117
118 # Two matches, from the global scope:
119 test_gdb_complete "local_ident" \
120                   [multi_line "p local_identical_one" \
121                               "p local_identical_two" ]
122
123 # Two matches, from the global scope, but using fully qualified names:
124 test_gdb_complete "pck.local_ident" \
125                   [multi_line "p pck.local_identical_one" \
126                               "p pck.local_identical_two" ]
127
128 # Two matches, from the global scope, but using mangled fully qualified
129 # names:
130 test_gdb_complete "pck__local_ident" \
131                   [multi_line "p pck__local_identical_one" \
132                               "p pck__local_identical_two" ]
133
134 # Two matches, one from the global scope, the other from the local scope:
135 test_gdb_complete "external_ident" \
136                   [multi_line "p external_identical_one" \
137                               "p external_identical_two" ]
138
139 # Complete on the name of package. 
140 test_gdb_complete "pck" \
141                   [multi_line "(p pck\\.ad\[sb\])?" \
142                               "(p pck\\.ad\[sb\])?" \
143                               "p pck.ambiguous_func" \
144                               "p pck.external_identical_one" \
145                               "p pck.inner.inside_variable" \
146                               "p pck.local_identical_one" \
147                               "p pck.local_identical_two" \
148                               "p pck.my_global_variable" \
149                               "p pck.proc" ]
150
151 # Complete on the name of a package followed by a dot:
152 test_gdb_complete "pck." \
153                   [multi_line "(p pck\\.ad\[sb\])?" \
154                               "(p pck\\.ad\[sb\])?" \
155                               "p pck.ambiguous_func" \
156                               "p pck.external_identical_one" \
157                               "p pck.inner.inside_variable" \
158                               "p pck.local_identical_one" \
159                               "p pck.local_identical_two" \
160                               "p pck.my_global_variable" \
161                               "p pck.proc" ]
162
163 # Complete a mangled symbol name, but using the '<...>' notation.
164 test_gdb_complete "<pck__my" \
165                   "p <pck__my_global_variable>"
166
167 # Very simple completion, but using the interactive form, this time.
168 # The verification we are trying to make involves the event loop,
169 # and using the "complete" command is not sufficient to reproduce
170 # the original problem.
171
172 if { [readline_is_used] } {
173     set test "interactive complete 'print some'"
174     send_gdb "print some\t"
175     gdb_test_multiple "" "$test" {
176         -re "^print some_local_variable $" {
177             send_gdb "\n"
178             gdb_test_multiple "" "$test" {
179                 -re " = 1$eol$gdb_prompt $" {
180                     pass "$test"
181                 }
182             }
183         }
184     }
185 }
186
187 # Usually, parsing a function name that is ambiguous yields a menu through
188 # which users can select a specific function.  This should not happen during
189 # completion, though.
190 test_gdb_complete "ambig" \
191                   [multi_line "p ambiguous_func" \
192                               "p ambiguous_proc" ]
193 test_gdb_complete "ambiguous_f" \
194                   "p ambiguous_func"
195 test_gdb_complete "ambiguous_func" \
196                   "p ambiguous_func"