Rewrite/enhance explicit locations completer, parse left->right
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.linespec / ls-errs.exp
CommitLineData
61baf725 1# Copyright 2012-2017 Free Software Foundation, Inc.
40e084e1
KS
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
1cafadb4 16# Tests for linespec errors with C and C++.
40e084e1 17
1cafadb4 18# The test proper. LANG is either C or C++.
40e084e1 19
1cafadb4
DB
20proc do_test {lang} {
21 global testfile srcfile error_messages compiler_info
40e084e1 22
1cafadb4
DB
23 standard_testfile
24 set exefile $testfile
25 if [info exists compiler_info] {
26 # Unsetting compiler_info allows us to switch compilers
27 # used by prepare_for_testing.
28 unset compiler_info
29 }
30 set options {debug}
31
32 if {$lang == "C++"} {
33 if {[skip_cplus_tests]} {
34 return 0
35 }
36 # Build ".c" source file with g++.
37 lappend options "c++"
38 }
40e084e1 39
5b362f04 40 if {[prepare_for_testing "failed to prepare" $exefile $srcfile $options]} {
1cafadb4
DB
41 return -1
42 }
ef0b411a 43
1cafadb4
DB
44 # Turn off the pending breakpoint queries.
45 gdb_test_no_output "set breakpoint pending off"
40e084e1 46
1cafadb4
DB
47 # Turn off completion limiting
48 gdb_test_no_output "set max-completions unlimited"
40e084e1 49
1cafadb4 50 if {![runto_main]} {
bc6c7af4 51 fail "can't run to main"
1cafadb4
DB
52 return 0
53 }
40e084e1 54
1cafadb4
DB
55 # Run to a location in the file.
56 set bp_location [gdb_get_line_number "set breakpoint here"]
57
58 gdb_test "break $srcfile:$bp_location" \
59 "Breakpoint.*at.* file .*$srcfile, line $bp_location\\." \
60 "breakpoint line number in file"
61
62 gdb_continue_to_breakpoint "$bp_location"
63
64 # Common error message format strings.
65 array set error_messages {
66 invalid_file "No source file named %s."
67 invalid_function "Function \"%s\" not defined."
68 invalid_var_or_func
69 "Undefined convenience variable or function \"%s\" not defined."
70 invalid_function_f "Function \"%s\" not defined in \"%s\"."
71 invalid_var_or_func_f \
72 "Undefined convenience variable or function \"%s\" not defined in \"%s\"."
73 invalid_label "No label \"%s\" defined in function \"%s\"."
74 invalid_parm "invalid linespec argument, \"%s\""
75 invalid_offset "No line %d in the current file."
76 invalid_offset_f "No line %d in file \"%s\"."
77 malformed_line_offset "malformed line offset: \"%s\""
78 source_incomplete \
79 "Source filename requires function, label, or line offset."
80 unexpected "malformed linespec error: unexpected %s"
81 unexpected_opt "malformed linespec error: unexpected %s, \"%s\""
82 unmatched_quote "unmatched quote"
83 garbage "Garbage '%s' at end of command"
84 }
40e084e1 85
1cafadb4 86 # We intentionally do not use gdb_breakpoint for these tests.
40e084e1 87
1cafadb4
DB
88 # Break at 'linespec' and expect the message in ::error_messages
89 # indexed by msg_id with the associated args.
90 proc test_break {linespec msg_id args} {
91 global error_messages
40e084e1 92
1cafadb4
DB
93 gdb_test "break $linespec" [string_to_regexp \
94 [eval format \$error_messages($msg_id) \
95 $args]]
96 }
40e084e1 97
1cafadb4
DB
98 # Some commonly used whitespace tests around ':'.
99 set spaces [list ":" ": " " :" " : " "\t: " " :\t" "\t:\t" \
100 " \t:\t " "\t \t:\t \t \t"]
40e084e1 101
1cafadb4
DB
102 # A list of invalid offsets.
103 set invalid_offsets [list -100 +500 1000]
40e084e1 104
1cafadb4
DB
105 # Try some simple, invalid linespecs involving spaces.
106 foreach x $spaces {
107 test_break $x unexpected "colon"
108 }
40e084e1 109
1cafadb4
DB
110 # Test invalid filespecs starting with offset. This is done
111 # first so that default offsets are tested.
112 foreach x $invalid_offsets {
113 set offset $x
114
115 # Relative offsets are relative to line 16. Adjust
116 # expected offset from error message accordingly.
117 if {[string index $x 0] == "+" || [string index $x 0] == "-"} {
118 incr offset 24
119 }
120 test_break $x invalid_offset $offset
121 test_break "-line $x" invalid_offset $offset
122 }
40e084e1 123
1cafadb4
DB
124 # Test offsets with trailing tokens w/ and w/o spaces.
125 foreach x $spaces {
126 test_break "3$x" unexpected "colon"
127 test_break "+10$x" unexpected "colon"
128 test_break "-10$x" unexpected "colon"
129 }
40e084e1 130
1cafadb4
DB
131 foreach x {1 +1 +100 -10} {
132 test_break "3 $x" unexpected_opt "number" $x
133 test_break "-line 3 $x" garbage $x
134 test_break "+10 $x" unexpected_opt "number" $x
135 test_break "-line +10 $x" garbage $x
136 test_break "-10 $x" unexpected_opt "number" $x
137 test_break "-line -10 $x" garbage $x
138 }
87f0e720 139
1cafadb4
DB
140 foreach x {3 +10 -10} {
141 test_break "$x foo" unexpected_opt "string" "foo"
142 test_break "-line $x foo" garbage "foo"
143 }
87f0e720 144
1cafadb4
DB
145 # Test invalid linespecs starting with filename.
146 # It's OK to use the ".c" extension for the C++ test
147 # since the extension doesn't affect GDB's lookup.
148 set invalid_files [list "this_file_doesn't_exist.c" \
149 "this file has spaces.c" \
150 "\"file::colons.c\"" \
151 "'file::colons.c'" \
152 "\"this \"file\" has quotes.c\"" \
153 "'this \"file\" has quotes.c'" \
154 "'this 'file' has quotes.c'" \
155 "\"this 'file' has quotes.c\"" \
156 "\"spaces: and :colons.c\"" \
157 "'more: :spaces: :and colons::.c'" \
158 "C:/nonexist-with-windrive.c"]
159
160 foreach x $invalid_files {
161 # Remove any quoting from FILENAME for the error message.
162 test_break "$x:3" invalid_file [string trim $x \"']
163 }
164 foreach x [list "this_file_doesn't_exist.c" \
165 "file::colons.c" \
166 "'file::colons.c'"] {
167 test_break "-source $x -line 3" invalid_file [string trim $x \"']
168 }
87f0e720 169
c6756f62
PA
170 # Test that option lexing stops at whitespace boundaries, except
171 # when lexing function names, where we want to handle setting
172 # breakpoints on e.g., "int template_function<int>()".
1cafadb4 173 test_break "-source this file has spaces.c -line 3" invalid_file "this"
c6756f62
PA
174 test_break "-function ret_type tmpl_function" \
175 invalid_function "ret_type tmpl_function"
176 test_break "-source $srcfile -function ret_type tmpl_function" \
177 invalid_function_f "ret_type tmpl_function" $srcfile
87f0e720 178
1cafadb4
DB
179 test_break "-function main -label label whitespace" \
180 invalid_label "label" "main"
40e084e1 181
1cafadb4
DB
182 # Test unmatched quotes.
183 foreach x {"\"src-file.c'" "'src-file.c"} {
184 test_break "$x:3" unmatched_quote
185 }
40e084e1 186
1cafadb4
DB
187 test_break $srcfile invalid_function $srcfile
188 foreach x {"foo" " foo" " foo "} {
189 # Trim any leading/trailing whitespace for error messages.
190 test_break "$srcfile:$x" invalid_function_f [string trim $x] $srcfile
191 test_break "-source $srcfile -function $x" \
192 invalid_function_f [string trim $x] $srcfile
193 test_break "$srcfile:main:$x" invalid_label [string trim $x] "main"
194 test_break "-source $srcfile -function main -label $x" \
195 invalid_label [string trim $x] "main"
196 }
40e084e1 197
1cafadb4
DB
198 foreach x $spaces {
199 test_break "$srcfile$x" unexpected "end of input"
200 test_break "$srcfile:main$x" unexpected "end of input"
201 }
40e084e1 202
1cafadb4
DB
203 test_break "${srcfile}::" invalid_function "${srcfile}::"
204 test_break "$srcfile:3 1" unexpected_opt "number" "1"
205 test_break "-source $srcfile -line 3 1" garbage "1"
206 test_break "$srcfile:3 +100" unexpected_opt "number" "+100"
207 test_break "-source $srcfile -line 3 +100" garbage "+100"
208 test_break "$srcfile:3 -100" unexpected_opt "number" "-100"
209 test_break "$srcfile:3 foo" unexpected_opt "string" "foo"
210 test_break "-source $srcfile -line 3 foo" garbage "foo"
211
212 foreach x $invalid_offsets {
213 test_break "$srcfile:$x" invalid_offset_f $x $srcfile
214 test_break "\"$srcfile:$x\"" invalid_offset_f $x $srcfile
215 test_break "'$srcfile:$x'" invalid_offset_f $x $srcfile
216 test_break "-source $srcfile -line $x" invalid_offset_f $x $srcfile
217 }
218 test_break "-source $srcfile -line -x" malformed_line_offset "-x"
40e084e1 219
1cafadb4
DB
220 # Test invalid filespecs starting with function.
221 foreach x {"foobar" "foo::bar" "foo.bar" "foo ." "foo bar" "foo 1" \
40e084e1 222 "foo 0" "foo +10" "foo -10" "foo +100" "foo -100"} {
1cafadb4
DB
223 test_break $x invalid_function $x
224 test_break "-function \"$x\"" invalid_function $x
225 }
40e084e1 226
1cafadb4
DB
227 foreach x $spaces {
228 test_break "main${x}there" invalid_label "there" "main"
229 if {[test_compiler_info {clang-*-*}]} {
230 setup_xfail clang/14500 *-*-*
231 }
232 test_break "main:here${x}" unexpected "end of input"
233 }
40e084e1 234
1cafadb4
DB
235 foreach x {"3" "+100" "-100" "foo"} {
236 test_break "main 3" invalid_function "main 3"
237 test_break "-function \"main $x\"" invalid_function "main $x"
c6756f62
PA
238 if {$x == "foo"} {
239 test_break "main:here $x" unexpected_opt "string" $x
240 } else {
241 test_break "main:here $x" unexpected_opt "number" $x
242 }
243
1cafadb4
DB
244 test_break "-function main -label \"here $x\"" \
245 invalid_label "here $x" "main"
246 }
40e084e1 247
1cafadb4
DB
248 foreach x {"if" "task" "thread"} {
249 test_break $x invalid_function $x
250 }
40e084e1 251
1cafadb4
DB
252 test_break "'main.c'flubber" unexpected_opt "string" "flubber"
253 test_break "'main.c',21" invalid_function "main.c"
254 test_break "'main.c' " invalid_function "main.c"
255 test_break "'main.c'3" unexpected_opt "number" "3"
256 test_break "'main.c'+3" unexpected_opt "number" "+3"
40e084e1 257
1cafadb4
DB
258 # Test undefined convenience variables.
259 set x {$zippo}
260 test_break $x invalid_var_or_func $x
261 test_break "$srcfile:$x" invalid_var_or_func_f $x $srcfile
87f0e720 262
1cafadb4
DB
263 # Explicit linespec-specific tests
264 test_break "-source $srcfile" source_incomplete
265}
266
267foreach_with_prefix lang {"C" "C++"} {
268 do_test ${lang}
269}
This page took 0.680618 seconds and 4 git commands to generate.