]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.linespec/ls-errs.exp
Update years in copyright notice for the GDB files.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.linespec / ls-errs.exp
CommitLineData
8acc9f48 1# Copyright 2012-2013 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
29# We intentionally do not use gdb_breakpoint for these tests.
30
31# Add the (invalid) LINESPEC to the test array named in ARRAY_NAME.
32# Use the index into ::error_messages MSG_ID and ARGS to create
33# an error message which is the expect result of attempting to
34# break on the given LINESPEC.
35proc add {array_name linespec msg_id args} {
36 global error_messages
37 upvar $array_name tests
38
39 lappend tests(linespecs) $linespec
40 set tests("$linespec") [string_to_regexp \
41 [eval format \$error_messages($msg_id) $args]]
42}
43
44# Common error message format strings.
45array set error_messages {
46 invalid_file "No source file named %s."
47 invalid_function "Function \"%s\" not defined."
48 invalid_var_or_func "Undefined convenience variable or function \"%s\" not defined."
49 invalid_function_f "Function \"%s\" not defined in \"%s\"."
50 invalid_var_or_func_f \
51 "Undefined convenience variable or function \"%s\" not defined in \"%s\"."
52 invalid_label "No label \"%s\" defined in function \"%s\"."
53 invalid_offset "No line %d in the current file."
54 invalid_offset_f "No line %d in file \"%s\"."
55 unexpected "malformed linespec error: unexpected %s"
56 unexpected_opt "malformed linespec error: unexpected %s, \"%s\""
57 unmatched_quote "unmatched quote"
58}
59
60# Some commonly used whitespace tests around ':'.
61set spaces [list ":" ": " " :" " : " "\t: " " :\t" "\t:\t" " \t:\t " \
62 "\t \t:\t \t \t"]
63
64# A list of invalid offsets.
65set invalid_offsets [list -100 +500 1000]
66
67# THE_TESTS will hold all of our test information. Array index
68# "linespecs" will contain the complete list of all linespecs
69# to be tested. An array index of \"$linespec\" will contain
70# the expected result.
71set the_tests(linespecs) {}
72
73# Try some simple, invalid linespecs involving spaces.
74foreach x $spaces {
75 add the_tests $x unexpected "colon"
76}
77
78# Test invalid filespecs starting with offset. This is done
79# first so that default offsets are tested.
80foreach x $invalid_offsets {
81 set offset $x
82
83 # Relative offsets are relative to line 16. Adjust
84 # expected offset from error message accordingly.
85 if {[string index $x 0] == "+" ||
86 [string index $x 0] == "-"} {
87 incr offset 16
88 }
89 add the_tests $x invalid_offset $offset
90}
91
92# Test offsets with trailing tokens w/ and w/o spaces.
93foreach x $spaces {
94 add the_tests "3$x" unexpected "colon"
95 add the_tests "+10$x" unexpected "colon"
96 add the_tests "-10$x" unexpected "colon"
97}
98
99foreach x {1 +1 +100 -10} {
100 add the_tests "3 $x" unexpected_opt "number" $x
101 add the_tests "+10 $x" unexpected_opt "number" $x
102 add the_tests "-10 $x" unexpected_opt "number" $x
103}
104
105add the_tests "3 foo" unexpected_opt "string" "foo"
106add the_tests "+10 foo" unexpected_opt "string" "foo"
107add the_tests "-10 foo" unexpected_opt "string" "foo"
108
109# Test invalid linespecs starting with filename.
110foreach x [list "this_file_doesn't_exist.c" \
111 "this file has spaces.c" \
112 "\"file::colons.c\"" \
113 "'file::colons.c'" \
114 "\"this \"file\" has quotes.c\"" \
115 "'this \"file\" has quotes.c'" \
116 "'this 'file' has quotes.c'" \
f3b5e280
KS
117 "\"this 'file' has quotes.c\"" \
118 "\"spaces: and :colons.c\"" \
119 "'more: :spaces: :and colons::.c'"] {
40e084e1
KS
120 # Remove any quoting from FILENAME for the error message.
121 add the_tests "$x:3" invalid_file [string trim $x \"']
122}
123
124# Test unmatched quotes.
125foreach x {"\"src-file.c'" "'src-file.c"} {
126 add the_tests "$x:3" unmatched_quote
127}
128
129add the_tests $srcfile invalid_function $srcfile
130foreach x {"foo" " foo" " foo "} {
131 # Trim any leading/trailing whitespace for error messages.
132 add the_tests "$srcfile:$x" invalid_function_f [string trim $x] $srcfile
133 add the_tests "$srcfile:main:$x" invalid_label [string trim $x] "main"
134}
135
136foreach x $spaces {
137 add the_tests "$srcfile$x" unexpected "end of input"
138 add the_tests "$srcfile:main$x" unexpected "end of input"
139}
140
141add the_tests "${srcfile}::" invalid_function "${srcfile}::"
142add the_tests "$srcfile:3 1" unexpected_opt "number" "1"
143add the_tests "$srcfile:3 +100" unexpected_opt "number" "+100"
144add the_tests "$srcfile:3 -100" unexpected_opt "number" "-100"
145add the_tests "$srcfile:3 foo" unexpected_opt "string" "foo"
146
147foreach x $invalid_offsets {
148 add the_tests "$srcfile:$x" invalid_offset_f $x $srcfile
eff9c3e6
KS
149 add the_tests "\"$srcfile:$x\"" invalid_offset_f $x $srcfile
150 add the_tests "'$srcfile:$x'" invalid_offset_f $x $srcfile
40e084e1
KS
151}
152
153# Test invalid filespecs starting with function.
154foreach x {"foobar" "foo::bar" "foo.bar" "foo ." "foo bar" "foo 1" \
155 "foo 0" "foo +10" "foo -10" "foo +100" "foo -100"} {
156 add the_tests $x invalid_function $x
157}
158
159foreach x $spaces {
160 add the_tests "main${x}there" invalid_label "there" "main"
161 add the_tests "main:here${x}" unexpected "end of input"
162}
163
164add the_tests "main 3" invalid_function "main 3"
165add the_tests "main +100" invalid_function "main +100"
166add the_tests "main -100" invalid_function "main -100"
167add the_tests "main foo" invalid_function "main foo"
168
169foreach x {"3" "+100" "-100" "foo"} {
170 add the_tests "main:here $x" invalid_label "here $x" "main"
171}
172
173foreach x {"if" "task" "thread"} {
7c09e5a0 174 add the_tests $x invalid_function $x
40e084e1
KS
175}
176
177add the_tests "'main.c'flubber" unexpected_opt "string" "flubber"
178add the_tests "'main.c',21" invalid_function "main.c"
179add the_tests "'main.c' " invalid_function "main.c"
180add the_tests "'main.c'3" unexpected_opt "number" "3"
181add the_tests "'main.c'+3" unexpected_opt "number" "+3"
182
183# Test undefined convenience variables.
184set x {$zippo}
185add the_tests $x invalid_var_or_func $x
186add the_tests "$srcfile:$x" invalid_var_or_func_f $x $srcfile
187
188# Run the tests
189foreach linespec $the_tests(linespecs) {
190 gdb_test "break $linespec" $the_tests("$linespec")
191}