1 /* Skipping uninteresting files and functions while stepping.
3 Copyright (C) 2011-2013 Free Software Foundation, Inc.
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.
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.
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/>. */
23 #include "gdb_string.h"
27 #include "completer.h"
29 #include "cli/cli-utils.h"
30 #include "arch-utils.h"
33 #include "exceptions.h"
34 #include "breakpoint.h" /* for get_sal_arch () */
36 #include "filenames.h"
42 /* NULL if this isn't a skiplist entry for an entire file.
43 The skiplist entry owns this pointer. */
46 /* The name of the marked-for-skip function, if this is a skiplist
48 The skiplist entry owns this pointer. */
53 struct skiplist_entry *next;
56 static void add_skiplist_entry (struct skiplist_entry *e);
57 static void skip_function (const char *name);
59 static struct skiplist_entry *skiplist_entry_chain;
60 static int skiplist_entry_count;
62 #define ALL_SKIPLIST_ENTRIES(E) \
63 for (E = skiplist_entry_chain; E; E = E->next)
65 #define ALL_SKIPLIST_ENTRIES_SAFE(E,TMP) \
66 for (E = skiplist_entry_chain; \
67 E ? (TMP = E->next, 1) : 0; \
71 skip_file_command (char *arg, int from_tty)
73 struct skiplist_entry *e;
74 struct symtab *symtab;
75 const char *filename = NULL;
77 /* If no argument was given, try to default to the last
78 displayed codepoint. */
81 symtab = get_last_displayed_symtab ();
83 error (_("No default file now."));
85 /* It is not a typo, symtab_to_filename_for_display woule be needlessly
87 filename = symtab_to_fullname (symtab);
91 symtab = lookup_symtab (arg);
94 fprintf_filtered (gdb_stderr, _("No source file named %s.\n"), arg);
96 Ignore file pending future shared library load? ")))
99 /* Do not use SYMTAB's filename, later loaded shared libraries may match
100 given ARG but not SYMTAB's filename. */
104 e = XZALLOC (struct skiplist_entry);
105 e->filename = xstrdup (filename);
108 add_skiplist_entry (e);
110 printf_filtered (_("File %s will be skipped when stepping.\n"), filename);
114 skip_function_command (char *arg, int from_tty)
116 const char *name = NULL;
118 /* Default to the current function if no argument is given. */
123 if (!last_displayed_sal_is_valid ())
124 error (_("No default function now."));
126 pc = get_last_displayed_addr ();
127 if (!find_pc_partial_function (pc, &name, NULL, NULL))
129 error (_("No function found containing current program point %s."),
130 paddress (get_current_arch (), pc));
132 skip_function (name);
136 if (lookup_symbol (arg, NULL, VAR_DOMAIN, NULL) == NULL)
138 fprintf_filtered (gdb_stderr,
139 _("No function found named %s.\n"), arg);
142 Ignore function pending future shared library load? ")))
144 /* Add the unverified skiplist entry. */
155 skip_info (char *arg, int from_tty)
157 struct skiplist_entry *e;
158 int num_printable_entries = 0;
159 struct value_print_options opts;
160 struct cleanup *tbl_chain;
162 get_user_print_options (&opts);
164 /* Count the number of rows in the table and see if we need space for a
165 64-bit address anywhere. */
166 ALL_SKIPLIST_ENTRIES (e)
167 if (arg == NULL || number_is_in_list (arg, e->number))
168 num_printable_entries++;
170 if (num_printable_entries == 0)
173 ui_out_message (current_uiout, 0, _("\
174 Not skipping any files or functions.\n"));
176 ui_out_message (current_uiout, 0,
177 _("No skiplist entries found with number %s.\n"), arg);
182 tbl_chain = make_cleanup_ui_out_table_begin_end (current_uiout, 4,
183 num_printable_entries,
186 ui_out_table_header (current_uiout, 7, ui_left, "number", "Num"); /* 1 */
187 ui_out_table_header (current_uiout, 14, ui_left, "type", "Type"); /* 2 */
188 ui_out_table_header (current_uiout, 3, ui_left, "enabled", "Enb"); /* 3 */
189 ui_out_table_header (current_uiout, 40, ui_noalign, "what", "What"); /* 4 */
190 ui_out_table_body (current_uiout);
192 ALL_SKIPLIST_ENTRIES (e)
194 struct cleanup *entry_chain;
197 if (arg != NULL && !number_is_in_list (arg, e->number))
200 entry_chain = make_cleanup_ui_out_tuple_begin_end (current_uiout,
202 ui_out_field_int (current_uiout, "number", e->number); /* 1 */
204 if (e->function_name != NULL)
205 ui_out_field_string (current_uiout, "type", "function"); /* 2 */
206 else if (e->filename != NULL)
207 ui_out_field_string (current_uiout, "type", "file"); /* 2 */
209 internal_error (__FILE__, __LINE__, _("\
210 Skiplist entry should have either a filename or a function name."));
213 ui_out_field_string (current_uiout, "enabled", "y"); /* 3 */
215 ui_out_field_string (current_uiout, "enabled", "n"); /* 3 */
217 if (e->function_name != NULL)
218 ui_out_field_string (current_uiout, "what", e->function_name); /* 4 */
219 else if (e->filename != NULL)
220 ui_out_field_string (current_uiout, "what", e->filename); /* 4 */
222 ui_out_text (current_uiout, "\n");
223 do_cleanups (entry_chain);
226 do_cleanups (tbl_chain);
230 skip_enable_command (char *arg, int from_tty)
232 struct skiplist_entry *e;
235 ALL_SKIPLIST_ENTRIES (e)
236 if (arg == NULL || number_is_in_list (arg, e->number))
243 error (_("No skiplist entries found with number %s."), arg);
247 skip_disable_command (char *arg, int from_tty)
249 struct skiplist_entry *e;
252 ALL_SKIPLIST_ENTRIES (e)
253 if (arg == NULL || number_is_in_list (arg, e->number))
260 error (_("No skiplist entries found with number %s."), arg);
264 skip_delete_command (char *arg, int from_tty)
266 struct skiplist_entry *e, *temp, *b_prev;
270 ALL_SKIPLIST_ENTRIES_SAFE (e, temp)
271 if (arg == NULL || number_is_in_list (arg, e->number))
274 b_prev->next = e->next;
276 skiplist_entry_chain = e->next;
278 xfree (e->function_name);
289 error (_("No skiplist entries found with number %s."), arg);
292 /* Create a skiplist entry for the given function NAME and add it to the
296 skip_function (const char *name)
298 struct skiplist_entry *e = XZALLOC (struct skiplist_entry);
301 e->function_name = xstrdup (name);
303 add_skiplist_entry (e);
305 printf_filtered (_("Function %s will be skipped when stepping.\n"), name);
308 /* Add the given skiplist entry to our list, and set the entry's number. */
311 add_skiplist_entry (struct skiplist_entry *e)
313 struct skiplist_entry *e1;
315 e->number = ++skiplist_entry_count;
317 /* Add to the end of the chain so that the list of
318 skiplist entries will be in numerical order. */
320 e1 = skiplist_entry_chain;
322 skiplist_entry_chain = e;
335 function_name_is_marked_for_skip (const char *function_name,
336 const struct symtab_and_line *function_sal)
338 int searched_for_fullname = 0;
339 const char *fullname = NULL;
340 struct skiplist_entry *e;
342 if (function_name == NULL)
345 ALL_SKIPLIST_ENTRIES (e)
350 /* Does the pc we're stepping into match e's stored pc? */
351 if (e->function_name != NULL
352 && strcmp_iw (function_name, e->function_name) == 0)
355 if (e->filename != NULL)
357 /* Check first sole SYMTAB->FILENAME. It does not need to be
358 a substring of symtab_to_fullname as it may contain "./" etc. */
359 if (function_sal->symtab != NULL
360 && compare_filenames_for_search (function_sal->symtab->filename,
364 /* Before we invoke realpath, which can get expensive when many
365 files are involved, do a quick comparison of the basenames. */
366 if (!basenames_may_differ
367 && (function_sal->symtab == NULL
368 || filename_cmp (lbasename (function_sal->symtab->filename),
369 lbasename (e->filename)) != 0))
372 /* Get the filename corresponding to this FUNCTION_SAL, if we haven't
374 if (!searched_for_fullname)
376 if (function_sal->symtab != NULL)
377 fullname = symtab_to_fullname (function_sal->symtab);
378 searched_for_fullname = 1;
381 && compare_filenames_for_search (fullname, e->filename))
389 /* Provide a prototype to silence -Wmissing-prototypes. */
390 extern initialize_file_ftype _initialize_step_skip;
393 _initialize_step_skip (void)
395 static struct cmd_list_element *skiplist = NULL;
396 struct cmd_list_element *c;
398 skiplist_entry_chain = 0;
399 skiplist_entry_count = 0;
401 add_prefix_cmd ("skip", class_breakpoint, skip_function_command, _("\
402 Ignore a function while stepping.\n\
403 Usage: skip [FUNCTION NAME]\n\
404 If no function name is given, ignore the current function."),
405 &skiplist, "skip ", 1, &cmdlist);
407 c = add_cmd ("file", class_breakpoint, skip_file_command, _("\
408 Ignore a file while stepping.\n\
409 Usage: skip file [FILENAME]\n\
410 If no filename is given, ignore the current file."),
412 set_cmd_completer (c, filename_completer);
414 c = add_cmd ("function", class_breakpoint, skip_function_command, _("\
415 Ignore a function while stepping.\n\
416 Usage: skip function [FUNCTION NAME]\n\
417 If no function name is given, skip the current function."),
419 set_cmd_completer (c, location_completer);
421 add_cmd ("enable", class_breakpoint, skip_enable_command, _("\
422 Enable skip entries. You can specify numbers (e.g. \"skip enable 1 3\"), \
423 ranges (e.g. \"skip enable 4-8\"), or both (e.g. \"skip enable 1 3 4-8\").\n\n\
424 If you don't specify any numbers or ranges, we'll enable all skip entries.\n\n\
425 Usage: skip enable [NUMBERS AND/OR RANGES]"),
428 add_cmd ("disable", class_breakpoint, skip_disable_command, _("\
429 Disable skip entries. You can specify numbers (e.g. \"skip disable 1 3\"), \
430 ranges (e.g. \"skip disable 4-8\"), or both (e.g. \"skip disable 1 3 4-8\").\n\n\
431 If you don't specify any numbers or ranges, we'll disable all skip entries.\n\n\
432 Usage: skip disable [NUMBERS AND/OR RANGES]"),
435 add_cmd ("delete", class_breakpoint, skip_delete_command, _("\
436 Delete skip entries. You can specify numbers (e.g. \"skip delete 1 3\"), \
437 ranges (e.g. \"skip delete 4-8\"), or both (e.g. \"skip delete 1 3 4-8\").\n\n\
438 If you don't specify any numbers or ranges, we'll delete all skip entries.\n\n\
439 Usage: skip delete [NUMBERS AND/OR RANGES]"),
442 add_info ("skip", skip_info, _("\
443 Display the status of skips. You can specify numbers (e.g. \"skip info 1 3\"), \
444 ranges (e.g. \"skip info 4-8\"), or both (e.g. \"skip info 1 3 4-8\").\n\n\
445 If you don't specify any numbers or ranges, we'll show all skips.\n\n\
446 Usage: skip info [NUMBERS AND/OR RANGES]\n\
447 The \"Type\" column indicates one of:\n\
448 \tfile - ignored file\n\
449 \tfunction - ignored function"));