| 1 | # Copyright 2011-2019 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 | fail "can't run to main" |
| 54 | return |
| 55 | } |
| 56 | |
| 57 | # Test |info skip| with an empty skiplist. |
| 58 | |
| 59 | gdb_test "info skip" "Not skipping any files or functions\." "info skip empty" |
| 60 | |
| 61 | # Create a skiplist entry for the current file and function. |
| 62 | |
| 63 | gdb_test "skip file" "File .*$srcfile will be skipped when stepping\." "skip file ($srcfile)" |
| 64 | gdb_test "skip" "Function main will be skipped when stepping\." "skip (main)" |
| 65 | |
| 66 | # Create a skiplist entry for a specified file and function. |
| 67 | |
| 68 | gdb_test "skip file skip1.c" "File .*$srcfile1 will be skipped when stepping\." |
| 69 | gdb_test "skip function baz" "Function baz will be skipped when stepping\." |
| 70 | |
| 71 | # Test bad skiplist entry modification commands |
| 72 | |
| 73 | gdb_test "skip enable 999" "No skiplist entries found with number 999." |
| 74 | gdb_test "skip disable 999" "No skiplist entries found with number 999." |
| 75 | gdb_test "skip delete 999" "No skiplist entries found with number 999." |
| 76 | gdb_test "skip enable a" "Arguments must be numbers or '\\$' variables." |
| 77 | gdb_test "skip disable a" "Arguments must be numbers or '\\$' variables." |
| 78 | gdb_test "skip delete a" "Arguments must be numbers or '\\$' variables." |
| 79 | |
| 80 | # Ask for info on a skiplist entry which doesn't exist. |
| 81 | |
| 82 | gdb_test "info skip 999" "No skiplist entries found with number 999." |
| 83 | |
| 84 | # Does |info skip| look right? |
| 85 | |
| 86 | gdb_test "info skip" \ |
| 87 | "Num\\s+Enb\\s+Glob\\s+File\\s+RE\\s+Function\\s* |
| 88 | 1\\s+y\\s+n\\s+.*$srcfile\\s+n\\s+<none>\\s* |
| 89 | 2\\s+y\\s+n\\s+<none>\\s+n\\s+main\\s* |
| 90 | 3\\s+y\\s+n\\s+$srcfile1\\s+n\\s+<none>\\s* |
| 91 | 4\\s+y\\s+n\\s+<none>\\s+n\\s+baz\\s*" |
| 92 | |
| 93 | # Right now, we have an outstanding skiplist entry on both source |
| 94 | # files, so when we step into the first line in main(), we should step |
| 95 | # right over it and go to the second line of main(). |
| 96 | |
| 97 | if ![runto_main] { |
| 98 | fail "can't run to main" |
| 99 | return |
| 100 | } |
| 101 | |
| 102 | gdb_test "step" ".*" "step in the main" |
| 103 | gdb_test "bt" "\\s*\\#0\\s+main.*" "step after all ignored" |
| 104 | |
| 105 | # Now remove skip.c from the skiplist. Our first step should take us |
| 106 | # into foo(), and our second step should take us to the next line in main(). |
| 107 | |
| 108 | with_test_prefix "step after deleting 1" { |
| 109 | gdb_test "skip delete 1" |
| 110 | # Check that entry 1 is missing from |info skip| |
| 111 | gdb_test "info skip" \ |
| 112 | "Num\\s+Enb\\s+Glob\\s+File\\s+RE\\s+Function\\s* |
| 113 | 2\\s+y\\s+n\\s+<none>\\s+n\\s+main\\s* |
| 114 | 3\\s+y\\s+n\\s+$srcfile1\\s+n\\s+<none>\\s* |
| 115 | 4\\s+y\\s+n\\s+<none>\\s+n\\s+baz\\s*" \ |
| 116 | "info skip (delete 1)" |
| 117 | |
| 118 | if ![runto_main] { |
| 119 | fail "can't run to main" |
| 120 | return |
| 121 | } |
| 122 | |
| 123 | gdb_test "step" "foo \\(\\) at.*" "step 1" |
| 124 | gdb_test "step" ".*" "step 2" ; # Return from foo() |
| 125 | gdb_test "step" "main \\(\\) at.*" "step 3" |
| 126 | } |
| 127 | |
| 128 | # Now disable the skiplist entry for skip1.c. We should now |
| 129 | # step into foo(), then into bar(), but not into baz(). |
| 130 | |
| 131 | with_test_prefix "step after disabling 3" { |
| 132 | gdb_test "skip disable 3" |
| 133 | # Is entry 3 disabled in |info skip|? |
| 134 | gdb_test "info skip 3" \ |
| 135 | "3\\s+n\\s+n\\s+$srcfile1\\s+n\\s+<none>\\s*" \ |
| 136 | "info skip shows entry as disabled" |
| 137 | |
| 138 | if ![runto_main] { |
| 139 | fail "can't run to main" |
| 140 | return |
| 141 | } |
| 142 | |
| 143 | gdb_test "step" "bar \\(\\) at.*" "step 1" |
| 144 | gdb_test "step" ".*" "step 2"; # Return from bar() |
| 145 | # With gcc 9.2.0 we jump once back to main before entering foo here. |
| 146 | # If that happens try to step a second time. |
| 147 | gdb_test "step" "foo \\(\\) at.*" "step 3" "main \\(\\) at .*" "step" |
| 148 | gdb_test "step" ".*" "step 4"; # Return from foo() |
| 149 | gdb_test "step" "main \\(\\) at.*" "step 5" |
| 150 | } |
| 151 | |
| 152 | # Enable skiplist entry 3 and make sure we step over it like before. |
| 153 | |
| 154 | with_test_prefix "step after enable 3" { |
| 155 | gdb_test "skip enable 3" |
| 156 | # Is entry 3 enabled in |info skip|? |
| 157 | gdb_test "info skip 3" \ |
| 158 | "3\\s+y\\s+n\\s+$srcfile1\\s+n\\s+<none>\\s*" \ |
| 159 | "info skip shows entry as enabled" |
| 160 | |
| 161 | if ![runto_main] { |
| 162 | fail "can't run to main" |
| 163 | return |
| 164 | } |
| 165 | |
| 166 | gdb_test "step" "foo \\(\\) at.*" "step 1" |
| 167 | gdb_test "step" ".*" "step 2"; # Return from foo() |
| 168 | gdb_test "step" "main \\(\\) at.*" "step 3" |
| 169 | } |
| 170 | |
| 171 | # Admin tests (disable,enable,delete). |
| 172 | |
| 173 | with_test_prefix "admin" { |
| 174 | gdb_test "skip disable" |
| 175 | gdb_test "info skip" \ |
| 176 | "Num\\s+Enb\\s+Glob\\s+File\\s+RE\\s+Function\\s* |
| 177 | 2\\s+n\\s+n\\s+<none>\\s+n\\s+main\\s* |
| 178 | 3\\s+n\\s+n\\s+$srcfile1\\s+n\\s+<none>\\s* |
| 179 | 4\\s+n\\s+n\\s+<none>\\s+n\\s+baz\\s*" \ |
| 180 | "info skip after disabling all" |
| 181 | |
| 182 | gdb_test "skip enable" |
| 183 | gdb_test "info skip" \ |
| 184 | "Num\\s+Enb\\s+Glob\\s+File\\s+RE\\s+Function\\s* |
| 185 | 2\\s+y\\s+n\\s+<none>\\s+n\\s+main\\s* |
| 186 | 3\\s+y\\s+n\\s+$srcfile1\\s+n\\s+<none>\\s* |
| 187 | 4\\s+y\\s+n\\s+<none>\\s+n\\s+baz\\s*" \ |
| 188 | "info skip after enabling all" |
| 189 | |
| 190 | gdb_test "skip disable 4 2-3" |
| 191 | gdb_test "info skip" \ |
| 192 | "Num\\s+Enb\\s+Glob\\s+File\\s+RE\\s+Function\\s* |
| 193 | 2\\s+n\\s+n\\s+<none>\\s+n\\s+main\\s* |
| 194 | 3\\s+n\\s+n\\s+$srcfile1\\s+n\\s+<none>\\s* |
| 195 | 4\\s+n\\s+n\\s+<none>\\s+n\\s+baz\\s*" \ |
| 196 | "info skip after disabling 4 2-3" |
| 197 | |
| 198 | gdb_test "skip enable 2-3" |
| 199 | gdb_test "info skip" \ |
| 200 | "Num\\s+Enb\\s+Glob\\s+File\\s+RE\\s+Function\\s* |
| 201 | 2\\s+y\\s+n\\s+<none>\\s+n\\s+main\\s* |
| 202 | 3\\s+y\\s+n\\s+$srcfile1\\s+n\\s+<none>\\s* |
| 203 | 4\\s+n\\s+n\\s+<none>\\s+n\\s+baz\\s*" \ |
| 204 | "info skip after enabling 2-3" |
| 205 | |
| 206 | gdb_test "info skip 2-3" \ |
| 207 | "Num\\s+Enb\\s+Glob\\s+File\\s+RE\\s+Function\\s* |
| 208 | 2\\s+y\\s+n\\s+<none>\\s+n\\s+main\\s* |
| 209 | 3\\s+y\\s+n\\s+$srcfile1\\s+n\\s+<none>\\s*" |
| 210 | |
| 211 | gdb_test "skip delete 2 3" |
| 212 | gdb_test "info skip" \ |
| 213 | "Num\\s+Enb\\s+Glob\\s+File\\s+RE\\s+Function\\s* |
| 214 | 4\\s+n\\s+n\\s+<none>\\s+n\\s+baz\\s*" \ |
| 215 | "info skip after deleting 2 3" |
| 216 | |
| 217 | gdb_test "skip delete" |
| 218 | gdb_test "info skip" "Not skipping any files or functions\." \ |
| 219 | "info skip after deleting all" |
| 220 | } |
| 221 | |
| 222 | # Now test skip -fi, etc. |
| 223 | |
| 224 | # Create a skiplist entry for a specified file and function. |
| 225 | gdb_test "skip -fi skip1.c" "File .*$srcfile1 will be skipped when stepping\." |
| 226 | gdb_test "skip -gfi sk*1.c" "File\\(s\\) sk\\*1.c will be skipped when stepping\." |
| 227 | gdb_test "skip -fu baz" "Function baz will be skipped when stepping\." |
| 228 | gdb_test "skip -rfu ^b.z$" "Function\\(s\\) \\^b\\.z\\$ will be skipped when stepping." |
| 229 | |
| 230 | with_test_prefix "step using -fi" { |
| 231 | if ![runto_main] { |
| 232 | fail "can't run to main" |
| 233 | return |
| 234 | } |
| 235 | |
| 236 | gdb_test_no_output "skip disable" |
| 237 | gdb_test_no_output "skip enable 5" |
| 238 | gdb_test "step" "foo \\(\\) at.*" "step 1" |
| 239 | gdb_test "step" ".*" "step 2"; # Return from foo() |
| 240 | gdb_test "step" "main \\(\\) at.*" "step 3" |
| 241 | } |
| 242 | |
| 243 | with_test_prefix "step using -gfi" { |
| 244 | if ![runto_main] { |
| 245 | fail "can't run to main" |
| 246 | return |
| 247 | } |
| 248 | |
| 249 | gdb_test_no_output "skip disable" |
| 250 | gdb_test_no_output "skip enable 6" |
| 251 | gdb_test "step" "foo \\(\\) at.*" "step 1" |
| 252 | gdb_test "step" ".*" "step 2"; # Return from foo() |
| 253 | gdb_test "step" "main \\(\\) at.*" "step 3" |
| 254 | } |
| 255 | |
| 256 | with_test_prefix "step using -fu for baz" { |
| 257 | if ![runto_main] { |
| 258 | fail "can't run to main" |
| 259 | return |
| 260 | } |
| 261 | |
| 262 | gdb_test_no_output "skip disable" |
| 263 | gdb_test_no_output "skip enable 7" |
| 264 | gdb_test "step" "bar \\(\\) at.*" "step 1" |
| 265 | gdb_test "step" ".*" "step 2"; # Return from bar() |
| 266 | # With gcc 9.2.0 we jump once back to main before entering foo here. |
| 267 | # If that happens try to step a second time. |
| 268 | gdb_test "step" "foo \\(\\) at.*" "step 3" "main \\(\\) at.*" "step" |
| 269 | gdb_test "step" ".*" "step 4"; # Return from foo() |
| 270 | gdb_test "step" "main \\(\\) at.*" "step 5" |
| 271 | } |
| 272 | |
| 273 | with_test_prefix "step using -rfu for baz" { |
| 274 | if ![runto_main] { |
| 275 | fail "can't run to main" |
| 276 | return |
| 277 | } |
| 278 | |
| 279 | gdb_test_no_output "skip disable" |
| 280 | gdb_test_no_output "skip enable 8" |
| 281 | gdb_test "step" "bar \\(\\) at.*" "step 1" |
| 282 | gdb_test "step" ".*" "step 2"; # Return from bar() |
| 283 | # With gcc 9.2.0 we jump once back to main before entering foo here. |
| 284 | # If that happens try to step a second time. |
| 285 | gdb_test "step" "foo \\(\\) at.*" "step 3" "main \\(\\) at.*" "step" |
| 286 | gdb_test "step" ".*" "step 4"; # Return from foo() |
| 287 | gdb_test "step" "main \\(\\) at.*" "step 5" |
| 288 | } |
| 289 | |
| 290 | # Test -fi + -fu. |
| 291 | |
| 292 | with_test_prefix "step using -fi + -fu" { |
| 293 | gdb_test_no_output "skip delete" |
| 294 | |
| 295 | if ![runto test_skip_file_and_function no-message] { |
| 296 | fail "can't run to 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 | fail "can't run to main" |
| 315 | return |
| 316 | } |
| 317 | |
| 318 | # Create a bunch of skips, don't care what they are. |
| 319 | for {set i 0} {$i < 12} {incr i} { |
| 320 | gdb_test "skip" ".*" "add skip $i" |
| 321 | } |
| 322 | |
| 323 | set all_numbers { "1" "10" "11" "12" "2" "3" "4" "5" "6" "7" "8" "9" } |
| 324 | |
| 325 | # Test completing single numbers. |
| 326 | test_gdb_complete_multiple "skip delete " "" "" $all_numbers |
| 327 | test_gdb_complete_multiple "skip delete " "1" "" { "1" "10" "11" "12" } |
| 328 | test_gdb_complete_multiple "skip delete 2 " "" "" $all_numbers |
| 329 | test_gdb_complete_unique "skip delete 11" "skip delete 11" |
| 330 | |
| 331 | # Test completing ranges. |
| 332 | test_gdb_complete_multiple "skip delete 2-" "" "" $all_numbers |
| 333 | test_gdb_complete_unique "skip delete 2-5" "skip delete 2-5" |
| 334 | |
| 335 | # Test cases with no completion. |
| 336 | test_gdb_complete_none "skip delete 123" |
| 337 | test_gdb_complete_none "skip delete a1" |
| 338 | test_gdb_complete_none "skip delete 2-33" |
| 339 | } |
| 340 | |