Commit | Line | Data |
---|---|---|
1bfeeb0f JL |
1 | /* Skipping uninteresting files and functions while stepping. |
2 | ||
61baf725 | 3 | Copyright (C) 2011-2017 Free Software Foundation, Inc. |
1bfeeb0f JL |
4 | |
5 | This program is free software; you can redistribute it and/or modify | |
6 | it under the terms of the GNU General Public License as published by | |
7 | the Free Software Foundation; either version 3 of the License, or | |
8 | (at your option) any later version. | |
9 | ||
10 | This program is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | GNU General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU General Public License | |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
17 | ||
18 | #include "defs.h" | |
19 | #include "skip.h" | |
20 | #include "value.h" | |
21 | #include "valprint.h" | |
22 | #include "ui-out.h" | |
1bfeeb0f JL |
23 | #include "symtab.h" |
24 | #include "gdbcmd.h" | |
25 | #include "command.h" | |
26 | #include "completer.h" | |
27 | #include "stack.h" | |
28 | #include "cli/cli-utils.h" | |
29 | #include "arch-utils.h" | |
30 | #include "linespec.h" | |
31 | #include "objfiles.h" | |
1bfeeb0f | 32 | #include "breakpoint.h" /* for get_sal_arch () */ |
05cba821 JK |
33 | #include "source.h" |
34 | #include "filenames.h" | |
cce0e923 DE |
35 | #include "fnmatch.h" |
36 | #include "gdb_regex.h" | |
2d7cc5c7 | 37 | #include "common/gdb_optional.h" |
1bfeeb0f JL |
38 | |
39 | struct skiplist_entry | |
40 | { | |
41 | int number; | |
42 | ||
cce0e923 DE |
43 | /* Non-zero if FILE is a glob-style pattern. |
44 | Otherewise it is the plain file name (possibly with directories). */ | |
45 | int file_is_glob; | |
46 | ||
47 | /* The name of the file or NULL. | |
1bfeeb0f | 48 | The skiplist entry owns this pointer. */ |
cce0e923 DE |
49 | char *file; |
50 | ||
51 | /* Non-zero if FUNCTION is a regexp. | |
52 | Otherwise it is a plain function name (possibly with arguments, | |
53 | for C++). */ | |
54 | int function_is_regexp; | |
1bfeeb0f | 55 | |
cce0e923 | 56 | /* The name of the function or NULL. |
1bfeeb0f | 57 | The skiplist entry owns this pointer. */ |
cce0e923 DE |
58 | char *function; |
59 | ||
60 | /* If this is a function regexp, the compiled form. */ | |
2d7cc5c7 | 61 | gdb::optional<compiled_regex> compiled_function_regexp; |
1bfeeb0f | 62 | |
1bfeeb0f | 63 | int enabled; |
1bfeeb0f JL |
64 | |
65 | struct skiplist_entry *next; | |
66 | }; | |
67 | ||
1bfeeb0f | 68 | static void add_skiplist_entry (struct skiplist_entry *e); |
1bfeeb0f JL |
69 | |
70 | static struct skiplist_entry *skiplist_entry_chain; | |
71 | static int skiplist_entry_count; | |
72 | ||
73 | #define ALL_SKIPLIST_ENTRIES(E) \ | |
74 | for (E = skiplist_entry_chain; E; E = E->next) | |
75 | ||
76 | #define ALL_SKIPLIST_ENTRIES_SAFE(E,TMP) \ | |
77 | for (E = skiplist_entry_chain; \ | |
78 | E ? (TMP = E->next, 1) : 0; \ | |
79 | E = TMP) | |
80 | ||
cce0e923 DE |
81 | /* Create a skip object. */ |
82 | ||
83 | static struct skiplist_entry * | |
84 | make_skip_entry (int file_is_glob, const char *file, | |
85 | int function_is_regexp, const char *function) | |
86 | { | |
87 | struct skiplist_entry *e = XCNEW (struct skiplist_entry); | |
88 | ||
89 | gdb_assert (file != NULL || function != NULL); | |
90 | if (file_is_glob) | |
91 | gdb_assert (file != NULL); | |
92 | if (function_is_regexp) | |
93 | gdb_assert (function != NULL); | |
94 | ||
95 | if (file != NULL) | |
96 | e->file = xstrdup (file); | |
97 | if (function != NULL) | |
98 | e->function = xstrdup (function); | |
99 | e->file_is_glob = file_is_glob; | |
100 | e->function_is_regexp = function_is_regexp; | |
101 | e->enabled = 1; | |
102 | ||
103 | return e; | |
104 | } | |
105 | ||
106 | /* Free a skiplist entry. */ | |
107 | ||
108 | static void | |
109 | free_skiplist_entry (struct skiplist_entry *e) | |
110 | { | |
111 | xfree (e->file); | |
112 | xfree (e->function); | |
cce0e923 DE |
113 | xfree (e); |
114 | } | |
115 | ||
116 | /* Wrapper to free_skiplist_entry for use as a cleanup. */ | |
117 | ||
118 | static void | |
119 | free_skiplist_entry_cleanup (void *e) | |
120 | { | |
121 | free_skiplist_entry ((struct skiplist_entry *) e); | |
122 | } | |
123 | ||
124 | /* Create a cleanup to free skiplist entry E. */ | |
125 | ||
126 | static struct cleanup * | |
127 | make_free_skiplist_entry_cleanup (struct skiplist_entry *e) | |
128 | { | |
129 | return make_cleanup (free_skiplist_entry_cleanup, e); | |
130 | } | |
131 | ||
1bfeeb0f JL |
132 | static void |
133 | skip_file_command (char *arg, int from_tty) | |
134 | { | |
05cba821 | 135 | struct symtab *symtab; |
3d745be3 | 136 | const char *filename = NULL; |
1bfeeb0f JL |
137 | |
138 | /* If no argument was given, try to default to the last | |
139 | displayed codepoint. */ | |
3d745be3 | 140 | if (arg == NULL) |
1bfeeb0f JL |
141 | { |
142 | symtab = get_last_displayed_symtab (); | |
3d745be3 | 143 | if (symtab == NULL) |
1bfeeb0f | 144 | error (_("No default file now.")); |
05cba821 JK |
145 | |
146 | /* It is not a typo, symtab_to_filename_for_display woule be needlessly | |
147 | ambiguous. */ | |
148 | filename = symtab_to_fullname (symtab); | |
1bfeeb0f JL |
149 | } |
150 | else | |
cce0e923 | 151 | filename = arg; |
1bfeeb0f | 152 | |
cce0e923 | 153 | add_skiplist_entry (make_skip_entry (0, filename, 0, NULL)); |
1bfeeb0f JL |
154 | |
155 | printf_filtered (_("File %s will be skipped when stepping.\n"), filename); | |
156 | } | |
157 | ||
cce0e923 DE |
158 | /* Create a skiplist entry for the given function NAME and add it to the |
159 | list. */ | |
160 | ||
1bfeeb0f | 161 | static void |
cce0e923 | 162 | skip_function (const char *name) |
1bfeeb0f | 163 | { |
cce0e923 DE |
164 | add_skiplist_entry (make_skip_entry (0, NULL, 0, name)); |
165 | ||
166 | printf_filtered (_("Function %s will be skipped when stepping.\n"), name); | |
167 | } | |
1bfeeb0f | 168 | |
cce0e923 DE |
169 | static void |
170 | skip_function_command (char *arg, int from_tty) | |
171 | { | |
1bfeeb0f | 172 | /* Default to the current function if no argument is given. */ |
3d745be3 | 173 | if (arg == NULL) |
1bfeeb0f | 174 | { |
cce0e923 | 175 | const char *name = NULL; |
1bfeeb0f | 176 | CORE_ADDR pc; |
3d745be3 | 177 | |
1bfeeb0f JL |
178 | if (!last_displayed_sal_is_valid ()) |
179 | error (_("No default function now.")); | |
180 | ||
181 | pc = get_last_displayed_addr (); | |
85817405 | 182 | if (!find_pc_partial_function (pc, &name, NULL, NULL)) |
1bfeeb0f JL |
183 | { |
184 | error (_("No function found containing current program point %s."), | |
185 | paddress (get_current_arch (), pc)); | |
186 | } | |
85817405 | 187 | skip_function (name); |
cce0e923 | 188 | return; |
1bfeeb0f | 189 | } |
cce0e923 DE |
190 | |
191 | skip_function (arg); | |
192 | } | |
193 | ||
194 | /* Compile the regexp in E. | |
195 | An error is thrown if there's an error. | |
196 | MESSAGE is used as a prefix of the error message. */ | |
197 | ||
198 | static void | |
199 | compile_skip_regexp (struct skiplist_entry *e, const char *message) | |
200 | { | |
cce0e923 DE |
201 | int flags = REG_NOSUB; |
202 | ||
203 | #ifdef REG_EXTENDED | |
204 | flags |= REG_EXTENDED; | |
205 | #endif | |
206 | ||
207 | gdb_assert (e->function_is_regexp && e->function != NULL); | |
2d7cc5c7 | 208 | e->compiled_function_regexp.emplace (e->function, flags, message); |
cce0e923 DE |
209 | } |
210 | ||
211 | /* Process "skip ..." that does not match "skip file" or "skip function". */ | |
212 | ||
213 | static void | |
214 | skip_command (char *arg, int from_tty) | |
215 | { | |
216 | const char *file = NULL; | |
217 | const char *gfile = NULL; | |
218 | const char *function = NULL; | |
219 | const char *rfunction = NULL; | |
cce0e923 DE |
220 | struct skiplist_entry *e; |
221 | int i; | |
222 | ||
223 | if (arg == NULL) | |
224 | { | |
225 | skip_function_command (arg, from_tty); | |
226 | return; | |
227 | } | |
228 | ||
773a1edc | 229 | gdb_argv argv (arg); |
cce0e923 DE |
230 | |
231 | for (i = 0; argv[i] != NULL; ++i) | |
232 | { | |
233 | const char *p = argv[i]; | |
234 | const char *value = argv[i + 1]; | |
235 | ||
236 | if (strcmp (p, "-fi") == 0 | |
237 | || strcmp (p, "-file") == 0) | |
238 | { | |
239 | if (value == NULL) | |
240 | error (_("Missing value for %s option."), p); | |
241 | file = value; | |
242 | ++i; | |
243 | } | |
244 | else if (strcmp (p, "-gfi") == 0 | |
245 | || strcmp (p, "-gfile") == 0) | |
246 | { | |
247 | if (value == NULL) | |
248 | error (_("Missing value for %s option."), p); | |
249 | gfile = value; | |
250 | ++i; | |
251 | } | |
252 | else if (strcmp (p, "-fu") == 0 | |
253 | || strcmp (p, "-function") == 0) | |
254 | { | |
255 | if (value == NULL) | |
256 | error (_("Missing value for %s option."), p); | |
257 | function = value; | |
258 | ++i; | |
259 | } | |
260 | else if (strcmp (p, "-rfu") == 0 | |
261 | || strcmp (p, "-rfunction") == 0) | |
262 | { | |
263 | if (value == NULL) | |
264 | error (_("Missing value for %s option."), p); | |
265 | rfunction = value; | |
266 | ++i; | |
267 | } | |
268 | else if (*p == '-') | |
269 | error (_("Invalid skip option: %s"), p); | |
270 | else if (i == 0) | |
271 | { | |
272 | /* Assume the user entered "skip FUNCTION-NAME". | |
273 | FUNCTION-NAME may be `foo (int)', and therefore we pass the | |
274 | complete original arg to skip_function command as if the user | |
275 | typed "skip function arg". */ | |
cce0e923 | 276 | skip_function_command (arg, from_tty); |
1bfeeb0f JL |
277 | return; |
278 | } | |
cce0e923 DE |
279 | else |
280 | error (_("Invalid argument: %s"), p); | |
281 | } | |
282 | ||
283 | if (file != NULL && gfile != NULL) | |
284 | error (_("Cannot specify both -file and -gfile.")); | |
285 | ||
286 | if (function != NULL && rfunction != NULL) | |
287 | error (_("Cannot specify both -function and -rfunction.")); | |
288 | ||
289 | /* This shouldn't happen as "skip" by itself gets punted to | |
290 | skip_function_command. */ | |
291 | gdb_assert (file != NULL || gfile != NULL | |
292 | || function != NULL || rfunction != NULL); | |
293 | ||
294 | e = make_skip_entry (gfile != NULL, file ? file : gfile, | |
295 | rfunction != NULL, function ? function : rfunction); | |
296 | if (rfunction != NULL) | |
297 | { | |
298 | struct cleanup *rf_cleanups = make_free_skiplist_entry_cleanup (e); | |
1bfeeb0f | 299 | |
cce0e923 DE |
300 | compile_skip_regexp (e, _("regexp")); |
301 | discard_cleanups (rf_cleanups); | |
1bfeeb0f | 302 | } |
cce0e923 DE |
303 | add_skiplist_entry (e); |
304 | ||
305 | /* I18N concerns drive some of the choices here (we can't piece together | |
306 | the output too much). OTOH we want to keep this simple. Therefore the | |
307 | only polish we add to the output is to append "(s)" to "File" or | |
308 | "Function" if they're a glob/regexp. */ | |
309 | { | |
310 | const char *file_to_print = file != NULL ? file : gfile; | |
311 | const char *function_to_print = function != NULL ? function : rfunction; | |
312 | const char *file_text = gfile != NULL ? _("File(s)") : _("File"); | |
313 | const char *lower_file_text = gfile != NULL ? _("file(s)") : _("file"); | |
314 | const char *function_text | |
315 | = rfunction != NULL ? _("Function(s)") : _("Function"); | |
316 | ||
317 | if (function_to_print == NULL) | |
318 | { | |
319 | printf_filtered (_("%s %s will be skipped when stepping.\n"), | |
320 | file_text, file_to_print); | |
321 | } | |
322 | else if (file_to_print == NULL) | |
323 | { | |
324 | printf_filtered (_("%s %s will be skipped when stepping.\n"), | |
325 | function_text, function_to_print); | |
326 | } | |
327 | else | |
328 | { | |
329 | printf_filtered (_("%s %s in %s %s will be skipped" | |
330 | " when stepping.\n"), | |
331 | function_text, function_to_print, | |
332 | lower_file_text, file_to_print); | |
333 | } | |
334 | } | |
1bfeeb0f JL |
335 | } |
336 | ||
337 | static void | |
338 | skip_info (char *arg, int from_tty) | |
339 | { | |
340 | struct skiplist_entry *e; | |
341 | int num_printable_entries = 0; | |
1bfeeb0f | 342 | struct value_print_options opts; |
1bfeeb0f JL |
343 | |
344 | get_user_print_options (&opts); | |
345 | ||
346 | /* Count the number of rows in the table and see if we need space for a | |
347 | 64-bit address anywhere. */ | |
348 | ALL_SKIPLIST_ENTRIES (e) | |
3d745be3 | 349 | if (arg == NULL || number_is_in_list (arg, e->number)) |
85817405 | 350 | num_printable_entries++; |
1bfeeb0f JL |
351 | |
352 | if (num_printable_entries == 0) | |
353 | { | |
3d745be3 | 354 | if (arg == NULL) |
112e8700 | 355 | current_uiout->message (_("Not skipping any files or functions.\n")); |
1bfeeb0f | 356 | else |
112e8700 SM |
357 | current_uiout->message ( |
358 | _("No skiplist entries found with number %s.\n"), arg); | |
1bfeeb0f JL |
359 | |
360 | return; | |
361 | } | |
362 | ||
4a2b031d TT |
363 | ui_out_emit_table table_emitter (current_uiout, 6, num_printable_entries, |
364 | "SkiplistTable"); | |
1bfeeb0f | 365 | |
112e8700 SM |
366 | current_uiout->table_header (5, ui_left, "number", "Num"); /* 1 */ |
367 | current_uiout->table_header (3, ui_left, "enabled", "Enb"); /* 2 */ | |
368 | current_uiout->table_header (4, ui_right, "regexp", "Glob"); /* 3 */ | |
369 | current_uiout->table_header (20, ui_left, "file", "File"); /* 4 */ | |
370 | current_uiout->table_header (2, ui_right, "regexp", "RE"); /* 5 */ | |
371 | current_uiout->table_header (40, ui_noalign, "function", "Function"); /* 6 */ | |
372 | current_uiout->table_body (); | |
1bfeeb0f JL |
373 | |
374 | ALL_SKIPLIST_ENTRIES (e) | |
375 | { | |
1bfeeb0f JL |
376 | |
377 | QUIT; | |
3d745be3 | 378 | if (arg != NULL && !number_is_in_list (arg, e->number)) |
1bfeeb0f JL |
379 | continue; |
380 | ||
2e783024 | 381 | ui_out_emit_tuple tuple_emitter (current_uiout, "blklst-entry"); |
112e8700 | 382 | current_uiout->field_int ("number", e->number); /* 1 */ |
1bfeeb0f | 383 | |
cce0e923 | 384 | if (e->enabled) |
112e8700 | 385 | current_uiout->field_string ("enabled", "y"); /* 2 */ |
1bfeeb0f | 386 | else |
112e8700 | 387 | current_uiout->field_string ("enabled", "n"); /* 2 */ |
1bfeeb0f | 388 | |
cce0e923 | 389 | if (e->file_is_glob) |
112e8700 | 390 | current_uiout->field_string ("regexp", "y"); /* 3 */ |
1bfeeb0f | 391 | else |
112e8700 | 392 | current_uiout->field_string ("regexp", "n"); /* 3 */ |
1bfeeb0f | 393 | |
112e8700 | 394 | current_uiout->field_string ("file", |
cce0e923 DE |
395 | e->file ? e->file : "<none>"); /* 4 */ |
396 | if (e->function_is_regexp) | |
112e8700 | 397 | current_uiout->field_string ("regexp", "y"); /* 5 */ |
cce0e923 | 398 | else |
112e8700 | 399 | current_uiout->field_string ("regexp", "n"); /* 5 */ |
cce0e923 | 400 | |
112e8700 SM |
401 | current_uiout->field_string ( |
402 | "function", e->function ? e->function : "<none>"); /* 6 */ | |
1bfeeb0f | 403 | |
112e8700 | 404 | current_uiout->text ("\n"); |
1bfeeb0f | 405 | } |
1bfeeb0f JL |
406 | } |
407 | ||
408 | static void | |
409 | skip_enable_command (char *arg, int from_tty) | |
410 | { | |
411 | struct skiplist_entry *e; | |
412 | int found = 0; | |
413 | ||
414 | ALL_SKIPLIST_ENTRIES (e) | |
3d745be3 | 415 | if (arg == NULL || number_is_in_list (arg, e->number)) |
1bfeeb0f JL |
416 | { |
417 | e->enabled = 1; | |
418 | found = 1; | |
419 | } | |
420 | ||
421 | if (!found) | |
422 | error (_("No skiplist entries found with number %s."), arg); | |
423 | } | |
424 | ||
425 | static void | |
426 | skip_disable_command (char *arg, int from_tty) | |
427 | { | |
428 | struct skiplist_entry *e; | |
429 | int found = 0; | |
430 | ||
431 | ALL_SKIPLIST_ENTRIES (e) | |
3d745be3 | 432 | if (arg == NULL || number_is_in_list (arg, e->number)) |
1bfeeb0f JL |
433 | { |
434 | e->enabled = 0; | |
435 | found = 1; | |
436 | } | |
437 | ||
438 | if (!found) | |
439 | error (_("No skiplist entries found with number %s."), arg); | |
440 | } | |
441 | ||
442 | static void | |
443 | skip_delete_command (char *arg, int from_tty) | |
444 | { | |
445 | struct skiplist_entry *e, *temp, *b_prev; | |
446 | int found = 0; | |
447 | ||
448 | b_prev = 0; | |
449 | ALL_SKIPLIST_ENTRIES_SAFE (e, temp) | |
3d745be3 | 450 | if (arg == NULL || number_is_in_list (arg, e->number)) |
1bfeeb0f | 451 | { |
3d745be3 | 452 | if (b_prev != NULL) |
1bfeeb0f JL |
453 | b_prev->next = e->next; |
454 | else | |
455 | skiplist_entry_chain = e->next; | |
456 | ||
cce0e923 | 457 | free_skiplist_entry (e); |
1bfeeb0f JL |
458 | found = 1; |
459 | } | |
460 | else | |
461 | { | |
462 | b_prev = e; | |
463 | } | |
464 | ||
465 | if (!found) | |
466 | error (_("No skiplist entries found with number %s."), arg); | |
467 | } | |
468 | ||
1bfeeb0f JL |
469 | /* Add the given skiplist entry to our list, and set the entry's number. */ |
470 | ||
471 | static void | |
472 | add_skiplist_entry (struct skiplist_entry *e) | |
473 | { | |
474 | struct skiplist_entry *e1; | |
475 | ||
476 | e->number = ++skiplist_entry_count; | |
477 | ||
478 | /* Add to the end of the chain so that the list of | |
479 | skiplist entries will be in numerical order. */ | |
480 | ||
481 | e1 = skiplist_entry_chain; | |
3d745be3 | 482 | if (e1 == NULL) |
1bfeeb0f JL |
483 | skiplist_entry_chain = e; |
484 | else | |
485 | { | |
486 | while (e1->next) | |
487 | e1 = e1->next; | |
488 | e1->next = e; | |
489 | } | |
490 | } | |
491 | ||
cce0e923 DE |
492 | /* Return non-zero if we're stopped at a file to be skipped. */ |
493 | ||
494 | static int | |
495 | skip_file_p (struct skiplist_entry *e, | |
496 | const struct symtab_and_line *function_sal) | |
497 | { | |
498 | gdb_assert (e->file != NULL && !e->file_is_glob); | |
499 | ||
500 | if (function_sal->symtab == NULL) | |
501 | return 0; | |
502 | ||
503 | /* Check first sole SYMTAB->FILENAME. It may not be a substring of | |
504 | symtab_to_fullname as it may contain "./" etc. */ | |
505 | if (compare_filenames_for_search (function_sal->symtab->filename, e->file)) | |
506 | return 1; | |
507 | ||
508 | /* Before we invoke realpath, which can get expensive when many | |
509 | files are involved, do a quick comparison of the basenames. */ | |
510 | if (!basenames_may_differ | |
511 | && filename_cmp (lbasename (function_sal->symtab->filename), | |
512 | lbasename (e->file)) != 0) | |
513 | return 0; | |
514 | ||
515 | /* Note: symtab_to_fullname caches its result, thus we don't have to. */ | |
516 | { | |
517 | const char *fullname = symtab_to_fullname (function_sal->symtab); | |
518 | ||
519 | if (compare_filenames_for_search (fullname, e->file)) | |
520 | return 1; | |
521 | } | |
522 | ||
523 | return 0; | |
524 | } | |
525 | ||
526 | /* Return non-zero if we're stopped at a globbed file to be skipped. */ | |
527 | ||
528 | static int | |
529 | skip_gfile_p (struct skiplist_entry *e, | |
530 | const struct symtab_and_line *function_sal) | |
531 | { | |
532 | gdb_assert (e->file != NULL && e->file_is_glob); | |
533 | ||
534 | if (function_sal->symtab == NULL) | |
535 | return 0; | |
536 | ||
537 | /* Check first sole SYMTAB->FILENAME. It may not be a substring of | |
538 | symtab_to_fullname as it may contain "./" etc. */ | |
539 | if (gdb_filename_fnmatch (e->file, function_sal->symtab->filename, | |
540 | FNM_FILE_NAME | FNM_NOESCAPE) == 0) | |
541 | return 1; | |
542 | ||
543 | /* Before we invoke symtab_to_fullname, which is expensive, do a quick | |
544 | comparison of the basenames. | |
545 | Note that we assume that lbasename works with glob-style patterns. | |
546 | If the basename of the glob pattern is something like "*.c" then this | |
547 | isn't much of a win. Oh well. */ | |
548 | if (!basenames_may_differ | |
549 | && gdb_filename_fnmatch (lbasename (e->file), | |
550 | lbasename (function_sal->symtab->filename), | |
551 | FNM_FILE_NAME | FNM_NOESCAPE) != 0) | |
552 | return 0; | |
553 | ||
554 | /* Note: symtab_to_fullname caches its result, thus we don't have to. */ | |
555 | { | |
556 | const char *fullname = symtab_to_fullname (function_sal->symtab); | |
557 | ||
558 | if (compare_glob_filenames_for_search (fullname, e->file)) | |
559 | return 1; | |
560 | } | |
561 | ||
562 | return 0; | |
563 | } | |
564 | ||
565 | /* Return non-zero if we're stopped at a function to be skipped. */ | |
566 | ||
567 | static int | |
568 | skip_function_p (struct skiplist_entry *e, const char *function_name) | |
569 | { | |
570 | gdb_assert (e->function != NULL && !e->function_is_regexp); | |
571 | return strcmp_iw (function_name, e->function) == 0; | |
572 | } | |
573 | ||
574 | /* Return non-zero if we're stopped at a function regexp to be skipped. */ | |
575 | ||
576 | static int | |
577 | skip_rfunction_p (struct skiplist_entry *e, const char *function_name) | |
578 | { | |
579 | gdb_assert (e->function != NULL && e->function_is_regexp | |
2d7cc5c7 PA |
580 | && e->compiled_function_regexp); |
581 | return (e->compiled_function_regexp->exec (function_name, 0, NULL, 0) | |
cce0e923 DE |
582 | == 0); |
583 | } | |
85817405 JK |
584 | |
585 | /* See skip.h. */ | |
1bfeeb0f JL |
586 | |
587 | int | |
85817405 JK |
588 | function_name_is_marked_for_skip (const char *function_name, |
589 | const struct symtab_and_line *function_sal) | |
1bfeeb0f | 590 | { |
1bfeeb0f JL |
591 | struct skiplist_entry *e; |
592 | ||
85817405 JK |
593 | if (function_name == NULL) |
594 | return 0; | |
595 | ||
1bfeeb0f JL |
596 | ALL_SKIPLIST_ENTRIES (e) |
597 | { | |
cce0e923 DE |
598 | int skip_by_file = 0; |
599 | int skip_by_function = 0; | |
600 | ||
85817405 | 601 | if (!e->enabled) |
1bfeeb0f JL |
602 | continue; |
603 | ||
cce0e923 | 604 | if (e->file != NULL) |
05cba821 | 605 | { |
cce0e923 DE |
606 | if (e->file_is_glob) |
607 | { | |
608 | if (skip_gfile_p (e, function_sal)) | |
609 | skip_by_file = 1; | |
610 | } | |
611 | else | |
05cba821 | 612 | { |
cce0e923 DE |
613 | if (skip_file_p (e, function_sal)) |
614 | skip_by_file = 1; | |
05cba821 | 615 | } |
cce0e923 DE |
616 | } |
617 | if (e->function != NULL) | |
618 | { | |
619 | if (e->function_is_regexp) | |
620 | { | |
621 | if (skip_rfunction_p (e, function_name)) | |
622 | skip_by_function = 1; | |
623 | } | |
624 | else | |
625 | { | |
626 | if (skip_function_p (e, function_name)) | |
627 | skip_by_function = 1; | |
628 | } | |
629 | } | |
630 | ||
631 | /* If both file and function must match, make sure we don't errantly | |
632 | exit if only one of them match. */ | |
633 | if (e->file != NULL && e->function != NULL) | |
634 | { | |
635 | if (skip_by_file && skip_by_function) | |
05cba821 JK |
636 | return 1; |
637 | } | |
cce0e923 DE |
638 | /* Only one of file/function is specified. */ |
639 | else if (skip_by_file || skip_by_function) | |
640 | return 1; | |
1bfeeb0f JL |
641 | } |
642 | ||
643 | return 0; | |
644 | } | |
645 | ||
70221824 PA |
646 | /* Provide a prototype to silence -Wmissing-prototypes. */ |
647 | extern initialize_file_ftype _initialize_step_skip; | |
648 | ||
1bfeeb0f JL |
649 | void |
650 | _initialize_step_skip (void) | |
651 | { | |
8bfd80db | 652 | static struct cmd_list_element *skiplist = NULL; |
1bfeeb0f JL |
653 | struct cmd_list_element *c; |
654 | ||
655 | skiplist_entry_chain = 0; | |
656 | skiplist_entry_count = 0; | |
657 | ||
cce0e923 | 658 | add_prefix_cmd ("skip", class_breakpoint, skip_command, _("\ |
1bfeeb0f | 659 | Ignore a function while stepping.\n\ |
cce0e923 DE |
660 | \n\ |
661 | Usage: skip [FUNCTION-NAME]\n\ | |
662 | skip [<file-spec>] [<function-spec>]\n\ | |
663 | If no arguments are given, ignore the current function.\n\ | |
664 | \n\ | |
665 | <file-spec> is one of:\n\ | |
666 | -fi|-file FILE-NAME\n\ | |
667 | -gfi|-gfile GLOB-FILE-PATTERN\n\ | |
668 | <function-spec> is one of:\n\ | |
669 | -fu|-function FUNCTION-NAME\n\ | |
670 | -rfu|-rfunction FUNCTION-NAME-REGULAR-EXPRESSION"), | |
1bfeeb0f JL |
671 | &skiplist, "skip ", 1, &cmdlist); |
672 | ||
673 | c = add_cmd ("file", class_breakpoint, skip_file_command, _("\ | |
674 | Ignore a file while stepping.\n\ | |
cce0e923 | 675 | Usage: skip file [FILE-NAME]\n\ |
1bfeeb0f JL |
676 | If no filename is given, ignore the current file."), |
677 | &skiplist); | |
678 | set_cmd_completer (c, filename_completer); | |
679 | ||
680 | c = add_cmd ("function", class_breakpoint, skip_function_command, _("\ | |
681 | Ignore a function while stepping.\n\ | |
cce0e923 | 682 | Usage: skip function [FUNCTION-NAME]\n\ |
1bfeeb0f JL |
683 | If no function name is given, skip the current function."), |
684 | &skiplist); | |
685 | set_cmd_completer (c, location_completer); | |
686 | ||
687 | add_cmd ("enable", class_breakpoint, skip_enable_command, _("\ | |
688 | Enable skip entries. You can specify numbers (e.g. \"skip enable 1 3\"), \ | |
689 | ranges (e.g. \"skip enable 4-8\"), or both (e.g. \"skip enable 1 3 4-8\").\n\n\ | |
690 | If you don't specify any numbers or ranges, we'll enable all skip entries.\n\n\ | |
691 | Usage: skip enable [NUMBERS AND/OR RANGES]"), | |
692 | &skiplist); | |
693 | ||
694 | add_cmd ("disable", class_breakpoint, skip_disable_command, _("\ | |
695 | Disable skip entries. You can specify numbers (e.g. \"skip disable 1 3\"), \ | |
696 | ranges (e.g. \"skip disable 4-8\"), or both (e.g. \"skip disable 1 3 4-8\").\n\n\ | |
697 | If you don't specify any numbers or ranges, we'll disable all skip entries.\n\n\ | |
698 | Usage: skip disable [NUMBERS AND/OR RANGES]"), | |
699 | &skiplist); | |
700 | ||
701 | add_cmd ("delete", class_breakpoint, skip_delete_command, _("\ | |
702 | Delete skip entries. You can specify numbers (e.g. \"skip delete 1 3\"), \ | |
703 | ranges (e.g. \"skip delete 4-8\"), or both (e.g. \"skip delete 1 3 4-8\").\n\n\ | |
704 | If you don't specify any numbers or ranges, we'll delete all skip entries.\n\n\ | |
705 | Usage: skip delete [NUMBERS AND/OR RANGES]"), | |
706 | &skiplist); | |
707 | ||
708 | add_info ("skip", skip_info, _("\ | |
709 | Display the status of skips. You can specify numbers (e.g. \"skip info 1 3\"), \ | |
710 | ranges (e.g. \"skip info 4-8\"), or both (e.g. \"skip info 1 3 4-8\").\n\n\ | |
711 | If you don't specify any numbers or ranges, we'll show all skips.\n\n\ | |
712 | Usage: skip info [NUMBERS AND/OR RANGES]\n\ | |
713 | The \"Type\" column indicates one of:\n\ | |
714 | \tfile - ignored file\n\ | |
715 | \tfunction - ignored function")); | |
716 | } |