Update years in copyright notice for the GDB files.
[deliverable/binutils-gdb.git] / gdb / skip.c
1 /* Skipping uninteresting files and functions while stepping.
2
3 Copyright (C) 2011-2013 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 "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 () */
35
36 struct skiplist_entry
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. */
47 char *function_name;
48
49 int enabled;
50
51 struct skiplist_entry *next;
52 };
53
54 static void add_skiplist_entry (struct skiplist_entry *e);
55 static void skip_function (const char *name);
56
57 static struct skiplist_entry *skiplist_entry_chain;
58 static int skiplist_entry_count;
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 const 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 else
83 filename = symtab->filename;
84 }
85 else
86 {
87 symtab = lookup_symtab (arg);
88 if (symtab == NULL)
89 {
90 fprintf_filtered (gdb_stderr, _("No source file named %s.\n"), arg);
91 if (!nquery (_("\
92 Ignore file pending future shared library load? ")))
93 return;
94
95 }
96 filename = arg;
97 }
98
99 e = XZALLOC (struct skiplist_entry);
100 e->filename = xstrdup (filename);
101 e->enabled = 1;
102
103 add_skiplist_entry (e);
104
105 printf_filtered (_("File %s will be skipped when stepping.\n"), filename);
106 }
107
108 static void
109 skip_function_command (char *arg, int from_tty)
110 {
111 const char *name = NULL;
112
113 /* Default to the current function if no argument is given. */
114 if (arg == NULL)
115 {
116 CORE_ADDR pc;
117
118 if (!last_displayed_sal_is_valid ())
119 error (_("No default function now."));
120
121 pc = get_last_displayed_addr ();
122 if (!find_pc_partial_function (pc, &name, NULL, NULL))
123 {
124 error (_("No function found containing current program point %s."),
125 paddress (get_current_arch (), pc));
126 }
127 skip_function (name);
128 }
129 else
130 {
131 if (lookup_symbol (arg, NULL, VAR_DOMAIN, NULL) == NULL)
132 {
133 fprintf_filtered (gdb_stderr,
134 _("No function found named %s.\n"), arg);
135
136 if (nquery (_("\
137 Ignore function pending future shared library load? ")))
138 {
139 /* Add the unverified skiplist entry. */
140 skip_function (arg);
141 }
142 return;
143 }
144
145 skip_function (arg);
146 }
147 }
148
149 static void
150 skip_info (char *arg, int from_tty)
151 {
152 struct skiplist_entry *e;
153 int num_printable_entries = 0;
154 struct value_print_options opts;
155 struct cleanup *tbl_chain;
156
157 get_user_print_options (&opts);
158
159 /* Count the number of rows in the table and see if we need space for a
160 64-bit address anywhere. */
161 ALL_SKIPLIST_ENTRIES (e)
162 if (arg == NULL || number_is_in_list (arg, e->number))
163 num_printable_entries++;
164
165 if (num_printable_entries == 0)
166 {
167 if (arg == NULL)
168 ui_out_message (current_uiout, 0, _("\
169 Not skipping any files or functions.\n"));
170 else
171 ui_out_message (current_uiout, 0,
172 _("No skiplist entries found with number %s.\n"), arg);
173
174 return;
175 }
176
177 tbl_chain = make_cleanup_ui_out_table_begin_end (current_uiout, 4,
178 num_printable_entries,
179 "SkiplistTable");
180
181 ui_out_table_header (current_uiout, 7, ui_left, "number", "Num"); /* 1 */
182 ui_out_table_header (current_uiout, 14, ui_left, "type", "Type"); /* 2 */
183 ui_out_table_header (current_uiout, 3, ui_left, "enabled", "Enb"); /* 3 */
184 ui_out_table_header (current_uiout, 40, ui_noalign, "what", "What"); /* 4 */
185 ui_out_table_body (current_uiout);
186
187 ALL_SKIPLIST_ENTRIES (e)
188 {
189 struct cleanup *entry_chain;
190
191 QUIT;
192 if (arg != NULL && !number_is_in_list (arg, e->number))
193 continue;
194
195 entry_chain = make_cleanup_ui_out_tuple_begin_end (current_uiout,
196 "blklst-entry");
197 ui_out_field_int (current_uiout, "number", e->number); /* 1 */
198
199 if (e->function_name != NULL)
200 ui_out_field_string (current_uiout, "type", "function"); /* 2 */
201 else if (e->filename != NULL)
202 ui_out_field_string (current_uiout, "type", "file"); /* 2 */
203 else
204 internal_error (__FILE__, __LINE__, _("\
205 Skiplist entry should have either a filename or a function name."));
206
207 if (e->enabled)
208 ui_out_field_string (current_uiout, "enabled", "y"); /* 3 */
209 else
210 ui_out_field_string (current_uiout, "enabled", "n"); /* 3 */
211
212 if (e->function_name != NULL)
213 ui_out_field_string (current_uiout, "what", e->function_name); /* 4 */
214 else if (e->filename != NULL)
215 ui_out_field_string (current_uiout, "what", e->filename); /* 4 */
216
217 ui_out_text (current_uiout, "\n");
218 do_cleanups (entry_chain);
219 }
220
221 do_cleanups (tbl_chain);
222 }
223
224 static void
225 skip_enable_command (char *arg, int from_tty)
226 {
227 struct skiplist_entry *e;
228 int found = 0;
229
230 ALL_SKIPLIST_ENTRIES (e)
231 if (arg == NULL || number_is_in_list (arg, e->number))
232 {
233 e->enabled = 1;
234 found = 1;
235 }
236
237 if (!found)
238 error (_("No skiplist entries found with number %s."), arg);
239 }
240
241 static void
242 skip_disable_command (char *arg, int from_tty)
243 {
244 struct skiplist_entry *e;
245 int found = 0;
246
247 ALL_SKIPLIST_ENTRIES (e)
248 if (arg == NULL || number_is_in_list (arg, e->number))
249 {
250 e->enabled = 0;
251 found = 1;
252 }
253
254 if (!found)
255 error (_("No skiplist entries found with number %s."), arg);
256 }
257
258 static void
259 skip_delete_command (char *arg, int from_tty)
260 {
261 struct skiplist_entry *e, *temp, *b_prev;
262 int found = 0;
263
264 b_prev = 0;
265 ALL_SKIPLIST_ENTRIES_SAFE (e, temp)
266 if (arg == NULL || number_is_in_list (arg, e->number))
267 {
268 if (b_prev != NULL)
269 b_prev->next = e->next;
270 else
271 skiplist_entry_chain = e->next;
272
273 xfree (e->function_name);
274 xfree (e->filename);
275 xfree (e);
276 found = 1;
277 }
278 else
279 {
280 b_prev = e;
281 }
282
283 if (!found)
284 error (_("No skiplist entries found with number %s."), arg);
285 }
286
287 /* Create a skiplist entry for the given function NAME and add it to the
288 list. */
289
290 static void
291 skip_function (const char *name)
292 {
293 struct skiplist_entry *e = XZALLOC (struct skiplist_entry);
294
295 e->enabled = 1;
296 e->function_name = xstrdup (name);
297
298 add_skiplist_entry (e);
299
300 printf_filtered (_("Function %s will be skipped when stepping.\n"), name);
301 }
302
303 /* Add the given skiplist entry to our list, and set the entry's number. */
304
305 static void
306 add_skiplist_entry (struct skiplist_entry *e)
307 {
308 struct skiplist_entry *e1;
309
310 e->number = ++skiplist_entry_count;
311
312 /* Add to the end of the chain so that the list of
313 skiplist entries will be in numerical order. */
314
315 e1 = skiplist_entry_chain;
316 if (e1 == NULL)
317 skiplist_entry_chain = e;
318 else
319 {
320 while (e1->next)
321 e1 = e1->next;
322 e1->next = e;
323 }
324 }
325
326
327 /* See skip.h. */
328
329 int
330 function_name_is_marked_for_skip (const char *function_name,
331 const struct symtab_and_line *function_sal)
332 {
333 struct skiplist_entry *e;
334
335 if (function_name == NULL)
336 return 0;
337
338 ALL_SKIPLIST_ENTRIES (e)
339 {
340 if (!e->enabled)
341 continue;
342
343 /* Does the pc we're stepping into match e's stored pc? */
344 if (e->function_name != NULL
345 && strcmp_iw (function_name, e->function_name) == 0)
346 return 1;
347
348 if (e->filename != NULL && function_sal->symtab != NULL
349 && function_sal->symtab->filename != NULL
350 && compare_filenames_for_search (function_sal->symtab->filename,
351 e->filename))
352 return 1;
353 }
354
355 return 0;
356 }
357
358 /* Provide a prototype to silence -Wmissing-prototypes. */
359 extern initialize_file_ftype _initialize_step_skip;
360
361 void
362 _initialize_step_skip (void)
363 {
364 static struct cmd_list_element *skiplist = NULL;
365 struct cmd_list_element *c;
366
367 skiplist_entry_chain = 0;
368 skiplist_entry_count = 0;
369
370 add_prefix_cmd ("skip", class_breakpoint, skip_function_command, _("\
371 Ignore a function while stepping.\n\
372 Usage: skip [FUNCTION NAME]\n\
373 If no function name is given, ignore the current function."),
374 &skiplist, "skip ", 1, &cmdlist);
375
376 c = add_cmd ("file", class_breakpoint, skip_file_command, _("\
377 Ignore a file while stepping.\n\
378 Usage: skip file [FILENAME]\n\
379 If no filename is given, ignore the current file."),
380 &skiplist);
381 set_cmd_completer (c, filename_completer);
382
383 c = add_cmd ("function", class_breakpoint, skip_function_command, _("\
384 Ignore a function while stepping.\n\
385 Usage: skip function [FUNCTION NAME]\n\
386 If no function name is given, skip the current function."),
387 &skiplist);
388 set_cmd_completer (c, location_completer);
389
390 add_cmd ("enable", class_breakpoint, skip_enable_command, _("\
391 Enable skip entries. You can specify numbers (e.g. \"skip enable 1 3\"), \
392 ranges (e.g. \"skip enable 4-8\"), or both (e.g. \"skip enable 1 3 4-8\").\n\n\
393 If you don't specify any numbers or ranges, we'll enable all skip entries.\n\n\
394 Usage: skip enable [NUMBERS AND/OR RANGES]"),
395 &skiplist);
396
397 add_cmd ("disable", class_breakpoint, skip_disable_command, _("\
398 Disable skip entries. You can specify numbers (e.g. \"skip disable 1 3\"), \
399 ranges (e.g. \"skip disable 4-8\"), or both (e.g. \"skip disable 1 3 4-8\").\n\n\
400 If you don't specify any numbers or ranges, we'll disable all skip entries.\n\n\
401 Usage: skip disable [NUMBERS AND/OR RANGES]"),
402 &skiplist);
403
404 add_cmd ("delete", class_breakpoint, skip_delete_command, _("\
405 Delete skip entries. You can specify numbers (e.g. \"skip delete 1 3\"), \
406 ranges (e.g. \"skip delete 4-8\"), or both (e.g. \"skip delete 1 3 4-8\").\n\n\
407 If you don't specify any numbers or ranges, we'll delete all skip entries.\n\n\
408 Usage: skip delete [NUMBERS AND/OR RANGES]"),
409 &skiplist);
410
411 add_info ("skip", skip_info, _("\
412 Display the status of skips. You can specify numbers (e.g. \"skip info 1 3\"), \
413 ranges (e.g. \"skip info 4-8\"), or both (e.g. \"skip info 1 3 4-8\").\n\n\
414 If you don't specify any numbers or ranges, we'll show all skips.\n\n\
415 Usage: skip info [NUMBERS AND/OR RANGES]\n\
416 The \"Type\" column indicates one of:\n\
417 \tfile - ignored file\n\
418 \tfunction - ignored function"));
419 }
This page took 0.059898 seconds and 5 git commands to generate.