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