GDB (xrefs)
/tmp/gdb-7.10/gdb/skip.c
Go to the documentation of this file.
1 /* Skipping uninteresting files and functions while stepping.
2 
3  Copyright (C) 2011-2015 Free Software Foundation, Inc.
4 
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.
9 
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.
14 
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/>. */
17 
18 #include "defs.h"
19 #include "skip.h"
20 #include "value.h"
21 #include "valprint.h"
22 #include "ui-out.h"
23 #include "symtab.h"
24 #include "gdbcmd.h"
25 #include "command.h"
26 #include "completer.h"
27 #include "stack.h"
28 #include "cli/cli-utils.h"
29 #include "arch-utils.h"
30 #include "linespec.h"
31 #include "objfiles.h"
32 #include "breakpoint.h" /* for get_sal_arch () */
33 #include "source.h"
34 #include "filenames.h"
35 
37 {
38  int number;
39 
40  /* NULL if this isn't a skiplist entry for an entire file.
41  The skiplist entry owns this pointer. */
42  char *filename;
43 
44  /* The name of the marked-for-skip function, if this is a skiplist
45  entry for a function.
46  The skiplist entry owns this pointer. */
48 
49  int enabled;
50 
52 };
53 
54 static void add_skiplist_entry (struct skiplist_entry *e);
55 static void skip_function (const char *name);
56 
59 
60 #define ALL_SKIPLIST_ENTRIES(E) \
61  for (E = skiplist_entry_chain; E; E = E->next)
62 
63 #define ALL_SKIPLIST_ENTRIES_SAFE(E,TMP) \
64  for (E = skiplist_entry_chain; \
65  E ? (TMP = E->next, 1) : 0; \
66  E = TMP)
67 
68 static void
69 skip_file_command (char *arg, int from_tty)
70 {
71  struct skiplist_entry *e;
72  struct symtab *symtab;
73  const char *filename = NULL;
74 
75  /* If no argument was given, try to default to the last
76  displayed codepoint. */
77  if (arg == NULL)
78  {
79  symtab = get_last_displayed_symtab ();
80  if (symtab == NULL)
81  error (_("No default file now."));
82 
83  /* It is not a typo, symtab_to_filename_for_display woule be needlessly
84  ambiguous. */
85  filename = symtab_to_fullname (symtab);
86  }
87  else
88  {
89  symtab = lookup_symtab (arg);
90  if (symtab == NULL)
91  {
92  fprintf_filtered (gdb_stderr, _("No source file named %s.\n"), arg);
93  if (!nquery (_("\
94 Ignore file pending future shared library load? ")))
95  return;
96  }
97  /* Do not use SYMTAB's filename, later loaded shared libraries may match
98  given ARG but not SYMTAB's filename. */
99  filename = arg;
100  }
101 
102  e = XCNEW (struct skiplist_entry);
103  e->filename = xstrdup (filename);
104  e->enabled = 1;
105 
106  add_skiplist_entry (e);
107 
108  printf_filtered (_("File %s will be skipped when stepping.\n"), filename);
109 }
110 
111 static void
112 skip_function_command (char *arg, int from_tty)
113 {
114  const char *name = NULL;
115 
116  /* Default to the current function if no argument is given. */
117  if (arg == NULL)
118  {
119  CORE_ADDR pc;
120 
122  error (_("No default function now."));
123 
124  pc = get_last_displayed_addr ();
125  if (!find_pc_partial_function (pc, &name, NULL, NULL))
126  {
127  error (_("No function found containing current program point %s."),
128  paddress (get_current_arch (), pc));
129  }
130  skip_function (name);
131  }
132  else
133  {
134  if (lookup_symbol (arg, NULL, VAR_DOMAIN, NULL) == NULL)
135  {
137  _("No function found named %s.\n"), arg);
138 
139  if (nquery (_("\
140 Ignore function pending future shared library load? ")))
141  {
142  /* Add the unverified skiplist entry. */
143  skip_function (arg);
144  }
145  return;
146  }
147 
148  skip_function (arg);
149  }
150 }
151 
152 static void
153 skip_info (char *arg, int from_tty)
154 {
155  struct skiplist_entry *e;
156  int num_printable_entries = 0;
157  struct value_print_options opts;
158  struct cleanup *tbl_chain;
159 
160  get_user_print_options (&opts);
161 
162  /* Count the number of rows in the table and see if we need space for a
163  64-bit address anywhere. */
165  if (arg == NULL || number_is_in_list (arg, e->number))
166  num_printable_entries++;
167 
168  if (num_printable_entries == 0)
169  {
170  if (arg == NULL)
172 Not skipping any files or functions.\n"));
173  else
175  _("No skiplist entries found with number %s.\n"), arg);
176 
177  return;
178  }
179 
181  num_printable_entries,
182  "SkiplistTable");
183 
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 */
189 
191  {
192  struct cleanup *entry_chain;
193 
194  QUIT;
195  if (arg != NULL && !number_is_in_list (arg, e->number))
196  continue;
197 
199  "blklst-entry");
200  ui_out_field_int (current_uiout, "number", e->number); /* 1 */
201 
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 */
206  else
207  internal_error (__FILE__, __LINE__, _("\
208 Skiplist entry should have either a filename or a function name."));
209 
210  if (e->enabled)
211  ui_out_field_string (current_uiout, "enabled", "y"); /* 3 */
212  else
213  ui_out_field_string (current_uiout, "enabled", "n"); /* 3 */
214 
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 */
219 
220  ui_out_text (current_uiout, "\n");
221  do_cleanups (entry_chain);
222  }
223 
224  do_cleanups (tbl_chain);
225 }
226 
227 static void
228 skip_enable_command (char *arg, int from_tty)
229 {
230  struct skiplist_entry *e;
231  int found = 0;
232 
234  if (arg == NULL || number_is_in_list (arg, e->number))
235  {
236  e->enabled = 1;
237  found = 1;
238  }
239 
240  if (!found)
241  error (_("No skiplist entries found with number %s."), arg);
242 }
243 
244 static void
245 skip_disable_command (char *arg, int from_tty)
246 {
247  struct skiplist_entry *e;
248  int found = 0;
249 
251  if (arg == NULL || number_is_in_list (arg, e->number))
252  {
253  e->enabled = 0;
254  found = 1;
255  }
256 
257  if (!found)
258  error (_("No skiplist entries found with number %s."), arg);
259 }
260 
261 static void
262 skip_delete_command (char *arg, int from_tty)
263 {
264  struct skiplist_entry *e, *temp, *b_prev;
265  int found = 0;
266 
267  b_prev = 0;
268  ALL_SKIPLIST_ENTRIES_SAFE (e, temp)
269  if (arg == NULL || number_is_in_list (arg, e->number))
270  {
271  if (b_prev != NULL)
272  b_prev->next = e->next;
273  else
274  skiplist_entry_chain = e->next;
275 
276  xfree (e->function_name);
277  xfree (e->filename);
278  xfree (e);
279  found = 1;
280  }
281  else
282  {
283  b_prev = e;
284  }
285 
286  if (!found)
287  error (_("No skiplist entries found with number %s."), arg);
288 }
289 
290 /* Create a skiplist entry for the given function NAME and add it to the
291  list. */
292 
293 static void
294 skip_function (const char *name)
295 {
296  struct skiplist_entry *e = XCNEW (struct skiplist_entry);
297 
298  e->enabled = 1;
299  e->function_name = xstrdup (name);
300 
301  add_skiplist_entry (e);
302 
303  printf_filtered (_("Function %s will be skipped when stepping.\n"), name);
304 }
305 
306 /* Add the given skiplist entry to our list, and set the entry's number. */
307 
308 static void
310 {
311  struct skiplist_entry *e1;
312 
314 
315  /* Add to the end of the chain so that the list of
316  skiplist entries will be in numerical order. */
317 
319  if (e1 == NULL)
320  skiplist_entry_chain = e;
321  else
322  {
323  while (e1->next)
324  e1 = e1->next;
325  e1->next = e;
326  }
327 }
328 
329 
330 /* See skip.h. */
331 
332 int
334  const struct symtab_and_line *function_sal)
335 {
336  int searched_for_fullname = 0;
337  const char *fullname = NULL;
338  struct skiplist_entry *e;
339 
340  if (function_name == NULL)
341  return 0;
342 
344  {
345  if (!e->enabled)
346  continue;
347 
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)
351  return 1;
352 
353  if (e->filename != NULL)
354  {
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,
359  e->filename))
360  return 1;
361 
362  /* Before we invoke realpath, which can get expensive when many
363  files are involved, do a quick comparison of the basenames. */
365  && (function_sal->symtab == NULL
366  || filename_cmp (lbasename (function_sal->symtab->filename),
367  lbasename (e->filename)) != 0))
368  continue;
369 
370  /* Get the filename corresponding to this FUNCTION_SAL, if we haven't
371  yet. */
372  if (!searched_for_fullname)
373  {
374  if (function_sal->symtab != NULL)
375  fullname = symtab_to_fullname (function_sal->symtab);
376  searched_for_fullname = 1;
377  }
378  if (fullname != NULL
379  && compare_filenames_for_search (fullname, e->filename))
380  return 1;
381  }
382  }
383 
384  return 0;
385 }
386 
387 /* Provide a prototype to silence -Wmissing-prototypes. */
389 
390 void
392 {
393  static struct cmd_list_element *skiplist = NULL;
394  struct cmd_list_element *c;
395 
396  skiplist_entry_chain = 0;
398 
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);
404 
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."),
409  &skiplist);
410  set_cmd_completer (c, filename_completer);
411 
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."),
416  &skiplist);
417  set_cmd_completer (c, location_completer);
418 
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]"),
424  &skiplist);
425 
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]"),
431  &skiplist);
432 
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]"),
438  &skiplist);
439 
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"));
448 }
CORE_ADDR get_last_displayed_addr(void)
Definition: stack.c:1000
struct cmd_list_element * add_prefix_cmd(const char *name, enum command_class theclass, cmd_cfunc_ftype *fun, const char *doc, struct cmd_list_element **prefixlist, const char *prefixname, int allow_unknown, struct cmd_list_element **list)
Definition: cli-decode.c:338
int function_name_is_marked_for_skip(const char *function_name, const struct symtab_and_line *function_sal)
Definition: skip.c:333
void ui_out_field_int(struct ui_out *uiout, const char *fldname, int value)
Definition: ui-out.c:467
bfd_vma CORE_ADDR
Definition: common-types.h:41
void xfree(void *)
Definition: common-utils.c:97
int strcmp_iw(const char *string1, const char *string2)
Definition: utils.c:2511
static struct skiplist_entry * skiplist_entry_chain
Definition: skip.c:57
int number_is_in_list(const char *list, int number)
Definition: cli-utils.c:205
struct cleanup * make_cleanup_ui_out_table_begin_end(struct ui_out *ui_out, int nr_cols, int nr_rows, const char *tblid)
Definition: ui-out.c:369
static int skiplist_entry_count
Definition: skip.c:58
int compare_filenames_for_search(const char *filename, const char *search_name)
Definition: symtab.c:313
struct symtab * lookup_symtab(const char *name)
Definition: symtab.c:489
void internal_error(const char *file, int line, const char *fmt,...)
Definition: errors.c:50
static void skip_enable_command(char *arg, int from_tty)
Definition: skip.c:228
static void skip_disable_command(char *arg, int from_tty)
Definition: skip.c:245
char * filename
Definition: skip.c:42
struct cmd_list_element * cmdlist
Definition: cli-cmds.c:103
static void add_skiplist_entry(struct skiplist_entry *e)
Definition: skip.c:309
const char * filename
Definition: symtab.h:943
#define _(String)
Definition: gdb_locale.h:40
Definition: ui-out.h:40
#define ALL_SKIPLIST_ENTRIES_SAFE(E, TMP)
Definition: skip.c:63
static void skip_function_command(char *arg, int from_tty)
Definition: skip.c:112
void ui_out_text(struct ui_out *uiout, const char *string)
Definition: ui-out.c:582
void printf_filtered(const char *format,...)
Definition: utils.c:2388
const char * paddress(struct gdbarch *gdbarch, CORE_ADDR addr)
Definition: utils.c:2743
const char * symtab_to_fullname(struct symtab *s)
Definition: source.c:1131
#define ALL_SKIPLIST_ENTRIES(E)
Definition: skip.c:60
const char *const name
Definition: aarch64-tdep.c:68
static void skip_info(char *arg, int from_tty)
Definition: skip.c:153
int enabled
Definition: skip.c:49
void initialize_file_ftype(void)
Definition: defs.h:281
struct cleanup * make_cleanup_ui_out_tuple_begin_end(struct ui_out *uiout, const char *id)
Definition: ui-out.c:451
void fprintf_filtered(struct ui_file *stream, const char *format,...)
Definition: utils.c:2351
void set_cmd_completer(struct cmd_list_element *cmd, completer_ftype *completer)
Definition: cli-decode.c:159
void ui_out_message(struct ui_out *uiout, int verbosity, const char *format,...)
Definition: ui-out.c:589
struct cmd_list_element * add_cmd(const char *name, enum command_class theclass, cmd_cfunc_ftype *fun, const char *doc, struct cmd_list_element **list)
Definition: cli-decode.c:192
int find_pc_partial_function(CORE_ADDR pc, const char **name, CORE_ADDR *address, CORE_ADDR *endaddr)
Definition: blockframe.c:321
struct cmd_list_element * add_info(const char *name, cmd_cfunc_ftype *fun, const char *doc)
Definition: cli-decode.c:857
struct gdbarch * get_current_arch(void)
Definition: arch-utils.c:781
int nquery(const char *ctlstr,...)
Definition: utils.c:1329
int number
Definition: skip.c:38
Definition: symtab.h:925
int basenames_may_differ
Definition: symtab.c:220
struct symtab * symtab
Definition: symtab.h:1369
struct symtab * get_last_displayed_symtab(void)
Definition: stack.c:1010
char * function_name
Definition: skip.c:47
int last_displayed_sal_is_valid(void)
Definition: stack.c:982
static void skip_function(const char *name)
Definition: skip.c:294
struct ui_file * gdb_stderr
Definition: main.c:72
struct symbol * lookup_symbol(const char *name, const struct block *block, domain_enum domain, struct field_of_this_result *is_a_field_of_this)
Definition: symtab.c:1967
void get_user_print_options(struct value_print_options *opts)
Definition: valprint.c:129
void ui_out_table_header(struct ui_out *uiout, int width, enum ui_align alignment, const char *col_name, const char *colhdr)
Definition: ui-out.c:346
void ui_out_field_string(struct ui_out *uiout, const char *fldname, const char *string)
Definition: ui-out.c:541
void ui_out_table_body(struct ui_out *uiout)
Definition: ui-out.c:309
void * arg
Definition: cleanups.c:43
struct ui_out * current_uiout
Definition: ui-out.c:233
initialize_file_ftype _initialize_step_skip
#define QUIT
Definition: defs.h:160
static void skip_delete_command(char *arg, int from_tty)
Definition: skip.c:262
void error(const char *fmt,...)
Definition: errors.c:38
void do_cleanups(struct cleanup *old_chain)
Definition: cleanups.c:175
Definition: skip.c:36
static void skip_file_command(char *arg, int from_tty)
Definition: skip.c:69
struct skiplist_entry * next
Definition: skip.c:51