]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/skip.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / skip.exp
1 # Copyright 2011-2023 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 # This file was written by Justin Lebar. (justin.lebar@gmail.com)
17 # And further hacked on by Doug Evans. (dje@google.com)
18
19 load_lib completion-support.exp
20
21 standard_testfile
22
23 if { [prepare_for_testing "failed to prepare" "skip" \
24 {skip.c skip1.c } \
25 {debug nowarnings}] } {
26 return -1
27 }
28
29 set srcfile skip.c
30 set srcfile1 skip1.c
31
32 # Right after we start gdb, there's no default file or function to skip.
33
34 gdb_test "skip file" "No default file now." "skip file (no default file)"
35 gdb_test "skip function" "No default function now."
36 gdb_test "skip" "No default function now." "skip (no default function)"
37
38 # Test elided args.
39
40 gdb_test "skip -fi" "Missing value for -fi option."
41 gdb_test "skip -file" "Missing value for -file option."
42 gdb_test "skip -fu" "Missing value for -fu option."
43 gdb_test "skip -function" "Missing value for -function option."
44 gdb_test "skip -rfu" "Missing value for -rfu option."
45 gdb_test "skip -rfunction" "Missing value for -rfunction option."
46
47 # Test other invalid option combinations.
48
49 gdb_test "skip -x" "Invalid skip option: -x"
50 gdb_test "skip -rfu foo.* xyzzy" "Invalid argument: xyzzy"
51
52 if ![runto_main] {
53 return
54 }
55
56 # Test |info skip| with an empty skiplist.
57
58 gdb_test "info skip" "Not skipping any files or functions\." "info skip empty"
59
60 # Create a skiplist entry for the current file and function.
61
62 gdb_test "skip file" "File .*$srcfile will be skipped when stepping\." "skip file ($srcfile)"
63 gdb_test "skip" "Function main will be skipped when stepping\." "skip (main)"
64
65 # Create a skiplist entry for a specified file and function.
66
67 gdb_test "skip file skip1.c" "File .*$srcfile1 will be skipped when stepping\."
68 gdb_test "skip function baz" "Function baz will be skipped when stepping\."
69
70 # Test bad skiplist entry modification commands
71
72 gdb_test "skip enable 999" "No skiplist entries found with number 999."
73 gdb_test "skip disable 999" "No skiplist entries found with number 999."
74 gdb_test "skip delete 999" "No skiplist entries found with number 999."
75 gdb_test "skip enable a" "Arguments must be numbers or '\\$' variables."
76 gdb_test "skip disable a" "Arguments must be numbers or '\\$' variables."
77 gdb_test "skip delete a" "Arguments must be numbers or '\\$' variables."
78
79 # Ask for info on a skiplist entry which doesn't exist.
80
81 gdb_test "info skip 999" "No skiplist entries found with number 999."
82
83 # Does |info skip| look right?
84
85 gdb_test "info skip" \
86 [multi_line "Num\\s+Enb\\s+Glob\\s+File\\s+RE\\s+Function" \
87 "1\\s+y\\s+n\\s+.*$srcfile\\s+n\\s+<none>" \
88 "2\\s+y\\s+n\\s+<none>\\s+n\\s+main" \
89 "3\\s+y\\s+n\\s+$srcfile1\\s+n\\s+<none>" \
90 "4\\s+y\\s+n\\s+<none>\\s+n\\s+baz"]
91
92 # Right now, we have an outstanding skiplist entry on both source
93 # files, so when we step into the first line in main(), we should step
94 # right over it and go to the second line of main().
95
96 if ![runto_main] {
97 return
98 }
99
100 gdb_test "step" ".*" "step in the main"
101 gdb_test "bt" "\\s*\\#0\\s+main.*" "step after all ignored"
102
103 # This proc tests that GDB can step into the function foo, exit it
104 # and skip the functions bar and baz.
105 proc step_foo_skip_bar_baz {} {
106 gdb_test "step" "foo \\(\\) at.*" "step and skip bar"
107 gdb_test "finish" ".*" "return from bar"
108 gdb_test "step" ".*test_skip_file_and_function.*" "step and skip baz"
109 }
110
111 # Now remove skip.c from the skiplist. Our first step should take us
112 # into foo(), and our second step should take us to the next line in main().
113
114 with_test_prefix "step after deleting 1" {
115 gdb_test "skip delete 1"
116 # Check that entry 1 is missing from |info skip|
117 gdb_test "info skip" \
118 [multi_line "Num\\s+Enb\\s+Glob\\s+File\\s+RE\\s+Function" \
119 "2\\s+y\\s+n\\s+<none>\\s+n\\s+main" \
120 "3\\s+y\\s+n\\s+$srcfile1\\s+n\\s+<none>" \
121 "4\\s+y\\s+n\\s+<none>\\s+n\\s+baz"] \
122 "info skip (delete 1)"
123
124 if ![runto_main] {
125 return
126 }
127
128 step_foo_skip_bar_baz
129 }
130
131 # Test that we step into foo(), then into bar(), but not into baz().
132 proc step_bar_foo_skip_baz {} {
133 gdb_test "step" "bar \\(\\) at.*" "step into bar"
134 gdb_test "finish" ".*" "return from bar"
135
136 # With at least gcc 6.5.0 and 9.2.0, we jump once back to main
137 # before entering foo here. If that happens try to step a second
138 # time.
139 set stepped_again 0
140 gdb_test_multiple "step" "step into foo" {
141 -re -wrap "foo \\(\\) at.*" {
142 pass $gdb_test_name
143 }
144 -re -wrap "main \\(\\) at .*" {
145 if {!$stepped_again} {
146 set stepped_again 1
147 send_gdb "step\n"
148 }
149 exp_continue
150 }
151 }
152
153 gdb_test "finish" ".*" "Return from foo"
154 gdb_test "step" ".*test_skip_file_and_function.*" "step and skip baz"
155 }
156
157 # Now disable the skiplist entry for skip1.c. We should now
158 # step into foo(), then into bar(), but not into baz().
159
160 with_test_prefix "step after disabling 3" {
161 gdb_test "skip disable 3"
162 # Is entry 3 disabled in |info skip|?
163 gdb_test "info skip 3" \
164 "3\\s+n\\s+n\\s+$srcfile1\\s+n\\s+<none>\\s*" \
165 "info skip shows entry as disabled"
166
167 if ![runto_main] {
168 return
169 }
170
171 step_bar_foo_skip_baz
172 }
173
174 # Enable skiplist entry 3 and make sure we step over it like before.
175
176 with_test_prefix "step after enable 3" {
177 gdb_test "skip enable 3"
178 # Is entry 3 enabled in |info skip|?
179 gdb_test "info skip 3" \
180 "3\\s+y\\s+n\\s+$srcfile1\\s+n\\s+<none>\\s*" \
181 "info skip shows entry as enabled"
182
183 if ![runto_main] {
184 return
185 }
186
187 step_foo_skip_bar_baz
188 }
189
190 # Admin tests (disable,enable,delete).
191
192 with_test_prefix "admin" {
193 gdb_test "skip disable"
194 gdb_test "info skip" \
195 [multi_line "Num\\s+Enb\\s+Glob\\s+File\\s+RE\\s+Function" \
196 "2\\s+n\\s+n\\s+<none>\\s+n\\s+main" \
197 "3\\s+n\\s+n\\s+$srcfile1\\s+n\\s+<none>" \
198 "4\\s+n\\s+n\\s+<none>\\s+n\\s+baz"] \
199 "info skip after disabling all"
200
201 gdb_test "skip enable"
202 gdb_test "info skip" \
203 [multi_line "Num\\s+Enb\\s+Glob\\s+File\\s+RE\\s+Function" \
204 "2\\s+y\\s+n\\s+<none>\\s+n\\s+main" \
205 "3\\s+y\\s+n\\s+$srcfile1\\s+n\\s+<none>" \
206 "4\\s+y\\s+n\\s+<none>\\s+n\\s+baz"] \
207 "info skip after enabling all"
208
209 gdb_test "skip disable 4 2-3"
210 gdb_test "info skip" \
211 [multi_line "Num\\s+Enb\\s+Glob\\s+File\\s+RE\\s+Function" \
212 "2\\s+n\\s+n\\s+<none>\\s+n\\s+main" \
213 "3\\s+n\\s+n\\s+$srcfile1\\s+n\\s+<none>" \
214 "4\\s+n\\s+n\\s+<none>\\s+n\\s+baz"] \
215 "info skip after disabling 4 2-3"
216
217 gdb_test "skip enable 2-3"
218 gdb_test "info skip" \
219 [multi_line "Num\\s+Enb\\s+Glob\\s+File\\s+RE\\s+Function" \
220 "2\\s+y\\s+n\\s+<none>\\s+n\\s+main" \
221 "3\\s+y\\s+n\\s+$srcfile1\\s+n\\s+<none>" \
222 "4\\s+n\\s+n\\s+<none>\\s+n\\s+baz"] \
223 "info skip after enabling 2-3"
224
225 gdb_test "info skip 2-3" \
226 [multi_line "Num\\s+Enb\\s+Glob\\s+File\\s+RE\\s+Function" \
227 "2\\s+y\\s+n\\s+<none>\\s+n\\s+main" \
228 "3\\s+y\\s+n\\s+$srcfile1\\s+n\\s+<none>"]
229
230 gdb_test "skip delete 2 3"
231 gdb_test "info skip" \
232 [multi_line "Num\\s+Enb\\s+Glob\\s+File\\s+RE\\s+Function" \
233 "4\\s+n\\s+n\\s+<none>\\s+n\\s+baz"] \
234 "info skip after deleting 2 3"
235
236 gdb_test "skip delete"
237 gdb_test "info skip" "Not skipping any files or functions\." \
238 "info skip after deleting all"
239 }
240
241 # Now test skip -fi, etc.
242
243 # Create a skiplist entry for a specified file and function.
244 gdb_test "skip -fi skip1.c" "File .*$srcfile1 will be skipped when stepping\."
245 gdb_test "skip -gfi sk*1.c" "File\\(s\\) sk\\*1.c will be skipped when stepping\."
246 gdb_test "skip -fu baz" "Function baz will be skipped when stepping\."
247 gdb_test "skip -rfu ^b.z$" "Function\\(s\\) \\^b\\.z\\$ will be skipped when stepping."
248
249 with_test_prefix "step using -fi" {
250 if ![runto_main] {
251 return
252 }
253
254 gdb_test_no_output "skip disable"
255 gdb_test_no_output "skip enable 5"
256 step_foo_skip_bar_baz
257 }
258
259 with_test_prefix "step using -gfi" {
260 if ![runto_main] {
261 return
262 }
263
264 gdb_test_no_output "skip disable"
265 gdb_test_no_output "skip enable 6"
266 step_foo_skip_bar_baz
267 }
268
269 with_test_prefix "step using -fu for baz" {
270 if ![runto_main] {
271 return
272 }
273
274 gdb_test_no_output "skip disable"
275 gdb_test_no_output "skip enable 7"
276
277 step_bar_foo_skip_baz
278 }
279
280 with_test_prefix "step using -rfu for baz" {
281 if ![runto_main] {
282 return
283 }
284
285 gdb_test_no_output "skip disable"
286 gdb_test_no_output "skip enable 8"
287
288 step_bar_foo_skip_baz
289 }
290
291 # Test -fi + -fu.
292
293 with_test_prefix "step using -fi + -fu" {
294 gdb_test_no_output "skip delete"
295
296 if ![runto test_skip_file_and_function] {
297 return
298 }
299
300 gdb_test "skip -fi skip1.c -fu test_skip" \
301 "Function test_skip in file skip1.c will be skipped when stepping\."
302 # Verify we can step into skip.c:test_skip but not skip1.c:test_skip.
303 gdb_test "step" "test_skip \\(\\) at.*" "step 1"
304 gdb_test "step" "test_skip_file_and_function \\(\\) at.*" "step 2"; # Return from test_skip()
305 gdb_test "step" "skip1_test_skip_file_and_function \\(\\) at.*" "step 3"
306 gdb_test "step" ".*" "step 4"; # Skip over test_skip()
307 gdb_test "step" "test_skip_file_and_function \\(\\) at.*" "step 5"; # Return from skip1_test_skip_file_and_function()
308 }
309
310 with_test_prefix "skip delete completion" {
311 global binfile
312 clean_restart "${binfile}"
313 if ![runto_main] {
314 return
315 }
316
317 # Create a bunch of skips, don't care what they are.
318 for {set i 0} {$i < 12} {incr i} {
319 gdb_test "skip" ".*" "add skip $i"
320 }
321
322 set all_numbers { "1" "10" "11" "12" "2" "3" "4" "5" "6" "7" "8" "9" }
323
324 # Test completing single numbers.
325 test_gdb_complete_multiple "skip delete " "" "" $all_numbers
326 test_gdb_complete_multiple "skip delete " "1" "" { "1" "10" "11" "12" }
327 test_gdb_complete_multiple "skip delete 2 " "" "" $all_numbers
328 test_gdb_complete_unique "skip delete 11" "skip delete 11"
329
330 # Test completing ranges.
331 test_gdb_complete_multiple "skip delete 2-" "" "" $all_numbers
332 test_gdb_complete_unique "skip delete 2-5" "skip delete 2-5"
333
334 # Test cases with no completion.
335 test_gdb_complete_none "skip delete 123"
336 test_gdb_complete_none "skip delete a1"
337 test_gdb_complete_none "skip delete 2-33"
338 }
339