1 /* Skipping uninteresting files and functions while stepping.
3 Copyright (C) 2011-2014 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/>. */
26 #include "completer.h"
28 #include "cli/cli-utils.h"
29 #include "arch-utils.h"
32 #include "exceptions.h"
33 #include "breakpoint.h" /* for get_sal_arch () */
35 #include "filenames.h"
41 /* NULL if this isn't a skiplist entry for an entire file.
42 The skiplist entry owns this pointer. */
45 /* The name of the marked-for-skip function, if this is a skiplist
47 The skiplist entry owns this pointer. */
52 struct skiplist_entry
*next
;
55 static void add_skiplist_entry (struct skiplist_entry
*e
);
56 static void skip_function (const char *name
);
58 static struct skiplist_entry
*skiplist_entry_chain
;
59 static int skiplist_entry_count
;
61 #define ALL_SKIPLIST_ENTRIES(E) \
62 for (E = skiplist_entry_chain; E; E = E->next)
64 #define ALL_SKIPLIST_ENTRIES_SAFE(E,TMP) \
65 for (E = skiplist_entry_chain; \
66 E ? (TMP = E->next, 1) : 0; \
70 skip_file_command (char *arg
, int from_tty
)
72 struct skiplist_entry
*e
;
73 struct symtab
*symtab
;
74 const char *filename
= NULL
;
76 /* If no argument was given, try to default to the last
77 displayed codepoint. */
80 symtab
= get_last_displayed_symtab ();
82 error (_("No default file now."));
84 /* It is not a typo, symtab_to_filename_for_display woule be needlessly
86 filename
= symtab_to_fullname (symtab
);
90 symtab
= lookup_symtab (arg
);
93 fprintf_filtered (gdb_stderr
, _("No source file named %s.\n"), arg
);
95 Ignore file pending future shared library load? ")))
98 /* Do not use SYMTAB's filename, later loaded shared libraries may match
99 given ARG but not SYMTAB's filename. */
103 e
= XCNEW (struct skiplist_entry
);
104 e
->filename
= xstrdup (filename
);
107 add_skiplist_entry (e
);
109 printf_filtered (_("File %s will be skipped when stepping.\n"), filename
);
113 skip_function_command (char *arg
, int from_tty
)
115 const char *name
= NULL
;
117 /* Default to the current function if no argument is given. */
122 if (!last_displayed_sal_is_valid ())
123 error (_("No default function now."));
125 pc
= get_last_displayed_addr ();
126 if (!find_pc_partial_function (pc
, &name
, NULL
, NULL
))
128 error (_("No function found containing current program point %s."),
129 paddress (get_current_arch (), pc
));
131 skip_function (name
);
135 if (lookup_symbol (arg
, NULL
, VAR_DOMAIN
, NULL
) == NULL
)
137 fprintf_filtered (gdb_stderr
,
138 _("No function found named %s.\n"), arg
);
141 Ignore function pending future shared library load? ")))
143 /* Add the unverified skiplist entry. */
154 skip_info (char *arg
, int from_tty
)
156 struct skiplist_entry
*e
;
157 int num_printable_entries
= 0;
158 struct value_print_options opts
;
159 struct cleanup
*tbl_chain
;
161 get_user_print_options (&opts
);
163 /* Count the number of rows in the table and see if we need space for a
164 64-bit address anywhere. */
165 ALL_SKIPLIST_ENTRIES (e
)
166 if (arg
== NULL
|| number_is_in_list (arg
, e
->number
))
167 num_printable_entries
++;
169 if (num_printable_entries
== 0)
172 ui_out_message (current_uiout
, 0, _("\
173 Not skipping any files or functions.\n"));
175 ui_out_message (current_uiout
, 0,
176 _("No skiplist entries found with number %s.\n"), arg
);
181 tbl_chain
= make_cleanup_ui_out_table_begin_end (current_uiout
, 4,
182 num_printable_entries
,
185 ui_out_table_header (current_uiout
, 7, ui_left
, "number", "Num"); /* 1 */
186 ui_out_table_header (current_uiout
, 14, ui_left
, "type", "Type"); /* 2 */
187 ui_out_table_header (current_uiout
, 3, ui_left
, "enabled", "Enb"); /* 3 */
188 ui_out_table_header (current_uiout
, 40, ui_noalign
, "what", "What"); /* 4 */
189 ui_out_table_body (current_uiout
);
191 ALL_SKIPLIST_ENTRIES (e
)
193 struct cleanup
*entry_chain
;
196 if (arg
!= NULL
&& !number_is_in_list (arg
, e
->number
))
199 entry_chain
= make_cleanup_ui_out_tuple_begin_end (current_uiout
,
201 ui_out_field_int (current_uiout
, "number", e
->number
); /* 1 */
203 if (e
->function_name
!= NULL
)
204 ui_out_field_string (current_uiout
, "type", "function"); /* 2 */
205 else if (e
->filename
!= NULL
)
206 ui_out_field_string (current_uiout
, "type", "file"); /* 2 */
208 internal_error (__FILE__
, __LINE__
, _("\
209 Skiplist entry should have either a filename or a function name."));
212 ui_out_field_string (current_uiout
, "enabled", "y"); /* 3 */
214 ui_out_field_string (current_uiout
, "enabled", "n"); /* 3 */
216 if (e
->function_name
!= NULL
)
217 ui_out_field_string (current_uiout
, "what", e
->function_name
); /* 4 */
218 else if (e
->filename
!= NULL
)
219 ui_out_field_string (current_uiout
, "what", e
->filename
); /* 4 */
221 ui_out_text (current_uiout
, "\n");
222 do_cleanups (entry_chain
);
225 do_cleanups (tbl_chain
);
229 skip_enable_command (char *arg
, int from_tty
)
231 struct skiplist_entry
*e
;
234 ALL_SKIPLIST_ENTRIES (e
)
235 if (arg
== NULL
|| number_is_in_list (arg
, e
->number
))
242 error (_("No skiplist entries found with number %s."), arg
);
246 skip_disable_command (char *arg
, int from_tty
)
248 struct skiplist_entry
*e
;
251 ALL_SKIPLIST_ENTRIES (e
)
252 if (arg
== NULL
|| number_is_in_list (arg
, e
->number
))
259 error (_("No skiplist entries found with number %s."), arg
);
263 skip_delete_command (char *arg
, int from_tty
)
265 struct skiplist_entry
*e
, *temp
, *b_prev
;
269 ALL_SKIPLIST_ENTRIES_SAFE (e
, temp
)
270 if (arg
== NULL
|| number_is_in_list (arg
, e
->number
))
273 b_prev
->next
= e
->next
;
275 skiplist_entry_chain
= e
->next
;
277 xfree (e
->function_name
);
288 error (_("No skiplist entries found with number %s."), arg
);
291 /* Create a skiplist entry for the given function NAME and add it to the
295 skip_function (const char *name
)
297 struct skiplist_entry
*e
= XCNEW (struct skiplist_entry
);
300 e
->function_name
= xstrdup (name
);
302 add_skiplist_entry (e
);
304 printf_filtered (_("Function %s will be skipped when stepping.\n"), name
);
307 /* Add the given skiplist entry to our list, and set the entry's number. */
310 add_skiplist_entry (struct skiplist_entry
*e
)
312 struct skiplist_entry
*e1
;
314 e
->number
= ++skiplist_entry_count
;
316 /* Add to the end of the chain so that the list of
317 skiplist entries will be in numerical order. */
319 e1
= skiplist_entry_chain
;
321 skiplist_entry_chain
= e
;
334 function_name_is_marked_for_skip (const char *function_name
,
335 const struct symtab_and_line
*function_sal
)
337 int searched_for_fullname
= 0;
338 const char *fullname
= NULL
;
339 struct skiplist_entry
*e
;
341 if (function_name
== NULL
)
344 ALL_SKIPLIST_ENTRIES (e
)
349 /* Does the pc we're stepping into match e's stored pc? */
350 if (e
->function_name
!= NULL
351 && strcmp_iw (function_name
, e
->function_name
) == 0)
354 if (e
->filename
!= NULL
)
356 /* Check first sole SYMTAB->FILENAME. It does not need to be
357 a substring of symtab_to_fullname as it may contain "./" etc. */
358 if (function_sal
->symtab
!= NULL
359 && compare_filenames_for_search (function_sal
->symtab
->filename
,
363 /* Before we invoke realpath, which can get expensive when many
364 files are involved, do a quick comparison of the basenames. */
365 if (!basenames_may_differ
366 && (function_sal
->symtab
== NULL
367 || filename_cmp (lbasename (function_sal
->symtab
->filename
),
368 lbasename (e
->filename
)) != 0))
371 /* Get the filename corresponding to this FUNCTION_SAL, if we haven't
373 if (!searched_for_fullname
)
375 if (function_sal
->symtab
!= NULL
)
376 fullname
= symtab_to_fullname (function_sal
->symtab
);
377 searched_for_fullname
= 1;
380 && compare_filenames_for_search (fullname
, e
->filename
))
388 /* Provide a prototype to silence -Wmissing-prototypes. */
389 extern initialize_file_ftype _initialize_step_skip
;
392 _initialize_step_skip (void)
394 static struct cmd_list_element
*skiplist
= NULL
;
395 struct cmd_list_element
*c
;
397 skiplist_entry_chain
= 0;
398 skiplist_entry_count
= 0;
400 add_prefix_cmd ("skip", class_breakpoint
, skip_function_command
, _("\
401 Ignore a function while stepping.\n\
402 Usage: skip [FUNCTION NAME]\n\
403 If no function name is given, ignore the current function."),
404 &skiplist
, "skip ", 1, &cmdlist
);
406 c
= add_cmd ("file", class_breakpoint
, skip_file_command
, _("\
407 Ignore a file while stepping.\n\
408 Usage: skip file [FILENAME]\n\
409 If no filename is given, ignore the current file."),
411 set_cmd_completer (c
, filename_completer
);
413 c
= add_cmd ("function", class_breakpoint
, skip_function_command
, _("\
414 Ignore a function while stepping.\n\
415 Usage: skip function [FUNCTION NAME]\n\
416 If no function name is given, skip the current function."),
418 set_cmd_completer (c
, location_completer
);
420 add_cmd ("enable", class_breakpoint
, skip_enable_command
, _("\
421 Enable skip entries. You can specify numbers (e.g. \"skip enable 1 3\"), \
422 ranges (e.g. \"skip enable 4-8\"), or both (e.g. \"skip enable 1 3 4-8\").\n\n\
423 If you don't specify any numbers or ranges, we'll enable all skip entries.\n\n\
424 Usage: skip enable [NUMBERS AND/OR RANGES]"),
427 add_cmd ("disable", class_breakpoint
, skip_disable_command
, _("\
428 Disable skip entries. You can specify numbers (e.g. \"skip disable 1 3\"), \
429 ranges (e.g. \"skip disable 4-8\"), or both (e.g. \"skip disable 1 3 4-8\").\n\n\
430 If you don't specify any numbers or ranges, we'll disable all skip entries.\n\n\
431 Usage: skip disable [NUMBERS AND/OR RANGES]"),
434 add_cmd ("delete", class_breakpoint
, skip_delete_command
, _("\
435 Delete skip entries. You can specify numbers (e.g. \"skip delete 1 3\"), \
436 ranges (e.g. \"skip delete 4-8\"), or both (e.g. \"skip delete 1 3 4-8\").\n\n\
437 If you don't specify any numbers or ranges, we'll delete all skip entries.\n\n\
438 Usage: skip delete [NUMBERS AND/OR RANGES]"),
441 add_info ("skip", skip_info
, _("\
442 Display the status of skips. You can specify numbers (e.g. \"skip info 1 3\"), \
443 ranges (e.g. \"skip info 4-8\"), or both (e.g. \"skip info 1 3 4-8\").\n\n\
444 If you don't specify any numbers or ranges, we'll show all skips.\n\n\
445 Usage: skip info [NUMBERS AND/OR RANGES]\n\
446 The \"Type\" column indicates one of:\n\
447 \tfile - ignored file\n\
448 \tfunction - ignored function"));