1 /* Skipping uninteresting files and functions while stepping.
3 Copyright (C) 2011-2012 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
45 entry for a function. Note that this might be non-null even if
46 the pc is 0 if the entry is pending a shared library load.
48 The skiplist entry owns this pointer. */
51 /* 0 if this is a skiplist entry for an entire file, or if this
52 entry will be on a function, pending a shared library load. */
55 /* Architecture we used to create the skiplist entry. May be null
56 if the entry is pending a shared library load. */
57 struct gdbarch
*gdbarch
;
62 struct skiplist_entry
*next
;
65 static void add_skiplist_entry (struct skiplist_entry
*e
);
66 static void skip_function_pc (CORE_ADDR pc
, const char *name
,
70 static struct skiplist_entry
*skiplist_entry_chain
;
71 static int skiplist_entry_count
;
73 #define ALL_SKIPLIST_ENTRIES(E) \
74 for (E = skiplist_entry_chain; E; E = E->next)
76 #define ALL_SKIPLIST_ENTRIES_SAFE(E,TMP) \
77 for (E = skiplist_entry_chain; \
78 E ? (TMP = E->next, 1) : 0; \
82 skip_file_command (char *arg
, int from_tty
)
84 struct skiplist_entry
*e
;
85 const struct symtab
*symtab
;
87 const char *filename
= NULL
;
89 /* If no argument was given, try to default to the last
90 displayed codepoint. */
93 symtab
= get_last_displayed_symtab ();
95 error (_("No default file now."));
97 filename
= symtab
->filename
;
101 symtab
= lookup_symtab (arg
);
104 fprintf_filtered (gdb_stderr
, _("No source file named %s.\n"), arg
);
106 Ignore file pending future shared library load? ")))
113 filename
= symtab
->filename
;
116 e
= XZALLOC (struct skiplist_entry
);
117 e
->filename
= xstrdup (filename
);
119 e
->pending
= pending
;
121 e
->gdbarch
= get_objfile_arch (symtab
->objfile
);
123 add_skiplist_entry (e
);
125 printf_filtered (_("File %s will be skipped when stepping.\n"), filename
);
129 skip_function_command (char *arg
, int from_tty
)
132 const char *name
= NULL
;
134 /* Default to the current function if no argument is given. */
139 if (!last_displayed_sal_is_valid ())
140 error (_("No default function now."));
142 pc
= get_last_displayed_addr ();
143 if (!find_pc_partial_function (pc
, &name
, &func_pc
, NULL
))
145 error (_("No function found containing current program point %s."),
146 paddress (get_current_arch (), pc
));
148 skip_function_pc (func_pc
, name
, get_current_arch (), 0);
152 /* Decode arg. We set funfirstline = 1 so decode_line_1 will give us the
153 first line of the function specified, if it can, and so that we'll
154 reject variable names and the like. */
155 char *orig_arg
= arg
; /* decode_line_1 modifies the arg pointer. */
156 volatile struct gdb_exception decode_exception
;
157 struct symtabs_and_lines sals
= { NULL
};
159 TRY_CATCH (decode_exception
, RETURN_MASK_ERROR
)
161 sals
= decode_line_1 (&arg
, DECODE_LINE_FUNFIRSTLINE
, NULL
, 0);
164 if (decode_exception
.reason
< 0)
166 if (decode_exception
.error
!= NOT_FOUND_ERROR
)
167 throw_exception (decode_exception
);
169 fprintf_filtered (gdb_stderr
,
170 _("No function found named %s.\n"), orig_arg
);
173 Ignore function pending future shared library load? ")))
175 /* Add the pending skiplist entry. */
176 skip_function_pc (0, orig_arg
, NULL
, 1);
183 error (_("Specify just one function at a time."));
185 error (_("Junk at end of arguments."));
187 /* The pc decode_line_1 gives us is the first line of the function,
188 but we actually want the line before that. The call to
189 find_pc_partial_function gets us the value we actually want. */
191 struct symtab_and_line sal
= sals
.sals
[0];
192 CORE_ADDR pc
= sal
.pc
;
193 CORE_ADDR func_start
= 0;
194 struct gdbarch
*arch
= get_sal_arch (sal
);
196 if (!find_pc_partial_function (pc
, &name
, &func_start
, NULL
))
198 error (_("No function found containing program point %s."),
199 paddress (arch
, pc
));
202 skip_function_pc (func_start
, name
, arch
, 0);
208 skip_info (char *arg
, int from_tty
)
210 struct skiplist_entry
*e
;
211 int num_printable_entries
= 0;
212 int address_width
= 10;
213 struct value_print_options opts
;
214 struct cleanup
*tbl_chain
;
216 get_user_print_options (&opts
);
218 /* Count the number of rows in the table and see if we need space for a
219 64-bit address anywhere. */
220 ALL_SKIPLIST_ENTRIES (e
)
221 if (arg
== NULL
|| number_is_in_list (arg
, e
->number
))
223 num_printable_entries
++;
224 if (e
->gdbarch
&& gdbarch_addr_bit (e
->gdbarch
) > 32)
228 if (num_printable_entries
== 0)
231 ui_out_message (current_uiout
, 0, _("\
232 Not skipping any files or functions.\n"));
234 ui_out_message (current_uiout
, 0,
235 _("No skiplist entries found with number %s.\n"), arg
);
240 if (opts
.addressprint
)
241 tbl_chain
= make_cleanup_ui_out_table_begin_end (current_uiout
, 5,
242 num_printable_entries
,
246 = make_cleanup_ui_out_table_begin_end (current_uiout
, 4,
247 num_printable_entries
,
250 ui_out_table_header (current_uiout
, 7, ui_left
, "number", "Num"); /* 1 */
251 ui_out_table_header (current_uiout
, 14, ui_left
, "type", "Type"); /* 2 */
252 ui_out_table_header (current_uiout
, 3, ui_left
, "enabled", "Enb"); /* 3 */
253 if (opts
.addressprint
)
255 ui_out_table_header (current_uiout
, address_width
, ui_left
,
256 "addr", "Address"); /* 4 */
258 ui_out_table_header (current_uiout
, 40, ui_noalign
, "what", "What"); /* 5 */
259 ui_out_table_body (current_uiout
);
261 ALL_SKIPLIST_ENTRIES (e
)
263 struct cleanup
*entry_chain
;
266 if (arg
!= NULL
&& !number_is_in_list (arg
, e
->number
))
269 entry_chain
= make_cleanup_ui_out_tuple_begin_end (current_uiout
,
271 ui_out_field_int (current_uiout
, "number", e
->number
); /* 1 */
273 if (e
->function_name
!= NULL
)
274 ui_out_field_string (current_uiout
, "type", "function"); /* 2 */
275 else if (e
->filename
!= NULL
)
276 ui_out_field_string (current_uiout
, "type", "file"); /* 2 */
278 internal_error (__FILE__
, __LINE__
, _("\
279 Skiplist entry should have either a filename or a function name."));
282 ui_out_field_string (current_uiout
, "enabled", "y"); /* 3 */
284 ui_out_field_string (current_uiout
, "enabled", "n"); /* 3 */
286 if (opts
.addressprint
)
289 ui_out_field_core_addr (current_uiout
, "addr",
290 e
->gdbarch
, e
->pc
); /* 4 */
292 ui_out_field_string (current_uiout
, "addr", ""); /* 4 */
295 if (!e
->pending
&& e
->function_name
!= NULL
)
299 gdb_assert (e
->pc
!= 0);
300 sym
= find_pc_function (e
->pc
);
302 ui_out_field_fmt (current_uiout
, "what", "%s at %s:%d",
304 SYMBOL_SYMTAB (sym
)->filename
,
307 ui_out_field_string (current_uiout
, "what", "?"); /* 5 */
309 else if (e
->pending
&& e
->function_name
!= NULL
)
311 ui_out_field_fmt (current_uiout
, "what", "%s (PENDING)",
312 e
->function_name
); /* 5 */
314 else if (!e
->pending
&& e
->filename
!= NULL
)
315 ui_out_field_string (current_uiout
, "what", e
->filename
); /* 5 */
316 else if (e
->pending
&& e
->filename
!= NULL
)
317 ui_out_field_fmt (current_uiout
, "what", "%s (PENDING)",
318 e
->filename
); /* 5 */
320 ui_out_text (current_uiout
, "\n");
321 do_cleanups (entry_chain
);
324 do_cleanups (tbl_chain
);
328 skip_enable_command (char *arg
, int from_tty
)
330 struct skiplist_entry
*e
;
333 ALL_SKIPLIST_ENTRIES (e
)
334 if (arg
== NULL
|| number_is_in_list (arg
, e
->number
))
341 error (_("No skiplist entries found with number %s."), arg
);
345 skip_disable_command (char *arg
, int from_tty
)
347 struct skiplist_entry
*e
;
350 ALL_SKIPLIST_ENTRIES (e
)
351 if (arg
== NULL
|| number_is_in_list (arg
, e
->number
))
358 error (_("No skiplist entries found with number %s."), arg
);
362 skip_delete_command (char *arg
, int from_tty
)
364 struct skiplist_entry
*e
, *temp
, *b_prev
;
368 ALL_SKIPLIST_ENTRIES_SAFE (e
, temp
)
369 if (arg
== NULL
|| number_is_in_list (arg
, e
->number
))
372 b_prev
->next
= e
->next
;
374 skiplist_entry_chain
= e
->next
;
376 xfree (e
->function_name
);
387 error (_("No skiplist entries found with number %s."), arg
);
390 /* Create a skiplist entry for the given pc corresponding to the given
391 function name and add it to the list. */
394 skip_function_pc (CORE_ADDR pc
, const char *name
, struct gdbarch
*arch
,
397 struct skiplist_entry
*e
= XZALLOC (struct skiplist_entry
);
402 e
->pending
= pending
;
403 e
->function_name
= xstrdup (name
);
405 add_skiplist_entry (e
);
408 printf_filtered (_("Function %s at %s will be skipped when stepping.\n"),
409 name
, paddress (get_current_arch (), pc
));
411 printf_filtered (_("Function %s will be skipped when stepping, "
412 "pending shared library load.\n"),
416 /* Add the given skiplist entry to our list, and set the entry's number. */
419 add_skiplist_entry (struct skiplist_entry
*e
)
421 struct skiplist_entry
*e1
;
423 e
->number
= ++skiplist_entry_count
;
425 /* Add to the end of the chain so that the list of
426 skiplist entries will be in numerical order. */
428 e1
= skiplist_entry_chain
;
430 skiplist_entry_chain
= e
;
439 /* Does the given pc correspond to the beginning of a skipped function? */
442 function_pc_is_marked_for_skip (CORE_ADDR pc
)
444 int searched_for_sal
= 0;
445 struct symtab_and_line sal
;
446 const char *filename
= NULL
;
447 struct skiplist_entry
*e
;
449 ALL_SKIPLIST_ENTRIES (e
)
451 if (!e
->enabled
|| e
->pending
)
454 /* Does the pc we're stepping into match e's stored pc? */
455 if (e
->pc
!= 0 && pc
== e
->pc
)
458 if (e
->filename
!= NULL
)
460 /* Get the filename corresponding to this pc, if we haven't yet. */
461 if (!searched_for_sal
)
463 sal
= find_pc_line (pc
, 0);
464 if (sal
.symtab
!= NULL
)
465 filename
= sal
.symtab
->filename
;
466 searched_for_sal
= 1;
468 if (filename
!= NULL
&& strcmp (filename
, e
->filename
) == 0)
476 /* Re-set the skip list after symbols have been re-loaded. */
481 struct skiplist_entry
*e
;
483 ALL_SKIPLIST_ENTRIES (e
)
485 if (e
->filename
!= NULL
)
487 /* If it's an entry telling us to skip a file, but the entry is
488 currently pending a solib load, let's see if we now know
490 const struct symtab
*symtab
= lookup_symtab (e
->filename
);
495 e
->filename
= xstrdup (symtab
->filename
);
496 e
->gdbarch
= get_objfile_arch (symtab
->objfile
);
504 else if (e
->function_name
!= NULL
)
506 char *func_name
= e
->function_name
;
507 struct symtabs_and_lines sals
= { NULL
};
508 volatile struct gdb_exception decode_exception
;
510 TRY_CATCH (decode_exception
, RETURN_MASK_ERROR
)
512 sals
= decode_line_1 (&func_name
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
516 if (decode_exception
.reason
>= 0
517 && sals
.nelts
== 1 && *func_name
== 0)
519 struct symtab_and_line sal
= sals
.sals
[0];
520 CORE_ADDR pc
= sal
.pc
;
521 CORE_ADDR func_start
= 0;
522 struct gdbarch
*arch
= get_sal_arch (sal
);
523 const char *func_name
;
525 if (find_pc_partial_function (pc
, &func_name
, &func_start
, NULL
))
528 e
->function_name
= xstrdup (func_name
);
541 /* Provide a prototype to silence -Wmissing-prototypes. */
542 extern initialize_file_ftype _initialize_step_skip
;
545 _initialize_step_skip (void)
547 static struct cmd_list_element
*skiplist
= NULL
;
548 struct cmd_list_element
*c
;
550 skiplist_entry_chain
= 0;
551 skiplist_entry_count
= 0;
553 add_prefix_cmd ("skip", class_breakpoint
, skip_function_command
, _("\
554 Ignore a function while stepping.\n\
555 Usage: skip [FUNCTION NAME]\n\
556 If no function name is given, ignore the current function."),
557 &skiplist
, "skip ", 1, &cmdlist
);
559 c
= add_cmd ("file", class_breakpoint
, skip_file_command
, _("\
560 Ignore a file while stepping.\n\
561 Usage: skip file [FILENAME]\n\
562 If no filename is given, ignore the current file."),
564 set_cmd_completer (c
, filename_completer
);
566 c
= add_cmd ("function", class_breakpoint
, skip_function_command
, _("\
567 Ignore a function while stepping.\n\
568 Usage: skip function [FUNCTION NAME]\n\
569 If no function name is given, skip the current function."),
571 set_cmd_completer (c
, location_completer
);
573 add_cmd ("enable", class_breakpoint
, skip_enable_command
, _("\
574 Enable skip entries. You can specify numbers (e.g. \"skip enable 1 3\"), \
575 ranges (e.g. \"skip enable 4-8\"), or both (e.g. \"skip enable 1 3 4-8\").\n\n\
576 If you don't specify any numbers or ranges, we'll enable all skip entries.\n\n\
577 Usage: skip enable [NUMBERS AND/OR RANGES]"),
580 add_cmd ("disable", class_breakpoint
, skip_disable_command
, _("\
581 Disable skip entries. You can specify numbers (e.g. \"skip disable 1 3\"), \
582 ranges (e.g. \"skip disable 4-8\"), or both (e.g. \"skip disable 1 3 4-8\").\n\n\
583 If you don't specify any numbers or ranges, we'll disable all skip entries.\n\n\
584 Usage: skip disable [NUMBERS AND/OR RANGES]"),
587 add_cmd ("delete", class_breakpoint
, skip_delete_command
, _("\
588 Delete skip entries. You can specify numbers (e.g. \"skip delete 1 3\"), \
589 ranges (e.g. \"skip delete 4-8\"), or both (e.g. \"skip delete 1 3 4-8\").\n\n\
590 If you don't specify any numbers or ranges, we'll delete all skip entries.\n\n\
591 Usage: skip delete [NUMBERS AND/OR RANGES]"),
594 add_info ("skip", skip_info
, _("\
595 Display the status of skips. You can specify numbers (e.g. \"skip info 1 3\"), \
596 ranges (e.g. \"skip info 4-8\"), or both (e.g. \"skip info 1 3 4-8\").\n\n\
597 If you don't specify any numbers or ranges, we'll show all skips.\n\n\
598 Usage: skip info [NUMBERS AND/OR RANGES]\n\
599 The \"Type\" column indicates one of:\n\
600 \tfile - ignored file\n\
601 \tfunction - ignored function"));