Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Everything about breakpoints, for GDB. |
8926118c | 2 | |
6aba47ca | 3 | Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, |
9b254dd1 | 4 | 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, |
0fb0cc75 | 5 | 2008, 2009 Free Software Foundation, Inc. |
c906108c | 6 | |
c5aa993b | 7 | This file is part of GDB. |
c906108c | 8 | |
c5aa993b JM |
9 | This program is free software; you can redistribute it and/or modify |
10 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 11 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 12 | (at your option) any later version. |
c906108c | 13 | |
c5aa993b JM |
14 | This program is distributed in the hope that it will be useful, |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | GNU General Public License for more details. | |
c906108c | 18 | |
c5aa993b | 19 | You should have received a copy of the GNU General Public License |
a9762ec7 | 20 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
21 | |
22 | #include "defs.h" | |
a6d9a66e | 23 | #include "arch-utils.h" |
c906108c | 24 | #include <ctype.h> |
776592bf | 25 | #include "hashtab.h" |
c906108c SS |
26 | #include "symtab.h" |
27 | #include "frame.h" | |
28 | #include "breakpoint.h" | |
1042e4c0 | 29 | #include "tracepoint.h" |
c906108c SS |
30 | #include "gdbtypes.h" |
31 | #include "expression.h" | |
32 | #include "gdbcore.h" | |
33 | #include "gdbcmd.h" | |
34 | #include "value.h" | |
35 | #include "command.h" | |
36 | #include "inferior.h" | |
37 | #include "gdbthread.h" | |
38 | #include "target.h" | |
39 | #include "language.h" | |
40 | #include "gdb_string.h" | |
41 | #include "demangle.h" | |
42 | #include "annotate.h" | |
43 | #include "symfile.h" | |
44 | #include "objfiles.h" | |
0378c332 | 45 | #include "source.h" |
c5f0f3d0 | 46 | #include "linespec.h" |
c94fdfd0 | 47 | #include "completer.h" |
5b7f31a4 | 48 | #include "gdb.h" |
8b93c638 | 49 | #include "ui-out.h" |
e1507482 | 50 | #include "cli/cli-script.h" |
0225421b | 51 | #include "gdb_assert.h" |
fe898f56 | 52 | #include "block.h" |
a77053c2 | 53 | #include "solib.h" |
84acb35a JJ |
54 | #include "solist.h" |
55 | #include "observer.h" | |
60250e8b | 56 | #include "exceptions.h" |
765dc015 | 57 | #include "memattr.h" |
f7f9143b | 58 | #include "ada-lang.h" |
d1aa2f50 | 59 | #include "top.h" |
fa4727a6 | 60 | #include "wrapper.h" |
79a45b7d | 61 | #include "valprint.h" |
4efc6507 | 62 | #include "jit.h" |
c906108c | 63 | |
1042e4c0 SS |
64 | /* readline include files */ |
65 | #include "readline/readline.h" | |
66 | #include "readline/history.h" | |
67 | ||
68 | /* readline defines this. */ | |
69 | #undef savestring | |
70 | ||
034dad6f | 71 | #include "mi/mi-common.h" |
104c1213 | 72 | |
44feb3ce TT |
73 | /* Arguments to pass as context to some catch command handlers. */ |
74 | #define CATCH_PERMANENT ((void *) (uintptr_t) 0) | |
75 | #define CATCH_TEMPORARY ((void *) (uintptr_t) 1) | |
c906108c | 76 | |
44feb3ce | 77 | /* Prototypes for local functions. */ |
c906108c | 78 | |
a14ed312 | 79 | static void enable_delete_command (char *, int); |
c906108c | 80 | |
a14ed312 | 81 | static void enable_delete_breakpoint (struct breakpoint *); |
c906108c | 82 | |
a14ed312 | 83 | static void enable_once_command (char *, int); |
c906108c | 84 | |
a14ed312 | 85 | static void enable_once_breakpoint (struct breakpoint *); |
c906108c | 86 | |
a14ed312 | 87 | static void disable_command (char *, int); |
c906108c | 88 | |
a14ed312 | 89 | static void enable_command (char *, int); |
c906108c | 90 | |
a14ed312 | 91 | static void map_breakpoint_numbers (char *, void (*)(struct breakpoint *)); |
c906108c | 92 | |
a14ed312 | 93 | static void ignore_command (char *, int); |
c906108c | 94 | |
4efb68b1 | 95 | static int breakpoint_re_set_one (void *); |
c906108c | 96 | |
a14ed312 | 97 | static void clear_command (char *, int); |
c906108c | 98 | |
a14ed312 | 99 | static void catch_command (char *, int); |
c906108c | 100 | |
a14ed312 | 101 | static void watch_command (char *, int); |
c906108c | 102 | |
a14ed312 | 103 | static int can_use_hardware_watchpoint (struct value *); |
c906108c | 104 | |
98deb0da | 105 | static void break_command_1 (char *, int, int); |
c906108c | 106 | |
a14ed312 | 107 | static void mention (struct breakpoint *); |
c906108c | 108 | |
63c252f8 PM |
109 | /* This function is used in gdbtk sources and thus can not be made static. */ |
110 | struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch, | |
a6d9a66e UW |
111 | struct symtab_and_line, |
112 | enum bptype); | |
c906108c | 113 | |
9f60f21b | 114 | static void check_duplicates (struct breakpoint *); |
c906108c | 115 | |
76897487 KB |
116 | static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); |
117 | ||
a6d9a66e UW |
118 | static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch, |
119 | CORE_ADDR bpaddr, | |
88f7da05 | 120 | enum bptype bptype); |
76897487 | 121 | |
5af949e3 UW |
122 | static void describe_other_breakpoints (struct gdbarch *, CORE_ADDR, |
123 | struct obj_section *, int); | |
c906108c | 124 | |
a14ed312 | 125 | static void breakpoints_info (char *, int); |
c906108c | 126 | |
a14ed312 | 127 | static void breakpoint_1 (int, int); |
c906108c | 128 | |
89f9893c | 129 | static bpstat bpstat_alloc (const struct bp_location *, bpstat); |
c906108c | 130 | |
4efb68b1 | 131 | static int breakpoint_cond_eval (void *); |
c906108c | 132 | |
4efb68b1 | 133 | static void cleanup_executing_breakpoints (void *); |
c906108c | 134 | |
a14ed312 | 135 | static void commands_command (char *, int); |
c906108c | 136 | |
a14ed312 | 137 | static void condition_command (char *, int); |
c906108c | 138 | |
a14ed312 | 139 | static int get_number_trailer (char **, int); |
c906108c | 140 | |
a14ed312 | 141 | void set_breakpoint_count (int); |
c906108c | 142 | |
c5aa993b JM |
143 | typedef enum |
144 | { | |
145 | mark_inserted, | |
146 | mark_uninserted | |
147 | } | |
148 | insertion_state_t; | |
c906108c | 149 | |
0bde7532 | 150 | static int remove_breakpoint (struct bp_location *, insertion_state_t); |
c906108c | 151 | |
a14ed312 | 152 | static enum print_stop_action print_it_typical (bpstat); |
e514a9d6 JM |
153 | |
154 | static enum print_stop_action print_bp_stop_message (bpstat bs); | |
c906108c | 155 | |
4efb68b1 | 156 | static int watchpoint_check (void *); |
c906108c | 157 | |
a14ed312 | 158 | static void maintenance_info_breakpoints (char *, int); |
c906108c | 159 | |
a14ed312 | 160 | static int hw_breakpoint_used_count (void); |
c906108c | 161 | |
a14ed312 | 162 | static int hw_watchpoint_used_count (enum bptype, int *); |
c906108c | 163 | |
a14ed312 | 164 | static void hbreak_command (char *, int); |
c906108c | 165 | |
a14ed312 | 166 | static void thbreak_command (char *, int); |
c906108c | 167 | |
a14ed312 | 168 | static void watch_command_1 (char *, int, int); |
c906108c | 169 | |
a14ed312 | 170 | static void rwatch_command (char *, int); |
c906108c | 171 | |
a14ed312 | 172 | static void awatch_command (char *, int); |
c906108c | 173 | |
a14ed312 | 174 | static void do_enable_breakpoint (struct breakpoint *, enum bpdisp); |
c906108c | 175 | |
a14ed312 | 176 | static void stop_command (char *arg, int from_tty); |
7a292a7a | 177 | |
a14ed312 | 178 | static void stopin_command (char *arg, int from_tty); |
7a292a7a | 179 | |
a14ed312 | 180 | static void stopat_command (char *arg, int from_tty); |
7a292a7a | 181 | |
a14ed312 | 182 | static char *ep_parse_optional_if_clause (char **arg); |
7a292a7a | 183 | |
a14ed312 | 184 | static char *ep_parse_optional_filename (char **arg); |
7a292a7a | 185 | |
d85310f7 MS |
186 | static void catch_exception_command_1 (enum exception_event_kind ex_event, |
187 | char *arg, int tempflag, int from_tty); | |
7a292a7a | 188 | |
a14ed312 | 189 | static void tcatch_command (char *arg, int from_tty); |
7a292a7a | 190 | |
a14ed312 | 191 | static void ep_skip_leading_whitespace (char **s); |
7a292a7a | 192 | |
1aafd4da UW |
193 | static int single_step_breakpoint_inserted_here_p (CORE_ADDR pc); |
194 | ||
fe3f5fa8 VP |
195 | static void free_bp_location (struct bp_location *loc); |
196 | ||
39d61571 | 197 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
a5606eee | 198 | |
b60e7edf | 199 | static void update_global_location_list (int); |
a5606eee | 200 | |
b60e7edf | 201 | static void update_global_location_list_nothrow (int); |
74960c60 VP |
202 | |
203 | static int is_hardware_watchpoint (struct breakpoint *bpt); | |
204 | ||
205 | static void insert_breakpoint_locations (void); | |
a5606eee | 206 | |
1042e4c0 SS |
207 | static void tracepoints_info (char *, int); |
208 | ||
209 | static void delete_trace_command (char *, int); | |
210 | ||
211 | static void enable_trace_command (char *, int); | |
212 | ||
213 | static void disable_trace_command (char *, int); | |
214 | ||
215 | static void trace_pass_command (char *, int); | |
216 | ||
3daf8fe5 JG |
217 | static void skip_prologue_sal (struct symtab_and_line *sal); |
218 | ||
219 | ||
f3b1572e PA |
220 | /* Flag indicating that a command has proceeded the inferior past the |
221 | current breakpoint. */ | |
222 | ||
223 | static int breakpoint_proceeded; | |
224 | ||
2cec12e5 AR |
225 | static const char * |
226 | bpdisp_text (enum bpdisp disp) | |
227 | { | |
228 | /* NOTE: the following values are a part of MI protocol and represent | |
229 | values of 'disp' field returned when inferior stops at a breakpoint. */ | |
230 | static char *bpdisps[] = {"del", "dstp", "dis", "keep"}; | |
231 | return bpdisps[(int) disp]; | |
232 | } | |
c906108c | 233 | |
2cec12e5 | 234 | /* Prototypes for exported functions. */ |
c906108c SS |
235 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
236 | if such is available. */ | |
237 | static int can_use_hw_watchpoints; | |
238 | ||
920d2a44 AC |
239 | static void |
240 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, | |
241 | struct cmd_list_element *c, | |
242 | const char *value) | |
243 | { | |
244 | fprintf_filtered (file, _("\ | |
245 | Debugger's willingness to use watchpoint hardware is %s.\n"), | |
246 | value); | |
247 | } | |
248 | ||
fa8d40ab JJ |
249 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
250 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints | |
251 | for unrecognized breakpoint locations. | |
252 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ | |
253 | static enum auto_boolean pending_break_support; | |
920d2a44 AC |
254 | static void |
255 | show_pending_break_support (struct ui_file *file, int from_tty, | |
256 | struct cmd_list_element *c, | |
257 | const char *value) | |
258 | { | |
259 | fprintf_filtered (file, _("\ | |
260 | Debugger's behavior regarding pending breakpoints is %s.\n"), | |
261 | value); | |
262 | } | |
fa8d40ab | 263 | |
765dc015 VP |
264 | /* If 1, gdb will automatically use hardware breakpoints for breakpoints |
265 | set with "break" but falling in read-only memory. | |
266 | If 0, gdb will warn about such breakpoints, but won't automatically | |
267 | use hardware breakpoints. */ | |
268 | static int automatic_hardware_breakpoints; | |
269 | static void | |
270 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, | |
271 | struct cmd_list_element *c, | |
272 | const char *value) | |
273 | { | |
274 | fprintf_filtered (file, _("\ | |
275 | Automatic usage of hardware breakpoints is %s.\n"), | |
276 | value); | |
277 | } | |
278 | ||
33e5cbd6 PA |
279 | /* If on, gdb will keep breakpoints inserted even as inferior is |
280 | stopped, and immediately insert any new breakpoints. If off, gdb | |
281 | will insert breakpoints into inferior only when resuming it, and | |
282 | will remove breakpoints upon stop. If auto, GDB will behave as ON | |
283 | if in non-stop mode, and as OFF if all-stop mode.*/ | |
284 | ||
285 | static const char always_inserted_auto[] = "auto"; | |
286 | static const char always_inserted_on[] = "on"; | |
287 | static const char always_inserted_off[] = "off"; | |
288 | static const char *always_inserted_enums[] = { | |
289 | always_inserted_auto, | |
290 | always_inserted_off, | |
291 | always_inserted_on, | |
292 | NULL | |
293 | }; | |
294 | static const char *always_inserted_mode = always_inserted_auto; | |
295 | static void | |
74960c60 | 296 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
33e5cbd6 | 297 | struct cmd_list_element *c, const char *value) |
74960c60 | 298 | { |
33e5cbd6 PA |
299 | if (always_inserted_mode == always_inserted_auto) |
300 | fprintf_filtered (file, _("\ | |
301 | Always inserted breakpoint mode is %s (currently %s).\n"), | |
302 | value, | |
303 | breakpoints_always_inserted_mode () ? "on" : "off"); | |
304 | else | |
305 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), value); | |
74960c60 VP |
306 | } |
307 | ||
33e5cbd6 PA |
308 | int |
309 | breakpoints_always_inserted_mode (void) | |
310 | { | |
311 | return (always_inserted_mode == always_inserted_on | |
312 | || (always_inserted_mode == always_inserted_auto && non_stop)); | |
313 | } | |
765dc015 | 314 | |
a14ed312 | 315 | void _initialize_breakpoint (void); |
c906108c | 316 | |
c906108c SS |
317 | /* Are we executing breakpoint commands? */ |
318 | static int executing_breakpoint_commands; | |
319 | ||
c02f5703 MS |
320 | /* Are overlay event breakpoints enabled? */ |
321 | static int overlay_events_enabled; | |
322 | ||
8bea4e01 UW |
323 | /* Are we executing startup code? */ |
324 | static int executing_startup; | |
325 | ||
c906108c SS |
326 | /* Walk the following statement or block through all breakpoints. |
327 | ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current | |
328 | breakpoint. */ | |
329 | ||
5c44784c | 330 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
c906108c | 331 | |
5c44784c JM |
332 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
333 | for (B = breakpoint_chain; \ | |
334 | B ? (TMP=B->next, 1): 0; \ | |
335 | B = TMP) | |
c906108c | 336 | |
7cc221ef DJ |
337 | /* Similar iterators for the low-level breakpoints. */ |
338 | ||
0d381245 | 339 | #define ALL_BP_LOCATIONS(B) for (B = bp_location_chain; B; B = B->global_next) |
7cc221ef DJ |
340 | |
341 | #define ALL_BP_LOCATIONS_SAFE(B,TMP) \ | |
342 | for (B = bp_location_chain; \ | |
0d381245 | 343 | B ? (TMP=B->global_next, 1): 0; \ |
7cc221ef DJ |
344 | B = TMP) |
345 | ||
1042e4c0 SS |
346 | /* Iterator for tracepoints only. */ |
347 | ||
348 | #define ALL_TRACEPOINTS(B) \ | |
349 | for (B = breakpoint_chain; B; B = B->next) \ | |
350 | if ((B)->type == bp_tracepoint) | |
351 | ||
7cc221ef | 352 | /* Chains of all breakpoints defined. */ |
c906108c SS |
353 | |
354 | struct breakpoint *breakpoint_chain; | |
355 | ||
7cc221ef DJ |
356 | struct bp_location *bp_location_chain; |
357 | ||
20874c92 VP |
358 | /* The locations that no longer correspond to any breakpoint, |
359 | unlinked from bp_location_chain, but for which a hit | |
360 | may still be reported by a target. */ | |
361 | VEC(bp_location_p) *moribund_locations = NULL; | |
362 | ||
c906108c SS |
363 | /* Number of last breakpoint made. */ |
364 | ||
365 | int breakpoint_count; | |
366 | ||
1042e4c0 SS |
367 | /* Number of last tracepoint made. */ |
368 | ||
369 | int tracepoint_count; | |
370 | ||
468d015d JJ |
371 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
372 | static int | |
373 | breakpoint_enabled (struct breakpoint *b) | |
374 | { | |
0d381245 | 375 | return (b->enable_state == bp_enabled); |
468d015d JJ |
376 | } |
377 | ||
c906108c SS |
378 | /* Set breakpoint count to NUM. */ |
379 | ||
380 | void | |
fba45db2 | 381 | set_breakpoint_count (int num) |
c906108c SS |
382 | { |
383 | breakpoint_count = num; | |
4fa62494 | 384 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
c906108c SS |
385 | } |
386 | ||
387 | /* Used in run_command to zero the hit count when a new run starts. */ | |
388 | ||
389 | void | |
fba45db2 | 390 | clear_breakpoint_hit_counts (void) |
c906108c SS |
391 | { |
392 | struct breakpoint *b; | |
393 | ||
394 | ALL_BREAKPOINTS (b) | |
395 | b->hit_count = 0; | |
396 | } | |
397 | ||
398 | /* Default address, symtab and line to put a breakpoint at | |
399 | for "break" command with no arg. | |
400 | if default_breakpoint_valid is zero, the other three are | |
401 | not valid, and "break" with no arg is an error. | |
402 | ||
403 | This set by print_stack_frame, which calls set_default_breakpoint. */ | |
404 | ||
405 | int default_breakpoint_valid; | |
406 | CORE_ADDR default_breakpoint_address; | |
407 | struct symtab *default_breakpoint_symtab; | |
408 | int default_breakpoint_line; | |
409 | \f | |
410 | /* *PP is a string denoting a breakpoint. Get the number of the breakpoint. | |
411 | Advance *PP after the string and any trailing whitespace. | |
412 | ||
413 | Currently the string can either be a number or "$" followed by the name | |
414 | of a convenience variable. Making it an expression wouldn't work well | |
5c44784c | 415 | for map_breakpoint_numbers (e.g. "4 + 5 + 6"). |
40c03ae8 EZ |
416 | |
417 | If the string is a NULL pointer, that denotes the last breakpoint. | |
5c44784c JM |
418 | |
419 | TRAILER is a character which can be found after the number; most | |
420 | commonly this is `-'. If you don't want a trailer, use \0. */ | |
c906108c | 421 | static int |
fba45db2 | 422 | get_number_trailer (char **pp, int trailer) |
c906108c | 423 | { |
5c44784c | 424 | int retval = 0; /* default */ |
c906108c SS |
425 | char *p = *pp; |
426 | ||
427 | if (p == NULL) | |
428 | /* Empty line means refer to the last breakpoint. */ | |
429 | return breakpoint_count; | |
430 | else if (*p == '$') | |
431 | { | |
432 | /* Make a copy of the name, so we can null-terminate it | |
c5aa993b | 433 | to pass to lookup_internalvar(). */ |
c906108c SS |
434 | char *varname; |
435 | char *start = ++p; | |
4fa62494 | 436 | LONGEST val; |
c906108c SS |
437 | |
438 | while (isalnum (*p) || *p == '_') | |
439 | p++; | |
440 | varname = (char *) alloca (p - start + 1); | |
441 | strncpy (varname, start, p - start); | |
442 | varname[p - start] = '\0'; | |
4fa62494 UW |
443 | if (get_internalvar_integer (lookup_internalvar (varname), &val)) |
444 | retval = (int) val; | |
5c44784c JM |
445 | else |
446 | { | |
a3f17187 | 447 | printf_filtered (_("Convenience variable must have integer value.\n")); |
5c44784c JM |
448 | retval = 0; |
449 | } | |
c906108c SS |
450 | } |
451 | else | |
452 | { | |
453 | if (*p == '-') | |
454 | ++p; | |
455 | while (*p >= '0' && *p <= '9') | |
456 | ++p; | |
457 | if (p == *pp) | |
458 | /* There is no number here. (e.g. "cond a == b"). */ | |
5c44784c JM |
459 | { |
460 | /* Skip non-numeric token */ | |
461 | while (*p && !isspace((int) *p)) | |
462 | ++p; | |
463 | /* Return zero, which caller must interpret as error. */ | |
464 | retval = 0; | |
465 | } | |
466 | else | |
467 | retval = atoi (*pp); | |
468 | } | |
469 | if (!(isspace (*p) || *p == '\0' || *p == trailer)) | |
470 | { | |
471 | /* Trailing junk: return 0 and let caller print error msg. */ | |
472 | while (!(isspace (*p) || *p == '\0' || *p == trailer)) | |
473 | ++p; | |
474 | retval = 0; | |
c906108c | 475 | } |
c906108c SS |
476 | while (isspace (*p)) |
477 | p++; | |
478 | *pp = p; | |
479 | return retval; | |
480 | } | |
5c44784c | 481 | |
11cf8741 | 482 | |
5c44784c JM |
483 | /* Like get_number_trailer, but don't allow a trailer. */ |
484 | int | |
fba45db2 | 485 | get_number (char **pp) |
5c44784c JM |
486 | { |
487 | return get_number_trailer (pp, '\0'); | |
488 | } | |
489 | ||
490 | /* Parse a number or a range. | |
491 | * A number will be of the form handled by get_number. | |
492 | * A range will be of the form <number1> - <number2>, and | |
493 | * will represent all the integers between number1 and number2, | |
494 | * inclusive. | |
495 | * | |
496 | * While processing a range, this fuction is called iteratively; | |
497 | * At each call it will return the next value in the range. | |
498 | * | |
499 | * At the beginning of parsing a range, the char pointer PP will | |
500 | * be advanced past <number1> and left pointing at the '-' token. | |
501 | * Subsequent calls will not advance the pointer until the range | |
502 | * is completed. The call that completes the range will advance | |
503 | * pointer PP past <number2>. | |
504 | */ | |
505 | ||
506 | int | |
fba45db2 | 507 | get_number_or_range (char **pp) |
5c44784c JM |
508 | { |
509 | static int last_retval, end_value; | |
510 | static char *end_ptr; | |
511 | static int in_range = 0; | |
512 | ||
513 | if (**pp != '-') | |
514 | { | |
515 | /* Default case: pp is pointing either to a solo number, | |
516 | or to the first number of a range. */ | |
517 | last_retval = get_number_trailer (pp, '-'); | |
518 | if (**pp == '-') | |
519 | { | |
520 | char **temp; | |
521 | ||
522 | /* This is the start of a range (<number1> - <number2>). | |
523 | Skip the '-', parse and remember the second number, | |
524 | and also remember the end of the final token. */ | |
525 | ||
526 | temp = &end_ptr; | |
527 | end_ptr = *pp + 1; | |
528 | while (isspace ((int) *end_ptr)) | |
529 | end_ptr++; /* skip white space */ | |
530 | end_value = get_number (temp); | |
531 | if (end_value < last_retval) | |
532 | { | |
8a3fe4f8 | 533 | error (_("inverted range")); |
5c44784c JM |
534 | } |
535 | else if (end_value == last_retval) | |
536 | { | |
537 | /* degenerate range (number1 == number2). Advance the | |
538 | token pointer so that the range will be treated as a | |
539 | single number. */ | |
540 | *pp = end_ptr; | |
541 | } | |
542 | else | |
543 | in_range = 1; | |
544 | } | |
545 | } | |
546 | else if (! in_range) | |
8a3fe4f8 | 547 | error (_("negative value")); |
5c44784c JM |
548 | else |
549 | { | |
550 | /* pp points to the '-' that betokens a range. All | |
551 | number-parsing has already been done. Return the next | |
552 | integer value (one greater than the saved previous value). | |
553 | Do not advance the token pointer 'pp' until the end of range | |
554 | is reached. */ | |
555 | ||
556 | if (++last_retval == end_value) | |
557 | { | |
558 | /* End of range reached; advance token pointer. */ | |
559 | *pp = end_ptr; | |
560 | in_range = 0; | |
561 | } | |
562 | } | |
563 | return last_retval; | |
564 | } | |
565 | ||
48cb2d85 VP |
566 | /* Return the breakpoint with the specified number, or NULL |
567 | if the number does not refer to an existing breakpoint. */ | |
568 | ||
569 | struct breakpoint * | |
570 | get_breakpoint (int num) | |
571 | { | |
572 | struct breakpoint *b; | |
573 | ||
574 | ALL_BREAKPOINTS (b) | |
575 | if (b->number == num) | |
576 | return b; | |
577 | ||
578 | return NULL; | |
579 | } | |
5c44784c | 580 | |
c906108c SS |
581 | \f |
582 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ | |
583 | ||
584 | static void | |
fba45db2 | 585 | condition_command (char *arg, int from_tty) |
c906108c | 586 | { |
52f0bd74 | 587 | struct breakpoint *b; |
c906108c | 588 | char *p; |
52f0bd74 | 589 | int bnum; |
c906108c SS |
590 | |
591 | if (arg == 0) | |
e2e0b3e5 | 592 | error_no_arg (_("breakpoint number")); |
c906108c SS |
593 | |
594 | p = arg; | |
595 | bnum = get_number (&p); | |
5c44784c | 596 | if (bnum == 0) |
8a3fe4f8 | 597 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
598 | |
599 | ALL_BREAKPOINTS (b) | |
600 | if (b->number == bnum) | |
2f069f6f JB |
601 | { |
602 | struct bp_location *loc = b->loc; | |
603 | for (; loc; loc = loc->next) | |
604 | { | |
605 | if (loc->cond) | |
606 | { | |
607 | xfree (loc->cond); | |
608 | loc->cond = 0; | |
609 | } | |
610 | } | |
611 | if (b->cond_string != NULL) | |
612 | xfree (b->cond_string); | |
c906108c | 613 | |
2f069f6f JB |
614 | if (*p == 0) |
615 | { | |
616 | b->cond_string = NULL; | |
617 | if (from_tty) | |
618 | printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum); | |
619 | } | |
620 | else | |
621 | { | |
622 | arg = p; | |
623 | /* I don't know if it matters whether this is the string the user | |
624 | typed in or the decompiled expression. */ | |
1b36a34b | 625 | b->cond_string = xstrdup (arg); |
2f069f6f JB |
626 | b->condition_not_parsed = 0; |
627 | for (loc = b->loc; loc; loc = loc->next) | |
628 | { | |
629 | arg = p; | |
630 | loc->cond = | |
631 | parse_exp_1 (&arg, block_for_pc (loc->address), 0); | |
632 | if (*arg) | |
633 | error (_("Junk at end of expression")); | |
634 | } | |
635 | } | |
636 | breakpoints_changed (); | |
383f836e | 637 | observer_notify_breakpoint_modified (b->number); |
2f069f6f JB |
638 | return; |
639 | } | |
c906108c | 640 | |
8a3fe4f8 | 641 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
642 | } |
643 | ||
48cb2d85 VP |
644 | /* Set the command list of B to COMMANDS. */ |
645 | ||
646 | void | |
647 | breakpoint_set_commands (struct breakpoint *b, struct command_line *commands) | |
648 | { | |
649 | free_command_lines (&b->commands); | |
650 | b->commands = commands; | |
651 | breakpoints_changed (); | |
652 | observer_notify_breakpoint_modified (b->number); | |
653 | } | |
654 | ||
c906108c | 655 | static void |
fba45db2 | 656 | commands_command (char *arg, int from_tty) |
c906108c | 657 | { |
52f0bd74 | 658 | struct breakpoint *b; |
c906108c | 659 | char *p; |
52f0bd74 | 660 | int bnum; |
c906108c SS |
661 | struct command_line *l; |
662 | ||
663 | /* If we allowed this, we would have problems with when to | |
664 | free the storage, if we change the commands currently | |
665 | being read from. */ | |
666 | ||
667 | if (executing_breakpoint_commands) | |
8a3fe4f8 | 668 | error (_("Can't use the \"commands\" command among a breakpoint's commands.")); |
c906108c SS |
669 | |
670 | p = arg; | |
671 | bnum = get_number (&p); | |
5c44784c | 672 | |
c906108c | 673 | if (p && *p) |
8a3fe4f8 | 674 | error (_("Unexpected extra arguments following breakpoint number.")); |
c5aa993b | 675 | |
c906108c SS |
676 | ALL_BREAKPOINTS (b) |
677 | if (b->number == bnum) | |
9ebf4acf AC |
678 | { |
679 | char *tmpbuf = xstrprintf ("Type commands for when breakpoint %d is hit, one per line.", | |
680 | bnum); | |
681 | struct cleanup *cleanups = make_cleanup (xfree, tmpbuf); | |
311a4e6b | 682 | l = read_command_lines (tmpbuf, from_tty, 1); |
9ebf4acf | 683 | do_cleanups (cleanups); |
48cb2d85 | 684 | breakpoint_set_commands (b, l); |
9ebf4acf | 685 | return; |
c5aa993b | 686 | } |
8a3fe4f8 | 687 | error (_("No breakpoint number %d."), bnum); |
c906108c | 688 | } |
40c03ae8 EZ |
689 | |
690 | /* Like commands_command, but instead of reading the commands from | |
691 | input stream, takes them from an already parsed command structure. | |
692 | ||
693 | This is used by cli-script.c to DTRT with breakpoint commands | |
694 | that are part of if and while bodies. */ | |
695 | enum command_control_type | |
696 | commands_from_control_command (char *arg, struct command_line *cmd) | |
697 | { | |
698 | struct breakpoint *b; | |
699 | char *p; | |
700 | int bnum; | |
701 | ||
702 | /* If we allowed this, we would have problems with when to | |
703 | free the storage, if we change the commands currently | |
704 | being read from. */ | |
705 | ||
706 | if (executing_breakpoint_commands) | |
707 | error (_("Can't use the \"commands\" command among a breakpoint's commands.")); | |
708 | ||
709 | /* An empty string for the breakpoint number means the last | |
710 | breakpoint, but get_number expects a NULL pointer. */ | |
711 | if (arg && !*arg) | |
712 | p = NULL; | |
713 | else | |
714 | p = arg; | |
715 | bnum = get_number (&p); | |
716 | ||
717 | if (p && *p) | |
718 | error (_("Unexpected extra arguments following breakpoint number.")); | |
719 | ||
720 | ALL_BREAKPOINTS (b) | |
721 | if (b->number == bnum) | |
722 | { | |
723 | free_command_lines (&b->commands); | |
724 | if (cmd->body_count != 1) | |
725 | error (_("Invalid \"commands\" block structure.")); | |
726 | /* We need to copy the commands because if/while will free the | |
727 | list after it finishes execution. */ | |
728 | b->commands = copy_command_lines (cmd->body_list[0]); | |
729 | breakpoints_changed (); | |
383f836e | 730 | observer_notify_breakpoint_modified (b->number); |
40c03ae8 | 731 | return simple_control; |
2f069f6f | 732 | } |
40c03ae8 EZ |
733 | error (_("No breakpoint number %d."), bnum); |
734 | } | |
c906108c | 735 | \f |
8defab1a DJ |
736 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
737 | by replacing any memory breakpoints with their shadowed contents. */ | |
c906108c | 738 | |
8defab1a DJ |
739 | void |
740 | breakpoint_restore_shadows (gdb_byte *buf, ULONGEST memaddr, LONGEST len) | |
c906108c | 741 | { |
8defab1a | 742 | struct bp_location *b; |
c906108c SS |
743 | CORE_ADDR bp_addr = 0; |
744 | int bp_size = 0; | |
8defab1a | 745 | int bptoffset = 0; |
c5aa993b | 746 | |
ffce0d52 | 747 | ALL_BP_LOCATIONS (b) |
c5aa993b | 748 | { |
ffce0d52 | 749 | if (b->owner->type == bp_none) |
8a3fe4f8 | 750 | warning (_("reading through apparently deleted breakpoint #%d?"), |
ffce0d52 DJ |
751 | b->owner->number); |
752 | ||
753 | if (b->loc_type != bp_loc_software_breakpoint) | |
c5aa993b | 754 | continue; |
ffce0d52 | 755 | if (!b->inserted) |
c5aa993b JM |
756 | continue; |
757 | /* Addresses and length of the part of the breakpoint that | |
758 | we need to copy. */ | |
8181d85f DJ |
759 | bp_addr = b->target_info.placed_address; |
760 | bp_size = b->target_info.shadow_len; | |
c5aa993b | 761 | if (bp_size == 0) |
8181d85f | 762 | /* bp isn't valid, or doesn't shadow memory. */ |
c5aa993b | 763 | continue; |
8defab1a | 764 | |
c5aa993b JM |
765 | if (bp_addr + bp_size <= memaddr) |
766 | /* The breakpoint is entirely before the chunk of memory we | |
767 | are reading. */ | |
768 | continue; | |
8defab1a | 769 | |
c5aa993b JM |
770 | if (bp_addr >= memaddr + len) |
771 | /* The breakpoint is entirely after the chunk of memory we are | |
772 | reading. */ | |
773 | continue; | |
c5aa993b | 774 | |
8defab1a DJ |
775 | /* Offset within shadow_contents. */ |
776 | if (bp_addr < memaddr) | |
777 | { | |
778 | /* Only copy the second part of the breakpoint. */ | |
779 | bp_size -= memaddr - bp_addr; | |
780 | bptoffset = memaddr - bp_addr; | |
781 | bp_addr = memaddr; | |
782 | } | |
c5aa993b | 783 | |
8defab1a DJ |
784 | if (bp_addr + bp_size > memaddr + len) |
785 | { | |
786 | /* Only copy the first part of the breakpoint. */ | |
787 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
788 | } | |
c5aa993b | 789 | |
8defab1a DJ |
790 | memcpy (buf + bp_addr - memaddr, |
791 | b->target_info.shadow_contents + bptoffset, bp_size); | |
c5aa993b | 792 | } |
c906108c | 793 | } |
c906108c | 794 | \f |
c5aa993b | 795 | |
687595f9 | 796 | /* A wrapper function for inserting catchpoints. */ |
9cbc821d | 797 | static void |
687595f9 DJ |
798 | insert_catchpoint (struct ui_out *uo, void *args) |
799 | { | |
800 | struct breakpoint *b = (struct breakpoint *) args; | |
801 | int val = -1; | |
802 | ||
fe798b75 JB |
803 | gdb_assert (b->type == bp_catchpoint); |
804 | gdb_assert (b->ops != NULL && b->ops->insert != NULL); | |
805 | ||
806 | b->ops->insert (b); | |
687595f9 DJ |
807 | } |
808 | ||
a5606eee VP |
809 | static int |
810 | is_hardware_watchpoint (struct breakpoint *bpt) | |
811 | { | |
812 | return (bpt->type == bp_hardware_watchpoint | |
813 | || bpt->type == bp_read_watchpoint | |
814 | || bpt->type == bp_access_watchpoint); | |
815 | } | |
7270d8f2 | 816 | |
fa4727a6 DJ |
817 | /* Find the current value of a watchpoint on EXP. Return the value in |
818 | *VALP and *RESULTP and the chain of intermediate and final values | |
819 | in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does | |
820 | not need them. | |
821 | ||
ccc57cf9 | 822 | If a memory error occurs while evaluating the expression, *RESULTP will |
fa4727a6 DJ |
823 | be set to NULL. *RESULTP may be a lazy value, if the result could |
824 | not be read from memory. It is used to determine whether a value | |
825 | is user-specified (we should watch the whole value) or intermediate | |
826 | (we should watch only the bit used to locate the final value). | |
827 | ||
828 | If the final value, or any intermediate value, could not be read | |
829 | from memory, *VALP will be set to NULL. *VAL_CHAIN will still be | |
830 | set to any referenced values. *VALP will never be a lazy value. | |
831 | This is the value which we store in struct breakpoint. | |
832 | ||
833 | If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the | |
834 | value chain. The caller must free the values individually. If | |
835 | VAL_CHAIN is NULL, all generated values will be left on the value | |
836 | chain. */ | |
837 | ||
838 | static void | |
839 | fetch_watchpoint_value (struct expression *exp, struct value **valp, | |
840 | struct value **resultp, struct value **val_chain) | |
841 | { | |
842 | struct value *mark, *new_mark, *result; | |
ccc57cf9 | 843 | volatile struct gdb_exception ex; |
fa4727a6 DJ |
844 | |
845 | *valp = NULL; | |
846 | if (resultp) | |
847 | *resultp = NULL; | |
848 | if (val_chain) | |
849 | *val_chain = NULL; | |
850 | ||
851 | /* Evaluate the expression. */ | |
852 | mark = value_mark (); | |
853 | result = NULL; | |
ccc57cf9 PA |
854 | |
855 | TRY_CATCH (ex, RETURN_MASK_ALL) | |
856 | { | |
857 | result = evaluate_expression (exp); | |
858 | } | |
859 | if (ex.reason < 0) | |
860 | { | |
861 | /* Ignore memory errors, we want watchpoints pointing at | |
862 | inaccessible memory to still be created; otherwise, throw the | |
863 | error to some higher catcher. */ | |
864 | switch (ex.error) | |
865 | { | |
866 | case MEMORY_ERROR: | |
867 | break; | |
868 | default: | |
869 | throw_exception (ex); | |
870 | break; | |
871 | } | |
872 | } | |
873 | ||
fa4727a6 DJ |
874 | new_mark = value_mark (); |
875 | if (mark == new_mark) | |
876 | return; | |
877 | if (resultp) | |
878 | *resultp = result; | |
879 | ||
880 | /* Make sure it's not lazy, so that after the target stops again we | |
881 | have a non-lazy previous value to compare with. */ | |
882 | if (result != NULL | |
883 | && (!value_lazy (result) || gdb_value_fetch_lazy (result))) | |
884 | *valp = result; | |
885 | ||
886 | if (val_chain) | |
887 | { | |
888 | /* Return the chain of intermediate values. We use this to | |
889 | decide which addresses to watch. */ | |
890 | *val_chain = new_mark; | |
891 | value_release_to_mark (mark); | |
892 | } | |
893 | } | |
894 | ||
567e1b4e JB |
895 | /* Assuming that B is a watchpoint: |
896 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 897 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
898 | - Evaluate the condition if there is one, and store the result |
899 | in b->loc->cond. | |
a5606eee VP |
900 | - Update the list of values that must be watched in B->loc. |
901 | ||
bfa149ac JB |
902 | If the watchpoint disposition is disp_del_at_next_stop, then do nothing. |
903 | If this is local watchpoint that is out of scope, delete it. */ | |
b40ce68a | 904 | static void |
a5606eee | 905 | update_watchpoint (struct breakpoint *b, int reparse) |
7270d8f2 | 906 | { |
a5606eee | 907 | int within_current_scope; |
a5606eee VP |
908 | struct frame_id saved_frame_id; |
909 | struct bp_location *loc; | |
910 | bpstat bs; | |
911 | ||
567e1b4e JB |
912 | /* We don't free locations. They are stored in bp_location_chain and |
913 | update_global_locations will eventually delete them and remove | |
914 | breakpoints if needed. */ | |
a5606eee VP |
915 | b->loc = NULL; |
916 | ||
917 | if (b->disposition == disp_del_at_next_stop) | |
918 | return; | |
919 | ||
920 | /* Save the current frame's ID so we can restore it after | |
921 | evaluating the watchpoint expression on its own frame. */ | |
922 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
923 | took a frame parameter, so that we didn't have to change the | |
924 | selected frame. */ | |
925 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
926 | ||
927 | /* Determine if the watchpoint is within scope. */ | |
928 | if (b->exp_valid_block == NULL) | |
929 | within_current_scope = 1; | |
930 | else | |
931 | { | |
932 | struct frame_info *fi; | |
933 | fi = frame_find_by_id (b->watchpoint_frame); | |
934 | within_current_scope = (fi != NULL); | |
935 | if (within_current_scope) | |
936 | select_frame (fi); | |
937 | } | |
938 | ||
939 | if (within_current_scope && reparse) | |
940 | { | |
941 | char *s; | |
942 | if (b->exp) | |
943 | { | |
944 | xfree (b->exp); | |
945 | b->exp = NULL; | |
946 | } | |
947 | s = b->exp_string; | |
948 | b->exp = parse_exp_1 (&s, b->exp_valid_block, 0); | |
949 | /* If the meaning of expression itself changed, the old value is | |
950 | no longer relevant. We don't want to report a watchpoint hit | |
951 | to the user when the old value and the new value may actually | |
952 | be completely different objects. */ | |
953 | value_free (b->val); | |
fa4727a6 DJ |
954 | b->val = NULL; |
955 | b->val_valid = 0; | |
a5606eee | 956 | } |
a5606eee VP |
957 | |
958 | /* If we failed to parse the expression, for example because | |
959 | it refers to a global variable in a not-yet-loaded shared library, | |
960 | don't try to insert watchpoint. We don't automatically delete | |
961 | such watchpoint, though, since failure to parse expression | |
962 | is different from out-of-scope watchpoint. */ | |
963 | if (within_current_scope && b->exp) | |
964 | { | |
fa4727a6 | 965 | struct value *val_chain, *v, *result, *next; |
a5606eee | 966 | |
fa4727a6 | 967 | fetch_watchpoint_value (b->exp, &v, &result, &val_chain); |
a5606eee | 968 | |
a5606eee VP |
969 | /* Avoid setting b->val if it's already set. The meaning of |
970 | b->val is 'the last value' user saw, and we should update | |
971 | it only if we reported that last value to user. As it | |
972 | happens, the code that reports it updates b->val directly. */ | |
fa4727a6 DJ |
973 | if (!b->val_valid) |
974 | { | |
975 | b->val = v; | |
976 | b->val_valid = 1; | |
977 | } | |
a5606eee | 978 | |
db2ad4c3 JK |
979 | /* Change the type of breakpoint between hardware assisted or an |
980 | ordinary watchpoint depending on the hardware support and free | |
981 | hardware slots. REPARSE is set when the inferior is started. */ | |
982 | if ((b->type == bp_watchpoint || b->type == bp_hardware_watchpoint) | |
983 | && reparse) | |
984 | { | |
ca2d49e8 | 985 | int i, mem_cnt, other_type_used; |
db2ad4c3 JK |
986 | |
987 | i = hw_watchpoint_used_count (bp_hardware_watchpoint, | |
988 | &other_type_used); | |
989 | mem_cnt = can_use_hardware_watchpoint (val_chain); | |
990 | ||
ca2d49e8 | 991 | if (!mem_cnt) |
db2ad4c3 JK |
992 | b->type = bp_watchpoint; |
993 | else | |
ca2d49e8 | 994 | { |
d92524f1 | 995 | int target_resources_ok = target_can_use_hardware_watchpoint |
ca2d49e8 SL |
996 | (bp_hardware_watchpoint, i + mem_cnt, other_type_used); |
997 | if (target_resources_ok <= 0) | |
998 | b->type = bp_watchpoint; | |
999 | else | |
1000 | b->type = bp_hardware_watchpoint; | |
1001 | } | |
db2ad4c3 JK |
1002 | } |
1003 | ||
a5606eee | 1004 | /* Look at each value on the value chain. */ |
fa4727a6 | 1005 | for (v = val_chain; v; v = next) |
a5606eee VP |
1006 | { |
1007 | /* If it's a memory location, and GDB actually needed | |
1008 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1009 | must watch it. If the first value returned is |
1010 | still lazy, that means an error occurred reading it; | |
1011 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1012 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 1013 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
1014 | { |
1015 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1016 | |
a5606eee VP |
1017 | /* We only watch structs and arrays if user asked |
1018 | for it explicitly, never if they just happen to | |
1019 | appear in the middle of some value chain. */ | |
fa4727a6 | 1020 | if (v == result |
a5606eee VP |
1021 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
1022 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
1023 | { | |
1024 | CORE_ADDR addr; | |
1025 | int len, type; | |
1026 | struct bp_location *loc, **tmp; | |
1027 | ||
42ae5230 | 1028 | addr = value_address (v); |
a5606eee VP |
1029 | len = TYPE_LENGTH (value_type (v)); |
1030 | type = hw_write; | |
1031 | if (b->type == bp_read_watchpoint) | |
1032 | type = hw_read; | |
1033 | else if (b->type == bp_access_watchpoint) | |
1034 | type = hw_access; | |
1035 | ||
39d61571 | 1036 | loc = allocate_bp_location (b); |
a5606eee VP |
1037 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
1038 | ; | |
1039 | *tmp = loc; | |
a6d9a66e | 1040 | loc->gdbarch = get_type_arch (value_type (v)); |
a5606eee VP |
1041 | loc->address = addr; |
1042 | loc->length = len; | |
1043 | loc->watchpoint_type = type; | |
1044 | } | |
1045 | } | |
1046 | ||
1047 | next = value_next (v); | |
1048 | if (v != b->val) | |
1049 | value_free (v); | |
1050 | } | |
1051 | ||
2ec93238 MK |
1052 | /* We just regenerated the list of breakpoint locations. |
1053 | The new location does not have its condition field set to anything | |
1054 | and therefore, we must always reparse the cond_string, independently | |
1055 | of the value of the reparse flag. */ | |
1056 | if (b->cond_string != NULL) | |
a5606eee VP |
1057 | { |
1058 | char *s = b->cond_string; | |
a5606eee VP |
1059 | b->loc->cond = parse_exp_1 (&s, b->exp_valid_block, 0); |
1060 | } | |
1061 | } | |
1062 | else if (!within_current_scope) | |
7270d8f2 | 1063 | { |
a5606eee | 1064 | printf_filtered (_("\ |
567e1b4e | 1065 | Watchpoint %d deleted because the program has left the block \n\ |
a5606eee VP |
1066 | in which its expression is valid.\n"), |
1067 | b->number); | |
1068 | if (b->related_breakpoint) | |
1069 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
1070 | b->disposition = disp_del_at_next_stop; | |
7270d8f2 | 1071 | } |
a5606eee VP |
1072 | |
1073 | /* Restore the selected frame. */ | |
1074 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
1075 | } |
1076 | ||
a5606eee | 1077 | |
74960c60 VP |
1078 | /* Returns 1 iff breakpoint location should be |
1079 | inserted in the inferior. */ | |
1080 | static int | |
1081 | should_be_inserted (struct bp_location *bpt) | |
1082 | { | |
1083 | if (!breakpoint_enabled (bpt->owner)) | |
1084 | return 0; | |
1085 | ||
1086 | if (bpt->owner->disposition == disp_del_at_next_stop) | |
1087 | return 0; | |
1088 | ||
1089 | if (!bpt->enabled || bpt->shlib_disabled || bpt->duplicate) | |
1090 | return 0; | |
1091 | ||
1042e4c0 SS |
1092 | /* Tracepoints are inserted by the target at a time of its choosing, |
1093 | not by us. */ | |
1094 | if (bpt->owner->type == bp_tracepoint) | |
1095 | return 0; | |
1096 | ||
74960c60 VP |
1097 | return 1; |
1098 | } | |
1099 | ||
879bfdc2 DJ |
1100 | /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint. |
1101 | Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS, | |
fa3a767f | 1102 | and HW_BREAKPOINT_ERROR are used to report problems. |
879bfdc2 DJ |
1103 | |
1104 | NOTE drow/2003-09-09: This routine could be broken down to an object-style | |
1105 | method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 1106 | static int |
879bfdc2 | 1107 | insert_bp_location (struct bp_location *bpt, |
26bb91f3 | 1108 | struct ui_file *tmp_error_stream, |
fa3a767f | 1109 | int *disabled_breaks, |
26bb91f3 | 1110 | int *hw_breakpoint_error) |
879bfdc2 DJ |
1111 | { |
1112 | int val = 0; | |
1113 | ||
74960c60 | 1114 | if (!should_be_inserted (bpt) || bpt->inserted) |
879bfdc2 DJ |
1115 | return 0; |
1116 | ||
8181d85f DJ |
1117 | /* Initialize the target-specific information. */ |
1118 | memset (&bpt->target_info, 0, sizeof (bpt->target_info)); | |
1119 | bpt->target_info.placed_address = bpt->address; | |
1120 | ||
879bfdc2 DJ |
1121 | if (bpt->loc_type == bp_loc_software_breakpoint |
1122 | || bpt->loc_type == bp_loc_hardware_breakpoint) | |
1123 | { | |
765dc015 VP |
1124 | if (bpt->owner->type != bp_hardware_breakpoint) |
1125 | { | |
1126 | /* If the explicitly specified breakpoint type | |
1127 | is not hardware breakpoint, check the memory map to see | |
1128 | if the breakpoint address is in read only memory or not. | |
1129 | Two important cases are: | |
1130 | - location type is not hardware breakpoint, memory | |
1131 | is readonly. We change the type of the location to | |
1132 | hardware breakpoint. | |
1133 | - location type is hardware breakpoint, memory is read-write. | |
1134 | This means we've previously made the location hardware one, but | |
1135 | then the memory map changed, so we undo. | |
1136 | ||
1137 | When breakpoints are removed, remove_breakpoints will | |
1138 | use location types we've just set here, the only possible | |
1139 | problem is that memory map has changed during running program, | |
1140 | but it's not going to work anyway with current gdb. */ | |
1141 | struct mem_region *mr | |
1142 | = lookup_mem_region (bpt->target_info.placed_address); | |
1143 | ||
1144 | if (mr) | |
1145 | { | |
1146 | if (automatic_hardware_breakpoints) | |
1147 | { | |
1148 | int changed = 0; | |
1149 | enum bp_loc_type new_type; | |
1150 | ||
1151 | if (mr->attrib.mode != MEM_RW) | |
1152 | new_type = bp_loc_hardware_breakpoint; | |
1153 | else | |
1154 | new_type = bp_loc_software_breakpoint; | |
1155 | ||
1156 | if (new_type != bpt->loc_type) | |
1157 | { | |
1158 | static int said = 0; | |
1159 | bpt->loc_type = new_type; | |
1160 | if (!said) | |
1161 | { | |
1162 | fprintf_filtered (gdb_stdout, _("\ | |
0767c96d | 1163 | Note: automatically using hardware breakpoints for read-only addresses.\n")); |
765dc015 VP |
1164 | said = 1; |
1165 | } | |
1166 | } | |
1167 | } | |
1168 | else if (bpt->loc_type == bp_loc_software_breakpoint | |
1169 | && mr->attrib.mode != MEM_RW) | |
1170 | warning (_("cannot set software breakpoint at readonly address %s"), | |
5af949e3 | 1171 | paddress (bpt->gdbarch, bpt->address)); |
765dc015 VP |
1172 | } |
1173 | } | |
1174 | ||
879bfdc2 DJ |
1175 | /* First check to see if we have to handle an overlay. */ |
1176 | if (overlay_debugging == ovly_off | |
1177 | || bpt->section == NULL | |
1178 | || !(section_is_overlay (bpt->section))) | |
1179 | { | |
1180 | /* No overlay handling: just set the breakpoint. */ | |
1181 | ||
1182 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
a6d9a66e UW |
1183 | val = target_insert_hw_breakpoint (bpt->gdbarch, |
1184 | &bpt->target_info); | |
879bfdc2 | 1185 | else |
a6d9a66e UW |
1186 | val = target_insert_breakpoint (bpt->gdbarch, |
1187 | &bpt->target_info); | |
879bfdc2 DJ |
1188 | } |
1189 | else | |
1190 | { | |
1191 | /* This breakpoint is in an overlay section. | |
1192 | Shall we set a breakpoint at the LMA? */ | |
1193 | if (!overlay_events_enabled) | |
1194 | { | |
1195 | /* Yes -- overlay event support is not active, | |
1196 | so we must try to set a breakpoint at the LMA. | |
1197 | This will not work for a hardware breakpoint. */ | |
1198 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
8a3fe4f8 | 1199 | warning (_("hardware breakpoint %d not supported in overlay!"), |
879bfdc2 DJ |
1200 | bpt->owner->number); |
1201 | else | |
1202 | { | |
1203 | CORE_ADDR addr = overlay_unmapped_address (bpt->address, | |
1204 | bpt->section); | |
1205 | /* Set a software (trap) breakpoint at the LMA. */ | |
8181d85f DJ |
1206 | bpt->overlay_target_info = bpt->target_info; |
1207 | bpt->overlay_target_info.placed_address = addr; | |
a6d9a66e UW |
1208 | val = target_insert_breakpoint (bpt->gdbarch, |
1209 | &bpt->overlay_target_info); | |
879bfdc2 | 1210 | if (val != 0) |
99361f52 DE |
1211 | fprintf_unfiltered (tmp_error_stream, |
1212 | "Overlay breakpoint %d failed: in ROM?\n", | |
879bfdc2 DJ |
1213 | bpt->owner->number); |
1214 | } | |
1215 | } | |
1216 | /* Shall we set a breakpoint at the VMA? */ | |
1217 | if (section_is_mapped (bpt->section)) | |
1218 | { | |
1219 | /* Yes. This overlay section is mapped into memory. */ | |
1220 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
a6d9a66e UW |
1221 | val = target_insert_hw_breakpoint (bpt->gdbarch, |
1222 | &bpt->target_info); | |
879bfdc2 | 1223 | else |
a6d9a66e UW |
1224 | val = target_insert_breakpoint (bpt->gdbarch, |
1225 | &bpt->target_info); | |
879bfdc2 DJ |
1226 | } |
1227 | else | |
1228 | { | |
1229 | /* No. This breakpoint will not be inserted. | |
1230 | No error, but do not mark the bp as 'inserted'. */ | |
1231 | return 0; | |
1232 | } | |
1233 | } | |
1234 | ||
1235 | if (val) | |
1236 | { | |
1237 | /* Can't set the breakpoint. */ | |
f5c9a895 | 1238 | if (solib_name_from_address (bpt->address)) |
879bfdc2 DJ |
1239 | { |
1240 | /* See also: disable_breakpoints_in_shlibs. */ | |
1241 | val = 0; | |
0d381245 | 1242 | bpt->shlib_disabled = 1; |
879bfdc2 DJ |
1243 | if (!*disabled_breaks) |
1244 | { | |
1245 | fprintf_unfiltered (tmp_error_stream, | |
1246 | "Cannot insert breakpoint %d.\n", | |
1247 | bpt->owner->number); | |
1248 | fprintf_unfiltered (tmp_error_stream, | |
1249 | "Temporarily disabling shared library breakpoints:\n"); | |
1250 | } | |
1251 | *disabled_breaks = 1; | |
1252 | fprintf_unfiltered (tmp_error_stream, | |
1253 | "breakpoint #%d\n", bpt->owner->number); | |
1254 | } | |
1255 | else | |
879bfdc2 | 1256 | { |
879bfdc2 DJ |
1257 | if (bpt->loc_type == bp_loc_hardware_breakpoint) |
1258 | { | |
1259 | *hw_breakpoint_error = 1; | |
1260 | fprintf_unfiltered (tmp_error_stream, | |
1261 | "Cannot insert hardware breakpoint %d.\n", | |
1262 | bpt->owner->number); | |
1263 | } | |
1264 | else | |
1265 | { | |
1266 | fprintf_unfiltered (tmp_error_stream, | |
1267 | "Cannot insert breakpoint %d.\n", | |
1268 | bpt->owner->number); | |
1269 | fprintf_filtered (tmp_error_stream, | |
1270 | "Error accessing memory address "); | |
5af949e3 UW |
1271 | fputs_filtered (paddress (bpt->gdbarch, bpt->address), |
1272 | tmp_error_stream); | |
879bfdc2 DJ |
1273 | fprintf_filtered (tmp_error_stream, ": %s.\n", |
1274 | safe_strerror (val)); | |
1275 | } | |
1276 | ||
1277 | } | |
1278 | } | |
1279 | else | |
1280 | bpt->inserted = 1; | |
1281 | ||
1282 | return val; | |
1283 | } | |
1284 | ||
1285 | else if (bpt->loc_type == bp_loc_hardware_watchpoint | |
1286 | /* NOTE drow/2003-09-08: This state only exists for removing | |
1287 | watchpoints. It's not clear that it's necessary... */ | |
1288 | && bpt->owner->disposition != disp_del_at_next_stop) | |
1289 | { | |
a5606eee VP |
1290 | val = target_insert_watchpoint (bpt->address, |
1291 | bpt->length, | |
1292 | bpt->watchpoint_type); | |
1293 | bpt->inserted = (val != -1); | |
879bfdc2 DJ |
1294 | } |
1295 | ||
fe798b75 | 1296 | else if (bpt->owner->type == bp_catchpoint) |
879bfdc2 | 1297 | { |
71fff37b AC |
1298 | struct gdb_exception e = catch_exception (uiout, insert_catchpoint, |
1299 | bpt->owner, RETURN_MASK_ERROR); | |
9cbc821d AC |
1300 | exception_fprintf (gdb_stderr, e, "warning: inserting catchpoint %d: ", |
1301 | bpt->owner->number); | |
1302 | if (e.reason < 0) | |
879bfdc2 DJ |
1303 | bpt->owner->enable_state = bp_disabled; |
1304 | else | |
1305 | bpt->inserted = 1; | |
1640b821 DJ |
1306 | |
1307 | /* We've already printed an error message if there was a problem | |
1308 | inserting this catchpoint, and we've disabled the catchpoint, | |
1309 | so just return success. */ | |
1310 | return 0; | |
879bfdc2 DJ |
1311 | } |
1312 | ||
1313 | return 0; | |
1314 | } | |
1315 | ||
74960c60 VP |
1316 | /* Make sure all breakpoints are inserted in inferior. |
1317 | Throws exception on any error. | |
1318 | A breakpoint that is already inserted won't be inserted | |
1319 | again, so calling this function twice is safe. */ | |
1320 | void | |
1321 | insert_breakpoints (void) | |
1322 | { | |
1323 | struct breakpoint *bpt; | |
1324 | ||
1325 | ALL_BREAKPOINTS (bpt) | |
1326 | if (is_hardware_watchpoint (bpt)) | |
1327 | update_watchpoint (bpt, 0 /* don't reparse. */); | |
1328 | ||
b60e7edf | 1329 | update_global_location_list (1); |
74960c60 | 1330 | |
c35b1492 PA |
1331 | /* update_global_location_list does not insert breakpoints when |
1332 | always_inserted_mode is not enabled. Explicitly insert them | |
1333 | now. */ | |
1334 | if (!breakpoints_always_inserted_mode ()) | |
74960c60 VP |
1335 | insert_breakpoint_locations (); |
1336 | } | |
1337 | ||
c906108c SS |
1338 | /* insert_breakpoints is used when starting or continuing the program. |
1339 | remove_breakpoints is used when the program stops. | |
1340 | Both return zero if successful, | |
1341 | or an `errno' value if could not write the inferior. */ | |
1342 | ||
74960c60 VP |
1343 | static void |
1344 | insert_breakpoint_locations (void) | |
c906108c | 1345 | { |
a5606eee | 1346 | struct breakpoint *bpt; |
879bfdc2 | 1347 | struct bp_location *b, *temp; |
e236ba44 | 1348 | int error = 0; |
c906108c SS |
1349 | int val = 0; |
1350 | int disabled_breaks = 0; | |
81d0cc19 | 1351 | int hw_breakpoint_error = 0; |
c906108c | 1352 | |
81d0cc19 | 1353 | struct ui_file *tmp_error_stream = mem_fileopen (); |
f7545552 | 1354 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
74960c60 | 1355 | |
81d0cc19 GS |
1356 | /* Explicitly mark the warning -- this will only be printed if |
1357 | there was an error. */ | |
1358 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
a5606eee | 1359 | |
879bfdc2 DJ |
1360 | ALL_BP_LOCATIONS_SAFE (b, temp) |
1361 | { | |
74960c60 | 1362 | if (!should_be_inserted (b) || b->inserted) |
879bfdc2 DJ |
1363 | continue; |
1364 | ||
f365de73 AS |
1365 | /* There is no point inserting thread-specific breakpoints if the |
1366 | thread no longer exists. */ | |
1367 | if (b->owner->thread != -1 | |
1368 | && !valid_thread_id (b->owner->thread)) | |
1369 | continue; | |
1370 | ||
879bfdc2 | 1371 | val = insert_bp_location (b, tmp_error_stream, |
fa3a767f | 1372 | &disabled_breaks, |
879bfdc2 DJ |
1373 | &hw_breakpoint_error); |
1374 | if (val) | |
e236ba44 | 1375 | error = val; |
879bfdc2 | 1376 | } |
c906108c | 1377 | |
a5606eee VP |
1378 | /* If we failed to insert all locations of a watchpoint, |
1379 | remove them, as half-inserted watchpoint is of limited use. */ | |
1380 | ALL_BREAKPOINTS (bpt) | |
1381 | { | |
1382 | int some_failed = 0; | |
1383 | struct bp_location *loc; | |
1384 | ||
1385 | if (!is_hardware_watchpoint (bpt)) | |
1386 | continue; | |
1387 | ||
d6b74ac4 | 1388 | if (!breakpoint_enabled (bpt)) |
a5606eee | 1389 | continue; |
74960c60 VP |
1390 | |
1391 | if (bpt->disposition == disp_del_at_next_stop) | |
1392 | continue; | |
a5606eee VP |
1393 | |
1394 | for (loc = bpt->loc; loc; loc = loc->next) | |
1395 | if (!loc->inserted) | |
1396 | { | |
1397 | some_failed = 1; | |
1398 | break; | |
1399 | } | |
1400 | if (some_failed) | |
1401 | { | |
1402 | for (loc = bpt->loc; loc; loc = loc->next) | |
1403 | if (loc->inserted) | |
1404 | remove_breakpoint (loc, mark_uninserted); | |
1405 | ||
1406 | hw_breakpoint_error = 1; | |
1407 | fprintf_unfiltered (tmp_error_stream, | |
1408 | "Could not insert hardware watchpoint %d.\n", | |
1409 | bpt->number); | |
1410 | error = -1; | |
1411 | } | |
1412 | } | |
1413 | ||
e236ba44 | 1414 | if (error) |
81d0cc19 GS |
1415 | { |
1416 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
1417 | message about possibly exhausted resources. */ | |
879bfdc2 | 1418 | if (hw_breakpoint_error) |
81d0cc19 | 1419 | { |
c6510018 MS |
1420 | fprintf_unfiltered (tmp_error_stream, |
1421 | "Could not insert hardware breakpoints:\n\ | |
1422 | You may have requested too many hardware breakpoints/watchpoints.\n"); | |
81d0cc19 | 1423 | } |
81d0cc19 GS |
1424 | target_terminal_ours_for_output (); |
1425 | error_stream (tmp_error_stream); | |
1426 | } | |
f7545552 TT |
1427 | |
1428 | do_cleanups (cleanups); | |
c906108c SS |
1429 | } |
1430 | ||
c906108c | 1431 | int |
fba45db2 | 1432 | remove_breakpoints (void) |
c906108c | 1433 | { |
0bde7532 | 1434 | struct bp_location *b; |
3a1bae8e | 1435 | int val = 0; |
c906108c | 1436 | |
0bde7532 | 1437 | ALL_BP_LOCATIONS (b) |
c5aa993b | 1438 | { |
0bde7532 | 1439 | if (b->inserted) |
3a1bae8e | 1440 | val |= remove_breakpoint (b, mark_uninserted); |
c5aa993b | 1441 | } |
3a1bae8e | 1442 | return val; |
c906108c SS |
1443 | } |
1444 | ||
692590c1 | 1445 | int |
80ce1ecb | 1446 | remove_hw_watchpoints (void) |
692590c1 | 1447 | { |
0bde7532 | 1448 | struct bp_location *b; |
3a1bae8e | 1449 | int val = 0; |
692590c1 | 1450 | |
0bde7532 | 1451 | ALL_BP_LOCATIONS (b) |
692590c1 | 1452 | { |
0bde7532 | 1453 | if (b->inserted && b->loc_type == bp_loc_hardware_watchpoint) |
3a1bae8e | 1454 | val |= remove_breakpoint (b, mark_uninserted); |
692590c1 | 1455 | } |
3a1bae8e | 1456 | return val; |
692590c1 MS |
1457 | } |
1458 | ||
c906108c | 1459 | int |
fba45db2 | 1460 | reattach_breakpoints (int pid) |
c906108c | 1461 | { |
0bde7532 | 1462 | struct bp_location *b; |
c906108c | 1463 | int val; |
ce696e05 | 1464 | struct cleanup *old_chain = save_inferior_ptid (); |
a4954f26 | 1465 | struct ui_file *tmp_error_stream = mem_fileopen (); |
fa3a767f | 1466 | int dummy1 = 0, dummy2 = 0; |
a4954f26 DJ |
1467 | |
1468 | make_cleanup_ui_file_delete (tmp_error_stream); | |
c906108c | 1469 | |
ce696e05 | 1470 | inferior_ptid = pid_to_ptid (pid); |
0bde7532 | 1471 | ALL_BP_LOCATIONS (b) |
c5aa993b | 1472 | { |
0bde7532 | 1473 | if (b->inserted) |
c5aa993b | 1474 | { |
a4954f26 DJ |
1475 | b->inserted = 0; |
1476 | val = insert_bp_location (b, tmp_error_stream, | |
fa3a767f | 1477 | &dummy1, &dummy2); |
c5aa993b JM |
1478 | if (val != 0) |
1479 | { | |
ce696e05 | 1480 | do_cleanups (old_chain); |
c5aa993b JM |
1481 | return val; |
1482 | } | |
1483 | } | |
1484 | } | |
ce696e05 | 1485 | do_cleanups (old_chain); |
c906108c SS |
1486 | return 0; |
1487 | } | |
1488 | ||
e58b0e63 PA |
1489 | static int internal_breakpoint_number = -1; |
1490 | ||
e62c965a | 1491 | static struct breakpoint * |
a6d9a66e UW |
1492 | create_internal_breakpoint (struct gdbarch *gdbarch, |
1493 | CORE_ADDR address, enum bptype type) | |
e62c965a | 1494 | { |
e62c965a PP |
1495 | struct symtab_and_line sal; |
1496 | struct breakpoint *b; | |
1497 | ||
1498 | init_sal (&sal); /* initialize to zeroes */ | |
1499 | ||
1500 | sal.pc = address; | |
1501 | sal.section = find_pc_overlay (sal.pc); | |
1502 | ||
a6d9a66e | 1503 | b = set_raw_breakpoint (gdbarch, sal, type); |
e62c965a PP |
1504 | b->number = internal_breakpoint_number--; |
1505 | b->disposition = disp_donttouch; | |
1506 | ||
1507 | return b; | |
1508 | } | |
1509 | ||
1510 | static void | |
69de3c6a | 1511 | create_overlay_event_breakpoint (char *func_name) |
e62c965a | 1512 | { |
69de3c6a | 1513 | struct objfile *objfile; |
e62c965a | 1514 | |
69de3c6a PP |
1515 | ALL_OBJFILES (objfile) |
1516 | { | |
1517 | struct breakpoint *b; | |
1518 | struct minimal_symbol *m; | |
1519 | ||
1520 | m = lookup_minimal_symbol_text (func_name, objfile); | |
1521 | if (m == NULL) | |
1522 | continue; | |
e62c965a | 1523 | |
a6d9a66e UW |
1524 | b = create_internal_breakpoint (get_objfile_arch (objfile), |
1525 | SYMBOL_VALUE_ADDRESS (m), | |
69de3c6a PP |
1526 | bp_overlay_event); |
1527 | b->addr_string = xstrdup (func_name); | |
e62c965a | 1528 | |
69de3c6a PP |
1529 | if (overlay_debugging == ovly_auto) |
1530 | { | |
1531 | b->enable_state = bp_enabled; | |
1532 | overlay_events_enabled = 1; | |
1533 | } | |
1534 | else | |
1535 | { | |
1536 | b->enable_state = bp_disabled; | |
1537 | overlay_events_enabled = 0; | |
1538 | } | |
e62c965a PP |
1539 | } |
1540 | update_global_location_list (1); | |
1541 | } | |
1542 | ||
0fd8e87f UW |
1543 | static void |
1544 | create_longjmp_master_breakpoint (char *func_name) | |
1545 | { | |
1546 | struct objfile *objfile; | |
1547 | ||
1548 | ALL_OBJFILES (objfile) | |
1549 | { | |
1550 | struct breakpoint *b; | |
1551 | struct minimal_symbol *m; | |
1552 | ||
1553 | if (!gdbarch_get_longjmp_target_p (get_objfile_arch (objfile))) | |
1554 | continue; | |
1555 | ||
1556 | m = lookup_minimal_symbol_text (func_name, objfile); | |
1557 | if (m == NULL) | |
1558 | continue; | |
1559 | ||
a6d9a66e UW |
1560 | b = create_internal_breakpoint (get_objfile_arch (objfile), |
1561 | SYMBOL_VALUE_ADDRESS (m), | |
0fd8e87f UW |
1562 | bp_longjmp_master); |
1563 | b->addr_string = xstrdup (func_name); | |
1564 | b->enable_state = bp_disabled; | |
1565 | } | |
1566 | update_global_location_list (1); | |
1567 | } | |
1568 | ||
c906108c | 1569 | void |
fba45db2 | 1570 | update_breakpoints_after_exec (void) |
c906108c | 1571 | { |
c5aa993b JM |
1572 | struct breakpoint *b; |
1573 | struct breakpoint *temp; | |
25b22b0a | 1574 | struct bp_location *bploc; |
c906108c | 1575 | |
25b22b0a PA |
1576 | /* We're about to delete breakpoints from GDB's lists. If the |
1577 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
1578 | writing the breakpoints' "shadow contents" back into memory. The | |
1579 | "shadow contents" are NOT valid after an exec, so GDB should not | |
1580 | do that. Instead, the target is responsible from marking | |
1581 | breakpoints out as soon as it detects an exec. We don't do that | |
1582 | here instead, because there may be other attempts to delete | |
1583 | breakpoints after detecting an exec and before reaching here. */ | |
1584 | ALL_BP_LOCATIONS (bploc) | |
1585 | gdb_assert (!bploc->inserted); | |
c906108c SS |
1586 | |
1587 | ALL_BREAKPOINTS_SAFE (b, temp) | |
c5aa993b JM |
1588 | { |
1589 | /* Solib breakpoints must be explicitly reset after an exec(). */ | |
1590 | if (b->type == bp_shlib_event) | |
1591 | { | |
1592 | delete_breakpoint (b); | |
1593 | continue; | |
1594 | } | |
c906108c | 1595 | |
4efc6507 DE |
1596 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
1597 | if (b->type == bp_jit_event) | |
1598 | { | |
1599 | delete_breakpoint (b); | |
1600 | continue; | |
1601 | } | |
1602 | ||
1900040c | 1603 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
1604 | as must overlay event and longjmp master breakpoints. */ |
1605 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
1606 | || b->type == bp_longjmp_master) | |
c4093a6a JM |
1607 | { |
1608 | delete_breakpoint (b); | |
1609 | continue; | |
1610 | } | |
1611 | ||
c5aa993b JM |
1612 | /* Step-resume breakpoints are meaningless after an exec(). */ |
1613 | if (b->type == bp_step_resume) | |
1614 | { | |
1615 | delete_breakpoint (b); | |
1616 | continue; | |
1617 | } | |
1618 | ||
611c83ae PA |
1619 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
1620 | after an exec. */ | |
1621 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume) | |
1622 | { | |
1623 | delete_breakpoint (b); | |
1624 | continue; | |
1625 | } | |
1626 | ||
ce78b96d JB |
1627 | if (b->type == bp_catchpoint) |
1628 | { | |
1629 | /* For now, none of the bp_catchpoint breakpoints need to | |
1630 | do anything at this point. In the future, if some of | |
1631 | the catchpoints need to something, we will need to add | |
1632 | a new method, and call this method from here. */ | |
1633 | continue; | |
1634 | } | |
1635 | ||
c5aa993b JM |
1636 | /* bp_finish is a special case. The only way we ought to be able |
1637 | to see one of these when an exec() has happened, is if the user | |
1638 | caught a vfork, and then said "finish". Ordinarily a finish just | |
1639 | carries them to the call-site of the current callee, by setting | |
1640 | a temporary bp there and resuming. But in this case, the finish | |
1641 | will carry them entirely through the vfork & exec. | |
1642 | ||
1643 | We don't want to allow a bp_finish to remain inserted now. But | |
1644 | we can't safely delete it, 'cause finish_command has a handle to | |
1645 | the bp on a bpstat, and will later want to delete it. There's a | |
1646 | chance (and I've seen it happen) that if we delete the bp_finish | |
1647 | here, that its storage will get reused by the time finish_command | |
1648 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
1649 | We really must allow finish_command to delete a bp_finish. | |
1650 | ||
53a5351d JM |
1651 | In the absense of a general solution for the "how do we know |
1652 | it's safe to delete something others may have handles to?" | |
1653 | problem, what we'll do here is just uninsert the bp_finish, and | |
1654 | let finish_command delete it. | |
1655 | ||
1656 | (We know the bp_finish is "doomed" in the sense that it's | |
1657 | momentary, and will be deleted as soon as finish_command sees | |
1658 | the inferior stopped. So it doesn't matter that the bp's | |
1659 | address is probably bogus in the new a.out, unlike e.g., the | |
1660 | solib breakpoints.) */ | |
c5aa993b | 1661 | |
c5aa993b JM |
1662 | if (b->type == bp_finish) |
1663 | { | |
1664 | continue; | |
1665 | } | |
1666 | ||
1667 | /* Without a symbolic address, we have little hope of the | |
1668 | pre-exec() address meaning the same thing in the post-exec() | |
1669 | a.out. */ | |
1670 | if (b->addr_string == NULL) | |
1671 | { | |
1672 | delete_breakpoint (b); | |
1673 | continue; | |
1674 | } | |
c5aa993b | 1675 | } |
1900040c | 1676 | /* FIXME what about longjmp breakpoints? Re-create them here? */ |
69de3c6a | 1677 | create_overlay_event_breakpoint ("_ovly_debug_event"); |
0fd8e87f UW |
1678 | create_longjmp_master_breakpoint ("longjmp"); |
1679 | create_longjmp_master_breakpoint ("_longjmp"); | |
1680 | create_longjmp_master_breakpoint ("siglongjmp"); | |
1681 | create_longjmp_master_breakpoint ("_siglongjmp"); | |
c906108c SS |
1682 | } |
1683 | ||
1684 | int | |
fba45db2 | 1685 | detach_breakpoints (int pid) |
c906108c | 1686 | { |
0bde7532 | 1687 | struct bp_location *b; |
3a1bae8e | 1688 | int val = 0; |
ce696e05 | 1689 | struct cleanup *old_chain = save_inferior_ptid (); |
c5aa993b | 1690 | |
39f77062 | 1691 | if (pid == PIDGET (inferior_ptid)) |
8a3fe4f8 | 1692 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 1693 | |
ce696e05 KB |
1694 | /* Set inferior_ptid; remove_breakpoint uses this global. */ |
1695 | inferior_ptid = pid_to_ptid (pid); | |
0bde7532 | 1696 | ALL_BP_LOCATIONS (b) |
c5aa993b | 1697 | { |
0bde7532 | 1698 | if (b->inserted) |
3a1bae8e | 1699 | val |= remove_breakpoint (b, mark_inserted); |
c5aa993b | 1700 | } |
ce696e05 | 1701 | do_cleanups (old_chain); |
3a1bae8e | 1702 | return val; |
c906108c SS |
1703 | } |
1704 | ||
1705 | static int | |
0bde7532 | 1706 | remove_breakpoint (struct bp_location *b, insertion_state_t is) |
c906108c SS |
1707 | { |
1708 | int val; | |
c5aa993b | 1709 | |
0bde7532 | 1710 | if (b->owner->enable_state == bp_permanent) |
c2c6d25f JM |
1711 | /* Permanent breakpoints cannot be inserted or removed. */ |
1712 | return 0; | |
1713 | ||
74960c60 VP |
1714 | /* The type of none suggests that owner is actually deleted. |
1715 | This should not ever happen. */ | |
1716 | gdb_assert (b->owner->type != bp_none); | |
0bde7532 DJ |
1717 | |
1718 | if (b->loc_type == bp_loc_software_breakpoint | |
1719 | || b->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 1720 | { |
c02f5703 MS |
1721 | /* "Normal" instruction breakpoint: either the standard |
1722 | trap-instruction bp (bp_breakpoint), or a | |
1723 | bp_hardware_breakpoint. */ | |
1724 | ||
1725 | /* First check to see if we have to handle an overlay. */ | |
1726 | if (overlay_debugging == ovly_off | |
0bde7532 DJ |
1727 | || b->section == NULL |
1728 | || !(section_is_overlay (b->section))) | |
c02f5703 MS |
1729 | { |
1730 | /* No overlay handling: just remove the breakpoint. */ | |
1731 | ||
0bde7532 | 1732 | if (b->loc_type == bp_loc_hardware_breakpoint) |
a6d9a66e | 1733 | val = target_remove_hw_breakpoint (b->gdbarch, &b->target_info); |
c02f5703 | 1734 | else |
a6d9a66e | 1735 | val = target_remove_breakpoint (b->gdbarch, &b->target_info); |
c02f5703 | 1736 | } |
c906108c SS |
1737 | else |
1738 | { | |
c02f5703 MS |
1739 | /* This breakpoint is in an overlay section. |
1740 | Did we set a breakpoint at the LMA? */ | |
1741 | if (!overlay_events_enabled) | |
1742 | { | |
1743 | /* Yes -- overlay event support is not active, so we | |
1744 | should have set a breakpoint at the LMA. Remove it. | |
1745 | */ | |
c02f5703 MS |
1746 | /* Ignore any failures: if the LMA is in ROM, we will |
1747 | have already warned when we failed to insert it. */ | |
0bde7532 | 1748 | if (b->loc_type == bp_loc_hardware_breakpoint) |
a6d9a66e UW |
1749 | target_remove_hw_breakpoint (b->gdbarch, |
1750 | &b->overlay_target_info); | |
c02f5703 | 1751 | else |
a6d9a66e UW |
1752 | target_remove_breakpoint (b->gdbarch, |
1753 | &b->overlay_target_info); | |
c02f5703 MS |
1754 | } |
1755 | /* Did we set a breakpoint at the VMA? | |
1756 | If so, we will have marked the breakpoint 'inserted'. */ | |
0bde7532 | 1757 | if (b->inserted) |
c906108c | 1758 | { |
c02f5703 MS |
1759 | /* Yes -- remove it. Previously we did not bother to |
1760 | remove the breakpoint if the section had been | |
1761 | unmapped, but let's not rely on that being safe. We | |
1762 | don't know what the overlay manager might do. */ | |
0bde7532 | 1763 | if (b->loc_type == bp_loc_hardware_breakpoint) |
a6d9a66e UW |
1764 | val = target_remove_hw_breakpoint (b->gdbarch, |
1765 | &b->target_info); | |
aa67235e UW |
1766 | |
1767 | /* However, we should remove *software* breakpoints only | |
1768 | if the section is still mapped, or else we overwrite | |
1769 | wrong code with the saved shadow contents. */ | |
1770 | else if (section_is_mapped (b->section)) | |
a6d9a66e UW |
1771 | val = target_remove_breakpoint (b->gdbarch, |
1772 | &b->target_info); | |
aa67235e UW |
1773 | else |
1774 | val = 0; | |
c906108c | 1775 | } |
c02f5703 MS |
1776 | else |
1777 | { | |
1778 | /* No -- not inserted, so no need to remove. No error. */ | |
1779 | val = 0; | |
1780 | } | |
c906108c | 1781 | } |
879d1e6b UW |
1782 | |
1783 | /* In some cases, we might not be able to remove a breakpoint | |
1784 | in a shared library that has already been removed, but we | |
1785 | have not yet processed the shlib unload event. */ | |
f5c9a895 | 1786 | if (val && solib_name_from_address (b->address)) |
879d1e6b UW |
1787 | val = 0; |
1788 | ||
c906108c SS |
1789 | if (val) |
1790 | return val; | |
0bde7532 | 1791 | b->inserted = (is == mark_inserted); |
c906108c | 1792 | } |
a5606eee | 1793 | else if (b->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 1794 | { |
278cd55f AC |
1795 | struct value *v; |
1796 | struct value *n; | |
c5aa993b | 1797 | |
0bde7532 | 1798 | b->inserted = (is == mark_inserted); |
a5606eee VP |
1799 | val = target_remove_watchpoint (b->address, b->length, |
1800 | b->watchpoint_type); | |
2e70b7b9 | 1801 | |
c906108c | 1802 | /* Failure to remove any of the hardware watchpoints comes here. */ |
0bde7532 | 1803 | if ((is == mark_uninserted) && (b->inserted)) |
8a3fe4f8 | 1804 | warning (_("Could not remove hardware watchpoint %d."), |
0bde7532 | 1805 | b->owner->number); |
c906108c | 1806 | } |
ce78b96d JB |
1807 | else if (b->owner->type == bp_catchpoint |
1808 | && breakpoint_enabled (b->owner) | |
1809 | && !b->duplicate) | |
1810 | { | |
1811 | gdb_assert (b->owner->ops != NULL && b->owner->ops->remove != NULL); | |
1812 | ||
1813 | val = b->owner->ops->remove (b->owner); | |
1814 | if (val) | |
1815 | return val; | |
1816 | b->inserted = (is == mark_inserted); | |
1817 | } | |
c906108c SS |
1818 | |
1819 | return 0; | |
1820 | } | |
1821 | ||
1822 | /* Clear the "inserted" flag in all breakpoints. */ | |
1823 | ||
25b22b0a | 1824 | void |
fba45db2 | 1825 | mark_breakpoints_out (void) |
c906108c | 1826 | { |
075f6582 | 1827 | struct bp_location *bpt; |
c906108c | 1828 | |
075f6582 DJ |
1829 | ALL_BP_LOCATIONS (bpt) |
1830 | bpt->inserted = 0; | |
c906108c SS |
1831 | } |
1832 | ||
53a5351d JM |
1833 | /* Clear the "inserted" flag in all breakpoints and delete any |
1834 | breakpoints which should go away between runs of the program. | |
c906108c SS |
1835 | |
1836 | Plus other such housekeeping that has to be done for breakpoints | |
1837 | between runs. | |
1838 | ||
53a5351d JM |
1839 | Note: this function gets called at the end of a run (by |
1840 | generic_mourn_inferior) and when a run begins (by | |
1841 | init_wait_for_inferior). */ | |
c906108c SS |
1842 | |
1843 | ||
1844 | ||
1845 | void | |
fba45db2 | 1846 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 1847 | { |
52f0bd74 | 1848 | struct breakpoint *b, *temp; |
075f6582 | 1849 | struct bp_location *bpt; |
1c5cfe86 | 1850 | int ix; |
c906108c | 1851 | |
50c71eaf PA |
1852 | /* If breakpoint locations are shared across processes, then there's |
1853 | nothing to do. */ | |
2567c7d9 | 1854 | if (gdbarch_has_global_breakpoints (target_gdbarch)) |
50c71eaf PA |
1855 | return; |
1856 | ||
075f6582 | 1857 | ALL_BP_LOCATIONS (bpt) |
514f746b AR |
1858 | if (bpt->owner->enable_state != bp_permanent) |
1859 | bpt->inserted = 0; | |
075f6582 | 1860 | |
c906108c | 1861 | ALL_BREAKPOINTS_SAFE (b, temp) |
c5aa993b | 1862 | { |
c5aa993b JM |
1863 | switch (b->type) |
1864 | { | |
1865 | case bp_call_dummy: | |
1866 | case bp_watchpoint_scope: | |
c906108c | 1867 | |
c5aa993b JM |
1868 | /* If the call dummy breakpoint is at the entry point it will |
1869 | cause problems when the inferior is rerun, so we better | |
1870 | get rid of it. | |
c906108c | 1871 | |
c5aa993b JM |
1872 | Also get rid of scope breakpoints. */ |
1873 | delete_breakpoint (b); | |
1874 | break; | |
c906108c | 1875 | |
c5aa993b JM |
1876 | case bp_watchpoint: |
1877 | case bp_hardware_watchpoint: | |
1878 | case bp_read_watchpoint: | |
1879 | case bp_access_watchpoint: | |
c906108c | 1880 | |
c5aa993b JM |
1881 | /* Likewise for watchpoints on local expressions. */ |
1882 | if (b->exp_valid_block != NULL) | |
1883 | delete_breakpoint (b); | |
967af18d | 1884 | else if (context == inf_starting) |
c860120c PM |
1885 | { |
1886 | /* Reset val field to force reread of starting value | |
1887 | in insert_breakpoints. */ | |
1888 | if (b->val) | |
1889 | value_free (b->val); | |
1890 | b->val = NULL; | |
fa4727a6 | 1891 | b->val_valid = 0; |
c860120c | 1892 | } |
c5aa993b JM |
1893 | break; |
1894 | default: | |
c5aa993b JM |
1895 | break; |
1896 | } | |
1897 | } | |
1c5cfe86 PA |
1898 | |
1899 | /* Get rid of the moribund locations. */ | |
1900 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bpt); ++ix) | |
1901 | free_bp_location (bpt); | |
1902 | VEC_free (bp_location_p, moribund_locations); | |
c906108c SS |
1903 | } |
1904 | ||
c2c6d25f JM |
1905 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
1906 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
1907 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
1908 | permanent breakpoint. | |
1909 | - When continuing from a location with an ordinary breakpoint, we | |
1910 | actually single step once before calling insert_breakpoints. | |
1911 | - When continuing from a localion with a permanent breakpoint, we | |
1912 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by | |
1913 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 1914 | |
c2c6d25f | 1915 | enum breakpoint_here |
fba45db2 | 1916 | breakpoint_here_p (CORE_ADDR pc) |
c906108c | 1917 | { |
89f9893c | 1918 | const struct bp_location *bpt; |
c2c6d25f | 1919 | int any_breakpoint_here = 0; |
c906108c | 1920 | |
075f6582 DJ |
1921 | ALL_BP_LOCATIONS (bpt) |
1922 | { | |
1923 | if (bpt->loc_type != bp_loc_software_breakpoint | |
1924 | && bpt->loc_type != bp_loc_hardware_breakpoint) | |
1925 | continue; | |
1926 | ||
468d015d | 1927 | if ((breakpoint_enabled (bpt->owner) |
075f6582 DJ |
1928 | || bpt->owner->enable_state == bp_permanent) |
1929 | && bpt->address == pc) /* bp is enabled and matches pc */ | |
1930 | { | |
1931 | if (overlay_debugging | |
1932 | && section_is_overlay (bpt->section) | |
1933 | && !section_is_mapped (bpt->section)) | |
1934 | continue; /* unmapped overlay -- can't be a match */ | |
1935 | else if (bpt->owner->enable_state == bp_permanent) | |
1936 | return permanent_breakpoint_here; | |
1937 | else | |
1938 | any_breakpoint_here = 1; | |
1939 | } | |
1940 | } | |
c906108c | 1941 | |
c2c6d25f | 1942 | return any_breakpoint_here ? ordinary_breakpoint_here : 0; |
c906108c SS |
1943 | } |
1944 | ||
1c5cfe86 PA |
1945 | /* Return true if there's a moribund breakpoint at PC. */ |
1946 | ||
1947 | int | |
1948 | moribund_breakpoint_here_p (CORE_ADDR pc) | |
1949 | { | |
1950 | struct bp_location *loc; | |
1951 | int ix; | |
1952 | ||
1953 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
1954 | if (loc->address == pc) | |
1955 | return 1; | |
1956 | ||
1957 | return 0; | |
1958 | } | |
c2c6d25f | 1959 | |
c36b740a VP |
1960 | /* Returns non-zero if there's a breakpoint inserted at PC, which is |
1961 | inserted using regular breakpoint_chain/bp_location_chain mechanism. | |
1962 | This does not check for single-step breakpoints, which are | |
1963 | inserted and removed using direct target manipulation. */ | |
c906108c SS |
1964 | |
1965 | int | |
c36b740a | 1966 | regular_breakpoint_inserted_here_p (CORE_ADDR pc) |
c906108c | 1967 | { |
89f9893c | 1968 | const struct bp_location *bpt; |
c906108c | 1969 | |
075f6582 | 1970 | ALL_BP_LOCATIONS (bpt) |
c5aa993b | 1971 | { |
075f6582 DJ |
1972 | if (bpt->loc_type != bp_loc_software_breakpoint |
1973 | && bpt->loc_type != bp_loc_hardware_breakpoint) | |
1974 | continue; | |
1975 | ||
1976 | if (bpt->inserted | |
1977 | && bpt->address == pc) /* bp is inserted and matches pc */ | |
1978 | { | |
1979 | if (overlay_debugging | |
1980 | && section_is_overlay (bpt->section) | |
1981 | && !section_is_mapped (bpt->section)) | |
1982 | continue; /* unmapped overlay -- can't be a match */ | |
1983 | else | |
1984 | return 1; | |
1985 | } | |
c5aa993b | 1986 | } |
c36b740a VP |
1987 | return 0; |
1988 | } | |
1989 | ||
1990 | /* Returns non-zero iff there's either regular breakpoint | |
1991 | or a single step breakpoint inserted at PC. */ | |
1992 | ||
1993 | int | |
1994 | breakpoint_inserted_here_p (CORE_ADDR pc) | |
1995 | { | |
1996 | if (regular_breakpoint_inserted_here_p (pc)) | |
1997 | return 1; | |
c906108c | 1998 | |
1aafd4da UW |
1999 | if (single_step_breakpoint_inserted_here_p (pc)) |
2000 | return 1; | |
2001 | ||
c906108c SS |
2002 | return 0; |
2003 | } | |
2004 | ||
4fa8626c DJ |
2005 | /* This function returns non-zero iff there is a software breakpoint |
2006 | inserted at PC. */ | |
2007 | ||
2008 | int | |
2009 | software_breakpoint_inserted_here_p (CORE_ADDR pc) | |
2010 | { | |
89f9893c | 2011 | const struct bp_location *bpt; |
4fa8626c DJ |
2012 | int any_breakpoint_here = 0; |
2013 | ||
2014 | ALL_BP_LOCATIONS (bpt) | |
2015 | { | |
2016 | if (bpt->loc_type != bp_loc_software_breakpoint) | |
2017 | continue; | |
2018 | ||
0d381245 | 2019 | if (bpt->inserted |
4fa8626c DJ |
2020 | && bpt->address == pc) /* bp is enabled and matches pc */ |
2021 | { | |
2022 | if (overlay_debugging | |
2023 | && section_is_overlay (bpt->section) | |
2024 | && !section_is_mapped (bpt->section)) | |
2025 | continue; /* unmapped overlay -- can't be a match */ | |
2026 | else | |
2027 | return 1; | |
2028 | } | |
2029 | } | |
2030 | ||
1aafd4da UW |
2031 | /* Also check for software single-step breakpoints. */ |
2032 | if (single_step_breakpoint_inserted_here_p (pc)) | |
2033 | return 1; | |
2034 | ||
4fa8626c DJ |
2035 | return 0; |
2036 | } | |
2037 | ||
075f6582 DJ |
2038 | /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at |
2039 | PC is valid for process/thread PTID. */ | |
c906108c SS |
2040 | |
2041 | int | |
39f77062 | 2042 | breakpoint_thread_match (CORE_ADDR pc, ptid_t ptid) |
c906108c | 2043 | { |
89f9893c | 2044 | const struct bp_location *bpt; |
4a306c9a | 2045 | /* The thread and task IDs associated to PTID, computed lazily. */ |
a6f1cd96 | 2046 | int thread = -1; |
4a306c9a | 2047 | int task = 0; |
a6f1cd96 | 2048 | |
075f6582 | 2049 | ALL_BP_LOCATIONS (bpt) |
c5aa993b | 2050 | { |
075f6582 DJ |
2051 | if (bpt->loc_type != bp_loc_software_breakpoint |
2052 | && bpt->loc_type != bp_loc_hardware_breakpoint) | |
2053 | continue; | |
2054 | ||
a6f1cd96 JB |
2055 | if (!breakpoint_enabled (bpt->owner) |
2056 | && bpt->owner->enable_state != bp_permanent) | |
2057 | continue; | |
2058 | ||
2059 | if (bpt->address != pc) | |
2060 | continue; | |
2061 | ||
2062 | if (bpt->owner->thread != -1) | |
075f6582 | 2063 | { |
a6f1cd96 JB |
2064 | /* This is a thread-specific breakpoint. Check that ptid |
2065 | matches that thread. If thread hasn't been computed yet, | |
2066 | it is now time to do so. */ | |
2067 | if (thread == -1) | |
2068 | thread = pid_to_thread_id (ptid); | |
2069 | if (bpt->owner->thread != thread) | |
2070 | continue; | |
075f6582 | 2071 | } |
a6f1cd96 | 2072 | |
4a306c9a JB |
2073 | if (bpt->owner->task != 0) |
2074 | { | |
2075 | /* This is a task-specific breakpoint. Check that ptid | |
2076 | matches that task. If task hasn't been computed yet, | |
2077 | it is now time to do so. */ | |
2078 | if (task == 0) | |
2079 | task = ada_get_task_number (ptid); | |
2080 | if (bpt->owner->task != task) | |
2081 | continue; | |
2082 | } | |
2083 | ||
a6f1cd96 JB |
2084 | if (overlay_debugging |
2085 | && section_is_overlay (bpt->section) | |
2086 | && !section_is_mapped (bpt->section)) | |
2087 | continue; /* unmapped overlay -- can't be a match */ | |
2088 | ||
2089 | return 1; | |
c5aa993b | 2090 | } |
c906108c SS |
2091 | |
2092 | return 0; | |
2093 | } | |
c906108c | 2094 | \f |
c5aa993b | 2095 | |
c906108c SS |
2096 | /* bpstat stuff. External routines' interfaces are documented |
2097 | in breakpoint.h. */ | |
2098 | ||
2099 | int | |
fba45db2 | 2100 | ep_is_catchpoint (struct breakpoint *ep) |
c906108c | 2101 | { |
533be4dd | 2102 | return (ep->type == bp_catchpoint); |
c906108c SS |
2103 | } |
2104 | ||
198757a8 VP |
2105 | void |
2106 | bpstat_free (bpstat bs) | |
2107 | { | |
2108 | if (bs->old_val != NULL) | |
2109 | value_free (bs->old_val); | |
2110 | free_command_lines (&bs->commands); | |
2111 | xfree (bs); | |
2112 | } | |
2113 | ||
c906108c SS |
2114 | /* Clear a bpstat so that it says we are not at any breakpoint. |
2115 | Also free any storage that is part of a bpstat. */ | |
2116 | ||
2117 | void | |
fba45db2 | 2118 | bpstat_clear (bpstat *bsp) |
c906108c SS |
2119 | { |
2120 | bpstat p; | |
2121 | bpstat q; | |
2122 | ||
2123 | if (bsp == 0) | |
2124 | return; | |
2125 | p = *bsp; | |
2126 | while (p != NULL) | |
2127 | { | |
2128 | q = p->next; | |
198757a8 | 2129 | bpstat_free (p); |
c906108c SS |
2130 | p = q; |
2131 | } | |
2132 | *bsp = NULL; | |
2133 | } | |
2134 | ||
2135 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
2136 | is part of the bpstat is copied as well. */ | |
2137 | ||
2138 | bpstat | |
fba45db2 | 2139 | bpstat_copy (bpstat bs) |
c906108c SS |
2140 | { |
2141 | bpstat p = NULL; | |
2142 | bpstat tmp; | |
2143 | bpstat retval = NULL; | |
2144 | ||
2145 | if (bs == NULL) | |
2146 | return bs; | |
2147 | ||
2148 | for (; bs != NULL; bs = bs->next) | |
2149 | { | |
2150 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
2151 | memcpy (tmp, bs, sizeof (*tmp)); | |
31cc81e9 DJ |
2152 | if (bs->commands != NULL) |
2153 | tmp->commands = copy_command_lines (bs->commands); | |
2154 | if (bs->old_val != NULL) | |
3c3185ac JK |
2155 | { |
2156 | tmp->old_val = value_copy (bs->old_val); | |
2157 | release_value (tmp->old_val); | |
2158 | } | |
31cc81e9 | 2159 | |
c906108c SS |
2160 | if (p == NULL) |
2161 | /* This is the first thing in the chain. */ | |
2162 | retval = tmp; | |
2163 | else | |
2164 | p->next = tmp; | |
2165 | p = tmp; | |
2166 | } | |
2167 | p->next = NULL; | |
2168 | return retval; | |
2169 | } | |
2170 | ||
2171 | /* Find the bpstat associated with this breakpoint */ | |
2172 | ||
2173 | bpstat | |
fba45db2 | 2174 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 2175 | { |
c5aa993b JM |
2176 | if (bsp == NULL) |
2177 | return NULL; | |
c906108c | 2178 | |
c5aa993b JM |
2179 | for (; bsp != NULL; bsp = bsp->next) |
2180 | { | |
4f8d1dc6 | 2181 | if (bsp->breakpoint_at && bsp->breakpoint_at->owner == breakpoint) |
c5aa993b JM |
2182 | return bsp; |
2183 | } | |
c906108c SS |
2184 | return NULL; |
2185 | } | |
2186 | ||
2187 | /* Find a step_resume breakpoint associated with this bpstat. | |
2188 | (If there are multiple step_resume bp's on the list, this function | |
2189 | will arbitrarily pick one.) | |
2190 | ||
2191 | It is an error to use this function if BPSTAT doesn't contain a | |
2192 | step_resume breakpoint. | |
2193 | ||
2194 | See wait_for_inferior's use of this function. */ | |
2195 | struct breakpoint * | |
fba45db2 | 2196 | bpstat_find_step_resume_breakpoint (bpstat bsp) |
c906108c | 2197 | { |
8601f500 MS |
2198 | int current_thread; |
2199 | ||
8a3fe4f8 | 2200 | gdb_assert (bsp != NULL); |
c906108c | 2201 | |
8601f500 MS |
2202 | current_thread = pid_to_thread_id (inferior_ptid); |
2203 | ||
c906108c SS |
2204 | for (; bsp != NULL; bsp = bsp->next) |
2205 | { | |
059fb39f PM |
2206 | if ((bsp->breakpoint_at != NULL) |
2207 | && (bsp->breakpoint_at->owner->type == bp_step_resume) | |
2208 | && (bsp->breakpoint_at->owner->thread == current_thread | |
2209 | || bsp->breakpoint_at->owner->thread == -1)) | |
4f8d1dc6 | 2210 | return bsp->breakpoint_at->owner; |
c906108c SS |
2211 | } |
2212 | ||
8a3fe4f8 | 2213 | internal_error (__FILE__, __LINE__, _("No step_resume breakpoint found.")); |
c906108c SS |
2214 | } |
2215 | ||
2216 | ||
8671a17b | 2217 | /* Put in *NUM the breakpoint number of the first breakpoint we are stopped |
c906108c SS |
2218 | at. *BSP upon return is a bpstat which points to the remaining |
2219 | breakpoints stopped at (but which is not guaranteed to be good for | |
2220 | anything but further calls to bpstat_num). | |
8671a17b PA |
2221 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
2222 | Return -1 if stopped at a breakpoint that has been deleted since | |
2223 | we set it. | |
2224 | Return 1 otherwise. */ | |
c906108c SS |
2225 | |
2226 | int | |
8671a17b | 2227 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
2228 | { |
2229 | struct breakpoint *b; | |
2230 | ||
2231 | if ((*bsp) == NULL) | |
2232 | return 0; /* No more breakpoint values */ | |
8671a17b | 2233 | |
4f8d1dc6 VP |
2234 | /* We assume we'll never have several bpstats that |
2235 | correspond to a single breakpoint -- otherwise, | |
2236 | this function might return the same number more | |
2237 | than once and this will look ugly. */ | |
2238 | b = (*bsp)->breakpoint_at ? (*bsp)->breakpoint_at->owner : NULL; | |
8671a17b PA |
2239 | *bsp = (*bsp)->next; |
2240 | if (b == NULL) | |
2241 | return -1; /* breakpoint that's been deleted since */ | |
2242 | ||
2243 | *num = b->number; /* We have its number */ | |
2244 | return 1; | |
c906108c SS |
2245 | } |
2246 | ||
2247 | /* Modify BS so that the actions will not be performed. */ | |
2248 | ||
2249 | void | |
fba45db2 | 2250 | bpstat_clear_actions (bpstat bs) |
c906108c SS |
2251 | { |
2252 | for (; bs != NULL; bs = bs->next) | |
2253 | { | |
c2b8ed2c | 2254 | free_command_lines (&bs->commands); |
c906108c SS |
2255 | if (bs->old_val != NULL) |
2256 | { | |
2257 | value_free (bs->old_val); | |
2258 | bs->old_val = NULL; | |
2259 | } | |
2260 | } | |
2261 | } | |
2262 | ||
f3b1572e PA |
2263 | /* Called when a command is about to proceed the inferior. */ |
2264 | ||
2265 | static void | |
2266 | breakpoint_about_to_proceed (void) | |
2267 | { | |
2268 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
2269 | { | |
2270 | struct thread_info *tp = inferior_thread (); | |
2271 | ||
2272 | /* Allow inferior function calls in breakpoint commands to not | |
2273 | interrupt the command list. When the call finishes | |
2274 | successfully, the inferior will be standing at the same | |
2275 | breakpoint as if nothing happened. */ | |
2276 | if (tp->in_infcall) | |
2277 | return; | |
2278 | } | |
2279 | ||
2280 | breakpoint_proceeded = 1; | |
2281 | } | |
2282 | ||
c906108c | 2283 | /* Stub for cleaning up our state if we error-out of a breakpoint command */ |
c906108c | 2284 | static void |
4efb68b1 | 2285 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
2286 | { |
2287 | executing_breakpoint_commands = 0; | |
2288 | } | |
2289 | ||
2290 | /* Execute all the commands associated with all the breakpoints at this | |
2291 | location. Any of these commands could cause the process to proceed | |
2292 | beyond this point, etc. We look out for such changes by checking | |
347bddb7 | 2293 | the global "breakpoint_proceeded" after each command. |
c906108c | 2294 | |
347bddb7 PA |
2295 | Returns true if a breakpoint command resumed the inferior. In that |
2296 | case, it is the caller's responsibility to recall it again with the | |
2297 | bpstat of the current thread. */ | |
2298 | ||
2299 | static int | |
2300 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
2301 | { |
2302 | bpstat bs; | |
2303 | struct cleanup *old_chain; | |
347bddb7 | 2304 | int again = 0; |
c906108c SS |
2305 | |
2306 | /* Avoid endless recursion if a `source' command is contained | |
2307 | in bs->commands. */ | |
2308 | if (executing_breakpoint_commands) | |
347bddb7 | 2309 | return 0; |
c906108c SS |
2310 | |
2311 | executing_breakpoint_commands = 1; | |
2312 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
2313 | ||
c906108c SS |
2314 | /* This pointer will iterate over the list of bpstat's. */ |
2315 | bs = *bsp; | |
2316 | ||
2317 | breakpoint_proceeded = 0; | |
2318 | for (; bs != NULL; bs = bs->next) | |
2319 | { | |
6c50ab1c JB |
2320 | struct command_line *cmd; |
2321 | struct cleanup *this_cmd_tree_chain; | |
2322 | ||
2323 | /* Take ownership of the BSP's command tree, if it has one. | |
2324 | ||
2325 | The command tree could legitimately contain commands like | |
2326 | 'step' and 'next', which call clear_proceed_status, which | |
2327 | frees stop_bpstat's command tree. To make sure this doesn't | |
2328 | free the tree we're executing out from under us, we need to | |
2329 | take ownership of the tree ourselves. Since a given bpstat's | |
2330 | commands are only executed once, we don't need to copy it; we | |
2331 | can clear the pointer in the bpstat, and make sure we free | |
2332 | the tree when we're done. */ | |
c906108c | 2333 | cmd = bs->commands; |
6c50ab1c JB |
2334 | bs->commands = 0; |
2335 | this_cmd_tree_chain = make_cleanup_free_command_lines (&cmd); | |
2336 | ||
c906108c SS |
2337 | while (cmd != NULL) |
2338 | { | |
2339 | execute_control_command (cmd); | |
2340 | ||
2341 | if (breakpoint_proceeded) | |
2342 | break; | |
2343 | else | |
2344 | cmd = cmd->next; | |
2345 | } | |
6c50ab1c JB |
2346 | |
2347 | /* We can free this command tree now. */ | |
2348 | do_cleanups (this_cmd_tree_chain); | |
2349 | ||
c906108c | 2350 | if (breakpoint_proceeded) |
32c1e744 VP |
2351 | { |
2352 | if (target_can_async_p ()) | |
347bddb7 PA |
2353 | /* If we are in async mode, then the target might be still |
2354 | running, not stopped at any breakpoint, so nothing for | |
2355 | us to do here -- just return to the event loop. */ | |
2356 | ; | |
32c1e744 VP |
2357 | else |
2358 | /* In sync mode, when execute_control_command returns | |
2359 | we're already standing on the next breakpoint. | |
347bddb7 PA |
2360 | Breakpoint commands for that stop were not run, since |
2361 | execute_command does not run breakpoint commands -- | |
2362 | only command_line_handler does, but that one is not | |
2363 | involved in execution of breakpoint commands. So, we | |
2364 | can now execute breakpoint commands. It should be | |
2365 | noted that making execute_command do bpstat actions is | |
2366 | not an option -- in this case we'll have recursive | |
2367 | invocation of bpstat for each breakpoint with a | |
2368 | command, and can easily blow up GDB stack. Instead, we | |
2369 | return true, which will trigger the caller to recall us | |
2370 | with the new stop_bpstat. */ | |
2371 | again = 1; | |
2372 | break; | |
32c1e744 | 2373 | } |
c906108c | 2374 | } |
c2b8ed2c | 2375 | do_cleanups (old_chain); |
347bddb7 PA |
2376 | return again; |
2377 | } | |
2378 | ||
2379 | void | |
2380 | bpstat_do_actions (void) | |
2381 | { | |
2382 | /* Do any commands attached to breakpoint we are stopped at. */ | |
2383 | while (!ptid_equal (inferior_ptid, null_ptid) | |
2384 | && target_has_execution | |
2385 | && !is_exited (inferior_ptid) | |
2386 | && !is_executing (inferior_ptid)) | |
2387 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
2388 | and only return when it is stopped at the next breakpoint, we | |
2389 | keep doing breakpoint actions until it returns false to | |
2390 | indicate the inferior was not resumed. */ | |
2391 | if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat)) | |
2392 | break; | |
c906108c SS |
2393 | } |
2394 | ||
fa4727a6 DJ |
2395 | /* Print out the (old or new) value associated with a watchpoint. */ |
2396 | ||
2397 | static void | |
2398 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
2399 | { | |
2400 | if (val == NULL) | |
2401 | fprintf_unfiltered (stream, _("<unreadable>")); | |
2402 | else | |
79a45b7d TT |
2403 | { |
2404 | struct value_print_options opts; | |
2405 | get_user_print_options (&opts); | |
2406 | value_print (val, stream, &opts); | |
2407 | } | |
fa4727a6 DJ |
2408 | } |
2409 | ||
e514a9d6 | 2410 | /* This is the normal print function for a bpstat. In the future, |
c906108c | 2411 | much of this logic could (should?) be moved to bpstat_stop_status, |
e514a9d6 JM |
2412 | by having it set different print_it values. |
2413 | ||
2414 | Current scheme: When we stop, bpstat_print() is called. It loops | |
2415 | through the bpstat list of things causing this stop, calling the | |
2416 | print_bp_stop_message function on each one. The behavior of the | |
2417 | print_bp_stop_message function depends on the print_it field of | |
2418 | bpstat. If such field so indicates, call this function here. | |
2419 | ||
2420 | Return values from this routine (ultimately used by bpstat_print() | |
2421 | and normal_stop() to decide what to do): | |
2422 | PRINT_NOTHING: Means we already printed all we needed to print, | |
2423 | don't print anything else. | |
2424 | PRINT_SRC_ONLY: Means we printed something, and we do *not* desire | |
2425 | that something to be followed by a location. | |
2426 | PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire | |
2427 | that something to be followed by a location. | |
2428 | PRINT_UNKNOWN: Means we printed nothing or we need to do some more | |
2429 | analysis. */ | |
c906108c | 2430 | |
917317f4 | 2431 | static enum print_stop_action |
fba45db2 | 2432 | print_it_typical (bpstat bs) |
c906108c | 2433 | { |
f7545552 | 2434 | struct cleanup *old_chain; |
4f8d1dc6 | 2435 | struct breakpoint *b; |
89f9893c | 2436 | const struct bp_location *bl; |
8b93c638 | 2437 | struct ui_stream *stb; |
f7545552 TT |
2438 | int bp_temp = 0; |
2439 | enum print_stop_action result; | |
2440 | ||
c906108c SS |
2441 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
2442 | which has since been deleted. */ | |
e514a9d6 | 2443 | if (bs->breakpoint_at == NULL) |
917317f4 | 2444 | return PRINT_UNKNOWN; |
0d381245 VP |
2445 | bl = bs->breakpoint_at; |
2446 | b = bl->owner; | |
c906108c | 2447 | |
f7545552 TT |
2448 | stb = ui_out_stream_new (uiout); |
2449 | old_chain = make_cleanup_ui_out_stream_delete (stb); | |
2450 | ||
4f8d1dc6 | 2451 | switch (b->type) |
c906108c | 2452 | { |
e514a9d6 JM |
2453 | case bp_breakpoint: |
2454 | case bp_hardware_breakpoint: | |
2cec12e5 | 2455 | bp_temp = bs->breakpoint_at->owner->disposition == disp_del; |
0d381245 VP |
2456 | if (bl->address != bl->requested_address) |
2457 | breakpoint_adjustment_warning (bl->requested_address, | |
2458 | bl->address, | |
4f8d1dc6 VP |
2459 | b->number, 1); |
2460 | annotate_breakpoint (b->number); | |
2cec12e5 AR |
2461 | if (bp_temp) |
2462 | ui_out_text (uiout, "\nTemporary breakpoint "); | |
2463 | else | |
2464 | ui_out_text (uiout, "\nBreakpoint "); | |
9dc5e2a9 | 2465 | if (ui_out_is_mi_like_p (uiout)) |
2cec12e5 AR |
2466 | { |
2467 | ui_out_field_string (uiout, "reason", | |
2468 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
2469 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
2470 | } | |
4f8d1dc6 | 2471 | ui_out_field_int (uiout, "bkptno", b->number); |
8b93c638 | 2472 | ui_out_text (uiout, ", "); |
f7545552 | 2473 | result = PRINT_SRC_AND_LOC; |
e514a9d6 JM |
2474 | break; |
2475 | ||
2476 | case bp_shlib_event: | |
917317f4 JM |
2477 | /* Did we stop because the user set the stop_on_solib_events |
2478 | variable? (If so, we report this as a generic, "Stopped due | |
2479 | to shlib event" message.) */ | |
a3f17187 | 2480 | printf_filtered (_("Stopped due to shared library event\n")); |
f7545552 | 2481 | result = PRINT_NOTHING; |
e514a9d6 JM |
2482 | break; |
2483 | ||
c4093a6a JM |
2484 | case bp_thread_event: |
2485 | /* Not sure how we will get here. | |
2486 | GDB should not stop for these breakpoints. */ | |
a3f17187 | 2487 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); |
f7545552 | 2488 | result = PRINT_NOTHING; |
c4093a6a JM |
2489 | break; |
2490 | ||
1900040c MS |
2491 | case bp_overlay_event: |
2492 | /* By analogy with the thread event, GDB should not stop for these. */ | |
a3f17187 | 2493 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); |
f7545552 | 2494 | result = PRINT_NOTHING; |
1900040c MS |
2495 | break; |
2496 | ||
0fd8e87f UW |
2497 | case bp_longjmp_master: |
2498 | /* These should never be enabled. */ | |
2499 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
2500 | result = PRINT_NOTHING; | |
2501 | break; | |
2502 | ||
e514a9d6 JM |
2503 | case bp_watchpoint: |
2504 | case bp_hardware_watchpoint: | |
fa4727a6 DJ |
2505 | annotate_watchpoint (b->number); |
2506 | if (ui_out_is_mi_like_p (uiout)) | |
2507 | ui_out_field_string | |
2508 | (uiout, "reason", | |
2509 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
2510 | mention (b); | |
f7545552 | 2511 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
fa4727a6 DJ |
2512 | ui_out_text (uiout, "\nOld value = "); |
2513 | watchpoint_value_print (bs->old_val, stb->stream); | |
2514 | ui_out_field_stream (uiout, "old", stb); | |
2515 | ui_out_text (uiout, "\nNew value = "); | |
2516 | watchpoint_value_print (b->val, stb->stream); | |
2517 | ui_out_field_stream (uiout, "new", stb); | |
fa4727a6 | 2518 | ui_out_text (uiout, "\n"); |
e514a9d6 | 2519 | /* More than one watchpoint may have been triggered. */ |
f7545552 | 2520 | result = PRINT_UNKNOWN; |
e514a9d6 JM |
2521 | break; |
2522 | ||
2523 | case bp_read_watchpoint: | |
9dc5e2a9 | 2524 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
2525 | ui_out_field_string |
2526 | (uiout, "reason", | |
2527 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
4f8d1dc6 | 2528 | mention (b); |
f7545552 | 2529 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 | 2530 | ui_out_text (uiout, "\nValue = "); |
fa4727a6 | 2531 | watchpoint_value_print (b->val, stb->stream); |
8b93c638 | 2532 | ui_out_field_stream (uiout, "value", stb); |
8b93c638 | 2533 | ui_out_text (uiout, "\n"); |
f7545552 | 2534 | result = PRINT_UNKNOWN; |
e514a9d6 JM |
2535 | break; |
2536 | ||
2537 | case bp_access_watchpoint: | |
fa4727a6 | 2538 | if (bs->old_val != NULL) |
8b93c638 | 2539 | { |
4f8d1dc6 | 2540 | annotate_watchpoint (b->number); |
9dc5e2a9 | 2541 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
2542 | ui_out_field_string |
2543 | (uiout, "reason", | |
2544 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
4f8d1dc6 | 2545 | mention (b); |
f7545552 | 2546 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 | 2547 | ui_out_text (uiout, "\nOld value = "); |
fa4727a6 | 2548 | watchpoint_value_print (bs->old_val, stb->stream); |
8b93c638 | 2549 | ui_out_field_stream (uiout, "old", stb); |
8b93c638 JM |
2550 | ui_out_text (uiout, "\nNew value = "); |
2551 | } | |
2552 | else | |
2553 | { | |
4f8d1dc6 | 2554 | mention (b); |
9dc5e2a9 | 2555 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
2556 | ui_out_field_string |
2557 | (uiout, "reason", | |
2558 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
f7545552 | 2559 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 JM |
2560 | ui_out_text (uiout, "\nValue = "); |
2561 | } | |
fa4727a6 | 2562 | watchpoint_value_print (b->val, stb->stream); |
8b93c638 | 2563 | ui_out_field_stream (uiout, "new", stb); |
8b93c638 | 2564 | ui_out_text (uiout, "\n"); |
f7545552 | 2565 | result = PRINT_UNKNOWN; |
e514a9d6 | 2566 | break; |
4ce44c66 | 2567 | |
e514a9d6 JM |
2568 | /* Fall through, we don't deal with these types of breakpoints |
2569 | here. */ | |
2570 | ||
11cf8741 | 2571 | case bp_finish: |
9dc5e2a9 | 2572 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
2573 | ui_out_field_string |
2574 | (uiout, "reason", | |
2575 | async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED)); | |
f7545552 | 2576 | result = PRINT_UNKNOWN; |
8b93c638 JM |
2577 | break; |
2578 | ||
e514a9d6 | 2579 | case bp_until: |
9dc5e2a9 | 2580 | if (ui_out_is_mi_like_p (uiout)) |
1fbc2a49 NR |
2581 | ui_out_field_string |
2582 | (uiout, "reason", | |
2583 | async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED)); | |
f7545552 | 2584 | result = PRINT_UNKNOWN; |
8b93c638 JM |
2585 | break; |
2586 | ||
c2d11a7d | 2587 | case bp_none: |
e514a9d6 JM |
2588 | case bp_longjmp: |
2589 | case bp_longjmp_resume: | |
2590 | case bp_step_resume: | |
e514a9d6 JM |
2591 | case bp_watchpoint_scope: |
2592 | case bp_call_dummy: | |
1042e4c0 | 2593 | case bp_tracepoint: |
4efc6507 | 2594 | case bp_jit_event: |
e514a9d6 | 2595 | default: |
f7545552 TT |
2596 | result = PRINT_UNKNOWN; |
2597 | break; | |
e514a9d6 | 2598 | } |
f7545552 TT |
2599 | |
2600 | do_cleanups (old_chain); | |
2601 | return result; | |
e514a9d6 JM |
2602 | } |
2603 | ||
2604 | /* Generic routine for printing messages indicating why we | |
2605 | stopped. The behavior of this function depends on the value | |
2606 | 'print_it' in the bpstat structure. Under some circumstances we | |
2607 | may decide not to print anything here and delegate the task to | |
2608 | normal_stop(). */ | |
2609 | ||
2610 | static enum print_stop_action | |
2611 | print_bp_stop_message (bpstat bs) | |
2612 | { | |
2613 | switch (bs->print_it) | |
2614 | { | |
2615 | case print_it_noop: | |
2616 | /* Nothing should be printed for this bpstat entry. */ | |
2617 | return PRINT_UNKNOWN; | |
2618 | break; | |
2619 | ||
2620 | case print_it_done: | |
2621 | /* We still want to print the frame, but we already printed the | |
2622 | relevant messages. */ | |
2623 | return PRINT_SRC_AND_LOC; | |
2624 | break; | |
2625 | ||
2626 | case print_it_normal: | |
4f8d1dc6 | 2627 | { |
89f9893c | 2628 | const struct bp_location *bl = bs->breakpoint_at; |
4f8d1dc6 VP |
2629 | struct breakpoint *b = bl ? bl->owner : NULL; |
2630 | ||
2631 | /* Normal case. Call the breakpoint's print_it method, or | |
2632 | print_it_typical. */ | |
2633 | /* FIXME: how breakpoint can ever be NULL here? */ | |
2634 | if (b != NULL && b->ops != NULL && b->ops->print_it != NULL) | |
2635 | return b->ops->print_it (b); | |
2636 | else | |
2637 | return print_it_typical (bs); | |
2638 | } | |
2639 | break; | |
3086aeae | 2640 | |
e514a9d6 | 2641 | default: |
8e65ff28 | 2642 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 2643 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 2644 | break; |
c906108c | 2645 | } |
c906108c SS |
2646 | } |
2647 | ||
e514a9d6 JM |
2648 | /* Print a message indicating what happened. This is called from |
2649 | normal_stop(). The input to this routine is the head of the bpstat | |
2650 | list - a list of the eventpoints that caused this stop. This | |
2651 | routine calls the generic print routine for printing a message | |
2652 | about reasons for stopping. This will print (for example) the | |
2653 | "Breakpoint n," part of the output. The return value of this | |
2654 | routine is one of: | |
c906108c | 2655 | |
917317f4 JM |
2656 | PRINT_UNKNOWN: Means we printed nothing |
2657 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent | |
c5aa993b JM |
2658 | code to print the location. An example is |
2659 | "Breakpoint 1, " which should be followed by | |
2660 | the location. | |
917317f4 | 2661 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
2662 | to also print the location part of the message. |
2663 | An example is the catch/throw messages, which | |
917317f4 JM |
2664 | don't require a location appended to the end. |
2665 | PRINT_NOTHING: We have done some printing and we don't need any | |
2666 | further info to be printed.*/ | |
c906108c | 2667 | |
917317f4 | 2668 | enum print_stop_action |
fba45db2 | 2669 | bpstat_print (bpstat bs) |
c906108c SS |
2670 | { |
2671 | int val; | |
c5aa993b | 2672 | |
c906108c | 2673 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
2674 | (Currently all watchpoints go on the bpstat whether hit or not. |
2675 | That probably could (should) be changed, provided care is taken | |
c906108c | 2676 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
2677 | for (; bs; bs = bs->next) |
2678 | { | |
2679 | val = print_bp_stop_message (bs); | |
2680 | if (val == PRINT_SRC_ONLY | |
2681 | || val == PRINT_SRC_AND_LOC | |
2682 | || val == PRINT_NOTHING) | |
2683 | return val; | |
2684 | } | |
c906108c | 2685 | |
e514a9d6 JM |
2686 | /* We reached the end of the chain, or we got a null BS to start |
2687 | with and nothing was printed. */ | |
917317f4 | 2688 | return PRINT_UNKNOWN; |
c906108c SS |
2689 | } |
2690 | ||
2691 | /* Evaluate the expression EXP and return 1 if value is zero. | |
2692 | This is used inside a catch_errors to evaluate the breakpoint condition. | |
2693 | The argument is a "struct expression *" that has been cast to char * to | |
2694 | make it pass through catch_errors. */ | |
2695 | ||
2696 | static int | |
4efb68b1 | 2697 | breakpoint_cond_eval (void *exp) |
c906108c | 2698 | { |
278cd55f | 2699 | struct value *mark = value_mark (); |
c5aa993b | 2700 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
c906108c SS |
2701 | value_free_to_mark (mark); |
2702 | return i; | |
2703 | } | |
2704 | ||
2705 | /* Allocate a new bpstat and chain it to the current one. */ | |
2706 | ||
2707 | static bpstat | |
89f9893c | 2708 | bpstat_alloc (const struct bp_location *bl, bpstat cbs /* Current "bs" value */ ) |
c906108c SS |
2709 | { |
2710 | bpstat bs; | |
2711 | ||
2712 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
2713 | cbs->next = bs; | |
4f8d1dc6 | 2714 | bs->breakpoint_at = bl; |
c906108c SS |
2715 | /* If the condition is false, etc., don't do the commands. */ |
2716 | bs->commands = NULL; | |
2717 | bs->old_val = NULL; | |
2718 | bs->print_it = print_it_normal; | |
2719 | return bs; | |
2720 | } | |
2721 | \f | |
d983da9c DJ |
2722 | /* The target has stopped with waitstatus WS. Check if any hardware |
2723 | watchpoints have triggered, according to the target. */ | |
2724 | ||
2725 | int | |
2726 | watchpoints_triggered (struct target_waitstatus *ws) | |
2727 | { | |
d92524f1 | 2728 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
2729 | CORE_ADDR addr; |
2730 | struct breakpoint *b; | |
2731 | ||
2732 | if (!stopped_by_watchpoint) | |
2733 | { | |
2734 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
2735 | as not triggered. */ | |
2736 | ALL_BREAKPOINTS (b) | |
2737 | if (b->type == bp_hardware_watchpoint | |
2738 | || b->type == bp_read_watchpoint | |
2739 | || b->type == bp_access_watchpoint) | |
2740 | b->watchpoint_triggered = watch_triggered_no; | |
2741 | ||
2742 | return 0; | |
2743 | } | |
2744 | ||
2745 | if (!target_stopped_data_address (¤t_target, &addr)) | |
2746 | { | |
2747 | /* We were stopped by a watchpoint, but we don't know where. | |
2748 | Mark all watchpoints as unknown. */ | |
2749 | ALL_BREAKPOINTS (b) | |
2750 | if (b->type == bp_hardware_watchpoint | |
2751 | || b->type == bp_read_watchpoint | |
2752 | || b->type == bp_access_watchpoint) | |
2753 | b->watchpoint_triggered = watch_triggered_unknown; | |
2754 | ||
2755 | return stopped_by_watchpoint; | |
2756 | } | |
2757 | ||
2758 | /* The target could report the data address. Mark watchpoints | |
2759 | affected by this data address as triggered, and all others as not | |
2760 | triggered. */ | |
2761 | ||
2762 | ALL_BREAKPOINTS (b) | |
2763 | if (b->type == bp_hardware_watchpoint | |
2764 | || b->type == bp_read_watchpoint | |
2765 | || b->type == bp_access_watchpoint) | |
2766 | { | |
a5606eee | 2767 | struct bp_location *loc; |
d983da9c DJ |
2768 | struct value *v; |
2769 | ||
2770 | b->watchpoint_triggered = watch_triggered_no; | |
a5606eee VP |
2771 | for (loc = b->loc; loc; loc = loc->next) |
2772 | /* Exact match not required. Within range is | |
2773 | sufficient. */ | |
5009afc5 AS |
2774 | if (target_watchpoint_addr_within_range (¤t_target, |
2775 | addr, loc->address, | |
2776 | loc->length)) | |
a5606eee VP |
2777 | { |
2778 | b->watchpoint_triggered = watch_triggered_yes; | |
2779 | break; | |
2780 | } | |
d983da9c DJ |
2781 | } |
2782 | ||
2783 | return 1; | |
2784 | } | |
2785 | ||
c906108c SS |
2786 | /* Possible return values for watchpoint_check (this can't be an enum |
2787 | because of check_errors). */ | |
2788 | /* The watchpoint has been deleted. */ | |
2789 | #define WP_DELETED 1 | |
2790 | /* The value has changed. */ | |
2791 | #define WP_VALUE_CHANGED 2 | |
2792 | /* The value has not changed. */ | |
2793 | #define WP_VALUE_NOT_CHANGED 3 | |
2794 | ||
2795 | #define BP_TEMPFLAG 1 | |
2796 | #define BP_HARDWAREFLAG 2 | |
2797 | ||
2798 | /* Check watchpoint condition. */ | |
2799 | ||
2800 | static int | |
4efb68b1 | 2801 | watchpoint_check (void *p) |
c906108c SS |
2802 | { |
2803 | bpstat bs = (bpstat) p; | |
2804 | struct breakpoint *b; | |
2805 | struct frame_info *fr; | |
2806 | int within_current_scope; | |
2807 | ||
4f8d1dc6 | 2808 | b = bs->breakpoint_at->owner; |
c906108c SS |
2809 | |
2810 | if (b->exp_valid_block == NULL) | |
2811 | within_current_scope = 1; | |
2812 | else | |
2813 | { | |
edb3359d DJ |
2814 | struct frame_info *frame = get_current_frame (); |
2815 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
2816 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
2817 | ||
101dcfbe | 2818 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 2819 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
2820 | |
2821 | /* If we've gotten confused in the unwinder, we might have | |
2822 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
2823 | if (within_current_scope) |
2824 | { | |
2825 | struct symbol *function; | |
2826 | ||
2827 | function = get_frame_function (fr); | |
2828 | if (function == NULL | |
2829 | || !contained_in (b->exp_valid_block, | |
2830 | SYMBOL_BLOCK_VALUE (function))) | |
2831 | within_current_scope = 0; | |
2832 | } | |
69fbadd5 | 2833 | |
c12260ac CV |
2834 | /* in_function_epilogue_p() returns a non-zero value if we're still |
2835 | in the function but the stack frame has already been invalidated. | |
2836 | Since we can't rely on the values of local variables after the | |
2837 | stack has been destroyed, we are treating the watchpoint in that | |
edb3359d DJ |
2838 | state as `not changed' without further checking. Don't mark |
2839 | watchpoints as changed if the current frame is in an epilogue - | |
2840 | even if they are in some other frame, our view of the stack | |
2841 | is likely to be wrong. */ | |
2842 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) | |
2843 | return WP_VALUE_NOT_CHANGED; | |
fb14de7b | 2844 | |
edb3359d | 2845 | if (within_current_scope) |
c906108c SS |
2846 | /* If we end up stopping, the current frame will get selected |
2847 | in normal_stop. So this call to select_frame won't affect | |
2848 | the user. */ | |
0f7d239c | 2849 | select_frame (fr); |
c906108c | 2850 | } |
c5aa993b | 2851 | |
c906108c SS |
2852 | if (within_current_scope) |
2853 | { | |
2854 | /* We use value_{,free_to_}mark because it could be a | |
2855 | *long* time before we return to the command level and | |
c5aa993b JM |
2856 | call free_all_values. We can't call free_all_values because |
2857 | we might be in the middle of evaluating a function call. */ | |
c906108c | 2858 | |
278cd55f | 2859 | struct value *mark = value_mark (); |
fa4727a6 DJ |
2860 | struct value *new_val; |
2861 | ||
2862 | fetch_watchpoint_value (b->exp, &new_val, NULL, NULL); | |
2863 | if ((b->val != NULL) != (new_val != NULL) | |
2864 | || (b->val != NULL && !value_equal (b->val, new_val))) | |
c906108c | 2865 | { |
fa4727a6 DJ |
2866 | if (new_val != NULL) |
2867 | { | |
2868 | release_value (new_val); | |
2869 | value_free_to_mark (mark); | |
2870 | } | |
c906108c SS |
2871 | bs->old_val = b->val; |
2872 | b->val = new_val; | |
fa4727a6 | 2873 | b->val_valid = 1; |
c906108c SS |
2874 | /* We will stop here */ |
2875 | return WP_VALUE_CHANGED; | |
2876 | } | |
2877 | else | |
2878 | { | |
2879 | /* Nothing changed, don't do anything. */ | |
2880 | value_free_to_mark (mark); | |
2881 | /* We won't stop here */ | |
2882 | return WP_VALUE_NOT_CHANGED; | |
2883 | } | |
2884 | } | |
2885 | else | |
2886 | { | |
2887 | /* This seems like the only logical thing to do because | |
c5aa993b JM |
2888 | if we temporarily ignored the watchpoint, then when |
2889 | we reenter the block in which it is valid it contains | |
2890 | garbage (in the case of a function, it may have two | |
2891 | garbage values, one before and one after the prologue). | |
2892 | So we can't even detect the first assignment to it and | |
2893 | watch after that (since the garbage may or may not equal | |
2894 | the first value assigned). */ | |
4ce44c66 JM |
2895 | /* We print all the stop information in print_it_typical(), but |
2896 | in this case, by the time we call print_it_typical() this bp | |
2897 | will be deleted already. So we have no choice but print the | |
2898 | information here. */ | |
9dc5e2a9 | 2899 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
2900 | ui_out_field_string |
2901 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
8b93c638 | 2902 | ui_out_text (uiout, "\nWatchpoint "); |
4f8d1dc6 | 2903 | ui_out_field_int (uiout, "wpnum", b->number); |
8b93c638 JM |
2904 | ui_out_text (uiout, " deleted because the program has left the block in\n\ |
2905 | which its expression is valid.\n"); | |
4ce44c66 | 2906 | |
c906108c | 2907 | if (b->related_breakpoint) |
b5de0fa7 EZ |
2908 | b->related_breakpoint->disposition = disp_del_at_next_stop; |
2909 | b->disposition = disp_del_at_next_stop; | |
c906108c SS |
2910 | |
2911 | return WP_DELETED; | |
2912 | } | |
2913 | } | |
2914 | ||
18a18393 VP |
2915 | /* Return true if it looks like target has stopped due to hitting |
2916 | breakpoint location BL. This function does not check if we | |
2917 | should stop, only if BL explains the stop. */ | |
2918 | static int | |
2919 | bpstat_check_location (const struct bp_location *bl, CORE_ADDR bp_addr) | |
2920 | { | |
2921 | struct breakpoint *b = bl->owner; | |
2922 | ||
2923 | if (b->type != bp_watchpoint | |
2924 | && b->type != bp_hardware_watchpoint | |
2925 | && b->type != bp_read_watchpoint | |
2926 | && b->type != bp_access_watchpoint | |
2927 | && b->type != bp_hardware_breakpoint | |
fe798b75 | 2928 | && b->type != bp_catchpoint) /* a non-watchpoint bp */ |
18a18393 VP |
2929 | { |
2930 | if (bl->address != bp_addr) /* address doesn't match */ | |
2931 | return 0; | |
2932 | if (overlay_debugging /* unmapped overlay section */ | |
2933 | && section_is_overlay (bl->section) | |
2934 | && !section_is_mapped (bl->section)) | |
2935 | return 0; | |
2936 | } | |
2937 | ||
2938 | /* Continuable hardware watchpoints are treated as non-existent if the | |
2939 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
2940 | some data address). Otherwise gdb won't stop on a break instruction | |
2941 | in the code (not from a breakpoint) when a hardware watchpoint has | |
2942 | been defined. Also skip watchpoints which we know did not trigger | |
2943 | (did not match the data address). */ | |
2944 | ||
2945 | if ((b->type == bp_hardware_watchpoint | |
2946 | || b->type == bp_read_watchpoint | |
2947 | || b->type == bp_access_watchpoint) | |
2948 | && b->watchpoint_triggered == watch_triggered_no) | |
2949 | return 0; | |
2950 | ||
2951 | if (b->type == bp_hardware_breakpoint) | |
2952 | { | |
2953 | if (bl->address != bp_addr) | |
2954 | return 0; | |
2955 | if (overlay_debugging /* unmapped overlay section */ | |
2956 | && section_is_overlay (bl->section) | |
2957 | && !section_is_mapped (bl->section)) | |
2958 | return 0; | |
2959 | } | |
ce78b96d | 2960 | |
ce78b96d JB |
2961 | if (b->type == bp_catchpoint) |
2962 | { | |
2963 | gdb_assert (b->ops != NULL && b->ops->breakpoint_hit != NULL); | |
2964 | if (!b->ops->breakpoint_hit (b)) | |
2965 | return 0; | |
2966 | } | |
2967 | ||
18a18393 VP |
2968 | return 1; |
2969 | } | |
2970 | ||
2971 | /* If BS refers to a watchpoint, determine if the watched values | |
2972 | has actually changed, and we should stop. If not, set BS->stop | |
2973 | to 0. */ | |
2974 | static void | |
2975 | bpstat_check_watchpoint (bpstat bs) | |
2976 | { | |
2977 | const struct bp_location *bl = bs->breakpoint_at; | |
2978 | struct breakpoint *b = bl->owner; | |
2979 | ||
2980 | if (b->type == bp_watchpoint | |
2981 | || b->type == bp_read_watchpoint | |
2982 | || b->type == bp_access_watchpoint | |
2983 | || b->type == bp_hardware_watchpoint) | |
2984 | { | |
2985 | CORE_ADDR addr; | |
2986 | struct value *v; | |
2987 | int must_check_value = 0; | |
2988 | ||
2989 | if (b->type == bp_watchpoint) | |
2990 | /* For a software watchpoint, we must always check the | |
2991 | watched value. */ | |
2992 | must_check_value = 1; | |
2993 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
2994 | /* We have a hardware watchpoint (read, write, or access) | |
2995 | and the target earlier reported an address watched by | |
2996 | this watchpoint. */ | |
2997 | must_check_value = 1; | |
2998 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
2999 | && b->type == bp_hardware_watchpoint) | |
3000 | /* We were stopped by a hardware watchpoint, but the target could | |
3001 | not report the data address. We must check the watchpoint's | |
3002 | value. Access and read watchpoints are out of luck; without | |
3003 | a data address, we can't figure it out. */ | |
3004 | must_check_value = 1; | |
3005 | ||
3006 | if (must_check_value) | |
3007 | { | |
3008 | char *message = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
3009 | b->number); | |
3010 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
3011 | int e = catch_errors (watchpoint_check, bs, message, | |
3012 | RETURN_MASK_ALL); | |
3013 | do_cleanups (cleanups); | |
3014 | switch (e) | |
3015 | { | |
3016 | case WP_DELETED: | |
3017 | /* We've already printed what needs to be printed. */ | |
3018 | bs->print_it = print_it_done; | |
3019 | /* Stop. */ | |
3020 | break; | |
3021 | case WP_VALUE_CHANGED: | |
3022 | if (b->type == bp_read_watchpoint) | |
3023 | { | |
3024 | /* Don't stop: read watchpoints shouldn't fire if | |
3025 | the value has changed. This is for targets | |
3026 | which cannot set read-only watchpoints. */ | |
3027 | bs->print_it = print_it_noop; | |
3028 | bs->stop = 0; | |
3029 | } | |
3030 | break; | |
3031 | case WP_VALUE_NOT_CHANGED: | |
3032 | if (b->type == bp_hardware_watchpoint | |
3033 | || b->type == bp_watchpoint) | |
3034 | { | |
3035 | /* Don't stop: write watchpoints shouldn't fire if | |
3036 | the value hasn't changed. */ | |
3037 | bs->print_it = print_it_noop; | |
3038 | bs->stop = 0; | |
3039 | } | |
3040 | /* Stop. */ | |
3041 | break; | |
3042 | default: | |
3043 | /* Can't happen. */ | |
3044 | case 0: | |
3045 | /* Error from catch_errors. */ | |
3046 | printf_filtered (_("Watchpoint %d deleted.\n"), b->number); | |
3047 | if (b->related_breakpoint) | |
3048 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
3049 | b->disposition = disp_del_at_next_stop; | |
3050 | /* We've already printed what needs to be printed. */ | |
3051 | bs->print_it = print_it_done; | |
3052 | break; | |
3053 | } | |
3054 | } | |
3055 | else /* must_check_value == 0 */ | |
3056 | { | |
3057 | /* This is a case where some watchpoint(s) triggered, but | |
3058 | not at the address of this watchpoint, or else no | |
3059 | watchpoint triggered after all. So don't print | |
3060 | anything for this watchpoint. */ | |
3061 | bs->print_it = print_it_noop; | |
3062 | bs->stop = 0; | |
3063 | } | |
3064 | } | |
3065 | } | |
3066 | ||
3067 | ||
3068 | /* Check conditions (condition proper, frame, thread and ignore count) | |
3069 | of breakpoint referred to by BS. If we should not stop for this | |
3070 | breakpoint, set BS->stop to 0. */ | |
3071 | static void | |
3072 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
3073 | { | |
3074 | int thread_id = pid_to_thread_id (ptid); | |
3075 | const struct bp_location *bl = bs->breakpoint_at; | |
3076 | struct breakpoint *b = bl->owner; | |
3077 | ||
3078 | if (frame_id_p (b->frame_id) | |
edb3359d | 3079 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 VP |
3080 | bs->stop = 0; |
3081 | else if (bs->stop) | |
3082 | { | |
3083 | int value_is_zero = 0; | |
3084 | ||
3085 | /* If this is a scope breakpoint, mark the associated | |
3086 | watchpoint as triggered so that we will handle the | |
3087 | out-of-scope event. We'll get to the watchpoint next | |
3088 | iteration. */ | |
3089 | if (b->type == bp_watchpoint_scope) | |
3090 | b->related_breakpoint->watchpoint_triggered = watch_triggered_yes; | |
3091 | ||
3092 | if (bl->cond && bl->owner->disposition != disp_del_at_next_stop) | |
3093 | { | |
c5bc3a77 DJ |
3094 | /* We use value_mark and value_free_to_mark because it could |
3095 | be a long time before we return to the command level and | |
3096 | call free_all_values. We can't call free_all_values | |
3097 | because we might be in the middle of evaluating a | |
3098 | function call. */ | |
3099 | struct value *mark = value_mark (); | |
3100 | ||
edb3359d DJ |
3101 | /* Need to select the frame, with all that implies so that |
3102 | the conditions will have the right context. Because we | |
3103 | use the frame, we will not see an inlined function's | |
3104 | variables when we arrive at a breakpoint at the start | |
3105 | of the inlined function; the current frame will be the | |
3106 | call site. */ | |
18a18393 VP |
3107 | select_frame (get_current_frame ()); |
3108 | value_is_zero | |
3109 | = catch_errors (breakpoint_cond_eval, (bl->cond), | |
3110 | "Error in testing breakpoint condition:\n", | |
3111 | RETURN_MASK_ALL); | |
3112 | /* FIXME-someday, should give breakpoint # */ | |
c5bc3a77 | 3113 | value_free_to_mark (mark); |
18a18393 VP |
3114 | } |
3115 | if (bl->cond && value_is_zero) | |
3116 | { | |
3117 | bs->stop = 0; | |
3118 | } | |
3119 | else if (b->thread != -1 && b->thread != thread_id) | |
3120 | { | |
3121 | bs->stop = 0; | |
3122 | } | |
3123 | else if (b->ignore_count > 0) | |
3124 | { | |
3125 | b->ignore_count--; | |
3126 | annotate_ignore_count_change (); | |
3127 | bs->stop = 0; | |
3128 | /* Increase the hit count even though we don't | |
3129 | stop. */ | |
3130 | ++(b->hit_count); | |
3131 | } | |
3132 | } | |
3133 | } | |
3134 | ||
3135 | ||
9709f61c | 3136 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 3137 | BP_ADDR in thread PTID. |
c906108c | 3138 | |
d983da9c | 3139 | Determine whether we stopped at a breakpoint, etc, or whether we |
c906108c SS |
3140 | don't understand this stop. Result is a chain of bpstat's such that: |
3141 | ||
c5aa993b | 3142 | if we don't understand the stop, the result is a null pointer. |
c906108c | 3143 | |
c5aa993b | 3144 | if we understand why we stopped, the result is not null. |
c906108c | 3145 | |
c5aa993b JM |
3146 | Each element of the chain refers to a particular breakpoint or |
3147 | watchpoint at which we have stopped. (We may have stopped for | |
3148 | several reasons concurrently.) | |
c906108c | 3149 | |
c5aa993b JM |
3150 | Each element of the chain has valid next, breakpoint_at, |
3151 | commands, FIXME??? fields. */ | |
c906108c SS |
3152 | |
3153 | bpstat | |
d983da9c | 3154 | bpstat_stop_status (CORE_ADDR bp_addr, ptid_t ptid) |
c906108c | 3155 | { |
0d381245 | 3156 | struct breakpoint *b = NULL; |
89f9893c | 3157 | const struct bp_location *bl; |
20874c92 | 3158 | struct bp_location *loc; |
c906108c SS |
3159 | /* Root of the chain of bpstat's */ |
3160 | struct bpstats root_bs[1]; | |
3161 | /* Pointer to the last thing in the chain currently. */ | |
3162 | bpstat bs = root_bs; | |
20874c92 | 3163 | int ix; |
d832cb68 | 3164 | int need_remove_insert; |
c906108c | 3165 | |
0d381245 | 3166 | ALL_BP_LOCATIONS (bl) |
c5aa993b | 3167 | { |
0d381245 VP |
3168 | b = bl->owner; |
3169 | gdb_assert (b); | |
468d015d | 3170 | if (!breakpoint_enabled (b) && b->enable_state != bp_permanent) |
c5aa993b JM |
3171 | continue; |
3172 | ||
a5606eee VP |
3173 | /* For hardware watchpoints, we look only at the first location. |
3174 | The watchpoint_check function will work on entire expression, | |
3175 | not the individual locations. For read watchopints, the | |
3176 | watchpoints_triggered function have checked all locations | |
3177 | alrea | |
3178 | */ | |
3179 | if (b->type == bp_hardware_watchpoint && bl != b->loc) | |
3180 | continue; | |
3181 | ||
18a18393 VP |
3182 | if (!bpstat_check_location (bl, bp_addr)) |
3183 | continue; | |
3184 | ||
c5aa993b JM |
3185 | /* Come here if it's a watchpoint, or if the break address matches */ |
3186 | ||
0d381245 | 3187 | bs = bpstat_alloc (bl, bs); /* Alloc a bpstat to explain stop */ |
c5aa993b | 3188 | |
18a18393 VP |
3189 | /* Assume we stop. Should we find watchpoint that is not actually |
3190 | triggered, or if condition of breakpoint is false, we'll reset | |
3191 | 'stop' to 0. */ | |
c5aa993b JM |
3192 | bs->stop = 1; |
3193 | bs->print = 1; | |
3194 | ||
18a18393 VP |
3195 | bpstat_check_watchpoint (bs); |
3196 | if (!bs->stop) | |
3197 | continue; | |
c5aa993b | 3198 | |
0fd8e87f UW |
3199 | if (b->type == bp_thread_event || b->type == bp_overlay_event |
3200 | || b->type == bp_longjmp_master) | |
18a18393 | 3201 | /* We do not stop for these. */ |
c5aa993b JM |
3202 | bs->stop = 0; |
3203 | else | |
18a18393 VP |
3204 | bpstat_check_breakpoint_conditions (bs, ptid); |
3205 | ||
3206 | if (bs->stop) | |
c5aa993b | 3207 | { |
18a18393 | 3208 | ++(b->hit_count); |
d983da9c | 3209 | |
18a18393 VP |
3210 | /* We will stop here */ |
3211 | if (b->disposition == disp_disable) | |
c5aa993b | 3212 | { |
514f746b AR |
3213 | if (b->enable_state != bp_permanent) |
3214 | b->enable_state = bp_disabled; | |
b60e7edf | 3215 | update_global_location_list (0); |
c5aa993b | 3216 | } |
18a18393 VP |
3217 | if (b->silent) |
3218 | bs->print = 0; | |
3219 | bs->commands = b->commands; | |
059fb39f PM |
3220 | if (bs->commands |
3221 | && (strcmp ("silent", bs->commands->line) == 0 | |
3222 | || (xdb_commands && strcmp ("Q", bs->commands->line) == 0))) | |
c5aa993b | 3223 | { |
18a18393 VP |
3224 | bs->commands = bs->commands->next; |
3225 | bs->print = 0; | |
c5aa993b | 3226 | } |
18a18393 | 3227 | bs->commands = copy_command_lines (bs->commands); |
c5aa993b | 3228 | } |
18a18393 | 3229 | |
c5aa993b JM |
3230 | /* Print nothing for this entry if we dont stop or if we dont print. */ |
3231 | if (bs->stop == 0 || bs->print == 0) | |
3232 | bs->print_it = print_it_noop; | |
3233 | } | |
c906108c | 3234 | |
20874c92 VP |
3235 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) |
3236 | { | |
3237 | if (loc->address == bp_addr) | |
3238 | { | |
3239 | bs = bpstat_alloc (loc, bs); | |
3240 | /* For hits of moribund locations, we should just proceed. */ | |
3241 | bs->stop = 0; | |
3242 | bs->print = 0; | |
3243 | bs->print_it = print_it_noop; | |
3244 | } | |
3245 | } | |
3246 | ||
c906108c SS |
3247 | bs->next = NULL; /* Terminate the chain */ |
3248 | bs = root_bs->next; /* Re-grab the head of the chain */ | |
3249 | ||
d983da9c DJ |
3250 | /* If we aren't stopping, the value of some hardware watchpoint may |
3251 | not have changed, but the intermediate memory locations we are | |
3252 | watching may have. Don't bother if we're stopping; this will get | |
3253 | done later. */ | |
3254 | for (bs = root_bs->next; bs != NULL; bs = bs->next) | |
3255 | if (bs->stop) | |
3256 | break; | |
3257 | ||
d832cb68 | 3258 | need_remove_insert = 0; |
d983da9c DJ |
3259 | if (bs == NULL) |
3260 | for (bs = root_bs->next; bs != NULL; bs = bs->next) | |
3261 | if (!bs->stop | |
20874c92 | 3262 | && bs->breakpoint_at->owner |
d983da9c DJ |
3263 | && (bs->breakpoint_at->owner->type == bp_hardware_watchpoint |
3264 | || bs->breakpoint_at->owner->type == bp_read_watchpoint | |
3265 | || bs->breakpoint_at->owner->type == bp_access_watchpoint)) | |
3266 | { | |
a5606eee VP |
3267 | /* remove/insert can invalidate bs->breakpoint_at, if this |
3268 | location is no longer used by the watchpoint. Prevent | |
3269 | further code from trying to use it. */ | |
3270 | bs->breakpoint_at = NULL; | |
d832cb68 | 3271 | need_remove_insert = 1; |
d983da9c DJ |
3272 | } |
3273 | ||
d832cb68 DD |
3274 | if (need_remove_insert) |
3275 | { | |
3276 | remove_breakpoints (); | |
3277 | insert_breakpoints (); | |
3278 | } | |
3279 | ||
d983da9c | 3280 | return root_bs->next; |
c906108c SS |
3281 | } |
3282 | \f | |
3283 | /* Tell what to do about this bpstat. */ | |
3284 | struct bpstat_what | |
fba45db2 | 3285 | bpstat_what (bpstat bs) |
c906108c SS |
3286 | { |
3287 | /* Classify each bpstat as one of the following. */ | |
c5aa993b JM |
3288 | enum class |
3289 | { | |
3290 | /* This bpstat element has no effect on the main_action. */ | |
3291 | no_effect = 0, | |
3292 | ||
3293 | /* There was a watchpoint, stop but don't print. */ | |
3294 | wp_silent, | |
c906108c | 3295 | |
c5aa993b JM |
3296 | /* There was a watchpoint, stop and print. */ |
3297 | wp_noisy, | |
c906108c | 3298 | |
c5aa993b JM |
3299 | /* There was a breakpoint but we're not stopping. */ |
3300 | bp_nostop, | |
c906108c | 3301 | |
c5aa993b JM |
3302 | /* There was a breakpoint, stop but don't print. */ |
3303 | bp_silent, | |
c906108c | 3304 | |
c5aa993b JM |
3305 | /* There was a breakpoint, stop and print. */ |
3306 | bp_noisy, | |
c906108c | 3307 | |
c5aa993b JM |
3308 | /* We hit the longjmp breakpoint. */ |
3309 | long_jump, | |
c906108c | 3310 | |
c5aa993b JM |
3311 | /* We hit the longjmp_resume breakpoint. */ |
3312 | long_resume, | |
c906108c | 3313 | |
c5aa993b JM |
3314 | /* We hit the step_resume breakpoint. */ |
3315 | step_resume, | |
c906108c | 3316 | |
c5aa993b JM |
3317 | /* We hit the shared library event breakpoint. */ |
3318 | shlib_event, | |
c906108c | 3319 | |
4efc6507 DE |
3320 | /* We hit the jit event breakpoint. */ |
3321 | jit_event, | |
3322 | ||
c5aa993b JM |
3323 | /* This is just used to count how many enums there are. */ |
3324 | class_last | |
c906108c SS |
3325 | }; |
3326 | ||
3327 | /* Here is the table which drives this routine. So that we can | |
3328 | format it pretty, we define some abbreviations for the | |
3329 | enum bpstat_what codes. */ | |
3330 | #define kc BPSTAT_WHAT_KEEP_CHECKING | |
3331 | #define ss BPSTAT_WHAT_STOP_SILENT | |
3332 | #define sn BPSTAT_WHAT_STOP_NOISY | |
3333 | #define sgl BPSTAT_WHAT_SINGLE | |
3334 | #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME | |
3335 | #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME | |
c906108c | 3336 | #define sr BPSTAT_WHAT_STEP_RESUME |
c906108c | 3337 | #define shl BPSTAT_WHAT_CHECK_SHLIBS |
4efc6507 | 3338 | #define jit BPSTAT_WHAT_CHECK_JIT |
c906108c SS |
3339 | |
3340 | /* "Can't happen." Might want to print an error message. | |
3341 | abort() is not out of the question, but chances are GDB is just | |
3342 | a bit confused, not unusable. */ | |
3343 | #define err BPSTAT_WHAT_STOP_NOISY | |
3344 | ||
3345 | /* Given an old action and a class, come up with a new action. */ | |
3346 | /* One interesting property of this table is that wp_silent is the same | |
3347 | as bp_silent and wp_noisy is the same as bp_noisy. That is because | |
3348 | after stopping, the check for whether to step over a breakpoint | |
3349 | (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without | |
53a5351d JM |
3350 | reference to how we stopped. We retain separate wp_silent and |
3351 | bp_silent codes in case we want to change that someday. | |
43ff13b4 JM |
3352 | |
3353 | Another possibly interesting property of this table is that | |
3354 | there's a partial ordering, priority-like, of the actions. Once | |
3355 | you've decided that some action is appropriate, you'll never go | |
3356 | back and decide something of a lower priority is better. The | |
3357 | ordering is: | |
3358 | ||
4efc6507 DE |
3359 | kc < jit clr sgl shl slr sn sr ss |
3360 | sgl < jit shl slr sn sr ss | |
3361 | slr < jit err shl sn sr ss | |
3362 | clr < jit err shl sn sr ss | |
3363 | ss < jit shl sn sr | |
3364 | sn < jit shl sr | |
3365 | jit < shl sr | |
d81191fc | 3366 | shl < sr |
4d5b2cd7 | 3367 | sr < |
c5aa993b | 3368 | |
43ff13b4 JM |
3369 | What I think this means is that we don't need a damned table |
3370 | here. If you just put the rows and columns in the right order, | |
3371 | it'd look awfully regular. We could simply walk the bpstat list | |
3372 | and choose the highest priority action we find, with a little | |
78b6a731 | 3373 | logic to handle the 'err' cases. */ |
c906108c SS |
3374 | |
3375 | /* step_resume entries: a step resume breakpoint overrides another | |
3376 | breakpoint of signal handling (see comment in wait_for_inferior | |
fcf70625 | 3377 | at where we set the step_resume breakpoint). */ |
c906108c SS |
3378 | |
3379 | static const enum bpstat_what_main_action | |
c5aa993b JM |
3380 | table[(int) class_last][(int) BPSTAT_WHAT_LAST] = |
3381 | { | |
3382 | /* old action */ | |
4efc6507 DE |
3383 | /* kc ss sn sgl slr clr sr shl jit */ |
3384 | /* no_effect */ {kc, ss, sn, sgl, slr, clr, sr, shl, jit}, | |
3385 | /* wp_silent */ {ss, ss, sn, ss, ss, ss, sr, shl, jit}, | |
3386 | /* wp_noisy */ {sn, sn, sn, sn, sn, sn, sr, shl, jit}, | |
3387 | /* bp_nostop */ {sgl, ss, sn, sgl, slr, slr, sr, shl, jit}, | |
3388 | /* bp_silent */ {ss, ss, sn, ss, ss, ss, sr, shl, jit}, | |
3389 | /* bp_noisy */ {sn, sn, sn, sn, sn, sn, sr, shl, jit}, | |
3390 | /* long_jump */ {slr, ss, sn, slr, slr, err, sr, shl, jit}, | |
3391 | /* long_resume */ {clr, ss, sn, err, err, err, sr, shl, jit}, | |
3392 | /* step_resume */ {sr, sr, sr, sr, sr, sr, sr, sr, sr }, | |
3393 | /* shlib */ {shl, shl, shl, shl, shl, shl, sr, shl, shl}, | |
3394 | /* jit_event */ {jit, jit, jit, jit, jit, jit, sr, jit, jit} | |
c5aa993b | 3395 | }; |
c906108c SS |
3396 | |
3397 | #undef kc | |
3398 | #undef ss | |
3399 | #undef sn | |
3400 | #undef sgl | |
3401 | #undef slr | |
3402 | #undef clr | |
c906108c SS |
3403 | #undef err |
3404 | #undef sr | |
3405 | #undef ts | |
3406 | #undef shl | |
4efc6507 | 3407 | #undef jit |
c906108c SS |
3408 | enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING; |
3409 | struct bpstat_what retval; | |
3410 | ||
3411 | retval.call_dummy = 0; | |
3412 | for (; bs != NULL; bs = bs->next) | |
3413 | { | |
3414 | enum class bs_class = no_effect; | |
3415 | if (bs->breakpoint_at == NULL) | |
3416 | /* I suspect this can happen if it was a momentary breakpoint | |
3417 | which has since been deleted. */ | |
3418 | continue; | |
20874c92 VP |
3419 | if (bs->breakpoint_at->owner == NULL) |
3420 | bs_class = bp_nostop; | |
3421 | else | |
4f8d1dc6 | 3422 | switch (bs->breakpoint_at->owner->type) |
c906108c SS |
3423 | { |
3424 | case bp_none: | |
3425 | continue; | |
3426 | ||
3427 | case bp_breakpoint: | |
3428 | case bp_hardware_breakpoint: | |
3429 | case bp_until: | |
3430 | case bp_finish: | |
3431 | if (bs->stop) | |
3432 | { | |
3433 | if (bs->print) | |
3434 | bs_class = bp_noisy; | |
3435 | else | |
3436 | bs_class = bp_silent; | |
3437 | } | |
3438 | else | |
3439 | bs_class = bp_nostop; | |
3440 | break; | |
3441 | case bp_watchpoint: | |
3442 | case bp_hardware_watchpoint: | |
3443 | case bp_read_watchpoint: | |
3444 | case bp_access_watchpoint: | |
3445 | if (bs->stop) | |
3446 | { | |
3447 | if (bs->print) | |
3448 | bs_class = wp_noisy; | |
3449 | else | |
3450 | bs_class = wp_silent; | |
3451 | } | |
3452 | else | |
53a5351d JM |
3453 | /* There was a watchpoint, but we're not stopping. |
3454 | This requires no further action. */ | |
c906108c SS |
3455 | bs_class = no_effect; |
3456 | break; | |
3457 | case bp_longjmp: | |
3458 | bs_class = long_jump; | |
3459 | break; | |
3460 | case bp_longjmp_resume: | |
3461 | bs_class = long_resume; | |
3462 | break; | |
3463 | case bp_step_resume: | |
3464 | if (bs->stop) | |
3465 | { | |
3466 | bs_class = step_resume; | |
3467 | } | |
3468 | else | |
3469 | /* It is for the wrong frame. */ | |
3470 | bs_class = bp_nostop; | |
3471 | break; | |
c906108c SS |
3472 | case bp_watchpoint_scope: |
3473 | bs_class = bp_nostop; | |
3474 | break; | |
c5aa993b JM |
3475 | case bp_shlib_event: |
3476 | bs_class = shlib_event; | |
3477 | break; | |
4efc6507 DE |
3478 | case bp_jit_event: |
3479 | bs_class = jit_event; | |
3480 | break; | |
c4093a6a | 3481 | case bp_thread_event: |
1900040c | 3482 | case bp_overlay_event: |
0fd8e87f | 3483 | case bp_longjmp_master: |
c4093a6a JM |
3484 | bs_class = bp_nostop; |
3485 | break; | |
ce78b96d | 3486 | case bp_catchpoint: |
c5aa993b JM |
3487 | if (bs->stop) |
3488 | { | |
3489 | if (bs->print) | |
3490 | bs_class = bp_noisy; | |
3491 | else | |
3492 | bs_class = bp_silent; | |
3493 | } | |
3494 | else | |
53a5351d JM |
3495 | /* There was a catchpoint, but we're not stopping. |
3496 | This requires no further action. */ | |
c5aa993b JM |
3497 | bs_class = no_effect; |
3498 | break; | |
c906108c | 3499 | case bp_call_dummy: |
53a5351d JM |
3500 | /* Make sure the action is stop (silent or noisy), |
3501 | so infrun.c pops the dummy frame. */ | |
c906108c SS |
3502 | bs_class = bp_silent; |
3503 | retval.call_dummy = 1; | |
3504 | break; | |
1042e4c0 SS |
3505 | case bp_tracepoint: |
3506 | /* Tracepoint hits should not be reported back to GDB, and | |
3507 | if one got through somehow, it should have been filtered | |
3508 | out already. */ | |
3509 | internal_error (__FILE__, __LINE__, | |
3510 | _("bpstat_what: bp_tracepoint encountered")); | |
3511 | break; | |
c906108c | 3512 | } |
c5aa993b | 3513 | current_action = table[(int) bs_class][(int) current_action]; |
c906108c SS |
3514 | } |
3515 | retval.main_action = current_action; | |
3516 | return retval; | |
3517 | } | |
3518 | ||
3519 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
3520 | without hardware support). This isn't related to a specific bpstat, | |
3521 | just to things like whether watchpoints are set. */ | |
3522 | ||
c5aa993b | 3523 | int |
fba45db2 | 3524 | bpstat_should_step (void) |
c906108c SS |
3525 | { |
3526 | struct breakpoint *b; | |
3527 | ALL_BREAKPOINTS (b) | |
717a8278 | 3528 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 3529 | return 1; |
c906108c SS |
3530 | return 0; |
3531 | } | |
3532 | ||
c906108c | 3533 | \f |
c5aa993b | 3534 | |
0d381245 VP |
3535 | static void print_breakpoint_location (struct breakpoint *b, |
3536 | struct bp_location *loc, | |
3537 | char *wrap_indent, | |
3538 | struct ui_stream *stb) | |
3539 | { | |
3540 | if (b->source_file) | |
3541 | { | |
3542 | struct symbol *sym | |
3543 | = find_pc_sect_function (loc->address, loc->section); | |
3544 | if (sym) | |
3545 | { | |
3546 | ui_out_text (uiout, "in "); | |
3547 | ui_out_field_string (uiout, "func", | |
3548 | SYMBOL_PRINT_NAME (sym)); | |
3549 | ui_out_wrap_hint (uiout, wrap_indent); | |
3550 | ui_out_text (uiout, " at "); | |
3551 | } | |
3552 | ui_out_field_string (uiout, "file", b->source_file); | |
3553 | ui_out_text (uiout, ":"); | |
3554 | ||
3555 | if (ui_out_is_mi_like_p (uiout)) | |
3556 | { | |
3557 | struct symtab_and_line sal = find_pc_line (loc->address, 0); | |
3558 | char *fullname = symtab_to_fullname (sal.symtab); | |
3559 | ||
3560 | if (fullname) | |
3561 | ui_out_field_string (uiout, "fullname", fullname); | |
3562 | } | |
3563 | ||
3564 | ui_out_field_int (uiout, "line", b->line_number); | |
3565 | } | |
3566 | else if (!b->loc) | |
3567 | { | |
3568 | ui_out_field_string (uiout, "pending", b->addr_string); | |
3569 | } | |
3570 | else | |
3571 | { | |
3572 | print_address_symbolic (loc->address, stb->stream, demangle, ""); | |
3573 | ui_out_field_stream (uiout, "at", stb); | |
3574 | } | |
3575 | } | |
3576 | ||
c4093a6a | 3577 | /* Print B to gdb_stdout. */ |
c906108c | 3578 | static void |
0d381245 VP |
3579 | print_one_breakpoint_location (struct breakpoint *b, |
3580 | struct bp_location *loc, | |
3581 | int loc_number, | |
a6d9a66e UW |
3582 | struct bp_location **last_loc, |
3583 | int print_address_bits) | |
c906108c | 3584 | { |
52f0bd74 AC |
3585 | struct command_line *l; |
3586 | struct symbol *sym; | |
c4093a6a JM |
3587 | struct ep_type_description |
3588 | { | |
3589 | enum bptype type; | |
3590 | char *description; | |
3591 | }; | |
3592 | static struct ep_type_description bptypes[] = | |
c906108c | 3593 | { |
c5aa993b JM |
3594 | {bp_none, "?deleted?"}, |
3595 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 3596 | {bp_hardware_breakpoint, "hw breakpoint"}, |
c5aa993b JM |
3597 | {bp_until, "until"}, |
3598 | {bp_finish, "finish"}, | |
3599 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 3600 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
3601 | {bp_read_watchpoint, "read watchpoint"}, |
3602 | {bp_access_watchpoint, "acc watchpoint"}, | |
3603 | {bp_longjmp, "longjmp"}, | |
3604 | {bp_longjmp_resume, "longjmp resume"}, | |
3605 | {bp_step_resume, "step resume"}, | |
c5aa993b JM |
3606 | {bp_watchpoint_scope, "watchpoint scope"}, |
3607 | {bp_call_dummy, "call dummy"}, | |
3608 | {bp_shlib_event, "shlib events"}, | |
c4093a6a | 3609 | {bp_thread_event, "thread events"}, |
1900040c | 3610 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 3611 | {bp_longjmp_master, "longjmp master"}, |
ce78b96d | 3612 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 3613 | {bp_tracepoint, "tracepoint"}, |
4efc6507 | 3614 | {bp_jit_event, "jit events"}, |
c5aa993b | 3615 | }; |
c4093a6a | 3616 | |
c2c6d25f | 3617 | static char bpenables[] = "nynny"; |
c906108c | 3618 | char wrap_indent[80]; |
8b93c638 JM |
3619 | struct ui_stream *stb = ui_out_stream_new (uiout); |
3620 | struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb); | |
3b31d625 | 3621 | struct cleanup *bkpt_chain; |
c906108c | 3622 | |
0d381245 VP |
3623 | int header_of_multiple = 0; |
3624 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
3625 | struct value_print_options opts; |
3626 | ||
3627 | get_user_print_options (&opts); | |
0d381245 VP |
3628 | |
3629 | gdb_assert (!loc || loc_number != 0); | |
3630 | /* See comment in print_one_breakpoint concerning | |
3631 | treatment of breakpoints with single disabled | |
3632 | location. */ | |
3633 | if (loc == NULL | |
3634 | && (b->loc != NULL | |
3635 | && (b->loc->next != NULL || !b->loc->enabled))) | |
3636 | header_of_multiple = 1; | |
3637 | if (loc == NULL) | |
3638 | loc = b->loc; | |
3639 | ||
c4093a6a | 3640 | annotate_record (); |
3b31d625 | 3641 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); |
c4093a6a JM |
3642 | |
3643 | /* 1 */ | |
3644 | annotate_field (0); | |
0d381245 VP |
3645 | if (part_of_multiple) |
3646 | { | |
3647 | char *formatted; | |
0c6773c1 | 3648 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
0d381245 VP |
3649 | ui_out_field_string (uiout, "number", formatted); |
3650 | xfree (formatted); | |
3651 | } | |
3652 | else | |
3653 | { | |
3654 | ui_out_field_int (uiout, "number", b->number); | |
3655 | } | |
c4093a6a JM |
3656 | |
3657 | /* 2 */ | |
3658 | annotate_field (1); | |
0d381245 VP |
3659 | if (part_of_multiple) |
3660 | ui_out_field_skip (uiout, "type"); | |
3661 | else | |
3662 | { | |
3663 | if (((int) b->type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
3664 | || ((int) b->type != bptypes[(int) b->type].type)) | |
3665 | internal_error (__FILE__, __LINE__, | |
3666 | _("bptypes table does not describe type #%d."), | |
3667 | (int) b->type); | |
3668 | ui_out_field_string (uiout, "type", bptypes[(int) b->type].description); | |
3669 | } | |
c4093a6a JM |
3670 | |
3671 | /* 3 */ | |
3672 | annotate_field (2); | |
0d381245 VP |
3673 | if (part_of_multiple) |
3674 | ui_out_field_skip (uiout, "disp"); | |
3675 | else | |
2cec12e5 | 3676 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
0d381245 | 3677 | |
c4093a6a JM |
3678 | |
3679 | /* 4 */ | |
3680 | annotate_field (3); | |
0d381245 | 3681 | if (part_of_multiple) |
54e52265 | 3682 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
0d381245 | 3683 | else |
54e52265 VP |
3684 | ui_out_field_fmt (uiout, "enabled", "%c", |
3685 | bpenables[(int) b->enable_state]); | |
3686 | ui_out_spaces (uiout, 2); | |
0d381245 | 3687 | |
c4093a6a JM |
3688 | |
3689 | /* 5 and 6 */ | |
3690 | strcpy (wrap_indent, " "); | |
79a45b7d | 3691 | if (opts.addressprint) |
75ac9d7b | 3692 | { |
a6d9a66e | 3693 | if (print_address_bits <= 32) |
75ac9d7b MS |
3694 | strcat (wrap_indent, " "); |
3695 | else | |
3696 | strcat (wrap_indent, " "); | |
3697 | } | |
c906108c | 3698 | |
3086aeae | 3699 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 VP |
3700 | { |
3701 | /* Although the print_one can possibly print | |
3702 | all locations, calling it here is not likely | |
3703 | to get any nice result. So, make sure there's | |
3704 | just one location. */ | |
3705 | gdb_assert (b->loc == NULL || b->loc->next == NULL); | |
a6d9a66e | 3706 | b->ops->print_one (b, last_loc); |
0d381245 | 3707 | } |
3086aeae DJ |
3708 | else |
3709 | switch (b->type) | |
3710 | { | |
3711 | case bp_none: | |
3712 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 3713 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 3714 | break; |
c906108c | 3715 | |
3086aeae DJ |
3716 | case bp_watchpoint: |
3717 | case bp_hardware_watchpoint: | |
3718 | case bp_read_watchpoint: | |
3719 | case bp_access_watchpoint: | |
3720 | /* Field 4, the address, is omitted (which makes the columns | |
3721 | not line up too nicely with the headers, but the effect | |
3722 | is relatively readable). */ | |
79a45b7d | 3723 | if (opts.addressprint) |
3086aeae DJ |
3724 | ui_out_field_skip (uiout, "addr"); |
3725 | annotate_field (5); | |
fa8a61dc | 3726 | ui_out_field_string (uiout, "what", b->exp_string); |
3086aeae DJ |
3727 | break; |
3728 | ||
3086aeae DJ |
3729 | case bp_breakpoint: |
3730 | case bp_hardware_breakpoint: | |
3731 | case bp_until: | |
3732 | case bp_finish: | |
3733 | case bp_longjmp: | |
3734 | case bp_longjmp_resume: | |
3735 | case bp_step_resume: | |
3086aeae DJ |
3736 | case bp_watchpoint_scope: |
3737 | case bp_call_dummy: | |
3738 | case bp_shlib_event: | |
3739 | case bp_thread_event: | |
3740 | case bp_overlay_event: | |
0fd8e87f | 3741 | case bp_longjmp_master: |
1042e4c0 | 3742 | case bp_tracepoint: |
4efc6507 | 3743 | case bp_jit_event: |
79a45b7d | 3744 | if (opts.addressprint) |
3086aeae DJ |
3745 | { |
3746 | annotate_field (4); | |
54e52265 | 3747 | if (header_of_multiple) |
0d381245 | 3748 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
e9bbd7c5 | 3749 | else if (b->loc == NULL || loc->shlib_disabled) |
54e52265 | 3750 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
0101ce28 | 3751 | else |
5af949e3 UW |
3752 | ui_out_field_core_addr (uiout, "addr", |
3753 | loc->gdbarch, loc->address); | |
3086aeae DJ |
3754 | } |
3755 | annotate_field (5); | |
0d381245 VP |
3756 | if (!header_of_multiple) |
3757 | print_breakpoint_location (b, loc, wrap_indent, stb); | |
3758 | if (b->loc) | |
a6d9a66e | 3759 | *last_loc = b->loc; |
3086aeae DJ |
3760 | break; |
3761 | } | |
c906108c | 3762 | |
4a306c9a | 3763 | if (!part_of_multiple) |
c4093a6a | 3764 | { |
4a306c9a JB |
3765 | if (b->thread != -1) |
3766 | { | |
3767 | /* FIXME: This seems to be redundant and lost here; see the | |
3768 | "stop only in" line a little further down. */ | |
3769 | ui_out_text (uiout, " thread "); | |
3770 | ui_out_field_int (uiout, "thread", b->thread); | |
3771 | } | |
3772 | else if (b->task != 0) | |
3773 | { | |
3774 | ui_out_text (uiout, " task "); | |
3775 | ui_out_field_int (uiout, "task", b->task); | |
3776 | } | |
c4093a6a JM |
3777 | } |
3778 | ||
8b93c638 | 3779 | ui_out_text (uiout, "\n"); |
c4093a6a | 3780 | |
0d381245 | 3781 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
3782 | { |
3783 | annotate_field (6); | |
8b93c638 | 3784 | ui_out_text (uiout, "\tstop only in stack frame at "); |
818dd999 AC |
3785 | /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside |
3786 | the frame ID. */ | |
5af949e3 UW |
3787 | ui_out_field_core_addr (uiout, "frame", |
3788 | b->gdbarch, b->frame_id.stack_addr); | |
8b93c638 | 3789 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
3790 | } |
3791 | ||
0d381245 | 3792 | if (!part_of_multiple && b->cond_string && !ada_exception_catchpoint_p (b)) |
c4093a6a | 3793 | { |
f7f9143b JB |
3794 | /* We do not print the condition for Ada exception catchpoints |
3795 | because the condition is an internal implementation detail | |
3796 | that we do not want to expose to the user. */ | |
c4093a6a | 3797 | annotate_field (7); |
1042e4c0 SS |
3798 | if (b->type == bp_tracepoint) |
3799 | ui_out_text (uiout, "\ttrace only if "); | |
3800 | else | |
3801 | ui_out_text (uiout, "\tstop only if "); | |
0101ce28 JJ |
3802 | ui_out_field_string (uiout, "cond", b->cond_string); |
3803 | ui_out_text (uiout, "\n"); | |
3804 | } | |
3805 | ||
0d381245 | 3806 | if (!part_of_multiple && b->thread != -1) |
c4093a6a JM |
3807 | { |
3808 | /* FIXME should make an annotation for this */ | |
8b93c638 JM |
3809 | ui_out_text (uiout, "\tstop only in thread "); |
3810 | ui_out_field_int (uiout, "thread", b->thread); | |
3811 | ui_out_text (uiout, "\n"); | |
c4093a6a JM |
3812 | } |
3813 | ||
63c715c6 | 3814 | if (!part_of_multiple && b->hit_count) |
c4093a6a JM |
3815 | { |
3816 | /* FIXME should make an annotation for this */ | |
8b93c638 JM |
3817 | if (ep_is_catchpoint (b)) |
3818 | ui_out_text (uiout, "\tcatchpoint"); | |
3819 | else | |
3820 | ui_out_text (uiout, "\tbreakpoint"); | |
3821 | ui_out_text (uiout, " already hit "); | |
3822 | ui_out_field_int (uiout, "times", b->hit_count); | |
3823 | if (b->hit_count == 1) | |
3824 | ui_out_text (uiout, " time\n"); | |
3825 | else | |
3826 | ui_out_text (uiout, " times\n"); | |
c4093a6a JM |
3827 | } |
3828 | ||
fb40c209 AC |
3829 | /* Output the count also if it is zero, but only if this is |
3830 | mi. FIXME: Should have a better test for this. */ | |
9dc5e2a9 | 3831 | if (ui_out_is_mi_like_p (uiout)) |
63c715c6 | 3832 | if (!part_of_multiple && b->hit_count == 0) |
fb40c209 | 3833 | ui_out_field_int (uiout, "times", b->hit_count); |
8b93c638 | 3834 | |
0d381245 | 3835 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
3836 | { |
3837 | annotate_field (8); | |
8b93c638 JM |
3838 | ui_out_text (uiout, "\tignore next "); |
3839 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
3840 | ui_out_text (uiout, " hits\n"); | |
c4093a6a | 3841 | } |
059fb39f PM |
3842 | |
3843 | l = b->commands; | |
3844 | if (!part_of_multiple && l) | |
c4093a6a | 3845 | { |
3b31d625 EZ |
3846 | struct cleanup *script_chain; |
3847 | ||
c4093a6a | 3848 | annotate_field (9); |
3b31d625 | 3849 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 3850 | print_command_lines (uiout, l, 4); |
3b31d625 | 3851 | do_cleanups (script_chain); |
c4093a6a | 3852 | } |
d24317b4 | 3853 | |
1042e4c0 SS |
3854 | if (!part_of_multiple && b->pass_count) |
3855 | { | |
3856 | annotate_field (10); | |
3857 | ui_out_text (uiout, "\tpass count "); | |
3858 | ui_out_field_int (uiout, "pass", b->pass_count); | |
3859 | ui_out_text (uiout, " \n"); | |
3860 | } | |
3861 | ||
3862 | if (!part_of_multiple && b->step_count) | |
3863 | { | |
3864 | annotate_field (11); | |
3865 | ui_out_text (uiout, "\tstep count "); | |
3866 | ui_out_field_int (uiout, "step", b->step_count); | |
3867 | ui_out_text (uiout, " \n"); | |
3868 | } | |
3869 | ||
3870 | if (!part_of_multiple && b->actions) | |
3871 | { | |
3872 | struct action_line *action; | |
3873 | annotate_field (12); | |
3874 | for (action = b->actions; action; action = action->next) | |
3875 | { | |
3876 | ui_out_text (uiout, " A\t"); | |
3877 | ui_out_text (uiout, action->action); | |
3878 | ui_out_text (uiout, "\n"); | |
3879 | } | |
3880 | } | |
3881 | ||
d24317b4 VP |
3882 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
3883 | { | |
3884 | if (b->addr_string) | |
3885 | ui_out_field_string (uiout, "original-location", b->addr_string); | |
3886 | else if (b->exp_string) | |
3887 | ui_out_field_string (uiout, "original-location", b->exp_string); | |
3888 | } | |
3889 | ||
3b31d625 | 3890 | do_cleanups (bkpt_chain); |
8b93c638 | 3891 | do_cleanups (old_chain); |
c4093a6a | 3892 | } |
c5aa993b | 3893 | |
0d381245 VP |
3894 | static void |
3895 | print_one_breakpoint (struct breakpoint *b, | |
a6d9a66e | 3896 | struct bp_location **last_loc, int print_address_bits) |
0d381245 | 3897 | { |
a6d9a66e | 3898 | print_one_breakpoint_location (b, NULL, 0, last_loc, print_address_bits); |
0d381245 VP |
3899 | |
3900 | /* If this breakpoint has custom print function, | |
3901 | it's already printed. Otherwise, print individual | |
3902 | locations, if any. */ | |
3903 | if (b->ops == NULL || b->ops->print_one == NULL) | |
3904 | { | |
3905 | /* If breakpoint has a single location that is | |
3906 | disabled, we print it as if it had | |
3907 | several locations, since otherwise it's hard to | |
3908 | represent "breakpoint enabled, location disabled" | |
a5606eee VP |
3909 | situation. |
3910 | Note that while hardware watchpoints have | |
3911 | several locations internally, that's no a property | |
3912 | exposed to user. */ | |
0d381245 | 3913 | if (b->loc |
a5606eee | 3914 | && !is_hardware_watchpoint (b) |
0d381245 | 3915 | && (b->loc->next || !b->loc->enabled) |
a5606eee | 3916 | && !ui_out_is_mi_like_p (uiout)) |
0d381245 VP |
3917 | { |
3918 | struct bp_location *loc; | |
3919 | int n = 1; | |
3920 | for (loc = b->loc; loc; loc = loc->next, ++n) | |
a6d9a66e UW |
3921 | print_one_breakpoint_location (b, loc, n, last_loc, |
3922 | print_address_bits); | |
0d381245 VP |
3923 | } |
3924 | } | |
3925 | } | |
3926 | ||
a6d9a66e UW |
3927 | static int |
3928 | breakpoint_address_bits (struct breakpoint *b) | |
3929 | { | |
3930 | int print_address_bits = 0; | |
3931 | struct bp_location *loc; | |
3932 | ||
3933 | for (loc = b->loc; loc; loc = loc->next) | |
3934 | { | |
3935 | int addr_bit = gdbarch_addr_bit (b->gdbarch); | |
3936 | if (addr_bit > print_address_bits) | |
3937 | print_address_bits = addr_bit; | |
3938 | } | |
3939 | ||
3940 | return print_address_bits; | |
3941 | } | |
0d381245 | 3942 | |
c4093a6a JM |
3943 | struct captured_breakpoint_query_args |
3944 | { | |
3945 | int bnum; | |
3946 | }; | |
c5aa993b | 3947 | |
c4093a6a | 3948 | static int |
2b65245e | 3949 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a JM |
3950 | { |
3951 | struct captured_breakpoint_query_args *args = data; | |
52f0bd74 | 3952 | struct breakpoint *b; |
a6d9a66e | 3953 | struct bp_location *dummy_loc = NULL; |
c4093a6a JM |
3954 | ALL_BREAKPOINTS (b) |
3955 | { | |
3956 | if (args->bnum == b->number) | |
c5aa993b | 3957 | { |
a6d9a66e UW |
3958 | int print_address_bits = breakpoint_address_bits (b); |
3959 | print_one_breakpoint (b, &dummy_loc, print_address_bits); | |
c4093a6a | 3960 | return GDB_RC_OK; |
c5aa993b | 3961 | } |
c4093a6a JM |
3962 | } |
3963 | return GDB_RC_NONE; | |
3964 | } | |
c5aa993b | 3965 | |
c4093a6a | 3966 | enum gdb_rc |
ce43223b | 3967 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, char **error_message) |
c4093a6a JM |
3968 | { |
3969 | struct captured_breakpoint_query_args args; | |
3970 | args.bnum = bnum; | |
3971 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
3972 | an error. */ | |
b0b13bb4 DJ |
3973 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
3974 | error_message, RETURN_MASK_ALL) < 0) | |
3975 | return GDB_RC_FAIL; | |
3976 | else | |
3977 | return GDB_RC_OK; | |
c4093a6a | 3978 | } |
c5aa993b | 3979 | |
7f3b0473 AC |
3980 | /* Return non-zero if B is user settable (breakpoints, watchpoints, |
3981 | catchpoints, et.al.). */ | |
3982 | ||
3983 | static int | |
3984 | user_settable_breakpoint (const struct breakpoint *b) | |
3985 | { | |
3986 | return (b->type == bp_breakpoint | |
ce78b96d | 3987 | || b->type == bp_catchpoint |
7f3b0473 | 3988 | || b->type == bp_hardware_breakpoint |
1042e4c0 | 3989 | || b->type == bp_tracepoint |
7f3b0473 AC |
3990 | || b->type == bp_watchpoint |
3991 | || b->type == bp_read_watchpoint | |
3992 | || b->type == bp_access_watchpoint | |
3993 | || b->type == bp_hardware_watchpoint); | |
3994 | } | |
3995 | ||
3996 | /* Print information on user settable breakpoint (watchpoint, etc) | |
3997 | number BNUM. If BNUM is -1 print all user settable breakpoints. | |
3998 | If ALLFLAG is non-zero, include non- user settable breakpoints. */ | |
c906108c | 3999 | |
c4093a6a | 4000 | static void |
fba45db2 | 4001 | breakpoint_1 (int bnum, int allflag) |
c4093a6a | 4002 | { |
52f0bd74 | 4003 | struct breakpoint *b; |
a6d9a66e | 4004 | struct bp_location *last_loc = NULL; |
7f3b0473 | 4005 | int nr_printable_breakpoints; |
3b31d625 | 4006 | struct cleanup *bkpttbl_chain; |
79a45b7d | 4007 | struct value_print_options opts; |
a6d9a66e | 4008 | int print_address_bits = 0; |
c4093a6a | 4009 | |
79a45b7d TT |
4010 | get_user_print_options (&opts); |
4011 | ||
a6d9a66e UW |
4012 | /* Compute the number of rows in the table, as well as the |
4013 | size required for address fields. */ | |
7f3b0473 AC |
4014 | nr_printable_breakpoints = 0; |
4015 | ALL_BREAKPOINTS (b) | |
4016 | if (bnum == -1 | |
4017 | || bnum == b->number) | |
4018 | { | |
4019 | if (allflag || user_settable_breakpoint (b)) | |
a6d9a66e UW |
4020 | { |
4021 | int addr_bit = breakpoint_address_bits (b); | |
4022 | if (addr_bit > print_address_bits) | |
4023 | print_address_bits = addr_bit; | |
4024 | ||
4025 | nr_printable_breakpoints++; | |
4026 | } | |
7f3b0473 AC |
4027 | } |
4028 | ||
79a45b7d | 4029 | if (opts.addressprint) |
3b31d625 EZ |
4030 | bkpttbl_chain |
4031 | = make_cleanup_ui_out_table_begin_end (uiout, 6, nr_printable_breakpoints, | |
4032 | "BreakpointTable"); | |
8b93c638 | 4033 | else |
3b31d625 EZ |
4034 | bkpttbl_chain |
4035 | = make_cleanup_ui_out_table_begin_end (uiout, 5, nr_printable_breakpoints, | |
4036 | "BreakpointTable"); | |
8b93c638 | 4037 | |
7f3b0473 | 4038 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
4039 | annotate_breakpoints_headers (); |
4040 | if (nr_printable_breakpoints > 0) | |
4041 | annotate_field (0); | |
0d381245 | 4042 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
4043 | if (nr_printable_breakpoints > 0) |
4044 | annotate_field (1); | |
4045 | ui_out_table_header (uiout, 14, ui_left, "type", "Type"); /* 2 */ | |
4046 | if (nr_printable_breakpoints > 0) | |
4047 | annotate_field (2); | |
4048 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ | |
4049 | if (nr_printable_breakpoints > 0) | |
4050 | annotate_field (3); | |
54e52265 | 4051 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 4052 | if (opts.addressprint) |
7f3b0473 | 4053 | { |
d7faa9e7 AC |
4054 | if (nr_printable_breakpoints > 0) |
4055 | annotate_field (4); | |
a6d9a66e | 4056 | if (print_address_bits <= 32) |
b25959ec | 4057 | ui_out_table_header (uiout, 10, ui_left, "addr", "Address");/* 5 */ |
7f3b0473 | 4058 | else |
b25959ec | 4059 | ui_out_table_header (uiout, 18, ui_left, "addr", "Address");/* 5 */ |
7f3b0473 | 4060 | } |
d7faa9e7 AC |
4061 | if (nr_printable_breakpoints > 0) |
4062 | annotate_field (5); | |
4063 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
4064 | ui_out_table_body (uiout); | |
4065 | if (nr_printable_breakpoints > 0) | |
4066 | annotate_breakpoints_table (); | |
7f3b0473 | 4067 | |
c4093a6a JM |
4068 | ALL_BREAKPOINTS (b) |
4069 | if (bnum == -1 | |
4070 | || bnum == b->number) | |
4071 | { | |
4072 | /* We only print out user settable breakpoints unless the | |
4073 | allflag is set. */ | |
7f3b0473 | 4074 | if (allflag || user_settable_breakpoint (b)) |
a6d9a66e | 4075 | print_one_breakpoint (b, &last_loc, print_address_bits); |
c4093a6a JM |
4076 | } |
4077 | ||
3b31d625 | 4078 | do_cleanups (bkpttbl_chain); |
698384cd | 4079 | |
7f3b0473 | 4080 | if (nr_printable_breakpoints == 0) |
c906108c | 4081 | { |
8b93c638 JM |
4082 | if (bnum == -1) |
4083 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); | |
4084 | else | |
4085 | ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n", | |
4086 | bnum); | |
c906108c SS |
4087 | } |
4088 | else | |
c4093a6a | 4089 | { |
a6d9a66e UW |
4090 | if (last_loc && !server_command) |
4091 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 4092 | } |
c906108c | 4093 | |
c4093a6a JM |
4094 | /* FIXME? Should this be moved up so that it is only called when |
4095 | there have been breakpoints? */ | |
c906108c SS |
4096 | annotate_breakpoints_table_end (); |
4097 | } | |
4098 | ||
c906108c | 4099 | static void |
fba45db2 | 4100 | breakpoints_info (char *bnum_exp, int from_tty) |
c906108c SS |
4101 | { |
4102 | int bnum = -1; | |
4103 | ||
4104 | if (bnum_exp) | |
bb518678 | 4105 | bnum = parse_and_eval_long (bnum_exp); |
c906108c SS |
4106 | |
4107 | breakpoint_1 (bnum, 0); | |
4108 | } | |
4109 | ||
7a292a7a | 4110 | static void |
fba45db2 | 4111 | maintenance_info_breakpoints (char *bnum_exp, int from_tty) |
c906108c SS |
4112 | { |
4113 | int bnum = -1; | |
4114 | ||
4115 | if (bnum_exp) | |
bb518678 | 4116 | bnum = parse_and_eval_long (bnum_exp); |
c906108c SS |
4117 | |
4118 | breakpoint_1 (bnum, 1); | |
4119 | } | |
4120 | ||
0d381245 | 4121 | static int |
714835d5 UW |
4122 | breakpoint_has_pc (struct breakpoint *b, |
4123 | CORE_ADDR pc, struct obj_section *section) | |
0d381245 VP |
4124 | { |
4125 | struct bp_location *bl = b->loc; | |
4126 | for (; bl; bl = bl->next) | |
4127 | { | |
4128 | if (bl->address == pc | |
4129 | && (!overlay_debugging || bl->section == section)) | |
4130 | return 1; | |
4131 | } | |
4132 | return 0; | |
4133 | } | |
4134 | ||
c906108c SS |
4135 | /* Print a message describing any breakpoints set at PC. */ |
4136 | ||
4137 | static void | |
5af949e3 UW |
4138 | describe_other_breakpoints (struct gdbarch *gdbarch, CORE_ADDR pc, |
4139 | struct obj_section *section, int thread) | |
c906108c | 4140 | { |
52f0bd74 AC |
4141 | int others = 0; |
4142 | struct breakpoint *b; | |
c906108c SS |
4143 | |
4144 | ALL_BREAKPOINTS (b) | |
0d381245 | 4145 | others += breakpoint_has_pc (b, pc, section); |
c906108c SS |
4146 | if (others > 0) |
4147 | { | |
a3f17187 AC |
4148 | if (others == 1) |
4149 | printf_filtered (_("Note: breakpoint ")); | |
4150 | else /* if (others == ???) */ | |
4151 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 4152 | ALL_BREAKPOINTS (b) |
0d381245 VP |
4153 | if (breakpoint_has_pc (b, pc, section)) |
4154 | { | |
4155 | others--; | |
4156 | printf_filtered ("%d", b->number); | |
4157 | if (b->thread == -1 && thread != -1) | |
4158 | printf_filtered (" (all threads)"); | |
4159 | else if (b->thread != -1) | |
4160 | printf_filtered (" (thread %d)", b->thread); | |
4161 | printf_filtered ("%s%s ", | |
059fb39f | 4162 | ((b->enable_state == bp_disabled |
8bea4e01 UW |
4163 | || b->enable_state == bp_call_disabled |
4164 | || b->enable_state == bp_startup_disabled) | |
0d381245 VP |
4165 | ? " (disabled)" |
4166 | : b->enable_state == bp_permanent | |
4167 | ? " (permanent)" | |
4168 | : ""), | |
4169 | (others > 1) ? "," | |
4170 | : ((others == 1) ? " and" : "")); | |
4171 | } | |
a3f17187 | 4172 | printf_filtered (_("also set at pc ")); |
5af949e3 | 4173 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
4174 | printf_filtered (".\n"); |
4175 | } | |
4176 | } | |
4177 | \f | |
4178 | /* Set the default place to put a breakpoint | |
4179 | for the `break' command with no arguments. */ | |
4180 | ||
4181 | void | |
fba45db2 KB |
4182 | set_default_breakpoint (int valid, CORE_ADDR addr, struct symtab *symtab, |
4183 | int line) | |
c906108c SS |
4184 | { |
4185 | default_breakpoint_valid = valid; | |
4186 | default_breakpoint_address = addr; | |
4187 | default_breakpoint_symtab = symtab; | |
4188 | default_breakpoint_line = line; | |
4189 | } | |
4190 | ||
e4f237da KB |
4191 | /* Return true iff it is meaningful to use the address member of |
4192 | BPT. For some breakpoint types, the address member is irrelevant | |
4193 | and it makes no sense to attempt to compare it to other addresses | |
4194 | (or use it for any other purpose either). | |
4195 | ||
4196 | More specifically, each of the following breakpoint types will always | |
4197 | have a zero valued address and we don't want check_duplicates() to mark | |
4198 | breakpoints of any of these types to be a duplicate of an actual | |
4199 | breakpoint at address zero: | |
4200 | ||
4201 | bp_watchpoint | |
4202 | bp_hardware_watchpoint | |
4203 | bp_read_watchpoint | |
4204 | bp_access_watchpoint | |
fe798b75 | 4205 | bp_catchpoint */ |
e4f237da KB |
4206 | |
4207 | static int | |
4208 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
4209 | { | |
4210 | enum bptype type = bpt->type; | |
4211 | ||
4212 | return (type != bp_watchpoint | |
4213 | && type != bp_hardware_watchpoint | |
4214 | && type != bp_read_watchpoint | |
4215 | && type != bp_access_watchpoint | |
fe798b75 | 4216 | && type != bp_catchpoint); |
e4f237da KB |
4217 | } |
4218 | ||
9f60f21b | 4219 | /* Rescan breakpoints at the same address and section as BPT, |
c906108c | 4220 | marking the first one as "first" and any others as "duplicates". |
c2c6d25f | 4221 | This is so that the bpt instruction is only inserted once. |
9f60f21b JB |
4222 | If we have a permanent breakpoint at the same place as BPT, make |
4223 | that one the official one, and the rest as duplicates. */ | |
c906108c SS |
4224 | |
4225 | static void | |
714835d5 | 4226 | check_duplicates_for (CORE_ADDR address, struct obj_section *section) |
c906108c | 4227 | { |
075f6582 | 4228 | struct bp_location *b; |
52f0bd74 | 4229 | int count = 0; |
075f6582 | 4230 | struct bp_location *perm_bp = 0; |
c906108c | 4231 | |
075f6582 DJ |
4232 | ALL_BP_LOCATIONS (b) |
4233 | if (b->owner->enable_state != bp_disabled | |
075f6582 | 4234 | && b->owner->enable_state != bp_call_disabled |
8bea4e01 | 4235 | && b->owner->enable_state != bp_startup_disabled |
0d381245 VP |
4236 | && b->enabled |
4237 | && !b->shlib_disabled | |
075f6582 DJ |
4238 | && b->address == address /* address / overlay match */ |
4239 | && (!overlay_debugging || b->section == section) | |
4240 | && breakpoint_address_is_meaningful (b->owner)) | |
c5aa993b | 4241 | { |
c2c6d25f | 4242 | /* Have we found a permanent breakpoint? */ |
075f6582 | 4243 | if (b->owner->enable_state == bp_permanent) |
c2c6d25f JM |
4244 | { |
4245 | perm_bp = b; | |
4246 | break; | |
4247 | } | |
4248 | ||
c5aa993b | 4249 | count++; |
075f6582 | 4250 | b->duplicate = count > 1; |
c5aa993b | 4251 | } |
c2c6d25f JM |
4252 | |
4253 | /* If we found a permanent breakpoint at this address, go over the | |
aae64587 PA |
4254 | list again and declare all the other breakpoints there (except |
4255 | other permanent breakpoints) to be the duplicates. */ | |
c2c6d25f JM |
4256 | if (perm_bp) |
4257 | { | |
075f6582 | 4258 | perm_bp->duplicate = 0; |
c2c6d25f JM |
4259 | |
4260 | /* Permanent breakpoint should always be inserted. */ | |
075f6582 | 4261 | if (! perm_bp->inserted) |
8e65ff28 | 4262 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 AC |
4263 | _("allegedly permanent breakpoint is not " |
4264 | "actually inserted")); | |
c2c6d25f | 4265 | |
075f6582 | 4266 | ALL_BP_LOCATIONS (b) |
c2c6d25f JM |
4267 | if (b != perm_bp) |
4268 | { | |
aae64587 PA |
4269 | if (b->owner->enable_state != bp_permanent |
4270 | && b->owner->enable_state != bp_disabled | |
075f6582 | 4271 | && b->owner->enable_state != bp_call_disabled |
8bea4e01 | 4272 | && b->owner->enable_state != bp_startup_disabled |
0d381245 | 4273 | && b->enabled && !b->shlib_disabled |
075f6582 DJ |
4274 | && b->address == address /* address / overlay match */ |
4275 | && (!overlay_debugging || b->section == section) | |
4276 | && breakpoint_address_is_meaningful (b->owner)) | |
4277 | { | |
4278 | if (b->inserted) | |
4279 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 AC |
4280 | _("another breakpoint was inserted on top of " |
4281 | "a permanent breakpoint")); | |
075f6582 DJ |
4282 | |
4283 | b->duplicate = 1; | |
4284 | } | |
c2c6d25f JM |
4285 | } |
4286 | } | |
c906108c SS |
4287 | } |
4288 | ||
0d381245 VP |
4289 | static void |
4290 | check_duplicates (struct breakpoint *bpt) | |
4291 | { | |
4292 | struct bp_location *bl = bpt->loc; | |
4293 | ||
4294 | if (! breakpoint_address_is_meaningful (bpt)) | |
4295 | return; | |
4296 | ||
4297 | for (; bl; bl = bl->next) | |
4298 | check_duplicates_for (bl->address, bl->section); | |
4299 | } | |
4300 | ||
76897487 KB |
4301 | static void |
4302 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
4303 | int bnum, int have_bnum) | |
4304 | { | |
4305 | char astr1[40]; | |
4306 | char astr2[40]; | |
4307 | ||
bb599908 PH |
4308 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
4309 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 4310 | if (have_bnum) |
8a3fe4f8 | 4311 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
4312 | bnum, astr1, astr2); |
4313 | else | |
8a3fe4f8 | 4314 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
4315 | } |
4316 | ||
4317 | /* Adjust a breakpoint's address to account for architectural constraints | |
4318 | on breakpoint placement. Return the adjusted address. Note: Very | |
4319 | few targets require this kind of adjustment. For most targets, | |
4320 | this function is simply the identity function. */ | |
4321 | ||
4322 | static CORE_ADDR | |
a6d9a66e UW |
4323 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
4324 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 4325 | { |
a6d9a66e | 4326 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
4327 | { |
4328 | /* Very few targets need any kind of breakpoint adjustment. */ | |
4329 | return bpaddr; | |
4330 | } | |
88f7da05 KB |
4331 | else if (bptype == bp_watchpoint |
4332 | || bptype == bp_hardware_watchpoint | |
4333 | || bptype == bp_read_watchpoint | |
4334 | || bptype == bp_access_watchpoint | |
fe798b75 | 4335 | || bptype == bp_catchpoint) |
88f7da05 KB |
4336 | { |
4337 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
4338 | have their addresses modified. */ | |
4339 | return bpaddr; | |
4340 | } | |
76897487 KB |
4341 | else |
4342 | { | |
4343 | CORE_ADDR adjusted_bpaddr; | |
4344 | ||
4345 | /* Some targets have architectural constraints on the placement | |
4346 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 4347 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
4348 | |
4349 | /* An adjusted breakpoint address can significantly alter | |
4350 | a user's expectations. Print a warning if an adjustment | |
4351 | is required. */ | |
4352 | if (adjusted_bpaddr != bpaddr) | |
4353 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
4354 | ||
4355 | return adjusted_bpaddr; | |
4356 | } | |
4357 | } | |
4358 | ||
7cc221ef DJ |
4359 | /* Allocate a struct bp_location. */ |
4360 | ||
26bb91f3 | 4361 | static struct bp_location * |
39d61571 | 4362 | allocate_bp_location (struct breakpoint *bpt) |
7cc221ef DJ |
4363 | { |
4364 | struct bp_location *loc, *loc_p; | |
4365 | ||
4366 | loc = xmalloc (sizeof (struct bp_location)); | |
4367 | memset (loc, 0, sizeof (*loc)); | |
4368 | ||
e049a4b5 | 4369 | loc->owner = bpt; |
511a6cd4 | 4370 | loc->cond = NULL; |
0d381245 VP |
4371 | loc->shlib_disabled = 0; |
4372 | loc->enabled = 1; | |
e049a4b5 | 4373 | |
39d61571 | 4374 | switch (bpt->type) |
e049a4b5 DJ |
4375 | { |
4376 | case bp_breakpoint: | |
1042e4c0 | 4377 | case bp_tracepoint: |
e049a4b5 DJ |
4378 | case bp_until: |
4379 | case bp_finish: | |
4380 | case bp_longjmp: | |
4381 | case bp_longjmp_resume: | |
4382 | case bp_step_resume: | |
e049a4b5 DJ |
4383 | case bp_watchpoint_scope: |
4384 | case bp_call_dummy: | |
4385 | case bp_shlib_event: | |
4386 | case bp_thread_event: | |
4387 | case bp_overlay_event: | |
4efc6507 | 4388 | case bp_jit_event: |
0fd8e87f | 4389 | case bp_longjmp_master: |
e049a4b5 DJ |
4390 | loc->loc_type = bp_loc_software_breakpoint; |
4391 | break; | |
4392 | case bp_hardware_breakpoint: | |
4393 | loc->loc_type = bp_loc_hardware_breakpoint; | |
4394 | break; | |
4395 | case bp_hardware_watchpoint: | |
4396 | case bp_read_watchpoint: | |
4397 | case bp_access_watchpoint: | |
4398 | loc->loc_type = bp_loc_hardware_watchpoint; | |
4399 | break; | |
4400 | case bp_watchpoint: | |
ce78b96d | 4401 | case bp_catchpoint: |
e049a4b5 DJ |
4402 | loc->loc_type = bp_loc_other; |
4403 | break; | |
4404 | default: | |
e2e0b3e5 | 4405 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
4406 | } |
4407 | ||
7cc221ef DJ |
4408 | return loc; |
4409 | } | |
4410 | ||
fe3f5fa8 VP |
4411 | static void free_bp_location (struct bp_location *loc) |
4412 | { | |
4413 | if (loc->cond) | |
4414 | xfree (loc->cond); | |
74960c60 VP |
4415 | |
4416 | if (loc->function_name) | |
4417 | xfree (loc->function_name); | |
4418 | ||
fe3f5fa8 VP |
4419 | xfree (loc); |
4420 | } | |
4421 | ||
0d381245 VP |
4422 | /* Helper to set_raw_breakpoint below. Creates a breakpoint |
4423 | that has type BPTYPE and has no locations as yet. */ | |
63c252f8 | 4424 | /* This function is used in gdbtk sources and thus can not be made static. */ |
c906108c | 4425 | |
c40e75cd | 4426 | static struct breakpoint * |
a6d9a66e UW |
4427 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, |
4428 | enum bptype bptype) | |
c906108c | 4429 | { |
52f0bd74 | 4430 | struct breakpoint *b, *b1; |
c906108c SS |
4431 | |
4432 | b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint)); | |
4433 | memset (b, 0, sizeof (*b)); | |
2219d63c | 4434 | |
4d28f7a8 | 4435 | b->type = bptype; |
a6d9a66e | 4436 | b->gdbarch = gdbarch; |
c906108c SS |
4437 | b->language = current_language->la_language; |
4438 | b->input_radix = input_radix; | |
4439 | b->thread = -1; | |
b5de0fa7 | 4440 | b->enable_state = bp_enabled; |
c906108c SS |
4441 | b->next = 0; |
4442 | b->silent = 0; | |
4443 | b->ignore_count = 0; | |
4444 | b->commands = NULL; | |
818dd999 | 4445 | b->frame_id = null_frame_id; |
3a3e9ee3 | 4446 | b->forked_inferior_pid = null_ptid; |
c906108c | 4447 | b->exec_pathname = NULL; |
3086aeae | 4448 | b->ops = NULL; |
0d381245 | 4449 | b->condition_not_parsed = 0; |
c906108c SS |
4450 | |
4451 | /* Add this breakpoint to the end of the chain | |
4452 | so that a list of breakpoints will come out in order | |
4453 | of increasing numbers. */ | |
4454 | ||
4455 | b1 = breakpoint_chain; | |
4456 | if (b1 == 0) | |
4457 | breakpoint_chain = b; | |
4458 | else | |
4459 | { | |
4460 | while (b1->next) | |
4461 | b1 = b1->next; | |
4462 | b1->next = b; | |
4463 | } | |
0d381245 VP |
4464 | return b; |
4465 | } | |
4466 | ||
4467 | /* Initialize loc->function_name. */ | |
4468 | static void | |
4469 | set_breakpoint_location_function (struct bp_location *loc) | |
4470 | { | |
4471 | if (loc->owner->type == bp_breakpoint | |
1042e4c0 SS |
4472 | || loc->owner->type == bp_hardware_breakpoint |
4473 | || loc->owner->type == bp_tracepoint) | |
0d381245 VP |
4474 | { |
4475 | find_pc_partial_function (loc->address, &(loc->function_name), | |
4476 | NULL, NULL); | |
4477 | if (loc->function_name) | |
4478 | loc->function_name = xstrdup (loc->function_name); | |
4479 | } | |
4480 | } | |
4481 | ||
a6d9a66e UW |
4482 | /* Attempt to determine architecture of location identified by SAL. */ |
4483 | static struct gdbarch * | |
4484 | get_sal_arch (struct symtab_and_line sal) | |
4485 | { | |
4486 | if (sal.section) | |
4487 | return get_objfile_arch (sal.section->objfile); | |
4488 | if (sal.symtab) | |
4489 | return get_objfile_arch (sal.symtab->objfile); | |
4490 | ||
4491 | return NULL; | |
4492 | } | |
4493 | ||
0d381245 VP |
4494 | /* set_raw_breakpoint is a low level routine for allocating and |
4495 | partially initializing a breakpoint of type BPTYPE. The newly | |
4496 | created breakpoint's address, section, source file name, and line | |
4497 | number are provided by SAL. The newly created and partially | |
4498 | initialized breakpoint is added to the breakpoint chain and | |
4499 | is also returned as the value of this function. | |
4500 | ||
4501 | It is expected that the caller will complete the initialization of | |
4502 | the newly created breakpoint struct as well as output any status | |
4503 | information regarding the creation of a new breakpoint. In | |
4504 | particular, set_raw_breakpoint does NOT set the breakpoint | |
4505 | number! Care should be taken to not allow an error to occur | |
4506 | prior to completing the initialization of the breakpoint. If this | |
4507 | should happen, a bogus breakpoint will be left on the chain. */ | |
4508 | ||
63c252f8 | 4509 | struct breakpoint * |
a6d9a66e UW |
4510 | set_raw_breakpoint (struct gdbarch *gdbarch, |
4511 | struct symtab_and_line sal, enum bptype bptype) | |
0d381245 | 4512 | { |
a6d9a66e | 4513 | struct breakpoint *b = set_raw_breakpoint_without_location (gdbarch, bptype); |
0d381245 | 4514 | CORE_ADDR adjusted_address; |
a6d9a66e UW |
4515 | struct gdbarch *loc_gdbarch; |
4516 | ||
4517 | loc_gdbarch = get_sal_arch (sal); | |
4518 | if (!loc_gdbarch) | |
4519 | loc_gdbarch = b->gdbarch; | |
0d381245 VP |
4520 | |
4521 | /* Adjust the breakpoint's address prior to allocating a location. | |
4522 | Once we call allocate_bp_location(), that mostly uninitialized | |
4523 | location will be placed on the location chain. Adjustment of the | |
8defab1a | 4524 | breakpoint may cause target_read_memory() to be called and we do |
0d381245 VP |
4525 | not want its scan of the location chain to find a breakpoint and |
4526 | location that's only been partially initialized. */ | |
a6d9a66e | 4527 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, sal.pc, b->type); |
0d381245 | 4528 | |
39d61571 | 4529 | b->loc = allocate_bp_location (b); |
a6d9a66e | 4530 | b->loc->gdbarch = loc_gdbarch; |
0d381245 VP |
4531 | b->loc->requested_address = sal.pc; |
4532 | b->loc->address = adjusted_address; | |
4533 | ||
4534 | if (sal.symtab == NULL) | |
4535 | b->source_file = NULL; | |
4536 | else | |
1b36a34b | 4537 | b->source_file = xstrdup (sal.symtab->filename); |
0d381245 VP |
4538 | b->loc->section = sal.section; |
4539 | b->line_number = sal.line; | |
4540 | ||
4541 | set_breakpoint_location_function (b->loc); | |
c906108c | 4542 | |
c906108c SS |
4543 | breakpoints_changed (); |
4544 | ||
4545 | return b; | |
4546 | } | |
4547 | ||
c2c6d25f JM |
4548 | |
4549 | /* Note that the breakpoint object B describes a permanent breakpoint | |
4550 | instruction, hard-wired into the inferior's code. */ | |
4551 | void | |
4552 | make_breakpoint_permanent (struct breakpoint *b) | |
4553 | { | |
0d381245 | 4554 | struct bp_location *bl; |
b5de0fa7 | 4555 | b->enable_state = bp_permanent; |
c2c6d25f | 4556 | |
0d381245 VP |
4557 | /* By definition, permanent breakpoints are already present in the code. |
4558 | Mark all locations as inserted. For now, make_breakpoint_permanent | |
4559 | is called in just one place, so it's hard to say if it's reasonable | |
4560 | to have permanent breakpoint with multiple locations or not, | |
4561 | but it's easy to implmement. */ | |
4562 | for (bl = b->loc; bl; bl = bl->next) | |
4563 | bl->inserted = 1; | |
c2c6d25f JM |
4564 | } |
4565 | ||
53a5351d | 4566 | /* Call this routine when stepping and nexting to enable a breakpoint |
0fd8e87f | 4567 | if we do a longjmp() in THREAD. When we hit that breakpoint, call |
c906108c SS |
4568 | set_longjmp_resume_breakpoint() to figure out where we are going. */ |
4569 | ||
4570 | void | |
0fd8e87f | 4571 | set_longjmp_breakpoint (int thread) |
c906108c | 4572 | { |
0fd8e87f UW |
4573 | struct breakpoint *b, *temp; |
4574 | ||
4575 | /* To avoid having to rescan all objfile symbols at every step, | |
4576 | we maintain a list of continually-inserted but always disabled | |
4577 | longjmp "master" breakpoints. Here, we simply create momentary | |
4578 | clones of those and enable them for the requested thread. */ | |
4579 | ALL_BREAKPOINTS_SAFE (b, temp) | |
4580 | if (b->type == bp_longjmp_master) | |
4581 | { | |
4582 | struct breakpoint *clone = clone_momentary_breakpoint (b); | |
4583 | clone->type = bp_longjmp; | |
4584 | clone->thread = thread; | |
4585 | } | |
c906108c SS |
4586 | } |
4587 | ||
611c83ae | 4588 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 4589 | void |
611c83ae | 4590 | delete_longjmp_breakpoint (int thread) |
c906108c | 4591 | { |
611c83ae | 4592 | struct breakpoint *b, *temp; |
c906108c | 4593 | |
611c83ae PA |
4594 | ALL_BREAKPOINTS_SAFE (b, temp) |
4595 | if (b->type == bp_longjmp) | |
4596 | { | |
4597 | if (b->thread == thread) | |
4598 | delete_breakpoint (b); | |
4599 | } | |
c906108c SS |
4600 | } |
4601 | ||
1900040c MS |
4602 | void |
4603 | enable_overlay_breakpoints (void) | |
4604 | { | |
52f0bd74 | 4605 | struct breakpoint *b; |
1900040c MS |
4606 | |
4607 | ALL_BREAKPOINTS (b) | |
4608 | if (b->type == bp_overlay_event) | |
4609 | { | |
4610 | b->enable_state = bp_enabled; | |
b60e7edf | 4611 | update_global_location_list (1); |
c02f5703 | 4612 | overlay_events_enabled = 1; |
1900040c MS |
4613 | } |
4614 | } | |
4615 | ||
4616 | void | |
4617 | disable_overlay_breakpoints (void) | |
4618 | { | |
52f0bd74 | 4619 | struct breakpoint *b; |
1900040c MS |
4620 | |
4621 | ALL_BREAKPOINTS (b) | |
4622 | if (b->type == bp_overlay_event) | |
4623 | { | |
4624 | b->enable_state = bp_disabled; | |
b60e7edf | 4625 | update_global_location_list (0); |
c02f5703 | 4626 | overlay_events_enabled = 0; |
1900040c MS |
4627 | } |
4628 | } | |
4629 | ||
c4093a6a | 4630 | struct breakpoint * |
a6d9a66e | 4631 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
4632 | { |
4633 | struct breakpoint *b; | |
c4093a6a | 4634 | |
a6d9a66e | 4635 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event); |
c4093a6a | 4636 | |
b5de0fa7 | 4637 | b->enable_state = bp_enabled; |
c4093a6a | 4638 | /* addr_string has to be used or breakpoint_re_set will delete me. */ |
5af949e3 UW |
4639 | b->addr_string |
4640 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
c4093a6a | 4641 | |
b60e7edf | 4642 | update_global_location_list_nothrow (1); |
74960c60 | 4643 | |
c4093a6a JM |
4644 | return b; |
4645 | } | |
4646 | ||
4647 | void | |
4648 | remove_thread_event_breakpoints (void) | |
4649 | { | |
4650 | struct breakpoint *b, *temp; | |
4651 | ||
4652 | ALL_BREAKPOINTS_SAFE (b, temp) | |
4653 | if (b->type == bp_thread_event) | |
4654 | delete_breakpoint (b); | |
4655 | } | |
4656 | ||
0101ce28 JJ |
4657 | struct captured_parse_breakpoint_args |
4658 | { | |
4659 | char **arg_p; | |
4660 | struct symtabs_and_lines *sals_p; | |
4661 | char ***addr_string_p; | |
4662 | int *not_found_ptr; | |
4663 | }; | |
4664 | ||
4665 | struct lang_and_radix | |
4666 | { | |
4667 | enum language lang; | |
4668 | int radix; | |
4669 | }; | |
4670 | ||
4efc6507 DE |
4671 | /* Create a breakpoint for JIT code registration and unregistration. */ |
4672 | ||
4673 | struct breakpoint * | |
4674 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
4675 | { | |
4676 | struct breakpoint *b; | |
4677 | ||
4678 | b = create_internal_breakpoint (gdbarch, address, bp_jit_event); | |
4679 | update_global_location_list_nothrow (1); | |
4680 | return b; | |
4681 | } | |
0101ce28 | 4682 | |
cae688ec JJ |
4683 | void |
4684 | remove_solib_event_breakpoints (void) | |
4685 | { | |
4686 | struct breakpoint *b, *temp; | |
4687 | ||
4688 | ALL_BREAKPOINTS_SAFE (b, temp) | |
4689 | if (b->type == bp_shlib_event) | |
4690 | delete_breakpoint (b); | |
4691 | } | |
4692 | ||
4693 | struct breakpoint * | |
a6d9a66e | 4694 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
cae688ec JJ |
4695 | { |
4696 | struct breakpoint *b; | |
4697 | ||
a6d9a66e | 4698 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event); |
b60e7edf | 4699 | update_global_location_list_nothrow (1); |
cae688ec JJ |
4700 | return b; |
4701 | } | |
4702 | ||
4703 | /* Disable any breakpoints that are on code in shared libraries. Only | |
4704 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
4705 | ||
4706 | void | |
cb851954 | 4707 | disable_breakpoints_in_shlibs (void) |
cae688ec | 4708 | { |
0d381245 | 4709 | struct bp_location *loc; |
cae688ec | 4710 | |
0d381245 | 4711 | ALL_BP_LOCATIONS (loc) |
cae688ec | 4712 | { |
0d381245 VP |
4713 | struct breakpoint *b = loc->owner; |
4714 | /* We apply the check to all breakpoints, including disabled | |
4715 | for those with loc->duplicate set. This is so that when breakpoint | |
4716 | becomes enabled, or the duplicate is removed, gdb will try to insert | |
4717 | all breakpoints. If we don't set shlib_disabled here, we'll try | |
4718 | to insert those breakpoints and fail. */ | |
1042e4c0 SS |
4719 | if (((b->type == bp_breakpoint) |
4720 | || (b->type == bp_hardware_breakpoint) | |
4721 | || (b->type == bp_tracepoint)) | |
0d381245 | 4722 | && !loc->shlib_disabled |
a77053c2 | 4723 | #ifdef PC_SOLIB |
0d381245 | 4724 | && PC_SOLIB (loc->address) |
a77053c2 | 4725 | #else |
f5c9a895 | 4726 | && solib_name_from_address (loc->address) |
a77053c2 MK |
4727 | #endif |
4728 | ) | |
0d381245 VP |
4729 | { |
4730 | loc->shlib_disabled = 1; | |
4731 | } | |
cae688ec JJ |
4732 | } |
4733 | } | |
4734 | ||
84acb35a JJ |
4735 | /* Disable any breakpoints that are in in an unloaded shared library. Only |
4736 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
4737 | ||
75149521 | 4738 | static void |
84acb35a JJ |
4739 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
4740 | { | |
0d381245 | 4741 | struct bp_location *loc; |
84acb35a JJ |
4742 | int disabled_shlib_breaks = 0; |
4743 | ||
c86cf029 VP |
4744 | /* SunOS a.out shared libraries are always mapped, so do not |
4745 | disable breakpoints; they will only be reported as unloaded | |
4746 | through clear_solib when GDB discards its shared library | |
4747 | list. See clear_solib for more information. */ | |
4748 | if (exec_bfd != NULL | |
4749 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) | |
4750 | return; | |
4751 | ||
0d381245 | 4752 | ALL_BP_LOCATIONS (loc) |
84acb35a | 4753 | { |
0d381245 VP |
4754 | struct breakpoint *b = loc->owner; |
4755 | if ((loc->loc_type == bp_loc_hardware_breakpoint | |
4756 | || loc->loc_type == bp_loc_software_breakpoint) | |
e2dd7057 PP |
4757 | && !loc->shlib_disabled |
4758 | && (b->type == bp_breakpoint || b->type == bp_hardware_breakpoint) | |
4759 | && solib_contains_address_p (solib, loc->address)) | |
84acb35a | 4760 | { |
e2dd7057 PP |
4761 | loc->shlib_disabled = 1; |
4762 | /* At this point, we cannot rely on remove_breakpoint | |
4763 | succeeding so we must mark the breakpoint as not inserted | |
4764 | to prevent future errors occurring in remove_breakpoints. */ | |
4765 | loc->inserted = 0; | |
4766 | if (!disabled_shlib_breaks) | |
4767 | { | |
4768 | target_terminal_ours_for_output (); | |
4769 | warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""), | |
4770 | solib->so_name); | |
84acb35a | 4771 | } |
e2dd7057 | 4772 | disabled_shlib_breaks = 1; |
84acb35a JJ |
4773 | } |
4774 | } | |
84acb35a JJ |
4775 | } |
4776 | ||
ce78b96d JB |
4777 | /* FORK & VFORK catchpoints. */ |
4778 | ||
4779 | /* Implement the "insert" breakpoint_ops method for fork catchpoints. */ | |
4780 | ||
c906108c | 4781 | static void |
ce78b96d JB |
4782 | insert_catch_fork (struct breakpoint *b) |
4783 | { | |
4784 | target_insert_fork_catchpoint (PIDGET (inferior_ptid)); | |
4785 | } | |
4786 | ||
4787 | /* Implement the "remove" breakpoint_ops method for fork catchpoints. */ | |
4788 | ||
4789 | static int | |
4790 | remove_catch_fork (struct breakpoint *b) | |
4791 | { | |
4792 | return target_remove_fork_catchpoint (PIDGET (inferior_ptid)); | |
4793 | } | |
4794 | ||
4795 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
4796 | catchpoints. */ | |
4797 | ||
4798 | static int | |
4799 | breakpoint_hit_catch_fork (struct breakpoint *b) | |
4800 | { | |
4801 | return inferior_has_forked (inferior_ptid, &b->forked_inferior_pid); | |
4802 | } | |
4803 | ||
4804 | /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */ | |
4805 | ||
4806 | static enum print_stop_action | |
4807 | print_it_catch_fork (struct breakpoint *b) | |
4808 | { | |
4809 | annotate_catchpoint (b->number); | |
4810 | printf_filtered (_("\nCatchpoint %d (forked process %d), "), | |
4811 | b->number, ptid_get_pid (b->forked_inferior_pid)); | |
4812 | return PRINT_SRC_AND_LOC; | |
4813 | } | |
4814 | ||
4815 | /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */ | |
4816 | ||
4817 | static void | |
a6d9a66e | 4818 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 4819 | { |
79a45b7d TT |
4820 | struct value_print_options opts; |
4821 | ||
4822 | get_user_print_options (&opts); | |
4823 | ||
ce78b96d JB |
4824 | /* Field 4, the address, is omitted (which makes the columns |
4825 | not line up too nicely with the headers, but the effect | |
4826 | is relatively readable). */ | |
79a45b7d | 4827 | if (opts.addressprint) |
ce78b96d JB |
4828 | ui_out_field_skip (uiout, "addr"); |
4829 | annotate_field (5); | |
4830 | ui_out_text (uiout, "fork"); | |
4831 | if (!ptid_equal (b->forked_inferior_pid, null_ptid)) | |
4832 | { | |
4833 | ui_out_text (uiout, ", process "); | |
4834 | ui_out_field_int (uiout, "what", | |
4835 | ptid_get_pid (b->forked_inferior_pid)); | |
4836 | ui_out_spaces (uiout, 1); | |
4837 | } | |
4838 | } | |
4839 | ||
4840 | /* Implement the "print_mention" breakpoint_ops method for fork | |
4841 | catchpoints. */ | |
4842 | ||
4843 | static void | |
4844 | print_mention_catch_fork (struct breakpoint *b) | |
4845 | { | |
4846 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
4847 | } | |
4848 | ||
4849 | /* The breakpoint_ops structure to be used in fork catchpoints. */ | |
4850 | ||
4851 | static struct breakpoint_ops catch_fork_breakpoint_ops = | |
4852 | { | |
4853 | insert_catch_fork, | |
4854 | remove_catch_fork, | |
4855 | breakpoint_hit_catch_fork, | |
4856 | print_it_catch_fork, | |
4857 | print_one_catch_fork, | |
4858 | print_mention_catch_fork | |
4859 | }; | |
4860 | ||
4861 | /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */ | |
4862 | ||
4863 | static void | |
4864 | insert_catch_vfork (struct breakpoint *b) | |
4865 | { | |
4866 | target_insert_vfork_catchpoint (PIDGET (inferior_ptid)); | |
4867 | } | |
4868 | ||
4869 | /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */ | |
4870 | ||
4871 | static int | |
4872 | remove_catch_vfork (struct breakpoint *b) | |
4873 | { | |
4874 | return target_remove_vfork_catchpoint (PIDGET (inferior_ptid)); | |
4875 | } | |
4876 | ||
4877 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
4878 | catchpoints. */ | |
4879 | ||
4880 | static int | |
4881 | breakpoint_hit_catch_vfork (struct breakpoint *b) | |
4882 | { | |
4883 | return inferior_has_vforked (inferior_ptid, &b->forked_inferior_pid); | |
4884 | } | |
4885 | ||
4886 | /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */ | |
4887 | ||
4888 | static enum print_stop_action | |
4889 | print_it_catch_vfork (struct breakpoint *b) | |
4890 | { | |
4891 | annotate_catchpoint (b->number); | |
4892 | printf_filtered (_("\nCatchpoint %d (vforked process %d), "), | |
4893 | b->number, ptid_get_pid (b->forked_inferior_pid)); | |
4894 | return PRINT_SRC_AND_LOC; | |
4895 | } | |
4896 | ||
4897 | /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */ | |
4898 | ||
4899 | static void | |
a6d9a66e | 4900 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 4901 | { |
79a45b7d TT |
4902 | struct value_print_options opts; |
4903 | ||
4904 | get_user_print_options (&opts); | |
ce78b96d JB |
4905 | /* Field 4, the address, is omitted (which makes the columns |
4906 | not line up too nicely with the headers, but the effect | |
4907 | is relatively readable). */ | |
79a45b7d | 4908 | if (opts.addressprint) |
ce78b96d JB |
4909 | ui_out_field_skip (uiout, "addr"); |
4910 | annotate_field (5); | |
4911 | ui_out_text (uiout, "vfork"); | |
4912 | if (!ptid_equal (b->forked_inferior_pid, null_ptid)) | |
4913 | { | |
4914 | ui_out_text (uiout, ", process "); | |
4915 | ui_out_field_int (uiout, "what", | |
4916 | ptid_get_pid (b->forked_inferior_pid)); | |
4917 | ui_out_spaces (uiout, 1); | |
4918 | } | |
4919 | } | |
4920 | ||
4921 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
4922 | catchpoints. */ | |
4923 | ||
4924 | static void | |
4925 | print_mention_catch_vfork (struct breakpoint *b) | |
4926 | { | |
4927 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
4928 | } | |
4929 | ||
4930 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ | |
4931 | ||
4932 | static struct breakpoint_ops catch_vfork_breakpoint_ops = | |
4933 | { | |
4934 | insert_catch_vfork, | |
4935 | remove_catch_vfork, | |
4936 | breakpoint_hit_catch_vfork, | |
4937 | print_it_catch_vfork, | |
4938 | print_one_catch_vfork, | |
4939 | print_mention_catch_vfork | |
4940 | }; | |
4941 | ||
4942 | /* Create a new breakpoint of the bp_catchpoint kind and return it. | |
4943 | ||
4944 | If TEMPFLAG is non-zero, then make the breakpoint temporary. | |
4945 | If COND_STRING is not NULL, then store it in the breakpoint. | |
4946 | OPS, if not NULL, is the breakpoint_ops structure associated | |
4947 | to the catchpoint. */ | |
4948 | ||
4949 | static struct breakpoint * | |
a6d9a66e UW |
4950 | create_catchpoint (struct gdbarch *gdbarch, int tempflag, |
4951 | char *cond_string, struct breakpoint_ops *ops) | |
c906108c | 4952 | { |
c5aa993b JM |
4953 | struct symtab_and_line sal; |
4954 | struct breakpoint *b; | |
c5aa993b | 4955 | |
fe39c653 | 4956 | init_sal (&sal); |
c906108c SS |
4957 | sal.pc = 0; |
4958 | sal.symtab = NULL; | |
4959 | sal.line = 0; | |
c5aa993b | 4960 | |
a6d9a66e | 4961 | b = set_raw_breakpoint (gdbarch, sal, bp_catchpoint); |
c906108c SS |
4962 | set_breakpoint_count (breakpoint_count + 1); |
4963 | b->number = breakpoint_count; | |
ce78b96d | 4964 | |
1b36a34b | 4965 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
ce78b96d | 4966 | b->thread = -1; |
c906108c | 4967 | b->addr_string = NULL; |
b5de0fa7 EZ |
4968 | b->enable_state = bp_enabled; |
4969 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
ce78b96d | 4970 | b->ops = ops; |
c5aa993b | 4971 | |
c906108c | 4972 | mention (b); |
ce78b96d | 4973 | update_global_location_list (1); |
c906108c | 4974 | |
ce78b96d | 4975 | return b; |
c906108c | 4976 | } |
c5aa993b | 4977 | |
9b70b993 | 4978 | static void |
a6d9a66e UW |
4979 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
4980 | int tempflag, char *cond_string, | |
ce78b96d | 4981 | struct breakpoint_ops *ops) |
c906108c | 4982 | { |
a6d9a66e UW |
4983 | struct breakpoint *b |
4984 | = create_catchpoint (gdbarch, tempflag, cond_string, ops); | |
ce78b96d JB |
4985 | |
4986 | /* FIXME: We should put this information in a breakpoint private data | |
4987 | area. */ | |
4988 | b->forked_inferior_pid = null_ptid; | |
c906108c SS |
4989 | } |
4990 | ||
fe798b75 JB |
4991 | /* Exec catchpoints. */ |
4992 | ||
9b70b993 | 4993 | static void |
fe798b75 | 4994 | insert_catch_exec (struct breakpoint *b) |
c906108c | 4995 | { |
fe798b75 JB |
4996 | target_insert_exec_catchpoint (PIDGET (inferior_ptid)); |
4997 | } | |
c906108c | 4998 | |
fe798b75 JB |
4999 | static int |
5000 | remove_catch_exec (struct breakpoint *b) | |
5001 | { | |
5002 | return target_remove_exec_catchpoint (PIDGET (inferior_ptid)); | |
5003 | } | |
c906108c | 5004 | |
fe798b75 JB |
5005 | static int |
5006 | breakpoint_hit_catch_exec (struct breakpoint *b) | |
5007 | { | |
5008 | return inferior_has_execd (inferior_ptid, &b->exec_pathname); | |
5009 | } | |
c906108c | 5010 | |
fe798b75 JB |
5011 | static enum print_stop_action |
5012 | print_it_catch_exec (struct breakpoint *b) | |
5013 | { | |
5014 | annotate_catchpoint (b->number); | |
5015 | printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b->number, | |
5016 | b->exec_pathname); | |
5017 | return PRINT_SRC_AND_LOC; | |
c906108c SS |
5018 | } |
5019 | ||
fe798b75 | 5020 | static void |
a6d9a66e | 5021 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 JB |
5022 | { |
5023 | struct value_print_options opts; | |
5024 | ||
5025 | get_user_print_options (&opts); | |
5026 | ||
5027 | /* Field 4, the address, is omitted (which makes the columns | |
5028 | not line up too nicely with the headers, but the effect | |
5029 | is relatively readable). */ | |
5030 | if (opts.addressprint) | |
5031 | ui_out_field_skip (uiout, "addr"); | |
5032 | annotate_field (5); | |
5033 | ui_out_text (uiout, "exec"); | |
5034 | if (b->exec_pathname != NULL) | |
5035 | { | |
5036 | ui_out_text (uiout, ", program \""); | |
5037 | ui_out_field_string (uiout, "what", b->exec_pathname); | |
5038 | ui_out_text (uiout, "\" "); | |
5039 | } | |
5040 | } | |
5041 | ||
5042 | static void | |
5043 | print_mention_catch_exec (struct breakpoint *b) | |
5044 | { | |
5045 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
5046 | } | |
5047 | ||
5048 | static struct breakpoint_ops catch_exec_breakpoint_ops = | |
5049 | { | |
5050 | insert_catch_exec, | |
5051 | remove_catch_exec, | |
5052 | breakpoint_hit_catch_exec, | |
5053 | print_it_catch_exec, | |
5054 | print_one_catch_exec, | |
5055 | print_mention_catch_exec | |
5056 | }; | |
5057 | ||
c906108c | 5058 | static int |
fba45db2 | 5059 | hw_breakpoint_used_count (void) |
c906108c | 5060 | { |
52f0bd74 | 5061 | struct breakpoint *b; |
c906108c SS |
5062 | int i = 0; |
5063 | ||
5064 | ALL_BREAKPOINTS (b) | |
c5aa993b | 5065 | { |
d6b74ac4 | 5066 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
c5aa993b JM |
5067 | i++; |
5068 | } | |
c906108c SS |
5069 | |
5070 | return i; | |
5071 | } | |
5072 | ||
5073 | static int | |
fba45db2 | 5074 | hw_watchpoint_used_count (enum bptype type, int *other_type_used) |
c906108c | 5075 | { |
52f0bd74 | 5076 | struct breakpoint *b; |
c906108c SS |
5077 | int i = 0; |
5078 | ||
5079 | *other_type_used = 0; | |
5080 | ALL_BREAKPOINTS (b) | |
c5aa993b | 5081 | { |
468d015d | 5082 | if (breakpoint_enabled (b)) |
c5aa993b JM |
5083 | { |
5084 | if (b->type == type) | |
5085 | i++; | |
059fb39f PM |
5086 | else if ((b->type == bp_hardware_watchpoint |
5087 | || b->type == bp_read_watchpoint | |
5088 | || b->type == bp_access_watchpoint)) | |
c5aa993b JM |
5089 | *other_type_used = 1; |
5090 | } | |
5091 | } | |
c906108c SS |
5092 | return i; |
5093 | } | |
5094 | ||
c906108c | 5095 | void |
fba45db2 | 5096 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 5097 | { |
c5aa993b | 5098 | struct breakpoint *b; |
c906108c SS |
5099 | |
5100 | ALL_BREAKPOINTS (b) | |
c5aa993b JM |
5101 | { |
5102 | if (((b->type == bp_watchpoint) | |
5103 | || (b->type == bp_hardware_watchpoint) | |
5104 | || (b->type == bp_read_watchpoint) | |
dfdfb3ca | 5105 | || (b->type == bp_access_watchpoint)) |
468d015d | 5106 | && breakpoint_enabled (b)) |
c5aa993b | 5107 | { |
b5de0fa7 | 5108 | b->enable_state = bp_call_disabled; |
b60e7edf | 5109 | update_global_location_list (0); |
c5aa993b JM |
5110 | } |
5111 | } | |
c906108c SS |
5112 | } |
5113 | ||
5114 | void | |
fba45db2 | 5115 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 5116 | { |
c5aa993b | 5117 | struct breakpoint *b; |
c906108c SS |
5118 | |
5119 | ALL_BREAKPOINTS (b) | |
c5aa993b JM |
5120 | { |
5121 | if (((b->type == bp_watchpoint) | |
5122 | || (b->type == bp_hardware_watchpoint) | |
5123 | || (b->type == bp_read_watchpoint) | |
dfdfb3ca | 5124 | || (b->type == bp_access_watchpoint)) |
b5de0fa7 | 5125 | && (b->enable_state == bp_call_disabled)) |
c5aa993b | 5126 | { |
b5de0fa7 | 5127 | b->enable_state = bp_enabled; |
b60e7edf | 5128 | update_global_location_list (1); |
c5aa993b JM |
5129 | } |
5130 | } | |
c906108c SS |
5131 | } |
5132 | ||
8bea4e01 UW |
5133 | void |
5134 | disable_breakpoints_before_startup (void) | |
5135 | { | |
5136 | struct breakpoint *b; | |
5137 | int found = 0; | |
5138 | ||
5139 | ALL_BREAKPOINTS (b) | |
5140 | { | |
5141 | if ((b->type == bp_breakpoint | |
5142 | || b->type == bp_hardware_breakpoint) | |
5143 | && breakpoint_enabled (b)) | |
5144 | { | |
5145 | b->enable_state = bp_startup_disabled; | |
5146 | found = 1; | |
5147 | } | |
5148 | } | |
5149 | ||
5150 | if (found) | |
5151 | update_global_location_list (0); | |
5152 | ||
5153 | executing_startup = 1; | |
5154 | } | |
5155 | ||
5156 | void | |
5157 | enable_breakpoints_after_startup (void) | |
5158 | { | |
5159 | struct breakpoint *b; | |
5160 | int found = 0; | |
5161 | ||
5162 | executing_startup = 0; | |
5163 | ||
5164 | ALL_BREAKPOINTS (b) | |
5165 | { | |
5166 | if ((b->type == bp_breakpoint | |
5167 | || b->type == bp_hardware_breakpoint) | |
5168 | && b->enable_state == bp_startup_disabled) | |
5169 | { | |
5170 | b->enable_state = bp_enabled; | |
5171 | found = 1; | |
5172 | } | |
5173 | } | |
5174 | ||
5175 | if (found) | |
5176 | breakpoint_re_set (); | |
5177 | } | |
5178 | ||
c906108c SS |
5179 | |
5180 | /* Set a breakpoint that will evaporate an end of command | |
5181 | at address specified by SAL. | |
5182 | Restrict it to frame FRAME if FRAME is nonzero. */ | |
5183 | ||
5184 | struct breakpoint * | |
a6d9a66e UW |
5185 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
5186 | struct frame_id frame_id, enum bptype type) | |
c906108c | 5187 | { |
52f0bd74 | 5188 | struct breakpoint *b; |
edb3359d DJ |
5189 | |
5190 | /* If FRAME_ID is valid, it should be a real frame, not an inlined | |
5191 | one. */ | |
5192 | gdb_assert (!frame_id_inlined_p (frame_id)); | |
5193 | ||
a6d9a66e | 5194 | b = set_raw_breakpoint (gdbarch, sal, type); |
b5de0fa7 EZ |
5195 | b->enable_state = bp_enabled; |
5196 | b->disposition = disp_donttouch; | |
818dd999 | 5197 | b->frame_id = frame_id; |
c906108c SS |
5198 | |
5199 | /* If we're debugging a multi-threaded program, then we | |
5200 | want momentary breakpoints to be active in only a | |
5201 | single thread of control. */ | |
39f77062 KB |
5202 | if (in_thread_list (inferior_ptid)) |
5203 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c | 5204 | |
b60e7edf | 5205 | update_global_location_list_nothrow (1); |
74960c60 | 5206 | |
c906108c SS |
5207 | return b; |
5208 | } | |
611c83ae | 5209 | |
e58b0e63 PA |
5210 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
5211 | ORIG is NULL. */ | |
5212 | ||
5213 | struct breakpoint * | |
5214 | clone_momentary_breakpoint (struct breakpoint *orig) | |
5215 | { | |
5216 | struct breakpoint *copy; | |
5217 | ||
5218 | /* If there's nothing to clone, then return nothing. */ | |
5219 | if (orig == NULL) | |
5220 | return NULL; | |
5221 | ||
a6d9a66e | 5222 | copy = set_raw_breakpoint_without_location (orig->gdbarch, orig->type); |
e58b0e63 PA |
5223 | copy->loc = allocate_bp_location (copy); |
5224 | set_breakpoint_location_function (copy->loc); | |
5225 | ||
a6d9a66e | 5226 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
5227 | copy->loc->requested_address = orig->loc->requested_address; |
5228 | copy->loc->address = orig->loc->address; | |
5229 | copy->loc->section = orig->loc->section; | |
5230 | ||
5231 | if (orig->source_file == NULL) | |
5232 | copy->source_file = NULL; | |
5233 | else | |
5234 | copy->source_file = xstrdup (orig->source_file); | |
5235 | ||
5236 | copy->line_number = orig->line_number; | |
5237 | copy->frame_id = orig->frame_id; | |
5238 | copy->thread = orig->thread; | |
5239 | ||
5240 | copy->enable_state = bp_enabled; | |
5241 | copy->disposition = disp_donttouch; | |
5242 | copy->number = internal_breakpoint_number--; | |
5243 | ||
5244 | update_global_location_list_nothrow (0); | |
5245 | return copy; | |
5246 | } | |
5247 | ||
611c83ae | 5248 | struct breakpoint * |
a6d9a66e UW |
5249 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
5250 | enum bptype type) | |
611c83ae PA |
5251 | { |
5252 | struct symtab_and_line sal; | |
5253 | ||
5254 | sal = find_pc_line (pc, 0); | |
5255 | sal.pc = pc; | |
5256 | sal.section = find_pc_overlay (pc); | |
5257 | sal.explicit_pc = 1; | |
5258 | ||
a6d9a66e | 5259 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 5260 | } |
c906108c | 5261 | \f |
c5aa993b | 5262 | |
c906108c SS |
5263 | /* Tell the user we have just set a breakpoint B. */ |
5264 | ||
5265 | static void | |
fba45db2 | 5266 | mention (struct breakpoint *b) |
c906108c SS |
5267 | { |
5268 | int say_where = 0; | |
fa8a61dc | 5269 | struct cleanup *ui_out_chain; |
79a45b7d TT |
5270 | struct value_print_options opts; |
5271 | ||
5272 | get_user_print_options (&opts); | |
8b93c638 | 5273 | |
9a4105ab AC |
5274 | /* FIXME: This is misplaced; mention() is called by things (like |
5275 | hitting a watchpoint) other than breakpoint creation. It should | |
5276 | be possible to clean this up and at the same time replace the | |
7f4b89d1 | 5277 | random calls to breakpoint_changed with this hook. */ |
383f836e | 5278 | observer_notify_breakpoint_created (b->number); |
c906108c | 5279 | |
3086aeae DJ |
5280 | if (b->ops != NULL && b->ops->print_mention != NULL) |
5281 | b->ops->print_mention (b); | |
5282 | else | |
5283 | switch (b->type) | |
5284 | { | |
5285 | case bp_none: | |
a3f17187 | 5286 | printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b->number); |
3086aeae DJ |
5287 | break; |
5288 | case bp_watchpoint: | |
5289 | ui_out_text (uiout, "Watchpoint "); | |
5290 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
5291 | ui_out_field_int (uiout, "number", b->number); | |
5292 | ui_out_text (uiout, ": "); | |
fa8a61dc | 5293 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
5294 | do_cleanups (ui_out_chain); |
5295 | break; | |
5296 | case bp_hardware_watchpoint: | |
5297 | ui_out_text (uiout, "Hardware watchpoint "); | |
5298 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
5299 | ui_out_field_int (uiout, "number", b->number); | |
5300 | ui_out_text (uiout, ": "); | |
fa8a61dc | 5301 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
5302 | do_cleanups (ui_out_chain); |
5303 | break; | |
5304 | case bp_read_watchpoint: | |
5305 | ui_out_text (uiout, "Hardware read watchpoint "); | |
5306 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
5307 | ui_out_field_int (uiout, "number", b->number); | |
5308 | ui_out_text (uiout, ": "); | |
fa8a61dc | 5309 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
5310 | do_cleanups (ui_out_chain); |
5311 | break; | |
5312 | case bp_access_watchpoint: | |
5313 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
5314 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
5315 | ui_out_field_int (uiout, "number", b->number); | |
5316 | ui_out_text (uiout, ": "); | |
fa8a61dc | 5317 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
5318 | do_cleanups (ui_out_chain); |
5319 | break; | |
5320 | case bp_breakpoint: | |
5321 | if (ui_out_is_mi_like_p (uiout)) | |
5322 | { | |
5323 | say_where = 0; | |
5324 | break; | |
5325 | } | |
2cec12e5 AR |
5326 | if (b->disposition == disp_del) |
5327 | printf_filtered (_("Temporary breakpoint")); | |
5328 | else | |
5329 | printf_filtered (_("Breakpoint")); | |
5330 | printf_filtered (_(" %d"), b->number); | |
3086aeae DJ |
5331 | say_where = 1; |
5332 | break; | |
5333 | case bp_hardware_breakpoint: | |
5334 | if (ui_out_is_mi_like_p (uiout)) | |
5335 | { | |
5336 | say_where = 0; | |
5337 | break; | |
5338 | } | |
a3f17187 | 5339 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); |
3086aeae DJ |
5340 | say_where = 1; |
5341 | break; | |
1042e4c0 SS |
5342 | case bp_tracepoint: |
5343 | if (ui_out_is_mi_like_p (uiout)) | |
5344 | { | |
5345 | say_where = 0; | |
5346 | break; | |
5347 | } | |
5348 | printf_filtered (_("Tracepoint")); | |
5349 | printf_filtered (_(" %d"), b->number); | |
5350 | say_where = 1; | |
5351 | break; | |
3086aeae DJ |
5352 | |
5353 | case bp_until: | |
5354 | case bp_finish: | |
5355 | case bp_longjmp: | |
5356 | case bp_longjmp_resume: | |
5357 | case bp_step_resume: | |
3086aeae DJ |
5358 | case bp_call_dummy: |
5359 | case bp_watchpoint_scope: | |
5360 | case bp_shlib_event: | |
5361 | case bp_thread_event: | |
5362 | case bp_overlay_event: | |
4efc6507 | 5363 | case bp_jit_event: |
0fd8e87f | 5364 | case bp_longjmp_master: |
3086aeae DJ |
5365 | break; |
5366 | } | |
c906108c | 5367 | |
c906108c SS |
5368 | if (say_where) |
5369 | { | |
a3f17187 AC |
5370 | /* i18n: cagney/2005-02-11: Below needs to be merged into a |
5371 | single string. */ | |
0d381245 | 5372 | if (b->loc == NULL) |
c906108c | 5373 | { |
a3f17187 | 5374 | printf_filtered (_(" (%s) pending."), b->addr_string); |
0101ce28 JJ |
5375 | } |
5376 | else | |
5377 | { | |
79a45b7d | 5378 | if (opts.addressprint || b->source_file == NULL) |
0101ce28 JJ |
5379 | { |
5380 | printf_filtered (" at "); | |
5af949e3 UW |
5381 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), |
5382 | gdb_stdout); | |
0101ce28 JJ |
5383 | } |
5384 | if (b->source_file) | |
5385 | printf_filtered (": file %s, line %d.", | |
5386 | b->source_file, b->line_number); | |
0d381245 VP |
5387 | |
5388 | if (b->loc->next) | |
5389 | { | |
5390 | struct bp_location *loc = b->loc; | |
5391 | int n = 0; | |
5392 | for (; loc; loc = loc->next) | |
5393 | ++n; | |
5394 | printf_filtered (" (%d locations)", n); | |
5395 | } | |
5396 | ||
c906108c | 5397 | } |
c906108c | 5398 | } |
9dc5e2a9 | 5399 | if (ui_out_is_mi_like_p (uiout)) |
fb40c209 | 5400 | return; |
c906108c SS |
5401 | printf_filtered ("\n"); |
5402 | } | |
c906108c | 5403 | \f |
c5aa993b | 5404 | |
0d381245 | 5405 | static struct bp_location * |
39d61571 | 5406 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
5407 | const struct symtab_and_line *sal) |
5408 | { | |
5409 | struct bp_location *loc, **tmp; | |
5410 | ||
39d61571 | 5411 | loc = allocate_bp_location (b); |
0d381245 VP |
5412 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
5413 | ; | |
5414 | *tmp = loc; | |
a6d9a66e UW |
5415 | loc->gdbarch = get_sal_arch (*sal); |
5416 | if (!loc->gdbarch) | |
5417 | loc->gdbarch = b->gdbarch; | |
0d381245 | 5418 | loc->requested_address = sal->pc; |
a6d9a66e UW |
5419 | loc->address = adjust_breakpoint_address (loc->gdbarch, |
5420 | loc->requested_address, b->type); | |
0d381245 VP |
5421 | loc->section = sal->section; |
5422 | ||
5423 | set_breakpoint_location_function (loc); | |
5424 | return loc; | |
5425 | } | |
514f746b AR |
5426 | \f |
5427 | ||
5428 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
5429 | return 0 otherwise. */ | |
5430 | ||
5431 | static int | |
5432 | bp_loc_is_permanent (struct bp_location *loc) | |
5433 | { | |
5434 | int len; | |
5435 | CORE_ADDR addr; | |
5436 | const gdb_byte *brk; | |
5437 | gdb_byte *target_mem; | |
939c61fa JK |
5438 | struct cleanup *cleanup; |
5439 | int retval = 0; | |
514f746b AR |
5440 | |
5441 | gdb_assert (loc != NULL); | |
5442 | ||
5443 | addr = loc->address; | |
a6d9a66e | 5444 | brk = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len); |
514f746b | 5445 | |
939c61fa JK |
5446 | /* Software breakpoints unsupported? */ |
5447 | if (brk == NULL) | |
5448 | return 0; | |
5449 | ||
514f746b AR |
5450 | target_mem = alloca (len); |
5451 | ||
939c61fa JK |
5452 | /* Enable the automatic memory restoration from breakpoints while |
5453 | we read the memory. Otherwise we could say about our temporary | |
5454 | breakpoints they are permanent. */ | |
5455 | cleanup = make_show_memory_breakpoints_cleanup (0); | |
5456 | ||
514f746b AR |
5457 | if (target_read_memory (loc->address, target_mem, len) == 0 |
5458 | && memcmp (target_mem, brk, len) == 0) | |
939c61fa | 5459 | retval = 1; |
514f746b | 5460 | |
939c61fa JK |
5461 | do_cleanups (cleanup); |
5462 | ||
5463 | return retval; | |
514f746b AR |
5464 | } |
5465 | ||
5466 | ||
c3f6f71d | 5467 | |
018d34a4 VP |
5468 | /* Create a breakpoint with SAL as location. Use ADDR_STRING |
5469 | as textual description of the location, and COND_STRING | |
db107f19 | 5470 | as condition expression. */ |
018d34a4 VP |
5471 | |
5472 | static void | |
a6d9a66e UW |
5473 | create_breakpoint (struct gdbarch *gdbarch, |
5474 | struct symtabs_and_lines sals, char *addr_string, | |
018d34a4 VP |
5475 | char *cond_string, |
5476 | enum bptype type, enum bpdisp disposition, | |
4a306c9a | 5477 | int thread, int task, int ignore_count, |
41447f92 | 5478 | struct breakpoint_ops *ops, int from_tty, int enabled) |
018d34a4 | 5479 | { |
0d381245 VP |
5480 | struct breakpoint *b = NULL; |
5481 | int i; | |
018d34a4 VP |
5482 | |
5483 | if (type == bp_hardware_breakpoint) | |
5484 | { | |
5485 | int i = hw_breakpoint_used_count (); | |
5486 | int target_resources_ok = | |
d92524f1 | 5487 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
018d34a4 VP |
5488 | i + 1, 0); |
5489 | if (target_resources_ok == 0) | |
5490 | error (_("No hardware breakpoint support in the target.")); | |
5491 | else if (target_resources_ok < 0) | |
5492 | error (_("Hardware breakpoints used exceeds limit.")); | |
5493 | } | |
5494 | ||
0d381245 VP |
5495 | for (i = 0; i < sals.nelts; ++i) |
5496 | { | |
5497 | struct symtab_and_line sal = sals.sals[i]; | |
5498 | struct bp_location *loc; | |
5499 | ||
5500 | if (from_tty) | |
5af949e3 UW |
5501 | { |
5502 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
5503 | if (!loc_gdbarch) | |
5504 | loc_gdbarch = gdbarch; | |
5505 | ||
5506 | describe_other_breakpoints (loc_gdbarch, | |
5507 | sal.pc, sal.section, thread); | |
5508 | } | |
0d381245 VP |
5509 | |
5510 | if (i == 0) | |
5511 | { | |
a6d9a66e | 5512 | b = set_raw_breakpoint (gdbarch, sal, type); |
0d381245 VP |
5513 | set_breakpoint_count (breakpoint_count + 1); |
5514 | b->number = breakpoint_count; | |
5515 | b->thread = thread; | |
4a306c9a | 5516 | b->task = task; |
018d34a4 | 5517 | |
0d381245 VP |
5518 | b->cond_string = cond_string; |
5519 | b->ignore_count = ignore_count; | |
41447f92 | 5520 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 5521 | b->disposition = disposition; |
018d34a4 | 5522 | |
8bea4e01 UW |
5523 | if (enabled && executing_startup |
5524 | && (b->type == bp_breakpoint | |
5525 | || b->type == bp_hardware_breakpoint)) | |
5526 | b->enable_state = bp_startup_disabled; | |
5527 | ||
0d381245 VP |
5528 | loc = b->loc; |
5529 | } | |
5530 | else | |
018d34a4 | 5531 | { |
39d61571 | 5532 | loc = add_location_to_breakpoint (b, &sal); |
0d381245 VP |
5533 | } |
5534 | ||
514f746b AR |
5535 | if (bp_loc_is_permanent (loc)) |
5536 | make_breakpoint_permanent (b); | |
5537 | ||
0d381245 VP |
5538 | if (b->cond_string) |
5539 | { | |
5540 | char *arg = b->cond_string; | |
d32a6982 | 5541 | loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0); |
0d381245 | 5542 | if (*arg) |
db107f19 | 5543 | error (_("Garbage %s follows condition"), arg); |
018d34a4 | 5544 | } |
0d381245 | 5545 | } |
018d34a4 VP |
5546 | |
5547 | if (addr_string) | |
5548 | b->addr_string = addr_string; | |
5549 | else | |
5550 | /* addr_string has to be used or breakpoint_re_set will delete | |
5551 | me. */ | |
5af949e3 UW |
5552 | b->addr_string |
5553 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
018d34a4 | 5554 | |
604133b5 | 5555 | b->ops = ops; |
018d34a4 VP |
5556 | mention (b); |
5557 | } | |
5558 | ||
ed0616c6 VP |
5559 | /* Remove element at INDEX_TO_REMOVE from SAL, shifting other |
5560 | elements to fill the void space. */ | |
2c0b251b PA |
5561 | static void |
5562 | remove_sal (struct symtabs_and_lines *sal, int index_to_remove) | |
ed0616c6 VP |
5563 | { |
5564 | int i = index_to_remove+1; | |
5565 | int last_index = sal->nelts-1; | |
5566 | ||
5567 | for (;i <= last_index; ++i) | |
5568 | sal->sals[i-1] = sal->sals[i]; | |
5569 | ||
5570 | --(sal->nelts); | |
5571 | } | |
5572 | ||
5573 | /* If appropriate, obtains all sals that correspond | |
5574 | to the same file and line as SAL. This is done | |
5575 | only if SAL does not have explicit PC and has | |
5576 | line and file information. If we got just a single | |
5577 | expanded sal, return the original. | |
5578 | ||
5579 | Otherwise, if SAL.explicit_line is not set, filter out | |
5580 | all sals for which the name of enclosing function | |
5581 | is different from SAL. This makes sure that if we have | |
5582 | breakpoint originally set in template instantiation, say | |
5583 | foo<int>(), we won't expand SAL to locations at the same | |
5584 | line in all existing instantiations of 'foo'. | |
5585 | ||
5586 | */ | |
2c0b251b | 5587 | static struct symtabs_and_lines |
ed0616c6 VP |
5588 | expand_line_sal_maybe (struct symtab_and_line sal) |
5589 | { | |
5590 | struct symtabs_and_lines expanded; | |
5591 | CORE_ADDR original_pc = sal.pc; | |
5592 | char *original_function = NULL; | |
5593 | int found; | |
5594 | int i; | |
5595 | ||
5596 | /* If we have explicit pc, don't expand. | |
5597 | If we have no line number, we can't expand. */ | |
5598 | if (sal.explicit_pc || sal.line == 0 || sal.symtab == NULL) | |
5599 | { | |
5600 | expanded.nelts = 1; | |
5601 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
5602 | expanded.sals[0] = sal; | |
5603 | return expanded; | |
5604 | } | |
5605 | ||
5606 | sal.pc = 0; | |
5607 | find_pc_partial_function (original_pc, &original_function, NULL, NULL); | |
5608 | ||
5609 | expanded = expand_line_sal (sal); | |
5610 | if (expanded.nelts == 1) | |
5611 | { | |
5612 | /* We had one sal, we got one sal. Without futher | |
5613 | processing, just return the original sal. */ | |
5614 | xfree (expanded.sals); | |
5615 | expanded.nelts = 1; | |
5616 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
5617 | sal.pc = original_pc; | |
5618 | expanded.sals[0] = sal; | |
5619 | return expanded; | |
5620 | } | |
5621 | ||
5622 | if (!sal.explicit_line) | |
5623 | { | |
5624 | CORE_ADDR func_addr, func_end; | |
5625 | for (i = 0; i < expanded.nelts; ++i) | |
5626 | { | |
5627 | CORE_ADDR pc = expanded.sals[i].pc; | |
5628 | char *this_function; | |
5629 | if (find_pc_partial_function (pc, &this_function, | |
5630 | &func_addr, &func_end)) | |
5631 | { | |
059fb39f PM |
5632 | if (this_function |
5633 | && strcmp (this_function, original_function) != 0) | |
ed0616c6 VP |
5634 | { |
5635 | remove_sal (&expanded, i); | |
5636 | --i; | |
5637 | } | |
5638 | else if (func_addr == pc) | |
5639 | { | |
5640 | /* We're at beginning of a function, and should | |
5641 | skip prologue. */ | |
5642 | struct symbol *sym = find_pc_function (pc); | |
5643 | if (sym) | |
5644 | expanded.sals[i] = find_function_start_sal (sym, 1); | |
5645 | else | |
d80b854b UW |
5646 | { |
5647 | /* Since find_pc_partial_function returned true, | |
5648 | we should really always find the section here. */ | |
5649 | struct obj_section *section = find_pc_section (pc); | |
5650 | if (section) | |
5651 | { | |
5652 | struct gdbarch *gdbarch | |
5653 | = get_objfile_arch (section->objfile); | |
5654 | expanded.sals[i].pc | |
5655 | = gdbarch_skip_prologue (gdbarch, pc); | |
5656 | } | |
5657 | } | |
ed0616c6 VP |
5658 | } |
5659 | } | |
5660 | } | |
5661 | } | |
3daf8fe5 JG |
5662 | else |
5663 | { | |
5664 | for (i = 0; i < expanded.nelts; ++i) | |
5665 | { | |
5666 | /* If this SAL corresponds to a breakpoint inserted using a | |
5667 | line number, then skip the function prologue if necessary. */ | |
5668 | skip_prologue_sal (&expanded.sals[i]); | |
5669 | } | |
5670 | } | |
ed0616c6 VP |
5671 | |
5672 | ||
5673 | if (expanded.nelts <= 1) | |
5674 | { | |
5675 | /* This is un ugly workaround. If we get zero | |
5676 | expanded sals then something is really wrong. | |
5677 | Fix that by returnign the original sal. */ | |
5678 | xfree (expanded.sals); | |
5679 | expanded.nelts = 1; | |
5680 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
5681 | sal.pc = original_pc; | |
5682 | expanded.sals[0] = sal; | |
5683 | return expanded; | |
5684 | } | |
5685 | ||
5686 | if (original_pc) | |
5687 | { | |
5688 | found = 0; | |
5689 | for (i = 0; i < expanded.nelts; ++i) | |
5690 | if (expanded.sals[i].pc == original_pc) | |
5691 | { | |
5692 | found = 1; | |
5693 | break; | |
5694 | } | |
5695 | gdb_assert (found); | |
5696 | } | |
5697 | ||
5698 | return expanded; | |
5699 | } | |
5700 | ||
018d34a4 VP |
5701 | /* Add SALS.nelts breakpoints to the breakpoint table. For each |
5702 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
5703 | value. COND_STRING, if not NULL, specified the condition to be | |
5704 | used for all breakpoints. Essentially the only case where | |
5705 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
5706 | function. In that case, it's still not possible to specify | |
5707 | separate conditions for different overloaded functions, so | |
5708 | we take just a single condition string. | |
5709 | ||
c3f6f71d | 5710 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 5711 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
5712 | array contents). If the function fails (error() is called), the |
5713 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
5714 | COND and SALS arrays and each of those arrays contents. */ | |
c906108c SS |
5715 | |
5716 | static void | |
a6d9a66e UW |
5717 | create_breakpoints (struct gdbarch *gdbarch, |
5718 | struct symtabs_and_lines sals, char **addr_string, | |
018d34a4 | 5719 | char *cond_string, |
c3f6f71d | 5720 | enum bptype type, enum bpdisp disposition, |
4a306c9a | 5721 | int thread, int task, int ignore_count, |
41447f92 VP |
5722 | struct breakpoint_ops *ops, int from_tty, |
5723 | int enabled) | |
c906108c | 5724 | { |
018d34a4 VP |
5725 | int i; |
5726 | for (i = 0; i < sals.nelts; ++i) | |
c3f6f71d | 5727 | { |
ed0616c6 VP |
5728 | struct symtabs_and_lines expanded = |
5729 | expand_line_sal_maybe (sals.sals[i]); | |
0d381245 | 5730 | |
a6d9a66e | 5731 | create_breakpoint (gdbarch, expanded, addr_string[i], |
018d34a4 | 5732 | cond_string, type, disposition, |
4a306c9a | 5733 | thread, task, ignore_count, ops, from_tty, enabled); |
c3f6f71d | 5734 | } |
c3f6f71d | 5735 | } |
c906108c | 5736 | |
c3f6f71d JM |
5737 | /* Parse ARG which is assumed to be a SAL specification possibly |
5738 | followed by conditionals. On return, SALS contains an array of SAL | |
5739 | addresses found. ADDR_STRING contains a vector of (canonical) | |
5740 | address strings. ARG points to the end of the SAL. */ | |
c906108c | 5741 | |
b9362cc7 | 5742 | static void |
c3f6f71d JM |
5743 | parse_breakpoint_sals (char **address, |
5744 | struct symtabs_and_lines *sals, | |
0101ce28 JJ |
5745 | char ***addr_string, |
5746 | int *not_found_ptr) | |
c3f6f71d JM |
5747 | { |
5748 | char *addr_start = *address; | |
5749 | *addr_string = NULL; | |
5750 | /* If no arg given, or if first arg is 'if ', use the default | |
5751 | breakpoint. */ | |
5752 | if ((*address) == NULL | |
5753 | || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2]))) | |
c906108c SS |
5754 | { |
5755 | if (default_breakpoint_valid) | |
5756 | { | |
c3f6f71d | 5757 | struct symtab_and_line sal; |
fe39c653 | 5758 | init_sal (&sal); /* initialize to zeroes */ |
c3f6f71d | 5759 | sals->sals = (struct symtab_and_line *) |
c906108c SS |
5760 | xmalloc (sizeof (struct symtab_and_line)); |
5761 | sal.pc = default_breakpoint_address; | |
5762 | sal.line = default_breakpoint_line; | |
5763 | sal.symtab = default_breakpoint_symtab; | |
c5aa993b | 5764 | sal.section = find_pc_overlay (sal.pc); |
00903456 JK |
5765 | |
5766 | /* "break" without arguments is equivalent to "break *PC" where PC is | |
5767 | the default_breakpoint_address. So make sure to set | |
5768 | sal.explicit_pc to prevent GDB from trying to expand the list of | |
5769 | sals to include all other instances with the same symtab and line. | |
5770 | */ | |
5771 | sal.explicit_pc = 1; | |
5772 | ||
c3f6f71d JM |
5773 | sals->sals[0] = sal; |
5774 | sals->nelts = 1; | |
c906108c SS |
5775 | } |
5776 | else | |
8a3fe4f8 | 5777 | error (_("No default breakpoint address now.")); |
c906108c SS |
5778 | } |
5779 | else | |
5780 | { | |
c906108c | 5781 | /* Force almost all breakpoints to be in terms of the |
c5aa993b JM |
5782 | current_source_symtab (which is decode_line_1's default). This |
5783 | should produce the results we want almost all of the time while | |
1aeae86e AF |
5784 | leaving default_breakpoint_* alone. |
5785 | ObjC: However, don't match an Objective-C method name which | |
5786 | may have a '+' or '-' succeeded by a '[' */ | |
0378c332 | 5787 | |
c214a6fd | 5788 | struct symtab_and_line cursal = get_current_source_symtab_and_line (); |
0378c332 | 5789 | |
c906108c | 5790 | if (default_breakpoint_valid |
0378c332 | 5791 | && (!cursal.symtab |
1aeae86e AF |
5792 | || ((strchr ("+-", (*address)[0]) != NULL) |
5793 | && ((*address)[1] != '[')))) | |
c3f6f71d | 5794 | *sals = decode_line_1 (address, 1, default_breakpoint_symtab, |
0101ce28 JJ |
5795 | default_breakpoint_line, addr_string, |
5796 | not_found_ptr); | |
c906108c | 5797 | else |
0101ce28 JJ |
5798 | *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0, |
5799 | addr_string, not_found_ptr); | |
c906108c | 5800 | } |
c3f6f71d JM |
5801 | /* For any SAL that didn't have a canonical string, fill one in. */ |
5802 | if (sals->nelts > 0 && *addr_string == NULL) | |
5803 | *addr_string = xcalloc (sals->nelts, sizeof (char **)); | |
5804 | if (addr_start != (*address)) | |
c906108c | 5805 | { |
c3f6f71d JM |
5806 | int i; |
5807 | for (i = 0; i < sals->nelts; i++) | |
c906108c | 5808 | { |
c3f6f71d JM |
5809 | /* Add the string if not present. */ |
5810 | if ((*addr_string)[i] == NULL) | |
5811 | (*addr_string)[i] = savestring (addr_start, (*address) - addr_start); | |
c906108c SS |
5812 | } |
5813 | } | |
c3f6f71d | 5814 | } |
c906108c | 5815 | |
c906108c | 5816 | |
c3f6f71d JM |
5817 | /* Convert each SAL into a real PC. Verify that the PC can be |
5818 | inserted as a breakpoint. If it can't throw an error. */ | |
c906108c | 5819 | |
b9362cc7 | 5820 | static void |
c3f6f71d JM |
5821 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals, |
5822 | char *address) | |
5823 | { | |
5824 | int i; | |
5825 | for (i = 0; i < sals->nelts; i++) | |
ee53e872 | 5826 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
5827 | } |
5828 | ||
05ff989b | 5829 | static void |
0101ce28 JJ |
5830 | do_captured_parse_breakpoint (struct ui_out *ui, void *data) |
5831 | { | |
5832 | struct captured_parse_breakpoint_args *args = data; | |
5833 | ||
5834 | parse_breakpoint_sals (args->arg_p, args->sals_p, args->addr_string_p, | |
5835 | args->not_found_ptr); | |
0101ce28 JJ |
5836 | } |
5837 | ||
018d34a4 VP |
5838 | /* Given TOK, a string specification of condition and thread, as |
5839 | accepted by the 'break' command, extract the condition | |
5840 | string and thread number and set *COND_STRING and *THREAD. | |
5841 | PC identifies the context at which the condition should be parsed. | |
5842 | If no condition is found, *COND_STRING is set to NULL. | |
5843 | If no thread is found, *THREAD is set to -1. */ | |
5844 | static void | |
5845 | find_condition_and_thread (char *tok, CORE_ADDR pc, | |
4a306c9a | 5846 | char **cond_string, int *thread, int *task) |
018d34a4 VP |
5847 | { |
5848 | *cond_string = NULL; | |
5849 | *thread = -1; | |
5850 | while (tok && *tok) | |
5851 | { | |
5852 | char *end_tok; | |
5853 | int toklen; | |
5854 | char *cond_start = NULL; | |
5855 | char *cond_end = NULL; | |
5856 | while (*tok == ' ' || *tok == '\t') | |
5857 | tok++; | |
5858 | ||
5859 | end_tok = tok; | |
5860 | ||
5861 | while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') | |
5862 | end_tok++; | |
5863 | ||
5864 | toklen = end_tok - tok; | |
5865 | ||
5866 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
5867 | { | |
f7545552 TT |
5868 | struct expression *expr; |
5869 | ||
018d34a4 | 5870 | tok = cond_start = end_tok + 1; |
f7545552 TT |
5871 | expr = parse_exp_1 (&tok, block_for_pc (pc), 0); |
5872 | xfree (expr); | |
018d34a4 VP |
5873 | cond_end = tok; |
5874 | *cond_string = savestring (cond_start, | |
5875 | cond_end - cond_start); | |
5876 | } | |
5877 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
5878 | { | |
5879 | char *tmptok; | |
5880 | ||
5881 | tok = end_tok + 1; | |
5882 | tmptok = tok; | |
5883 | *thread = strtol (tok, &tok, 0); | |
5884 | if (tok == tmptok) | |
5885 | error (_("Junk after thread keyword.")); | |
5886 | if (!valid_thread_id (*thread)) | |
5887 | error (_("Unknown thread %d."), *thread); | |
5888 | } | |
4a306c9a JB |
5889 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
5890 | { | |
5891 | char *tmptok; | |
5892 | ||
5893 | tok = end_tok + 1; | |
5894 | tmptok = tok; | |
5895 | *task = strtol (tok, &tok, 0); | |
5896 | if (tok == tmptok) | |
5897 | error (_("Junk after task keyword.")); | |
5898 | if (!valid_task_id (*task)) | |
5899 | error (_("Unknown task %d\n"), *task); | |
5900 | } | |
018d34a4 VP |
5901 | else |
5902 | error (_("Junk at end of arguments.")); | |
5903 | } | |
5904 | } | |
5905 | ||
72b2ff0e VP |
5906 | /* Set a breakpoint. This function is shared between |
5907 | CLI and MI functions for setting a breakpoint. | |
5908 | This function has two major modes of operations, | |
5909 | selected by the PARSE_CONDITION_AND_THREAD parameter. | |
5910 | If non-zero, the function will parse arg, extracting | |
5911 | breakpoint location, address and thread. Otherwise, | |
5912 | ARG is just the location of breakpoint, with condition | |
5913 | and thread specified by the COND_STRING and THREAD | |
5914 | parameters. */ | |
0101ce28 | 5915 | |
98deb0da | 5916 | static void |
a6d9a66e UW |
5917 | break_command_really (struct gdbarch *gdbarch, |
5918 | char *arg, char *cond_string, int thread, | |
60c46647 | 5919 | int parse_condition_and_thread, |
1042e4c0 | 5920 | int tempflag, int hardwareflag, int traceflag, |
60c46647 VP |
5921 | int ignore_count, |
5922 | enum auto_boolean pending_break_support, | |
604133b5 | 5923 | struct breakpoint_ops *ops, |
41447f92 VP |
5924 | int from_tty, |
5925 | int enabled) | |
c3f6f71d | 5926 | { |
71fff37b | 5927 | struct gdb_exception e; |
c3f6f71d | 5928 | struct symtabs_and_lines sals; |
0101ce28 | 5929 | struct symtab_and_line pending_sal; |
0101ce28 JJ |
5930 | char *copy_arg; |
5931 | char *err_msg; | |
c3f6f71d JM |
5932 | char *addr_start = arg; |
5933 | char **addr_string; | |
5934 | struct cleanup *old_chain; | |
80c99de1 | 5935 | struct cleanup *bkpt_chain = NULL; |
0101ce28 | 5936 | struct captured_parse_breakpoint_args parse_args; |
05ff989b | 5937 | int i; |
0101ce28 | 5938 | int pending = 0; |
0101ce28 | 5939 | int not_found = 0; |
1042e4c0 | 5940 | enum bptype type_wanted; |
4a306c9a | 5941 | int task = 0; |
c3f6f71d | 5942 | |
c3f6f71d JM |
5943 | sals.sals = NULL; |
5944 | sals.nelts = 0; | |
5945 | addr_string = NULL; | |
c3f6f71d | 5946 | |
0101ce28 JJ |
5947 | parse_args.arg_p = &arg; |
5948 | parse_args.sals_p = &sals; | |
5949 | parse_args.addr_string_p = &addr_string; | |
5950 | parse_args.not_found_ptr = ¬_found; | |
5951 | ||
05ff989b AC |
5952 | e = catch_exception (uiout, do_captured_parse_breakpoint, |
5953 | &parse_args, RETURN_MASK_ALL); | |
0101ce28 JJ |
5954 | |
5955 | /* If caller is interested in rc value from parse, set value. */ | |
05ff989b | 5956 | switch (e.reason) |
0101ce28 | 5957 | { |
05ff989b | 5958 | case RETURN_QUIT: |
98deb0da | 5959 | throw_exception (e); |
05ff989b AC |
5960 | case RETURN_ERROR: |
5961 | switch (e.error) | |
0101ce28 | 5962 | { |
05ff989b | 5963 | case NOT_FOUND_ERROR: |
0101ce28 | 5964 | |
05ff989b AC |
5965 | /* If pending breakpoint support is turned off, throw |
5966 | error. */ | |
fa8d40ab JJ |
5967 | |
5968 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
5969 | throw_exception (e); |
5970 | ||
5971 | exception_print (gdb_stderr, e); | |
fa8d40ab | 5972 | |
05ff989b AC |
5973 | /* If pending breakpoint support is auto query and the user |
5974 | selects no, then simply return the error code. */ | |
059fb39f PM |
5975 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
5976 | && !nquery ("Make breakpoint pending on future shared library load? ")) | |
98deb0da | 5977 | return; |
fa8d40ab | 5978 | |
05ff989b AC |
5979 | /* At this point, either the user was queried about setting |
5980 | a pending breakpoint and selected yes, or pending | |
5981 | breakpoint behavior is on and thus a pending breakpoint | |
5982 | is defaulted on behalf of the user. */ | |
0101ce28 JJ |
5983 | copy_arg = xstrdup (addr_start); |
5984 | addr_string = ©_arg; | |
5985 | sals.nelts = 1; | |
5986 | sals.sals = &pending_sal; | |
5987 | pending_sal.pc = 0; | |
5988 | pending = 1; | |
05ff989b AC |
5989 | break; |
5990 | default: | |
98deb0da | 5991 | throw_exception (e); |
0101ce28 | 5992 | } |
05ff989b AC |
5993 | default: |
5994 | if (!sals.nelts) | |
98deb0da | 5995 | return; |
0101ce28 | 5996 | } |
c3f6f71d JM |
5997 | |
5998 | /* Create a chain of things that always need to be cleaned up. */ | |
5999 | old_chain = make_cleanup (null_cleanup, 0); | |
6000 | ||
0101ce28 JJ |
6001 | if (!pending) |
6002 | { | |
6003 | /* Make sure that all storage allocated to SALS gets freed. */ | |
6004 | make_cleanup (xfree, sals.sals); | |
6005 | ||
6006 | /* Cleanup the addr_string array but not its contents. */ | |
6007 | make_cleanup (xfree, addr_string); | |
6008 | } | |
c3f6f71d | 6009 | |
c3f6f71d JM |
6010 | /* ----------------------------- SNIP ----------------------------- |
6011 | Anything added to the cleanup chain beyond this point is assumed | |
6012 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
6013 | then the memory is not reclaimed. */ |
6014 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d JM |
6015 | |
6016 | /* Mark the contents of the addr_string for cleanup. These go on | |
80c99de1 | 6017 | the bkpt_chain and only occur if the breakpoint create fails. */ |
c3f6f71d JM |
6018 | for (i = 0; i < sals.nelts; i++) |
6019 | { | |
6020 | if (addr_string[i] != NULL) | |
b8c9b27d | 6021 | make_cleanup (xfree, addr_string[i]); |
c3f6f71d JM |
6022 | } |
6023 | ||
6024 | /* Resolve all line numbers to PC's and verify that the addresses | |
6025 | are ok for the target. */ | |
0101ce28 JJ |
6026 | if (!pending) |
6027 | breakpoint_sals_to_pc (&sals, addr_start); | |
c3f6f71d | 6028 | |
1042e4c0 SS |
6029 | type_wanted = (traceflag |
6030 | ? bp_tracepoint | |
6031 | : (hardwareflag ? bp_hardware_breakpoint : bp_breakpoint)); | |
6032 | ||
c3f6f71d JM |
6033 | /* Verify that condition can be parsed, before setting any |
6034 | breakpoints. Allocate a separate condition expression for each | |
6035 | breakpoint. */ | |
0101ce28 | 6036 | if (!pending) |
c3f6f71d | 6037 | { |
2f069f6f | 6038 | if (parse_condition_and_thread) |
72b2ff0e VP |
6039 | { |
6040 | /* Here we only parse 'arg' to separate condition | |
6041 | from thread number, so parsing in context of first | |
6042 | sal is OK. When setting the breakpoint we'll | |
6043 | re-parse it in context of each sal. */ | |
6044 | cond_string = NULL; | |
6045 | thread = -1; | |
4a306c9a JB |
6046 | find_condition_and_thread (arg, sals.sals[0].pc, &cond_string, |
6047 | &thread, &task); | |
72b2ff0e VP |
6048 | if (cond_string) |
6049 | make_cleanup (xfree, cond_string); | |
6050 | } | |
2f069f6f | 6051 | else |
72b2ff0e VP |
6052 | { |
6053 | /* Create a private copy of condition string. */ | |
6054 | if (cond_string) | |
6055 | { | |
6056 | cond_string = xstrdup (cond_string); | |
6057 | make_cleanup (xfree, cond_string); | |
6058 | } | |
6059 | } | |
a6d9a66e | 6060 | create_breakpoints (gdbarch, sals, addr_string, cond_string, type_wanted, |
0101ce28 | 6061 | tempflag ? disp_del : disp_donttouch, |
4a306c9a | 6062 | thread, task, ignore_count, ops, from_tty, enabled); |
c906108c | 6063 | } |
0101ce28 JJ |
6064 | else |
6065 | { | |
fe3f5fa8 | 6066 | struct symtab_and_line sal = {0}; |
0101ce28 JJ |
6067 | struct breakpoint *b; |
6068 | ||
0101ce28 JJ |
6069 | make_cleanup (xfree, copy_arg); |
6070 | ||
a6d9a66e | 6071 | b = set_raw_breakpoint_without_location (gdbarch, type_wanted); |
0101ce28 JJ |
6072 | set_breakpoint_count (breakpoint_count + 1); |
6073 | b->number = breakpoint_count; | |
72b2ff0e | 6074 | b->thread = -1; |
018d34a4 | 6075 | b->addr_string = addr_string[0]; |
72b2ff0e | 6076 | b->cond_string = NULL; |
0101ce28 | 6077 | b->ignore_count = ignore_count; |
0101ce28 | 6078 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 6079 | b->condition_not_parsed = 1; |
604133b5 | 6080 | b->ops = ops; |
41447f92 | 6081 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
74960c60 | 6082 | |
8bea4e01 UW |
6083 | if (enabled && executing_startup |
6084 | && (b->type == bp_breakpoint | |
6085 | || b->type == bp_hardware_breakpoint)) | |
6086 | b->enable_state = bp_startup_disabled; | |
6087 | ||
0101ce28 JJ |
6088 | mention (b); |
6089 | } | |
6090 | ||
c3f6f71d | 6091 | if (sals.nelts > 1) |
8a3fe4f8 AC |
6092 | warning (_("Multiple breakpoints were set.\n" |
6093 | "Use the \"delete\" command to delete unwanted breakpoints.")); | |
80c99de1 PA |
6094 | /* That's it. Discard the cleanups for data inserted into the |
6095 | breakpoint. */ | |
6096 | discard_cleanups (bkpt_chain); | |
6097 | /* But cleanup everything else. */ | |
c3f6f71d | 6098 | do_cleanups (old_chain); |
217dc9e2 | 6099 | |
80c99de1 | 6100 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
217dc9e2 | 6101 | update_global_location_list (1); |
c3f6f71d | 6102 | } |
c906108c | 6103 | |
72b2ff0e VP |
6104 | /* Set a breakpoint. |
6105 | ARG is a string describing breakpoint address, | |
6106 | condition, and thread. | |
6107 | FLAG specifies if a breakpoint is hardware on, | |
6108 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
6109 | and BP_TEMPFLAG. */ | |
6110 | ||
98deb0da | 6111 | static void |
72b2ff0e | 6112 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 6113 | { |
72b2ff0e VP |
6114 | int hardwareflag = flag & BP_HARDWAREFLAG; |
6115 | int tempflag = flag & BP_TEMPFLAG; | |
c3f6f71d | 6116 | |
a6d9a66e UW |
6117 | break_command_really (get_current_arch (), |
6118 | arg, | |
98deb0da | 6119 | NULL, 0, 1 /* parse arg */, |
1042e4c0 | 6120 | tempflag, hardwareflag, 0 /* traceflag */, |
98deb0da | 6121 | 0 /* Ignore count */, |
604133b5 AR |
6122 | pending_break_support, |
6123 | NULL /* breakpoint_ops */, | |
41447f92 VP |
6124 | from_tty, |
6125 | 1 /* enabled */); | |
c906108c SS |
6126 | } |
6127 | ||
72b2ff0e | 6128 | |
98deb0da | 6129 | void |
a6d9a66e UW |
6130 | set_breakpoint (struct gdbarch *gdbarch, |
6131 | char *address, char *condition, | |
c3f6f71d | 6132 | int hardwareflag, int tempflag, |
ce43223b | 6133 | int thread, int ignore_count, |
41447f92 | 6134 | int pending, int enabled) |
c3f6f71d | 6135 | { |
a6d9a66e UW |
6136 | break_command_really (gdbarch, |
6137 | address, condition, thread, | |
98deb0da | 6138 | 0 /* condition and thread are valid. */, |
1042e4c0 | 6139 | tempflag, hardwareflag, 0 /* traceflag */, |
98deb0da VP |
6140 | ignore_count, |
6141 | pending | |
6142 | ? AUTO_BOOLEAN_TRUE : AUTO_BOOLEAN_FALSE, | |
41447f92 | 6143 | NULL, 0, enabled); |
c3f6f71d JM |
6144 | } |
6145 | ||
6a048695 JB |
6146 | /* Adjust SAL to the first instruction past the function prologue. |
6147 | The end of the prologue is determined using the line table from | |
3daf8fe5 JG |
6148 | the debugging information. explicit_pc and explicit_line are |
6149 | not modified. | |
6a048695 JB |
6150 | |
6151 | If SAL is already past the prologue, then do nothing. */ | |
6152 | ||
6153 | static void | |
6154 | skip_prologue_sal (struct symtab_and_line *sal) | |
6155 | { | |
6156 | struct symbol *sym = find_pc_function (sal->pc); | |
6157 | struct symtab_and_line start_sal; | |
6158 | ||
6159 | if (sym == NULL) | |
6160 | return; | |
6161 | ||
6162 | start_sal = find_function_start_sal (sym, 1); | |
6163 | if (sal->pc < start_sal.pc) | |
3daf8fe5 JG |
6164 | { |
6165 | start_sal.explicit_line = sal->explicit_line; | |
6166 | start_sal.explicit_pc = sal->explicit_pc; | |
6167 | *sal = start_sal; | |
6168 | } | |
6a048695 | 6169 | } |
c3f6f71d | 6170 | |
c906108c SS |
6171 | /* Helper function for break_command_1 and disassemble_command. */ |
6172 | ||
6173 | void | |
fba45db2 | 6174 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
6175 | { |
6176 | CORE_ADDR pc; | |
6177 | ||
6178 | if (sal->pc == 0 && sal->symtab != NULL) | |
6179 | { | |
6180 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 6181 | error (_("No line %d in file \"%s\"."), |
c906108c SS |
6182 | sal->line, sal->symtab->filename); |
6183 | sal->pc = pc; | |
6a048695 JB |
6184 | |
6185 | /* If this SAL corresponds to a breakpoint inserted using | |
6186 | a line number, then skip the function prologue if necessary. */ | |
6187 | if (sal->explicit_line) | |
56ef84b1 TT |
6188 | { |
6189 | /* Preserve the original line number. */ | |
6190 | int saved_line = sal->line; | |
6191 | skip_prologue_sal (sal); | |
6192 | sal->line = saved_line; | |
6193 | } | |
c906108c SS |
6194 | } |
6195 | ||
6196 | if (sal->section == 0 && sal->symtab != NULL) | |
6197 | { | |
6198 | struct blockvector *bv; | |
c5aa993b JM |
6199 | struct block *b; |
6200 | struct symbol *sym; | |
c906108c | 6201 | |
801e3a5b | 6202 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab); |
c906108c SS |
6203 | if (bv != NULL) |
6204 | { | |
7f0df278 | 6205 | sym = block_linkage_function (b); |
c906108c SS |
6206 | if (sym != NULL) |
6207 | { | |
6208 | fixup_symbol_section (sym, sal->symtab->objfile); | |
714835d5 | 6209 | sal->section = SYMBOL_OBJ_SECTION (sym); |
c906108c SS |
6210 | } |
6211 | else | |
6212 | { | |
6213 | /* It really is worthwhile to have the section, so we'll just | |
c5aa993b JM |
6214 | have to look harder. This case can be executed if we have |
6215 | line numbers but no functions (as can happen in assembly | |
6216 | source). */ | |
c906108c | 6217 | |
c5aa993b | 6218 | struct minimal_symbol *msym; |
c906108c SS |
6219 | |
6220 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
6221 | if (msym) | |
714835d5 | 6222 | sal->section = SYMBOL_OBJ_SECTION (msym); |
c906108c SS |
6223 | } |
6224 | } | |
6225 | } | |
6226 | } | |
6227 | ||
6228 | void | |
fba45db2 | 6229 | break_command (char *arg, int from_tty) |
c906108c | 6230 | { |
db107f19 | 6231 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
6232 | } |
6233 | ||
c906108c | 6234 | void |
fba45db2 | 6235 | tbreak_command (char *arg, int from_tty) |
c906108c | 6236 | { |
db107f19 | 6237 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
6238 | } |
6239 | ||
c906108c | 6240 | static void |
fba45db2 | 6241 | hbreak_command (char *arg, int from_tty) |
c906108c | 6242 | { |
db107f19 | 6243 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
6244 | } |
6245 | ||
6246 | static void | |
fba45db2 | 6247 | thbreak_command (char *arg, int from_tty) |
c906108c | 6248 | { |
db107f19 | 6249 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
6250 | } |
6251 | ||
6252 | static void | |
fba45db2 | 6253 | stop_command (char *arg, int from_tty) |
c906108c | 6254 | { |
a3f17187 | 6255 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 6256 | Usage: stop in <function | address>\n\ |
a3f17187 | 6257 | stop at <line>\n")); |
c906108c SS |
6258 | } |
6259 | ||
6260 | static void | |
fba45db2 | 6261 | stopin_command (char *arg, int from_tty) |
c906108c SS |
6262 | { |
6263 | int badInput = 0; | |
6264 | ||
c5aa993b | 6265 | if (arg == (char *) NULL) |
c906108c SS |
6266 | badInput = 1; |
6267 | else if (*arg != '*') | |
6268 | { | |
6269 | char *argptr = arg; | |
6270 | int hasColon = 0; | |
6271 | ||
53a5351d JM |
6272 | /* look for a ':'. If this is a line number specification, then |
6273 | say it is bad, otherwise, it should be an address or | |
6274 | function/method name */ | |
c906108c | 6275 | while (*argptr && !hasColon) |
c5aa993b JM |
6276 | { |
6277 | hasColon = (*argptr == ':'); | |
6278 | argptr++; | |
6279 | } | |
c906108c SS |
6280 | |
6281 | if (hasColon) | |
c5aa993b | 6282 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 6283 | else |
c5aa993b | 6284 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
6285 | } |
6286 | ||
6287 | if (badInput) | |
a3f17187 | 6288 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 6289 | else |
db107f19 | 6290 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
6291 | } |
6292 | ||
6293 | static void | |
fba45db2 | 6294 | stopat_command (char *arg, int from_tty) |
c906108c SS |
6295 | { |
6296 | int badInput = 0; | |
6297 | ||
c5aa993b | 6298 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
6299 | badInput = 1; |
6300 | else | |
6301 | { | |
6302 | char *argptr = arg; | |
6303 | int hasColon = 0; | |
6304 | ||
6305 | /* look for a ':'. If there is a '::' then get out, otherwise | |
c5aa993b | 6306 | it is probably a line number. */ |
c906108c | 6307 | while (*argptr && !hasColon) |
c5aa993b JM |
6308 | { |
6309 | hasColon = (*argptr == ':'); | |
6310 | argptr++; | |
6311 | } | |
c906108c SS |
6312 | |
6313 | if (hasColon) | |
c5aa993b | 6314 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 6315 | else |
c5aa993b | 6316 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
6317 | } |
6318 | ||
6319 | if (badInput) | |
a3f17187 | 6320 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 6321 | else |
db107f19 | 6322 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
6323 | } |
6324 | ||
53a5351d JM |
6325 | /* accessflag: hw_write: watch write, |
6326 | hw_read: watch read, | |
6327 | hw_access: watch access (read or write) */ | |
c906108c | 6328 | static void |
fba45db2 | 6329 | watch_command_1 (char *arg, int accessflag, int from_tty) |
c906108c | 6330 | { |
a6d9a66e | 6331 | struct gdbarch *gdbarch = get_current_arch (); |
d983da9c | 6332 | struct breakpoint *b, *scope_breakpoint = NULL; |
c906108c SS |
6333 | struct symtab_and_line sal; |
6334 | struct expression *exp; | |
6335 | struct block *exp_valid_block; | |
6336 | struct value *val, *mark; | |
6337 | struct frame_info *frame; | |
c906108c SS |
6338 | char *exp_start = NULL; |
6339 | char *exp_end = NULL; | |
37e4754d | 6340 | char *tok, *id_tok_start, *end_tok; |
c906108c SS |
6341 | int toklen; |
6342 | char *cond_start = NULL; | |
6343 | char *cond_end = NULL; | |
6344 | struct expression *cond = NULL; | |
6345 | int i, other_type_used, target_resources_ok = 0; | |
6346 | enum bptype bp_type; | |
6347 | int mem_cnt = 0; | |
37e4754d | 6348 | int thread = -1; |
c906108c | 6349 | |
fe39c653 | 6350 | init_sal (&sal); /* initialize to zeroes */ |
c5aa993b | 6351 | |
37e4754d LM |
6352 | /* Make sure that we actually have parameters to parse. */ |
6353 | if (arg != NULL && arg[0] != '\0') | |
6354 | { | |
6355 | toklen = strlen (arg); /* Size of argument list. */ | |
6356 | ||
6357 | /* Points tok to the end of the argument list. */ | |
6358 | tok = arg + toklen - 1; | |
6359 | ||
6360 | /* Go backwards in the parameters list. Skip the last parameter. | |
6361 | If we're expecting a 'thread <thread_num>' parameter, this should | |
6362 | be the thread identifier. */ | |
6363 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
6364 | tok--; | |
6365 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
6366 | tok--; | |
6367 | ||
6368 | /* Points end_tok to the beginning of the last token. */ | |
6369 | id_tok_start = tok + 1; | |
6370 | ||
6371 | /* Go backwards in the parameters list. Skip one more parameter. | |
6372 | If we're expecting a 'thread <thread_num>' parameter, we should | |
6373 | reach a "thread" token. */ | |
6374 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
6375 | tok--; | |
6376 | ||
6377 | end_tok = tok; | |
6378 | ||
6379 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
6380 | tok--; | |
6381 | ||
6382 | /* Move the pointer forward to skip the whitespace and | |
6383 | calculate the length of the token. */ | |
6384 | tok++; | |
6385 | toklen = end_tok - tok; | |
6386 | ||
6387 | if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
6388 | { | |
6389 | /* At this point we've found a "thread" token, which means | |
6390 | the user is trying to set a watchpoint that triggers | |
6391 | only in a specific thread. */ | |
6392 | char *endp; | |
6393 | ||
6394 | /* Extract the thread ID from the next token. */ | |
6395 | thread = strtol (id_tok_start, &endp, 0); | |
6396 | ||
6397 | /* Check if the user provided a valid numeric value for the | |
6398 | thread ID. */ | |
6399 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
6400 | error (_("Invalid thread ID specification %s."), id_tok_start); | |
6401 | ||
6402 | /* Check if the thread actually exists. */ | |
6403 | if (!valid_thread_id (thread)) | |
6404 | error (_("Unknown thread %d."), thread); | |
6405 | ||
6406 | /* Truncate the string and get rid of the thread <thread_num> | |
6407 | parameter before the parameter list is parsed by the | |
6408 | evaluate_expression() function. */ | |
6409 | *tok = '\0'; | |
6410 | } | |
6411 | } | |
6412 | ||
6413 | /* Parse the rest of the arguments. */ | |
c906108c SS |
6414 | innermost_block = NULL; |
6415 | exp_start = arg; | |
6416 | exp = parse_exp_1 (&arg, 0, 0); | |
6417 | exp_end = arg; | |
fa8a61dc TT |
6418 | /* Remove trailing whitespace from the expression before saving it. |
6419 | This makes the eventual display of the expression string a bit | |
6420 | prettier. */ | |
6421 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
6422 | --exp_end; | |
6423 | ||
c906108c SS |
6424 | exp_valid_block = innermost_block; |
6425 | mark = value_mark (); | |
fa4727a6 DJ |
6426 | fetch_watchpoint_value (exp, &val, NULL, NULL); |
6427 | if (val != NULL) | |
6428 | release_value (val); | |
c906108c SS |
6429 | |
6430 | tok = arg; | |
6431 | while (*tok == ' ' || *tok == '\t') | |
6432 | tok++; | |
6433 | end_tok = tok; | |
6434 | ||
6435 | while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') | |
6436 | end_tok++; | |
6437 | ||
6438 | toklen = end_tok - tok; | |
6439 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
6440 | { | |
6441 | tok = cond_start = end_tok + 1; | |
6442 | cond = parse_exp_1 (&tok, 0, 0); | |
6443 | cond_end = tok; | |
6444 | } | |
6445 | if (*tok) | |
8a3fe4f8 | 6446 | error (_("Junk at end of command.")); |
c906108c | 6447 | |
53a5351d | 6448 | if (accessflag == hw_read) |
c5aa993b | 6449 | bp_type = bp_read_watchpoint; |
53a5351d | 6450 | else if (accessflag == hw_access) |
c5aa993b JM |
6451 | bp_type = bp_access_watchpoint; |
6452 | else | |
6453 | bp_type = bp_hardware_watchpoint; | |
c906108c SS |
6454 | |
6455 | mem_cnt = can_use_hardware_watchpoint (val); | |
6456 | if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint) | |
8a3fe4f8 | 6457 | error (_("Expression cannot be implemented with read/access watchpoint.")); |
c5aa993b JM |
6458 | if (mem_cnt != 0) |
6459 | { | |
6460 | i = hw_watchpoint_used_count (bp_type, &other_type_used); | |
53a5351d | 6461 | target_resources_ok = |
d92524f1 | 6462 | target_can_use_hardware_watchpoint (bp_type, i + mem_cnt, |
53a5351d | 6463 | other_type_used); |
c5aa993b | 6464 | if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint) |
8a3fe4f8 | 6465 | error (_("Target does not support this type of hardware watchpoint.")); |
53a5351d | 6466 | |
c5aa993b | 6467 | if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint) |
8a3fe4f8 | 6468 | error (_("Target can only support one kind of HW watchpoint at a time.")); |
c5aa993b | 6469 | } |
c906108c | 6470 | |
4d28f7a8 KB |
6471 | /* Change the type of breakpoint to an ordinary watchpoint if a hardware |
6472 | watchpoint could not be set. */ | |
6473 | if (!mem_cnt || target_resources_ok <= 0) | |
6474 | bp_type = bp_watchpoint; | |
6475 | ||
d983da9c | 6476 | frame = block_innermost_frame (exp_valid_block); |
d983da9c DJ |
6477 | |
6478 | /* If the expression is "local", then set up a "watchpoint scope" | |
6479 | breakpoint at the point where we've left the scope of the watchpoint | |
6480 | expression. Create the scope breakpoint before the watchpoint, so | |
6481 | that we will encounter it first in bpstat_stop_status. */ | |
edb3359d | 6482 | if (innermost_block && frame) |
d983da9c | 6483 | { |
edb3359d DJ |
6484 | if (frame_id_p (frame_unwind_caller_id (frame))) |
6485 | { | |
6486 | scope_breakpoint | |
a6d9a66e UW |
6487 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
6488 | frame_unwind_caller_pc (frame), | |
edb3359d | 6489 | bp_watchpoint_scope); |
d983da9c | 6490 | |
edb3359d | 6491 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 6492 | |
edb3359d DJ |
6493 | /* Automatically delete the breakpoint when it hits. */ |
6494 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 6495 | |
edb3359d DJ |
6496 | /* Only break in the proper frame (help with recursion). */ |
6497 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); | |
d983da9c | 6498 | |
edb3359d | 6499 | /* Set the address at which we will stop. */ |
a6d9a66e UW |
6500 | scope_breakpoint->loc->gdbarch |
6501 | = frame_unwind_caller_arch (frame); | |
edb3359d DJ |
6502 | scope_breakpoint->loc->requested_address |
6503 | = frame_unwind_caller_pc (frame); | |
6504 | scope_breakpoint->loc->address | |
a6d9a66e UW |
6505 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
6506 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
6507 | scope_breakpoint->type); |
6508 | } | |
d983da9c DJ |
6509 | } |
6510 | ||
c906108c | 6511 | /* Now set up the breakpoint. */ |
a6d9a66e | 6512 | b = set_raw_breakpoint (gdbarch, sal, bp_type); |
c906108c SS |
6513 | set_breakpoint_count (breakpoint_count + 1); |
6514 | b->number = breakpoint_count; | |
37e4754d | 6515 | b->thread = thread; |
b5de0fa7 | 6516 | b->disposition = disp_donttouch; |
c906108c SS |
6517 | b->exp = exp; |
6518 | b->exp_valid_block = exp_valid_block; | |
6519 | b->exp_string = savestring (exp_start, exp_end - exp_start); | |
6520 | b->val = val; | |
fa4727a6 | 6521 | b->val_valid = 1; |
511a6cd4 | 6522 | b->loc->cond = cond; |
c906108c SS |
6523 | if (cond_start) |
6524 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
6525 | else | |
6526 | b->cond_string = 0; | |
c5aa993b | 6527 | |
c906108c | 6528 | if (frame) |
d983da9c | 6529 | b->watchpoint_frame = get_frame_id (frame); |
c906108c | 6530 | else |
35a487f1 | 6531 | b->watchpoint_frame = null_frame_id; |
c906108c | 6532 | |
d983da9c | 6533 | if (scope_breakpoint != NULL) |
c906108c | 6534 | { |
d983da9c DJ |
6535 | /* The scope breakpoint is related to the watchpoint. We will |
6536 | need to act on them together. */ | |
6537 | b->related_breakpoint = scope_breakpoint; | |
6538 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 6539 | } |
d983da9c | 6540 | |
c906108c SS |
6541 | value_free_to_mark (mark); |
6542 | mention (b); | |
b60e7edf | 6543 | update_global_location_list (1); |
c906108c SS |
6544 | } |
6545 | ||
6546 | /* Return count of locations need to be watched and can be handled | |
6547 | in hardware. If the watchpoint can not be handled | |
6548 | in hardware return zero. */ | |
6549 | ||
c906108c | 6550 | static int |
fba45db2 | 6551 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
6552 | { |
6553 | int found_memory_cnt = 0; | |
2e70b7b9 | 6554 | struct value *head = v; |
c906108c SS |
6555 | |
6556 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 6557 | if (!can_use_hw_watchpoints) |
c906108c | 6558 | return 0; |
c5aa993b | 6559 | |
5c44784c JM |
6560 | /* Make sure that the value of the expression depends only upon |
6561 | memory contents, and values computed from them within GDB. If we | |
6562 | find any register references or function calls, we can't use a | |
6563 | hardware watchpoint. | |
6564 | ||
6565 | The idea here is that evaluating an expression generates a series | |
6566 | of values, one holding the value of every subexpression. (The | |
6567 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
6568 | a*b+c.) GDB's values hold almost enough information to establish | |
6569 | the criteria given above --- they identify memory lvalues, | |
6570 | register lvalues, computed values, etcetera. So we can evaluate | |
6571 | the expression, and then scan the chain of values that leaves | |
6572 | behind to decide whether we can detect any possible change to the | |
6573 | expression's final value using only hardware watchpoints. | |
6574 | ||
6575 | However, I don't think that the values returned by inferior | |
6576 | function calls are special in any way. So this function may not | |
6577 | notice that an expression involving an inferior function call | |
6578 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 6579 | for (; v; v = value_next (v)) |
c906108c | 6580 | { |
5c44784c | 6581 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 6582 | { |
d69fe07e | 6583 | if (value_lazy (v)) |
5c44784c JM |
6584 | /* A lazy memory lvalue is one that GDB never needed to fetch; |
6585 | we either just used its address (e.g., `a' in `a.b') or | |
6586 | we never needed it at all (e.g., `a' in `a,b'). */ | |
6587 | ; | |
53a5351d | 6588 | else |
5c44784c JM |
6589 | { |
6590 | /* Ahh, memory we actually used! Check if we can cover | |
6591 | it with hardware watchpoints. */ | |
df407dfe | 6592 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
6593 | |
6594 | /* We only watch structs and arrays if user asked for it | |
6595 | explicitly, never if they just happen to appear in a | |
6596 | middle of some value chain. */ | |
6597 | if (v == head | |
6598 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
6599 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
6600 | { | |
42ae5230 | 6601 | CORE_ADDR vaddr = value_address (v); |
df407dfe | 6602 | int len = TYPE_LENGTH (value_type (v)); |
2e70b7b9 | 6603 | |
d92524f1 | 6604 | if (!target_region_ok_for_hw_watchpoint (vaddr, len)) |
2e70b7b9 MS |
6605 | return 0; |
6606 | else | |
6607 | found_memory_cnt++; | |
6608 | } | |
5c44784c | 6609 | } |
c5aa993b | 6610 | } |
5086187c AC |
6611 | else if (VALUE_LVAL (v) != not_lval |
6612 | && deprecated_value_modifiable (v) == 0) | |
53a5351d | 6613 | return 0; /* ??? What does this represent? */ |
5086187c | 6614 | else if (VALUE_LVAL (v) == lval_register) |
53a5351d | 6615 | return 0; /* cannot watch a register with a HW watchpoint */ |
c906108c SS |
6616 | } |
6617 | ||
6618 | /* The expression itself looks suitable for using a hardware | |
6619 | watchpoint, but give the target machine a chance to reject it. */ | |
6620 | return found_memory_cnt; | |
6621 | } | |
6622 | ||
8b93c638 | 6623 | void |
fba45db2 | 6624 | watch_command_wrapper (char *arg, int from_tty) |
8b93c638 JM |
6625 | { |
6626 | watch_command (arg, from_tty); | |
6627 | } | |
8926118c | 6628 | |
c5aa993b | 6629 | static void |
fba45db2 | 6630 | watch_command (char *arg, int from_tty) |
c906108c | 6631 | { |
53a5351d | 6632 | watch_command_1 (arg, hw_write, from_tty); |
c906108c SS |
6633 | } |
6634 | ||
8b93c638 | 6635 | void |
fba45db2 | 6636 | rwatch_command_wrapper (char *arg, int from_tty) |
8b93c638 JM |
6637 | { |
6638 | rwatch_command (arg, from_tty); | |
6639 | } | |
8926118c | 6640 | |
c5aa993b | 6641 | static void |
fba45db2 | 6642 | rwatch_command (char *arg, int from_tty) |
c906108c | 6643 | { |
53a5351d | 6644 | watch_command_1 (arg, hw_read, from_tty); |
c906108c SS |
6645 | } |
6646 | ||
8b93c638 | 6647 | void |
fba45db2 | 6648 | awatch_command_wrapper (char *arg, int from_tty) |
8b93c638 JM |
6649 | { |
6650 | awatch_command (arg, from_tty); | |
6651 | } | |
8926118c | 6652 | |
c5aa993b | 6653 | static void |
fba45db2 | 6654 | awatch_command (char *arg, int from_tty) |
c906108c | 6655 | { |
53a5351d | 6656 | watch_command_1 (arg, hw_access, from_tty); |
c906108c | 6657 | } |
c906108c | 6658 | \f |
c5aa993b | 6659 | |
43ff13b4 | 6660 | /* Helper routines for the until_command routine in infcmd.c. Here |
c906108c SS |
6661 | because it uses the mechanisms of breakpoints. */ |
6662 | ||
bfec99b2 PA |
6663 | struct until_break_command_continuation_args |
6664 | { | |
6665 | struct breakpoint *breakpoint; | |
6666 | struct breakpoint *breakpoint2; | |
6667 | }; | |
6668 | ||
43ff13b4 JM |
6669 | /* This function is called by fetch_inferior_event via the |
6670 | cmd_continuation pointer, to complete the until command. It takes | |
6671 | care of cleaning up the temporary breakpoints set up by the until | |
6672 | command. */ | |
c2c6d25f | 6673 | static void |
604ead4a | 6674 | until_break_command_continuation (void *arg) |
43ff13b4 | 6675 | { |
bfec99b2 PA |
6676 | struct until_break_command_continuation_args *a = arg; |
6677 | ||
6678 | delete_breakpoint (a->breakpoint); | |
6679 | if (a->breakpoint2) | |
6680 | delete_breakpoint (a->breakpoint2); | |
43ff13b4 JM |
6681 | } |
6682 | ||
c906108c | 6683 | void |
ae66c1fc | 6684 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
6685 | { |
6686 | struct symtabs_and_lines sals; | |
6687 | struct symtab_and_line sal; | |
206415a3 | 6688 | struct frame_info *frame = get_selected_frame (NULL); |
c906108c | 6689 | struct breakpoint *breakpoint; |
f107f563 | 6690 | struct breakpoint *breakpoint2 = NULL; |
c906108c SS |
6691 | struct cleanup *old_chain; |
6692 | ||
6693 | clear_proceed_status (); | |
6694 | ||
6695 | /* Set a breakpoint where the user wants it and at return from | |
6696 | this function */ | |
c5aa993b | 6697 | |
c906108c SS |
6698 | if (default_breakpoint_valid) |
6699 | sals = decode_line_1 (&arg, 1, default_breakpoint_symtab, | |
68219205 | 6700 | default_breakpoint_line, (char ***) NULL, NULL); |
c906108c | 6701 | else |
53a5351d | 6702 | sals = decode_line_1 (&arg, 1, (struct symtab *) NULL, |
68219205 | 6703 | 0, (char ***) NULL, NULL); |
c5aa993b | 6704 | |
c906108c | 6705 | if (sals.nelts != 1) |
8a3fe4f8 | 6706 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 6707 | |
c906108c | 6708 | sal = sals.sals[0]; |
b8c9b27d | 6709 | xfree (sals.sals); /* malloc'd, so freed */ |
c5aa993b | 6710 | |
c906108c | 6711 | if (*arg) |
8a3fe4f8 | 6712 | error (_("Junk at end of arguments.")); |
c5aa993b | 6713 | |
c906108c | 6714 | resolve_sal_pc (&sal); |
c5aa993b | 6715 | |
ae66c1fc EZ |
6716 | if (anywhere) |
6717 | /* If the user told us to continue until a specified location, | |
6718 | we don't specify a frame at which we need to stop. */ | |
a6d9a66e UW |
6719 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
6720 | null_frame_id, bp_until); | |
ae66c1fc | 6721 | else |
edb3359d | 6722 | /* Otherwise, specify the selected frame, because we want to stop only |
ae66c1fc | 6723 | at the very same frame. */ |
a6d9a66e UW |
6724 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
6725 | get_stack_frame_id (frame), | |
ae66c1fc | 6726 | bp_until); |
c5aa993b | 6727 | |
f107f563 | 6728 | old_chain = make_cleanup_delete_breakpoint (breakpoint); |
c906108c | 6729 | |
ae66c1fc EZ |
6730 | /* Keep within the current frame, or in frames called by the current |
6731 | one. */ | |
edb3359d DJ |
6732 | |
6733 | if (frame_id_p (frame_unwind_caller_id (frame))) | |
c906108c | 6734 | { |
edb3359d DJ |
6735 | sal = find_pc_line (frame_unwind_caller_pc (frame), 0); |
6736 | sal.pc = frame_unwind_caller_pc (frame); | |
a6d9a66e UW |
6737 | breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame), |
6738 | sal, | |
edb3359d | 6739 | frame_unwind_caller_id (frame), |
f107f563 VP |
6740 | bp_until); |
6741 | make_cleanup_delete_breakpoint (breakpoint2); | |
c906108c | 6742 | } |
c5aa993b | 6743 | |
c906108c | 6744 | proceed (-1, TARGET_SIGNAL_DEFAULT, 0); |
f107f563 VP |
6745 | |
6746 | /* If we are running asynchronously, and proceed call above has actually | |
6747 | managed to start the target, arrange for breakpoints to be | |
6748 | deleted when the target stops. Otherwise, we're already stopped and | |
6749 | delete breakpoints via cleanup chain. */ | |
6750 | ||
8ea051c5 | 6751 | if (target_can_async_p () && is_running (inferior_ptid)) |
f107f563 | 6752 | { |
bfec99b2 PA |
6753 | struct until_break_command_continuation_args *args; |
6754 | args = xmalloc (sizeof (*args)); | |
f107f563 | 6755 | |
bfec99b2 PA |
6756 | args->breakpoint = breakpoint; |
6757 | args->breakpoint2 = breakpoint2; | |
f107f563 VP |
6758 | |
6759 | discard_cleanups (old_chain); | |
95e54da7 PA |
6760 | add_continuation (inferior_thread (), |
6761 | until_break_command_continuation, args, | |
604ead4a | 6762 | xfree); |
f107f563 VP |
6763 | } |
6764 | else | |
c5aa993b | 6765 | do_cleanups (old_chain); |
c906108c | 6766 | } |
ae66c1fc | 6767 | |
c906108c | 6768 | static void |
fba45db2 | 6769 | ep_skip_leading_whitespace (char **s) |
c906108c | 6770 | { |
c5aa993b JM |
6771 | if ((s == NULL) || (*s == NULL)) |
6772 | return; | |
6773 | while (isspace (**s)) | |
6774 | *s += 1; | |
c906108c | 6775 | } |
c5aa993b | 6776 | |
c906108c SS |
6777 | /* This function attempts to parse an optional "if <cond>" clause |
6778 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 6779 | |
c906108c SS |
6780 | Else, it returns a pointer to the condition string. (It does not |
6781 | attempt to evaluate the string against a particular block.) And, | |
6782 | it updates arg to point to the first character following the parsed | |
6783 | if clause in the arg string. */ | |
53a5351d | 6784 | |
c906108c | 6785 | static char * |
fba45db2 | 6786 | ep_parse_optional_if_clause (char **arg) |
c906108c | 6787 | { |
c5aa993b JM |
6788 | char *cond_string; |
6789 | ||
6790 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 6791 | return NULL; |
c5aa993b | 6792 | |
c906108c SS |
6793 | /* Skip the "if" keyword. */ |
6794 | (*arg) += 2; | |
c5aa993b | 6795 | |
c906108c SS |
6796 | /* Skip any extra leading whitespace, and record the start of the |
6797 | condition string. */ | |
6798 | ep_skip_leading_whitespace (arg); | |
6799 | cond_string = *arg; | |
c5aa993b | 6800 | |
c906108c SS |
6801 | /* Assume that the condition occupies the remainder of the arg string. */ |
6802 | (*arg) += strlen (cond_string); | |
c5aa993b | 6803 | |
c906108c SS |
6804 | return cond_string; |
6805 | } | |
c5aa993b | 6806 | |
c906108c SS |
6807 | /* This function attempts to parse an optional filename from the arg |
6808 | string. If one is not found, it returns NULL. | |
c5aa993b | 6809 | |
c906108c SS |
6810 | Else, it returns a pointer to the parsed filename. (This function |
6811 | makes no attempt to verify that a file of that name exists, or is | |
6812 | accessible.) And, it updates arg to point to the first character | |
6813 | following the parsed filename in the arg string. | |
c5aa993b | 6814 | |
c906108c SS |
6815 | Note that clients needing to preserve the returned filename for |
6816 | future access should copy it to their own buffers. */ | |
6817 | static char * | |
fba45db2 | 6818 | ep_parse_optional_filename (char **arg) |
c906108c | 6819 | { |
c5aa993b JM |
6820 | static char filename[1024]; |
6821 | char *arg_p = *arg; | |
6822 | int i; | |
6823 | char c; | |
6824 | ||
c906108c SS |
6825 | if ((*arg_p == '\0') || isspace (*arg_p)) |
6826 | return NULL; | |
c5aa993b JM |
6827 | |
6828 | for (i = 0;; i++) | |
c906108c SS |
6829 | { |
6830 | c = *arg_p; | |
6831 | if (isspace (c)) | |
c5aa993b | 6832 | c = '\0'; |
c906108c SS |
6833 | filename[i] = c; |
6834 | if (c == '\0') | |
c5aa993b | 6835 | break; |
c906108c SS |
6836 | arg_p++; |
6837 | } | |
6838 | *arg = arg_p; | |
c5aa993b | 6839 | |
c906108c SS |
6840 | return filename; |
6841 | } | |
c5aa993b | 6842 | |
c906108c SS |
6843 | /* Commands to deal with catching events, such as signals, exceptions, |
6844 | process start/exit, etc. */ | |
c5aa993b JM |
6845 | |
6846 | typedef enum | |
6847 | { | |
44feb3ce TT |
6848 | catch_fork_temporary, catch_vfork_temporary, |
6849 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
6850 | } |
6851 | catch_fork_kind; | |
6852 | ||
c906108c | 6853 | static void |
44feb3ce | 6854 | catch_fork_command_1 (char *arg, int from_tty, struct cmd_list_element *command) |
c906108c | 6855 | { |
a6d9a66e | 6856 | struct gdbarch *gdbarch = get_current_arch (); |
c5aa993b | 6857 | char *cond_string = NULL; |
44feb3ce TT |
6858 | catch_fork_kind fork_kind; |
6859 | int tempflag; | |
6860 | ||
6861 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
6862 | tempflag = (fork_kind == catch_fork_temporary | |
6863 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 6864 | |
44feb3ce TT |
6865 | if (!arg) |
6866 | arg = ""; | |
c906108c | 6867 | ep_skip_leading_whitespace (&arg); |
c5aa993b | 6868 | |
c906108c | 6869 | /* The allowed syntax is: |
c5aa993b JM |
6870 | catch [v]fork |
6871 | catch [v]fork if <cond> | |
6872 | ||
c906108c SS |
6873 | First, check if there's an if clause. */ |
6874 | cond_string = ep_parse_optional_if_clause (&arg); | |
c5aa993b | 6875 | |
c906108c | 6876 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 6877 | error (_("Junk at end of arguments.")); |
c5aa993b | 6878 | |
c906108c SS |
6879 | /* If this target supports it, create a fork or vfork catchpoint |
6880 | and enable reporting of such events. */ | |
c5aa993b JM |
6881 | switch (fork_kind) |
6882 | { | |
44feb3ce TT |
6883 | case catch_fork_temporary: |
6884 | case catch_fork_permanent: | |
a6d9a66e | 6885 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 6886 | &catch_fork_breakpoint_ops); |
c906108c | 6887 | break; |
44feb3ce TT |
6888 | case catch_vfork_temporary: |
6889 | case catch_vfork_permanent: | |
a6d9a66e | 6890 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 6891 | &catch_vfork_breakpoint_ops); |
c906108c | 6892 | break; |
c5aa993b | 6893 | default: |
8a3fe4f8 | 6894 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 6895 | break; |
c5aa993b | 6896 | } |
c906108c SS |
6897 | } |
6898 | ||
6899 | static void | |
44feb3ce | 6900 | catch_exec_command_1 (char *arg, int from_tty, struct cmd_list_element *command) |
c906108c | 6901 | { |
a6d9a66e | 6902 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 6903 | int tempflag; |
c5aa993b | 6904 | char *cond_string = NULL; |
c906108c | 6905 | |
44feb3ce TT |
6906 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
6907 | ||
6908 | if (!arg) | |
6909 | arg = ""; | |
c906108c SS |
6910 | ep_skip_leading_whitespace (&arg); |
6911 | ||
6912 | /* The allowed syntax is: | |
c5aa993b JM |
6913 | catch exec |
6914 | catch exec if <cond> | |
c906108c SS |
6915 | |
6916 | First, check if there's an if clause. */ | |
6917 | cond_string = ep_parse_optional_if_clause (&arg); | |
6918 | ||
6919 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 6920 | error (_("Junk at end of arguments.")); |
c906108c SS |
6921 | |
6922 | /* If this target supports it, create an exec catchpoint | |
6923 | and enable reporting of such events. */ | |
a6d9a66e UW |
6924 | create_catchpoint (gdbarch, tempflag, cond_string, |
6925 | &catch_exec_breakpoint_ops); | |
c906108c | 6926 | } |
c5aa993b | 6927 | |
3086aeae DJ |
6928 | static enum print_stop_action |
6929 | print_exception_catchpoint (struct breakpoint *b) | |
6930 | { | |
ade92717 | 6931 | int bp_temp, bp_throw; |
3086aeae | 6932 | |
ade92717 | 6933 | annotate_catchpoint (b->number); |
3086aeae | 6934 | |
ade92717 AR |
6935 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
6936 | if (b->loc->address != b->loc->requested_address) | |
6937 | breakpoint_adjustment_warning (b->loc->requested_address, | |
6938 | b->loc->address, | |
6939 | b->number, 1); | |
df2b6d2d | 6940 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
6941 | ui_out_text (uiout, |
6942 | bp_temp ? "Temporary catchpoint " | |
6943 | : "Catchpoint "); | |
6944 | if (!ui_out_is_mi_like_p (uiout)) | |
6945 | ui_out_field_int (uiout, "bkptno", b->number); | |
6946 | ui_out_text (uiout, | |
c0b37c48 AR |
6947 | bp_throw ? " (exception thrown), " |
6948 | : " (exception caught), "); | |
ade92717 AR |
6949 | if (ui_out_is_mi_like_p (uiout)) |
6950 | { | |
6951 | ui_out_field_string (uiout, "reason", | |
6952 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
6953 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
6954 | ui_out_field_int (uiout, "bkptno", b->number); | |
6955 | } | |
3086aeae DJ |
6956 | return PRINT_SRC_AND_LOC; |
6957 | } | |
6958 | ||
6959 | static void | |
a6d9a66e | 6960 | print_one_exception_catchpoint (struct breakpoint *b, struct bp_location **last_loc) |
3086aeae | 6961 | { |
79a45b7d TT |
6962 | struct value_print_options opts; |
6963 | get_user_print_options (&opts); | |
6964 | if (opts.addressprint) | |
3086aeae DJ |
6965 | { |
6966 | annotate_field (4); | |
604133b5 AR |
6967 | if (b->loc == NULL || b->loc->shlib_disabled) |
6968 | ui_out_field_string (uiout, "addr", "<PENDING>"); | |
6969 | else | |
5af949e3 UW |
6970 | ui_out_field_core_addr (uiout, "addr", |
6971 | b->loc->gdbarch, b->loc->address); | |
3086aeae DJ |
6972 | } |
6973 | annotate_field (5); | |
604133b5 | 6974 | if (b->loc) |
a6d9a66e | 6975 | *last_loc = b->loc; |
3086aeae DJ |
6976 | if (strstr (b->addr_string, "throw") != NULL) |
6977 | ui_out_field_string (uiout, "what", "exception throw"); | |
6978 | else | |
6979 | ui_out_field_string (uiout, "what", "exception catch"); | |
6980 | } | |
6981 | ||
6982 | static void | |
6983 | print_mention_exception_catchpoint (struct breakpoint *b) | |
6984 | { | |
ade92717 AR |
6985 | int bp_temp; |
6986 | int bp_throw; | |
6987 | ||
df2b6d2d | 6988 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
6989 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
6990 | ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ") | |
6991 | : _("Catchpoint ")); | |
6992 | ui_out_field_int (uiout, "bkptno", b->number); | |
6993 | ui_out_text (uiout, bp_throw ? _(" (throw)") | |
6994 | : _(" (catch)")); | |
3086aeae DJ |
6995 | } |
6996 | ||
6997 | static struct breakpoint_ops gnu_v3_exception_catchpoint_ops = { | |
ce78b96d JB |
6998 | NULL, /* insert */ |
6999 | NULL, /* remove */ | |
7000 | NULL, /* breakpoint_hit */ | |
3086aeae DJ |
7001 | print_exception_catchpoint, |
7002 | print_one_exception_catchpoint, | |
7003 | print_mention_exception_catchpoint | |
7004 | }; | |
7005 | ||
7006 | static int | |
7007 | handle_gnu_v3_exceptions (int tempflag, char *cond_string, | |
7008 | enum exception_event_kind ex_event, int from_tty) | |
7009 | { | |
604133b5 AR |
7010 | char *trigger_func_name; |
7011 | ||
3086aeae | 7012 | if (ex_event == EX_EVENT_CATCH) |
604133b5 | 7013 | trigger_func_name = "__cxa_begin_catch"; |
3086aeae | 7014 | else |
604133b5 | 7015 | trigger_func_name = "__cxa_throw"; |
3086aeae | 7016 | |
a6d9a66e UW |
7017 | break_command_really (get_current_arch (), |
7018 | trigger_func_name, cond_string, -1, | |
604133b5 | 7019 | 0 /* condition and thread are valid. */, |
1042e4c0 | 7020 | tempflag, 0, 0, |
604133b5 AR |
7021 | 0, |
7022 | AUTO_BOOLEAN_TRUE /* pending */, | |
41447f92 VP |
7023 | &gnu_v3_exception_catchpoint_ops, from_tty, |
7024 | 1 /* enabled */); | |
3086aeae | 7025 | |
3086aeae DJ |
7026 | return 1; |
7027 | } | |
7028 | ||
c5aa993b | 7029 | /* Deal with "catch catch" and "catch throw" commands */ |
c906108c SS |
7030 | |
7031 | static void | |
fba45db2 KB |
7032 | catch_exception_command_1 (enum exception_event_kind ex_event, char *arg, |
7033 | int tempflag, int from_tty) | |
c906108c | 7034 | { |
c5aa993b JM |
7035 | char *cond_string = NULL; |
7036 | struct symtab_and_line *sal = NULL; | |
7037 | ||
44feb3ce TT |
7038 | if (!arg) |
7039 | arg = ""; | |
c906108c | 7040 | ep_skip_leading_whitespace (&arg); |
c5aa993b | 7041 | |
c906108c SS |
7042 | cond_string = ep_parse_optional_if_clause (&arg); |
7043 | ||
7044 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 7045 | error (_("Junk at end of arguments.")); |
c906108c | 7046 | |
059fb39f PM |
7047 | if (ex_event != EX_EVENT_THROW |
7048 | && ex_event != EX_EVENT_CATCH) | |
8a3fe4f8 | 7049 | error (_("Unsupported or unknown exception event; cannot catch it")); |
c906108c | 7050 | |
3086aeae DJ |
7051 | if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty)) |
7052 | return; | |
7053 | ||
8a3fe4f8 | 7054 | warning (_("Unsupported with this platform/compiler combination.")); |
c906108c SS |
7055 | } |
7056 | ||
44feb3ce TT |
7057 | /* Implementation of "catch catch" command. */ |
7058 | ||
7059 | static void | |
7060 | catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command) | |
7061 | { | |
7062 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
7063 | catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty); | |
7064 | } | |
7065 | ||
7066 | /* Implementation of "catch throw" command. */ | |
7067 | ||
7068 | static void | |
7069 | catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command) | |
7070 | { | |
7071 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
7072 | catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty); | |
7073 | } | |
7074 | ||
f7f9143b JB |
7075 | /* Create a breakpoint struct for Ada exception catchpoints. */ |
7076 | ||
7077 | static void | |
a6d9a66e UW |
7078 | create_ada_exception_breakpoint (struct gdbarch *gdbarch, |
7079 | struct symtab_and_line sal, | |
f7f9143b JB |
7080 | char *addr_string, |
7081 | char *exp_string, | |
7082 | char *cond_string, | |
7083 | struct expression *cond, | |
7084 | struct breakpoint_ops *ops, | |
7085 | int tempflag, | |
7086 | int from_tty) | |
7087 | { | |
7088 | struct breakpoint *b; | |
7089 | ||
7090 | if (from_tty) | |
7091 | { | |
5af949e3 UW |
7092 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
7093 | if (!loc_gdbarch) | |
7094 | loc_gdbarch = gdbarch; | |
7095 | ||
7096 | describe_other_breakpoints (loc_gdbarch, sal.pc, sal.section, -1); | |
f7f9143b JB |
7097 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
7098 | version for exception catchpoints, because two catchpoints | |
7099 | used for different exception names will use the same address. | |
7100 | In this case, a "breakpoint ... also set at..." warning is | |
7101 | unproductive. Besides. the warning phrasing is also a bit | |
7102 | inapropriate, we should use the word catchpoint, and tell | |
7103 | the user what type of catchpoint it is. The above is good | |
7104 | enough for now, though. */ | |
7105 | } | |
7106 | ||
a6d9a66e | 7107 | b = set_raw_breakpoint (gdbarch, sal, bp_breakpoint); |
f7f9143b JB |
7108 | set_breakpoint_count (breakpoint_count + 1); |
7109 | ||
7110 | b->enable_state = bp_enabled; | |
7111 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
7112 | b->number = breakpoint_count; | |
7113 | b->ignore_count = 0; | |
511a6cd4 | 7114 | b->loc->cond = cond; |
f7f9143b JB |
7115 | b->addr_string = addr_string; |
7116 | b->language = language_ada; | |
7117 | b->cond_string = cond_string; | |
7118 | b->exp_string = exp_string; | |
7119 | b->thread = -1; | |
7120 | b->ops = ops; | |
f7f9143b JB |
7121 | |
7122 | mention (b); | |
b60e7edf | 7123 | update_global_location_list (1); |
f7f9143b JB |
7124 | } |
7125 | ||
7126 | /* Implement the "catch exception" command. */ | |
7127 | ||
7128 | static void | |
44feb3ce TT |
7129 | catch_ada_exception_command (char *arg, int from_tty, |
7130 | struct cmd_list_element *command) | |
f7f9143b | 7131 | { |
a6d9a66e | 7132 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 7133 | int tempflag; |
f7f9143b JB |
7134 | struct symtab_and_line sal; |
7135 | enum bptype type; | |
7136 | char *addr_string = NULL; | |
7137 | char *exp_string = NULL; | |
7138 | char *cond_string = NULL; | |
7139 | struct expression *cond = NULL; | |
7140 | struct breakpoint_ops *ops = NULL; | |
7141 | ||
44feb3ce TT |
7142 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
7143 | ||
7144 | if (!arg) | |
7145 | arg = ""; | |
f7f9143b JB |
7146 | sal = ada_decode_exception_location (arg, &addr_string, &exp_string, |
7147 | &cond_string, &cond, &ops); | |
a6d9a66e | 7148 | create_ada_exception_breakpoint (gdbarch, sal, addr_string, exp_string, |
f7f9143b JB |
7149 | cond_string, cond, ops, tempflag, |
7150 | from_tty); | |
7151 | } | |
7152 | ||
7153 | /* Implement the "catch assert" command. */ | |
7154 | ||
7155 | static void | |
44feb3ce | 7156 | catch_assert_command (char *arg, int from_tty, struct cmd_list_element *command) |
f7f9143b | 7157 | { |
a6d9a66e | 7158 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 7159 | int tempflag; |
f7f9143b JB |
7160 | struct symtab_and_line sal; |
7161 | char *addr_string = NULL; | |
7162 | struct breakpoint_ops *ops = NULL; | |
7163 | ||
44feb3ce TT |
7164 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
7165 | ||
7166 | if (!arg) | |
7167 | arg = ""; | |
f7f9143b | 7168 | sal = ada_decode_assert_location (arg, &addr_string, &ops); |
a6d9a66e UW |
7169 | create_ada_exception_breakpoint (gdbarch, sal, addr_string, NULL, NULL, NULL, |
7170 | ops, tempflag, from_tty); | |
f7f9143b JB |
7171 | } |
7172 | ||
c906108c | 7173 | static void |
fba45db2 | 7174 | catch_command (char *arg, int from_tty) |
c906108c | 7175 | { |
44feb3ce | 7176 | error (_("Catch requires an event name.")); |
c906108c SS |
7177 | } |
7178 | \f | |
7179 | ||
7180 | static void | |
fba45db2 | 7181 | tcatch_command (char *arg, int from_tty) |
c906108c | 7182 | { |
44feb3ce | 7183 | error (_("Catch requires an event name.")); |
c906108c SS |
7184 | } |
7185 | ||
80f8a6eb | 7186 | /* Delete breakpoints by address or line. */ |
c906108c SS |
7187 | |
7188 | static void | |
fba45db2 | 7189 | clear_command (char *arg, int from_tty) |
c906108c | 7190 | { |
d6e956e5 VP |
7191 | struct breakpoint *b; |
7192 | VEC(breakpoint_p) *found = 0; | |
7193 | int ix; | |
c906108c SS |
7194 | int default_match; |
7195 | struct symtabs_and_lines sals; | |
7196 | struct symtab_and_line sal; | |
c906108c SS |
7197 | int i; |
7198 | ||
7199 | if (arg) | |
7200 | { | |
7201 | sals = decode_line_spec (arg, 1); | |
7202 | default_match = 0; | |
7203 | } | |
7204 | else | |
7205 | { | |
c5aa993b | 7206 | sals.sals = (struct symtab_and_line *) |
c906108c | 7207 | xmalloc (sizeof (struct symtab_and_line)); |
80f8a6eb | 7208 | make_cleanup (xfree, sals.sals); |
fe39c653 | 7209 | init_sal (&sal); /* initialize to zeroes */ |
c906108c SS |
7210 | sal.line = default_breakpoint_line; |
7211 | sal.symtab = default_breakpoint_symtab; | |
7212 | sal.pc = default_breakpoint_address; | |
7213 | if (sal.symtab == 0) | |
8a3fe4f8 | 7214 | error (_("No source file specified.")); |
c906108c SS |
7215 | |
7216 | sals.sals[0] = sal; | |
7217 | sals.nelts = 1; | |
7218 | ||
7219 | default_match = 1; | |
7220 | } | |
7221 | ||
ed0616c6 VP |
7222 | /* We don't call resolve_sal_pc here. That's not |
7223 | as bad as it seems, because all existing breakpoints | |
7224 | typically have both file/line and pc set. So, if | |
7225 | clear is given file/line, we can match this to existing | |
7226 | breakpoint without obtaining pc at all. | |
7227 | ||
7228 | We only support clearing given the address explicitly | |
7229 | present in breakpoint table. Say, we've set breakpoint | |
7230 | at file:line. There were several PC values for that file:line, | |
7231 | due to optimization, all in one block. | |
7232 | We've picked one PC value. If "clear" is issued with another | |
7233 | PC corresponding to the same file:line, the breakpoint won't | |
7234 | be cleared. We probably can still clear the breakpoint, but | |
7235 | since the other PC value is never presented to user, user | |
7236 | can only find it by guessing, and it does not seem important | |
7237 | to support that. */ | |
7238 | ||
c906108c | 7239 | /* For each line spec given, delete bps which correspond |
80f8a6eb MS |
7240 | to it. Do it in two passes, solely to preserve the current |
7241 | behavior that from_tty is forced true if we delete more than | |
7242 | one breakpoint. */ | |
c906108c | 7243 | |
80f8a6eb | 7244 | found = NULL; |
c906108c SS |
7245 | for (i = 0; i < sals.nelts; i++) |
7246 | { | |
7247 | /* If exact pc given, clear bpts at that pc. | |
c5aa993b JM |
7248 | If line given (pc == 0), clear all bpts on specified line. |
7249 | If defaulting, clear all bpts on default line | |
c906108c | 7250 | or at default pc. |
c5aa993b JM |
7251 | |
7252 | defaulting sal.pc != 0 tests to do | |
7253 | ||
7254 | 0 1 pc | |
7255 | 1 1 pc _and_ line | |
7256 | 0 0 line | |
7257 | 1 0 <can't happen> */ | |
c906108c SS |
7258 | |
7259 | sal = sals.sals[i]; | |
c906108c | 7260 | |
d6e956e5 VP |
7261 | /* Find all matching breakpoints and add them to |
7262 | 'found'. */ | |
7263 | ALL_BREAKPOINTS (b) | |
c5aa993b | 7264 | { |
0d381245 | 7265 | int match = 0; |
80f8a6eb MS |
7266 | /* Are we going to delete b? */ |
7267 | if (b->type != bp_none | |
7268 | && b->type != bp_watchpoint | |
7269 | && b->type != bp_hardware_watchpoint | |
7270 | && b->type != bp_read_watchpoint | |
0d381245 VP |
7271 | && b->type != bp_access_watchpoint) |
7272 | { | |
7273 | struct bp_location *loc = b->loc; | |
7274 | for (; loc; loc = loc->next) | |
7275 | { | |
7276 | int pc_match = sal.pc | |
7277 | && (loc->address == sal.pc) | |
7278 | && (!section_is_overlay (loc->section) | |
7279 | || loc->section == sal.section); | |
7280 | int line_match = ((default_match || (0 == sal.pc)) | |
7281 | && b->source_file != NULL | |
7282 | && sal.symtab != NULL | |
7283 | && strcmp (b->source_file, sal.symtab->filename) == 0 | |
7284 | && b->line_number == sal.line); | |
7285 | if (pc_match || line_match) | |
7286 | { | |
7287 | match = 1; | |
7288 | break; | |
7289 | } | |
7290 | } | |
7291 | } | |
7292 | ||
7293 | if (match) | |
d6e956e5 | 7294 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 7295 | } |
80f8a6eb MS |
7296 | } |
7297 | /* Now go thru the 'found' chain and delete them. */ | |
d6e956e5 | 7298 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
7299 | { |
7300 | if (arg) | |
8a3fe4f8 | 7301 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 7302 | else |
8a3fe4f8 | 7303 | error (_("No breakpoint at this line.")); |
80f8a6eb | 7304 | } |
c906108c | 7305 | |
d6e956e5 | 7306 | if (VEC_length(breakpoint_p, found) > 1) |
80f8a6eb MS |
7307 | from_tty = 1; /* Always report if deleted more than one */ |
7308 | if (from_tty) | |
a3f17187 | 7309 | { |
d6e956e5 | 7310 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
7311 | printf_unfiltered (_("Deleted breakpoint ")); |
7312 | else | |
7313 | printf_unfiltered (_("Deleted breakpoints ")); | |
7314 | } | |
80f8a6eb | 7315 | breakpoints_changed (); |
d6e956e5 VP |
7316 | |
7317 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 7318 | { |
c5aa993b | 7319 | if (from_tty) |
d6e956e5 VP |
7320 | printf_unfiltered ("%d ", b->number); |
7321 | delete_breakpoint (b); | |
c906108c | 7322 | } |
80f8a6eb MS |
7323 | if (from_tty) |
7324 | putchar_unfiltered ('\n'); | |
c906108c SS |
7325 | } |
7326 | \f | |
7327 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
7328 | all breakpoints that are marked for deletion, whether hit or not. | |
7329 | This is called after any breakpoint is hit, or after errors. */ | |
7330 | ||
7331 | void | |
fba45db2 | 7332 | breakpoint_auto_delete (bpstat bs) |
c906108c SS |
7333 | { |
7334 | struct breakpoint *b, *temp; | |
7335 | ||
7336 | for (; bs; bs = bs->next) | |
20874c92 VP |
7337 | if (bs->breakpoint_at |
7338 | && bs->breakpoint_at->owner | |
7339 | && bs->breakpoint_at->owner->disposition == disp_del | |
c906108c | 7340 | && bs->stop) |
4f8d1dc6 | 7341 | delete_breakpoint (bs->breakpoint_at->owner); |
c906108c SS |
7342 | |
7343 | ALL_BREAKPOINTS_SAFE (b, temp) | |
c5aa993b | 7344 | { |
b5de0fa7 | 7345 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
7346 | delete_breakpoint (b); |
7347 | } | |
c906108c SS |
7348 | } |
7349 | ||
f7545552 TT |
7350 | /* A cleanup function which destroys a vector. */ |
7351 | ||
7352 | static void | |
7353 | do_vec_free (void *p) | |
7354 | { | |
7355 | VEC(bp_location_p) **vec = p; | |
7356 | if (*vec) | |
7357 | VEC_free (bp_location_p, *vec); | |
7358 | } | |
7359 | ||
4cd9bd08 | 7360 | /* If SHOULD_INSERT is false, do not insert any breakpoint locations |
b60e7edf PA |
7361 | into the inferior, only remove already-inserted locations that no |
7362 | longer should be inserted. Functions that delete a breakpoint or | |
7363 | breakpoints should pass false, so that deleting a breakpoint | |
7364 | doesn't have the side effect of inserting the locations of other | |
7365 | breakpoints that are marked not-inserted, but should_be_inserted | |
7366 | returns true on them. | |
7367 | ||
7368 | This behaviour is useful is situations close to tear-down -- e.g., | |
7369 | after an exec, while the target still has execution, but breakpoint | |
7370 | shadows of the previous executable image should *NOT* be restored | |
7371 | to the new image; or before detaching, where the target still has | |
7372 | execution and wants to delete breakpoints from GDB's lists, and all | |
7373 | breakpoints had already been removed from the inferior. */ | |
7374 | ||
0d381245 | 7375 | static void |
b60e7edf | 7376 | update_global_location_list (int should_insert) |
0d381245 | 7377 | { |
74960c60 VP |
7378 | struct breakpoint *b; |
7379 | struct bp_location **next = &bp_location_chain; | |
7380 | struct bp_location *loc; | |
7381 | struct bp_location *loc2; | |
74960c60 VP |
7382 | VEC(bp_location_p) *old_locations = NULL; |
7383 | int ret; | |
7384 | int ix; | |
f7545552 TT |
7385 | struct cleanup *cleanups; |
7386 | ||
7387 | cleanups = make_cleanup (do_vec_free, &old_locations); | |
74960c60 VP |
7388 | /* Store old locations for future reference. */ |
7389 | for (loc = bp_location_chain; loc; loc = loc->global_next) | |
7390 | VEC_safe_push (bp_location_p, old_locations, loc); | |
0d381245 | 7391 | |
74960c60 VP |
7392 | bp_location_chain = NULL; |
7393 | ALL_BREAKPOINTS (b) | |
0d381245 | 7394 | { |
74960c60 | 7395 | for (loc = b->loc; loc; loc = loc->next) |
0d381245 | 7396 | { |
74960c60 VP |
7397 | *next = loc; |
7398 | next = &(loc->global_next); | |
7399 | *next = NULL; | |
0d381245 | 7400 | } |
74960c60 VP |
7401 | } |
7402 | ||
7403 | /* Identify bp_location instances that are no longer present in the new | |
7404 | list, and therefore should be freed. Note that it's not necessary that | |
7405 | those locations should be removed from inferior -- if there's another | |
7406 | location at the same address (previously marked as duplicate), | |
7407 | we don't need to remove/insert the location. */ | |
7408 | for (ix = 0; VEC_iterate(bp_location_p, old_locations, ix, loc); ++ix) | |
7409 | { | |
7410 | /* Tells if 'loc' is found amoung the new locations. If not, we | |
7411 | have to free it. */ | |
7412 | int found_object = 0; | |
20874c92 VP |
7413 | /* Tells if the location should remain inserted in the target. */ |
7414 | int keep_in_target = 0; | |
7415 | int removed = 0; | |
74960c60 VP |
7416 | for (loc2 = bp_location_chain; loc2; loc2 = loc2->global_next) |
7417 | if (loc2 == loc) | |
7418 | { | |
7419 | found_object = 1; | |
7420 | break; | |
7421 | } | |
7422 | ||
7423 | /* If this location is no longer present, and inserted, look if there's | |
7424 | maybe a new location at the same address. If so, mark that one | |
7425 | inserted, and don't remove this one. This is needed so that we | |
7426 | don't have a time window where a breakpoint at certain location is not | |
7427 | inserted. */ | |
7428 | ||
7429 | if (loc->inserted) | |
0d381245 | 7430 | { |
74960c60 | 7431 | /* If the location is inserted now, we might have to remove it. */ |
74960c60 VP |
7432 | |
7433 | if (found_object && should_be_inserted (loc)) | |
7434 | { | |
7435 | /* The location is still present in the location list, and still | |
7436 | should be inserted. Don't do anything. */ | |
20874c92 | 7437 | keep_in_target = 1; |
74960c60 VP |
7438 | } |
7439 | else | |
7440 | { | |
7441 | /* The location is either no longer present, or got disabled. | |
7442 | See if there's another location at the same address, in which | |
7443 | case we don't need to remove this one from the target. */ | |
7444 | if (breakpoint_address_is_meaningful (loc->owner)) | |
7445 | for (loc2 = bp_location_chain; loc2; loc2 = loc2->global_next) | |
7446 | { | |
7447 | /* For the sake of should_insert_location. The | |
7448 | call to check_duplicates will fix up this later. */ | |
7449 | loc2->duplicate = 0; | |
7450 | if (should_be_inserted (loc2) | |
7451 | && loc2 != loc && loc2->address == loc->address) | |
7452 | { | |
7453 | loc2->inserted = 1; | |
7454 | loc2->target_info = loc->target_info; | |
20874c92 | 7455 | keep_in_target = 1; |
74960c60 VP |
7456 | break; |
7457 | } | |
7458 | } | |
7459 | } | |
7460 | ||
20874c92 VP |
7461 | if (!keep_in_target) |
7462 | { | |
7463 | if (remove_breakpoint (loc, mark_uninserted)) | |
7464 | { | |
7465 | /* This is just about all we can do. We could keep this | |
7466 | location on the global list, and try to remove it next | |
7467 | time, but there's no particular reason why we will | |
7468 | succeed next time. | |
7469 | ||
7470 | Note that at this point, loc->owner is still valid, | |
7471 | as delete_breakpoint frees the breakpoint only | |
7472 | after calling us. */ | |
7473 | printf_filtered (_("warning: Error removing breakpoint %d\n"), | |
7474 | loc->owner->number); | |
7475 | } | |
7476 | removed = 1; | |
7477 | } | |
0d381245 | 7478 | } |
74960c60 VP |
7479 | |
7480 | if (!found_object) | |
1c5cfe86 PA |
7481 | { |
7482 | if (removed && non_stop) | |
20874c92 VP |
7483 | { |
7484 | /* This location was removed from the targets. In non-stop mode, | |
7485 | a race condition is possible where we've removed a breakpoint, | |
7486 | but stop events for that breakpoint are already queued and will | |
7487 | arrive later. To suppress spurious SIGTRAPs reported to user, | |
7488 | we keep this breakpoint location for a bit, and will retire it | |
7489 | after we see 3 * thread_count events. | |
1c5cfe86 | 7490 | The theory here is that reporting of events should, |
20874c92 VP |
7491 | "on the average", be fair, so after that many event we'll see |
7492 | events from all threads that have anything of interest, and no | |
1c5cfe86 | 7493 | longer need to keep this breakpoint. This is just a |
20874c92 | 7494 | heuristic, but if it's wrong, we'll report unexpected SIGTRAP, |
1c5cfe86 | 7495 | which is usability issue, but not a correctness problem. */ |
20874c92 VP |
7496 | loc->events_till_retirement = 3 * (thread_count () + 1); |
7497 | loc->owner = NULL; | |
20874c92 | 7498 | |
1c5cfe86 PA |
7499 | VEC_safe_push (bp_location_p, moribund_locations, loc); |
7500 | } | |
7501 | else | |
7502 | free_bp_location (loc); | |
20874c92 | 7503 | } |
74960c60 | 7504 | } |
1c5cfe86 | 7505 | |
74960c60 VP |
7506 | ALL_BREAKPOINTS (b) |
7507 | { | |
7508 | check_duplicates (b); | |
0d381245 | 7509 | } |
74960c60 | 7510 | |
50c71eaf | 7511 | if (breakpoints_always_inserted_mode () && should_insert |
c35b1492 | 7512 | && (have_live_inferiors () |
2567c7d9 | 7513 | || (gdbarch_has_global_breakpoints (target_gdbarch)))) |
74960c60 | 7514 | insert_breakpoint_locations (); |
f7545552 TT |
7515 | |
7516 | do_cleanups (cleanups); | |
74960c60 VP |
7517 | } |
7518 | ||
20874c92 VP |
7519 | void |
7520 | breakpoint_retire_moribund (void) | |
7521 | { | |
7522 | struct bp_location *loc; | |
7523 | int ix; | |
7524 | ||
7525 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
7526 | if (--(loc->events_till_retirement) == 0) | |
7527 | { | |
7528 | free_bp_location (loc); | |
7529 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); | |
7530 | --ix; | |
7531 | } | |
7532 | } | |
7533 | ||
74960c60 | 7534 | static void |
b60e7edf | 7535 | update_global_location_list_nothrow (int inserting) |
74960c60 VP |
7536 | { |
7537 | struct gdb_exception e; | |
7538 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
b60e7edf | 7539 | update_global_location_list (inserting); |
0d381245 VP |
7540 | } |
7541 | ||
a474d7c2 PA |
7542 | /* Clear BPT from a BPS. */ |
7543 | static void | |
7544 | bpstat_remove_breakpoint (bpstat bps, struct breakpoint *bpt) | |
7545 | { | |
7546 | bpstat bs; | |
7547 | for (bs = bps; bs; bs = bs->next) | |
7548 | if (bs->breakpoint_at && bs->breakpoint_at->owner == bpt) | |
7549 | { | |
7550 | bs->breakpoint_at = NULL; | |
7551 | bs->old_val = NULL; | |
7552 | /* bs->commands will be freed later. */ | |
7553 | } | |
7554 | } | |
7555 | ||
7556 | /* Callback for iterate_over_threads. */ | |
7557 | static int | |
7558 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
7559 | { | |
7560 | struct breakpoint *bpt = data; | |
7561 | bpstat_remove_breakpoint (th->stop_bpstat, bpt); | |
7562 | return 0; | |
7563 | } | |
7564 | ||
53a5351d JM |
7565 | /* Delete a breakpoint and clean up all traces of it in the data |
7566 | structures. */ | |
c906108c SS |
7567 | |
7568 | void | |
fba45db2 | 7569 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 7570 | { |
52f0bd74 | 7571 | struct breakpoint *b; |
74960c60 | 7572 | struct bp_location *loc, *next; |
c906108c | 7573 | |
8a3fe4f8 | 7574 | gdb_assert (bpt != NULL); |
c906108c SS |
7575 | |
7576 | /* Has this bp already been deleted? This can happen because multiple | |
7577 | lists can hold pointers to bp's. bpstat lists are especial culprits. | |
7578 | ||
7579 | One example of this happening is a watchpoint's scope bp. When the | |
7580 | scope bp triggers, we notice that the watchpoint is out of scope, and | |
7581 | delete it. We also delete its scope bp. But the scope bp is marked | |
7582 | "auto-deleting", and is already on a bpstat. That bpstat is then | |
7583 | checked for auto-deleting bp's, which are deleted. | |
7584 | ||
7585 | A real solution to this problem might involve reference counts in bp's, | |
7586 | and/or giving them pointers back to their referencing bpstat's, and | |
7587 | teaching delete_breakpoint to only free a bp's storage when no more | |
1272ad14 | 7588 | references were extent. A cheaper bandaid was chosen. */ |
c906108c SS |
7589 | if (bpt->type == bp_none) |
7590 | return; | |
7591 | ||
383f836e | 7592 | observer_notify_breakpoint_deleted (bpt->number); |
c906108c | 7593 | |
c906108c SS |
7594 | if (breakpoint_chain == bpt) |
7595 | breakpoint_chain = bpt->next; | |
7596 | ||
c906108c SS |
7597 | ALL_BREAKPOINTS (b) |
7598 | if (b->next == bpt) | |
c5aa993b JM |
7599 | { |
7600 | b->next = bpt->next; | |
7601 | break; | |
7602 | } | |
c906108c | 7603 | |
c906108c | 7604 | free_command_lines (&bpt->commands); |
c906108c | 7605 | if (bpt->cond_string != NULL) |
b8c9b27d | 7606 | xfree (bpt->cond_string); |
c906108c | 7607 | if (bpt->addr_string != NULL) |
b8c9b27d | 7608 | xfree (bpt->addr_string); |
c906108c | 7609 | if (bpt->exp != NULL) |
b8c9b27d | 7610 | xfree (bpt->exp); |
c906108c | 7611 | if (bpt->exp_string != NULL) |
b8c9b27d | 7612 | xfree (bpt->exp_string); |
c906108c SS |
7613 | if (bpt->val != NULL) |
7614 | value_free (bpt->val); | |
7615 | if (bpt->source_file != NULL) | |
b8c9b27d | 7616 | xfree (bpt->source_file); |
c906108c | 7617 | if (bpt->exec_pathname != NULL) |
b8c9b27d | 7618 | xfree (bpt->exec_pathname); |
c906108c SS |
7619 | |
7620 | /* Be sure no bpstat's are pointing at it after it's been freed. */ | |
7621 | /* FIXME, how can we find all bpstat's? | |
198757a8 VP |
7622 | We just check stop_bpstat for now. Note that we cannot just |
7623 | remove bpstats pointing at bpt from the stop_bpstat list | |
7624 | entirely, as breakpoint commands are associated with the bpstat; | |
7625 | if we remove it here, then the later call to | |
7626 | bpstat_do_actions (&stop_bpstat); | |
7627 | in event-top.c won't do anything, and temporary breakpoints | |
7628 | with commands won't work. */ | |
a474d7c2 | 7629 | |
a474d7c2 | 7630 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); |
74960c60 VP |
7631 | |
7632 | /* Now that breakpoint is removed from breakpoint | |
7633 | list, update the global location list. This | |
7634 | will remove locations that used to belong to | |
7635 | this breakpoint. Do this before freeing | |
7636 | the breakpoint itself, since remove_breakpoint | |
7637 | looks at location's owner. It might be better | |
7638 | design to have location completely self-contained, | |
7639 | but it's not the case now. */ | |
b60e7edf | 7640 | update_global_location_list (0); |
74960c60 VP |
7641 | |
7642 | ||
c906108c SS |
7643 | /* On the chance that someone will soon try again to delete this same |
7644 | bp, we mark it as deleted before freeing its storage. */ | |
7645 | bpt->type = bp_none; | |
7646 | ||
b8c9b27d | 7647 | xfree (bpt); |
c906108c SS |
7648 | } |
7649 | ||
4d6140d9 AC |
7650 | static void |
7651 | do_delete_breakpoint_cleanup (void *b) | |
7652 | { | |
7653 | delete_breakpoint (b); | |
7654 | } | |
7655 | ||
7656 | struct cleanup * | |
7657 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
7658 | { | |
7659 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
7660 | } | |
7661 | ||
c906108c | 7662 | void |
fba45db2 | 7663 | delete_command (char *arg, int from_tty) |
c906108c SS |
7664 | { |
7665 | struct breakpoint *b, *temp; | |
7666 | ||
ea9365bb TT |
7667 | dont_repeat (); |
7668 | ||
c906108c SS |
7669 | if (arg == 0) |
7670 | { | |
7671 | int breaks_to_delete = 0; | |
7672 | ||
7673 | /* Delete all breakpoints if no argument. | |
c5aa993b JM |
7674 | Do not delete internal or call-dummy breakpoints, these |
7675 | have to be deleted with an explicit breakpoint number argument. */ | |
7676 | ALL_BREAKPOINTS (b) | |
7677 | { | |
059fb39f PM |
7678 | if (b->type != bp_call_dummy |
7679 | && b->type != bp_shlib_event | |
4efc6507 | 7680 | && b->type != bp_jit_event |
059fb39f PM |
7681 | && b->type != bp_thread_event |
7682 | && b->type != bp_overlay_event | |
0fd8e87f | 7683 | && b->type != bp_longjmp_master |
059fb39f | 7684 | && b->number >= 0) |
973d738b DJ |
7685 | { |
7686 | breaks_to_delete = 1; | |
7687 | break; | |
7688 | } | |
c5aa993b | 7689 | } |
c906108c SS |
7690 | |
7691 | /* Ask user only if there are some breakpoints to delete. */ | |
7692 | if (!from_tty | |
e2e0b3e5 | 7693 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 7694 | { |
c5aa993b JM |
7695 | ALL_BREAKPOINTS_SAFE (b, temp) |
7696 | { | |
059fb39f PM |
7697 | if (b->type != bp_call_dummy |
7698 | && b->type != bp_shlib_event | |
7699 | && b->type != bp_thread_event | |
4efc6507 | 7700 | && b->type != bp_jit_event |
059fb39f | 7701 | && b->type != bp_overlay_event |
0fd8e87f | 7702 | && b->type != bp_longjmp_master |
059fb39f | 7703 | && b->number >= 0) |
c5aa993b JM |
7704 | delete_breakpoint (b); |
7705 | } | |
c906108c SS |
7706 | } |
7707 | } | |
7708 | else | |
7709 | map_breakpoint_numbers (arg, delete_breakpoint); | |
7710 | } | |
7711 | ||
0d381245 VP |
7712 | static int |
7713 | all_locations_are_pending (struct bp_location *loc) | |
fe3f5fa8 | 7714 | { |
0d381245 VP |
7715 | for (; loc; loc = loc->next) |
7716 | if (!loc->shlib_disabled) | |
7717 | return 0; | |
7718 | return 1; | |
fe3f5fa8 VP |
7719 | } |
7720 | ||
776592bf DE |
7721 | /* Subroutine of update_breakpoint_locations to simplify it. |
7722 | Return non-zero if multiple fns in list LOC have the same name. | |
7723 | Null names are ignored. */ | |
7724 | ||
7725 | static int | |
7726 | ambiguous_names_p (struct bp_location *loc) | |
7727 | { | |
7728 | struct bp_location *l; | |
7729 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
7730 | (int (*) (const void *, const void *)) streq, | |
7731 | NULL, xcalloc, xfree); | |
7732 | ||
7733 | for (l = loc; l != NULL; l = l->next) | |
7734 | { | |
7735 | const char **slot; | |
7736 | const char *name = l->function_name; | |
7737 | ||
7738 | /* Allow for some names to be NULL, ignore them. */ | |
7739 | if (name == NULL) | |
7740 | continue; | |
7741 | ||
7742 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
7743 | INSERT); | |
7744 | /* NOTE: We can assume slot != NULL here because xcalloc never returns | |
7745 | NULL. */ | |
7746 | if (*slot != NULL) | |
7747 | { | |
7748 | htab_delete (htab); | |
7749 | return 1; | |
7750 | } | |
7751 | *slot = name; | |
7752 | } | |
7753 | ||
7754 | htab_delete (htab); | |
7755 | return 0; | |
7756 | } | |
7757 | ||
fe3f5fa8 | 7758 | static void |
0d381245 VP |
7759 | update_breakpoint_locations (struct breakpoint *b, |
7760 | struct symtabs_and_lines sals) | |
fe3f5fa8 VP |
7761 | { |
7762 | int i; | |
7763 | char *s; | |
0d381245 VP |
7764 | struct bp_location *existing_locations = b->loc; |
7765 | ||
7766 | /* If there's no new locations, and all existing locations | |
7767 | are pending, don't do anything. This optimizes | |
7768 | the common case where all locations are in the same | |
7769 | shared library, that was unloaded. We'd like to | |
7770 | retain the location, so that when the library | |
7771 | is loaded again, we don't loose the enabled/disabled | |
7772 | status of the individual locations. */ | |
7773 | if (all_locations_are_pending (existing_locations) && sals.nelts == 0) | |
fe3f5fa8 VP |
7774 | return; |
7775 | ||
fe3f5fa8 VP |
7776 | b->loc = NULL; |
7777 | ||
0d381245 | 7778 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 7779 | { |
0d381245 | 7780 | struct bp_location *new_loc = |
39d61571 | 7781 | add_location_to_breakpoint (b, &(sals.sals[i])); |
fe3f5fa8 | 7782 | |
0d381245 VP |
7783 | /* Reparse conditions, they might contain references to the |
7784 | old symtab. */ | |
7785 | if (b->cond_string != NULL) | |
7786 | { | |
7787 | struct gdb_exception e; | |
fe3f5fa8 | 7788 | |
0d381245 VP |
7789 | s = b->cond_string; |
7790 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
7791 | { | |
7792 | new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), | |
7793 | 0); | |
7794 | } | |
7795 | if (e.reason < 0) | |
7796 | { | |
7797 | warning (_("failed to reevaluate condition for breakpoint %d: %s"), | |
7798 | b->number, e.message); | |
7799 | new_loc->enabled = 0; | |
7800 | } | |
7801 | } | |
fe3f5fa8 | 7802 | |
0d381245 VP |
7803 | if (b->source_file != NULL) |
7804 | xfree (b->source_file); | |
7805 | if (sals.sals[i].symtab == NULL) | |
7806 | b->source_file = NULL; | |
7807 | else | |
1b36a34b | 7808 | b->source_file = xstrdup (sals.sals[i].symtab->filename); |
fe3f5fa8 | 7809 | |
0d381245 VP |
7810 | if (b->line_number == 0) |
7811 | b->line_number = sals.sals[i].line; | |
7812 | } | |
fe3f5fa8 | 7813 | |
514f746b AR |
7814 | /* Update locations of permanent breakpoints. */ |
7815 | if (b->enable_state == bp_permanent) | |
7816 | make_breakpoint_permanent (b); | |
7817 | ||
0d381245 VP |
7818 | /* If possible, carry over 'disable' status from existing breakpoints. */ |
7819 | { | |
7820 | struct bp_location *e = existing_locations; | |
776592bf DE |
7821 | /* If there are multiple breakpoints with the same function name, |
7822 | e.g. for inline functions, comparing function names won't work. | |
7823 | Instead compare pc addresses; this is just a heuristic as things | |
7824 | may have moved, but in practice it gives the correct answer | |
7825 | often enough until a better solution is found. */ | |
7826 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
7827 | ||
0d381245 VP |
7828 | for (; e; e = e->next) |
7829 | { | |
7830 | if (!e->enabled && e->function_name) | |
7831 | { | |
7832 | struct bp_location *l = b->loc; | |
776592bf DE |
7833 | if (have_ambiguous_names) |
7834 | { | |
7835 | for (; l; l = l->next) | |
7836 | if (e->address == l->address) | |
7837 | { | |
7838 | l->enabled = 0; | |
7839 | break; | |
7840 | } | |
7841 | } | |
7842 | else | |
7843 | { | |
7844 | for (; l; l = l->next) | |
7845 | if (l->function_name | |
7846 | && strcmp (e->function_name, l->function_name) == 0) | |
7847 | { | |
7848 | l->enabled = 0; | |
7849 | break; | |
7850 | } | |
7851 | } | |
0d381245 VP |
7852 | } |
7853 | } | |
7854 | } | |
fe3f5fa8 | 7855 | |
b60e7edf | 7856 | update_global_location_list (1); |
fe3f5fa8 VP |
7857 | } |
7858 | ||
7859 | ||
c906108c SS |
7860 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
7861 | The value we return ends up being the return value from catch_errors. | |
7862 | Unused in this case. */ | |
7863 | ||
7864 | static int | |
4efb68b1 | 7865 | breakpoint_re_set_one (void *bint) |
c906108c | 7866 | { |
53a5351d JM |
7867 | /* get past catch_errs */ |
7868 | struct breakpoint *b = (struct breakpoint *) bint; | |
c906108c SS |
7869 | struct value *mark; |
7870 | int i; | |
fe3f5fa8 VP |
7871 | int not_found = 0; |
7872 | int *not_found_ptr = ¬_found; | |
7873 | struct symtabs_and_lines sals = {}; | |
ed0616c6 | 7874 | struct symtabs_and_lines expanded; |
c906108c | 7875 | char *s; |
b5de0fa7 | 7876 | enum enable_state save_enable; |
fe3f5fa8 | 7877 | struct gdb_exception e; |
f7545552 | 7878 | struct cleanup *cleanups; |
c906108c SS |
7879 | |
7880 | switch (b->type) | |
7881 | { | |
7882 | case bp_none: | |
8a3fe4f8 | 7883 | warning (_("attempted to reset apparently deleted breakpoint #%d?"), |
53a5351d | 7884 | b->number); |
c906108c SS |
7885 | return 0; |
7886 | case bp_breakpoint: | |
7887 | case bp_hardware_breakpoint: | |
1042e4c0 | 7888 | case bp_tracepoint: |
8bea4e01 UW |
7889 | /* Do not attempt to re-set breakpoints disabled during startup. */ |
7890 | if (b->enable_state == bp_startup_disabled) | |
7891 | return 0; | |
7892 | ||
c906108c SS |
7893 | if (b->addr_string == NULL) |
7894 | { | |
7895 | /* Anything without a string can't be re-set. */ | |
7896 | delete_breakpoint (b); | |
7897 | return 0; | |
7898 | } | |
c906108c SS |
7899 | |
7900 | set_language (b->language); | |
7901 | input_radix = b->input_radix; | |
7902 | s = b->addr_string; | |
fe3f5fa8 | 7903 | TRY_CATCH (e, RETURN_MASK_ERROR) |
c906108c | 7904 | { |
fe3f5fa8 VP |
7905 | sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL, |
7906 | not_found_ptr); | |
7907 | } | |
7908 | if (e.reason < 0) | |
7909 | { | |
7910 | int not_found_and_ok = 0; | |
7911 | /* For pending breakpoints, it's expected that parsing | |
7912 | will fail until the right shared library is loaded. | |
7913 | User has already told to create pending breakpoints and | |
7914 | don't need extra messages. If breakpoint is in bp_shlib_disabled | |
7915 | state, then user already saw the message about that breakpoint | |
7916 | being disabled, and don't want to see more errors. */ | |
0d381245 VP |
7917 | if (not_found |
7918 | && (b->condition_not_parsed | |
7919 | || (b->loc && b->loc->shlib_disabled) | |
7920 | || b->enable_state == bp_disabled)) | |
fe3f5fa8 VP |
7921 | not_found_and_ok = 1; |
7922 | ||
7923 | if (!not_found_and_ok) | |
c906108c | 7924 | { |
fe3f5fa8 VP |
7925 | /* We surely don't want to warn about the same breakpoint |
7926 | 10 times. One solution, implemented here, is disable | |
7927 | the breakpoint on error. Another solution would be to | |
7928 | have separate 'warning emitted' flag. Since this | |
7929 | happens only when a binary has changed, I don't know | |
7930 | which approach is better. */ | |
7931 | b->enable_state = bp_disabled; | |
7932 | throw_exception (e); | |
c906108c | 7933 | } |
fe3f5fa8 | 7934 | } |
c906108c | 7935 | |
fe3f5fa8 VP |
7936 | if (not_found) |
7937 | break; | |
7938 | ||
7939 | gdb_assert (sals.nelts == 1); | |
7940 | resolve_sal_pc (&sals.sals[0]); | |
0d381245 | 7941 | if (b->condition_not_parsed && s && s[0]) |
fe3f5fa8 VP |
7942 | { |
7943 | char *cond_string = 0; | |
7944 | int thread = -1; | |
4a306c9a JB |
7945 | int task = 0; |
7946 | ||
fe3f5fa8 | 7947 | find_condition_and_thread (s, sals.sals[0].pc, |
4a306c9a | 7948 | &cond_string, &thread, &task); |
fe3f5fa8 VP |
7949 | if (cond_string) |
7950 | b->cond_string = cond_string; | |
7951 | b->thread = thread; | |
4a306c9a | 7952 | b->task = task; |
0d381245 | 7953 | b->condition_not_parsed = 0; |
fe3f5fa8 | 7954 | } |
ed0616c6 | 7955 | expanded = expand_line_sal_maybe (sals.sals[0]); |
f7545552 | 7956 | cleanups = make_cleanup (xfree, sals.sals); |
ed0616c6 | 7957 | update_breakpoint_locations (b, expanded); |
f7545552 | 7958 | do_cleanups (cleanups); |
c906108c SS |
7959 | break; |
7960 | ||
7961 | case bp_watchpoint: | |
7962 | case bp_hardware_watchpoint: | |
7963 | case bp_read_watchpoint: | |
7964 | case bp_access_watchpoint: | |
0b3de036 VP |
7965 | /* Watchpoint can be either on expression using entirely global variables, |
7966 | or it can be on local variables. | |
7967 | ||
7968 | Watchpoints of the first kind are never auto-deleted, and even persist | |
7969 | across program restarts. Since they can use variables from shared | |
7970 | libraries, we need to reparse expression as libraries are loaded | |
7971 | and unloaded. | |
7972 | ||
7973 | Watchpoints on local variables can also change meaning as result | |
7974 | of solib event. For example, if a watchpoint uses both a local and | |
7975 | a global variables in expression, it's a local watchpoint, but | |
7976 | unloading of a shared library will make the expression invalid. | |
7977 | This is not a very common use case, but we still re-evaluate | |
7978 | expression, to avoid surprises to the user. | |
7979 | ||
7980 | Note that for local watchpoints, we re-evaluate it only if | |
7981 | watchpoints frame id is still valid. If it's not, it means | |
7982 | the watchpoint is out of scope and will be deleted soon. In fact, | |
7983 | I'm not sure we'll ever be called in this case. | |
7984 | ||
7985 | If a local watchpoint's frame id is still valid, then | |
7986 | b->exp_valid_block is likewise valid, and we can safely use it. | |
7987 | ||
7988 | Don't do anything about disabled watchpoints, since they will | |
7989 | be reevaluated again when enabled. */ | |
a5606eee | 7990 | update_watchpoint (b, 1 /* reparse */); |
c906108c | 7991 | break; |
c5aa993b JM |
7992 | /* We needn't really do anything to reset these, since the mask |
7993 | that requests them is unaffected by e.g., new libraries being | |
7994 | loaded. */ | |
ce78b96d | 7995 | case bp_catchpoint: |
c906108c | 7996 | break; |
c5aa993b | 7997 | |
c906108c | 7998 | default: |
a3f17187 | 7999 | printf_filtered (_("Deleting unknown breakpoint type %d\n"), b->type); |
c906108c | 8000 | /* fall through */ |
0fd8e87f UW |
8001 | /* Delete overlay event and longjmp master breakpoints; they will be |
8002 | reset later by breakpoint_re_set. */ | |
1900040c | 8003 | case bp_overlay_event: |
0fd8e87f | 8004 | case bp_longjmp_master: |
c906108c SS |
8005 | delete_breakpoint (b); |
8006 | break; | |
8007 | ||
c5aa993b JM |
8008 | /* This breakpoint is special, it's set up when the inferior |
8009 | starts and we really don't want to touch it. */ | |
c906108c SS |
8010 | case bp_shlib_event: |
8011 | ||
c4093a6a JM |
8012 | /* Like bp_shlib_event, this breakpoint type is special. |
8013 | Once it is set up, we do not want to touch it. */ | |
8014 | case bp_thread_event: | |
8015 | ||
c5aa993b JM |
8016 | /* Keep temporary breakpoints, which can be encountered when we step |
8017 | over a dlopen call and SOLIB_ADD is resetting the breakpoints. | |
8018 | Otherwise these should have been blown away via the cleanup chain | |
8019 | or by breakpoint_init_inferior when we rerun the executable. */ | |
c906108c SS |
8020 | case bp_until: |
8021 | case bp_finish: | |
8022 | case bp_watchpoint_scope: | |
8023 | case bp_call_dummy: | |
8024 | case bp_step_resume: | |
611c83ae PA |
8025 | case bp_longjmp: |
8026 | case bp_longjmp_resume: | |
4efc6507 | 8027 | case bp_jit_event: |
c906108c SS |
8028 | break; |
8029 | } | |
8030 | ||
8031 | return 0; | |
8032 | } | |
8033 | ||
69de3c6a | 8034 | /* Re-set all breakpoints after symbols have been re-loaded. */ |
c906108c | 8035 | void |
69de3c6a | 8036 | breakpoint_re_set (void) |
c906108c SS |
8037 | { |
8038 | struct breakpoint *b, *temp; | |
8039 | enum language save_language; | |
8040 | int save_input_radix; | |
c5aa993b | 8041 | |
c906108c SS |
8042 | save_language = current_language->la_language; |
8043 | save_input_radix = input_radix; | |
8044 | ALL_BREAKPOINTS_SAFE (b, temp) | |
c5aa993b | 8045 | { |
53a5351d | 8046 | /* Format possible error msg */ |
fe3f5fa8 | 8047 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
8048 | b->number); |
8049 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 8050 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 8051 | do_cleanups (cleanups); |
c5aa993b | 8052 | } |
c906108c SS |
8053 | set_language (save_language); |
8054 | input_radix = save_input_radix; | |
e62c965a | 8055 | |
0756c555 | 8056 | jit_breakpoint_re_set (); |
4efc6507 | 8057 | |
69de3c6a | 8058 | create_overlay_event_breakpoint ("_ovly_debug_event"); |
0fd8e87f UW |
8059 | create_longjmp_master_breakpoint ("longjmp"); |
8060 | create_longjmp_master_breakpoint ("_longjmp"); | |
8061 | create_longjmp_master_breakpoint ("siglongjmp"); | |
8062 | create_longjmp_master_breakpoint ("_siglongjmp"); | |
c906108c SS |
8063 | } |
8064 | \f | |
c906108c SS |
8065 | /* Reset the thread number of this breakpoint: |
8066 | ||
8067 | - If the breakpoint is for all threads, leave it as-is. | |
39f77062 | 8068 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 8069 | void |
fba45db2 | 8070 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
8071 | { |
8072 | if (b->thread != -1) | |
8073 | { | |
39f77062 KB |
8074 | if (in_thread_list (inferior_ptid)) |
8075 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c SS |
8076 | } |
8077 | } | |
8078 | ||
03ac34d5 MS |
8079 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
8080 | If from_tty is nonzero, it prints a message to that effect, | |
8081 | which ends with a period (no newline). */ | |
8082 | ||
c906108c | 8083 | void |
fba45db2 | 8084 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 8085 | { |
52f0bd74 | 8086 | struct breakpoint *b; |
c906108c SS |
8087 | |
8088 | if (count < 0) | |
8089 | count = 0; | |
8090 | ||
8091 | ALL_BREAKPOINTS (b) | |
8092 | if (b->number == bptnum) | |
c5aa993b JM |
8093 | { |
8094 | b->ignore_count = count; | |
221ea385 KS |
8095 | if (from_tty) |
8096 | { | |
8097 | if (count == 0) | |
a3f17187 | 8098 | printf_filtered (_("Will stop next time breakpoint %d is reached."), |
221ea385 KS |
8099 | bptnum); |
8100 | else if (count == 1) | |
a3f17187 | 8101 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
8102 | bptnum); |
8103 | else | |
a3f17187 | 8104 | printf_filtered (_("Will ignore next %d crossings of breakpoint %d."), |
221ea385 KS |
8105 | count, bptnum); |
8106 | } | |
c5aa993b | 8107 | breakpoints_changed (); |
383f836e | 8108 | observer_notify_breakpoint_modified (b->number); |
c5aa993b JM |
8109 | return; |
8110 | } | |
c906108c | 8111 | |
8a3fe4f8 | 8112 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
8113 | } |
8114 | ||
b2175913 MS |
8115 | void |
8116 | make_breakpoint_silent (struct breakpoint *b) | |
8117 | { | |
8118 | /* Silence the breakpoint. */ | |
8119 | b->silent = 1; | |
8120 | } | |
8121 | ||
c906108c SS |
8122 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
8123 | ||
8124 | static void | |
fba45db2 | 8125 | ignore_command (char *args, int from_tty) |
c906108c SS |
8126 | { |
8127 | char *p = args; | |
52f0bd74 | 8128 | int num; |
c906108c SS |
8129 | |
8130 | if (p == 0) | |
e2e0b3e5 | 8131 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 8132 | |
c906108c | 8133 | num = get_number (&p); |
5c44784c | 8134 | if (num == 0) |
8a3fe4f8 | 8135 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 8136 | if (*p == 0) |
8a3fe4f8 | 8137 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
8138 | |
8139 | set_ignore_count (num, | |
8140 | longest_to_int (value_as_long (parse_and_eval (p))), | |
8141 | from_tty); | |
221ea385 KS |
8142 | if (from_tty) |
8143 | printf_filtered ("\n"); | |
c906108c SS |
8144 | } |
8145 | \f | |
8146 | /* Call FUNCTION on each of the breakpoints | |
8147 | whose numbers are given in ARGS. */ | |
8148 | ||
8149 | static void | |
831662b3 | 8150 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *)) |
c906108c | 8151 | { |
52f0bd74 | 8152 | char *p = args; |
c906108c | 8153 | char *p1; |
52f0bd74 AC |
8154 | int num; |
8155 | struct breakpoint *b, *tmp; | |
11cf8741 | 8156 | int match; |
c906108c SS |
8157 | |
8158 | if (p == 0) | |
e2e0b3e5 | 8159 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c SS |
8160 | |
8161 | while (*p) | |
8162 | { | |
11cf8741 | 8163 | match = 0; |
c906108c | 8164 | p1 = p; |
c5aa993b | 8165 | |
5c44784c JM |
8166 | num = get_number_or_range (&p1); |
8167 | if (num == 0) | |
c5aa993b | 8168 | { |
8a3fe4f8 | 8169 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
8170 | } |
8171 | else | |
8172 | { | |
8173 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
8174 | if (b->number == num) | |
8175 | { | |
8176 | struct breakpoint *related_breakpoint = b->related_breakpoint; | |
11cf8741 | 8177 | match = 1; |
5c44784c JM |
8178 | function (b); |
8179 | if (related_breakpoint) | |
8180 | function (related_breakpoint); | |
11cf8741 | 8181 | break; |
5c44784c | 8182 | } |
11cf8741 | 8183 | if (match == 0) |
a3f17187 | 8184 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 8185 | } |
c906108c SS |
8186 | p = p1; |
8187 | } | |
8188 | } | |
8189 | ||
0d381245 VP |
8190 | static struct bp_location * |
8191 | find_location_by_number (char *number) | |
8192 | { | |
8193 | char *dot = strchr (number, '.'); | |
8194 | char *p1; | |
8195 | int bp_num; | |
8196 | int loc_num; | |
8197 | struct breakpoint *b; | |
8198 | struct bp_location *loc; | |
8199 | ||
8200 | *dot = '\0'; | |
8201 | ||
8202 | p1 = number; | |
8203 | bp_num = get_number_or_range (&p1); | |
8204 | if (bp_num == 0) | |
8205 | error (_("Bad breakpoint number '%s'"), number); | |
8206 | ||
8207 | ALL_BREAKPOINTS (b) | |
8208 | if (b->number == bp_num) | |
8209 | { | |
8210 | break; | |
8211 | } | |
8212 | ||
8213 | if (!b || b->number != bp_num) | |
8214 | error (_("Bad breakpoint number '%s'"), number); | |
8215 | ||
8216 | p1 = dot+1; | |
8217 | loc_num = get_number_or_range (&p1); | |
8218 | if (loc_num == 0) | |
8219 | error (_("Bad breakpoint location number '%s'"), number); | |
8220 | ||
8221 | --loc_num; | |
8222 | loc = b->loc; | |
8223 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
8224 | ; | |
8225 | if (!loc) | |
8226 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
8227 | ||
8228 | return loc; | |
8229 | } | |
8230 | ||
8231 | ||
1900040c MS |
8232 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
8233 | If from_tty is nonzero, it prints a message to that effect, | |
8234 | which ends with a period (no newline). */ | |
8235 | ||
c906108c | 8236 | void |
fba45db2 | 8237 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
8238 | { |
8239 | /* Never disable a watchpoint scope breakpoint; we want to | |
8240 | hit them when we leave scope so we can delete both the | |
8241 | watchpoint and its scope breakpoint at that time. */ | |
8242 | if (bpt->type == bp_watchpoint_scope) | |
8243 | return; | |
8244 | ||
c2c6d25f | 8245 | /* You can't disable permanent breakpoints. */ |
b5de0fa7 | 8246 | if (bpt->enable_state == bp_permanent) |
c2c6d25f JM |
8247 | return; |
8248 | ||
b5de0fa7 | 8249 | bpt->enable_state = bp_disabled; |
c906108c | 8250 | |
b60e7edf | 8251 | update_global_location_list (0); |
c906108c | 8252 | |
383f836e | 8253 | observer_notify_breakpoint_modified (bpt->number); |
c906108c SS |
8254 | } |
8255 | ||
c906108c | 8256 | static void |
fba45db2 | 8257 | disable_command (char *args, int from_tty) |
c906108c | 8258 | { |
52f0bd74 | 8259 | struct breakpoint *bpt; |
c906108c SS |
8260 | if (args == 0) |
8261 | ALL_BREAKPOINTS (bpt) | |
8262 | switch (bpt->type) | |
c5aa993b JM |
8263 | { |
8264 | case bp_none: | |
8a3fe4f8 | 8265 | warning (_("attempted to disable apparently deleted breakpoint #%d?"), |
53a5351d | 8266 | bpt->number); |
c5aa993b JM |
8267 | continue; |
8268 | case bp_breakpoint: | |
1042e4c0 | 8269 | case bp_tracepoint: |
ce78b96d | 8270 | case bp_catchpoint: |
c5aa993b JM |
8271 | case bp_hardware_breakpoint: |
8272 | case bp_watchpoint: | |
8273 | case bp_hardware_watchpoint: | |
8274 | case bp_read_watchpoint: | |
8275 | case bp_access_watchpoint: | |
8276 | disable_breakpoint (bpt); | |
8277 | default: | |
8278 | continue; | |
8279 | } | |
0d381245 VP |
8280 | else if (strchr (args, '.')) |
8281 | { | |
8282 | struct bp_location *loc = find_location_by_number (args); | |
8283 | if (loc) | |
8284 | loc->enabled = 0; | |
b60e7edf | 8285 | update_global_location_list (0); |
0d381245 | 8286 | } |
c906108c SS |
8287 | else |
8288 | map_breakpoint_numbers (args, disable_breakpoint); | |
8289 | } | |
8290 | ||
8291 | static void | |
fba45db2 | 8292 | do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition) |
c906108c | 8293 | { |
c906108c SS |
8294 | int target_resources_ok, other_type_used; |
8295 | struct value *mark; | |
8296 | ||
8297 | if (bpt->type == bp_hardware_breakpoint) | |
8298 | { | |
8299 | int i; | |
c5aa993b | 8300 | i = hw_breakpoint_used_count (); |
53a5351d | 8301 | target_resources_ok = |
d92524f1 | 8302 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 8303 | i + 1, 0); |
c906108c | 8304 | if (target_resources_ok == 0) |
8a3fe4f8 | 8305 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 8306 | else if (target_resources_ok < 0) |
8a3fe4f8 | 8307 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
8308 | } |
8309 | ||
059fb39f PM |
8310 | if (bpt->type == bp_watchpoint |
8311 | || bpt->type == bp_hardware_watchpoint | |
8312 | || bpt->type == bp_read_watchpoint | |
8313 | || bpt->type == bp_access_watchpoint) | |
c906108c | 8314 | { |
dde02812 ES |
8315 | struct gdb_exception e; |
8316 | ||
8317 | TRY_CATCH (e, RETURN_MASK_ALL) | |
c906108c | 8318 | { |
dde02812 | 8319 | update_watchpoint (bpt, 1 /* reparse */); |
c906108c | 8320 | } |
dde02812 | 8321 | if (e.reason < 0) |
c5aa993b | 8322 | { |
dde02812 ES |
8323 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
8324 | bpt->number); | |
8325 | return; | |
c5aa993b | 8326 | } |
c906108c | 8327 | } |
0101ce28 | 8328 | |
b4c291bb KH |
8329 | if (bpt->enable_state != bp_permanent) |
8330 | bpt->enable_state = bp_enabled; | |
8331 | bpt->disposition = disposition; | |
b60e7edf | 8332 | update_global_location_list (1); |
b4c291bb KH |
8333 | breakpoints_changed (); |
8334 | ||
383f836e | 8335 | observer_notify_breakpoint_modified (bpt->number); |
c906108c SS |
8336 | } |
8337 | ||
fe3f5fa8 | 8338 | |
c906108c | 8339 | void |
fba45db2 | 8340 | enable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
8341 | { |
8342 | do_enable_breakpoint (bpt, bpt->disposition); | |
8343 | } | |
8344 | ||
8345 | /* The enable command enables the specified breakpoints (or all defined | |
8346 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 8347 | in stopping the inferior. */ |
c906108c | 8348 | |
c906108c | 8349 | static void |
fba45db2 | 8350 | enable_command (char *args, int from_tty) |
c906108c | 8351 | { |
52f0bd74 | 8352 | struct breakpoint *bpt; |
c906108c SS |
8353 | if (args == 0) |
8354 | ALL_BREAKPOINTS (bpt) | |
8355 | switch (bpt->type) | |
c5aa993b JM |
8356 | { |
8357 | case bp_none: | |
8a3fe4f8 | 8358 | warning (_("attempted to enable apparently deleted breakpoint #%d?"), |
53a5351d | 8359 | bpt->number); |
c5aa993b JM |
8360 | continue; |
8361 | case bp_breakpoint: | |
1042e4c0 | 8362 | case bp_tracepoint: |
ce78b96d | 8363 | case bp_catchpoint: |
c5aa993b JM |
8364 | case bp_hardware_breakpoint: |
8365 | case bp_watchpoint: | |
8366 | case bp_hardware_watchpoint: | |
8367 | case bp_read_watchpoint: | |
8368 | case bp_access_watchpoint: | |
8369 | enable_breakpoint (bpt); | |
8370 | default: | |
8371 | continue; | |
8372 | } | |
0d381245 VP |
8373 | else if (strchr (args, '.')) |
8374 | { | |
8375 | struct bp_location *loc = find_location_by_number (args); | |
8376 | if (loc) | |
8377 | loc->enabled = 1; | |
b60e7edf | 8378 | update_global_location_list (1); |
0d381245 | 8379 | } |
c906108c SS |
8380 | else |
8381 | map_breakpoint_numbers (args, enable_breakpoint); | |
8382 | } | |
8383 | ||
8384 | static void | |
fba45db2 | 8385 | enable_once_breakpoint (struct breakpoint *bpt) |
c906108c | 8386 | { |
b5de0fa7 | 8387 | do_enable_breakpoint (bpt, disp_disable); |
c906108c SS |
8388 | } |
8389 | ||
c906108c | 8390 | static void |
fba45db2 | 8391 | enable_once_command (char *args, int from_tty) |
c906108c SS |
8392 | { |
8393 | map_breakpoint_numbers (args, enable_once_breakpoint); | |
8394 | } | |
8395 | ||
8396 | static void | |
fba45db2 | 8397 | enable_delete_breakpoint (struct breakpoint *bpt) |
c906108c | 8398 | { |
b5de0fa7 | 8399 | do_enable_breakpoint (bpt, disp_del); |
c906108c SS |
8400 | } |
8401 | ||
c906108c | 8402 | static void |
fba45db2 | 8403 | enable_delete_command (char *args, int from_tty) |
c906108c SS |
8404 | { |
8405 | map_breakpoint_numbers (args, enable_delete_breakpoint); | |
8406 | } | |
8407 | \f | |
fa8d40ab JJ |
8408 | static void |
8409 | set_breakpoint_cmd (char *args, int from_tty) | |
8410 | { | |
8411 | } | |
8412 | ||
8413 | static void | |
8414 | show_breakpoint_cmd (char *args, int from_tty) | |
8415 | { | |
8416 | } | |
8417 | ||
c906108c SS |
8418 | /* Use default_breakpoint_'s, or nothing if they aren't valid. */ |
8419 | ||
8420 | struct symtabs_and_lines | |
fba45db2 | 8421 | decode_line_spec_1 (char *string, int funfirstline) |
c906108c SS |
8422 | { |
8423 | struct symtabs_and_lines sals; | |
8424 | if (string == 0) | |
8a3fe4f8 | 8425 | error (_("Empty line specification.")); |
c906108c SS |
8426 | if (default_breakpoint_valid) |
8427 | sals = decode_line_1 (&string, funfirstline, | |
53a5351d JM |
8428 | default_breakpoint_symtab, |
8429 | default_breakpoint_line, | |
68219205 | 8430 | (char ***) NULL, NULL); |
c906108c SS |
8431 | else |
8432 | sals = decode_line_1 (&string, funfirstline, | |
68219205 | 8433 | (struct symtab *) NULL, 0, (char ***) NULL, NULL); |
c906108c | 8434 | if (*string) |
8a3fe4f8 | 8435 | error (_("Junk at end of line specification: %s"), string); |
c906108c SS |
8436 | return sals; |
8437 | } | |
8181d85f DJ |
8438 | |
8439 | /* Create and insert a raw software breakpoint at PC. Return an | |
8440 | identifier, which should be used to remove the breakpoint later. | |
8441 | In general, places which call this should be using something on the | |
8442 | breakpoint chain instead; this function should be eliminated | |
8443 | someday. */ | |
8444 | ||
8445 | void * | |
a6d9a66e | 8446 | deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch, CORE_ADDR pc) |
8181d85f DJ |
8447 | { |
8448 | struct bp_target_info *bp_tgt; | |
8449 | ||
8450 | bp_tgt = xmalloc (sizeof (struct bp_target_info)); | |
8451 | memset (bp_tgt, 0, sizeof (struct bp_target_info)); | |
8452 | ||
8453 | bp_tgt->placed_address = pc; | |
a6d9a66e | 8454 | if (target_insert_breakpoint (gdbarch, bp_tgt) != 0) |
8181d85f DJ |
8455 | { |
8456 | /* Could not insert the breakpoint. */ | |
8457 | xfree (bp_tgt); | |
8458 | return NULL; | |
8459 | } | |
8460 | ||
8461 | return bp_tgt; | |
8462 | } | |
8463 | ||
8464 | /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */ | |
8465 | ||
8466 | int | |
a6d9a66e | 8467 | deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp) |
8181d85f DJ |
8468 | { |
8469 | struct bp_target_info *bp_tgt = bp; | |
8470 | int ret; | |
8471 | ||
a6d9a66e | 8472 | ret = target_remove_breakpoint (gdbarch, bp_tgt); |
8181d85f DJ |
8473 | xfree (bp_tgt); |
8474 | ||
8475 | return ret; | |
8476 | } | |
8477 | ||
8478 | /* One (or perhaps two) breakpoints used for software single stepping. */ | |
8479 | ||
8480 | static void *single_step_breakpoints[2]; | |
a6d9a66e | 8481 | static struct gdbarch *single_step_gdbarch[2]; |
8181d85f DJ |
8482 | |
8483 | /* Create and insert a breakpoint for software single step. */ | |
8484 | ||
8485 | void | |
a6d9a66e | 8486 | insert_single_step_breakpoint (struct gdbarch *gdbarch, CORE_ADDR next_pc) |
8181d85f DJ |
8487 | { |
8488 | void **bpt_p; | |
8489 | ||
8490 | if (single_step_breakpoints[0] == NULL) | |
a6d9a66e UW |
8491 | { |
8492 | bpt_p = &single_step_breakpoints[0]; | |
8493 | single_step_gdbarch[0] = gdbarch; | |
8494 | } | |
8181d85f DJ |
8495 | else |
8496 | { | |
8497 | gdb_assert (single_step_breakpoints[1] == NULL); | |
8498 | bpt_p = &single_step_breakpoints[1]; | |
a6d9a66e | 8499 | single_step_gdbarch[1] = gdbarch; |
8181d85f DJ |
8500 | } |
8501 | ||
8502 | /* NOTE drow/2006-04-11: A future improvement to this function would be | |
8503 | to only create the breakpoints once, and actually put them on the | |
8504 | breakpoint chain. That would let us use set_raw_breakpoint. We could | |
8505 | adjust the addresses each time they were needed. Doing this requires | |
8506 | corresponding changes elsewhere where single step breakpoints are | |
8507 | handled, however. So, for now, we use this. */ | |
8508 | ||
a6d9a66e | 8509 | *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, next_pc); |
8181d85f | 8510 | if (*bpt_p == NULL) |
5af949e3 UW |
8511 | error (_("Could not insert single-step breakpoint at %s"), |
8512 | paddress (gdbarch, next_pc)); | |
8181d85f DJ |
8513 | } |
8514 | ||
8515 | /* Remove and delete any breakpoints used for software single step. */ | |
8516 | ||
8517 | void | |
8518 | remove_single_step_breakpoints (void) | |
8519 | { | |
8520 | gdb_assert (single_step_breakpoints[0] != NULL); | |
8521 | ||
8522 | /* See insert_single_step_breakpoint for more about this deprecated | |
8523 | call. */ | |
a6d9a66e UW |
8524 | deprecated_remove_raw_breakpoint (single_step_gdbarch[0], |
8525 | single_step_breakpoints[0]); | |
8526 | single_step_gdbarch[0] = NULL; | |
8181d85f DJ |
8527 | single_step_breakpoints[0] = NULL; |
8528 | ||
8529 | if (single_step_breakpoints[1] != NULL) | |
8530 | { | |
a6d9a66e UW |
8531 | deprecated_remove_raw_breakpoint (single_step_gdbarch[1], |
8532 | single_step_breakpoints[1]); | |
8533 | single_step_gdbarch[1] = NULL; | |
8181d85f DJ |
8534 | single_step_breakpoints[1] = NULL; |
8535 | } | |
8536 | } | |
8537 | ||
1aafd4da UW |
8538 | /* Check whether a software single-step breakpoint is inserted at PC. */ |
8539 | ||
8540 | static int | |
8541 | single_step_breakpoint_inserted_here_p (CORE_ADDR pc) | |
8542 | { | |
8543 | int i; | |
8544 | ||
8545 | for (i = 0; i < 2; i++) | |
8546 | { | |
8547 | struct bp_target_info *bp_tgt = single_step_breakpoints[i]; | |
8548 | if (bp_tgt && bp_tgt->placed_address == pc) | |
8549 | return 1; | |
8550 | } | |
8551 | ||
8552 | return 0; | |
8553 | } | |
8554 | ||
1042e4c0 SS |
8555 | /* Tracepoint-specific operations. */ |
8556 | ||
8557 | /* Set tracepoint count to NUM. */ | |
8558 | static void | |
8559 | set_tracepoint_count (int num) | |
8560 | { | |
8561 | tracepoint_count = num; | |
4fa62494 | 8562 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
8563 | } |
8564 | ||
8565 | void | |
8566 | trace_command (char *arg, int from_tty) | |
8567 | { | |
a6d9a66e UW |
8568 | break_command_really (get_current_arch (), |
8569 | arg, | |
1042e4c0 SS |
8570 | NULL, 0, 1 /* parse arg */, |
8571 | 0 /* tempflag */, 0 /* hardwareflag */, | |
8572 | 1 /* traceflag */, | |
8573 | 0 /* Ignore count */, | |
8574 | pending_break_support, | |
8575 | NULL, | |
8576 | from_tty, | |
8577 | 1 /* enabled */); | |
8578 | set_tracepoint_count (breakpoint_count); | |
8579 | } | |
8580 | ||
8581 | /* Print information on tracepoint number TPNUM_EXP, or all if | |
8582 | omitted. */ | |
8583 | ||
8584 | static void | |
8585 | tracepoints_info (char *tpnum_exp, int from_tty) | |
8586 | { | |
8587 | struct breakpoint *b; | |
8588 | int tps_to_list = 0; | |
8589 | ||
8590 | /* In the no-arguments case, say "No tracepoints" if none found. */ | |
8591 | if (tpnum_exp == 0) | |
8592 | { | |
8593 | ALL_TRACEPOINTS (b) | |
8594 | { | |
8595 | if (b->number >= 0) | |
8596 | { | |
8597 | tps_to_list = 1; | |
8598 | break; | |
8599 | } | |
8600 | } | |
8601 | if (!tps_to_list) | |
8602 | { | |
8603 | ui_out_message (uiout, 0, "No tracepoints.\n"); | |
8604 | return; | |
8605 | } | |
8606 | } | |
8607 | ||
8608 | /* Otherwise be the same as "info break". */ | |
8609 | breakpoints_info (tpnum_exp, from_tty); | |
8610 | } | |
8611 | ||
8612 | /* The 'enable trace' command enables tracepoints. | |
8613 | Not supported by all targets. */ | |
8614 | static void | |
8615 | enable_trace_command (char *args, int from_tty) | |
8616 | { | |
8617 | enable_command (args, from_tty); | |
8618 | } | |
8619 | ||
8620 | /* The 'disable trace' command disables tracepoints. | |
8621 | Not supported by all targets. */ | |
8622 | static void | |
8623 | disable_trace_command (char *args, int from_tty) | |
8624 | { | |
8625 | disable_command (args, from_tty); | |
8626 | } | |
8627 | ||
8628 | /* Remove a tracepoint (or all if no argument) */ | |
8629 | static void | |
8630 | delete_trace_command (char *arg, int from_tty) | |
8631 | { | |
8632 | struct breakpoint *b, *temp; | |
8633 | ||
8634 | dont_repeat (); | |
8635 | ||
8636 | if (arg == 0) | |
8637 | { | |
8638 | int breaks_to_delete = 0; | |
8639 | ||
8640 | /* Delete all breakpoints if no argument. | |
8641 | Do not delete internal or call-dummy breakpoints, these | |
8642 | have to be deleted with an explicit breakpoint number argument. */ | |
8643 | ALL_TRACEPOINTS (b) | |
8644 | { | |
8645 | if (b->number >= 0) | |
8646 | { | |
8647 | breaks_to_delete = 1; | |
8648 | break; | |
8649 | } | |
8650 | } | |
8651 | ||
8652 | /* Ask user only if there are some breakpoints to delete. */ | |
8653 | if (!from_tty | |
8654 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
8655 | { | |
8656 | ALL_BREAKPOINTS_SAFE (b, temp) | |
8657 | { | |
059fb39f PM |
8658 | if (b->type == bp_tracepoint |
8659 | && b->number >= 0) | |
1042e4c0 SS |
8660 | delete_breakpoint (b); |
8661 | } | |
8662 | } | |
8663 | } | |
8664 | else | |
8665 | map_breakpoint_numbers (arg, delete_breakpoint); | |
8666 | } | |
8667 | ||
8668 | /* Set passcount for tracepoint. | |
8669 | ||
8670 | First command argument is passcount, second is tracepoint number. | |
8671 | If tracepoint number omitted, apply to most recently defined. | |
8672 | Also accepts special argument "all". */ | |
8673 | ||
8674 | static void | |
8675 | trace_pass_command (char *args, int from_tty) | |
8676 | { | |
8677 | struct breakpoint *t1 = (struct breakpoint *) -1, *t2; | |
8678 | unsigned int count; | |
8679 | int all = 0; | |
8680 | ||
8681 | if (args == 0 || *args == 0) | |
8682 | error (_("passcount command requires an argument (count + optional TP num)")); | |
8683 | ||
8684 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ | |
8685 | ||
8686 | while (*args && isspace ((int) *args)) | |
8687 | args++; | |
8688 | ||
8689 | if (*args && strncasecmp (args, "all", 3) == 0) | |
8690 | { | |
8691 | args += 3; /* Skip special argument "all". */ | |
8692 | all = 1; | |
8693 | if (*args) | |
8694 | error (_("Junk at end of arguments.")); | |
8695 | } | |
8696 | else | |
8697 | t1 = get_tracepoint_by_number (&args, 1, 1); | |
8698 | ||
8699 | do | |
8700 | { | |
8701 | if (t1) | |
8702 | { | |
8703 | ALL_TRACEPOINTS (t2) | |
8704 | if (t1 == (struct breakpoint *) -1 || t1 == t2) | |
8705 | { | |
8706 | t2->pass_count = count; | |
8707 | observer_notify_tracepoint_modified (t2->number); | |
8708 | if (from_tty) | |
8709 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
8710 | t2->number, count); | |
8711 | } | |
8712 | if (! all && *args) | |
8713 | t1 = get_tracepoint_by_number (&args, 1, 0); | |
8714 | } | |
8715 | } | |
8716 | while (*args); | |
8717 | } | |
8718 | ||
8719 | struct breakpoint * | |
8720 | get_tracepoint (int num) | |
8721 | { | |
8722 | struct breakpoint *t; | |
8723 | ||
8724 | ALL_TRACEPOINTS (t) | |
8725 | if (t->number == num) | |
8726 | return t; | |
8727 | ||
8728 | return NULL; | |
8729 | } | |
8730 | ||
8731 | /* Utility: parse a tracepoint number and look it up in the list. | |
8732 | If MULTI_P is true, there might be a range of tracepoints in ARG. | |
8733 | if OPTIONAL_P is true, then if the argument is missing, the most | |
8734 | recent tracepoint (tracepoint_count) is returned. */ | |
8735 | struct breakpoint * | |
8736 | get_tracepoint_by_number (char **arg, int multi_p, int optional_p) | |
8737 | { | |
8738 | extern int tracepoint_count; | |
8739 | struct breakpoint *t; | |
8740 | int tpnum; | |
8741 | char *instring = arg == NULL ? NULL : *arg; | |
8742 | ||
8743 | if (arg == NULL || *arg == NULL || ! **arg) | |
8744 | { | |
8745 | if (optional_p) | |
8746 | tpnum = tracepoint_count; | |
8747 | else | |
8748 | error_no_arg (_("tracepoint number")); | |
8749 | } | |
8750 | else | |
8751 | tpnum = multi_p ? get_number_or_range (arg) : get_number (arg); | |
8752 | ||
8753 | if (tpnum <= 0) | |
8754 | { | |
8755 | if (instring && *instring) | |
8756 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
8757 | instring); | |
8758 | else | |
8759 | printf_filtered (_("Tracepoint argument missing and no previous tracepoint\n")); | |
8760 | return NULL; | |
8761 | } | |
8762 | ||
8763 | ALL_TRACEPOINTS (t) | |
8764 | if (t->number == tpnum) | |
8765 | { | |
8766 | return t; | |
8767 | } | |
8768 | ||
8769 | /* FIXME: if we are in the middle of a range we don't want to give | |
8770 | a message. The current interface to get_number_or_range doesn't | |
8771 | allow us to discover this. */ | |
8772 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); | |
8773 | return NULL; | |
8774 | } | |
8775 | ||
8776 | /* save-tracepoints command */ | |
8777 | static void | |
8778 | tracepoint_save_command (char *args, int from_tty) | |
8779 | { | |
8780 | struct breakpoint *tp; | |
8781 | int any_tp = 0; | |
8782 | struct action_line *line; | |
8783 | FILE *fp; | |
8784 | char *i1 = " ", *i2 = " "; | |
8785 | char *indent, *actionline, *pathname; | |
8786 | char tmp[40]; | |
8787 | struct cleanup *cleanup; | |
8788 | ||
8789 | if (args == 0 || *args == 0) | |
8790 | error (_("Argument required (file name in which to save tracepoints)")); | |
8791 | ||
8792 | /* See if we have anything to save. */ | |
8793 | ALL_TRACEPOINTS (tp) | |
8794 | { | |
8795 | any_tp = 1; | |
8796 | break; | |
8797 | } | |
8798 | if (!any_tp) | |
8799 | { | |
8800 | warning (_("save-tracepoints: no tracepoints to save.")); | |
8801 | return; | |
8802 | } | |
8803 | ||
8804 | pathname = tilde_expand (args); | |
8805 | cleanup = make_cleanup (xfree, pathname); | |
059fb39f PM |
8806 | fp = fopen (pathname, "w"); |
8807 | if (!fp) | |
1042e4c0 SS |
8808 | error (_("Unable to open file '%s' for saving tracepoints (%s)"), |
8809 | args, safe_strerror (errno)); | |
8810 | make_cleanup_fclose (fp); | |
8811 | ||
8812 | ALL_TRACEPOINTS (tp) | |
8813 | { | |
8814 | if (tp->addr_string) | |
8815 | fprintf (fp, "trace %s\n", tp->addr_string); | |
8816 | else | |
8817 | { | |
8818 | sprintf_vma (tmp, tp->loc->address); | |
8819 | fprintf (fp, "trace *0x%s\n", tmp); | |
8820 | } | |
8821 | ||
8822 | if (tp->pass_count) | |
8823 | fprintf (fp, " passcount %d\n", tp->pass_count); | |
8824 | ||
8825 | if (tp->actions) | |
8826 | { | |
8827 | fprintf (fp, " actions\n"); | |
8828 | indent = i1; | |
8829 | for (line = tp->actions; line; line = line->next) | |
8830 | { | |
8831 | struct cmd_list_element *cmd; | |
8832 | ||
8833 | QUIT; /* allow user to bail out with ^C */ | |
8834 | actionline = line->action; | |
8835 | while (isspace ((int) *actionline)) | |
8836 | actionline++; | |
8837 | ||
8838 | fprintf (fp, "%s%s\n", indent, actionline); | |
8839 | if (*actionline != '#') /* skip for comment lines */ | |
8840 | { | |
8841 | cmd = lookup_cmd (&actionline, cmdlist, "", -1, 1); | |
8842 | if (cmd == 0) | |
8843 | error (_("Bad action list item: %s"), actionline); | |
8844 | if (cmd_cfunc_eq (cmd, while_stepping_pseudocommand)) | |
8845 | indent = i2; | |
8846 | else if (cmd_cfunc_eq (cmd, end_actions_pseudocommand)) | |
8847 | indent = i1; | |
8848 | } | |
8849 | } | |
8850 | } | |
8851 | } | |
8852 | do_cleanups (cleanup); | |
8853 | if (from_tty) | |
8854 | printf_filtered (_("Tracepoints saved to file '%s'.\n"), args); | |
8855 | return; | |
8856 | } | |
8857 | ||
8858 | /* Create a vector of all tracepoints. */ | |
8859 | ||
8860 | VEC(breakpoint_p) * | |
8861 | all_tracepoints () | |
8862 | { | |
8863 | VEC(breakpoint_p) *tp_vec = 0; | |
8864 | struct breakpoint *tp; | |
8865 | ||
8866 | ALL_TRACEPOINTS (tp) | |
8867 | { | |
8868 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
8869 | } | |
8870 | ||
8871 | return tp_vec; | |
8872 | } | |
8873 | ||
c906108c | 8874 | \f |
31e2b00f AS |
8875 | /* This help string is used for the break, hbreak, tbreak and thbreak commands. |
8876 | It is defined as a macro to prevent duplication. | |
8877 | COMMAND should be a string constant containing the name of the command. */ | |
8878 | #define BREAK_ARGS_HELP(command) \ | |
8879 | command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\ | |
8880 | LOCATION may be a line number, function name, or \"*\" and an address.\n\ | |
8881 | If a line number is specified, break at start of code for that line.\n\ | |
8882 | If a function is specified, break at start of code for that function.\n\ | |
8883 | If an address is specified, break at that exact address.\n\ | |
8884 | With no LOCATION, uses current execution address of selected stack frame.\n\ | |
8885 | This is useful for breaking on return to a stack frame.\n\ | |
8886 | \n\ | |
8887 | THREADNUM is the number from \"info threads\".\n\ | |
8888 | CONDITION is a boolean expression.\n\ | |
8889 | \n\ | |
8890 | Multiple breakpoints at one place are permitted, and useful if conditional.\n\ | |
8891 | \n\ | |
8892 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
8893 | ||
44feb3ce TT |
8894 | /* List of subcommands for "catch". */ |
8895 | static struct cmd_list_element *catch_cmdlist; | |
8896 | ||
8897 | /* List of subcommands for "tcatch". */ | |
8898 | static struct cmd_list_element *tcatch_cmdlist; | |
8899 | ||
8900 | /* Like add_cmd, but add the command to both the "catch" and "tcatch" | |
8901 | lists, and pass some additional user data to the command function. */ | |
8902 | static void | |
8903 | add_catch_command (char *name, char *docstring, | |
8904 | void (*sfunc) (char *args, int from_tty, | |
8905 | struct cmd_list_element *command), | |
8906 | void *user_data_catch, | |
8907 | void *user_data_tcatch) | |
8908 | { | |
8909 | struct cmd_list_element *command; | |
8910 | ||
8911 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
8912 | &catch_cmdlist); | |
8913 | set_cmd_sfunc (command, sfunc); | |
8914 | set_cmd_context (command, user_data_catch); | |
8915 | ||
8916 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
8917 | &tcatch_cmdlist); | |
8918 | set_cmd_sfunc (command, sfunc); | |
8919 | set_cmd_context (command, user_data_tcatch); | |
8920 | } | |
8921 | ||
c906108c | 8922 | void |
fba45db2 | 8923 | _initialize_breakpoint (void) |
c906108c | 8924 | { |
fa8d40ab JJ |
8925 | static struct cmd_list_element *breakpoint_set_cmdlist; |
8926 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
c906108c SS |
8927 | struct cmd_list_element *c; |
8928 | ||
84acb35a | 8929 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
84acb35a | 8930 | |
c906108c SS |
8931 | breakpoint_chain = 0; |
8932 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
8933 | before a breakpoint is set. */ | |
8934 | breakpoint_count = 0; | |
8935 | ||
1042e4c0 SS |
8936 | tracepoint_count = 0; |
8937 | ||
1bedd215 AC |
8938 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
8939 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
8940 | Usage is `ignore N COUNT'.")); | |
c906108c | 8941 | if (xdb_commands) |
c5aa993b | 8942 | add_com_alias ("bc", "ignore", class_breakpoint, 1); |
c906108c | 8943 | |
1bedd215 AC |
8944 | add_com ("commands", class_breakpoint, commands_command, _("\ |
8945 | Set commands to be executed when a breakpoint is hit.\n\ | |
c906108c SS |
8946 | Give breakpoint number as argument after \"commands\".\n\ |
8947 | With no argument, the targeted breakpoint is the last one set.\n\ | |
8948 | The commands themselves follow starting on the next line.\n\ | |
8949 | Type a line containing \"end\" to indicate the end of them.\n\ | |
8950 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 8951 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 8952 | |
1bedd215 AC |
8953 | add_com ("condition", class_breakpoint, condition_command, _("\ |
8954 | Specify breakpoint number N to break only if COND is true.\n\ | |
c906108c | 8955 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 8956 | expression to be evaluated whenever breakpoint N is reached.")); |
c906108c | 8957 | |
1bedd215 | 8958 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 8959 | Set a temporary breakpoint.\n\ |
c906108c SS |
8960 | Like \"break\" except the breakpoint is only temporary,\n\ |
8961 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
8962 | by using \"enable delete\" on the breakpoint number.\n\ |
8963 | \n" | |
8964 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 8965 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 8966 | |
1bedd215 | 8967 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
31e2b00f | 8968 | Set a hardware assisted breakpoint.\n\ |
c906108c | 8969 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
8970 | some target hardware may not have this support.\n\ |
8971 | \n" | |
8972 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 8973 | set_cmd_completer (c, location_completer); |
c906108c | 8974 | |
1bedd215 | 8975 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 8976 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 8977 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
8978 | so it will be deleted when hit.\n\ |
8979 | \n" | |
8980 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 8981 | set_cmd_completer (c, location_completer); |
c906108c | 8982 | |
1bedd215 AC |
8983 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
8984 | Enable some breakpoints.\n\ | |
c906108c SS |
8985 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
8986 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
8987 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 8988 | With a subcommand you can enable temporarily."), |
c906108c SS |
8989 | &enablelist, "enable ", 1, &cmdlist); |
8990 | if (xdb_commands) | |
1bedd215 AC |
8991 | add_com ("ab", class_breakpoint, enable_command, _("\ |
8992 | Enable some breakpoints.\n\ | |
c906108c SS |
8993 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
8994 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
8995 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 8996 | With a subcommand you can enable temporarily.")); |
c906108c SS |
8997 | |
8998 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
8999 | ||
1bedd215 AC |
9000 | add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
9001 | Enable some breakpoints.\n\ | |
c906108c SS |
9002 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
9003 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 9004 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 9005 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 9006 | |
1a966eab AC |
9007 | add_cmd ("once", no_class, enable_once_command, _("\ |
9008 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
9009 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
9010 | &enablebreaklist); |
9011 | ||
1a966eab AC |
9012 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
9013 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
9014 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
9015 | &enablebreaklist); |
9016 | ||
1a966eab AC |
9017 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
9018 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
9019 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
9020 | &enablelist); |
9021 | ||
1a966eab AC |
9022 | add_cmd ("once", no_class, enable_once_command, _("\ |
9023 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
9024 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
9025 | &enablelist); |
9026 | ||
1bedd215 AC |
9027 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
9028 | Disable some breakpoints.\n\ | |
c906108c SS |
9029 | Arguments are breakpoint numbers with spaces in between.\n\ |
9030 | To disable all breakpoints, give no argument.\n\ | |
1bedd215 | 9031 | A disabled breakpoint is not forgotten, but has no effect until reenabled."), |
c906108c SS |
9032 | &disablelist, "disable ", 1, &cmdlist); |
9033 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
9034 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
9035 | if (xdb_commands) | |
1bedd215 AC |
9036 | add_com ("sb", class_breakpoint, disable_command, _("\ |
9037 | Disable some breakpoints.\n\ | |
c906108c SS |
9038 | Arguments are breakpoint numbers with spaces in between.\n\ |
9039 | To disable all breakpoints, give no argument.\n\ | |
1bedd215 | 9040 | A disabled breakpoint is not forgotten, but has no effect until reenabled.")); |
c906108c | 9041 | |
1a966eab AC |
9042 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
9043 | Disable some breakpoints.\n\ | |
c906108c SS |
9044 | Arguments are breakpoint numbers with spaces in between.\n\ |
9045 | To disable all breakpoints, give no argument.\n\ | |
9046 | A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\ | |
1a966eab | 9047 | This command may be abbreviated \"disable\"."), |
c906108c SS |
9048 | &disablelist); |
9049 | ||
1bedd215 AC |
9050 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
9051 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
9052 | Arguments are breakpoint numbers with spaces in between.\n\ |
9053 | To delete all breakpoints, give no argument.\n\ | |
9054 | \n\ | |
9055 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 9056 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
9057 | &deletelist, "delete ", 1, &cmdlist); |
9058 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 9059 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 9060 | if (xdb_commands) |
1bedd215 AC |
9061 | add_com ("db", class_breakpoint, delete_command, _("\ |
9062 | Delete some breakpoints.\n\ | |
c906108c | 9063 | Arguments are breakpoint numbers with spaces in between.\n\ |
1bedd215 | 9064 | To delete all breakpoints, give no argument.\n")); |
c906108c | 9065 | |
1a966eab AC |
9066 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
9067 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
9068 | Arguments are breakpoint numbers with spaces in between.\n\ |
9069 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 9070 | This command may be abbreviated \"delete\"."), |
c906108c SS |
9071 | &deletelist); |
9072 | ||
1bedd215 AC |
9073 | add_com ("clear", class_breakpoint, clear_command, _("\ |
9074 | Clear breakpoint at specified line or function.\n\ | |
c906108c SS |
9075 | Argument may be line number, function name, or \"*\" and an address.\n\ |
9076 | If line number is specified, all breakpoints in that line are cleared.\n\ | |
9077 | If function is specified, breakpoints at beginning of function are cleared.\n\ | |
1bedd215 AC |
9078 | If an address is specified, breakpoints at that address are cleared.\n\ |
9079 | \n\ | |
9080 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
c906108c SS |
9081 | is executing in.\n\ |
9082 | \n\ | |
1bedd215 | 9083 | See also the \"delete\" command which clears breakpoints by number.")); |
c906108c | 9084 | |
1bedd215 | 9085 | c = add_com ("break", class_breakpoint, break_command, _("\ |
31e2b00f AS |
9086 | Set breakpoint at specified line or function.\n" |
9087 | BREAK_ARGS_HELP ("break"))); | |
5ba2abeb | 9088 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 9089 | |
c906108c SS |
9090 | add_com_alias ("b", "break", class_run, 1); |
9091 | add_com_alias ("br", "break", class_run, 1); | |
9092 | add_com_alias ("bre", "break", class_run, 1); | |
9093 | add_com_alias ("brea", "break", class_run, 1); | |
9094 | ||
7681d515 PM |
9095 | if (xdb_commands) |
9096 | add_com_alias ("ba", "break", class_breakpoint, 1); | |
c906108c SS |
9097 | |
9098 | if (dbx_commands) | |
9099 | { | |
1bedd215 AC |
9100 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
9101 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
9102 | &stoplist, "stop ", 1, &cmdlist); |
9103 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 9104 | _("Break in function or address."), &stoplist); |
c5aa993b | 9105 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 9106 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
9107 | add_com ("status", class_info, breakpoints_info, _("\ |
9108 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
9109 | The \"Type\" column indicates one of:\n\ |
9110 | \tbreakpoint - normal breakpoint\n\ | |
9111 | \twatchpoint - watchpoint\n\ | |
9112 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
9113 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
9114 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
9115 | address and file/line number respectively.\n\ |
9116 | \n\ | |
9117 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
9118 | are set to the address of the last breakpoint listed unless the command\n\ |
9119 | is prefixed with \"server \".\n\n\ | |
c906108c | 9120 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 9121 | breakpoint set.")); |
c906108c SS |
9122 | } |
9123 | ||
1bedd215 AC |
9124 | add_info ("breakpoints", breakpoints_info, _("\ |
9125 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
9126 | The \"Type\" column indicates one of:\n\ |
9127 | \tbreakpoint - normal breakpoint\n\ | |
9128 | \twatchpoint - watchpoint\n\ | |
9129 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
9130 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
9131 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
9132 | address and file/line number respectively.\n\ |
9133 | \n\ | |
9134 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
9135 | are set to the address of the last breakpoint listed unless the command\n\ |
9136 | is prefixed with \"server \".\n\n\ | |
c906108c | 9137 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 9138 | breakpoint set.")); |
c906108c SS |
9139 | |
9140 | if (xdb_commands) | |
1bedd215 AC |
9141 | add_com ("lb", class_breakpoint, breakpoints_info, _("\ |
9142 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
9143 | The \"Type\" column indicates one of:\n\ |
9144 | \tbreakpoint - normal breakpoint\n\ | |
9145 | \twatchpoint - watchpoint\n\ | |
9146 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
9147 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
9148 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
9149 | address and file/line number respectively.\n\ |
9150 | \n\ | |
9151 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
9152 | are set to the address of the last breakpoint listed unless the command\n\ |
9153 | is prefixed with \"server \".\n\n\ | |
c906108c | 9154 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 9155 | breakpoint set.")); |
c906108c | 9156 | |
1a966eab AC |
9157 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
9158 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
9159 | The \"Type\" column indicates one of:\n\ |
9160 | \tbreakpoint - normal breakpoint\n\ | |
9161 | \twatchpoint - watchpoint\n\ | |
9162 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
9163 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
9164 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
9165 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
9166 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
9167 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
9168 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
9169 | address and file/line number respectively.\n\ |
9170 | \n\ | |
9171 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
9172 | are set to the address of the last breakpoint listed unless the command\n\ |
9173 | is prefixed with \"server \".\n\n\ | |
c906108c | 9174 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 9175 | breakpoint set."), |
c906108c SS |
9176 | &maintenanceinfolist); |
9177 | ||
44feb3ce TT |
9178 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
9179 | Set catchpoints to catch events."), | |
9180 | &catch_cmdlist, "catch ", | |
9181 | 0/*allow-unknown*/, &cmdlist); | |
9182 | ||
9183 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
9184 | Set temporary catchpoints to catch events."), | |
9185 | &tcatch_cmdlist, "tcatch ", | |
9186 | 0/*allow-unknown*/, &cmdlist); | |
9187 | ||
9188 | /* Add catch and tcatch sub-commands. */ | |
9189 | add_catch_command ("catch", _("\ | |
9190 | Catch an exception, when caught.\n\ | |
9191 | With an argument, catch only exceptions with the given name."), | |
9192 | catch_catch_command, | |
9193 | CATCH_PERMANENT, | |
9194 | CATCH_TEMPORARY); | |
9195 | add_catch_command ("throw", _("\ | |
9196 | Catch an exception, when thrown.\n\ | |
9197 | With an argument, catch only exceptions with the given name."), | |
9198 | catch_throw_command, | |
9199 | CATCH_PERMANENT, | |
9200 | CATCH_TEMPORARY); | |
9201 | add_catch_command ("fork", _("Catch calls to fork."), | |
9202 | catch_fork_command_1, | |
9203 | (void *) (uintptr_t) catch_fork_permanent, | |
9204 | (void *) (uintptr_t) catch_fork_temporary); | |
9205 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
9206 | catch_fork_command_1, | |
9207 | (void *) (uintptr_t) catch_vfork_permanent, | |
9208 | (void *) (uintptr_t) catch_vfork_temporary); | |
9209 | add_catch_command ("exec", _("Catch calls to exec."), | |
9210 | catch_exec_command_1, | |
9211 | CATCH_PERMANENT, | |
9212 | CATCH_TEMPORARY); | |
44feb3ce TT |
9213 | add_catch_command ("exception", _("\ |
9214 | Catch Ada exceptions, when raised.\n\ | |
9215 | With an argument, catch only exceptions with the given name."), | |
9216 | catch_ada_exception_command, | |
9217 | CATCH_PERMANENT, | |
9218 | CATCH_TEMPORARY); | |
9219 | add_catch_command ("assert", _("\ | |
9220 | Catch failed Ada assertions, when raised.\n\ | |
9221 | With an argument, catch only exceptions with the given name."), | |
9222 | catch_assert_command, | |
9223 | CATCH_PERMANENT, | |
9224 | CATCH_TEMPORARY); | |
c5aa993b | 9225 | |
1bedd215 AC |
9226 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
9227 | Set a watchpoint for an expression.\n\ | |
c906108c | 9228 | A watchpoint stops execution of your program whenever the value of\n\ |
1bedd215 | 9229 | an expression changes.")); |
65d12d83 | 9230 | set_cmd_completer (c, expression_completer); |
c906108c | 9231 | |
1bedd215 AC |
9232 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
9233 | Set a read watchpoint for an expression.\n\ | |
c906108c | 9234 | A watchpoint stops execution of your program whenever the value of\n\ |
1bedd215 | 9235 | an expression is read.")); |
65d12d83 | 9236 | set_cmd_completer (c, expression_completer); |
c906108c | 9237 | |
1bedd215 AC |
9238 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
9239 | Set a watchpoint for an expression.\n\ | |
c906108c | 9240 | A watchpoint stops execution of your program whenever the value of\n\ |
1bedd215 | 9241 | an expression is either read or written.")); |
65d12d83 | 9242 | set_cmd_completer (c, expression_completer); |
c906108c SS |
9243 | |
9244 | add_info ("watchpoints", breakpoints_info, | |
1bedd215 | 9245 | _("Synonym for ``info breakpoints''.")); |
c906108c SS |
9246 | |
9247 | ||
920d2a44 AC |
9248 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
9249 | respond to changes - contrary to the description. */ | |
85c07804 AC |
9250 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
9251 | &can_use_hw_watchpoints, _("\ | |
9252 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
9253 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
9254 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
9255 | such is available. (However, any hardware watchpoints that were\n\ | |
9256 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
9257 | hardware.)"), |
9258 | NULL, | |
920d2a44 | 9259 | show_can_use_hw_watchpoints, |
85c07804 | 9260 | &setlist, &showlist); |
c906108c SS |
9261 | |
9262 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 9263 | |
1042e4c0 SS |
9264 | /* Tracepoint manipulation commands. */ |
9265 | ||
9266 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
9267 | Set a tracepoint at specified line or function.\n\ | |
9268 | \n" | |
9269 | BREAK_ARGS_HELP ("trace") "\n\ | |
9270 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
9271 | set_cmd_completer (c, location_completer); | |
9272 | ||
9273 | add_com_alias ("tp", "trace", class_alias, 0); | |
9274 | add_com_alias ("tr", "trace", class_alias, 1); | |
9275 | add_com_alias ("tra", "trace", class_alias, 1); | |
9276 | add_com_alias ("trac", "trace", class_alias, 1); | |
9277 | ||
9278 | add_info ("tracepoints", tracepoints_info, _("\ | |
9279 | Status of tracepoints, or tracepoint number NUMBER.\n\ | |
9280 | Convenience variable \"$tpnum\" contains the number of the\n\ | |
9281 | last tracepoint set.")); | |
9282 | ||
9283 | add_info_alias ("tp", "tracepoints", 1); | |
9284 | ||
9285 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
9286 | Delete specified tracepoints.\n\ | |
9287 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
9288 | No argument means delete all tracepoints."), | |
9289 | &deletelist); | |
9290 | ||
9291 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
9292 | Disable specified tracepoints.\n\ | |
9293 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
9294 | No argument means disable all tracepoints."), | |
9295 | &disablelist); | |
9296 | deprecate_cmd (c, "disable"); | |
9297 | ||
9298 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
9299 | Enable specified tracepoints.\n\ | |
9300 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
9301 | No argument means enable all tracepoints."), | |
9302 | &enablelist); | |
9303 | deprecate_cmd (c, "enable"); | |
9304 | ||
9305 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
9306 | Set the passcount for a tracepoint.\n\ | |
9307 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
9308 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
9309 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
9310 | ||
9311 | c = add_com ("save-tracepoints", class_trace, tracepoint_save_command, _("\ | |
9312 | Save current tracepoint definitions as a script.\n\ | |
9313 | Use the 'source' command in another debug session to restore them.")); | |
9314 | set_cmd_completer (c, filename_completer); | |
9315 | ||
1bedd215 | 9316 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
9317 | Breakpoint specific settings\n\ |
9318 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 9319 | pending breakpoint behavior"), |
fa8d40ab JJ |
9320 | &breakpoint_set_cmdlist, "set breakpoint ", |
9321 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 9322 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
9323 | Breakpoint specific settings\n\ |
9324 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 9325 | pending breakpoint behavior"), |
fa8d40ab JJ |
9326 | &breakpoint_show_cmdlist, "show breakpoint ", |
9327 | 0/*allow-unknown*/, &showlist); | |
9328 | ||
7915a72c AC |
9329 | add_setshow_auto_boolean_cmd ("pending", no_class, |
9330 | &pending_break_support, _("\ | |
9331 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
9332 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
9333 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
9334 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
9335 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 9336 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 9337 | NULL, |
920d2a44 | 9338 | show_pending_break_support, |
6e1d7d6c AC |
9339 | &breakpoint_set_cmdlist, |
9340 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
9341 | |
9342 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
9343 | |
9344 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
9345 | &automatic_hardware_breakpoints, _("\ | |
9346 | Set automatic usage of hardware breakpoints."), _("\ | |
9347 | Show automatic usage of hardware breakpoints."), _("\ | |
9348 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
9349 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
9350 | a warning will be emitted for such breakpoints."), | |
9351 | NULL, | |
9352 | show_automatic_hardware_breakpoints, | |
9353 | &breakpoint_set_cmdlist, | |
9354 | &breakpoint_show_cmdlist); | |
74960c60 | 9355 | |
33e5cbd6 PA |
9356 | add_setshow_enum_cmd ("always-inserted", class_support, |
9357 | always_inserted_enums, &always_inserted_mode, _("\ | |
74960c60 VP |
9358 | Set mode for inserting breakpoints."), _("\ |
9359 | Show mode for inserting breakpoints."), _("\ | |
33e5cbd6 PA |
9360 | When this mode is off, breakpoints are inserted in inferior when it is\n\ |
9361 | resumed, and removed when execution stops. When this mode is on,\n\ | |
9362 | breakpoints are inserted immediately and removed only when the user\n\ | |
9363 | deletes the breakpoint. When this mode is auto (which is the default),\n\ | |
9364 | the behaviour depends on the non-stop setting (see help set non-stop).\n\ | |
9365 | In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\ | |
9366 | behaves as if always-inserted mode is on; if gdb is controlling the\n\ | |
9367 | inferior in all-stop mode, gdb behaves as if always-inserted mode is off."), | |
74960c60 VP |
9368 | NULL, |
9369 | &show_always_inserted_mode, | |
9370 | &breakpoint_set_cmdlist, | |
9371 | &breakpoint_show_cmdlist); | |
765dc015 VP |
9372 | |
9373 | automatic_hardware_breakpoints = 1; | |
f3b1572e PA |
9374 | |
9375 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
c906108c | 9376 | } |