]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.linespec/ls-errs.exp
Rename to allow_cplus_tests and allow_stl_tests
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.linespec / ls-errs.exp
CommitLineData
213516ef 1# Copyright 2012-2023 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++"} {
0b94d2b9 33 if {![allow_cplus_tests]} {
1cafadb4
DB
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]} {
1cafadb4
DB
51 return 0
52 }
40e084e1 53
1cafadb4
DB
54 # Run to a location in the file.
55 set bp_location [gdb_get_line_number "set breakpoint here"]
56
57 gdb_test "break $srcfile:$bp_location" \
58 "Breakpoint.*at.* file .*$srcfile, line $bp_location\\." \
59 "breakpoint line number in file"
60
61 gdb_continue_to_breakpoint "$bp_location"
62
63 # Common error message format strings.
64 array set error_messages {
65 invalid_file "No source file named %s."
66 invalid_function "Function \"%s\" not defined."
67 invalid_var_or_func
68 "Undefined convenience variable or function \"%s\" not defined."
69 invalid_function_f "Function \"%s\" not defined in \"%s\"."
70 invalid_var_or_func_f \
71 "Undefined convenience variable or function \"%s\" not defined in \"%s\"."
72 invalid_label "No label \"%s\" defined in function \"%s\"."
73 invalid_parm "invalid linespec argument, \"%s\""
74 invalid_offset "No line %d in the current file."
75 invalid_offset_f "No line %d in file \"%s\"."
76 malformed_line_offset "malformed line offset: \"%s\""
77 source_incomplete \
78 "Source filename requires function, label, or line offset."
79 unexpected "malformed linespec error: unexpected %s"
80 unexpected_opt "malformed linespec error: unexpected %s, \"%s\""
81 unmatched_quote "unmatched quote"
82 garbage "Garbage '%s' at end of command"
83 }
40e084e1 84
1cafadb4 85 # We intentionally do not use gdb_breakpoint for these tests.
40e084e1 86
1cafadb4
DB
87 # Break at 'linespec' and expect the message in ::error_messages
88 # indexed by msg_id with the associated args.
89 proc test_break {linespec msg_id args} {
90 global error_messages
40e084e1 91
1cafadb4
DB
92 gdb_test "break $linespec" [string_to_regexp \
93 [eval format \$error_messages($msg_id) \
58eb20d5
AB
94 $args]] \
95 "'break $linespec'"
1cafadb4 96 }
40e084e1 97
1cafadb4 98 # Some commonly used whitespace tests around ':'.
c45ec17c
PA
99 set spaces [list \
100 ":" \
101 ": " \
102 " :" \
103 " : " \
104 " : " \
105 ]
40e084e1 106
1cafadb4
DB
107 # A list of invalid offsets.
108 set invalid_offsets [list -100 +500 1000]
40e084e1 109
1cafadb4
DB
110 # Try some simple, invalid linespecs involving spaces.
111 foreach x $spaces {
112 test_break $x unexpected "colon"
113 }
40e084e1 114
1cafadb4
DB
115 # Test invalid filespecs starting with offset. This is done
116 # first so that default offsets are tested.
117 foreach x $invalid_offsets {
118 set offset $x
119
49a4ce2e 120 # Relative offsets are relative to the current line. Adjust
1cafadb4
DB
121 # expected offset from error message accordingly.
122 if {[string index $x 0] == "+" || [string index $x 0] == "-"} {
49a4ce2e 123 incr offset $bp_location
1cafadb4
DB
124 }
125 test_break $x invalid_offset $offset
126 test_break "-line $x" invalid_offset $offset
127 }
40e084e1 128
1cafadb4
DB
129 # Test offsets with trailing tokens w/ and w/o spaces.
130 foreach x $spaces {
131 test_break "3$x" unexpected "colon"
132 test_break "+10$x" unexpected "colon"
133 test_break "-10$x" unexpected "colon"
134 }
40e084e1 135
1cafadb4
DB
136 foreach x {1 +1 +100 -10} {
137 test_break "3 $x" unexpected_opt "number" $x
138 test_break "-line 3 $x" garbage $x
139 test_break "+10 $x" unexpected_opt "number" $x
140 test_break "-line +10 $x" garbage $x
141 test_break "-10 $x" unexpected_opt "number" $x
142 test_break "-line -10 $x" garbage $x
143 }
87f0e720 144
1cafadb4
DB
145 foreach x {3 +10 -10} {
146 test_break "$x foo" unexpected_opt "string" "foo"
147 test_break "-line $x foo" garbage "foo"
148 }
87f0e720 149
1cafadb4
DB
150 # Test invalid linespecs starting with filename.
151 # It's OK to use the ".c" extension for the C++ test
152 # since the extension doesn't affect GDB's lookup.
153 set invalid_files [list "this_file_doesn't_exist.c" \
154 "this file has spaces.c" \
155 "\"file::colons.c\"" \
156 "'file::colons.c'" \
157 "\"this \"file\" has quotes.c\"" \
158 "'this \"file\" has quotes.c'" \
159 "'this 'file' has quotes.c'" \
160 "\"this 'file' has quotes.c\"" \
161 "\"spaces: and :colons.c\"" \
162 "'more: :spaces: :and colons::.c'" \
163 "C:/nonexist-with-windrive.c"]
164
165 foreach x $invalid_files {
166 # Remove any quoting from FILENAME for the error message.
167 test_break "$x:3" invalid_file [string trim $x \"']
168 }
169 foreach x [list "this_file_doesn't_exist.c" \
170 "file::colons.c" \
171 "'file::colons.c'"] {
172 test_break "-source $x -line 3" invalid_file [string trim $x \"']
173 }
87f0e720 174
c6756f62
PA
175 # Test that option lexing stops at whitespace boundaries, except
176 # when lexing function names, where we want to handle setting
177 # breakpoints on e.g., "int template_function<int>()".
fa6eb693 178 test_break "-source this file has spaces.c -line 3" source_incomplete
c6756f62
PA
179 test_break "-function ret_type tmpl_function" \
180 invalid_function "ret_type tmpl_function"
181 test_break "-source $srcfile -function ret_type tmpl_function" \
182 invalid_function_f "ret_type tmpl_function" $srcfile
87f0e720 183
1cafadb4
DB
184 test_break "-function main -label label whitespace" \
185 invalid_label "label" "main"
40e084e1 186
1cafadb4
DB
187 # Test unmatched quotes.
188 foreach x {"\"src-file.c'" "'src-file.c"} {
189 test_break "$x:3" unmatched_quote
190 }
40e084e1 191
1cafadb4
DB
192 test_break $srcfile invalid_function $srcfile
193 foreach x {"foo" " foo" " foo "} {
194 # Trim any leading/trailing whitespace for error messages.
195 test_break "$srcfile:$x" invalid_function_f [string trim $x] $srcfile
196 test_break "-source $srcfile -function $x" \
197 invalid_function_f [string trim $x] $srcfile
198 test_break "$srcfile:main:$x" invalid_label [string trim $x] "main"
199 test_break "-source $srcfile -function main -label $x" \
200 invalid_label [string trim $x] "main"
201 }
40e084e1 202
1cafadb4
DB
203 foreach x $spaces {
204 test_break "$srcfile$x" unexpected "end of input"
205 test_break "$srcfile:main$x" unexpected "end of input"
206 }
40e084e1 207
1cafadb4
DB
208 test_break "${srcfile}::" invalid_function "${srcfile}::"
209 test_break "$srcfile:3 1" unexpected_opt "number" "1"
210 test_break "-source $srcfile -line 3 1" garbage "1"
211 test_break "$srcfile:3 +100" unexpected_opt "number" "+100"
212 test_break "-source $srcfile -line 3 +100" garbage "+100"
213 test_break "$srcfile:3 -100" unexpected_opt "number" "-100"
214 test_break "$srcfile:3 foo" unexpected_opt "string" "foo"
215 test_break "-source $srcfile -line 3 foo" garbage "foo"
216
217 foreach x $invalid_offsets {
218 test_break "$srcfile:$x" invalid_offset_f $x $srcfile
219 test_break "\"$srcfile:$x\"" invalid_offset_f $x $srcfile
220 test_break "'$srcfile:$x'" invalid_offset_f $x $srcfile
221 test_break "-source $srcfile -line $x" invalid_offset_f $x $srcfile
222 }
223 test_break "-source $srcfile -line -x" malformed_line_offset "-x"
40e084e1 224
1cafadb4
DB
225 # Test invalid filespecs starting with function.
226 foreach x {"foobar" "foo::bar" "foo.bar" "foo ." "foo bar" "foo 1" \
40e084e1 227 "foo 0" "foo +10" "foo -10" "foo +100" "foo -100"} {
1cafadb4
DB
228 test_break $x invalid_function $x
229 test_break "-function \"$x\"" invalid_function $x
230 }
40e084e1 231
1cafadb4
DB
232 foreach x $spaces {
233 test_break "main${x}there" invalid_label "there" "main"
1cafadb4
DB
234 test_break "main:here${x}" unexpected "end of input"
235 }
40e084e1 236
58eb20d5 237 foreach_with_prefix x {"3" "+100" "-100" "foo"} {
1cafadb4
DB
238 test_break "main 3" invalid_function "main 3"
239 test_break "-function \"main $x\"" invalid_function "main $x"
c6756f62
PA
240 if {$x == "foo"} {
241 test_break "main:here $x" unexpected_opt "string" $x
242 } else {
243 test_break "main:here $x" unexpected_opt "number" $x
244 }
245
1cafadb4
DB
246 test_break "-function main -label \"here $x\"" \
247 invalid_label "here $x" "main"
248 }
40e084e1 249
1cafadb4
DB
250 foreach x {"if" "task" "thread"} {
251 test_break $x invalid_function $x
252 }
40e084e1 253
1cafadb4
DB
254 test_break "'main.c'flubber" unexpected_opt "string" "flubber"
255 test_break "'main.c',21" invalid_function "main.c"
256 test_break "'main.c' " invalid_function "main.c"
257 test_break "'main.c'3" unexpected_opt "number" "3"
258 test_break "'main.c'+3" unexpected_opt "number" "+3"
40e084e1 259
1cafadb4
DB
260 # Test undefined convenience variables.
261 set x {$zippo}
262 test_break $x invalid_var_or_func $x
263 test_break "$srcfile:$x" invalid_var_or_func_f $x $srcfile
87f0e720 264
1cafadb4
DB
265 # Explicit linespec-specific tests
266 test_break "-source $srcfile" source_incomplete
fa6eb693 267 test_break "-source $srcfile main" source_incomplete
1cafadb4
DB
268}
269
270foreach_with_prefix lang {"C" "C++"} {
271 do_test ${lang}
272}