Replace the block_found global with explicit data-flow
[deliverable/binutils-gdb.git] / gdb / skip.c
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
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 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
121 if (!last_displayed_sal_is_valid ())
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).symbol == NULL)
135 {
136 fprintf_filtered (gdb_stderr,
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. */
164 ALL_SKIPLIST_ENTRIES (e)
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)
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);
176
177 return;
178 }
179
180 tbl_chain = make_cleanup_ui_out_table_begin_end (current_uiout, 4,
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 */
188 ui_out_table_body (current_uiout);
189
190 ALL_SKIPLIST_ENTRIES (e)
191 {
192 struct cleanup *entry_chain;
193
194 QUIT;
195 if (arg != NULL && !number_is_in_list (arg, e->number))
196 continue;
197
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 */
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
233 ALL_SKIPLIST_ENTRIES (e)
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
250 ALL_SKIPLIST_ENTRIES (e)
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
309 add_skiplist_entry (struct skiplist_entry *e)
310 {
311 struct skiplist_entry *e1;
312
313 e->number = ++skiplist_entry_count;
314
315 /* Add to the end of the chain so that the list of
316 skiplist entries will be in numerical order. */
317
318 e1 = skiplist_entry_chain;
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
333 function_name_is_marked_for_skip (const char *function_name,
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
343 ALL_SKIPLIST_ENTRIES (e)
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. */
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;
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. */
388 extern initialize_file_ftype _initialize_step_skip;
389
390 void
391 _initialize_step_skip (void)
392 {
393 static struct cmd_list_element *skiplist = NULL;
394 struct cmd_list_element *c;
395
396 skiplist_entry_chain = 0;
397 skiplist_entry_count = 0;
398
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);
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
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);
425
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);
432
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);
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 }
This page took 0.038522 seconds and 4 git commands to generate.