gdb/
[deliverable/binutils-gdb.git] / gdb / skip.c
CommitLineData
1bfeeb0f
JL
1/* Skipping uninteresting files and functions while stepping.
2
28e7fd62 3 Copyright (C) 2011-2013 Free Software Foundation, Inc.
1bfeeb0f
JL
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 "gdb_string.h"
24#include "symtab.h"
25#include "gdbcmd.h"
26#include "command.h"
27#include "completer.h"
28#include "stack.h"
29#include "cli/cli-utils.h"
30#include "arch-utils.h"
31#include "linespec.h"
32#include "objfiles.h"
33#include "exceptions.h"
34#include "breakpoint.h" /* for get_sal_arch () */
05cba821
JK
35#include "source.h"
36#include "filenames.h"
1bfeeb0f
JL
37
38struct skiplist_entry
39{
40 int number;
41
42 /* NULL if this isn't a skiplist entry for an entire file.
43 The skiplist entry owns this pointer. */
44 char *filename;
45
46 /* The name of the marked-for-skip function, if this is a skiplist
85817405 47 entry for a function.
1bfeeb0f
JL
48 The skiplist entry owns this pointer. */
49 char *function_name;
50
1bfeeb0f 51 int enabled;
1bfeeb0f
JL
52
53 struct skiplist_entry *next;
54};
55
1bfeeb0f 56static void add_skiplist_entry (struct skiplist_entry *e);
85817405 57static void skip_function (const char *name);
1bfeeb0f
JL
58
59static struct skiplist_entry *skiplist_entry_chain;
60static int skiplist_entry_count;
61
62#define ALL_SKIPLIST_ENTRIES(E) \
63 for (E = skiplist_entry_chain; E; E = E->next)
64
65#define ALL_SKIPLIST_ENTRIES_SAFE(E,TMP) \
66 for (E = skiplist_entry_chain; \
67 E ? (TMP = E->next, 1) : 0; \
68 E = TMP)
69
70static void
71skip_file_command (char *arg, int from_tty)
72{
73 struct skiplist_entry *e;
05cba821 74 struct symtab *symtab;
3d745be3 75 const char *filename = NULL;
1bfeeb0f
JL
76
77 /* If no argument was given, try to default to the last
78 displayed codepoint. */
3d745be3 79 if (arg == NULL)
1bfeeb0f
JL
80 {
81 symtab = get_last_displayed_symtab ();
3d745be3 82 if (symtab == NULL)
1bfeeb0f 83 error (_("No default file now."));
05cba821
JK
84
85 /* It is not a typo, symtab_to_filename_for_display woule be needlessly
86 ambiguous. */
87 filename = symtab_to_fullname (symtab);
1bfeeb0f
JL
88 }
89 else
90 {
91 symtab = lookup_symtab (arg);
3d745be3 92 if (symtab == NULL)
1bfeeb0f
JL
93 {
94 fprintf_filtered (gdb_stderr, _("No source file named %s.\n"), arg);
95 if (!nquery (_("\
96Ignore file pending future shared library load? ")))
97 return;
1bfeeb0f 98 }
05cba821
JK
99 /* Do not use SYMTAB's filename, later loaded shared libraries may match
100 given ARG but not SYMTAB's filename. */
85817405 101 filename = arg;
1bfeeb0f
JL
102 }
103
104 e = XZALLOC (struct skiplist_entry);
105 e->filename = xstrdup (filename);
106 e->enabled = 1;
1bfeeb0f
JL
107
108 add_skiplist_entry (e);
109
110 printf_filtered (_("File %s will be skipped when stepping.\n"), filename);
111}
112
113static void
114skip_function_command (char *arg, int from_tty)
115{
2c02bd72 116 const char *name = NULL;
1bfeeb0f
JL
117
118 /* Default to the current function if no argument is given. */
3d745be3 119 if (arg == NULL)
1bfeeb0f
JL
120 {
121 CORE_ADDR pc;
3d745be3 122
1bfeeb0f
JL
123 if (!last_displayed_sal_is_valid ())
124 error (_("No default function now."));
125
126 pc = get_last_displayed_addr ();
85817405 127 if (!find_pc_partial_function (pc, &name, NULL, NULL))
1bfeeb0f
JL
128 {
129 error (_("No function found containing current program point %s."),
130 paddress (get_current_arch (), pc));
131 }
85817405 132 skip_function (name);
1bfeeb0f
JL
133 }
134 else
135 {
85817405 136 if (lookup_symbol (arg, NULL, VAR_DOMAIN, NULL) == NULL)
1bfeeb0f 137 {
1bfeeb0f 138 fprintf_filtered (gdb_stderr,
85817405 139 _("No function found named %s.\n"), arg);
1bfeeb0f
JL
140
141 if (nquery (_("\
142Ignore function pending future shared library load? ")))
143 {
85817405
JK
144 /* Add the unverified skiplist entry. */
145 skip_function (arg);
1bfeeb0f 146 }
1bfeeb0f
JL
147 return;
148 }
149
85817405 150 skip_function (arg);
1bfeeb0f
JL
151 }
152}
153
154static void
155skip_info (char *arg, int from_tty)
156{
157 struct skiplist_entry *e;
158 int num_printable_entries = 0;
1bfeeb0f
JL
159 struct value_print_options opts;
160 struct cleanup *tbl_chain;
161
162 get_user_print_options (&opts);
163
164 /* Count the number of rows in the table and see if we need space for a
165 64-bit address anywhere. */
166 ALL_SKIPLIST_ENTRIES (e)
3d745be3 167 if (arg == NULL || number_is_in_list (arg, e->number))
85817405 168 num_printable_entries++;
1bfeeb0f
JL
169
170 if (num_printable_entries == 0)
171 {
3d745be3 172 if (arg == NULL)
1bfeeb0f
JL
173 ui_out_message (current_uiout, 0, _("\
174Not skipping any files or functions.\n"));
175 else
176 ui_out_message (current_uiout, 0,
177 _("No skiplist entries found with number %s.\n"), arg);
178
179 return;
180 }
181
85817405
JK
182 tbl_chain = make_cleanup_ui_out_table_begin_end (current_uiout, 4,
183 num_printable_entries,
184 "SkiplistTable");
1bfeeb0f
JL
185
186 ui_out_table_header (current_uiout, 7, ui_left, "number", "Num"); /* 1 */
187 ui_out_table_header (current_uiout, 14, ui_left, "type", "Type"); /* 2 */
188 ui_out_table_header (current_uiout, 3, ui_left, "enabled", "Enb"); /* 3 */
85817405 189 ui_out_table_header (current_uiout, 40, ui_noalign, "what", "What"); /* 4 */
1bfeeb0f
JL
190 ui_out_table_body (current_uiout);
191
192 ALL_SKIPLIST_ENTRIES (e)
193 {
194 struct cleanup *entry_chain;
195
196 QUIT;
3d745be3 197 if (arg != NULL && !number_is_in_list (arg, e->number))
1bfeeb0f
JL
198 continue;
199
200 entry_chain = make_cleanup_ui_out_tuple_begin_end (current_uiout,
201 "blklst-entry");
202 ui_out_field_int (current_uiout, "number", e->number); /* 1 */
203
3d745be3 204 if (e->function_name != NULL)
1bfeeb0f 205 ui_out_field_string (current_uiout, "type", "function"); /* 2 */
3d745be3 206 else if (e->filename != NULL)
1bfeeb0f
JL
207 ui_out_field_string (current_uiout, "type", "file"); /* 2 */
208 else
209 internal_error (__FILE__, __LINE__, _("\
210Skiplist entry should have either a filename or a function name."));
211
212 if (e->enabled)
213 ui_out_field_string (current_uiout, "enabled", "y"); /* 3 */
214 else
215 ui_out_field_string (current_uiout, "enabled", "n"); /* 3 */
216
85817405
JK
217 if (e->function_name != NULL)
218 ui_out_field_string (current_uiout, "what", e->function_name); /* 4 */
219 else if (e->filename != NULL)
220 ui_out_field_string (current_uiout, "what", e->filename); /* 4 */
1bfeeb0f
JL
221
222 ui_out_text (current_uiout, "\n");
223 do_cleanups (entry_chain);
224 }
225
226 do_cleanups (tbl_chain);
227}
228
229static void
230skip_enable_command (char *arg, int from_tty)
231{
232 struct skiplist_entry *e;
233 int found = 0;
234
235 ALL_SKIPLIST_ENTRIES (e)
3d745be3 236 if (arg == NULL || number_is_in_list (arg, e->number))
1bfeeb0f
JL
237 {
238 e->enabled = 1;
239 found = 1;
240 }
241
242 if (!found)
243 error (_("No skiplist entries found with number %s."), arg);
244}
245
246static void
247skip_disable_command (char *arg, int from_tty)
248{
249 struct skiplist_entry *e;
250 int found = 0;
251
252 ALL_SKIPLIST_ENTRIES (e)
3d745be3 253 if (arg == NULL || number_is_in_list (arg, e->number))
1bfeeb0f
JL
254 {
255 e->enabled = 0;
256 found = 1;
257 }
258
259 if (!found)
260 error (_("No skiplist entries found with number %s."), arg);
261}
262
263static void
264skip_delete_command (char *arg, int from_tty)
265{
266 struct skiplist_entry *e, *temp, *b_prev;
267 int found = 0;
268
269 b_prev = 0;
270 ALL_SKIPLIST_ENTRIES_SAFE (e, temp)
3d745be3 271 if (arg == NULL || number_is_in_list (arg, e->number))
1bfeeb0f 272 {
3d745be3 273 if (b_prev != NULL)
1bfeeb0f
JL
274 b_prev->next = e->next;
275 else
276 skiplist_entry_chain = e->next;
277
278 xfree (e->function_name);
279 xfree (e->filename);
280 xfree (e);
281 found = 1;
282 }
283 else
284 {
285 b_prev = e;
286 }
287
288 if (!found)
289 error (_("No skiplist entries found with number %s."), arg);
290}
291
85817405
JK
292/* Create a skiplist entry for the given function NAME and add it to the
293 list. */
1bfeeb0f
JL
294
295static void
85817405 296skip_function (const char *name)
1bfeeb0f
JL
297{
298 struct skiplist_entry *e = XZALLOC (struct skiplist_entry);
299
1bfeeb0f 300 e->enabled = 1;
1bfeeb0f
JL
301 e->function_name = xstrdup (name);
302
303 add_skiplist_entry (e);
304
85817405 305 printf_filtered (_("Function %s will be skipped when stepping.\n"), name);
1bfeeb0f
JL
306}
307
308/* Add the given skiplist entry to our list, and set the entry's number. */
309
310static void
311add_skiplist_entry (struct skiplist_entry *e)
312{
313 struct skiplist_entry *e1;
314
315 e->number = ++skiplist_entry_count;
316
317 /* Add to the end of the chain so that the list of
318 skiplist entries will be in numerical order. */
319
320 e1 = skiplist_entry_chain;
3d745be3 321 if (e1 == NULL)
1bfeeb0f
JL
322 skiplist_entry_chain = e;
323 else
324 {
325 while (e1->next)
326 e1 = e1->next;
327 e1->next = e;
328 }
329}
330
85817405
JK
331
332/* See skip.h. */
1bfeeb0f
JL
333
334int
85817405
JK
335function_name_is_marked_for_skip (const char *function_name,
336 const struct symtab_and_line *function_sal)
1bfeeb0f 337{
05cba821
JK
338 int searched_for_fullname = 0;
339 const char *fullname = NULL;
1bfeeb0f
JL
340 struct skiplist_entry *e;
341
85817405
JK
342 if (function_name == NULL)
343 return 0;
344
1bfeeb0f
JL
345 ALL_SKIPLIST_ENTRIES (e)
346 {
85817405 347 if (!e->enabled)
1bfeeb0f
JL
348 continue;
349
350 /* Does the pc we're stepping into match e's stored pc? */
85817405
JK
351 if (e->function_name != NULL
352 && strcmp_iw (function_name, e->function_name) == 0)
1bfeeb0f
JL
353 return 1;
354
05cba821
JK
355 if (e->filename != NULL)
356 {
357 /* Check first sole SYMTAB->FILENAME. It does not need to be
358 a substring of symtab_to_fullname as it may contain "./" etc. */
359 if (function_sal->symtab != NULL
360 && compare_filenames_for_search (function_sal->symtab->filename,
361 e->filename))
362 return 1;
363
364 /* Before we invoke realpath, which can get expensive when many
365 files are involved, do a quick comparison of the basenames. */
366 if (!basenames_may_differ
367 && (function_sal->symtab == NULL
368 || filename_cmp (lbasename (function_sal->symtab->filename),
369 lbasename (e->filename)) != 0))
370 continue;
371
372 /* Get the filename corresponding to this FUNCTION_SAL, if we haven't
373 yet. */
374 if (!searched_for_fullname)
375 {
376 if (function_sal->symtab != NULL)
377 fullname = symtab_to_fullname (function_sal->symtab);
378 searched_for_fullname = 1;
379 }
380 if (fullname != NULL
381 && compare_filenames_for_search (fullname, e->filename))
382 return 1;
383 }
1bfeeb0f
JL
384 }
385
386 return 0;
387}
388
70221824
PA
389/* Provide a prototype to silence -Wmissing-prototypes. */
390extern initialize_file_ftype _initialize_step_skip;
391
1bfeeb0f
JL
392void
393_initialize_step_skip (void)
394{
8bfd80db 395 static struct cmd_list_element *skiplist = NULL;
1bfeeb0f
JL
396 struct cmd_list_element *c;
397
398 skiplist_entry_chain = 0;
399 skiplist_entry_count = 0;
400
401 add_prefix_cmd ("skip", class_breakpoint, skip_function_command, _("\
402Ignore a function while stepping.\n\
403Usage: skip [FUNCTION NAME]\n\
404If no function name is given, ignore the current function."),
405 &skiplist, "skip ", 1, &cmdlist);
406
407 c = add_cmd ("file", class_breakpoint, skip_file_command, _("\
408Ignore a file while stepping.\n\
409Usage: skip file [FILENAME]\n\
410If no filename is given, ignore the current file."),
411 &skiplist);
412 set_cmd_completer (c, filename_completer);
413
414 c = add_cmd ("function", class_breakpoint, skip_function_command, _("\
415Ignore a function while stepping.\n\
416Usage: skip function [FUNCTION NAME]\n\
417If no function name is given, skip the current function."),
418 &skiplist);
419 set_cmd_completer (c, location_completer);
420
421 add_cmd ("enable", class_breakpoint, skip_enable_command, _("\
422Enable skip entries. You can specify numbers (e.g. \"skip enable 1 3\"), \
423ranges (e.g. \"skip enable 4-8\"), or both (e.g. \"skip enable 1 3 4-8\").\n\n\
424If you don't specify any numbers or ranges, we'll enable all skip entries.\n\n\
425Usage: skip enable [NUMBERS AND/OR RANGES]"),
426 &skiplist);
427
428 add_cmd ("disable", class_breakpoint, skip_disable_command, _("\
429Disable skip entries. You can specify numbers (e.g. \"skip disable 1 3\"), \
430ranges (e.g. \"skip disable 4-8\"), or both (e.g. \"skip disable 1 3 4-8\").\n\n\
431If you don't specify any numbers or ranges, we'll disable all skip entries.\n\n\
432Usage: skip disable [NUMBERS AND/OR RANGES]"),
433 &skiplist);
434
435 add_cmd ("delete", class_breakpoint, skip_delete_command, _("\
436Delete skip entries. You can specify numbers (e.g. \"skip delete 1 3\"), \
437ranges (e.g. \"skip delete 4-8\"), or both (e.g. \"skip delete 1 3 4-8\").\n\n\
438If you don't specify any numbers or ranges, we'll delete all skip entries.\n\n\
439Usage: skip delete [NUMBERS AND/OR RANGES]"),
440 &skiplist);
441
442 add_info ("skip", skip_info, _("\
443Display the status of skips. You can specify numbers (e.g. \"skip info 1 3\"), \
444ranges (e.g. \"skip info 4-8\"), or both (e.g. \"skip info 1 3 4-8\").\n\n\
445If you don't specify any numbers or ranges, we'll show all skips.\n\n\
446Usage: skip info [NUMBERS AND/OR RANGES]\n\
447The \"Type\" column indicates one of:\n\
448\tfile - ignored file\n\
449\tfunction - ignored function"));
450}
This page took 0.17954 seconds and 4 git commands to generate.