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 () */
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 const 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 filename
= symtab
->filename
;
87 symtab
= lookup_symtab (arg
);
90 fprintf_filtered (gdb_stderr
, _("No source file named %s.\n"), arg
);
92 Ignore file pending future shared library load? ")))
99 e
= XZALLOC (struct skiplist_entry
);
100 e
->filename
= xstrdup (filename
);
103 add_skiplist_entry (e
);
105 printf_filtered (_("File %s will be skipped when stepping.\n"), filename
);
109 skip_function_command (char *arg
, int from_tty
)
111 const char *name
= NULL
;
113 /* Default to the current function if no argument is given. */
118 if (!last_displayed_sal_is_valid ())
119 error (_("No default function now."));
121 pc
= get_last_displayed_addr ();
122 if (!find_pc_partial_function (pc
, &name
, NULL
, NULL
))
124 error (_("No function found containing current program point %s."),
125 paddress (get_current_arch (), pc
));
127 skip_function (name
);
131 if (lookup_symbol (arg
, NULL
, VAR_DOMAIN
, NULL
) == NULL
)
133 fprintf_filtered (gdb_stderr
,
134 _("No function found named %s.\n"), arg
);
137 Ignore function pending future shared library load? ")))
139 /* Add the unverified skiplist entry. */
150 skip_info (char *arg
, int from_tty
)
152 struct skiplist_entry
*e
;
153 int num_printable_entries
= 0;
154 struct value_print_options opts
;
155 struct cleanup
*tbl_chain
;
157 get_user_print_options (&opts
);
159 /* Count the number of rows in the table and see if we need space for a
160 64-bit address anywhere. */
161 ALL_SKIPLIST_ENTRIES (e
)
162 if (arg
== NULL
|| number_is_in_list (arg
, e
->number
))
163 num_printable_entries
++;
165 if (num_printable_entries
== 0)
168 ui_out_message (current_uiout
, 0, _("\
169 Not skipping any files or functions.\n"));
171 ui_out_message (current_uiout
, 0,
172 _("No skiplist entries found with number %s.\n"), arg
);
177 tbl_chain
= make_cleanup_ui_out_table_begin_end (current_uiout
, 4,
178 num_printable_entries
,
181 ui_out_table_header (current_uiout
, 7, ui_left
, "number", "Num"); /* 1 */
182 ui_out_table_header (current_uiout
, 14, ui_left
, "type", "Type"); /* 2 */
183 ui_out_table_header (current_uiout
, 3, ui_left
, "enabled", "Enb"); /* 3 */
184 ui_out_table_header (current_uiout
, 40, ui_noalign
, "what", "What"); /* 4 */
185 ui_out_table_body (current_uiout
);
187 ALL_SKIPLIST_ENTRIES (e
)
189 struct cleanup
*entry_chain
;
192 if (arg
!= NULL
&& !number_is_in_list (arg
, e
->number
))
195 entry_chain
= make_cleanup_ui_out_tuple_begin_end (current_uiout
,
197 ui_out_field_int (current_uiout
, "number", e
->number
); /* 1 */
199 if (e
->function_name
!= NULL
)
200 ui_out_field_string (current_uiout
, "type", "function"); /* 2 */
201 else if (e
->filename
!= NULL
)
202 ui_out_field_string (current_uiout
, "type", "file"); /* 2 */
204 internal_error (__FILE__
, __LINE__
, _("\
205 Skiplist entry should have either a filename or a function name."));
208 ui_out_field_string (current_uiout
, "enabled", "y"); /* 3 */
210 ui_out_field_string (current_uiout
, "enabled", "n"); /* 3 */
212 if (e
->function_name
!= NULL
)
213 ui_out_field_string (current_uiout
, "what", e
->function_name
); /* 4 */
214 else if (e
->filename
!= NULL
)
215 ui_out_field_string (current_uiout
, "what", e
->filename
); /* 4 */
217 ui_out_text (current_uiout
, "\n");
218 do_cleanups (entry_chain
);
221 do_cleanups (tbl_chain
);
225 skip_enable_command (char *arg
, int from_tty
)
227 struct skiplist_entry
*e
;
230 ALL_SKIPLIST_ENTRIES (e
)
231 if (arg
== NULL
|| number_is_in_list (arg
, e
->number
))
238 error (_("No skiplist entries found with number %s."), arg
);
242 skip_disable_command (char *arg
, int from_tty
)
244 struct skiplist_entry
*e
;
247 ALL_SKIPLIST_ENTRIES (e
)
248 if (arg
== NULL
|| number_is_in_list (arg
, e
->number
))
255 error (_("No skiplist entries found with number %s."), arg
);
259 skip_delete_command (char *arg
, int from_tty
)
261 struct skiplist_entry
*e
, *temp
, *b_prev
;
265 ALL_SKIPLIST_ENTRIES_SAFE (e
, temp
)
266 if (arg
== NULL
|| number_is_in_list (arg
, e
->number
))
269 b_prev
->next
= e
->next
;
271 skiplist_entry_chain
= e
->next
;
273 xfree (e
->function_name
);
284 error (_("No skiplist entries found with number %s."), arg
);
287 /* Create a skiplist entry for the given function NAME and add it to the
291 skip_function (const char *name
)
293 struct skiplist_entry
*e
= XZALLOC (struct skiplist_entry
);
296 e
->function_name
= xstrdup (name
);
298 add_skiplist_entry (e
);
300 printf_filtered (_("Function %s will be skipped when stepping.\n"), name
);
303 /* Add the given skiplist entry to our list, and set the entry's number. */
306 add_skiplist_entry (struct skiplist_entry
*e
)
308 struct skiplist_entry
*e1
;
310 e
->number
= ++skiplist_entry_count
;
312 /* Add to the end of the chain so that the list of
313 skiplist entries will be in numerical order. */
315 e1
= skiplist_entry_chain
;
317 skiplist_entry_chain
= e
;
330 function_name_is_marked_for_skip (const char *function_name
,
331 const struct symtab_and_line
*function_sal
)
333 struct skiplist_entry
*e
;
335 if (function_name
== NULL
)
338 ALL_SKIPLIST_ENTRIES (e
)
343 /* Does the pc we're stepping into match e's stored pc? */
344 if (e
->function_name
!= NULL
345 && strcmp_iw (function_name
, e
->function_name
) == 0)
348 if (e
->filename
!= NULL
&& function_sal
->symtab
!= NULL
349 && function_sal
->symtab
->filename
!= NULL
350 && compare_filenames_for_search (function_sal
->symtab
->filename
,
358 /* Provide a prototype to silence -Wmissing-prototypes. */
359 extern initialize_file_ftype _initialize_step_skip
;
362 _initialize_step_skip (void)
364 static struct cmd_list_element
*skiplist
= NULL
;
365 struct cmd_list_element
*c
;
367 skiplist_entry_chain
= 0;
368 skiplist_entry_count
= 0;
370 add_prefix_cmd ("skip", class_breakpoint
, skip_function_command
, _("\
371 Ignore a function while stepping.\n\
372 Usage: skip [FUNCTION NAME]\n\
373 If no function name is given, ignore the current function."),
374 &skiplist
, "skip ", 1, &cmdlist
);
376 c
= add_cmd ("file", class_breakpoint
, skip_file_command
, _("\
377 Ignore a file while stepping.\n\
378 Usage: skip file [FILENAME]\n\
379 If no filename is given, ignore the current file."),
381 set_cmd_completer (c
, filename_completer
);
383 c
= add_cmd ("function", class_breakpoint
, skip_function_command
, _("\
384 Ignore a function while stepping.\n\
385 Usage: skip function [FUNCTION NAME]\n\
386 If no function name is given, skip the current function."),
388 set_cmd_completer (c
, location_completer
);
390 add_cmd ("enable", class_breakpoint
, skip_enable_command
, _("\
391 Enable skip entries. You can specify numbers (e.g. \"skip enable 1 3\"), \
392 ranges (e.g. \"skip enable 4-8\"), or both (e.g. \"skip enable 1 3 4-8\").\n\n\
393 If you don't specify any numbers or ranges, we'll enable all skip entries.\n\n\
394 Usage: skip enable [NUMBERS AND/OR RANGES]"),
397 add_cmd ("disable", class_breakpoint
, skip_disable_command
, _("\
398 Disable skip entries. You can specify numbers (e.g. \"skip disable 1 3\"), \
399 ranges (e.g. \"skip disable 4-8\"), or both (e.g. \"skip disable 1 3 4-8\").\n\n\
400 If you don't specify any numbers or ranges, we'll disable all skip entries.\n\n\
401 Usage: skip disable [NUMBERS AND/OR RANGES]"),
404 add_cmd ("delete", class_breakpoint
, skip_delete_command
, _("\
405 Delete skip entries. You can specify numbers (e.g. \"skip delete 1 3\"), \
406 ranges (e.g. \"skip delete 4-8\"), or both (e.g. \"skip delete 1 3 4-8\").\n\n\
407 If you don't specify any numbers or ranges, we'll delete all skip entries.\n\n\
408 Usage: skip delete [NUMBERS AND/OR RANGES]"),
411 add_info ("skip", skip_info
, _("\
412 Display the status of skips. You can specify numbers (e.g. \"skip info 1 3\"), \
413 ranges (e.g. \"skip info 4-8\"), or both (e.g. \"skip info 1 3 4-8\").\n\n\
414 If you don't specify any numbers or ranges, we'll show all skips.\n\n\
415 Usage: skip info [NUMBERS AND/OR RANGES]\n\
416 The \"Type\" column indicates one of:\n\
417 \tfile - ignored file\n\
418 \tfunction - ignored function"));