Imported Upstream version 7.9
[platform/upstream/gdb.git] / gdb / testsuite / gdb.linespec / ls-errs.exp
1 # Copyright 2012-2015 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 # We intentionally do not use gdb_breakpoint for these tests.
30
31 # Break at 'linespec' and expect the message in ::error_messages indexed by
32 # msg_id with the associated args.
33 proc test_break {linespec msg_id args} {
34     global error_messages
35
36     gdb_test "break $linespec" [string_to_regexp \
37                                 [eval format \$error_messages($msg_id) $args]]
38 }
39
40 # Common error message format strings.
41 array set error_messages {
42     invalid_file "No source file named %s."
43     invalid_function "Function \"%s\" not defined."
44     invalid_var_or_func "Undefined convenience variable or function \"%s\" not defined."
45     invalid_function_f "Function \"%s\" not defined in \"%s\"."
46     invalid_var_or_func_f \
47         "Undefined convenience variable or function \"%s\" not defined in \"%s\"."
48     invalid_label "No label \"%s\" defined in function \"%s\"."
49     invalid_offset "No line %d in the current file."
50     invalid_offset_f "No line %d in file \"%s\"."
51     unexpected "malformed linespec error: unexpected %s"
52     unexpected_opt "malformed linespec error: unexpected %s, \"%s\""
53     unmatched_quote "unmatched quote"
54 }
55
56 # Some commonly used whitespace tests around ':'.
57 set spaces [list ":" ": " " :" " : " "\t:  " "  :\t" "\t:\t" " \t:\t " \
58                 "\t  \t:\t  \t  \t"]
59
60 # A list of invalid offsets.
61 set invalid_offsets [list -100 +500 1000]
62
63 # Try some simple, invalid linespecs involving spaces.
64 foreach x $spaces {
65     test_break $x unexpected "colon"
66 }
67
68 # Test invalid filespecs starting with offset.  This is done
69 # first so that default offsets are tested.
70 foreach x $invalid_offsets {
71     set offset $x
72
73     # Relative offsets are relative to line 16.  Adjust
74     # expected offset from error message accordingly.
75     if {[string index $x 0] == "+" ||
76         [string index $x 0] == "-"} {
77         incr offset 16
78     }
79     test_break $x invalid_offset $offset
80 }
81
82 # Test offsets with trailing tokens w/ and w/o spaces.
83 foreach x $spaces {
84     test_break "3$x" unexpected "colon"
85     test_break "+10$x" unexpected "colon"
86     test_break "-10$x" unexpected "colon"
87 }
88
89 foreach x {1 +1 +100 -10} {
90     test_break "3 $x" unexpected_opt "number" $x
91     test_break "+10 $x" unexpected_opt "number" $x
92     test_break "-10 $x" unexpected_opt "number" $x
93 }
94
95 test_break "3 foo" unexpected_opt "string" "foo"
96 test_break "+10 foo" unexpected_opt "string" "foo"
97 test_break "-10 foo" unexpected_opt "string" "foo"
98
99 # Test invalid linespecs starting with filename.
100 foreach x [list "this_file_doesn't_exist.c" \
101                "this file has spaces.c" \
102                "\"file::colons.c\"" \
103                "'file::colons.c'" \
104                "\"this \"file\" has quotes.c\"" \
105                "'this \"file\" has quotes.c'" \
106                "'this 'file' has quotes.c'" \
107                "\"this 'file' has quotes.c\"" \
108                "\"spaces: and :colons.c\"" \
109                "'more: :spaces: :and  colons::.c'"] {
110     # Remove any quoting from FILENAME for the error message.
111     test_break "$x:3" invalid_file [string trim $x \"']
112 }
113
114 # Test unmatched quotes.
115 foreach x {"\"src-file.c'" "'src-file.c"} {
116     test_break "$x:3" unmatched_quote
117 }
118
119 test_break $srcfile invalid_function $srcfile
120 foreach x {"foo" " foo" " foo "} {
121     # Trim any leading/trailing whitespace for error messages.
122     test_break "$srcfile:$x" invalid_function_f [string trim $x] $srcfile
123     test_break "$srcfile:main:$x" invalid_label [string trim $x] "main"
124 }
125
126 foreach x $spaces {
127     test_break "$srcfile$x" unexpected "end of input"
128     test_break "$srcfile:main$x" unexpected "end of input"
129 }
130
131 test_break "${srcfile}::" invalid_function "${srcfile}::"
132 test_break "$srcfile:3 1" unexpected_opt "number" "1"
133 test_break "$srcfile:3 +100" unexpected_opt "number" "+100"
134 test_break "$srcfile:3 -100" unexpected_opt "number" "-100"
135 test_break "$srcfile:3 foo" unexpected_opt "string" "foo"
136
137 foreach x $invalid_offsets {
138     test_break "$srcfile:$x" invalid_offset_f $x $srcfile
139     test_break "\"$srcfile:$x\"" invalid_offset_f $x $srcfile
140     test_break "'$srcfile:$x'" invalid_offset_f $x $srcfile
141 }
142
143 # Test invalid filespecs starting with function.
144 foreach x {"foobar" "foo::bar" "foo.bar" "foo ." "foo bar" "foo 1" \
145                "foo 0" "foo +10" "foo -10" "foo +100" "foo -100"} {
146     test_break $x invalid_function $x
147 }
148
149 foreach x $spaces {
150     test_break "main${x}there" invalid_label "there" "main"
151     if {[test_compiler_info {clang-*-*}]} {  setup_xfail clang/14500 *-*-* }
152     test_break "main:here${x}" unexpected "end of input"
153 }
154
155 test_break "main 3" invalid_function "main 3"
156 test_break "main +100" invalid_function "main +100"
157 test_break "main -100" invalid_function "main -100"
158 test_break "main foo" invalid_function "main foo"
159
160 foreach x {"3" "+100" "-100" "foo"} {
161     test_break "main:here $x" invalid_label "here $x" "main"
162 }
163
164 foreach x {"if" "task" "thread"} {
165     test_break $x invalid_function $x
166 }
167
168 test_break "'main.c'flubber" unexpected_opt "string" "flubber"
169 test_break "'main.c',21" invalid_function "main.c"
170 test_break "'main.c' " invalid_function "main.c"
171 test_break "'main.c'3" unexpected_opt "number" "3"
172 test_break "'main.c'+3" unexpected_opt "number" "+3"
173
174 # Test undefined convenience variables.
175 set x {$zippo}
176 test_break $x invalid_var_or_func $x
177 test_break "$srcfile:$x" invalid_var_or_func_f $x $srcfile