S390: Add target descriptions for vector register sets
[binutils-gdb.git] / gdb / skip.c
blobba38194b534c36aac85d5a4fa528ada81184e316
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/>. */
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"
36 struct skiplist_entry
38 int number;
40 /* NULL if this isn't a skiplist entry for an entire file.
41 The skiplist entry owns this pointer. */
42 char *filename;
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. */
47 char *function_name;
49 int enabled;
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; \
66 E = TMP)
68 static void
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. */
77 if (arg == NULL)
79 symtab = get_last_displayed_symtab ();
80 if (symtab == NULL)
81 error (_("No default file now."));
83 /* It is not a typo, symtab_to_filename_for_display woule be needlessly
84 ambiguous. */
85 filename = symtab_to_fullname (symtab);
87 else
89 symtab = lookup_symtab (arg);
90 if (symtab == NULL)
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;
97 /* Do not use SYMTAB's filename, later loaded shared libraries may match
98 given ARG but not SYMTAB's filename. */
99 filename = arg;
102 e = XCNEW (struct skiplist_entry);
103 e->filename = xstrdup (filename);
104 e->enabled = 1;
106 add_skiplist_entry (e);
108 printf_filtered (_("File %s will be skipped when stepping.\n"), filename);
111 static void
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. */
117 if (arg == NULL)
119 CORE_ADDR pc;
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);
132 else
134 if (lookup_symbol (arg, NULL, VAR_DOMAIN, NULL) == NULL)
136 fprintf_filtered (gdb_stderr,
137 _("No function found named %s.\n"), arg);
139 if (nquery (_("\
140 Ignore function pending future shared library load? ")))
142 /* Add the unverified skiplist entry. */
143 skip_function (arg);
145 return;
148 skip_function (arg);
152 static void
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)
170 if (arg == NULL)
171 ui_out_message (current_uiout, 0, _("\
172 Not skipping any files or functions.\n"));
173 else
174 ui_out_message (current_uiout, 0,
175 _("No skiplist entries found with number %s.\n"), arg);
177 return;
180 tbl_chain = make_cleanup_ui_out_table_begin_end (current_uiout, 4,
181 num_printable_entries,
182 "SkiplistTable");
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;
194 QUIT;
195 if (arg != NULL && !number_is_in_list (arg, e->number))
196 continue;
198 entry_chain = make_cleanup_ui_out_tuple_begin_end (current_uiout,
199 "blklst-entry");
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 */
206 else
207 internal_error (__FILE__, __LINE__, _("\
208 Skiplist entry should have either a filename or a function name."));
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 */
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);
227 static void
228 skip_enable_command (char *arg, int from_tty)
230 struct skiplist_entry *e;
231 int found = 0;
233 ALL_SKIPLIST_ENTRIES (e)
234 if (arg == NULL || number_is_in_list (arg, e->number))
236 e->enabled = 1;
237 found = 1;
240 if (!found)
241 error (_("No skiplist entries found with number %s."), arg);
244 static void
245 skip_disable_command (char *arg, int from_tty)
247 struct skiplist_entry *e;
248 int found = 0;
250 ALL_SKIPLIST_ENTRIES (e)
251 if (arg == NULL || number_is_in_list (arg, e->number))
253 e->enabled = 0;
254 found = 1;
257 if (!found)
258 error (_("No skiplist entries found with number %s."), arg);
261 static void
262 skip_delete_command (char *arg, int from_tty)
264 struct skiplist_entry *e, *temp, *b_prev;
265 int found = 0;
267 b_prev = 0;
268 ALL_SKIPLIST_ENTRIES_SAFE (e, temp)
269 if (arg == NULL || number_is_in_list (arg, e->number))
271 if (b_prev != NULL)
272 b_prev->next = e->next;
273 else
274 skiplist_entry_chain = e->next;
276 xfree (e->function_name);
277 xfree (e->filename);
278 xfree (e);
279 found = 1;
281 else
283 b_prev = e;
286 if (!found)
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
291 list. */
293 static void
294 skip_function (const char *name)
296 struct skiplist_entry *e = XCNEW (struct skiplist_entry);
298 e->enabled = 1;
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. */
308 static void
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;
319 if (e1 == NULL)
320 skiplist_entry_chain = e;
321 else
323 while (e1->next)
324 e1 = e1->next;
325 e1->next = e;
330 /* See skip.h. */
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)
341 return 0;
343 ALL_SKIPLIST_ENTRIES (e)
345 if (!e->enabled)
346 continue;
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;
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,
359 e->filename))
360 return 1;
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))
368 continue;
370 /* Get the filename corresponding to this FUNCTION_SAL, if we haven't
371 yet. */
372 if (!searched_for_fullname)
374 if (function_sal->symtab != NULL)
375 fullname = symtab_to_fullname (function_sal->symtab);
376 searched_for_fullname = 1;
378 if (fullname != NULL
379 && compare_filenames_for_search (fullname, e->filename))
380 return 1;
384 return 0;
387 /* Provide a prototype to silence -Wmissing-prototypes. */
388 extern initialize_file_ftype _initialize_step_skip;
390 void
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."),
409 &skiplist);
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."),
416 &skiplist);
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]"),
424 &skiplist);
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]"),
431 &skiplist);
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]"),
438 &skiplist);
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"));