Commit | Line | Data |
---|---|---|
1bfeeb0f JL |
1 | /* Skipping uninteresting files and functions while stepping. |
2 | ||
32d0add0 | 3 | Copyright (C) 2011-2015 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" | |
1bfeeb0f | 32 | #include "breakpoint.h" /* for get_sal_arch () */ |
05cba821 JK |
33 | #include "source.h" |
34 | #include "filenames.h" | |
1bfeeb0f JL |
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 | |
85817405 | 45 | entry for a function. |
1bfeeb0f JL |
46 | The skiplist entry owns this pointer. */ |
47 | char *function_name; | |
48 | ||
1bfeeb0f | 49 | int enabled; |
1bfeeb0f JL |
50 | |
51 | struct skiplist_entry *next; | |
52 | }; | |
53 | ||
1bfeeb0f | 54 | static void add_skiplist_entry (struct skiplist_entry *e); |
85817405 | 55 | static void skip_function (const char *name); |
1bfeeb0f JL |
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; | |
05cba821 | 72 | struct symtab *symtab; |
3d745be3 | 73 | const char *filename = NULL; |
1bfeeb0f JL |
74 | |
75 | /* If no argument was given, try to default to the last | |
76 | displayed codepoint. */ | |
3d745be3 | 77 | if (arg == NULL) |
1bfeeb0f JL |
78 | { |
79 | symtab = get_last_displayed_symtab (); | |
3d745be3 | 80 | if (symtab == NULL) |
1bfeeb0f | 81 | error (_("No default file now.")); |
05cba821 JK |
82 | |
83 | /* It is not a typo, symtab_to_filename_for_display woule be needlessly | |
84 | ambiguous. */ | |
85 | filename = symtab_to_fullname (symtab); | |
1bfeeb0f JL |
86 | } |
87 | else | |
88 | { | |
89 | symtab = lookup_symtab (arg); | |
3d745be3 | 90 | if (symtab == NULL) |
1bfeeb0f JL |
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; | |
1bfeeb0f | 96 | } |
05cba821 JK |
97 | /* Do not use SYMTAB's filename, later loaded shared libraries may match |
98 | given ARG but not SYMTAB's filename. */ | |
85817405 | 99 | filename = arg; |
1bfeeb0f JL |
100 | } |
101 | ||
41bf6aca | 102 | e = XCNEW (struct skiplist_entry); |
1bfeeb0f JL |
103 | e->filename = xstrdup (filename); |
104 | e->enabled = 1; | |
1bfeeb0f JL |
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 | { | |
2c02bd72 | 114 | const char *name = NULL; |
1bfeeb0f JL |
115 | |
116 | /* Default to the current function if no argument is given. */ | |
3d745be3 | 117 | if (arg == NULL) |
1bfeeb0f JL |
118 | { |
119 | CORE_ADDR pc; | |
3d745be3 | 120 | |
1bfeeb0f JL |
121 | if (!last_displayed_sal_is_valid ()) |
122 | error (_("No default function now.")); | |
123 | ||
124 | pc = get_last_displayed_addr (); | |
85817405 | 125 | if (!find_pc_partial_function (pc, &name, NULL, NULL)) |
1bfeeb0f JL |
126 | { |
127 | error (_("No function found containing current program point %s."), | |
128 | paddress (get_current_arch (), pc)); | |
129 | } | |
85817405 | 130 | skip_function (name); |
1bfeeb0f JL |
131 | } |
132 | else | |
133 | { | |
85817405 | 134 | if (lookup_symbol (arg, NULL, VAR_DOMAIN, NULL) == NULL) |
1bfeeb0f | 135 | { |
1bfeeb0f | 136 | fprintf_filtered (gdb_stderr, |
85817405 | 137 | _("No function found named %s.\n"), arg); |
1bfeeb0f JL |
138 | |
139 | if (nquery (_("\ | |
140 | Ignore function pending future shared library load? "))) | |
141 | { | |
85817405 JK |
142 | /* Add the unverified skiplist entry. */ |
143 | skip_function (arg); | |
1bfeeb0f | 144 | } |
1bfeeb0f JL |
145 | return; |
146 | } | |
147 | ||
85817405 | 148 | skip_function (arg); |
1bfeeb0f JL |
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; | |
1bfeeb0f JL |
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) | |
3d745be3 | 165 | if (arg == NULL || number_is_in_list (arg, e->number)) |
85817405 | 166 | num_printable_entries++; |
1bfeeb0f JL |
167 | |
168 | if (num_printable_entries == 0) | |
169 | { | |
3d745be3 | 170 | if (arg == NULL) |
1bfeeb0f JL |
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 | ||
85817405 JK |
180 | tbl_chain = make_cleanup_ui_out_table_begin_end (current_uiout, 4, |
181 | num_printable_entries, | |
182 | "SkiplistTable"); | |
1bfeeb0f JL |
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 */ | |
85817405 | 187 | ui_out_table_header (current_uiout, 40, ui_noalign, "what", "What"); /* 4 */ |
1bfeeb0f JL |
188 | ui_out_table_body (current_uiout); |
189 | ||
190 | ALL_SKIPLIST_ENTRIES (e) | |
191 | { | |
192 | struct cleanup *entry_chain; | |
193 | ||
194 | QUIT; | |
3d745be3 | 195 | if (arg != NULL && !number_is_in_list (arg, e->number)) |
1bfeeb0f JL |
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 | ||
3d745be3 | 202 | if (e->function_name != NULL) |
1bfeeb0f | 203 | ui_out_field_string (current_uiout, "type", "function"); /* 2 */ |
3d745be3 | 204 | else if (e->filename != NULL) |
1bfeeb0f JL |
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 | ||
85817405 JK |
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 */ | |
1bfeeb0f JL |
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) | |
3d745be3 | 234 | if (arg == NULL || number_is_in_list (arg, e->number)) |
1bfeeb0f JL |
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) | |
3d745be3 | 251 | if (arg == NULL || number_is_in_list (arg, e->number)) |
1bfeeb0f JL |
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) | |
3d745be3 | 269 | if (arg == NULL || number_is_in_list (arg, e->number)) |
1bfeeb0f | 270 | { |
3d745be3 | 271 | if (b_prev != NULL) |
1bfeeb0f JL |
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 | ||
85817405 JK |
290 | /* Create a skiplist entry for the given function NAME and add it to the |
291 | list. */ | |
1bfeeb0f JL |
292 | |
293 | static void | |
85817405 | 294 | skip_function (const char *name) |
1bfeeb0f | 295 | { |
41bf6aca | 296 | struct skiplist_entry *e = XCNEW (struct skiplist_entry); |
1bfeeb0f | 297 | |
1bfeeb0f | 298 | e->enabled = 1; |
1bfeeb0f JL |
299 | e->function_name = xstrdup (name); |
300 | ||
301 | add_skiplist_entry (e); | |
302 | ||
85817405 | 303 | printf_filtered (_("Function %s will be skipped when stepping.\n"), name); |
1bfeeb0f JL |
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; | |
3d745be3 | 319 | if (e1 == NULL) |
1bfeeb0f JL |
320 | skiplist_entry_chain = e; |
321 | else | |
322 | { | |
323 | while (e1->next) | |
324 | e1 = e1->next; | |
325 | e1->next = e; | |
326 | } | |
327 | } | |
328 | ||
85817405 JK |
329 | |
330 | /* See skip.h. */ | |
1bfeeb0f JL |
331 | |
332 | int | |
85817405 JK |
333 | function_name_is_marked_for_skip (const char *function_name, |
334 | const struct symtab_and_line *function_sal) | |
1bfeeb0f | 335 | { |
05cba821 JK |
336 | int searched_for_fullname = 0; |
337 | const char *fullname = NULL; | |
1bfeeb0f JL |
338 | struct skiplist_entry *e; |
339 | ||
85817405 JK |
340 | if (function_name == NULL) |
341 | return 0; | |
342 | ||
1bfeeb0f JL |
343 | ALL_SKIPLIST_ENTRIES (e) |
344 | { | |
85817405 | 345 | if (!e->enabled) |
1bfeeb0f JL |
346 | continue; |
347 | ||
348 | /* Does the pc we're stepping into match e's stored pc? */ | |
85817405 JK |
349 | if (e->function_name != NULL |
350 | && strcmp_iw (function_name, e->function_name) == 0) | |
1bfeeb0f JL |
351 | return 1; |
352 | ||
05cba821 JK |
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 | } | |
1bfeeb0f JL |
382 | } |
383 | ||
384 | return 0; | |
385 | } | |
386 | ||
70221824 PA |
387 | /* Provide a prototype to silence -Wmissing-prototypes. */ |
388 | extern initialize_file_ftype _initialize_step_skip; | |
389 | ||
1bfeeb0f JL |
390 | void |
391 | _initialize_step_skip (void) | |
392 | { | |
8bfd80db | 393 | static struct cmd_list_element *skiplist = NULL; |
1bfeeb0f JL |
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 | } |