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