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