1 /* Skipping uninteresting files and functions while stepping.
3 Copyright (C) 2011-2015 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 "breakpoint.h" /* for get_sal_arch () */
34 #include "filenames.h"
40 /* NULL if this isn't a skiplist entry for an entire file.
41 The skiplist entry owns this pointer. */
44 /* The name of the marked-for-skip function, if this is a skiplist
46 The skiplist entry owns this pointer. */
51 struct skiplist_entry
*next
;
54 static void add_skiplist_entry (struct skiplist_entry
*e
);
55 static void skip_function (const char *name
);
57 static struct skiplist_entry
*skiplist_entry_chain
;
58 static int skiplist_entry_count
;
60 #define ALL_SKIPLIST_ENTRIES(E) \
61 for (E = skiplist_entry_chain; E; E = E->next)
63 #define ALL_SKIPLIST_ENTRIES_SAFE(E,TMP) \
64 for (E = skiplist_entry_chain; \
65 E ? (TMP = E->next, 1) : 0; \
69 skip_file_command (char *arg
, int from_tty
)
71 struct skiplist_entry
*e
;
72 struct symtab
*symtab
;
73 const char *filename
= NULL
;
75 /* If no argument was given, try to default to the last
76 displayed codepoint. */
79 symtab
= get_last_displayed_symtab ();
81 error (_("No default file now."));
83 /* It is not a typo, symtab_to_filename_for_display woule be needlessly
85 filename
= symtab_to_fullname (symtab
);
89 symtab
= lookup_symtab (arg
);
92 fprintf_filtered (gdb_stderr
, _("No source file named %s.\n"), arg
);
94 Ignore file pending future shared library load? ")))
97 /* Do not use SYMTAB's filename, later loaded shared libraries may match
98 given ARG but not SYMTAB's filename. */
102 e
= XCNEW (struct skiplist_entry
);
103 e
->filename
= xstrdup (filename
);
106 add_skiplist_entry (e
);
108 printf_filtered (_("File %s will be skipped when stepping.\n"), filename
);
112 skip_function_command (char *arg
, int from_tty
)
114 const char *name
= NULL
;
116 /* Default to the current function if no argument is given. */
121 if (!last_displayed_sal_is_valid ())
122 error (_("No default function now."));
124 pc
= get_last_displayed_addr ();
125 if (!find_pc_partial_function (pc
, &name
, NULL
, NULL
))
127 error (_("No function found containing current program point %s."),
128 paddress (get_current_arch (), pc
));
130 skip_function (name
);
134 if (lookup_symbol (arg
, NULL
, VAR_DOMAIN
, NULL
) == NULL
)
136 fprintf_filtered (gdb_stderr
,
137 _("No function found named %s.\n"), arg
);
140 Ignore function pending future shared library load? ")))
142 /* Add the unverified skiplist entry. */
153 skip_info (char *arg
, int from_tty
)
155 struct skiplist_entry
*e
;
156 int num_printable_entries
= 0;
157 struct value_print_options opts
;
158 struct cleanup
*tbl_chain
;
160 get_user_print_options (&opts
);
162 /* Count the number of rows in the table and see if we need space for a
163 64-bit address anywhere. */
164 ALL_SKIPLIST_ENTRIES (e
)
165 if (arg
== NULL
|| number_is_in_list (arg
, e
->number
))
166 num_printable_entries
++;
168 if (num_printable_entries
== 0)
171 ui_out_message (current_uiout
, 0, _("\
172 Not skipping any files or functions.\n"));
174 ui_out_message (current_uiout
, 0,
175 _("No skiplist entries found with number %s.\n"), arg
);
180 tbl_chain
= make_cleanup_ui_out_table_begin_end (current_uiout
, 4,
181 num_printable_entries
,
184 ui_out_table_header (current_uiout
, 7, ui_left
, "number", "Num"); /* 1 */
185 ui_out_table_header (current_uiout
, 14, ui_left
, "type", "Type"); /* 2 */
186 ui_out_table_header (current_uiout
, 3, ui_left
, "enabled", "Enb"); /* 3 */
187 ui_out_table_header (current_uiout
, 40, ui_noalign
, "what", "What"); /* 4 */
188 ui_out_table_body (current_uiout
);
190 ALL_SKIPLIST_ENTRIES (e
)
192 struct cleanup
*entry_chain
;
195 if (arg
!= NULL
&& !number_is_in_list (arg
, e
->number
))
198 entry_chain
= make_cleanup_ui_out_tuple_begin_end (current_uiout
,
200 ui_out_field_int (current_uiout
, "number", e
->number
); /* 1 */
202 if (e
->function_name
!= NULL
)
203 ui_out_field_string (current_uiout
, "type", "function"); /* 2 */
204 else if (e
->filename
!= NULL
)
205 ui_out_field_string (current_uiout
, "type", "file"); /* 2 */
207 internal_error (__FILE__
, __LINE__
, _("\
208 Skiplist entry should have either a filename or a function name."));
211 ui_out_field_string (current_uiout
, "enabled", "y"); /* 3 */
213 ui_out_field_string (current_uiout
, "enabled", "n"); /* 3 */
215 if (e
->function_name
!= NULL
)
216 ui_out_field_string (current_uiout
, "what", e
->function_name
); /* 4 */
217 else if (e
->filename
!= NULL
)
218 ui_out_field_string (current_uiout
, "what", e
->filename
); /* 4 */
220 ui_out_text (current_uiout
, "\n");
221 do_cleanups (entry_chain
);
224 do_cleanups (tbl_chain
);
228 skip_enable_command (char *arg
, int from_tty
)
230 struct skiplist_entry
*e
;
233 ALL_SKIPLIST_ENTRIES (e
)
234 if (arg
== NULL
|| number_is_in_list (arg
, e
->number
))
241 error (_("No skiplist entries found with number %s."), arg
);
245 skip_disable_command (char *arg
, int from_tty
)
247 struct skiplist_entry
*e
;
250 ALL_SKIPLIST_ENTRIES (e
)
251 if (arg
== NULL
|| number_is_in_list (arg
, e
->number
))
258 error (_("No skiplist entries found with number %s."), arg
);
262 skip_delete_command (char *arg
, int from_tty
)
264 struct skiplist_entry
*e
, *temp
, *b_prev
;
268 ALL_SKIPLIST_ENTRIES_SAFE (e
, temp
)
269 if (arg
== NULL
|| number_is_in_list (arg
, e
->number
))
272 b_prev
->next
= e
->next
;
274 skiplist_entry_chain
= e
->next
;
276 xfree (e
->function_name
);
287 error (_("No skiplist entries found with number %s."), arg
);
290 /* Create a skiplist entry for the given function NAME and add it to the
294 skip_function (const char *name
)
296 struct skiplist_entry
*e
= XCNEW (struct skiplist_entry
);
299 e
->function_name
= xstrdup (name
);
301 add_skiplist_entry (e
);
303 printf_filtered (_("Function %s will be skipped when stepping.\n"), name
);
306 /* Add the given skiplist entry to our list, and set the entry's number. */
309 add_skiplist_entry (struct skiplist_entry
*e
)
311 struct skiplist_entry
*e1
;
313 e
->number
= ++skiplist_entry_count
;
315 /* Add to the end of the chain so that the list of
316 skiplist entries will be in numerical order. */
318 e1
= skiplist_entry_chain
;
320 skiplist_entry_chain
= e
;
333 function_name_is_marked_for_skip (const char *function_name
,
334 const struct symtab_and_line
*function_sal
)
336 int searched_for_fullname
= 0;
337 const char *fullname
= NULL
;
338 struct skiplist_entry
*e
;
340 if (function_name
== NULL
)
343 ALL_SKIPLIST_ENTRIES (e
)
348 /* Does the pc we're stepping into match e's stored pc? */
349 if (e
->function_name
!= NULL
350 && strcmp_iw (function_name
, e
->function_name
) == 0)
353 if (e
->filename
!= NULL
)
355 /* Check first sole SYMTAB->FILENAME. It does not need to be
356 a substring of symtab_to_fullname as it may contain "./" etc. */
357 if (function_sal
->symtab
!= NULL
358 && compare_filenames_for_search (function_sal
->symtab
->filename
,
362 /* Before we invoke realpath, which can get expensive when many
363 files are involved, do a quick comparison of the basenames. */
364 if (!basenames_may_differ
365 && (function_sal
->symtab
== NULL
366 || filename_cmp (lbasename (function_sal
->symtab
->filename
),
367 lbasename (e
->filename
)) != 0))
370 /* Get the filename corresponding to this FUNCTION_SAL, if we haven't
372 if (!searched_for_fullname
)
374 if (function_sal
->symtab
!= NULL
)
375 fullname
= symtab_to_fullname (function_sal
->symtab
);
376 searched_for_fullname
= 1;
379 && compare_filenames_for_search (fullname
, e
->filename
))
387 /* Provide a prototype to silence -Wmissing-prototypes. */
388 extern initialize_file_ftype _initialize_step_skip
;
391 _initialize_step_skip (void)
393 static struct cmd_list_element
*skiplist
= NULL
;
394 struct cmd_list_element
*c
;
396 skiplist_entry_chain
= 0;
397 skiplist_entry_count
= 0;
399 add_prefix_cmd ("skip", class_breakpoint
, skip_function_command
, _("\
400 Ignore a function while stepping.\n\
401 Usage: skip [FUNCTION NAME]\n\
402 If no function name is given, ignore the current function."),
403 &skiplist
, "skip ", 1, &cmdlist
);
405 c
= add_cmd ("file", class_breakpoint
, skip_file_command
, _("\
406 Ignore a file while stepping.\n\
407 Usage: skip file [FILENAME]\n\
408 If no filename is given, ignore the current file."),
410 set_cmd_completer (c
, filename_completer
);
412 c
= add_cmd ("function", class_breakpoint
, skip_function_command
, _("\
413 Ignore a function while stepping.\n\
414 Usage: skip function [FUNCTION NAME]\n\
415 If no function name is given, skip the current function."),
417 set_cmd_completer (c
, location_completer
);
419 add_cmd ("enable", class_breakpoint
, skip_enable_command
, _("\
420 Enable skip entries. You can specify numbers (e.g. \"skip enable 1 3\"), \
421 ranges (e.g. \"skip enable 4-8\"), or both (e.g. \"skip enable 1 3 4-8\").\n\n\
422 If you don't specify any numbers or ranges, we'll enable all skip entries.\n\n\
423 Usage: skip enable [NUMBERS AND/OR RANGES]"),
426 add_cmd ("disable", class_breakpoint
, skip_disable_command
, _("\
427 Disable skip entries. You can specify numbers (e.g. \"skip disable 1 3\"), \
428 ranges (e.g. \"skip disable 4-8\"), or both (e.g. \"skip disable 1 3 4-8\").\n\n\
429 If you don't specify any numbers or ranges, we'll disable all skip entries.\n\n\
430 Usage: skip disable [NUMBERS AND/OR RANGES]"),
433 add_cmd ("delete", class_breakpoint
, skip_delete_command
, _("\
434 Delete skip entries. You can specify numbers (e.g. \"skip delete 1 3\"), \
435 ranges (e.g. \"skip delete 4-8\"), or both (e.g. \"skip delete 1 3 4-8\").\n\n\
436 If you don't specify any numbers or ranges, we'll delete all skip entries.\n\n\
437 Usage: skip delete [NUMBERS AND/OR RANGES]"),
440 add_info ("skip", skip_info
, _("\
441 Display the status of skips. You can specify numbers (e.g. \"skip info 1 3\"), \
442 ranges (e.g. \"skip info 4-8\"), or both (e.g. \"skip info 1 3 4-8\").\n\n\
443 If you don't specify any numbers or ranges, we'll show all skips.\n\n\
444 Usage: skip info [NUMBERS AND/OR RANGES]\n\
445 The \"Type\" column indicates one of:\n\
446 \tfile - ignored file\n\
447 \tfunction - ignored function"));