Commit | Line | Data |
---|---|---|
32d0add0 | 1 | # Copyright 2012-2015 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 |
18 | standard_testfile |
19 | set exefile $testfile | |
40e084e1 KS |
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 | ||
ef0b411a GB |
29 | # Turn off completion limiting |
30 | gdb_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. | |
36 | proc 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. | |
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\"." | |
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 ':'. | |
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 | ||
40e084e1 KS |
71 | # Try some simple, invalid linespecs involving spaces. |
72 | foreach 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. | |
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 | } | |
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. | |
92 | foreach 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 | ||
98 | foreach 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 |
107 | foreach 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. | |
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'" \ | |
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 |
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" | |
40e084e1 KS |
145 | |
146 | # Test unmatched quotes. | |
147 | foreach x {"\"src-file.c'" "'src-file.c"} { | |
c2e827ad | 148 | test_break "$x:3" unmatched_quote |
40e084e1 KS |
149 | } |
150 | ||
c2e827ad | 151 | test_break $srcfile invalid_function $srcfile |
40e084e1 KS |
152 | foreach 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 | ||
162 | foreach 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 |
167 | test_break "${srcfile}::" invalid_function "${srcfile}::" |
168 | test_break "$srcfile:3 1" unexpected_opt "number" "1" | |
87f0e720 | 169 | test_break "-source $srcfile -line 3 1" garbage "1" |
c2e827ad | 170 | test_break "$srcfile:3 +100" unexpected_opt "number" "+100" |
87f0e720 | 171 | test_break "-source $srcfile -line 3 +100" garbage "+100" |
c2e827ad DB |
172 | test_break "$srcfile:3 -100" unexpected_opt "number" "-100" |
173 | test_break "$srcfile:3 foo" unexpected_opt "string" "foo" | |
87f0e720 | 174 | test_break "-source $srcfile -line 3 foo" garbage "foo" |
40e084e1 KS |
175 | |
176 | foreach 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 | 182 | test_break "-source $srcfile -line -x" malformed_line_offset "-x" |
40e084e1 KS |
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"} { | |
c2e827ad | 187 | test_break $x invalid_function $x |
87f0e720 | 188 | test_break "-function \"$x\"" invalid_function $x |
40e084e1 KS |
189 | } |
190 | ||
191 | foreach 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 | 197 | foreach 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 | ||
205 | foreach x {"if" "task" "thread"} { | |
c2e827ad | 206 | test_break $x invalid_function $x |
40e084e1 KS |
207 | } |
208 | ||
c2e827ad DB |
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" | |
40e084e1 KS |
214 | |
215 | # Test undefined convenience variables. | |
216 | set x {$zippo} | |
c2e827ad DB |
217 | test_break $x invalid_var_or_func $x |
218 | test_break "$srcfile:$x" invalid_var_or_func_f $x $srcfile | |
87f0e720 KS |
219 | |
220 | # Explicit linespec-specific tests | |
221 | test_break "-source $srcfile" source_incomplete |