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