16d4574c21e60ca946bd9cea0207dfcfccc00b76
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.linespec / ls-errs.exp
1 # Copyright 2012-2016 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 # Tests for linespec error conditions
17
18 standard_testfile
19 set exefile $testfile
20
21 if {[prepare_for_testing $testfile $exefile $srcfile \
22 {debug nowarnings}]} {
23 return -1
24 }
25
26 # Turn off the pending breakpoint queries.
27 gdb_test_no_output "set breakpoint pending off"
28
29 # Turn off completion limiting
30 gdb_test_no_output "set max-completions unlimited"
31
32 # We intentionally do not use gdb_breakpoint for these tests.
33
34 # Break at 'linespec' and expect the message in ::error_messages indexed by
35 # msg_id with the associated args.
36 proc test_break {linespec msg_id args} {
37 global error_messages
38
39 gdb_test "break $linespec" [string_to_regexp \
40 [eval format \$error_messages($msg_id) $args]]
41 }
42
43 # Common error message format strings.
44 array set error_messages {
45 invalid_file "No source file named %s."
46 invalid_function "Function \"%s\" not defined."
47 invalid_var_or_func "Undefined convenience variable or function \"%s\" not defined."
48 invalid_function_f "Function \"%s\" not defined in \"%s\"."
49 invalid_var_or_func_f \
50 "Undefined convenience variable or function \"%s\" not defined in \"%s\"."
51 invalid_label "No label \"%s\" defined in function \"%s\"."
52 invalid_parm "invalid linespec argument, \"%s\""
53 invalid_offset "No line %d in the current file."
54 invalid_offset_f "No line %d in file \"%s\"."
55 malformed_line_offset "malformed line offset: \"%s\""
56 source_incomplete \
57 "Source filename requires function, label, or line offset."
58 unexpected "malformed linespec error: unexpected %s"
59 unexpected_opt "malformed linespec error: unexpected %s, \"%s\""
60 unmatched_quote "unmatched quote"
61 garbage "Garbage '%s' at end of command"
62 }
63
64 # Some commonly used whitespace tests around ':'.
65 set spaces [list ":" ": " " :" " : " "\t: " " :\t" "\t:\t" " \t:\t " \
66 "\t \t:\t \t \t"]
67
68 # A list of invalid offsets.
69 set invalid_offsets [list -100 +500 1000]
70
71 # Try some simple, invalid linespecs involving spaces.
72 foreach x $spaces {
73 test_break $x unexpected "colon"
74 }
75
76 # Test invalid filespecs starting with offset. This is done
77 # first so that default offsets are tested.
78 foreach x $invalid_offsets {
79 set offset $x
80
81 # Relative offsets are relative to line 16. Adjust
82 # expected offset from error message accordingly.
83 if {[string index $x 0] == "+" ||
84 [string index $x 0] == "-"} {
85 incr offset 16
86 }
87 test_break $x invalid_offset $offset
88 test_break "-line $x" invalid_offset $offset
89 }
90
91 # Test offsets with trailing tokens w/ and w/o spaces.
92 foreach x $spaces {
93 test_break "3$x" unexpected "colon"
94 test_break "+10$x" unexpected "colon"
95 test_break "-10$x" unexpected "colon"
96 }
97
98 foreach x {1 +1 +100 -10} {
99 test_break "3 $x" unexpected_opt "number" $x
100 test_break "-line 3 $x" garbage $x
101 test_break "+10 $x" unexpected_opt "number" $x
102 test_break "-line +10 $x" garbage $x
103 test_break "-10 $x" unexpected_opt "number" $x
104 test_break "-line -10 $x" garbage $x
105 }
106
107 foreach x {3 +10 -10} {
108 test_break "$x foo" unexpected_opt "string" "foo"
109 test_break "-line $x foo" garbage "foo"
110 }
111
112 # Test invalid linespecs starting with filename.
113 foreach x [list "this_file_doesn't_exist.c" \
114 "this file has spaces.c" \
115 "\"file::colons.c\"" \
116 "'file::colons.c'" \
117 "\"this \"file\" has quotes.c\"" \
118 "'this \"file\" has quotes.c'" \
119 "'this 'file' has quotes.c'" \
120 "\"this 'file' has quotes.c\"" \
121 "\"spaces: and :colons.c\"" \
122 "'more: :spaces: :and colons::.c'"] {
123 # Remove any quoting from FILENAME for the error message.
124 test_break "$x:3" invalid_file [string trim $x \"']
125 }
126 foreach x [list "this_file_doesn't_exist.c" \
127 "file::colons.c" \
128 "'file::colons.c'"] {
129 test_break "-source $x -line 3" \
130 invalid_file [string trim $x \"']
131 }
132
133 # Test that option lexing stops at whitespace boundaries
134 test_break "-source this file has spaces.c -line 3" \
135 invalid_file "this"
136
137 test_break "-function function whitespace" \
138 invalid_function "function"
139
140 test_break "-source $srcfile -function function whitespace" \
141 invalid_function_f "function" $srcfile
142
143 test_break "-function main -label label whitespace" \
144 invalid_label "label" "main"
145
146 # Test unmatched quotes.
147 foreach x {"\"src-file.c'" "'src-file.c"} {
148 test_break "$x:3" unmatched_quote
149 }
150
151 test_break $srcfile invalid_function $srcfile
152 foreach x {"foo" " foo" " foo "} {
153 # Trim any leading/trailing whitespace for error messages.
154 test_break "$srcfile:$x" invalid_function_f [string trim $x] $srcfile
155 test_break "-source $srcfile -function $x" \
156 invalid_function_f [string trim $x] $srcfile
157 test_break "$srcfile:main:$x" invalid_label [string trim $x] "main"
158 test_break "-source $srcfile -function main -label $x" \
159 invalid_label [string trim $x] "main"
160 }
161
162 foreach x $spaces {
163 test_break "$srcfile$x" unexpected "end of input"
164 test_break "$srcfile:main$x" unexpected "end of input"
165 }
166
167 test_break "${srcfile}::" invalid_function "${srcfile}::"
168 test_break "$srcfile:3 1" unexpected_opt "number" "1"
169 test_break "-source $srcfile -line 3 1" garbage "1"
170 test_break "$srcfile:3 +100" unexpected_opt "number" "+100"
171 test_break "-source $srcfile -line 3 +100" garbage "+100"
172 test_break "$srcfile:3 -100" unexpected_opt "number" "-100"
173 test_break "$srcfile:3 foo" unexpected_opt "string" "foo"
174 test_break "-source $srcfile -line 3 foo" garbage "foo"
175
176 foreach x $invalid_offsets {
177 test_break "$srcfile:$x" invalid_offset_f $x $srcfile
178 test_break "\"$srcfile:$x\"" invalid_offset_f $x $srcfile
179 test_break "'$srcfile:$x'" invalid_offset_f $x $srcfile
180 test_break "-source $srcfile -line $x" invalid_offset_f $x $srcfile
181 }
182 test_break "-source $srcfile -line -x" malformed_line_offset "-x"
183
184 # Test invalid filespecs starting with function.
185 foreach x {"foobar" "foo::bar" "foo.bar" "foo ." "foo bar" "foo 1" \
186 "foo 0" "foo +10" "foo -10" "foo +100" "foo -100"} {
187 test_break $x invalid_function $x
188 test_break "-function \"$x\"" invalid_function $x
189 }
190
191 foreach x $spaces {
192 test_break "main${x}there" invalid_label "there" "main"
193 if {[test_compiler_info {clang-*-*}]} { setup_xfail clang/14500 *-*-* }
194 test_break "main:here${x}" unexpected "end of input"
195 }
196
197 foreach x {"3" "+100" "-100" "foo"} {
198 test_break "main 3" invalid_function "main 3"
199 test_break "-function \"main $x\"" invalid_function "main $x"
200 test_break "main:here $x" invalid_label "here $x" "main"
201 test_break "-function main -label \"here $x\"" \
202 invalid_label "here $x" "main"
203 }
204
205 foreach x {"if" "task" "thread"} {
206 test_break $x invalid_function $x
207 }
208
209 test_break "'main.c'flubber" unexpected_opt "string" "flubber"
210 test_break "'main.c',21" invalid_function "main.c"
211 test_break "'main.c' " invalid_function "main.c"
212 test_break "'main.c'3" unexpected_opt "number" "3"
213 test_break "'main.c'+3" unexpected_opt "number" "+3"
214
215 # Test undefined convenience variables.
216 set x {$zippo}
217 test_break $x invalid_var_or_func $x
218 test_break "$srcfile:$x" invalid_var_or_func_f $x $srcfile
219
220 # Explicit linespec-specific tests
221 test_break "-source $srcfile" source_incomplete
This page took 0.04909 seconds and 3 git commands to generate.