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" |
c906108c | 62 | |
1042e4c0 SS |
63 | /* readline include files */ |
64 | #include "readline/readline.h" | |
65 | #include "readline/history.h" | |
66 | ||
67 | /* readline defines this. */ | |
68 | #undef savestring | |
69 | ||
034dad6f | 70 | #include "mi/mi-common.h" |
104c1213 | 71 | |
44feb3ce TT |
72 | /* Arguments to pass as context to some catch command handlers. */ |
73 | #define CATCH_PERMANENT ((void *) (uintptr_t) 0) | |
74 | #define CATCH_TEMPORARY ((void *) (uintptr_t) 1) | |
c906108c | 75 | |
44feb3ce | 76 | /* Prototypes for local functions. */ |
c906108c | 77 | |
a14ed312 | 78 | static void enable_delete_command (char *, int); |
c906108c | 79 | |
a14ed312 | 80 | static void enable_delete_breakpoint (struct breakpoint *); |
c906108c | 81 | |
a14ed312 | 82 | static void enable_once_command (char *, int); |
c906108c | 83 | |
a14ed312 | 84 | static void enable_once_breakpoint (struct breakpoint *); |
c906108c | 85 | |
a14ed312 | 86 | static void disable_command (char *, int); |
c906108c | 87 | |
a14ed312 | 88 | static void enable_command (char *, int); |
c906108c | 89 | |
a14ed312 | 90 | static void map_breakpoint_numbers (char *, void (*)(struct breakpoint *)); |
c906108c | 91 | |
a14ed312 | 92 | static void ignore_command (char *, int); |
c906108c | 93 | |
4efb68b1 | 94 | static int breakpoint_re_set_one (void *); |
c906108c | 95 | |
a14ed312 | 96 | static void clear_command (char *, int); |
c906108c | 97 | |
a14ed312 | 98 | static void catch_command (char *, int); |
c906108c | 99 | |
a14ed312 | 100 | static void watch_command (char *, int); |
c906108c | 101 | |
a14ed312 | 102 | static int can_use_hardware_watchpoint (struct value *); |
c906108c | 103 | |
98deb0da | 104 | static void break_command_1 (char *, int, int); |
c906108c | 105 | |
a14ed312 | 106 | static void mention (struct breakpoint *); |
c906108c | 107 | |
63c252f8 PM |
108 | /* This function is used in gdbtk sources and thus can not be made static. */ |
109 | struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch, | |
a6d9a66e UW |
110 | struct symtab_and_line, |
111 | enum bptype); | |
c906108c | 112 | |
9f60f21b | 113 | static void check_duplicates (struct breakpoint *); |
c906108c | 114 | |
76897487 KB |
115 | static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); |
116 | ||
a6d9a66e UW |
117 | static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch, |
118 | CORE_ADDR bpaddr, | |
88f7da05 | 119 | enum bptype bptype); |
76897487 | 120 | |
5af949e3 UW |
121 | static void describe_other_breakpoints (struct gdbarch *, CORE_ADDR, |
122 | struct obj_section *, int); | |
c906108c | 123 | |
a14ed312 | 124 | static void breakpoints_info (char *, int); |
c906108c | 125 | |
a14ed312 | 126 | static void breakpoint_1 (int, int); |
c906108c | 127 | |
89f9893c | 128 | static bpstat bpstat_alloc (const struct bp_location *, bpstat); |
c906108c | 129 | |
4efb68b1 | 130 | static int breakpoint_cond_eval (void *); |
c906108c | 131 | |
4efb68b1 | 132 | static void cleanup_executing_breakpoints (void *); |
c906108c | 133 | |
a14ed312 | 134 | static void commands_command (char *, int); |
c906108c | 135 | |
a14ed312 | 136 | static void condition_command (char *, int); |
c906108c | 137 | |
a14ed312 | 138 | static int get_number_trailer (char **, int); |
c906108c | 139 | |
a14ed312 | 140 | void set_breakpoint_count (int); |
c906108c | 141 | |
c5aa993b JM |
142 | typedef enum |
143 | { | |
144 | mark_inserted, | |
145 | mark_uninserted | |
146 | } | |
147 | insertion_state_t; | |
c906108c | 148 | |
0bde7532 | 149 | static int remove_breakpoint (struct bp_location *, insertion_state_t); |
c906108c | 150 | |
a14ed312 | 151 | static enum print_stop_action print_it_typical (bpstat); |
e514a9d6 JM |
152 | |
153 | static enum print_stop_action print_bp_stop_message (bpstat bs); | |
c906108c | 154 | |
4efb68b1 | 155 | static int watchpoint_check (void *); |
c906108c | 156 | |
a14ed312 | 157 | static void maintenance_info_breakpoints (char *, int); |
c906108c | 158 | |
a14ed312 | 159 | static int hw_breakpoint_used_count (void); |
c906108c | 160 | |
a14ed312 | 161 | static int hw_watchpoint_used_count (enum bptype, int *); |
c906108c | 162 | |
a14ed312 | 163 | static void hbreak_command (char *, int); |
c906108c | 164 | |
a14ed312 | 165 | static void thbreak_command (char *, int); |
c906108c | 166 | |
a14ed312 | 167 | static void watch_command_1 (char *, int, int); |
c906108c | 168 | |
a14ed312 | 169 | static void rwatch_command (char *, int); |
c906108c | 170 | |
a14ed312 | 171 | static void awatch_command (char *, int); |
c906108c | 172 | |
a14ed312 | 173 | static void do_enable_breakpoint (struct breakpoint *, enum bpdisp); |
c906108c | 174 | |
a14ed312 | 175 | static void stop_command (char *arg, int from_tty); |
7a292a7a | 176 | |
a14ed312 | 177 | static void stopin_command (char *arg, int from_tty); |
7a292a7a | 178 | |
a14ed312 | 179 | static void stopat_command (char *arg, int from_tty); |
7a292a7a | 180 | |
a14ed312 | 181 | static char *ep_parse_optional_if_clause (char **arg); |
7a292a7a | 182 | |
a14ed312 | 183 | static char *ep_parse_optional_filename (char **arg); |
7a292a7a | 184 | |
d85310f7 MS |
185 | static void catch_exception_command_1 (enum exception_event_kind ex_event, |
186 | char *arg, int tempflag, int from_tty); | |
7a292a7a | 187 | |
a14ed312 | 188 | static void tcatch_command (char *arg, int from_tty); |
7a292a7a | 189 | |
a14ed312 | 190 | static void ep_skip_leading_whitespace (char **s); |
7a292a7a | 191 | |
1aafd4da UW |
192 | static int single_step_breakpoint_inserted_here_p (CORE_ADDR pc); |
193 | ||
fe3f5fa8 VP |
194 | static void free_bp_location (struct bp_location *loc); |
195 | ||
39d61571 | 196 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
a5606eee | 197 | |
b60e7edf | 198 | static void update_global_location_list (int); |
a5606eee | 199 | |
b60e7edf | 200 | static void update_global_location_list_nothrow (int); |
74960c60 VP |
201 | |
202 | static int is_hardware_watchpoint (struct breakpoint *bpt); | |
203 | ||
204 | static void insert_breakpoint_locations (void); | |
a5606eee | 205 | |
1042e4c0 SS |
206 | static void tracepoints_info (char *, int); |
207 | ||
208 | static void delete_trace_command (char *, int); | |
209 | ||
210 | static void enable_trace_command (char *, int); | |
211 | ||
212 | static void disable_trace_command (char *, int); | |
213 | ||
214 | static void trace_pass_command (char *, int); | |
215 | ||
3daf8fe5 JG |
216 | static void skip_prologue_sal (struct symtab_and_line *sal); |
217 | ||
218 | ||
f3b1572e PA |
219 | /* Flag indicating that a command has proceeded the inferior past the |
220 | current breakpoint. */ | |
221 | ||
222 | static int breakpoint_proceeded; | |
223 | ||
2cec12e5 AR |
224 | static const char * |
225 | bpdisp_text (enum bpdisp disp) | |
226 | { | |
227 | /* NOTE: the following values are a part of MI protocol and represent | |
228 | values of 'disp' field returned when inferior stops at a breakpoint. */ | |
229 | static char *bpdisps[] = {"del", "dstp", "dis", "keep"}; | |
230 | return bpdisps[(int) disp]; | |
231 | } | |
c906108c | 232 | |
2cec12e5 | 233 | /* Prototypes for exported functions. */ |
c906108c SS |
234 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
235 | if such is available. */ | |
236 | static int can_use_hw_watchpoints; | |
237 | ||
920d2a44 AC |
238 | static void |
239 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, | |
240 | struct cmd_list_element *c, | |
241 | const char *value) | |
242 | { | |
243 | fprintf_filtered (file, _("\ | |
244 | Debugger's willingness to use watchpoint hardware is %s.\n"), | |
245 | value); | |
246 | } | |
247 | ||
fa8d40ab JJ |
248 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
249 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints | |
250 | for unrecognized breakpoint locations. | |
251 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ | |
252 | static enum auto_boolean pending_break_support; | |
920d2a44 AC |
253 | static void |
254 | show_pending_break_support (struct ui_file *file, int from_tty, | |
255 | struct cmd_list_element *c, | |
256 | const char *value) | |
257 | { | |
258 | fprintf_filtered (file, _("\ | |
259 | Debugger's behavior regarding pending breakpoints is %s.\n"), | |
260 | value); | |
261 | } | |
fa8d40ab | 262 | |
765dc015 VP |
263 | /* If 1, gdb will automatically use hardware breakpoints for breakpoints |
264 | set with "break" but falling in read-only memory. | |
265 | If 0, gdb will warn about such breakpoints, but won't automatically | |
266 | use hardware breakpoints. */ | |
267 | static int automatic_hardware_breakpoints; | |
268 | static void | |
269 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, | |
270 | struct cmd_list_element *c, | |
271 | const char *value) | |
272 | { | |
273 | fprintf_filtered (file, _("\ | |
274 | Automatic usage of hardware breakpoints is %s.\n"), | |
275 | value); | |
276 | } | |
277 | ||
33e5cbd6 PA |
278 | /* If on, gdb will keep breakpoints inserted even as inferior is |
279 | stopped, and immediately insert any new breakpoints. If off, gdb | |
280 | will insert breakpoints into inferior only when resuming it, and | |
281 | will remove breakpoints upon stop. If auto, GDB will behave as ON | |
282 | if in non-stop mode, and as OFF if all-stop mode.*/ | |
283 | ||
284 | static const char always_inserted_auto[] = "auto"; | |
285 | static const char always_inserted_on[] = "on"; | |
286 | static const char always_inserted_off[] = "off"; | |
287 | static const char *always_inserted_enums[] = { | |
288 | always_inserted_auto, | |
289 | always_inserted_off, | |
290 | always_inserted_on, | |
291 | NULL | |
292 | }; | |
293 | static const char *always_inserted_mode = always_inserted_auto; | |
294 | static void | |
74960c60 | 295 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
33e5cbd6 | 296 | struct cmd_list_element *c, const char *value) |
74960c60 | 297 | { |
33e5cbd6 PA |
298 | if (always_inserted_mode == always_inserted_auto) |
299 | fprintf_filtered (file, _("\ | |
300 | Always inserted breakpoint mode is %s (currently %s).\n"), | |
301 | value, | |
302 | breakpoints_always_inserted_mode () ? "on" : "off"); | |
303 | else | |
304 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), value); | |
74960c60 VP |
305 | } |
306 | ||
33e5cbd6 PA |
307 | int |
308 | breakpoints_always_inserted_mode (void) | |
309 | { | |
310 | return (always_inserted_mode == always_inserted_on | |
311 | || (always_inserted_mode == always_inserted_auto && non_stop)); | |
312 | } | |
765dc015 | 313 | |
a14ed312 | 314 | void _initialize_breakpoint (void); |
c906108c | 315 | |
c906108c SS |
316 | /* Are we executing breakpoint commands? */ |
317 | static int executing_breakpoint_commands; | |
318 | ||
c02f5703 MS |
319 | /* Are overlay event breakpoints enabled? */ |
320 | static int overlay_events_enabled; | |
321 | ||
8bea4e01 UW |
322 | /* Are we executing startup code? */ |
323 | static int executing_startup; | |
324 | ||
c906108c SS |
325 | /* Walk the following statement or block through all breakpoints. |
326 | ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current | |
327 | breakpoint. */ | |
328 | ||
5c44784c | 329 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
c906108c | 330 | |
5c44784c JM |
331 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
332 | for (B = breakpoint_chain; \ | |
333 | B ? (TMP=B->next, 1): 0; \ | |
334 | B = TMP) | |
c906108c | 335 | |
7cc221ef DJ |
336 | /* Similar iterators for the low-level breakpoints. */ |
337 | ||
0d381245 | 338 | #define ALL_BP_LOCATIONS(B) for (B = bp_location_chain; B; B = B->global_next) |
7cc221ef DJ |
339 | |
340 | #define ALL_BP_LOCATIONS_SAFE(B,TMP) \ | |
341 | for (B = bp_location_chain; \ | |
0d381245 | 342 | B ? (TMP=B->global_next, 1): 0; \ |
7cc221ef DJ |
343 | B = TMP) |
344 | ||
1042e4c0 SS |
345 | /* Iterator for tracepoints only. */ |
346 | ||
347 | #define ALL_TRACEPOINTS(B) \ | |
348 | for (B = breakpoint_chain; B; B = B->next) \ | |
349 | if ((B)->type == bp_tracepoint) | |
350 | ||
7cc221ef | 351 | /* Chains of all breakpoints defined. */ |
c906108c SS |
352 | |
353 | struct breakpoint *breakpoint_chain; | |
354 | ||
7cc221ef DJ |
355 | struct bp_location *bp_location_chain; |
356 | ||
20874c92 VP |
357 | /* The locations that no longer correspond to any breakpoint, |
358 | unlinked from bp_location_chain, but for which a hit | |
359 | may still be reported by a target. */ | |
360 | VEC(bp_location_p) *moribund_locations = NULL; | |
361 | ||
c906108c SS |
362 | /* Number of last breakpoint made. */ |
363 | ||
364 | int breakpoint_count; | |
365 | ||
1042e4c0 SS |
366 | /* Number of last tracepoint made. */ |
367 | ||
368 | int tracepoint_count; | |
369 | ||
468d015d JJ |
370 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
371 | static int | |
372 | breakpoint_enabled (struct breakpoint *b) | |
373 | { | |
0d381245 | 374 | return (b->enable_state == bp_enabled); |
468d015d JJ |
375 | } |
376 | ||
c906108c SS |
377 | /* Set breakpoint count to NUM. */ |
378 | ||
379 | void | |
fba45db2 | 380 | set_breakpoint_count (int num) |
c906108c SS |
381 | { |
382 | breakpoint_count = num; | |
4fa62494 | 383 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
c906108c SS |
384 | } |
385 | ||
386 | /* Used in run_command to zero the hit count when a new run starts. */ | |
387 | ||
388 | void | |
fba45db2 | 389 | clear_breakpoint_hit_counts (void) |
c906108c SS |
390 | { |
391 | struct breakpoint *b; | |
392 | ||
393 | ALL_BREAKPOINTS (b) | |
394 | b->hit_count = 0; | |
395 | } | |
396 | ||
397 | /* Default address, symtab and line to put a breakpoint at | |
398 | for "break" command with no arg. | |
399 | if default_breakpoint_valid is zero, the other three are | |
400 | not valid, and "break" with no arg is an error. | |
401 | ||
402 | This set by print_stack_frame, which calls set_default_breakpoint. */ | |
403 | ||
404 | int default_breakpoint_valid; | |
405 | CORE_ADDR default_breakpoint_address; | |
406 | struct symtab *default_breakpoint_symtab; | |
407 | int default_breakpoint_line; | |
408 | \f | |
409 | /* *PP is a string denoting a breakpoint. Get the number of the breakpoint. | |
410 | Advance *PP after the string and any trailing whitespace. | |
411 | ||
412 | Currently the string can either be a number or "$" followed by the name | |
413 | of a convenience variable. Making it an expression wouldn't work well | |
5c44784c | 414 | for map_breakpoint_numbers (e.g. "4 + 5 + 6"). |
40c03ae8 EZ |
415 | |
416 | If the string is a NULL pointer, that denotes the last breakpoint. | |
5c44784c JM |
417 | |
418 | TRAILER is a character which can be found after the number; most | |
419 | commonly this is `-'. If you don't want a trailer, use \0. */ | |
c906108c | 420 | static int |
fba45db2 | 421 | get_number_trailer (char **pp, int trailer) |
c906108c | 422 | { |
5c44784c | 423 | int retval = 0; /* default */ |
c906108c SS |
424 | char *p = *pp; |
425 | ||
426 | if (p == NULL) | |
427 | /* Empty line means refer to the last breakpoint. */ | |
428 | return breakpoint_count; | |
429 | else if (*p == '$') | |
430 | { | |
431 | /* Make a copy of the name, so we can null-terminate it | |
c5aa993b | 432 | to pass to lookup_internalvar(). */ |
c906108c SS |
433 | char *varname; |
434 | char *start = ++p; | |
4fa62494 | 435 | LONGEST val; |
c906108c SS |
436 | |
437 | while (isalnum (*p) || *p == '_') | |
438 | p++; | |
439 | varname = (char *) alloca (p - start + 1); | |
440 | strncpy (varname, start, p - start); | |
441 | varname[p - start] = '\0'; | |
4fa62494 UW |
442 | if (get_internalvar_integer (lookup_internalvar (varname), &val)) |
443 | retval = (int) val; | |
5c44784c JM |
444 | else |
445 | { | |
a3f17187 | 446 | printf_filtered (_("Convenience variable must have integer value.\n")); |
5c44784c JM |
447 | retval = 0; |
448 | } | |
c906108c SS |
449 | } |
450 | else | |
451 | { | |
452 | if (*p == '-') | |
453 | ++p; | |
454 | while (*p >= '0' && *p <= '9') | |
455 | ++p; | |
456 | if (p == *pp) | |
457 | /* There is no number here. (e.g. "cond a == b"). */ | |
5c44784c JM |
458 | { |
459 | /* Skip non-numeric token */ | |
460 | while (*p && !isspace((int) *p)) | |
461 | ++p; | |
462 | /* Return zero, which caller must interpret as error. */ | |
463 | retval = 0; | |
464 | } | |
465 | else | |
466 | retval = atoi (*pp); | |
467 | } | |
468 | if (!(isspace (*p) || *p == '\0' || *p == trailer)) | |
469 | { | |
470 | /* Trailing junk: return 0 and let caller print error msg. */ | |
471 | while (!(isspace (*p) || *p == '\0' || *p == trailer)) | |
472 | ++p; | |
473 | retval = 0; | |
c906108c | 474 | } |
c906108c SS |
475 | while (isspace (*p)) |
476 | p++; | |
477 | *pp = p; | |
478 | return retval; | |
479 | } | |
5c44784c | 480 | |
11cf8741 | 481 | |
5c44784c JM |
482 | /* Like get_number_trailer, but don't allow a trailer. */ |
483 | int | |
fba45db2 | 484 | get_number (char **pp) |
5c44784c JM |
485 | { |
486 | return get_number_trailer (pp, '\0'); | |
487 | } | |
488 | ||
489 | /* Parse a number or a range. | |
490 | * A number will be of the form handled by get_number. | |
491 | * A range will be of the form <number1> - <number2>, and | |
492 | * will represent all the integers between number1 and number2, | |
493 | * inclusive. | |
494 | * | |
495 | * While processing a range, this fuction is called iteratively; | |
496 | * At each call it will return the next value in the range. | |
497 | * | |
498 | * At the beginning of parsing a range, the char pointer PP will | |
499 | * be advanced past <number1> and left pointing at the '-' token. | |
500 | * Subsequent calls will not advance the pointer until the range | |
501 | * is completed. The call that completes the range will advance | |
502 | * pointer PP past <number2>. | |
503 | */ | |
504 | ||
505 | int | |
fba45db2 | 506 | get_number_or_range (char **pp) |
5c44784c JM |
507 | { |
508 | static int last_retval, end_value; | |
509 | static char *end_ptr; | |
510 | static int in_range = 0; | |
511 | ||
512 | if (**pp != '-') | |
513 | { | |
514 | /* Default case: pp is pointing either to a solo number, | |
515 | or to the first number of a range. */ | |
516 | last_retval = get_number_trailer (pp, '-'); | |
517 | if (**pp == '-') | |
518 | { | |
519 | char **temp; | |
520 | ||
521 | /* This is the start of a range (<number1> - <number2>). | |
522 | Skip the '-', parse and remember the second number, | |
523 | and also remember the end of the final token. */ | |
524 | ||
525 | temp = &end_ptr; | |
526 | end_ptr = *pp + 1; | |
527 | while (isspace ((int) *end_ptr)) | |
528 | end_ptr++; /* skip white space */ | |
529 | end_value = get_number (temp); | |
530 | if (end_value < last_retval) | |
531 | { | |
8a3fe4f8 | 532 | error (_("inverted range")); |
5c44784c JM |
533 | } |
534 | else if (end_value == last_retval) | |
535 | { | |
536 | /* degenerate range (number1 == number2). Advance the | |
537 | token pointer so that the range will be treated as a | |
538 | single number. */ | |
539 | *pp = end_ptr; | |
540 | } | |
541 | else | |
542 | in_range = 1; | |
543 | } | |
544 | } | |
545 | else if (! in_range) | |
8a3fe4f8 | 546 | error (_("negative value")); |
5c44784c JM |
547 | else |
548 | { | |
549 | /* pp points to the '-' that betokens a range. All | |
550 | number-parsing has already been done. Return the next | |
551 | integer value (one greater than the saved previous value). | |
552 | Do not advance the token pointer 'pp' until the end of range | |
553 | is reached. */ | |
554 | ||
555 | if (++last_retval == end_value) | |
556 | { | |
557 | /* End of range reached; advance token pointer. */ | |
558 | *pp = end_ptr; | |
559 | in_range = 0; | |
560 | } | |
561 | } | |
562 | return last_retval; | |
563 | } | |
564 | ||
565 | ||
c906108c SS |
566 | \f |
567 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ | |
568 | ||
569 | static void | |
fba45db2 | 570 | condition_command (char *arg, int from_tty) |
c906108c | 571 | { |
52f0bd74 | 572 | struct breakpoint *b; |
c906108c | 573 | char *p; |
52f0bd74 | 574 | int bnum; |
c906108c SS |
575 | |
576 | if (arg == 0) | |
e2e0b3e5 | 577 | error_no_arg (_("breakpoint number")); |
c906108c SS |
578 | |
579 | p = arg; | |
580 | bnum = get_number (&p); | |
5c44784c | 581 | if (bnum == 0) |
8a3fe4f8 | 582 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
583 | |
584 | ALL_BREAKPOINTS (b) | |
585 | if (b->number == bnum) | |
2f069f6f JB |
586 | { |
587 | struct bp_location *loc = b->loc; | |
588 | for (; loc; loc = loc->next) | |
589 | { | |
590 | if (loc->cond) | |
591 | { | |
592 | xfree (loc->cond); | |
593 | loc->cond = 0; | |
594 | } | |
595 | } | |
596 | if (b->cond_string != NULL) | |
597 | xfree (b->cond_string); | |
c906108c | 598 | |
2f069f6f JB |
599 | if (*p == 0) |
600 | { | |
601 | b->cond_string = NULL; | |
602 | if (from_tty) | |
603 | printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum); | |
604 | } | |
605 | else | |
606 | { | |
607 | arg = p; | |
608 | /* I don't know if it matters whether this is the string the user | |
609 | typed in or the decompiled expression. */ | |
1b36a34b | 610 | b->cond_string = xstrdup (arg); |
2f069f6f JB |
611 | b->condition_not_parsed = 0; |
612 | for (loc = b->loc; loc; loc = loc->next) | |
613 | { | |
614 | arg = p; | |
615 | loc->cond = | |
616 | parse_exp_1 (&arg, block_for_pc (loc->address), 0); | |
617 | if (*arg) | |
618 | error (_("Junk at end of expression")); | |
619 | } | |
620 | } | |
621 | breakpoints_changed (); | |
383f836e | 622 | observer_notify_breakpoint_modified (b->number); |
2f069f6f JB |
623 | return; |
624 | } | |
c906108c | 625 | |
8a3fe4f8 | 626 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
627 | } |
628 | ||
c906108c | 629 | static void |
fba45db2 | 630 | commands_command (char *arg, int from_tty) |
c906108c | 631 | { |
52f0bd74 | 632 | struct breakpoint *b; |
c906108c | 633 | char *p; |
52f0bd74 | 634 | int bnum; |
c906108c SS |
635 | struct command_line *l; |
636 | ||
637 | /* If we allowed this, we would have problems with when to | |
638 | free the storage, if we change the commands currently | |
639 | being read from. */ | |
640 | ||
641 | if (executing_breakpoint_commands) | |
8a3fe4f8 | 642 | error (_("Can't use the \"commands\" command among a breakpoint's commands.")); |
c906108c SS |
643 | |
644 | p = arg; | |
645 | bnum = get_number (&p); | |
5c44784c | 646 | |
c906108c | 647 | if (p && *p) |
8a3fe4f8 | 648 | error (_("Unexpected extra arguments following breakpoint number.")); |
c5aa993b | 649 | |
c906108c SS |
650 | ALL_BREAKPOINTS (b) |
651 | if (b->number == bnum) | |
9ebf4acf AC |
652 | { |
653 | char *tmpbuf = xstrprintf ("Type commands for when breakpoint %d is hit, one per line.", | |
654 | bnum); | |
655 | struct cleanup *cleanups = make_cleanup (xfree, tmpbuf); | |
311a4e6b | 656 | l = read_command_lines (tmpbuf, from_tty, 1); |
9ebf4acf AC |
657 | do_cleanups (cleanups); |
658 | free_command_lines (&b->commands); | |
659 | b->commands = l; | |
660 | breakpoints_changed (); | |
383f836e | 661 | observer_notify_breakpoint_modified (b->number); |
9ebf4acf | 662 | return; |
c5aa993b | 663 | } |
8a3fe4f8 | 664 | error (_("No breakpoint number %d."), bnum); |
c906108c | 665 | } |
40c03ae8 EZ |
666 | |
667 | /* Like commands_command, but instead of reading the commands from | |
668 | input stream, takes them from an already parsed command structure. | |
669 | ||
670 | This is used by cli-script.c to DTRT with breakpoint commands | |
671 | that are part of if and while bodies. */ | |
672 | enum command_control_type | |
673 | commands_from_control_command (char *arg, struct command_line *cmd) | |
674 | { | |
675 | struct breakpoint *b; | |
676 | char *p; | |
677 | int bnum; | |
678 | ||
679 | /* If we allowed this, we would have problems with when to | |
680 | free the storage, if we change the commands currently | |
681 | being read from. */ | |
682 | ||
683 | if (executing_breakpoint_commands) | |
684 | error (_("Can't use the \"commands\" command among a breakpoint's commands.")); | |
685 | ||
686 | /* An empty string for the breakpoint number means the last | |
687 | breakpoint, but get_number expects a NULL pointer. */ | |
688 | if (arg && !*arg) | |
689 | p = NULL; | |
690 | else | |
691 | p = arg; | |
692 | bnum = get_number (&p); | |
693 | ||
694 | if (p && *p) | |
695 | error (_("Unexpected extra arguments following breakpoint number.")); | |
696 | ||
697 | ALL_BREAKPOINTS (b) | |
698 | if (b->number == bnum) | |
699 | { | |
700 | free_command_lines (&b->commands); | |
701 | if (cmd->body_count != 1) | |
702 | error (_("Invalid \"commands\" block structure.")); | |
703 | /* We need to copy the commands because if/while will free the | |
704 | list after it finishes execution. */ | |
705 | b->commands = copy_command_lines (cmd->body_list[0]); | |
706 | breakpoints_changed (); | |
383f836e | 707 | observer_notify_breakpoint_modified (b->number); |
40c03ae8 | 708 | return simple_control; |
2f069f6f | 709 | } |
40c03ae8 EZ |
710 | error (_("No breakpoint number %d."), bnum); |
711 | } | |
c906108c | 712 | \f |
8defab1a DJ |
713 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
714 | by replacing any memory breakpoints with their shadowed contents. */ | |
c906108c | 715 | |
8defab1a DJ |
716 | void |
717 | breakpoint_restore_shadows (gdb_byte *buf, ULONGEST memaddr, LONGEST len) | |
c906108c | 718 | { |
8defab1a | 719 | struct bp_location *b; |
c906108c SS |
720 | CORE_ADDR bp_addr = 0; |
721 | int bp_size = 0; | |
8defab1a | 722 | int bptoffset = 0; |
c5aa993b | 723 | |
ffce0d52 | 724 | ALL_BP_LOCATIONS (b) |
c5aa993b | 725 | { |
ffce0d52 | 726 | if (b->owner->type == bp_none) |
8a3fe4f8 | 727 | warning (_("reading through apparently deleted breakpoint #%d?"), |
ffce0d52 DJ |
728 | b->owner->number); |
729 | ||
730 | if (b->loc_type != bp_loc_software_breakpoint) | |
c5aa993b | 731 | continue; |
ffce0d52 | 732 | if (!b->inserted) |
c5aa993b JM |
733 | continue; |
734 | /* Addresses and length of the part of the breakpoint that | |
735 | we need to copy. */ | |
8181d85f DJ |
736 | bp_addr = b->target_info.placed_address; |
737 | bp_size = b->target_info.shadow_len; | |
c5aa993b | 738 | if (bp_size == 0) |
8181d85f | 739 | /* bp isn't valid, or doesn't shadow memory. */ |
c5aa993b | 740 | continue; |
8defab1a | 741 | |
c5aa993b JM |
742 | if (bp_addr + bp_size <= memaddr) |
743 | /* The breakpoint is entirely before the chunk of memory we | |
744 | are reading. */ | |
745 | continue; | |
8defab1a | 746 | |
c5aa993b JM |
747 | if (bp_addr >= memaddr + len) |
748 | /* The breakpoint is entirely after the chunk of memory we are | |
749 | reading. */ | |
750 | continue; | |
c5aa993b | 751 | |
8defab1a DJ |
752 | /* Offset within shadow_contents. */ |
753 | if (bp_addr < memaddr) | |
754 | { | |
755 | /* Only copy the second part of the breakpoint. */ | |
756 | bp_size -= memaddr - bp_addr; | |
757 | bptoffset = memaddr - bp_addr; | |
758 | bp_addr = memaddr; | |
759 | } | |
c5aa993b | 760 | |
8defab1a DJ |
761 | if (bp_addr + bp_size > memaddr + len) |
762 | { | |
763 | /* Only copy the first part of the breakpoint. */ | |
764 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
765 | } | |
c5aa993b | 766 | |
8defab1a DJ |
767 | memcpy (buf + bp_addr - memaddr, |
768 | b->target_info.shadow_contents + bptoffset, bp_size); | |
c5aa993b | 769 | } |
c906108c | 770 | } |
c906108c | 771 | \f |
c5aa993b | 772 | |
687595f9 | 773 | /* A wrapper function for inserting catchpoints. */ |
9cbc821d | 774 | static void |
687595f9 DJ |
775 | insert_catchpoint (struct ui_out *uo, void *args) |
776 | { | |
777 | struct breakpoint *b = (struct breakpoint *) args; | |
778 | int val = -1; | |
779 | ||
fe798b75 JB |
780 | gdb_assert (b->type == bp_catchpoint); |
781 | gdb_assert (b->ops != NULL && b->ops->insert != NULL); | |
782 | ||
783 | b->ops->insert (b); | |
687595f9 DJ |
784 | } |
785 | ||
a5606eee VP |
786 | static int |
787 | is_hardware_watchpoint (struct breakpoint *bpt) | |
788 | { | |
789 | return (bpt->type == bp_hardware_watchpoint | |
790 | || bpt->type == bp_read_watchpoint | |
791 | || bpt->type == bp_access_watchpoint); | |
792 | } | |
7270d8f2 | 793 | |
fa4727a6 DJ |
794 | /* Find the current value of a watchpoint on EXP. Return the value in |
795 | *VALP and *RESULTP and the chain of intermediate and final values | |
796 | in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does | |
797 | not need them. | |
798 | ||
ccc57cf9 | 799 | If a memory error occurs while evaluating the expression, *RESULTP will |
fa4727a6 DJ |
800 | be set to NULL. *RESULTP may be a lazy value, if the result could |
801 | not be read from memory. It is used to determine whether a value | |
802 | is user-specified (we should watch the whole value) or intermediate | |
803 | (we should watch only the bit used to locate the final value). | |
804 | ||
805 | If the final value, or any intermediate value, could not be read | |
806 | from memory, *VALP will be set to NULL. *VAL_CHAIN will still be | |
807 | set to any referenced values. *VALP will never be a lazy value. | |
808 | This is the value which we store in struct breakpoint. | |
809 | ||
810 | If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the | |
811 | value chain. The caller must free the values individually. If | |
812 | VAL_CHAIN is NULL, all generated values will be left on the value | |
813 | chain. */ | |
814 | ||
815 | static void | |
816 | fetch_watchpoint_value (struct expression *exp, struct value **valp, | |
817 | struct value **resultp, struct value **val_chain) | |
818 | { | |
819 | struct value *mark, *new_mark, *result; | |
ccc57cf9 | 820 | volatile struct gdb_exception ex; |
fa4727a6 DJ |
821 | |
822 | *valp = NULL; | |
823 | if (resultp) | |
824 | *resultp = NULL; | |
825 | if (val_chain) | |
826 | *val_chain = NULL; | |
827 | ||
828 | /* Evaluate the expression. */ | |
829 | mark = value_mark (); | |
830 | result = NULL; | |
ccc57cf9 PA |
831 | |
832 | TRY_CATCH (ex, RETURN_MASK_ALL) | |
833 | { | |
834 | result = evaluate_expression (exp); | |
835 | } | |
836 | if (ex.reason < 0) | |
837 | { | |
838 | /* Ignore memory errors, we want watchpoints pointing at | |
839 | inaccessible memory to still be created; otherwise, throw the | |
840 | error to some higher catcher. */ | |
841 | switch (ex.error) | |
842 | { | |
843 | case MEMORY_ERROR: | |
844 | break; | |
845 | default: | |
846 | throw_exception (ex); | |
847 | break; | |
848 | } | |
849 | } | |
850 | ||
fa4727a6 DJ |
851 | new_mark = value_mark (); |
852 | if (mark == new_mark) | |
853 | return; | |
854 | if (resultp) | |
855 | *resultp = result; | |
856 | ||
857 | /* Make sure it's not lazy, so that after the target stops again we | |
858 | have a non-lazy previous value to compare with. */ | |
859 | if (result != NULL | |
860 | && (!value_lazy (result) || gdb_value_fetch_lazy (result))) | |
861 | *valp = result; | |
862 | ||
863 | if (val_chain) | |
864 | { | |
865 | /* Return the chain of intermediate values. We use this to | |
866 | decide which addresses to watch. */ | |
867 | *val_chain = new_mark; | |
868 | value_release_to_mark (mark); | |
869 | } | |
870 | } | |
871 | ||
567e1b4e JB |
872 | /* Assuming that B is a watchpoint: |
873 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 874 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
875 | - Evaluate the condition if there is one, and store the result |
876 | in b->loc->cond. | |
a5606eee VP |
877 | - Update the list of values that must be watched in B->loc. |
878 | ||
bfa149ac JB |
879 | If the watchpoint disposition is disp_del_at_next_stop, then do nothing. |
880 | If this is local watchpoint that is out of scope, delete it. */ | |
b40ce68a | 881 | static void |
a5606eee | 882 | update_watchpoint (struct breakpoint *b, int reparse) |
7270d8f2 | 883 | { |
a5606eee | 884 | int within_current_scope; |
a5606eee VP |
885 | struct frame_id saved_frame_id; |
886 | struct bp_location *loc; | |
887 | bpstat bs; | |
888 | ||
567e1b4e JB |
889 | /* We don't free locations. They are stored in bp_location_chain and |
890 | update_global_locations will eventually delete them and remove | |
891 | breakpoints if needed. */ | |
a5606eee VP |
892 | b->loc = NULL; |
893 | ||
894 | if (b->disposition == disp_del_at_next_stop) | |
895 | return; | |
896 | ||
897 | /* Save the current frame's ID so we can restore it after | |
898 | evaluating the watchpoint expression on its own frame. */ | |
899 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
900 | took a frame parameter, so that we didn't have to change the | |
901 | selected frame. */ | |
902 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
903 | ||
904 | /* Determine if the watchpoint is within scope. */ | |
905 | if (b->exp_valid_block == NULL) | |
906 | within_current_scope = 1; | |
907 | else | |
908 | { | |
909 | struct frame_info *fi; | |
910 | fi = frame_find_by_id (b->watchpoint_frame); | |
911 | within_current_scope = (fi != NULL); | |
912 | if (within_current_scope) | |
913 | select_frame (fi); | |
914 | } | |
915 | ||
916 | if (within_current_scope && reparse) | |
917 | { | |
918 | char *s; | |
919 | if (b->exp) | |
920 | { | |
921 | xfree (b->exp); | |
922 | b->exp = NULL; | |
923 | } | |
924 | s = b->exp_string; | |
925 | b->exp = parse_exp_1 (&s, b->exp_valid_block, 0); | |
926 | /* If the meaning of expression itself changed, the old value is | |
927 | no longer relevant. We don't want to report a watchpoint hit | |
928 | to the user when the old value and the new value may actually | |
929 | be completely different objects. */ | |
930 | value_free (b->val); | |
fa4727a6 DJ |
931 | b->val = NULL; |
932 | b->val_valid = 0; | |
a5606eee | 933 | } |
a5606eee VP |
934 | |
935 | /* If we failed to parse the expression, for example because | |
936 | it refers to a global variable in a not-yet-loaded shared library, | |
937 | don't try to insert watchpoint. We don't automatically delete | |
938 | such watchpoint, though, since failure to parse expression | |
939 | is different from out-of-scope watchpoint. */ | |
940 | if (within_current_scope && b->exp) | |
941 | { | |
fa4727a6 | 942 | struct value *val_chain, *v, *result, *next; |
a5606eee | 943 | |
fa4727a6 | 944 | fetch_watchpoint_value (b->exp, &v, &result, &val_chain); |
a5606eee | 945 | |
a5606eee VP |
946 | /* Avoid setting b->val if it's already set. The meaning of |
947 | b->val is 'the last value' user saw, and we should update | |
948 | it only if we reported that last value to user. As it | |
949 | happens, the code that reports it updates b->val directly. */ | |
fa4727a6 DJ |
950 | if (!b->val_valid) |
951 | { | |
952 | b->val = v; | |
953 | b->val_valid = 1; | |
954 | } | |
a5606eee | 955 | |
db2ad4c3 JK |
956 | /* Change the type of breakpoint between hardware assisted or an |
957 | ordinary watchpoint depending on the hardware support and free | |
958 | hardware slots. REPARSE is set when the inferior is started. */ | |
959 | if ((b->type == bp_watchpoint || b->type == bp_hardware_watchpoint) | |
960 | && reparse) | |
961 | { | |
ca2d49e8 | 962 | int i, mem_cnt, other_type_used; |
db2ad4c3 JK |
963 | |
964 | i = hw_watchpoint_used_count (bp_hardware_watchpoint, | |
965 | &other_type_used); | |
966 | mem_cnt = can_use_hardware_watchpoint (val_chain); | |
967 | ||
ca2d49e8 | 968 | if (!mem_cnt) |
db2ad4c3 JK |
969 | b->type = bp_watchpoint; |
970 | else | |
ca2d49e8 | 971 | { |
d92524f1 | 972 | int target_resources_ok = target_can_use_hardware_watchpoint |
ca2d49e8 SL |
973 | (bp_hardware_watchpoint, i + mem_cnt, other_type_used); |
974 | if (target_resources_ok <= 0) | |
975 | b->type = bp_watchpoint; | |
976 | else | |
977 | b->type = bp_hardware_watchpoint; | |
978 | } | |
db2ad4c3 JK |
979 | } |
980 | ||
a5606eee | 981 | /* Look at each value on the value chain. */ |
fa4727a6 | 982 | for (v = val_chain; v; v = next) |
a5606eee VP |
983 | { |
984 | /* If it's a memory location, and GDB actually needed | |
985 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
986 | must watch it. If the first value returned is |
987 | still lazy, that means an error occurred reading it; | |
988 | watch it anyway in case it becomes readable. */ | |
a5606eee | 989 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 990 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
991 | { |
992 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 993 | |
a5606eee VP |
994 | /* We only watch structs and arrays if user asked |
995 | for it explicitly, never if they just happen to | |
996 | appear in the middle of some value chain. */ | |
fa4727a6 | 997 | if (v == result |
a5606eee VP |
998 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
999 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
1000 | { | |
1001 | CORE_ADDR addr; | |
1002 | int len, type; | |
1003 | struct bp_location *loc, **tmp; | |
1004 | ||
42ae5230 | 1005 | addr = value_address (v); |
a5606eee VP |
1006 | len = TYPE_LENGTH (value_type (v)); |
1007 | type = hw_write; | |
1008 | if (b->type == bp_read_watchpoint) | |
1009 | type = hw_read; | |
1010 | else if (b->type == bp_access_watchpoint) | |
1011 | type = hw_access; | |
1012 | ||
39d61571 | 1013 | loc = allocate_bp_location (b); |
a5606eee VP |
1014 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
1015 | ; | |
1016 | *tmp = loc; | |
a6d9a66e | 1017 | loc->gdbarch = get_type_arch (value_type (v)); |
a5606eee VP |
1018 | loc->address = addr; |
1019 | loc->length = len; | |
1020 | loc->watchpoint_type = type; | |
1021 | } | |
1022 | } | |
1023 | ||
1024 | next = value_next (v); | |
1025 | if (v != b->val) | |
1026 | value_free (v); | |
1027 | } | |
1028 | ||
2ec93238 MK |
1029 | /* We just regenerated the list of breakpoint locations. |
1030 | The new location does not have its condition field set to anything | |
1031 | and therefore, we must always reparse the cond_string, independently | |
1032 | of the value of the reparse flag. */ | |
1033 | if (b->cond_string != NULL) | |
a5606eee VP |
1034 | { |
1035 | char *s = b->cond_string; | |
a5606eee VP |
1036 | b->loc->cond = parse_exp_1 (&s, b->exp_valid_block, 0); |
1037 | } | |
1038 | } | |
1039 | else if (!within_current_scope) | |
7270d8f2 | 1040 | { |
a5606eee | 1041 | printf_filtered (_("\ |
567e1b4e | 1042 | Watchpoint %d deleted because the program has left the block \n\ |
a5606eee VP |
1043 | in which its expression is valid.\n"), |
1044 | b->number); | |
1045 | if (b->related_breakpoint) | |
1046 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
1047 | b->disposition = disp_del_at_next_stop; | |
7270d8f2 | 1048 | } |
a5606eee VP |
1049 | |
1050 | /* Restore the selected frame. */ | |
1051 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
1052 | } |
1053 | ||
a5606eee | 1054 | |
74960c60 VP |
1055 | /* Returns 1 iff breakpoint location should be |
1056 | inserted in the inferior. */ | |
1057 | static int | |
1058 | should_be_inserted (struct bp_location *bpt) | |
1059 | { | |
1060 | if (!breakpoint_enabled (bpt->owner)) | |
1061 | return 0; | |
1062 | ||
1063 | if (bpt->owner->disposition == disp_del_at_next_stop) | |
1064 | return 0; | |
1065 | ||
1066 | if (!bpt->enabled || bpt->shlib_disabled || bpt->duplicate) | |
1067 | return 0; | |
1068 | ||
1042e4c0 SS |
1069 | /* Tracepoints are inserted by the target at a time of its choosing, |
1070 | not by us. */ | |
1071 | if (bpt->owner->type == bp_tracepoint) | |
1072 | return 0; | |
1073 | ||
74960c60 VP |
1074 | return 1; |
1075 | } | |
1076 | ||
879bfdc2 DJ |
1077 | /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint. |
1078 | Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS, | |
fa3a767f | 1079 | and HW_BREAKPOINT_ERROR are used to report problems. |
879bfdc2 DJ |
1080 | |
1081 | NOTE drow/2003-09-09: This routine could be broken down to an object-style | |
1082 | method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 1083 | static int |
879bfdc2 | 1084 | insert_bp_location (struct bp_location *bpt, |
26bb91f3 | 1085 | struct ui_file *tmp_error_stream, |
fa3a767f | 1086 | int *disabled_breaks, |
26bb91f3 | 1087 | int *hw_breakpoint_error) |
879bfdc2 DJ |
1088 | { |
1089 | int val = 0; | |
1090 | ||
74960c60 | 1091 | if (!should_be_inserted (bpt) || bpt->inserted) |
879bfdc2 DJ |
1092 | return 0; |
1093 | ||
8181d85f DJ |
1094 | /* Initialize the target-specific information. */ |
1095 | memset (&bpt->target_info, 0, sizeof (bpt->target_info)); | |
1096 | bpt->target_info.placed_address = bpt->address; | |
1097 | ||
879bfdc2 DJ |
1098 | if (bpt->loc_type == bp_loc_software_breakpoint |
1099 | || bpt->loc_type == bp_loc_hardware_breakpoint) | |
1100 | { | |
765dc015 VP |
1101 | if (bpt->owner->type != bp_hardware_breakpoint) |
1102 | { | |
1103 | /* If the explicitly specified breakpoint type | |
1104 | is not hardware breakpoint, check the memory map to see | |
1105 | if the breakpoint address is in read only memory or not. | |
1106 | Two important cases are: | |
1107 | - location type is not hardware breakpoint, memory | |
1108 | is readonly. We change the type of the location to | |
1109 | hardware breakpoint. | |
1110 | - location type is hardware breakpoint, memory is read-write. | |
1111 | This means we've previously made the location hardware one, but | |
1112 | then the memory map changed, so we undo. | |
1113 | ||
1114 | When breakpoints are removed, remove_breakpoints will | |
1115 | use location types we've just set here, the only possible | |
1116 | problem is that memory map has changed during running program, | |
1117 | but it's not going to work anyway with current gdb. */ | |
1118 | struct mem_region *mr | |
1119 | = lookup_mem_region (bpt->target_info.placed_address); | |
1120 | ||
1121 | if (mr) | |
1122 | { | |
1123 | if (automatic_hardware_breakpoints) | |
1124 | { | |
1125 | int changed = 0; | |
1126 | enum bp_loc_type new_type; | |
1127 | ||
1128 | if (mr->attrib.mode != MEM_RW) | |
1129 | new_type = bp_loc_hardware_breakpoint; | |
1130 | else | |
1131 | new_type = bp_loc_software_breakpoint; | |
1132 | ||
1133 | if (new_type != bpt->loc_type) | |
1134 | { | |
1135 | static int said = 0; | |
1136 | bpt->loc_type = new_type; | |
1137 | if (!said) | |
1138 | { | |
1139 | fprintf_filtered (gdb_stdout, _("\ | |
0767c96d | 1140 | Note: automatically using hardware breakpoints for read-only addresses.\n")); |
765dc015 VP |
1141 | said = 1; |
1142 | } | |
1143 | } | |
1144 | } | |
1145 | else if (bpt->loc_type == bp_loc_software_breakpoint | |
1146 | && mr->attrib.mode != MEM_RW) | |
1147 | warning (_("cannot set software breakpoint at readonly address %s"), | |
5af949e3 | 1148 | paddress (bpt->gdbarch, bpt->address)); |
765dc015 VP |
1149 | } |
1150 | } | |
1151 | ||
879bfdc2 DJ |
1152 | /* First check to see if we have to handle an overlay. */ |
1153 | if (overlay_debugging == ovly_off | |
1154 | || bpt->section == NULL | |
1155 | || !(section_is_overlay (bpt->section))) | |
1156 | { | |
1157 | /* No overlay handling: just set the breakpoint. */ | |
1158 | ||
1159 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
a6d9a66e UW |
1160 | val = target_insert_hw_breakpoint (bpt->gdbarch, |
1161 | &bpt->target_info); | |
879bfdc2 | 1162 | else |
a6d9a66e UW |
1163 | val = target_insert_breakpoint (bpt->gdbarch, |
1164 | &bpt->target_info); | |
879bfdc2 DJ |
1165 | } |
1166 | else | |
1167 | { | |
1168 | /* This breakpoint is in an overlay section. | |
1169 | Shall we set a breakpoint at the LMA? */ | |
1170 | if (!overlay_events_enabled) | |
1171 | { | |
1172 | /* Yes -- overlay event support is not active, | |
1173 | so we must try to set a breakpoint at the LMA. | |
1174 | This will not work for a hardware breakpoint. */ | |
1175 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
8a3fe4f8 | 1176 | warning (_("hardware breakpoint %d not supported in overlay!"), |
879bfdc2 DJ |
1177 | bpt->owner->number); |
1178 | else | |
1179 | { | |
1180 | CORE_ADDR addr = overlay_unmapped_address (bpt->address, | |
1181 | bpt->section); | |
1182 | /* Set a software (trap) breakpoint at the LMA. */ | |
8181d85f DJ |
1183 | bpt->overlay_target_info = bpt->target_info; |
1184 | bpt->overlay_target_info.placed_address = addr; | |
a6d9a66e UW |
1185 | val = target_insert_breakpoint (bpt->gdbarch, |
1186 | &bpt->overlay_target_info); | |
879bfdc2 | 1187 | if (val != 0) |
99361f52 DE |
1188 | fprintf_unfiltered (tmp_error_stream, |
1189 | "Overlay breakpoint %d failed: in ROM?\n", | |
879bfdc2 DJ |
1190 | bpt->owner->number); |
1191 | } | |
1192 | } | |
1193 | /* Shall we set a breakpoint at the VMA? */ | |
1194 | if (section_is_mapped (bpt->section)) | |
1195 | { | |
1196 | /* Yes. This overlay section is mapped into memory. */ | |
1197 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
a6d9a66e UW |
1198 | val = target_insert_hw_breakpoint (bpt->gdbarch, |
1199 | &bpt->target_info); | |
879bfdc2 | 1200 | else |
a6d9a66e UW |
1201 | val = target_insert_breakpoint (bpt->gdbarch, |
1202 | &bpt->target_info); | |
879bfdc2 DJ |
1203 | } |
1204 | else | |
1205 | { | |
1206 | /* No. This breakpoint will not be inserted. | |
1207 | No error, but do not mark the bp as 'inserted'. */ | |
1208 | return 0; | |
1209 | } | |
1210 | } | |
1211 | ||
1212 | if (val) | |
1213 | { | |
1214 | /* Can't set the breakpoint. */ | |
f5c9a895 | 1215 | if (solib_name_from_address (bpt->address)) |
879bfdc2 DJ |
1216 | { |
1217 | /* See also: disable_breakpoints_in_shlibs. */ | |
1218 | val = 0; | |
0d381245 | 1219 | bpt->shlib_disabled = 1; |
879bfdc2 DJ |
1220 | if (!*disabled_breaks) |
1221 | { | |
1222 | fprintf_unfiltered (tmp_error_stream, | |
1223 | "Cannot insert breakpoint %d.\n", | |
1224 | bpt->owner->number); | |
1225 | fprintf_unfiltered (tmp_error_stream, | |
1226 | "Temporarily disabling shared library breakpoints:\n"); | |
1227 | } | |
1228 | *disabled_breaks = 1; | |
1229 | fprintf_unfiltered (tmp_error_stream, | |
1230 | "breakpoint #%d\n", bpt->owner->number); | |
1231 | } | |
1232 | else | |
879bfdc2 | 1233 | { |
879bfdc2 DJ |
1234 | if (bpt->loc_type == bp_loc_hardware_breakpoint) |
1235 | { | |
1236 | *hw_breakpoint_error = 1; | |
1237 | fprintf_unfiltered (tmp_error_stream, | |
1238 | "Cannot insert hardware breakpoint %d.\n", | |
1239 | bpt->owner->number); | |
1240 | } | |
1241 | else | |
1242 | { | |
1243 | fprintf_unfiltered (tmp_error_stream, | |
1244 | "Cannot insert breakpoint %d.\n", | |
1245 | bpt->owner->number); | |
1246 | fprintf_filtered (tmp_error_stream, | |
1247 | "Error accessing memory address "); | |
5af949e3 UW |
1248 | fputs_filtered (paddress (bpt->gdbarch, bpt->address), |
1249 | tmp_error_stream); | |
879bfdc2 DJ |
1250 | fprintf_filtered (tmp_error_stream, ": %s.\n", |
1251 | safe_strerror (val)); | |
1252 | } | |
1253 | ||
1254 | } | |
1255 | } | |
1256 | else | |
1257 | bpt->inserted = 1; | |
1258 | ||
1259 | return val; | |
1260 | } | |
1261 | ||
1262 | else if (bpt->loc_type == bp_loc_hardware_watchpoint | |
1263 | /* NOTE drow/2003-09-08: This state only exists for removing | |
1264 | watchpoints. It's not clear that it's necessary... */ | |
1265 | && bpt->owner->disposition != disp_del_at_next_stop) | |
1266 | { | |
a5606eee VP |
1267 | val = target_insert_watchpoint (bpt->address, |
1268 | bpt->length, | |
1269 | bpt->watchpoint_type); | |
1270 | bpt->inserted = (val != -1); | |
879bfdc2 DJ |
1271 | } |
1272 | ||
fe798b75 | 1273 | else if (bpt->owner->type == bp_catchpoint) |
879bfdc2 | 1274 | { |
71fff37b AC |
1275 | struct gdb_exception e = catch_exception (uiout, insert_catchpoint, |
1276 | bpt->owner, RETURN_MASK_ERROR); | |
9cbc821d AC |
1277 | exception_fprintf (gdb_stderr, e, "warning: inserting catchpoint %d: ", |
1278 | bpt->owner->number); | |
1279 | if (e.reason < 0) | |
879bfdc2 DJ |
1280 | bpt->owner->enable_state = bp_disabled; |
1281 | else | |
1282 | bpt->inserted = 1; | |
1640b821 DJ |
1283 | |
1284 | /* We've already printed an error message if there was a problem | |
1285 | inserting this catchpoint, and we've disabled the catchpoint, | |
1286 | so just return success. */ | |
1287 | return 0; | |
879bfdc2 DJ |
1288 | } |
1289 | ||
1290 | return 0; | |
1291 | } | |
1292 | ||
74960c60 VP |
1293 | /* Make sure all breakpoints are inserted in inferior. |
1294 | Throws exception on any error. | |
1295 | A breakpoint that is already inserted won't be inserted | |
1296 | again, so calling this function twice is safe. */ | |
1297 | void | |
1298 | insert_breakpoints (void) | |
1299 | { | |
1300 | struct breakpoint *bpt; | |
1301 | ||
1302 | ALL_BREAKPOINTS (bpt) | |
1303 | if (is_hardware_watchpoint (bpt)) | |
1304 | update_watchpoint (bpt, 0 /* don't reparse. */); | |
1305 | ||
b60e7edf | 1306 | update_global_location_list (1); |
74960c60 | 1307 | |
c35b1492 PA |
1308 | /* update_global_location_list does not insert breakpoints when |
1309 | always_inserted_mode is not enabled. Explicitly insert them | |
1310 | now. */ | |
1311 | if (!breakpoints_always_inserted_mode ()) | |
74960c60 VP |
1312 | insert_breakpoint_locations (); |
1313 | } | |
1314 | ||
c906108c SS |
1315 | /* insert_breakpoints is used when starting or continuing the program. |
1316 | remove_breakpoints is used when the program stops. | |
1317 | Both return zero if successful, | |
1318 | or an `errno' value if could not write the inferior. */ | |
1319 | ||
74960c60 VP |
1320 | static void |
1321 | insert_breakpoint_locations (void) | |
c906108c | 1322 | { |
a5606eee | 1323 | struct breakpoint *bpt; |
879bfdc2 | 1324 | struct bp_location *b, *temp; |
e236ba44 | 1325 | int error = 0; |
c906108c SS |
1326 | int val = 0; |
1327 | int disabled_breaks = 0; | |
81d0cc19 | 1328 | int hw_breakpoint_error = 0; |
c906108c | 1329 | |
81d0cc19 | 1330 | struct ui_file *tmp_error_stream = mem_fileopen (); |
f7545552 | 1331 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
74960c60 | 1332 | |
81d0cc19 GS |
1333 | /* Explicitly mark the warning -- this will only be printed if |
1334 | there was an error. */ | |
1335 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
a5606eee | 1336 | |
879bfdc2 DJ |
1337 | ALL_BP_LOCATIONS_SAFE (b, temp) |
1338 | { | |
74960c60 | 1339 | if (!should_be_inserted (b) || b->inserted) |
879bfdc2 DJ |
1340 | continue; |
1341 | ||
f365de73 AS |
1342 | /* There is no point inserting thread-specific breakpoints if the |
1343 | thread no longer exists. */ | |
1344 | if (b->owner->thread != -1 | |
1345 | && !valid_thread_id (b->owner->thread)) | |
1346 | continue; | |
1347 | ||
879bfdc2 | 1348 | val = insert_bp_location (b, tmp_error_stream, |
fa3a767f | 1349 | &disabled_breaks, |
879bfdc2 DJ |
1350 | &hw_breakpoint_error); |
1351 | if (val) | |
e236ba44 | 1352 | error = val; |
879bfdc2 | 1353 | } |
c906108c | 1354 | |
a5606eee VP |
1355 | /* If we failed to insert all locations of a watchpoint, |
1356 | remove them, as half-inserted watchpoint is of limited use. */ | |
1357 | ALL_BREAKPOINTS (bpt) | |
1358 | { | |
1359 | int some_failed = 0; | |
1360 | struct bp_location *loc; | |
1361 | ||
1362 | if (!is_hardware_watchpoint (bpt)) | |
1363 | continue; | |
1364 | ||
d6b74ac4 | 1365 | if (!breakpoint_enabled (bpt)) |
a5606eee | 1366 | continue; |
74960c60 VP |
1367 | |
1368 | if (bpt->disposition == disp_del_at_next_stop) | |
1369 | continue; | |
a5606eee VP |
1370 | |
1371 | for (loc = bpt->loc; loc; loc = loc->next) | |
1372 | if (!loc->inserted) | |
1373 | { | |
1374 | some_failed = 1; | |
1375 | break; | |
1376 | } | |
1377 | if (some_failed) | |
1378 | { | |
1379 | for (loc = bpt->loc; loc; loc = loc->next) | |
1380 | if (loc->inserted) | |
1381 | remove_breakpoint (loc, mark_uninserted); | |
1382 | ||
1383 | hw_breakpoint_error = 1; | |
1384 | fprintf_unfiltered (tmp_error_stream, | |
1385 | "Could not insert hardware watchpoint %d.\n", | |
1386 | bpt->number); | |
1387 | error = -1; | |
1388 | } | |
1389 | } | |
1390 | ||
e236ba44 | 1391 | if (error) |
81d0cc19 GS |
1392 | { |
1393 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
1394 | message about possibly exhausted resources. */ | |
879bfdc2 | 1395 | if (hw_breakpoint_error) |
81d0cc19 | 1396 | { |
c6510018 MS |
1397 | fprintf_unfiltered (tmp_error_stream, |
1398 | "Could not insert hardware breakpoints:\n\ | |
1399 | You may have requested too many hardware breakpoints/watchpoints.\n"); | |
81d0cc19 | 1400 | } |
81d0cc19 GS |
1401 | target_terminal_ours_for_output (); |
1402 | error_stream (tmp_error_stream); | |
1403 | } | |
f7545552 TT |
1404 | |
1405 | do_cleanups (cleanups); | |
c906108c SS |
1406 | } |
1407 | ||
c906108c | 1408 | int |
fba45db2 | 1409 | remove_breakpoints (void) |
c906108c | 1410 | { |
0bde7532 | 1411 | struct bp_location *b; |
3a1bae8e | 1412 | int val = 0; |
c906108c | 1413 | |
0bde7532 | 1414 | ALL_BP_LOCATIONS (b) |
c5aa993b | 1415 | { |
0bde7532 | 1416 | if (b->inserted) |
3a1bae8e | 1417 | val |= remove_breakpoint (b, mark_uninserted); |
c5aa993b | 1418 | } |
3a1bae8e | 1419 | return val; |
c906108c SS |
1420 | } |
1421 | ||
692590c1 | 1422 | int |
80ce1ecb | 1423 | remove_hw_watchpoints (void) |
692590c1 | 1424 | { |
0bde7532 | 1425 | struct bp_location *b; |
3a1bae8e | 1426 | int val = 0; |
692590c1 | 1427 | |
0bde7532 | 1428 | ALL_BP_LOCATIONS (b) |
692590c1 | 1429 | { |
0bde7532 | 1430 | if (b->inserted && b->loc_type == bp_loc_hardware_watchpoint) |
3a1bae8e | 1431 | val |= remove_breakpoint (b, mark_uninserted); |
692590c1 | 1432 | } |
3a1bae8e | 1433 | return val; |
692590c1 MS |
1434 | } |
1435 | ||
c906108c | 1436 | int |
fba45db2 | 1437 | reattach_breakpoints (int pid) |
c906108c | 1438 | { |
0bde7532 | 1439 | struct bp_location *b; |
c906108c | 1440 | int val; |
ce696e05 | 1441 | struct cleanup *old_chain = save_inferior_ptid (); |
a4954f26 | 1442 | struct ui_file *tmp_error_stream = mem_fileopen (); |
fa3a767f | 1443 | int dummy1 = 0, dummy2 = 0; |
a4954f26 DJ |
1444 | |
1445 | make_cleanup_ui_file_delete (tmp_error_stream); | |
c906108c | 1446 | |
ce696e05 | 1447 | inferior_ptid = pid_to_ptid (pid); |
0bde7532 | 1448 | ALL_BP_LOCATIONS (b) |
c5aa993b | 1449 | { |
0bde7532 | 1450 | if (b->inserted) |
c5aa993b | 1451 | { |
a4954f26 DJ |
1452 | b->inserted = 0; |
1453 | val = insert_bp_location (b, tmp_error_stream, | |
fa3a767f | 1454 | &dummy1, &dummy2); |
c5aa993b JM |
1455 | if (val != 0) |
1456 | { | |
ce696e05 | 1457 | do_cleanups (old_chain); |
c5aa993b JM |
1458 | return val; |
1459 | } | |
1460 | } | |
1461 | } | |
ce696e05 | 1462 | do_cleanups (old_chain); |
c906108c SS |
1463 | return 0; |
1464 | } | |
1465 | ||
e58b0e63 PA |
1466 | static int internal_breakpoint_number = -1; |
1467 | ||
e62c965a | 1468 | static struct breakpoint * |
a6d9a66e UW |
1469 | create_internal_breakpoint (struct gdbarch *gdbarch, |
1470 | CORE_ADDR address, enum bptype type) | |
e62c965a | 1471 | { |
e62c965a PP |
1472 | struct symtab_and_line sal; |
1473 | struct breakpoint *b; | |
1474 | ||
1475 | init_sal (&sal); /* initialize to zeroes */ | |
1476 | ||
1477 | sal.pc = address; | |
1478 | sal.section = find_pc_overlay (sal.pc); | |
1479 | ||
a6d9a66e | 1480 | b = set_raw_breakpoint (gdbarch, sal, type); |
e62c965a PP |
1481 | b->number = internal_breakpoint_number--; |
1482 | b->disposition = disp_donttouch; | |
1483 | ||
1484 | return b; | |
1485 | } | |
1486 | ||
1487 | static void | |
69de3c6a | 1488 | create_overlay_event_breakpoint (char *func_name) |
e62c965a | 1489 | { |
69de3c6a | 1490 | struct objfile *objfile; |
e62c965a | 1491 | |
69de3c6a PP |
1492 | ALL_OBJFILES (objfile) |
1493 | { | |
1494 | struct breakpoint *b; | |
1495 | struct minimal_symbol *m; | |
1496 | ||
1497 | m = lookup_minimal_symbol_text (func_name, objfile); | |
1498 | if (m == NULL) | |
1499 | continue; | |
e62c965a | 1500 | |
a6d9a66e UW |
1501 | b = create_internal_breakpoint (get_objfile_arch (objfile), |
1502 | SYMBOL_VALUE_ADDRESS (m), | |
69de3c6a PP |
1503 | bp_overlay_event); |
1504 | b->addr_string = xstrdup (func_name); | |
e62c965a | 1505 | |
69de3c6a PP |
1506 | if (overlay_debugging == ovly_auto) |
1507 | { | |
1508 | b->enable_state = bp_enabled; | |
1509 | overlay_events_enabled = 1; | |
1510 | } | |
1511 | else | |
1512 | { | |
1513 | b->enable_state = bp_disabled; | |
1514 | overlay_events_enabled = 0; | |
1515 | } | |
e62c965a PP |
1516 | } |
1517 | update_global_location_list (1); | |
1518 | } | |
1519 | ||
0fd8e87f UW |
1520 | static void |
1521 | create_longjmp_master_breakpoint (char *func_name) | |
1522 | { | |
1523 | struct objfile *objfile; | |
1524 | ||
1525 | ALL_OBJFILES (objfile) | |
1526 | { | |
1527 | struct breakpoint *b; | |
1528 | struct minimal_symbol *m; | |
1529 | ||
1530 | if (!gdbarch_get_longjmp_target_p (get_objfile_arch (objfile))) | |
1531 | continue; | |
1532 | ||
1533 | m = lookup_minimal_symbol_text (func_name, objfile); | |
1534 | if (m == NULL) | |
1535 | continue; | |
1536 | ||
a6d9a66e UW |
1537 | b = create_internal_breakpoint (get_objfile_arch (objfile), |
1538 | SYMBOL_VALUE_ADDRESS (m), | |
0fd8e87f UW |
1539 | bp_longjmp_master); |
1540 | b->addr_string = xstrdup (func_name); | |
1541 | b->enable_state = bp_disabled; | |
1542 | } | |
1543 | update_global_location_list (1); | |
1544 | } | |
1545 | ||
c906108c | 1546 | void |
fba45db2 | 1547 | update_breakpoints_after_exec (void) |
c906108c | 1548 | { |
c5aa993b JM |
1549 | struct breakpoint *b; |
1550 | struct breakpoint *temp; | |
25b22b0a | 1551 | struct bp_location *bploc; |
c906108c | 1552 | |
25b22b0a PA |
1553 | /* We're about to delete breakpoints from GDB's lists. If the |
1554 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
1555 | writing the breakpoints' "shadow contents" back into memory. The | |
1556 | "shadow contents" are NOT valid after an exec, so GDB should not | |
1557 | do that. Instead, the target is responsible from marking | |
1558 | breakpoints out as soon as it detects an exec. We don't do that | |
1559 | here instead, because there may be other attempts to delete | |
1560 | breakpoints after detecting an exec and before reaching here. */ | |
1561 | ALL_BP_LOCATIONS (bploc) | |
1562 | gdb_assert (!bploc->inserted); | |
c906108c SS |
1563 | |
1564 | ALL_BREAKPOINTS_SAFE (b, temp) | |
c5aa993b JM |
1565 | { |
1566 | /* Solib breakpoints must be explicitly reset after an exec(). */ | |
1567 | if (b->type == bp_shlib_event) | |
1568 | { | |
1569 | delete_breakpoint (b); | |
1570 | continue; | |
1571 | } | |
c906108c | 1572 | |
1900040c | 1573 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
1574 | as must overlay event and longjmp master breakpoints. */ |
1575 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
1576 | || b->type == bp_longjmp_master) | |
c4093a6a JM |
1577 | { |
1578 | delete_breakpoint (b); | |
1579 | continue; | |
1580 | } | |
1581 | ||
c5aa993b JM |
1582 | /* Step-resume breakpoints are meaningless after an exec(). */ |
1583 | if (b->type == bp_step_resume) | |
1584 | { | |
1585 | delete_breakpoint (b); | |
1586 | continue; | |
1587 | } | |
1588 | ||
611c83ae PA |
1589 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
1590 | after an exec. */ | |
1591 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume) | |
1592 | { | |
1593 | delete_breakpoint (b); | |
1594 | continue; | |
1595 | } | |
1596 | ||
ce78b96d JB |
1597 | if (b->type == bp_catchpoint) |
1598 | { | |
1599 | /* For now, none of the bp_catchpoint breakpoints need to | |
1600 | do anything at this point. In the future, if some of | |
1601 | the catchpoints need to something, we will need to add | |
1602 | a new method, and call this method from here. */ | |
1603 | continue; | |
1604 | } | |
1605 | ||
c5aa993b JM |
1606 | /* bp_finish is a special case. The only way we ought to be able |
1607 | to see one of these when an exec() has happened, is if the user | |
1608 | caught a vfork, and then said "finish". Ordinarily a finish just | |
1609 | carries them to the call-site of the current callee, by setting | |
1610 | a temporary bp there and resuming. But in this case, the finish | |
1611 | will carry them entirely through the vfork & exec. | |
1612 | ||
1613 | We don't want to allow a bp_finish to remain inserted now. But | |
1614 | we can't safely delete it, 'cause finish_command has a handle to | |
1615 | the bp on a bpstat, and will later want to delete it. There's a | |
1616 | chance (and I've seen it happen) that if we delete the bp_finish | |
1617 | here, that its storage will get reused by the time finish_command | |
1618 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
1619 | We really must allow finish_command to delete a bp_finish. | |
1620 | ||
53a5351d JM |
1621 | In the absense of a general solution for the "how do we know |
1622 | it's safe to delete something others may have handles to?" | |
1623 | problem, what we'll do here is just uninsert the bp_finish, and | |
1624 | let finish_command delete it. | |
1625 | ||
1626 | (We know the bp_finish is "doomed" in the sense that it's | |
1627 | momentary, and will be deleted as soon as finish_command sees | |
1628 | the inferior stopped. So it doesn't matter that the bp's | |
1629 | address is probably bogus in the new a.out, unlike e.g., the | |
1630 | solib breakpoints.) */ | |
c5aa993b | 1631 | |
c5aa993b JM |
1632 | if (b->type == bp_finish) |
1633 | { | |
1634 | continue; | |
1635 | } | |
1636 | ||
1637 | /* Without a symbolic address, we have little hope of the | |
1638 | pre-exec() address meaning the same thing in the post-exec() | |
1639 | a.out. */ | |
1640 | if (b->addr_string == NULL) | |
1641 | { | |
1642 | delete_breakpoint (b); | |
1643 | continue; | |
1644 | } | |
c5aa993b | 1645 | } |
1900040c | 1646 | /* FIXME what about longjmp breakpoints? Re-create them here? */ |
69de3c6a | 1647 | create_overlay_event_breakpoint ("_ovly_debug_event"); |
0fd8e87f UW |
1648 | create_longjmp_master_breakpoint ("longjmp"); |
1649 | create_longjmp_master_breakpoint ("_longjmp"); | |
1650 | create_longjmp_master_breakpoint ("siglongjmp"); | |
1651 | create_longjmp_master_breakpoint ("_siglongjmp"); | |
c906108c SS |
1652 | } |
1653 | ||
1654 | int | |
fba45db2 | 1655 | detach_breakpoints (int pid) |
c906108c | 1656 | { |
0bde7532 | 1657 | struct bp_location *b; |
3a1bae8e | 1658 | int val = 0; |
ce696e05 | 1659 | struct cleanup *old_chain = save_inferior_ptid (); |
c5aa993b | 1660 | |
39f77062 | 1661 | if (pid == PIDGET (inferior_ptid)) |
8a3fe4f8 | 1662 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 1663 | |
ce696e05 KB |
1664 | /* Set inferior_ptid; remove_breakpoint uses this global. */ |
1665 | inferior_ptid = pid_to_ptid (pid); | |
0bde7532 | 1666 | ALL_BP_LOCATIONS (b) |
c5aa993b | 1667 | { |
0bde7532 | 1668 | if (b->inserted) |
3a1bae8e | 1669 | val |= remove_breakpoint (b, mark_inserted); |
c5aa993b | 1670 | } |
ce696e05 | 1671 | do_cleanups (old_chain); |
3a1bae8e | 1672 | return val; |
c906108c SS |
1673 | } |
1674 | ||
1675 | static int | |
0bde7532 | 1676 | remove_breakpoint (struct bp_location *b, insertion_state_t is) |
c906108c SS |
1677 | { |
1678 | int val; | |
c5aa993b | 1679 | |
0bde7532 | 1680 | if (b->owner->enable_state == bp_permanent) |
c2c6d25f JM |
1681 | /* Permanent breakpoints cannot be inserted or removed. */ |
1682 | return 0; | |
1683 | ||
74960c60 VP |
1684 | /* The type of none suggests that owner is actually deleted. |
1685 | This should not ever happen. */ | |
1686 | gdb_assert (b->owner->type != bp_none); | |
0bde7532 DJ |
1687 | |
1688 | if (b->loc_type == bp_loc_software_breakpoint | |
1689 | || b->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 1690 | { |
c02f5703 MS |
1691 | /* "Normal" instruction breakpoint: either the standard |
1692 | trap-instruction bp (bp_breakpoint), or a | |
1693 | bp_hardware_breakpoint. */ | |
1694 | ||
1695 | /* First check to see if we have to handle an overlay. */ | |
1696 | if (overlay_debugging == ovly_off | |
0bde7532 DJ |
1697 | || b->section == NULL |
1698 | || !(section_is_overlay (b->section))) | |
c02f5703 MS |
1699 | { |
1700 | /* No overlay handling: just remove the breakpoint. */ | |
1701 | ||
0bde7532 | 1702 | if (b->loc_type == bp_loc_hardware_breakpoint) |
a6d9a66e | 1703 | val = target_remove_hw_breakpoint (b->gdbarch, &b->target_info); |
c02f5703 | 1704 | else |
a6d9a66e | 1705 | val = target_remove_breakpoint (b->gdbarch, &b->target_info); |
c02f5703 | 1706 | } |
c906108c SS |
1707 | else |
1708 | { | |
c02f5703 MS |
1709 | /* This breakpoint is in an overlay section. |
1710 | Did we set a breakpoint at the LMA? */ | |
1711 | if (!overlay_events_enabled) | |
1712 | { | |
1713 | /* Yes -- overlay event support is not active, so we | |
1714 | should have set a breakpoint at the LMA. Remove it. | |
1715 | */ | |
c02f5703 MS |
1716 | /* Ignore any failures: if the LMA is in ROM, we will |
1717 | have already warned when we failed to insert it. */ | |
0bde7532 | 1718 | if (b->loc_type == bp_loc_hardware_breakpoint) |
a6d9a66e UW |
1719 | target_remove_hw_breakpoint (b->gdbarch, |
1720 | &b->overlay_target_info); | |
c02f5703 | 1721 | else |
a6d9a66e UW |
1722 | target_remove_breakpoint (b->gdbarch, |
1723 | &b->overlay_target_info); | |
c02f5703 MS |
1724 | } |
1725 | /* Did we set a breakpoint at the VMA? | |
1726 | If so, we will have marked the breakpoint 'inserted'. */ | |
0bde7532 | 1727 | if (b->inserted) |
c906108c | 1728 | { |
c02f5703 MS |
1729 | /* Yes -- remove it. Previously we did not bother to |
1730 | remove the breakpoint if the section had been | |
1731 | unmapped, but let's not rely on that being safe. We | |
1732 | don't know what the overlay manager might do. */ | |
0bde7532 | 1733 | if (b->loc_type == bp_loc_hardware_breakpoint) |
a6d9a66e UW |
1734 | val = target_remove_hw_breakpoint (b->gdbarch, |
1735 | &b->target_info); | |
aa67235e UW |
1736 | |
1737 | /* However, we should remove *software* breakpoints only | |
1738 | if the section is still mapped, or else we overwrite | |
1739 | wrong code with the saved shadow contents. */ | |
1740 | else if (section_is_mapped (b->section)) | |
a6d9a66e UW |
1741 | val = target_remove_breakpoint (b->gdbarch, |
1742 | &b->target_info); | |
aa67235e UW |
1743 | else |
1744 | val = 0; | |
c906108c | 1745 | } |
c02f5703 MS |
1746 | else |
1747 | { | |
1748 | /* No -- not inserted, so no need to remove. No error. */ | |
1749 | val = 0; | |
1750 | } | |
c906108c | 1751 | } |
879d1e6b UW |
1752 | |
1753 | /* In some cases, we might not be able to remove a breakpoint | |
1754 | in a shared library that has already been removed, but we | |
1755 | have not yet processed the shlib unload event. */ | |
f5c9a895 | 1756 | if (val && solib_name_from_address (b->address)) |
879d1e6b UW |
1757 | val = 0; |
1758 | ||
c906108c SS |
1759 | if (val) |
1760 | return val; | |
0bde7532 | 1761 | b->inserted = (is == mark_inserted); |
c906108c | 1762 | } |
a5606eee | 1763 | else if (b->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 1764 | { |
278cd55f AC |
1765 | struct value *v; |
1766 | struct value *n; | |
c5aa993b | 1767 | |
0bde7532 | 1768 | b->inserted = (is == mark_inserted); |
a5606eee VP |
1769 | val = target_remove_watchpoint (b->address, b->length, |
1770 | b->watchpoint_type); | |
2e70b7b9 | 1771 | |
c906108c | 1772 | /* Failure to remove any of the hardware watchpoints comes here. */ |
0bde7532 | 1773 | if ((is == mark_uninserted) && (b->inserted)) |
8a3fe4f8 | 1774 | warning (_("Could not remove hardware watchpoint %d."), |
0bde7532 | 1775 | b->owner->number); |
c906108c | 1776 | } |
ce78b96d JB |
1777 | else if (b->owner->type == bp_catchpoint |
1778 | && breakpoint_enabled (b->owner) | |
1779 | && !b->duplicate) | |
1780 | { | |
1781 | gdb_assert (b->owner->ops != NULL && b->owner->ops->remove != NULL); | |
1782 | ||
1783 | val = b->owner->ops->remove (b->owner); | |
1784 | if (val) | |
1785 | return val; | |
1786 | b->inserted = (is == mark_inserted); | |
1787 | } | |
c906108c SS |
1788 | |
1789 | return 0; | |
1790 | } | |
1791 | ||
1792 | /* Clear the "inserted" flag in all breakpoints. */ | |
1793 | ||
25b22b0a | 1794 | void |
fba45db2 | 1795 | mark_breakpoints_out (void) |
c906108c | 1796 | { |
075f6582 | 1797 | struct bp_location *bpt; |
c906108c | 1798 | |
075f6582 DJ |
1799 | ALL_BP_LOCATIONS (bpt) |
1800 | bpt->inserted = 0; | |
c906108c SS |
1801 | } |
1802 | ||
53a5351d JM |
1803 | /* Clear the "inserted" flag in all breakpoints and delete any |
1804 | breakpoints which should go away between runs of the program. | |
c906108c SS |
1805 | |
1806 | Plus other such housekeeping that has to be done for breakpoints | |
1807 | between runs. | |
1808 | ||
53a5351d JM |
1809 | Note: this function gets called at the end of a run (by |
1810 | generic_mourn_inferior) and when a run begins (by | |
1811 | init_wait_for_inferior). */ | |
c906108c SS |
1812 | |
1813 | ||
1814 | ||
1815 | void | |
fba45db2 | 1816 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 1817 | { |
52f0bd74 | 1818 | struct breakpoint *b, *temp; |
075f6582 | 1819 | struct bp_location *bpt; |
1c5cfe86 | 1820 | int ix; |
c906108c | 1821 | |
50c71eaf PA |
1822 | /* If breakpoint locations are shared across processes, then there's |
1823 | nothing to do. */ | |
2567c7d9 | 1824 | if (gdbarch_has_global_breakpoints (target_gdbarch)) |
50c71eaf PA |
1825 | return; |
1826 | ||
075f6582 | 1827 | ALL_BP_LOCATIONS (bpt) |
514f746b AR |
1828 | if (bpt->owner->enable_state != bp_permanent) |
1829 | bpt->inserted = 0; | |
075f6582 | 1830 | |
c906108c | 1831 | ALL_BREAKPOINTS_SAFE (b, temp) |
c5aa993b | 1832 | { |
c5aa993b JM |
1833 | switch (b->type) |
1834 | { | |
1835 | case bp_call_dummy: | |
1836 | case bp_watchpoint_scope: | |
c906108c | 1837 | |
c5aa993b JM |
1838 | /* If the call dummy breakpoint is at the entry point it will |
1839 | cause problems when the inferior is rerun, so we better | |
1840 | get rid of it. | |
c906108c | 1841 | |
c5aa993b JM |
1842 | Also get rid of scope breakpoints. */ |
1843 | delete_breakpoint (b); | |
1844 | break; | |
c906108c | 1845 | |
c5aa993b JM |
1846 | case bp_watchpoint: |
1847 | case bp_hardware_watchpoint: | |
1848 | case bp_read_watchpoint: | |
1849 | case bp_access_watchpoint: | |
c906108c | 1850 | |
c5aa993b JM |
1851 | /* Likewise for watchpoints on local expressions. */ |
1852 | if (b->exp_valid_block != NULL) | |
1853 | delete_breakpoint (b); | |
967af18d | 1854 | else if (context == inf_starting) |
c860120c PM |
1855 | { |
1856 | /* Reset val field to force reread of starting value | |
1857 | in insert_breakpoints. */ | |
1858 | if (b->val) | |
1859 | value_free (b->val); | |
1860 | b->val = NULL; | |
fa4727a6 | 1861 | b->val_valid = 0; |
c860120c | 1862 | } |
c5aa993b JM |
1863 | break; |
1864 | default: | |
c5aa993b JM |
1865 | break; |
1866 | } | |
1867 | } | |
1c5cfe86 PA |
1868 | |
1869 | /* Get rid of the moribund locations. */ | |
1870 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bpt); ++ix) | |
1871 | free_bp_location (bpt); | |
1872 | VEC_free (bp_location_p, moribund_locations); | |
c906108c SS |
1873 | } |
1874 | ||
c2c6d25f JM |
1875 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
1876 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
1877 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
1878 | permanent breakpoint. | |
1879 | - When continuing from a location with an ordinary breakpoint, we | |
1880 | actually single step once before calling insert_breakpoints. | |
1881 | - When continuing from a localion with a permanent breakpoint, we | |
1882 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by | |
1883 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 1884 | |
c2c6d25f | 1885 | enum breakpoint_here |
fba45db2 | 1886 | breakpoint_here_p (CORE_ADDR pc) |
c906108c | 1887 | { |
89f9893c | 1888 | const struct bp_location *bpt; |
c2c6d25f | 1889 | int any_breakpoint_here = 0; |
c906108c | 1890 | |
075f6582 DJ |
1891 | ALL_BP_LOCATIONS (bpt) |
1892 | { | |
1893 | if (bpt->loc_type != bp_loc_software_breakpoint | |
1894 | && bpt->loc_type != bp_loc_hardware_breakpoint) | |
1895 | continue; | |
1896 | ||
468d015d | 1897 | if ((breakpoint_enabled (bpt->owner) |
075f6582 DJ |
1898 | || bpt->owner->enable_state == bp_permanent) |
1899 | && bpt->address == pc) /* bp is enabled and matches pc */ | |
1900 | { | |
1901 | if (overlay_debugging | |
1902 | && section_is_overlay (bpt->section) | |
1903 | && !section_is_mapped (bpt->section)) | |
1904 | continue; /* unmapped overlay -- can't be a match */ | |
1905 | else if (bpt->owner->enable_state == bp_permanent) | |
1906 | return permanent_breakpoint_here; | |
1907 | else | |
1908 | any_breakpoint_here = 1; | |
1909 | } | |
1910 | } | |
c906108c | 1911 | |
c2c6d25f | 1912 | return any_breakpoint_here ? ordinary_breakpoint_here : 0; |
c906108c SS |
1913 | } |
1914 | ||
1c5cfe86 PA |
1915 | /* Return true if there's a moribund breakpoint at PC. */ |
1916 | ||
1917 | int | |
1918 | moribund_breakpoint_here_p (CORE_ADDR pc) | |
1919 | { | |
1920 | struct bp_location *loc; | |
1921 | int ix; | |
1922 | ||
1923 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
1924 | if (loc->address == pc) | |
1925 | return 1; | |
1926 | ||
1927 | return 0; | |
1928 | } | |
c2c6d25f | 1929 | |
c36b740a VP |
1930 | /* Returns non-zero if there's a breakpoint inserted at PC, which is |
1931 | inserted using regular breakpoint_chain/bp_location_chain mechanism. | |
1932 | This does not check for single-step breakpoints, which are | |
1933 | inserted and removed using direct target manipulation. */ | |
c906108c SS |
1934 | |
1935 | int | |
c36b740a | 1936 | regular_breakpoint_inserted_here_p (CORE_ADDR pc) |
c906108c | 1937 | { |
89f9893c | 1938 | const struct bp_location *bpt; |
c906108c | 1939 | |
075f6582 | 1940 | ALL_BP_LOCATIONS (bpt) |
c5aa993b | 1941 | { |
075f6582 DJ |
1942 | if (bpt->loc_type != bp_loc_software_breakpoint |
1943 | && bpt->loc_type != bp_loc_hardware_breakpoint) | |
1944 | continue; | |
1945 | ||
1946 | if (bpt->inserted | |
1947 | && bpt->address == pc) /* bp is inserted and matches pc */ | |
1948 | { | |
1949 | if (overlay_debugging | |
1950 | && section_is_overlay (bpt->section) | |
1951 | && !section_is_mapped (bpt->section)) | |
1952 | continue; /* unmapped overlay -- can't be a match */ | |
1953 | else | |
1954 | return 1; | |
1955 | } | |
c5aa993b | 1956 | } |
c36b740a VP |
1957 | return 0; |
1958 | } | |
1959 | ||
1960 | /* Returns non-zero iff there's either regular breakpoint | |
1961 | or a single step breakpoint inserted at PC. */ | |
1962 | ||
1963 | int | |
1964 | breakpoint_inserted_here_p (CORE_ADDR pc) | |
1965 | { | |
1966 | if (regular_breakpoint_inserted_here_p (pc)) | |
1967 | return 1; | |
c906108c | 1968 | |
1aafd4da UW |
1969 | if (single_step_breakpoint_inserted_here_p (pc)) |
1970 | return 1; | |
1971 | ||
c906108c SS |
1972 | return 0; |
1973 | } | |
1974 | ||
4fa8626c DJ |
1975 | /* This function returns non-zero iff there is a software breakpoint |
1976 | inserted at PC. */ | |
1977 | ||
1978 | int | |
1979 | software_breakpoint_inserted_here_p (CORE_ADDR pc) | |
1980 | { | |
89f9893c | 1981 | const struct bp_location *bpt; |
4fa8626c DJ |
1982 | int any_breakpoint_here = 0; |
1983 | ||
1984 | ALL_BP_LOCATIONS (bpt) | |
1985 | { | |
1986 | if (bpt->loc_type != bp_loc_software_breakpoint) | |
1987 | continue; | |
1988 | ||
0d381245 | 1989 | if (bpt->inserted |
4fa8626c DJ |
1990 | && bpt->address == pc) /* bp is enabled and matches pc */ |
1991 | { | |
1992 | if (overlay_debugging | |
1993 | && section_is_overlay (bpt->section) | |
1994 | && !section_is_mapped (bpt->section)) | |
1995 | continue; /* unmapped overlay -- can't be a match */ | |
1996 | else | |
1997 | return 1; | |
1998 | } | |
1999 | } | |
2000 | ||
1aafd4da UW |
2001 | /* Also check for software single-step breakpoints. */ |
2002 | if (single_step_breakpoint_inserted_here_p (pc)) | |
2003 | return 1; | |
2004 | ||
4fa8626c DJ |
2005 | return 0; |
2006 | } | |
2007 | ||
075f6582 DJ |
2008 | /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at |
2009 | PC is valid for process/thread PTID. */ | |
c906108c SS |
2010 | |
2011 | int | |
39f77062 | 2012 | breakpoint_thread_match (CORE_ADDR pc, ptid_t ptid) |
c906108c | 2013 | { |
89f9893c | 2014 | const struct bp_location *bpt; |
4a306c9a | 2015 | /* The thread and task IDs associated to PTID, computed lazily. */ |
a6f1cd96 | 2016 | int thread = -1; |
4a306c9a | 2017 | int task = 0; |
a6f1cd96 | 2018 | |
075f6582 | 2019 | ALL_BP_LOCATIONS (bpt) |
c5aa993b | 2020 | { |
075f6582 DJ |
2021 | if (bpt->loc_type != bp_loc_software_breakpoint |
2022 | && bpt->loc_type != bp_loc_hardware_breakpoint) | |
2023 | continue; | |
2024 | ||
a6f1cd96 JB |
2025 | if (!breakpoint_enabled (bpt->owner) |
2026 | && bpt->owner->enable_state != bp_permanent) | |
2027 | continue; | |
2028 | ||
2029 | if (bpt->address != pc) | |
2030 | continue; | |
2031 | ||
2032 | if (bpt->owner->thread != -1) | |
075f6582 | 2033 | { |
a6f1cd96 JB |
2034 | /* This is a thread-specific breakpoint. Check that ptid |
2035 | matches that thread. If thread hasn't been computed yet, | |
2036 | it is now time to do so. */ | |
2037 | if (thread == -1) | |
2038 | thread = pid_to_thread_id (ptid); | |
2039 | if (bpt->owner->thread != thread) | |
2040 | continue; | |
075f6582 | 2041 | } |
a6f1cd96 | 2042 | |
4a306c9a JB |
2043 | if (bpt->owner->task != 0) |
2044 | { | |
2045 | /* This is a task-specific breakpoint. Check that ptid | |
2046 | matches that task. If task hasn't been computed yet, | |
2047 | it is now time to do so. */ | |
2048 | if (task == 0) | |
2049 | task = ada_get_task_number (ptid); | |
2050 | if (bpt->owner->task != task) | |
2051 | continue; | |
2052 | } | |
2053 | ||
a6f1cd96 JB |
2054 | if (overlay_debugging |
2055 | && section_is_overlay (bpt->section) | |
2056 | && !section_is_mapped (bpt->section)) | |
2057 | continue; /* unmapped overlay -- can't be a match */ | |
2058 | ||
2059 | return 1; | |
c5aa993b | 2060 | } |
c906108c SS |
2061 | |
2062 | return 0; | |
2063 | } | |
c906108c | 2064 | \f |
c5aa993b | 2065 | |
c906108c SS |
2066 | /* bpstat stuff. External routines' interfaces are documented |
2067 | in breakpoint.h. */ | |
2068 | ||
2069 | int | |
fba45db2 | 2070 | ep_is_catchpoint (struct breakpoint *ep) |
c906108c | 2071 | { |
533be4dd | 2072 | return (ep->type == bp_catchpoint); |
c906108c SS |
2073 | } |
2074 | ||
198757a8 VP |
2075 | void |
2076 | bpstat_free (bpstat bs) | |
2077 | { | |
2078 | if (bs->old_val != NULL) | |
2079 | value_free (bs->old_val); | |
2080 | free_command_lines (&bs->commands); | |
2081 | xfree (bs); | |
2082 | } | |
2083 | ||
c906108c SS |
2084 | /* Clear a bpstat so that it says we are not at any breakpoint. |
2085 | Also free any storage that is part of a bpstat. */ | |
2086 | ||
2087 | void | |
fba45db2 | 2088 | bpstat_clear (bpstat *bsp) |
c906108c SS |
2089 | { |
2090 | bpstat p; | |
2091 | bpstat q; | |
2092 | ||
2093 | if (bsp == 0) | |
2094 | return; | |
2095 | p = *bsp; | |
2096 | while (p != NULL) | |
2097 | { | |
2098 | q = p->next; | |
198757a8 | 2099 | bpstat_free (p); |
c906108c SS |
2100 | p = q; |
2101 | } | |
2102 | *bsp = NULL; | |
2103 | } | |
2104 | ||
2105 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
2106 | is part of the bpstat is copied as well. */ | |
2107 | ||
2108 | bpstat | |
fba45db2 | 2109 | bpstat_copy (bpstat bs) |
c906108c SS |
2110 | { |
2111 | bpstat p = NULL; | |
2112 | bpstat tmp; | |
2113 | bpstat retval = NULL; | |
2114 | ||
2115 | if (bs == NULL) | |
2116 | return bs; | |
2117 | ||
2118 | for (; bs != NULL; bs = bs->next) | |
2119 | { | |
2120 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
2121 | memcpy (tmp, bs, sizeof (*tmp)); | |
31cc81e9 DJ |
2122 | if (bs->commands != NULL) |
2123 | tmp->commands = copy_command_lines (bs->commands); | |
2124 | if (bs->old_val != NULL) | |
3c3185ac JK |
2125 | { |
2126 | tmp->old_val = value_copy (bs->old_val); | |
2127 | release_value (tmp->old_val); | |
2128 | } | |
31cc81e9 | 2129 | |
c906108c SS |
2130 | if (p == NULL) |
2131 | /* This is the first thing in the chain. */ | |
2132 | retval = tmp; | |
2133 | else | |
2134 | p->next = tmp; | |
2135 | p = tmp; | |
2136 | } | |
2137 | p->next = NULL; | |
2138 | return retval; | |
2139 | } | |
2140 | ||
2141 | /* Find the bpstat associated with this breakpoint */ | |
2142 | ||
2143 | bpstat | |
fba45db2 | 2144 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 2145 | { |
c5aa993b JM |
2146 | if (bsp == NULL) |
2147 | return NULL; | |
c906108c | 2148 | |
c5aa993b JM |
2149 | for (; bsp != NULL; bsp = bsp->next) |
2150 | { | |
4f8d1dc6 | 2151 | if (bsp->breakpoint_at && bsp->breakpoint_at->owner == breakpoint) |
c5aa993b JM |
2152 | return bsp; |
2153 | } | |
c906108c SS |
2154 | return NULL; |
2155 | } | |
2156 | ||
2157 | /* Find a step_resume breakpoint associated with this bpstat. | |
2158 | (If there are multiple step_resume bp's on the list, this function | |
2159 | will arbitrarily pick one.) | |
2160 | ||
2161 | It is an error to use this function if BPSTAT doesn't contain a | |
2162 | step_resume breakpoint. | |
2163 | ||
2164 | See wait_for_inferior's use of this function. */ | |
2165 | struct breakpoint * | |
fba45db2 | 2166 | bpstat_find_step_resume_breakpoint (bpstat bsp) |
c906108c | 2167 | { |
8601f500 MS |
2168 | int current_thread; |
2169 | ||
8a3fe4f8 | 2170 | gdb_assert (bsp != NULL); |
c906108c | 2171 | |
8601f500 MS |
2172 | current_thread = pid_to_thread_id (inferior_ptid); |
2173 | ||
c906108c SS |
2174 | for (; bsp != NULL; bsp = bsp->next) |
2175 | { | |
059fb39f PM |
2176 | if ((bsp->breakpoint_at != NULL) |
2177 | && (bsp->breakpoint_at->owner->type == bp_step_resume) | |
2178 | && (bsp->breakpoint_at->owner->thread == current_thread | |
2179 | || bsp->breakpoint_at->owner->thread == -1)) | |
4f8d1dc6 | 2180 | return bsp->breakpoint_at->owner; |
c906108c SS |
2181 | } |
2182 | ||
8a3fe4f8 | 2183 | internal_error (__FILE__, __LINE__, _("No step_resume breakpoint found.")); |
c906108c SS |
2184 | } |
2185 | ||
2186 | ||
8671a17b | 2187 | /* Put in *NUM the breakpoint number of the first breakpoint we are stopped |
c906108c SS |
2188 | at. *BSP upon return is a bpstat which points to the remaining |
2189 | breakpoints stopped at (but which is not guaranteed to be good for | |
2190 | anything but further calls to bpstat_num). | |
8671a17b PA |
2191 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
2192 | Return -1 if stopped at a breakpoint that has been deleted since | |
2193 | we set it. | |
2194 | Return 1 otherwise. */ | |
c906108c SS |
2195 | |
2196 | int | |
8671a17b | 2197 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
2198 | { |
2199 | struct breakpoint *b; | |
2200 | ||
2201 | if ((*bsp) == NULL) | |
2202 | return 0; /* No more breakpoint values */ | |
8671a17b | 2203 | |
4f8d1dc6 VP |
2204 | /* We assume we'll never have several bpstats that |
2205 | correspond to a single breakpoint -- otherwise, | |
2206 | this function might return the same number more | |
2207 | than once and this will look ugly. */ | |
2208 | b = (*bsp)->breakpoint_at ? (*bsp)->breakpoint_at->owner : NULL; | |
8671a17b PA |
2209 | *bsp = (*bsp)->next; |
2210 | if (b == NULL) | |
2211 | return -1; /* breakpoint that's been deleted since */ | |
2212 | ||
2213 | *num = b->number; /* We have its number */ | |
2214 | return 1; | |
c906108c SS |
2215 | } |
2216 | ||
2217 | /* Modify BS so that the actions will not be performed. */ | |
2218 | ||
2219 | void | |
fba45db2 | 2220 | bpstat_clear_actions (bpstat bs) |
c906108c SS |
2221 | { |
2222 | for (; bs != NULL; bs = bs->next) | |
2223 | { | |
c2b8ed2c | 2224 | free_command_lines (&bs->commands); |
c906108c SS |
2225 | if (bs->old_val != NULL) |
2226 | { | |
2227 | value_free (bs->old_val); | |
2228 | bs->old_val = NULL; | |
2229 | } | |
2230 | } | |
2231 | } | |
2232 | ||
f3b1572e PA |
2233 | /* Called when a command is about to proceed the inferior. */ |
2234 | ||
2235 | static void | |
2236 | breakpoint_about_to_proceed (void) | |
2237 | { | |
2238 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
2239 | { | |
2240 | struct thread_info *tp = inferior_thread (); | |
2241 | ||
2242 | /* Allow inferior function calls in breakpoint commands to not | |
2243 | interrupt the command list. When the call finishes | |
2244 | successfully, the inferior will be standing at the same | |
2245 | breakpoint as if nothing happened. */ | |
2246 | if (tp->in_infcall) | |
2247 | return; | |
2248 | } | |
2249 | ||
2250 | breakpoint_proceeded = 1; | |
2251 | } | |
2252 | ||
c906108c | 2253 | /* Stub for cleaning up our state if we error-out of a breakpoint command */ |
c906108c | 2254 | static void |
4efb68b1 | 2255 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
2256 | { |
2257 | executing_breakpoint_commands = 0; | |
2258 | } | |
2259 | ||
2260 | /* Execute all the commands associated with all the breakpoints at this | |
2261 | location. Any of these commands could cause the process to proceed | |
2262 | beyond this point, etc. We look out for such changes by checking | |
347bddb7 | 2263 | the global "breakpoint_proceeded" after each command. |
c906108c | 2264 | |
347bddb7 PA |
2265 | Returns true if a breakpoint command resumed the inferior. In that |
2266 | case, it is the caller's responsibility to recall it again with the | |
2267 | bpstat of the current thread. */ | |
2268 | ||
2269 | static int | |
2270 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
2271 | { |
2272 | bpstat bs; | |
2273 | struct cleanup *old_chain; | |
347bddb7 | 2274 | int again = 0; |
c906108c SS |
2275 | |
2276 | /* Avoid endless recursion if a `source' command is contained | |
2277 | in bs->commands. */ | |
2278 | if (executing_breakpoint_commands) | |
347bddb7 | 2279 | return 0; |
c906108c SS |
2280 | |
2281 | executing_breakpoint_commands = 1; | |
2282 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
2283 | ||
c906108c SS |
2284 | /* This pointer will iterate over the list of bpstat's. */ |
2285 | bs = *bsp; | |
2286 | ||
2287 | breakpoint_proceeded = 0; | |
2288 | for (; bs != NULL; bs = bs->next) | |
2289 | { | |
6c50ab1c JB |
2290 | struct command_line *cmd; |
2291 | struct cleanup *this_cmd_tree_chain; | |
2292 | ||
2293 | /* Take ownership of the BSP's command tree, if it has one. | |
2294 | ||
2295 | The command tree could legitimately contain commands like | |
2296 | 'step' and 'next', which call clear_proceed_status, which | |
2297 | frees stop_bpstat's command tree. To make sure this doesn't | |
2298 | free the tree we're executing out from under us, we need to | |
2299 | take ownership of the tree ourselves. Since a given bpstat's | |
2300 | commands are only executed once, we don't need to copy it; we | |
2301 | can clear the pointer in the bpstat, and make sure we free | |
2302 | the tree when we're done. */ | |
c906108c | 2303 | cmd = bs->commands; |
6c50ab1c JB |
2304 | bs->commands = 0; |
2305 | this_cmd_tree_chain = make_cleanup_free_command_lines (&cmd); | |
2306 | ||
c906108c SS |
2307 | while (cmd != NULL) |
2308 | { | |
2309 | execute_control_command (cmd); | |
2310 | ||
2311 | if (breakpoint_proceeded) | |
2312 | break; | |
2313 | else | |
2314 | cmd = cmd->next; | |
2315 | } | |
6c50ab1c JB |
2316 | |
2317 | /* We can free this command tree now. */ | |
2318 | do_cleanups (this_cmd_tree_chain); | |
2319 | ||
c906108c | 2320 | if (breakpoint_proceeded) |
32c1e744 VP |
2321 | { |
2322 | if (target_can_async_p ()) | |
347bddb7 PA |
2323 | /* If we are in async mode, then the target might be still |
2324 | running, not stopped at any breakpoint, so nothing for | |
2325 | us to do here -- just return to the event loop. */ | |
2326 | ; | |
32c1e744 VP |
2327 | else |
2328 | /* In sync mode, when execute_control_command returns | |
2329 | we're already standing on the next breakpoint. | |
347bddb7 PA |
2330 | Breakpoint commands for that stop were not run, since |
2331 | execute_command does not run breakpoint commands -- | |
2332 | only command_line_handler does, but that one is not | |
2333 | involved in execution of breakpoint commands. So, we | |
2334 | can now execute breakpoint commands. It should be | |
2335 | noted that making execute_command do bpstat actions is | |
2336 | not an option -- in this case we'll have recursive | |
2337 | invocation of bpstat for each breakpoint with a | |
2338 | command, and can easily blow up GDB stack. Instead, we | |
2339 | return true, which will trigger the caller to recall us | |
2340 | with the new stop_bpstat. */ | |
2341 | again = 1; | |
2342 | break; | |
32c1e744 | 2343 | } |
c906108c | 2344 | } |
c2b8ed2c | 2345 | do_cleanups (old_chain); |
347bddb7 PA |
2346 | return again; |
2347 | } | |
2348 | ||
2349 | void | |
2350 | bpstat_do_actions (void) | |
2351 | { | |
2352 | /* Do any commands attached to breakpoint we are stopped at. */ | |
2353 | while (!ptid_equal (inferior_ptid, null_ptid) | |
2354 | && target_has_execution | |
2355 | && !is_exited (inferior_ptid) | |
2356 | && !is_executing (inferior_ptid)) | |
2357 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
2358 | and only return when it is stopped at the next breakpoint, we | |
2359 | keep doing breakpoint actions until it returns false to | |
2360 | indicate the inferior was not resumed. */ | |
2361 | if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat)) | |
2362 | break; | |
c906108c SS |
2363 | } |
2364 | ||
fa4727a6 DJ |
2365 | /* Print out the (old or new) value associated with a watchpoint. */ |
2366 | ||
2367 | static void | |
2368 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
2369 | { | |
2370 | if (val == NULL) | |
2371 | fprintf_unfiltered (stream, _("<unreadable>")); | |
2372 | else | |
79a45b7d TT |
2373 | { |
2374 | struct value_print_options opts; | |
2375 | get_user_print_options (&opts); | |
2376 | value_print (val, stream, &opts); | |
2377 | } | |
fa4727a6 DJ |
2378 | } |
2379 | ||
e514a9d6 | 2380 | /* This is the normal print function for a bpstat. In the future, |
c906108c | 2381 | much of this logic could (should?) be moved to bpstat_stop_status, |
e514a9d6 JM |
2382 | by having it set different print_it values. |
2383 | ||
2384 | Current scheme: When we stop, bpstat_print() is called. It loops | |
2385 | through the bpstat list of things causing this stop, calling the | |
2386 | print_bp_stop_message function on each one. The behavior of the | |
2387 | print_bp_stop_message function depends on the print_it field of | |
2388 | bpstat. If such field so indicates, call this function here. | |
2389 | ||
2390 | Return values from this routine (ultimately used by bpstat_print() | |
2391 | and normal_stop() to decide what to do): | |
2392 | PRINT_NOTHING: Means we already printed all we needed to print, | |
2393 | don't print anything else. | |
2394 | PRINT_SRC_ONLY: Means we printed something, and we do *not* desire | |
2395 | that something to be followed by a location. | |
2396 | PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire | |
2397 | that something to be followed by a location. | |
2398 | PRINT_UNKNOWN: Means we printed nothing or we need to do some more | |
2399 | analysis. */ | |
c906108c | 2400 | |
917317f4 | 2401 | static enum print_stop_action |
fba45db2 | 2402 | print_it_typical (bpstat bs) |
c906108c | 2403 | { |
f7545552 | 2404 | struct cleanup *old_chain; |
4f8d1dc6 | 2405 | struct breakpoint *b; |
89f9893c | 2406 | const struct bp_location *bl; |
8b93c638 | 2407 | struct ui_stream *stb; |
f7545552 TT |
2408 | int bp_temp = 0; |
2409 | enum print_stop_action result; | |
2410 | ||
c906108c SS |
2411 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
2412 | which has since been deleted. */ | |
e514a9d6 | 2413 | if (bs->breakpoint_at == NULL) |
917317f4 | 2414 | return PRINT_UNKNOWN; |
0d381245 VP |
2415 | bl = bs->breakpoint_at; |
2416 | b = bl->owner; | |
c906108c | 2417 | |
f7545552 TT |
2418 | stb = ui_out_stream_new (uiout); |
2419 | old_chain = make_cleanup_ui_out_stream_delete (stb); | |
2420 | ||
4f8d1dc6 | 2421 | switch (b->type) |
c906108c | 2422 | { |
e514a9d6 JM |
2423 | case bp_breakpoint: |
2424 | case bp_hardware_breakpoint: | |
2cec12e5 | 2425 | bp_temp = bs->breakpoint_at->owner->disposition == disp_del; |
0d381245 VP |
2426 | if (bl->address != bl->requested_address) |
2427 | breakpoint_adjustment_warning (bl->requested_address, | |
2428 | bl->address, | |
4f8d1dc6 VP |
2429 | b->number, 1); |
2430 | annotate_breakpoint (b->number); | |
2cec12e5 AR |
2431 | if (bp_temp) |
2432 | ui_out_text (uiout, "\nTemporary breakpoint "); | |
2433 | else | |
2434 | ui_out_text (uiout, "\nBreakpoint "); | |
9dc5e2a9 | 2435 | if (ui_out_is_mi_like_p (uiout)) |
2cec12e5 AR |
2436 | { |
2437 | ui_out_field_string (uiout, "reason", | |
2438 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
2439 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
2440 | } | |
4f8d1dc6 | 2441 | ui_out_field_int (uiout, "bkptno", b->number); |
8b93c638 | 2442 | ui_out_text (uiout, ", "); |
f7545552 | 2443 | result = PRINT_SRC_AND_LOC; |
e514a9d6 JM |
2444 | break; |
2445 | ||
2446 | case bp_shlib_event: | |
917317f4 JM |
2447 | /* Did we stop because the user set the stop_on_solib_events |
2448 | variable? (If so, we report this as a generic, "Stopped due | |
2449 | to shlib event" message.) */ | |
a3f17187 | 2450 | printf_filtered (_("Stopped due to shared library event\n")); |
f7545552 | 2451 | result = PRINT_NOTHING; |
e514a9d6 JM |
2452 | break; |
2453 | ||
c4093a6a JM |
2454 | case bp_thread_event: |
2455 | /* Not sure how we will get here. | |
2456 | GDB should not stop for these breakpoints. */ | |
a3f17187 | 2457 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); |
f7545552 | 2458 | result = PRINT_NOTHING; |
c4093a6a JM |
2459 | break; |
2460 | ||
1900040c MS |
2461 | case bp_overlay_event: |
2462 | /* By analogy with the thread event, GDB should not stop for these. */ | |
a3f17187 | 2463 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); |
f7545552 | 2464 | result = PRINT_NOTHING; |
1900040c MS |
2465 | break; |
2466 | ||
0fd8e87f UW |
2467 | case bp_longjmp_master: |
2468 | /* These should never be enabled. */ | |
2469 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
2470 | result = PRINT_NOTHING; | |
2471 | break; | |
2472 | ||
e514a9d6 JM |
2473 | case bp_watchpoint: |
2474 | case bp_hardware_watchpoint: | |
fa4727a6 DJ |
2475 | annotate_watchpoint (b->number); |
2476 | if (ui_out_is_mi_like_p (uiout)) | |
2477 | ui_out_field_string | |
2478 | (uiout, "reason", | |
2479 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
2480 | mention (b); | |
f7545552 | 2481 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
fa4727a6 DJ |
2482 | ui_out_text (uiout, "\nOld value = "); |
2483 | watchpoint_value_print (bs->old_val, stb->stream); | |
2484 | ui_out_field_stream (uiout, "old", stb); | |
2485 | ui_out_text (uiout, "\nNew value = "); | |
2486 | watchpoint_value_print (b->val, stb->stream); | |
2487 | ui_out_field_stream (uiout, "new", stb); | |
fa4727a6 | 2488 | ui_out_text (uiout, "\n"); |
e514a9d6 | 2489 | /* More than one watchpoint may have been triggered. */ |
f7545552 | 2490 | result = PRINT_UNKNOWN; |
e514a9d6 JM |
2491 | break; |
2492 | ||
2493 | case bp_read_watchpoint: | |
9dc5e2a9 | 2494 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
2495 | ui_out_field_string |
2496 | (uiout, "reason", | |
2497 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
4f8d1dc6 | 2498 | mention (b); |
f7545552 | 2499 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 | 2500 | ui_out_text (uiout, "\nValue = "); |
fa4727a6 | 2501 | watchpoint_value_print (b->val, stb->stream); |
8b93c638 | 2502 | ui_out_field_stream (uiout, "value", stb); |
8b93c638 | 2503 | ui_out_text (uiout, "\n"); |
f7545552 | 2504 | result = PRINT_UNKNOWN; |
e514a9d6 JM |
2505 | break; |
2506 | ||
2507 | case bp_access_watchpoint: | |
fa4727a6 | 2508 | if (bs->old_val != NULL) |
8b93c638 | 2509 | { |
4f8d1dc6 | 2510 | annotate_watchpoint (b->number); |
9dc5e2a9 | 2511 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
2512 | ui_out_field_string |
2513 | (uiout, "reason", | |
2514 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
4f8d1dc6 | 2515 | mention (b); |
f7545552 | 2516 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 | 2517 | ui_out_text (uiout, "\nOld value = "); |
fa4727a6 | 2518 | watchpoint_value_print (bs->old_val, stb->stream); |
8b93c638 | 2519 | ui_out_field_stream (uiout, "old", stb); |
8b93c638 JM |
2520 | ui_out_text (uiout, "\nNew value = "); |
2521 | } | |
2522 | else | |
2523 | { | |
4f8d1dc6 | 2524 | mention (b); |
9dc5e2a9 | 2525 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
2526 | ui_out_field_string |
2527 | (uiout, "reason", | |
2528 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
f7545552 | 2529 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 JM |
2530 | ui_out_text (uiout, "\nValue = "); |
2531 | } | |
fa4727a6 | 2532 | watchpoint_value_print (b->val, stb->stream); |
8b93c638 | 2533 | ui_out_field_stream (uiout, "new", stb); |
8b93c638 | 2534 | ui_out_text (uiout, "\n"); |
f7545552 | 2535 | result = PRINT_UNKNOWN; |
e514a9d6 | 2536 | break; |
4ce44c66 | 2537 | |
e514a9d6 JM |
2538 | /* Fall through, we don't deal with these types of breakpoints |
2539 | here. */ | |
2540 | ||
11cf8741 | 2541 | case bp_finish: |
9dc5e2a9 | 2542 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
2543 | ui_out_field_string |
2544 | (uiout, "reason", | |
2545 | async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED)); | |
f7545552 | 2546 | result = PRINT_UNKNOWN; |
8b93c638 JM |
2547 | break; |
2548 | ||
e514a9d6 | 2549 | case bp_until: |
9dc5e2a9 | 2550 | if (ui_out_is_mi_like_p (uiout)) |
1fbc2a49 NR |
2551 | ui_out_field_string |
2552 | (uiout, "reason", | |
2553 | async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED)); | |
f7545552 | 2554 | result = PRINT_UNKNOWN; |
8b93c638 JM |
2555 | break; |
2556 | ||
c2d11a7d | 2557 | case bp_none: |
e514a9d6 JM |
2558 | case bp_longjmp: |
2559 | case bp_longjmp_resume: | |
2560 | case bp_step_resume: | |
e514a9d6 JM |
2561 | case bp_watchpoint_scope: |
2562 | case bp_call_dummy: | |
1042e4c0 | 2563 | case bp_tracepoint: |
e514a9d6 | 2564 | default: |
f7545552 TT |
2565 | result = PRINT_UNKNOWN; |
2566 | break; | |
e514a9d6 | 2567 | } |
f7545552 TT |
2568 | |
2569 | do_cleanups (old_chain); | |
2570 | return result; | |
e514a9d6 JM |
2571 | } |
2572 | ||
2573 | /* Generic routine for printing messages indicating why we | |
2574 | stopped. The behavior of this function depends on the value | |
2575 | 'print_it' in the bpstat structure. Under some circumstances we | |
2576 | may decide not to print anything here and delegate the task to | |
2577 | normal_stop(). */ | |
2578 | ||
2579 | static enum print_stop_action | |
2580 | print_bp_stop_message (bpstat bs) | |
2581 | { | |
2582 | switch (bs->print_it) | |
2583 | { | |
2584 | case print_it_noop: | |
2585 | /* Nothing should be printed for this bpstat entry. */ | |
2586 | return PRINT_UNKNOWN; | |
2587 | break; | |
2588 | ||
2589 | case print_it_done: | |
2590 | /* We still want to print the frame, but we already printed the | |
2591 | relevant messages. */ | |
2592 | return PRINT_SRC_AND_LOC; | |
2593 | break; | |
2594 | ||
2595 | case print_it_normal: | |
4f8d1dc6 | 2596 | { |
89f9893c | 2597 | const struct bp_location *bl = bs->breakpoint_at; |
4f8d1dc6 VP |
2598 | struct breakpoint *b = bl ? bl->owner : NULL; |
2599 | ||
2600 | /* Normal case. Call the breakpoint's print_it method, or | |
2601 | print_it_typical. */ | |
2602 | /* FIXME: how breakpoint can ever be NULL here? */ | |
2603 | if (b != NULL && b->ops != NULL && b->ops->print_it != NULL) | |
2604 | return b->ops->print_it (b); | |
2605 | else | |
2606 | return print_it_typical (bs); | |
2607 | } | |
2608 | break; | |
3086aeae | 2609 | |
e514a9d6 | 2610 | default: |
8e65ff28 | 2611 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 2612 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 2613 | break; |
c906108c | 2614 | } |
c906108c SS |
2615 | } |
2616 | ||
e514a9d6 JM |
2617 | /* Print a message indicating what happened. This is called from |
2618 | normal_stop(). The input to this routine is the head of the bpstat | |
2619 | list - a list of the eventpoints that caused this stop. This | |
2620 | routine calls the generic print routine for printing a message | |
2621 | about reasons for stopping. This will print (for example) the | |
2622 | "Breakpoint n," part of the output. The return value of this | |
2623 | routine is one of: | |
c906108c | 2624 | |
917317f4 JM |
2625 | PRINT_UNKNOWN: Means we printed nothing |
2626 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent | |
c5aa993b JM |
2627 | code to print the location. An example is |
2628 | "Breakpoint 1, " which should be followed by | |
2629 | the location. | |
917317f4 | 2630 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
2631 | to also print the location part of the message. |
2632 | An example is the catch/throw messages, which | |
917317f4 JM |
2633 | don't require a location appended to the end. |
2634 | PRINT_NOTHING: We have done some printing and we don't need any | |
2635 | further info to be printed.*/ | |
c906108c | 2636 | |
917317f4 | 2637 | enum print_stop_action |
fba45db2 | 2638 | bpstat_print (bpstat bs) |
c906108c SS |
2639 | { |
2640 | int val; | |
c5aa993b | 2641 | |
c906108c | 2642 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
2643 | (Currently all watchpoints go on the bpstat whether hit or not. |
2644 | That probably could (should) be changed, provided care is taken | |
c906108c | 2645 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
2646 | for (; bs; bs = bs->next) |
2647 | { | |
2648 | val = print_bp_stop_message (bs); | |
2649 | if (val == PRINT_SRC_ONLY | |
2650 | || val == PRINT_SRC_AND_LOC | |
2651 | || val == PRINT_NOTHING) | |
2652 | return val; | |
2653 | } | |
c906108c | 2654 | |
e514a9d6 JM |
2655 | /* We reached the end of the chain, or we got a null BS to start |
2656 | with and nothing was printed. */ | |
917317f4 | 2657 | return PRINT_UNKNOWN; |
c906108c SS |
2658 | } |
2659 | ||
2660 | /* Evaluate the expression EXP and return 1 if value is zero. | |
2661 | This is used inside a catch_errors to evaluate the breakpoint condition. | |
2662 | The argument is a "struct expression *" that has been cast to char * to | |
2663 | make it pass through catch_errors. */ | |
2664 | ||
2665 | static int | |
4efb68b1 | 2666 | breakpoint_cond_eval (void *exp) |
c906108c | 2667 | { |
278cd55f | 2668 | struct value *mark = value_mark (); |
c5aa993b | 2669 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
c906108c SS |
2670 | value_free_to_mark (mark); |
2671 | return i; | |
2672 | } | |
2673 | ||
2674 | /* Allocate a new bpstat and chain it to the current one. */ | |
2675 | ||
2676 | static bpstat | |
89f9893c | 2677 | bpstat_alloc (const struct bp_location *bl, bpstat cbs /* Current "bs" value */ ) |
c906108c SS |
2678 | { |
2679 | bpstat bs; | |
2680 | ||
2681 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
2682 | cbs->next = bs; | |
4f8d1dc6 | 2683 | bs->breakpoint_at = bl; |
c906108c SS |
2684 | /* If the condition is false, etc., don't do the commands. */ |
2685 | bs->commands = NULL; | |
2686 | bs->old_val = NULL; | |
2687 | bs->print_it = print_it_normal; | |
2688 | return bs; | |
2689 | } | |
2690 | \f | |
d983da9c DJ |
2691 | /* The target has stopped with waitstatus WS. Check if any hardware |
2692 | watchpoints have triggered, according to the target. */ | |
2693 | ||
2694 | int | |
2695 | watchpoints_triggered (struct target_waitstatus *ws) | |
2696 | { | |
d92524f1 | 2697 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
2698 | CORE_ADDR addr; |
2699 | struct breakpoint *b; | |
2700 | ||
2701 | if (!stopped_by_watchpoint) | |
2702 | { | |
2703 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
2704 | as not triggered. */ | |
2705 | ALL_BREAKPOINTS (b) | |
2706 | if (b->type == bp_hardware_watchpoint | |
2707 | || b->type == bp_read_watchpoint | |
2708 | || b->type == bp_access_watchpoint) | |
2709 | b->watchpoint_triggered = watch_triggered_no; | |
2710 | ||
2711 | return 0; | |
2712 | } | |
2713 | ||
2714 | if (!target_stopped_data_address (¤t_target, &addr)) | |
2715 | { | |
2716 | /* We were stopped by a watchpoint, but we don't know where. | |
2717 | Mark all watchpoints as unknown. */ | |
2718 | ALL_BREAKPOINTS (b) | |
2719 | if (b->type == bp_hardware_watchpoint | |
2720 | || b->type == bp_read_watchpoint | |
2721 | || b->type == bp_access_watchpoint) | |
2722 | b->watchpoint_triggered = watch_triggered_unknown; | |
2723 | ||
2724 | return stopped_by_watchpoint; | |
2725 | } | |
2726 | ||
2727 | /* The target could report the data address. Mark watchpoints | |
2728 | affected by this data address as triggered, and all others as not | |
2729 | triggered. */ | |
2730 | ||
2731 | ALL_BREAKPOINTS (b) | |
2732 | if (b->type == bp_hardware_watchpoint | |
2733 | || b->type == bp_read_watchpoint | |
2734 | || b->type == bp_access_watchpoint) | |
2735 | { | |
a5606eee | 2736 | struct bp_location *loc; |
d983da9c DJ |
2737 | struct value *v; |
2738 | ||
2739 | b->watchpoint_triggered = watch_triggered_no; | |
a5606eee VP |
2740 | for (loc = b->loc; loc; loc = loc->next) |
2741 | /* Exact match not required. Within range is | |
2742 | sufficient. */ | |
5009afc5 AS |
2743 | if (target_watchpoint_addr_within_range (¤t_target, |
2744 | addr, loc->address, | |
2745 | loc->length)) | |
a5606eee VP |
2746 | { |
2747 | b->watchpoint_triggered = watch_triggered_yes; | |
2748 | break; | |
2749 | } | |
d983da9c DJ |
2750 | } |
2751 | ||
2752 | return 1; | |
2753 | } | |
2754 | ||
c906108c SS |
2755 | /* Possible return values for watchpoint_check (this can't be an enum |
2756 | because of check_errors). */ | |
2757 | /* The watchpoint has been deleted. */ | |
2758 | #define WP_DELETED 1 | |
2759 | /* The value has changed. */ | |
2760 | #define WP_VALUE_CHANGED 2 | |
2761 | /* The value has not changed. */ | |
2762 | #define WP_VALUE_NOT_CHANGED 3 | |
2763 | ||
2764 | #define BP_TEMPFLAG 1 | |
2765 | #define BP_HARDWAREFLAG 2 | |
2766 | ||
2767 | /* Check watchpoint condition. */ | |
2768 | ||
2769 | static int | |
4efb68b1 | 2770 | watchpoint_check (void *p) |
c906108c SS |
2771 | { |
2772 | bpstat bs = (bpstat) p; | |
2773 | struct breakpoint *b; | |
2774 | struct frame_info *fr; | |
2775 | int within_current_scope; | |
2776 | ||
4f8d1dc6 | 2777 | b = bs->breakpoint_at->owner; |
c906108c SS |
2778 | |
2779 | if (b->exp_valid_block == NULL) | |
2780 | within_current_scope = 1; | |
2781 | else | |
2782 | { | |
edb3359d DJ |
2783 | struct frame_info *frame = get_current_frame (); |
2784 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
2785 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
2786 | ||
101dcfbe | 2787 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 2788 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
2789 | |
2790 | /* If we've gotten confused in the unwinder, we might have | |
2791 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
2792 | if (within_current_scope) |
2793 | { | |
2794 | struct symbol *function; | |
2795 | ||
2796 | function = get_frame_function (fr); | |
2797 | if (function == NULL | |
2798 | || !contained_in (b->exp_valid_block, | |
2799 | SYMBOL_BLOCK_VALUE (function))) | |
2800 | within_current_scope = 0; | |
2801 | } | |
69fbadd5 | 2802 | |
c12260ac CV |
2803 | /* in_function_epilogue_p() returns a non-zero value if we're still |
2804 | in the function but the stack frame has already been invalidated. | |
2805 | Since we can't rely on the values of local variables after the | |
2806 | stack has been destroyed, we are treating the watchpoint in that | |
edb3359d DJ |
2807 | state as `not changed' without further checking. Don't mark |
2808 | watchpoints as changed if the current frame is in an epilogue - | |
2809 | even if they are in some other frame, our view of the stack | |
2810 | is likely to be wrong. */ | |
2811 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) | |
2812 | return WP_VALUE_NOT_CHANGED; | |
fb14de7b | 2813 | |
edb3359d | 2814 | if (within_current_scope) |
c906108c SS |
2815 | /* If we end up stopping, the current frame will get selected |
2816 | in normal_stop. So this call to select_frame won't affect | |
2817 | the user. */ | |
0f7d239c | 2818 | select_frame (fr); |
c906108c | 2819 | } |
c5aa993b | 2820 | |
c906108c SS |
2821 | if (within_current_scope) |
2822 | { | |
2823 | /* We use value_{,free_to_}mark because it could be a | |
2824 | *long* time before we return to the command level and | |
c5aa993b JM |
2825 | call free_all_values. We can't call free_all_values because |
2826 | we might be in the middle of evaluating a function call. */ | |
c906108c | 2827 | |
278cd55f | 2828 | struct value *mark = value_mark (); |
fa4727a6 DJ |
2829 | struct value *new_val; |
2830 | ||
2831 | fetch_watchpoint_value (b->exp, &new_val, NULL, NULL); | |
2832 | if ((b->val != NULL) != (new_val != NULL) | |
2833 | || (b->val != NULL && !value_equal (b->val, new_val))) | |
c906108c | 2834 | { |
fa4727a6 DJ |
2835 | if (new_val != NULL) |
2836 | { | |
2837 | release_value (new_val); | |
2838 | value_free_to_mark (mark); | |
2839 | } | |
c906108c SS |
2840 | bs->old_val = b->val; |
2841 | b->val = new_val; | |
fa4727a6 | 2842 | b->val_valid = 1; |
c906108c SS |
2843 | /* We will stop here */ |
2844 | return WP_VALUE_CHANGED; | |
2845 | } | |
2846 | else | |
2847 | { | |
2848 | /* Nothing changed, don't do anything. */ | |
2849 | value_free_to_mark (mark); | |
2850 | /* We won't stop here */ | |
2851 | return WP_VALUE_NOT_CHANGED; | |
2852 | } | |
2853 | } | |
2854 | else | |
2855 | { | |
2856 | /* This seems like the only logical thing to do because | |
c5aa993b JM |
2857 | if we temporarily ignored the watchpoint, then when |
2858 | we reenter the block in which it is valid it contains | |
2859 | garbage (in the case of a function, it may have two | |
2860 | garbage values, one before and one after the prologue). | |
2861 | So we can't even detect the first assignment to it and | |
2862 | watch after that (since the garbage may or may not equal | |
2863 | the first value assigned). */ | |
4ce44c66 JM |
2864 | /* We print all the stop information in print_it_typical(), but |
2865 | in this case, by the time we call print_it_typical() this bp | |
2866 | will be deleted already. So we have no choice but print the | |
2867 | information here. */ | |
9dc5e2a9 | 2868 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
2869 | ui_out_field_string |
2870 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
8b93c638 | 2871 | ui_out_text (uiout, "\nWatchpoint "); |
4f8d1dc6 | 2872 | ui_out_field_int (uiout, "wpnum", b->number); |
8b93c638 JM |
2873 | ui_out_text (uiout, " deleted because the program has left the block in\n\ |
2874 | which its expression is valid.\n"); | |
4ce44c66 | 2875 | |
c906108c | 2876 | if (b->related_breakpoint) |
b5de0fa7 EZ |
2877 | b->related_breakpoint->disposition = disp_del_at_next_stop; |
2878 | b->disposition = disp_del_at_next_stop; | |
c906108c SS |
2879 | |
2880 | return WP_DELETED; | |
2881 | } | |
2882 | } | |
2883 | ||
18a18393 VP |
2884 | /* Return true if it looks like target has stopped due to hitting |
2885 | breakpoint location BL. This function does not check if we | |
2886 | should stop, only if BL explains the stop. */ | |
2887 | static int | |
2888 | bpstat_check_location (const struct bp_location *bl, CORE_ADDR bp_addr) | |
2889 | { | |
2890 | struct breakpoint *b = bl->owner; | |
2891 | ||
2892 | if (b->type != bp_watchpoint | |
2893 | && b->type != bp_hardware_watchpoint | |
2894 | && b->type != bp_read_watchpoint | |
2895 | && b->type != bp_access_watchpoint | |
2896 | && b->type != bp_hardware_breakpoint | |
fe798b75 | 2897 | && b->type != bp_catchpoint) /* a non-watchpoint bp */ |
18a18393 VP |
2898 | { |
2899 | if (bl->address != bp_addr) /* address doesn't match */ | |
2900 | return 0; | |
2901 | if (overlay_debugging /* unmapped overlay section */ | |
2902 | && section_is_overlay (bl->section) | |
2903 | && !section_is_mapped (bl->section)) | |
2904 | return 0; | |
2905 | } | |
2906 | ||
2907 | /* Continuable hardware watchpoints are treated as non-existent if the | |
2908 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
2909 | some data address). Otherwise gdb won't stop on a break instruction | |
2910 | in the code (not from a breakpoint) when a hardware watchpoint has | |
2911 | been defined. Also skip watchpoints which we know did not trigger | |
2912 | (did not match the data address). */ | |
2913 | ||
2914 | if ((b->type == bp_hardware_watchpoint | |
2915 | || b->type == bp_read_watchpoint | |
2916 | || b->type == bp_access_watchpoint) | |
2917 | && b->watchpoint_triggered == watch_triggered_no) | |
2918 | return 0; | |
2919 | ||
2920 | if (b->type == bp_hardware_breakpoint) | |
2921 | { | |
2922 | if (bl->address != bp_addr) | |
2923 | return 0; | |
2924 | if (overlay_debugging /* unmapped overlay section */ | |
2925 | && section_is_overlay (bl->section) | |
2926 | && !section_is_mapped (bl->section)) | |
2927 | return 0; | |
2928 | } | |
ce78b96d | 2929 | |
ce78b96d JB |
2930 | if (b->type == bp_catchpoint) |
2931 | { | |
2932 | gdb_assert (b->ops != NULL && b->ops->breakpoint_hit != NULL); | |
2933 | if (!b->ops->breakpoint_hit (b)) | |
2934 | return 0; | |
2935 | } | |
2936 | ||
18a18393 VP |
2937 | return 1; |
2938 | } | |
2939 | ||
2940 | /* If BS refers to a watchpoint, determine if the watched values | |
2941 | has actually changed, and we should stop. If not, set BS->stop | |
2942 | to 0. */ | |
2943 | static void | |
2944 | bpstat_check_watchpoint (bpstat bs) | |
2945 | { | |
2946 | const struct bp_location *bl = bs->breakpoint_at; | |
2947 | struct breakpoint *b = bl->owner; | |
2948 | ||
2949 | if (b->type == bp_watchpoint | |
2950 | || b->type == bp_read_watchpoint | |
2951 | || b->type == bp_access_watchpoint | |
2952 | || b->type == bp_hardware_watchpoint) | |
2953 | { | |
2954 | CORE_ADDR addr; | |
2955 | struct value *v; | |
2956 | int must_check_value = 0; | |
2957 | ||
2958 | if (b->type == bp_watchpoint) | |
2959 | /* For a software watchpoint, we must always check the | |
2960 | watched value. */ | |
2961 | must_check_value = 1; | |
2962 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
2963 | /* We have a hardware watchpoint (read, write, or access) | |
2964 | and the target earlier reported an address watched by | |
2965 | this watchpoint. */ | |
2966 | must_check_value = 1; | |
2967 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
2968 | && b->type == bp_hardware_watchpoint) | |
2969 | /* We were stopped by a hardware watchpoint, but the target could | |
2970 | not report the data address. We must check the watchpoint's | |
2971 | value. Access and read watchpoints are out of luck; without | |
2972 | a data address, we can't figure it out. */ | |
2973 | must_check_value = 1; | |
2974 | ||
2975 | if (must_check_value) | |
2976 | { | |
2977 | char *message = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
2978 | b->number); | |
2979 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
2980 | int e = catch_errors (watchpoint_check, bs, message, | |
2981 | RETURN_MASK_ALL); | |
2982 | do_cleanups (cleanups); | |
2983 | switch (e) | |
2984 | { | |
2985 | case WP_DELETED: | |
2986 | /* We've already printed what needs to be printed. */ | |
2987 | bs->print_it = print_it_done; | |
2988 | /* Stop. */ | |
2989 | break; | |
2990 | case WP_VALUE_CHANGED: | |
2991 | if (b->type == bp_read_watchpoint) | |
2992 | { | |
2993 | /* Don't stop: read watchpoints shouldn't fire if | |
2994 | the value has changed. This is for targets | |
2995 | which cannot set read-only watchpoints. */ | |
2996 | bs->print_it = print_it_noop; | |
2997 | bs->stop = 0; | |
2998 | } | |
2999 | break; | |
3000 | case WP_VALUE_NOT_CHANGED: | |
3001 | if (b->type == bp_hardware_watchpoint | |
3002 | || b->type == bp_watchpoint) | |
3003 | { | |
3004 | /* Don't stop: write watchpoints shouldn't fire if | |
3005 | the value hasn't changed. */ | |
3006 | bs->print_it = print_it_noop; | |
3007 | bs->stop = 0; | |
3008 | } | |
3009 | /* Stop. */ | |
3010 | break; | |
3011 | default: | |
3012 | /* Can't happen. */ | |
3013 | case 0: | |
3014 | /* Error from catch_errors. */ | |
3015 | printf_filtered (_("Watchpoint %d deleted.\n"), b->number); | |
3016 | if (b->related_breakpoint) | |
3017 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
3018 | b->disposition = disp_del_at_next_stop; | |
3019 | /* We've already printed what needs to be printed. */ | |
3020 | bs->print_it = print_it_done; | |
3021 | break; | |
3022 | } | |
3023 | } | |
3024 | else /* must_check_value == 0 */ | |
3025 | { | |
3026 | /* This is a case where some watchpoint(s) triggered, but | |
3027 | not at the address of this watchpoint, or else no | |
3028 | watchpoint triggered after all. So don't print | |
3029 | anything for this watchpoint. */ | |
3030 | bs->print_it = print_it_noop; | |
3031 | bs->stop = 0; | |
3032 | } | |
3033 | } | |
3034 | } | |
3035 | ||
3036 | ||
3037 | /* Check conditions (condition proper, frame, thread and ignore count) | |
3038 | of breakpoint referred to by BS. If we should not stop for this | |
3039 | breakpoint, set BS->stop to 0. */ | |
3040 | static void | |
3041 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
3042 | { | |
3043 | int thread_id = pid_to_thread_id (ptid); | |
3044 | const struct bp_location *bl = bs->breakpoint_at; | |
3045 | struct breakpoint *b = bl->owner; | |
3046 | ||
3047 | if (frame_id_p (b->frame_id) | |
edb3359d | 3048 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 VP |
3049 | bs->stop = 0; |
3050 | else if (bs->stop) | |
3051 | { | |
3052 | int value_is_zero = 0; | |
3053 | ||
3054 | /* If this is a scope breakpoint, mark the associated | |
3055 | watchpoint as triggered so that we will handle the | |
3056 | out-of-scope event. We'll get to the watchpoint next | |
3057 | iteration. */ | |
3058 | if (b->type == bp_watchpoint_scope) | |
3059 | b->related_breakpoint->watchpoint_triggered = watch_triggered_yes; | |
3060 | ||
3061 | if (bl->cond && bl->owner->disposition != disp_del_at_next_stop) | |
3062 | { | |
c5bc3a77 DJ |
3063 | /* We use value_mark and value_free_to_mark because it could |
3064 | be a long time before we return to the command level and | |
3065 | call free_all_values. We can't call free_all_values | |
3066 | because we might be in the middle of evaluating a | |
3067 | function call. */ | |
3068 | struct value *mark = value_mark (); | |
3069 | ||
edb3359d DJ |
3070 | /* Need to select the frame, with all that implies so that |
3071 | the conditions will have the right context. Because we | |
3072 | use the frame, we will not see an inlined function's | |
3073 | variables when we arrive at a breakpoint at the start | |
3074 | of the inlined function; the current frame will be the | |
3075 | call site. */ | |
18a18393 VP |
3076 | select_frame (get_current_frame ()); |
3077 | value_is_zero | |
3078 | = catch_errors (breakpoint_cond_eval, (bl->cond), | |
3079 | "Error in testing breakpoint condition:\n", | |
3080 | RETURN_MASK_ALL); | |
3081 | /* FIXME-someday, should give breakpoint # */ | |
c5bc3a77 | 3082 | value_free_to_mark (mark); |
18a18393 VP |
3083 | } |
3084 | if (bl->cond && value_is_zero) | |
3085 | { | |
3086 | bs->stop = 0; | |
3087 | } | |
3088 | else if (b->thread != -1 && b->thread != thread_id) | |
3089 | { | |
3090 | bs->stop = 0; | |
3091 | } | |
3092 | else if (b->ignore_count > 0) | |
3093 | { | |
3094 | b->ignore_count--; | |
3095 | annotate_ignore_count_change (); | |
3096 | bs->stop = 0; | |
3097 | /* Increase the hit count even though we don't | |
3098 | stop. */ | |
3099 | ++(b->hit_count); | |
3100 | } | |
3101 | } | |
3102 | } | |
3103 | ||
3104 | ||
9709f61c | 3105 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 3106 | BP_ADDR in thread PTID. |
c906108c | 3107 | |
d983da9c | 3108 | Determine whether we stopped at a breakpoint, etc, or whether we |
c906108c SS |
3109 | don't understand this stop. Result is a chain of bpstat's such that: |
3110 | ||
c5aa993b | 3111 | if we don't understand the stop, the result is a null pointer. |
c906108c | 3112 | |
c5aa993b | 3113 | if we understand why we stopped, the result is not null. |
c906108c | 3114 | |
c5aa993b JM |
3115 | Each element of the chain refers to a particular breakpoint or |
3116 | watchpoint at which we have stopped. (We may have stopped for | |
3117 | several reasons concurrently.) | |
c906108c | 3118 | |
c5aa993b JM |
3119 | Each element of the chain has valid next, breakpoint_at, |
3120 | commands, FIXME??? fields. */ | |
c906108c SS |
3121 | |
3122 | bpstat | |
d983da9c | 3123 | bpstat_stop_status (CORE_ADDR bp_addr, ptid_t ptid) |
c906108c | 3124 | { |
0d381245 | 3125 | struct breakpoint *b = NULL; |
89f9893c | 3126 | const struct bp_location *bl; |
20874c92 | 3127 | struct bp_location *loc; |
c906108c SS |
3128 | /* Root of the chain of bpstat's */ |
3129 | struct bpstats root_bs[1]; | |
3130 | /* Pointer to the last thing in the chain currently. */ | |
3131 | bpstat bs = root_bs; | |
20874c92 | 3132 | int ix; |
d832cb68 | 3133 | int need_remove_insert; |
c906108c | 3134 | |
0d381245 | 3135 | ALL_BP_LOCATIONS (bl) |
c5aa993b | 3136 | { |
0d381245 VP |
3137 | b = bl->owner; |
3138 | gdb_assert (b); | |
468d015d | 3139 | if (!breakpoint_enabled (b) && b->enable_state != bp_permanent) |
c5aa993b JM |
3140 | continue; |
3141 | ||
a5606eee VP |
3142 | /* For hardware watchpoints, we look only at the first location. |
3143 | The watchpoint_check function will work on entire expression, | |
3144 | not the individual locations. For read watchopints, the | |
3145 | watchpoints_triggered function have checked all locations | |
3146 | alrea | |
3147 | */ | |
3148 | if (b->type == bp_hardware_watchpoint && bl != b->loc) | |
3149 | continue; | |
3150 | ||
18a18393 VP |
3151 | if (!bpstat_check_location (bl, bp_addr)) |
3152 | continue; | |
3153 | ||
c5aa993b JM |
3154 | /* Come here if it's a watchpoint, or if the break address matches */ |
3155 | ||
0d381245 | 3156 | bs = bpstat_alloc (bl, bs); /* Alloc a bpstat to explain stop */ |
c5aa993b | 3157 | |
18a18393 VP |
3158 | /* Assume we stop. Should we find watchpoint that is not actually |
3159 | triggered, or if condition of breakpoint is false, we'll reset | |
3160 | 'stop' to 0. */ | |
c5aa993b JM |
3161 | bs->stop = 1; |
3162 | bs->print = 1; | |
3163 | ||
18a18393 VP |
3164 | bpstat_check_watchpoint (bs); |
3165 | if (!bs->stop) | |
3166 | continue; | |
c5aa993b | 3167 | |
0fd8e87f UW |
3168 | if (b->type == bp_thread_event || b->type == bp_overlay_event |
3169 | || b->type == bp_longjmp_master) | |
18a18393 | 3170 | /* We do not stop for these. */ |
c5aa993b JM |
3171 | bs->stop = 0; |
3172 | else | |
18a18393 VP |
3173 | bpstat_check_breakpoint_conditions (bs, ptid); |
3174 | ||
3175 | if (bs->stop) | |
c5aa993b | 3176 | { |
18a18393 | 3177 | ++(b->hit_count); |
d983da9c | 3178 | |
18a18393 VP |
3179 | /* We will stop here */ |
3180 | if (b->disposition == disp_disable) | |
c5aa993b | 3181 | { |
514f746b AR |
3182 | if (b->enable_state != bp_permanent) |
3183 | b->enable_state = bp_disabled; | |
b60e7edf | 3184 | update_global_location_list (0); |
c5aa993b | 3185 | } |
18a18393 VP |
3186 | if (b->silent) |
3187 | bs->print = 0; | |
3188 | bs->commands = b->commands; | |
059fb39f PM |
3189 | if (bs->commands |
3190 | && (strcmp ("silent", bs->commands->line) == 0 | |
3191 | || (xdb_commands && strcmp ("Q", bs->commands->line) == 0))) | |
c5aa993b | 3192 | { |
18a18393 VP |
3193 | bs->commands = bs->commands->next; |
3194 | bs->print = 0; | |
c5aa993b | 3195 | } |
18a18393 | 3196 | bs->commands = copy_command_lines (bs->commands); |
c5aa993b | 3197 | } |
18a18393 | 3198 | |
c5aa993b JM |
3199 | /* Print nothing for this entry if we dont stop or if we dont print. */ |
3200 | if (bs->stop == 0 || bs->print == 0) | |
3201 | bs->print_it = print_it_noop; | |
3202 | } | |
c906108c | 3203 | |
20874c92 VP |
3204 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) |
3205 | { | |
3206 | if (loc->address == bp_addr) | |
3207 | { | |
3208 | bs = bpstat_alloc (loc, bs); | |
3209 | /* For hits of moribund locations, we should just proceed. */ | |
3210 | bs->stop = 0; | |
3211 | bs->print = 0; | |
3212 | bs->print_it = print_it_noop; | |
3213 | } | |
3214 | } | |
3215 | ||
c906108c SS |
3216 | bs->next = NULL; /* Terminate the chain */ |
3217 | bs = root_bs->next; /* Re-grab the head of the chain */ | |
3218 | ||
d983da9c DJ |
3219 | /* If we aren't stopping, the value of some hardware watchpoint may |
3220 | not have changed, but the intermediate memory locations we are | |
3221 | watching may have. Don't bother if we're stopping; this will get | |
3222 | done later. */ | |
3223 | for (bs = root_bs->next; bs != NULL; bs = bs->next) | |
3224 | if (bs->stop) | |
3225 | break; | |
3226 | ||
d832cb68 | 3227 | need_remove_insert = 0; |
d983da9c DJ |
3228 | if (bs == NULL) |
3229 | for (bs = root_bs->next; bs != NULL; bs = bs->next) | |
3230 | if (!bs->stop | |
20874c92 | 3231 | && bs->breakpoint_at->owner |
d983da9c DJ |
3232 | && (bs->breakpoint_at->owner->type == bp_hardware_watchpoint |
3233 | || bs->breakpoint_at->owner->type == bp_read_watchpoint | |
3234 | || bs->breakpoint_at->owner->type == bp_access_watchpoint)) | |
3235 | { | |
a5606eee VP |
3236 | /* remove/insert can invalidate bs->breakpoint_at, if this |
3237 | location is no longer used by the watchpoint. Prevent | |
3238 | further code from trying to use it. */ | |
3239 | bs->breakpoint_at = NULL; | |
d832cb68 | 3240 | need_remove_insert = 1; |
d983da9c DJ |
3241 | } |
3242 | ||
d832cb68 DD |
3243 | if (need_remove_insert) |
3244 | { | |
3245 | remove_breakpoints (); | |
3246 | insert_breakpoints (); | |
3247 | } | |
3248 | ||
d983da9c | 3249 | return root_bs->next; |
c906108c SS |
3250 | } |
3251 | \f | |
3252 | /* Tell what to do about this bpstat. */ | |
3253 | struct bpstat_what | |
fba45db2 | 3254 | bpstat_what (bpstat bs) |
c906108c SS |
3255 | { |
3256 | /* Classify each bpstat as one of the following. */ | |
c5aa993b JM |
3257 | enum class |
3258 | { | |
3259 | /* This bpstat element has no effect on the main_action. */ | |
3260 | no_effect = 0, | |
3261 | ||
3262 | /* There was a watchpoint, stop but don't print. */ | |
3263 | wp_silent, | |
c906108c | 3264 | |
c5aa993b JM |
3265 | /* There was a watchpoint, stop and print. */ |
3266 | wp_noisy, | |
c906108c | 3267 | |
c5aa993b JM |
3268 | /* There was a breakpoint but we're not stopping. */ |
3269 | bp_nostop, | |
c906108c | 3270 | |
c5aa993b JM |
3271 | /* There was a breakpoint, stop but don't print. */ |
3272 | bp_silent, | |
c906108c | 3273 | |
c5aa993b JM |
3274 | /* There was a breakpoint, stop and print. */ |
3275 | bp_noisy, | |
c906108c | 3276 | |
c5aa993b JM |
3277 | /* We hit the longjmp breakpoint. */ |
3278 | long_jump, | |
c906108c | 3279 | |
c5aa993b JM |
3280 | /* We hit the longjmp_resume breakpoint. */ |
3281 | long_resume, | |
c906108c | 3282 | |
c5aa993b JM |
3283 | /* We hit the step_resume breakpoint. */ |
3284 | step_resume, | |
c906108c | 3285 | |
c5aa993b JM |
3286 | /* We hit the shared library event breakpoint. */ |
3287 | shlib_event, | |
c906108c | 3288 | |
c5aa993b JM |
3289 | /* This is just used to count how many enums there are. */ |
3290 | class_last | |
c906108c SS |
3291 | }; |
3292 | ||
3293 | /* Here is the table which drives this routine. So that we can | |
3294 | format it pretty, we define some abbreviations for the | |
3295 | enum bpstat_what codes. */ | |
3296 | #define kc BPSTAT_WHAT_KEEP_CHECKING | |
3297 | #define ss BPSTAT_WHAT_STOP_SILENT | |
3298 | #define sn BPSTAT_WHAT_STOP_NOISY | |
3299 | #define sgl BPSTAT_WHAT_SINGLE | |
3300 | #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME | |
3301 | #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME | |
c906108c | 3302 | #define sr BPSTAT_WHAT_STEP_RESUME |
c906108c | 3303 | #define shl BPSTAT_WHAT_CHECK_SHLIBS |
c906108c SS |
3304 | |
3305 | /* "Can't happen." Might want to print an error message. | |
3306 | abort() is not out of the question, but chances are GDB is just | |
3307 | a bit confused, not unusable. */ | |
3308 | #define err BPSTAT_WHAT_STOP_NOISY | |
3309 | ||
3310 | /* Given an old action and a class, come up with a new action. */ | |
3311 | /* One interesting property of this table is that wp_silent is the same | |
3312 | as bp_silent and wp_noisy is the same as bp_noisy. That is because | |
3313 | after stopping, the check for whether to step over a breakpoint | |
3314 | (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without | |
53a5351d JM |
3315 | reference to how we stopped. We retain separate wp_silent and |
3316 | bp_silent codes in case we want to change that someday. | |
43ff13b4 JM |
3317 | |
3318 | Another possibly interesting property of this table is that | |
3319 | there's a partial ordering, priority-like, of the actions. Once | |
3320 | you've decided that some action is appropriate, you'll never go | |
3321 | back and decide something of a lower priority is better. The | |
3322 | ordering is: | |
3323 | ||
d81191fc JB |
3324 | kc < clr sgl shl slr sn sr ss |
3325 | sgl < shl slr sn sr ss | |
3326 | slr < err shl sn sr ss | |
3327 | clr < err shl sn sr ss | |
3328 | ss < shl sn sr | |
3329 | sn < shl sr | |
3330 | shl < sr | |
4d5b2cd7 | 3331 | sr < |
c5aa993b | 3332 | |
43ff13b4 JM |
3333 | What I think this means is that we don't need a damned table |
3334 | here. If you just put the rows and columns in the right order, | |
3335 | it'd look awfully regular. We could simply walk the bpstat list | |
3336 | and choose the highest priority action we find, with a little | |
78b6a731 | 3337 | logic to handle the 'err' cases. */ |
c906108c SS |
3338 | |
3339 | /* step_resume entries: a step resume breakpoint overrides another | |
3340 | breakpoint of signal handling (see comment in wait_for_inferior | |
fcf70625 | 3341 | at where we set the step_resume breakpoint). */ |
c906108c SS |
3342 | |
3343 | static const enum bpstat_what_main_action | |
c5aa993b JM |
3344 | table[(int) class_last][(int) BPSTAT_WHAT_LAST] = |
3345 | { | |
3346 | /* old action */ | |
d81191fc | 3347 | /* kc ss sn sgl slr clr sr shl |
c5aa993b JM |
3348 | */ |
3349 | /*no_effect */ | |
d81191fc | 3350 | {kc, ss, sn, sgl, slr, clr, sr, shl}, |
c5aa993b | 3351 | /*wp_silent */ |
d81191fc | 3352 | {ss, ss, sn, ss, ss, ss, sr, shl}, |
c5aa993b | 3353 | /*wp_noisy */ |
d81191fc | 3354 | {sn, sn, sn, sn, sn, sn, sr, shl}, |
c5aa993b | 3355 | /*bp_nostop */ |
d81191fc | 3356 | {sgl, ss, sn, sgl, slr, slr, sr, shl}, |
c5aa993b | 3357 | /*bp_silent */ |
d81191fc | 3358 | {ss, ss, sn, ss, ss, ss, sr, shl}, |
c5aa993b | 3359 | /*bp_noisy */ |
d81191fc | 3360 | {sn, sn, sn, sn, sn, sn, sr, shl}, |
c5aa993b | 3361 | /*long_jump */ |
d81191fc | 3362 | {slr, ss, sn, slr, slr, err, sr, shl}, |
c5aa993b | 3363 | /*long_resume */ |
d81191fc | 3364 | {clr, ss, sn, err, err, err, sr, shl}, |
c5aa993b | 3365 | /*step_resume */ |
d81191fc | 3366 | {sr, sr, sr, sr, sr, sr, sr, sr}, |
c5aa993b | 3367 | /*shlib */ |
d81191fc | 3368 | {shl, shl, shl, shl, shl, shl, sr, shl} |
c5aa993b | 3369 | }; |
c906108c SS |
3370 | |
3371 | #undef kc | |
3372 | #undef ss | |
3373 | #undef sn | |
3374 | #undef sgl | |
3375 | #undef slr | |
3376 | #undef clr | |
c906108c SS |
3377 | #undef err |
3378 | #undef sr | |
3379 | #undef ts | |
3380 | #undef shl | |
c906108c SS |
3381 | enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING; |
3382 | struct bpstat_what retval; | |
3383 | ||
3384 | retval.call_dummy = 0; | |
3385 | for (; bs != NULL; bs = bs->next) | |
3386 | { | |
3387 | enum class bs_class = no_effect; | |
3388 | if (bs->breakpoint_at == NULL) | |
3389 | /* I suspect this can happen if it was a momentary breakpoint | |
3390 | which has since been deleted. */ | |
3391 | continue; | |
20874c92 VP |
3392 | if (bs->breakpoint_at->owner == NULL) |
3393 | bs_class = bp_nostop; | |
3394 | else | |
4f8d1dc6 | 3395 | switch (bs->breakpoint_at->owner->type) |
c906108c SS |
3396 | { |
3397 | case bp_none: | |
3398 | continue; | |
3399 | ||
3400 | case bp_breakpoint: | |
3401 | case bp_hardware_breakpoint: | |
3402 | case bp_until: | |
3403 | case bp_finish: | |
3404 | if (bs->stop) | |
3405 | { | |
3406 | if (bs->print) | |
3407 | bs_class = bp_noisy; | |
3408 | else | |
3409 | bs_class = bp_silent; | |
3410 | } | |
3411 | else | |
3412 | bs_class = bp_nostop; | |
3413 | break; | |
3414 | case bp_watchpoint: | |
3415 | case bp_hardware_watchpoint: | |
3416 | case bp_read_watchpoint: | |
3417 | case bp_access_watchpoint: | |
3418 | if (bs->stop) | |
3419 | { | |
3420 | if (bs->print) | |
3421 | bs_class = wp_noisy; | |
3422 | else | |
3423 | bs_class = wp_silent; | |
3424 | } | |
3425 | else | |
53a5351d JM |
3426 | /* There was a watchpoint, but we're not stopping. |
3427 | This requires no further action. */ | |
c906108c SS |
3428 | bs_class = no_effect; |
3429 | break; | |
3430 | case bp_longjmp: | |
3431 | bs_class = long_jump; | |
3432 | break; | |
3433 | case bp_longjmp_resume: | |
3434 | bs_class = long_resume; | |
3435 | break; | |
3436 | case bp_step_resume: | |
3437 | if (bs->stop) | |
3438 | { | |
3439 | bs_class = step_resume; | |
3440 | } | |
3441 | else | |
3442 | /* It is for the wrong frame. */ | |
3443 | bs_class = bp_nostop; | |
3444 | break; | |
c906108c SS |
3445 | case bp_watchpoint_scope: |
3446 | bs_class = bp_nostop; | |
3447 | break; | |
c5aa993b JM |
3448 | case bp_shlib_event: |
3449 | bs_class = shlib_event; | |
3450 | break; | |
c4093a6a | 3451 | case bp_thread_event: |
1900040c | 3452 | case bp_overlay_event: |
0fd8e87f | 3453 | case bp_longjmp_master: |
c4093a6a JM |
3454 | bs_class = bp_nostop; |
3455 | break; | |
ce78b96d | 3456 | case bp_catchpoint: |
c5aa993b JM |
3457 | if (bs->stop) |
3458 | { | |
3459 | if (bs->print) | |
3460 | bs_class = bp_noisy; | |
3461 | else | |
3462 | bs_class = bp_silent; | |
3463 | } | |
3464 | else | |
53a5351d JM |
3465 | /* There was a catchpoint, but we're not stopping. |
3466 | This requires no further action. */ | |
c5aa993b JM |
3467 | bs_class = no_effect; |
3468 | break; | |
c906108c | 3469 | case bp_call_dummy: |
53a5351d JM |
3470 | /* Make sure the action is stop (silent or noisy), |
3471 | so infrun.c pops the dummy frame. */ | |
c906108c SS |
3472 | bs_class = bp_silent; |
3473 | retval.call_dummy = 1; | |
3474 | break; | |
1042e4c0 SS |
3475 | case bp_tracepoint: |
3476 | /* Tracepoint hits should not be reported back to GDB, and | |
3477 | if one got through somehow, it should have been filtered | |
3478 | out already. */ | |
3479 | internal_error (__FILE__, __LINE__, | |
3480 | _("bpstat_what: bp_tracepoint encountered")); | |
3481 | break; | |
c906108c | 3482 | } |
c5aa993b | 3483 | current_action = table[(int) bs_class][(int) current_action]; |
c906108c SS |
3484 | } |
3485 | retval.main_action = current_action; | |
3486 | return retval; | |
3487 | } | |
3488 | ||
3489 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
3490 | without hardware support). This isn't related to a specific bpstat, | |
3491 | just to things like whether watchpoints are set. */ | |
3492 | ||
c5aa993b | 3493 | int |
fba45db2 | 3494 | bpstat_should_step (void) |
c906108c SS |
3495 | { |
3496 | struct breakpoint *b; | |
3497 | ALL_BREAKPOINTS (b) | |
717a8278 | 3498 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 3499 | return 1; |
c906108c SS |
3500 | return 0; |
3501 | } | |
3502 | ||
c906108c | 3503 | \f |
c5aa993b | 3504 | |
0d381245 VP |
3505 | static void print_breakpoint_location (struct breakpoint *b, |
3506 | struct bp_location *loc, | |
3507 | char *wrap_indent, | |
3508 | struct ui_stream *stb) | |
3509 | { | |
3510 | if (b->source_file) | |
3511 | { | |
3512 | struct symbol *sym | |
3513 | = find_pc_sect_function (loc->address, loc->section); | |
3514 | if (sym) | |
3515 | { | |
3516 | ui_out_text (uiout, "in "); | |
3517 | ui_out_field_string (uiout, "func", | |
3518 | SYMBOL_PRINT_NAME (sym)); | |
3519 | ui_out_wrap_hint (uiout, wrap_indent); | |
3520 | ui_out_text (uiout, " at "); | |
3521 | } | |
3522 | ui_out_field_string (uiout, "file", b->source_file); | |
3523 | ui_out_text (uiout, ":"); | |
3524 | ||
3525 | if (ui_out_is_mi_like_p (uiout)) | |
3526 | { | |
3527 | struct symtab_and_line sal = find_pc_line (loc->address, 0); | |
3528 | char *fullname = symtab_to_fullname (sal.symtab); | |
3529 | ||
3530 | if (fullname) | |
3531 | ui_out_field_string (uiout, "fullname", fullname); | |
3532 | } | |
3533 | ||
3534 | ui_out_field_int (uiout, "line", b->line_number); | |
3535 | } | |
3536 | else if (!b->loc) | |
3537 | { | |
3538 | ui_out_field_string (uiout, "pending", b->addr_string); | |
3539 | } | |
3540 | else | |
3541 | { | |
3542 | print_address_symbolic (loc->address, stb->stream, demangle, ""); | |
3543 | ui_out_field_stream (uiout, "at", stb); | |
3544 | } | |
3545 | } | |
3546 | ||
c4093a6a | 3547 | /* Print B to gdb_stdout. */ |
c906108c | 3548 | static void |
0d381245 VP |
3549 | print_one_breakpoint_location (struct breakpoint *b, |
3550 | struct bp_location *loc, | |
3551 | int loc_number, | |
a6d9a66e UW |
3552 | struct bp_location **last_loc, |
3553 | int print_address_bits) | |
c906108c | 3554 | { |
52f0bd74 AC |
3555 | struct command_line *l; |
3556 | struct symbol *sym; | |
c4093a6a JM |
3557 | struct ep_type_description |
3558 | { | |
3559 | enum bptype type; | |
3560 | char *description; | |
3561 | }; | |
3562 | static struct ep_type_description bptypes[] = | |
c906108c | 3563 | { |
c5aa993b JM |
3564 | {bp_none, "?deleted?"}, |
3565 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 3566 | {bp_hardware_breakpoint, "hw breakpoint"}, |
c5aa993b JM |
3567 | {bp_until, "until"}, |
3568 | {bp_finish, "finish"}, | |
3569 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 3570 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
3571 | {bp_read_watchpoint, "read watchpoint"}, |
3572 | {bp_access_watchpoint, "acc watchpoint"}, | |
3573 | {bp_longjmp, "longjmp"}, | |
3574 | {bp_longjmp_resume, "longjmp resume"}, | |
3575 | {bp_step_resume, "step resume"}, | |
c5aa993b JM |
3576 | {bp_watchpoint_scope, "watchpoint scope"}, |
3577 | {bp_call_dummy, "call dummy"}, | |
3578 | {bp_shlib_event, "shlib events"}, | |
c4093a6a | 3579 | {bp_thread_event, "thread events"}, |
1900040c | 3580 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 3581 | {bp_longjmp_master, "longjmp master"}, |
ce78b96d | 3582 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 3583 | {bp_tracepoint, "tracepoint"}, |
c5aa993b | 3584 | }; |
c4093a6a | 3585 | |
c2c6d25f | 3586 | static char bpenables[] = "nynny"; |
c906108c | 3587 | char wrap_indent[80]; |
8b93c638 JM |
3588 | struct ui_stream *stb = ui_out_stream_new (uiout); |
3589 | struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb); | |
3b31d625 | 3590 | struct cleanup *bkpt_chain; |
c906108c | 3591 | |
0d381245 VP |
3592 | int header_of_multiple = 0; |
3593 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
3594 | struct value_print_options opts; |
3595 | ||
3596 | get_user_print_options (&opts); | |
0d381245 VP |
3597 | |
3598 | gdb_assert (!loc || loc_number != 0); | |
3599 | /* See comment in print_one_breakpoint concerning | |
3600 | treatment of breakpoints with single disabled | |
3601 | location. */ | |
3602 | if (loc == NULL | |
3603 | && (b->loc != NULL | |
3604 | && (b->loc->next != NULL || !b->loc->enabled))) | |
3605 | header_of_multiple = 1; | |
3606 | if (loc == NULL) | |
3607 | loc = b->loc; | |
3608 | ||
c4093a6a | 3609 | annotate_record (); |
3b31d625 | 3610 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); |
c4093a6a JM |
3611 | |
3612 | /* 1 */ | |
3613 | annotate_field (0); | |
0d381245 VP |
3614 | if (part_of_multiple) |
3615 | { | |
3616 | char *formatted; | |
0c6773c1 | 3617 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
0d381245 VP |
3618 | ui_out_field_string (uiout, "number", formatted); |
3619 | xfree (formatted); | |
3620 | } | |
3621 | else | |
3622 | { | |
3623 | ui_out_field_int (uiout, "number", b->number); | |
3624 | } | |
c4093a6a JM |
3625 | |
3626 | /* 2 */ | |
3627 | annotate_field (1); | |
0d381245 VP |
3628 | if (part_of_multiple) |
3629 | ui_out_field_skip (uiout, "type"); | |
3630 | else | |
3631 | { | |
3632 | if (((int) b->type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
3633 | || ((int) b->type != bptypes[(int) b->type].type)) | |
3634 | internal_error (__FILE__, __LINE__, | |
3635 | _("bptypes table does not describe type #%d."), | |
3636 | (int) b->type); | |
3637 | ui_out_field_string (uiout, "type", bptypes[(int) b->type].description); | |
3638 | } | |
c4093a6a JM |
3639 | |
3640 | /* 3 */ | |
3641 | annotate_field (2); | |
0d381245 VP |
3642 | if (part_of_multiple) |
3643 | ui_out_field_skip (uiout, "disp"); | |
3644 | else | |
2cec12e5 | 3645 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
0d381245 | 3646 | |
c4093a6a JM |
3647 | |
3648 | /* 4 */ | |
3649 | annotate_field (3); | |
0d381245 | 3650 | if (part_of_multiple) |
54e52265 | 3651 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
0d381245 | 3652 | else |
54e52265 VP |
3653 | ui_out_field_fmt (uiout, "enabled", "%c", |
3654 | bpenables[(int) b->enable_state]); | |
3655 | ui_out_spaces (uiout, 2); | |
0d381245 | 3656 | |
c4093a6a JM |
3657 | |
3658 | /* 5 and 6 */ | |
3659 | strcpy (wrap_indent, " "); | |
79a45b7d | 3660 | if (opts.addressprint) |
75ac9d7b | 3661 | { |
a6d9a66e | 3662 | if (print_address_bits <= 32) |
75ac9d7b MS |
3663 | strcat (wrap_indent, " "); |
3664 | else | |
3665 | strcat (wrap_indent, " "); | |
3666 | } | |
c906108c | 3667 | |
3086aeae | 3668 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 VP |
3669 | { |
3670 | /* Although the print_one can possibly print | |
3671 | all locations, calling it here is not likely | |
3672 | to get any nice result. So, make sure there's | |
3673 | just one location. */ | |
3674 | gdb_assert (b->loc == NULL || b->loc->next == NULL); | |
a6d9a66e | 3675 | b->ops->print_one (b, last_loc); |
0d381245 | 3676 | } |
3086aeae DJ |
3677 | else |
3678 | switch (b->type) | |
3679 | { | |
3680 | case bp_none: | |
3681 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 3682 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 3683 | break; |
c906108c | 3684 | |
3086aeae DJ |
3685 | case bp_watchpoint: |
3686 | case bp_hardware_watchpoint: | |
3687 | case bp_read_watchpoint: | |
3688 | case bp_access_watchpoint: | |
3689 | /* Field 4, the address, is omitted (which makes the columns | |
3690 | not line up too nicely with the headers, but the effect | |
3691 | is relatively readable). */ | |
79a45b7d | 3692 | if (opts.addressprint) |
3086aeae DJ |
3693 | ui_out_field_skip (uiout, "addr"); |
3694 | annotate_field (5); | |
fa8a61dc | 3695 | ui_out_field_string (uiout, "what", b->exp_string); |
3086aeae DJ |
3696 | break; |
3697 | ||
3086aeae DJ |
3698 | case bp_breakpoint: |
3699 | case bp_hardware_breakpoint: | |
3700 | case bp_until: | |
3701 | case bp_finish: | |
3702 | case bp_longjmp: | |
3703 | case bp_longjmp_resume: | |
3704 | case bp_step_resume: | |
3086aeae DJ |
3705 | case bp_watchpoint_scope: |
3706 | case bp_call_dummy: | |
3707 | case bp_shlib_event: | |
3708 | case bp_thread_event: | |
3709 | case bp_overlay_event: | |
0fd8e87f | 3710 | case bp_longjmp_master: |
1042e4c0 | 3711 | case bp_tracepoint: |
79a45b7d | 3712 | if (opts.addressprint) |
3086aeae DJ |
3713 | { |
3714 | annotate_field (4); | |
54e52265 | 3715 | if (header_of_multiple) |
0d381245 | 3716 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
e9bbd7c5 | 3717 | else if (b->loc == NULL || loc->shlib_disabled) |
54e52265 | 3718 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
0101ce28 | 3719 | else |
5af949e3 UW |
3720 | ui_out_field_core_addr (uiout, "addr", |
3721 | loc->gdbarch, loc->address); | |
3086aeae DJ |
3722 | } |
3723 | annotate_field (5); | |
0d381245 VP |
3724 | if (!header_of_multiple) |
3725 | print_breakpoint_location (b, loc, wrap_indent, stb); | |
3726 | if (b->loc) | |
a6d9a66e | 3727 | *last_loc = b->loc; |
3086aeae DJ |
3728 | break; |
3729 | } | |
c906108c | 3730 | |
4a306c9a | 3731 | if (!part_of_multiple) |
c4093a6a | 3732 | { |
4a306c9a JB |
3733 | if (b->thread != -1) |
3734 | { | |
3735 | /* FIXME: This seems to be redundant and lost here; see the | |
3736 | "stop only in" line a little further down. */ | |
3737 | ui_out_text (uiout, " thread "); | |
3738 | ui_out_field_int (uiout, "thread", b->thread); | |
3739 | } | |
3740 | else if (b->task != 0) | |
3741 | { | |
3742 | ui_out_text (uiout, " task "); | |
3743 | ui_out_field_int (uiout, "task", b->task); | |
3744 | } | |
c4093a6a JM |
3745 | } |
3746 | ||
8b93c638 | 3747 | ui_out_text (uiout, "\n"); |
c4093a6a | 3748 | |
0d381245 | 3749 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
3750 | { |
3751 | annotate_field (6); | |
8b93c638 | 3752 | ui_out_text (uiout, "\tstop only in stack frame at "); |
818dd999 AC |
3753 | /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside |
3754 | the frame ID. */ | |
5af949e3 UW |
3755 | ui_out_field_core_addr (uiout, "frame", |
3756 | b->gdbarch, b->frame_id.stack_addr); | |
8b93c638 | 3757 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
3758 | } |
3759 | ||
0d381245 | 3760 | if (!part_of_multiple && b->cond_string && !ada_exception_catchpoint_p (b)) |
c4093a6a | 3761 | { |
f7f9143b JB |
3762 | /* We do not print the condition for Ada exception catchpoints |
3763 | because the condition is an internal implementation detail | |
3764 | that we do not want to expose to the user. */ | |
c4093a6a | 3765 | annotate_field (7); |
1042e4c0 SS |
3766 | if (b->type == bp_tracepoint) |
3767 | ui_out_text (uiout, "\ttrace only if "); | |
3768 | else | |
3769 | ui_out_text (uiout, "\tstop only if "); | |
0101ce28 JJ |
3770 | ui_out_field_string (uiout, "cond", b->cond_string); |
3771 | ui_out_text (uiout, "\n"); | |
3772 | } | |
3773 | ||
0d381245 | 3774 | if (!part_of_multiple && b->thread != -1) |
c4093a6a JM |
3775 | { |
3776 | /* FIXME should make an annotation for this */ | |
8b93c638 JM |
3777 | ui_out_text (uiout, "\tstop only in thread "); |
3778 | ui_out_field_int (uiout, "thread", b->thread); | |
3779 | ui_out_text (uiout, "\n"); | |
c4093a6a JM |
3780 | } |
3781 | ||
63c715c6 | 3782 | if (!part_of_multiple && b->hit_count) |
c4093a6a JM |
3783 | { |
3784 | /* FIXME should make an annotation for this */ | |
8b93c638 JM |
3785 | if (ep_is_catchpoint (b)) |
3786 | ui_out_text (uiout, "\tcatchpoint"); | |
3787 | else | |
3788 | ui_out_text (uiout, "\tbreakpoint"); | |
3789 | ui_out_text (uiout, " already hit "); | |
3790 | ui_out_field_int (uiout, "times", b->hit_count); | |
3791 | if (b->hit_count == 1) | |
3792 | ui_out_text (uiout, " time\n"); | |
3793 | else | |
3794 | ui_out_text (uiout, " times\n"); | |
c4093a6a JM |
3795 | } |
3796 | ||
fb40c209 AC |
3797 | /* Output the count also if it is zero, but only if this is |
3798 | mi. FIXME: Should have a better test for this. */ | |
9dc5e2a9 | 3799 | if (ui_out_is_mi_like_p (uiout)) |
63c715c6 | 3800 | if (!part_of_multiple && b->hit_count == 0) |
fb40c209 | 3801 | ui_out_field_int (uiout, "times", b->hit_count); |
8b93c638 | 3802 | |
0d381245 | 3803 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
3804 | { |
3805 | annotate_field (8); | |
8b93c638 JM |
3806 | ui_out_text (uiout, "\tignore next "); |
3807 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
3808 | ui_out_text (uiout, " hits\n"); | |
c4093a6a | 3809 | } |
059fb39f PM |
3810 | |
3811 | l = b->commands; | |
3812 | if (!part_of_multiple && l) | |
c4093a6a | 3813 | { |
3b31d625 EZ |
3814 | struct cleanup *script_chain; |
3815 | ||
c4093a6a | 3816 | annotate_field (9); |
3b31d625 | 3817 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 3818 | print_command_lines (uiout, l, 4); |
3b31d625 | 3819 | do_cleanups (script_chain); |
c4093a6a | 3820 | } |
d24317b4 | 3821 | |
1042e4c0 SS |
3822 | if (!part_of_multiple && b->pass_count) |
3823 | { | |
3824 | annotate_field (10); | |
3825 | ui_out_text (uiout, "\tpass count "); | |
3826 | ui_out_field_int (uiout, "pass", b->pass_count); | |
3827 | ui_out_text (uiout, " \n"); | |
3828 | } | |
3829 | ||
3830 | if (!part_of_multiple && b->step_count) | |
3831 | { | |
3832 | annotate_field (11); | |
3833 | ui_out_text (uiout, "\tstep count "); | |
3834 | ui_out_field_int (uiout, "step", b->step_count); | |
3835 | ui_out_text (uiout, " \n"); | |
3836 | } | |
3837 | ||
3838 | if (!part_of_multiple && b->actions) | |
3839 | { | |
3840 | struct action_line *action; | |
3841 | annotate_field (12); | |
3842 | for (action = b->actions; action; action = action->next) | |
3843 | { | |
3844 | ui_out_text (uiout, " A\t"); | |
3845 | ui_out_text (uiout, action->action); | |
3846 | ui_out_text (uiout, "\n"); | |
3847 | } | |
3848 | } | |
3849 | ||
d24317b4 VP |
3850 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
3851 | { | |
3852 | if (b->addr_string) | |
3853 | ui_out_field_string (uiout, "original-location", b->addr_string); | |
3854 | else if (b->exp_string) | |
3855 | ui_out_field_string (uiout, "original-location", b->exp_string); | |
3856 | } | |
3857 | ||
3b31d625 | 3858 | do_cleanups (bkpt_chain); |
8b93c638 | 3859 | do_cleanups (old_chain); |
c4093a6a | 3860 | } |
c5aa993b | 3861 | |
0d381245 VP |
3862 | static void |
3863 | print_one_breakpoint (struct breakpoint *b, | |
a6d9a66e | 3864 | struct bp_location **last_loc, int print_address_bits) |
0d381245 | 3865 | { |
a6d9a66e | 3866 | print_one_breakpoint_location (b, NULL, 0, last_loc, print_address_bits); |
0d381245 VP |
3867 | |
3868 | /* If this breakpoint has custom print function, | |
3869 | it's already printed. Otherwise, print individual | |
3870 | locations, if any. */ | |
3871 | if (b->ops == NULL || b->ops->print_one == NULL) | |
3872 | { | |
3873 | /* If breakpoint has a single location that is | |
3874 | disabled, we print it as if it had | |
3875 | several locations, since otherwise it's hard to | |
3876 | represent "breakpoint enabled, location disabled" | |
a5606eee VP |
3877 | situation. |
3878 | Note that while hardware watchpoints have | |
3879 | several locations internally, that's no a property | |
3880 | exposed to user. */ | |
0d381245 | 3881 | if (b->loc |
a5606eee | 3882 | && !is_hardware_watchpoint (b) |
0d381245 | 3883 | && (b->loc->next || !b->loc->enabled) |
a5606eee | 3884 | && !ui_out_is_mi_like_p (uiout)) |
0d381245 VP |
3885 | { |
3886 | struct bp_location *loc; | |
3887 | int n = 1; | |
3888 | for (loc = b->loc; loc; loc = loc->next, ++n) | |
a6d9a66e UW |
3889 | print_one_breakpoint_location (b, loc, n, last_loc, |
3890 | print_address_bits); | |
0d381245 VP |
3891 | } |
3892 | } | |
3893 | } | |
3894 | ||
a6d9a66e UW |
3895 | static int |
3896 | breakpoint_address_bits (struct breakpoint *b) | |
3897 | { | |
3898 | int print_address_bits = 0; | |
3899 | struct bp_location *loc; | |
3900 | ||
3901 | for (loc = b->loc; loc; loc = loc->next) | |
3902 | { | |
3903 | int addr_bit = gdbarch_addr_bit (b->gdbarch); | |
3904 | if (addr_bit > print_address_bits) | |
3905 | print_address_bits = addr_bit; | |
3906 | } | |
3907 | ||
3908 | return print_address_bits; | |
3909 | } | |
0d381245 | 3910 | |
c4093a6a JM |
3911 | struct captured_breakpoint_query_args |
3912 | { | |
3913 | int bnum; | |
3914 | }; | |
c5aa993b | 3915 | |
c4093a6a | 3916 | static int |
2b65245e | 3917 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a JM |
3918 | { |
3919 | struct captured_breakpoint_query_args *args = data; | |
52f0bd74 | 3920 | struct breakpoint *b; |
a6d9a66e | 3921 | struct bp_location *dummy_loc = NULL; |
c4093a6a JM |
3922 | ALL_BREAKPOINTS (b) |
3923 | { | |
3924 | if (args->bnum == b->number) | |
c5aa993b | 3925 | { |
a6d9a66e UW |
3926 | int print_address_bits = breakpoint_address_bits (b); |
3927 | print_one_breakpoint (b, &dummy_loc, print_address_bits); | |
c4093a6a | 3928 | return GDB_RC_OK; |
c5aa993b | 3929 | } |
c4093a6a JM |
3930 | } |
3931 | return GDB_RC_NONE; | |
3932 | } | |
c5aa993b | 3933 | |
c4093a6a | 3934 | enum gdb_rc |
ce43223b | 3935 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, char **error_message) |
c4093a6a JM |
3936 | { |
3937 | struct captured_breakpoint_query_args args; | |
3938 | args.bnum = bnum; | |
3939 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
3940 | an error. */ | |
b0b13bb4 DJ |
3941 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
3942 | error_message, RETURN_MASK_ALL) < 0) | |
3943 | return GDB_RC_FAIL; | |
3944 | else | |
3945 | return GDB_RC_OK; | |
c4093a6a | 3946 | } |
c5aa993b | 3947 | |
7f3b0473 AC |
3948 | /* Return non-zero if B is user settable (breakpoints, watchpoints, |
3949 | catchpoints, et.al.). */ | |
3950 | ||
3951 | static int | |
3952 | user_settable_breakpoint (const struct breakpoint *b) | |
3953 | { | |
3954 | return (b->type == bp_breakpoint | |
ce78b96d | 3955 | || b->type == bp_catchpoint |
7f3b0473 | 3956 | || b->type == bp_hardware_breakpoint |
1042e4c0 | 3957 | || b->type == bp_tracepoint |
7f3b0473 AC |
3958 | || b->type == bp_watchpoint |
3959 | || b->type == bp_read_watchpoint | |
3960 | || b->type == bp_access_watchpoint | |
3961 | || b->type == bp_hardware_watchpoint); | |
3962 | } | |
3963 | ||
3964 | /* Print information on user settable breakpoint (watchpoint, etc) | |
3965 | number BNUM. If BNUM is -1 print all user settable breakpoints. | |
3966 | If ALLFLAG is non-zero, include non- user settable breakpoints. */ | |
c906108c | 3967 | |
c4093a6a | 3968 | static void |
fba45db2 | 3969 | breakpoint_1 (int bnum, int allflag) |
c4093a6a | 3970 | { |
52f0bd74 | 3971 | struct breakpoint *b; |
a6d9a66e | 3972 | struct bp_location *last_loc = NULL; |
7f3b0473 | 3973 | int nr_printable_breakpoints; |
3b31d625 | 3974 | struct cleanup *bkpttbl_chain; |
79a45b7d | 3975 | struct value_print_options opts; |
a6d9a66e | 3976 | int print_address_bits = 0; |
c4093a6a | 3977 | |
79a45b7d TT |
3978 | get_user_print_options (&opts); |
3979 | ||
a6d9a66e UW |
3980 | /* Compute the number of rows in the table, as well as the |
3981 | size required for address fields. */ | |
7f3b0473 AC |
3982 | nr_printable_breakpoints = 0; |
3983 | ALL_BREAKPOINTS (b) | |
3984 | if (bnum == -1 | |
3985 | || bnum == b->number) | |
3986 | { | |
3987 | if (allflag || user_settable_breakpoint (b)) | |
a6d9a66e UW |
3988 | { |
3989 | int addr_bit = breakpoint_address_bits (b); | |
3990 | if (addr_bit > print_address_bits) | |
3991 | print_address_bits = addr_bit; | |
3992 | ||
3993 | nr_printable_breakpoints++; | |
3994 | } | |
7f3b0473 AC |
3995 | } |
3996 | ||
79a45b7d | 3997 | if (opts.addressprint) |
3b31d625 EZ |
3998 | bkpttbl_chain |
3999 | = make_cleanup_ui_out_table_begin_end (uiout, 6, nr_printable_breakpoints, | |
4000 | "BreakpointTable"); | |
8b93c638 | 4001 | else |
3b31d625 EZ |
4002 | bkpttbl_chain |
4003 | = make_cleanup_ui_out_table_begin_end (uiout, 5, nr_printable_breakpoints, | |
4004 | "BreakpointTable"); | |
8b93c638 | 4005 | |
7f3b0473 | 4006 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
4007 | annotate_breakpoints_headers (); |
4008 | if (nr_printable_breakpoints > 0) | |
4009 | annotate_field (0); | |
0d381245 | 4010 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
4011 | if (nr_printable_breakpoints > 0) |
4012 | annotate_field (1); | |
4013 | ui_out_table_header (uiout, 14, ui_left, "type", "Type"); /* 2 */ | |
4014 | if (nr_printable_breakpoints > 0) | |
4015 | annotate_field (2); | |
4016 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ | |
4017 | if (nr_printable_breakpoints > 0) | |
4018 | annotate_field (3); | |
54e52265 | 4019 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 4020 | if (opts.addressprint) |
7f3b0473 | 4021 | { |
d7faa9e7 AC |
4022 | if (nr_printable_breakpoints > 0) |
4023 | annotate_field (4); | |
a6d9a66e | 4024 | if (print_address_bits <= 32) |
b25959ec | 4025 | ui_out_table_header (uiout, 10, ui_left, "addr", "Address");/* 5 */ |
7f3b0473 | 4026 | else |
b25959ec | 4027 | ui_out_table_header (uiout, 18, ui_left, "addr", "Address");/* 5 */ |
7f3b0473 | 4028 | } |
d7faa9e7 AC |
4029 | if (nr_printable_breakpoints > 0) |
4030 | annotate_field (5); | |
4031 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
4032 | ui_out_table_body (uiout); | |
4033 | if (nr_printable_breakpoints > 0) | |
4034 | annotate_breakpoints_table (); | |
7f3b0473 | 4035 | |
c4093a6a JM |
4036 | ALL_BREAKPOINTS (b) |
4037 | if (bnum == -1 | |
4038 | || bnum == b->number) | |
4039 | { | |
4040 | /* We only print out user settable breakpoints unless the | |
4041 | allflag is set. */ | |
7f3b0473 | 4042 | if (allflag || user_settable_breakpoint (b)) |
a6d9a66e | 4043 | print_one_breakpoint (b, &last_loc, print_address_bits); |
c4093a6a JM |
4044 | } |
4045 | ||
3b31d625 | 4046 | do_cleanups (bkpttbl_chain); |
698384cd | 4047 | |
7f3b0473 | 4048 | if (nr_printable_breakpoints == 0) |
c906108c | 4049 | { |
8b93c638 JM |
4050 | if (bnum == -1) |
4051 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); | |
4052 | else | |
4053 | ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n", | |
4054 | bnum); | |
c906108c SS |
4055 | } |
4056 | else | |
c4093a6a | 4057 | { |
a6d9a66e UW |
4058 | if (last_loc && !server_command) |
4059 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 4060 | } |
c906108c | 4061 | |
c4093a6a JM |
4062 | /* FIXME? Should this be moved up so that it is only called when |
4063 | there have been breakpoints? */ | |
c906108c SS |
4064 | annotate_breakpoints_table_end (); |
4065 | } | |
4066 | ||
c906108c | 4067 | static void |
fba45db2 | 4068 | breakpoints_info (char *bnum_exp, int from_tty) |
c906108c SS |
4069 | { |
4070 | int bnum = -1; | |
4071 | ||
4072 | if (bnum_exp) | |
bb518678 | 4073 | bnum = parse_and_eval_long (bnum_exp); |
c906108c SS |
4074 | |
4075 | breakpoint_1 (bnum, 0); | |
4076 | } | |
4077 | ||
7a292a7a | 4078 | static void |
fba45db2 | 4079 | maintenance_info_breakpoints (char *bnum_exp, int from_tty) |
c906108c SS |
4080 | { |
4081 | int bnum = -1; | |
4082 | ||
4083 | if (bnum_exp) | |
bb518678 | 4084 | bnum = parse_and_eval_long (bnum_exp); |
c906108c SS |
4085 | |
4086 | breakpoint_1 (bnum, 1); | |
4087 | } | |
4088 | ||
0d381245 | 4089 | static int |
714835d5 UW |
4090 | breakpoint_has_pc (struct breakpoint *b, |
4091 | CORE_ADDR pc, struct obj_section *section) | |
0d381245 VP |
4092 | { |
4093 | struct bp_location *bl = b->loc; | |
4094 | for (; bl; bl = bl->next) | |
4095 | { | |
4096 | if (bl->address == pc | |
4097 | && (!overlay_debugging || bl->section == section)) | |
4098 | return 1; | |
4099 | } | |
4100 | return 0; | |
4101 | } | |
4102 | ||
c906108c SS |
4103 | /* Print a message describing any breakpoints set at PC. */ |
4104 | ||
4105 | static void | |
5af949e3 UW |
4106 | describe_other_breakpoints (struct gdbarch *gdbarch, CORE_ADDR pc, |
4107 | struct obj_section *section, int thread) | |
c906108c | 4108 | { |
52f0bd74 AC |
4109 | int others = 0; |
4110 | struct breakpoint *b; | |
c906108c SS |
4111 | |
4112 | ALL_BREAKPOINTS (b) | |
0d381245 | 4113 | others += breakpoint_has_pc (b, pc, section); |
c906108c SS |
4114 | if (others > 0) |
4115 | { | |
a3f17187 AC |
4116 | if (others == 1) |
4117 | printf_filtered (_("Note: breakpoint ")); | |
4118 | else /* if (others == ???) */ | |
4119 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 4120 | ALL_BREAKPOINTS (b) |
0d381245 VP |
4121 | if (breakpoint_has_pc (b, pc, section)) |
4122 | { | |
4123 | others--; | |
4124 | printf_filtered ("%d", b->number); | |
4125 | if (b->thread == -1 && thread != -1) | |
4126 | printf_filtered (" (all threads)"); | |
4127 | else if (b->thread != -1) | |
4128 | printf_filtered (" (thread %d)", b->thread); | |
4129 | printf_filtered ("%s%s ", | |
059fb39f | 4130 | ((b->enable_state == bp_disabled |
8bea4e01 UW |
4131 | || b->enable_state == bp_call_disabled |
4132 | || b->enable_state == bp_startup_disabled) | |
0d381245 VP |
4133 | ? " (disabled)" |
4134 | : b->enable_state == bp_permanent | |
4135 | ? " (permanent)" | |
4136 | : ""), | |
4137 | (others > 1) ? "," | |
4138 | : ((others == 1) ? " and" : "")); | |
4139 | } | |
a3f17187 | 4140 | printf_filtered (_("also set at pc ")); |
5af949e3 | 4141 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
4142 | printf_filtered (".\n"); |
4143 | } | |
4144 | } | |
4145 | \f | |
4146 | /* Set the default place to put a breakpoint | |
4147 | for the `break' command with no arguments. */ | |
4148 | ||
4149 | void | |
fba45db2 KB |
4150 | set_default_breakpoint (int valid, CORE_ADDR addr, struct symtab *symtab, |
4151 | int line) | |
c906108c SS |
4152 | { |
4153 | default_breakpoint_valid = valid; | |
4154 | default_breakpoint_address = addr; | |
4155 | default_breakpoint_symtab = symtab; | |
4156 | default_breakpoint_line = line; | |
4157 | } | |
4158 | ||
e4f237da KB |
4159 | /* Return true iff it is meaningful to use the address member of |
4160 | BPT. For some breakpoint types, the address member is irrelevant | |
4161 | and it makes no sense to attempt to compare it to other addresses | |
4162 | (or use it for any other purpose either). | |
4163 | ||
4164 | More specifically, each of the following breakpoint types will always | |
4165 | have a zero valued address and we don't want check_duplicates() to mark | |
4166 | breakpoints of any of these types to be a duplicate of an actual | |
4167 | breakpoint at address zero: | |
4168 | ||
4169 | bp_watchpoint | |
4170 | bp_hardware_watchpoint | |
4171 | bp_read_watchpoint | |
4172 | bp_access_watchpoint | |
fe798b75 | 4173 | bp_catchpoint */ |
e4f237da KB |
4174 | |
4175 | static int | |
4176 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
4177 | { | |
4178 | enum bptype type = bpt->type; | |
4179 | ||
4180 | return (type != bp_watchpoint | |
4181 | && type != bp_hardware_watchpoint | |
4182 | && type != bp_read_watchpoint | |
4183 | && type != bp_access_watchpoint | |
fe798b75 | 4184 | && type != bp_catchpoint); |
e4f237da KB |
4185 | } |
4186 | ||
9f60f21b | 4187 | /* Rescan breakpoints at the same address and section as BPT, |
c906108c | 4188 | marking the first one as "first" and any others as "duplicates". |
c2c6d25f | 4189 | This is so that the bpt instruction is only inserted once. |
9f60f21b JB |
4190 | If we have a permanent breakpoint at the same place as BPT, make |
4191 | that one the official one, and the rest as duplicates. */ | |
c906108c SS |
4192 | |
4193 | static void | |
714835d5 | 4194 | check_duplicates_for (CORE_ADDR address, struct obj_section *section) |
c906108c | 4195 | { |
075f6582 | 4196 | struct bp_location *b; |
52f0bd74 | 4197 | int count = 0; |
075f6582 | 4198 | struct bp_location *perm_bp = 0; |
c906108c | 4199 | |
075f6582 DJ |
4200 | ALL_BP_LOCATIONS (b) |
4201 | if (b->owner->enable_state != bp_disabled | |
075f6582 | 4202 | && b->owner->enable_state != bp_call_disabled |
8bea4e01 | 4203 | && b->owner->enable_state != bp_startup_disabled |
0d381245 VP |
4204 | && b->enabled |
4205 | && !b->shlib_disabled | |
075f6582 DJ |
4206 | && b->address == address /* address / overlay match */ |
4207 | && (!overlay_debugging || b->section == section) | |
4208 | && breakpoint_address_is_meaningful (b->owner)) | |
c5aa993b | 4209 | { |
c2c6d25f | 4210 | /* Have we found a permanent breakpoint? */ |
075f6582 | 4211 | if (b->owner->enable_state == bp_permanent) |
c2c6d25f JM |
4212 | { |
4213 | perm_bp = b; | |
4214 | break; | |
4215 | } | |
4216 | ||
c5aa993b | 4217 | count++; |
075f6582 | 4218 | b->duplicate = count > 1; |
c5aa993b | 4219 | } |
c2c6d25f JM |
4220 | |
4221 | /* If we found a permanent breakpoint at this address, go over the | |
aae64587 PA |
4222 | list again and declare all the other breakpoints there (except |
4223 | other permanent breakpoints) to be the duplicates. */ | |
c2c6d25f JM |
4224 | if (perm_bp) |
4225 | { | |
075f6582 | 4226 | perm_bp->duplicate = 0; |
c2c6d25f JM |
4227 | |
4228 | /* Permanent breakpoint should always be inserted. */ | |
075f6582 | 4229 | if (! perm_bp->inserted) |
8e65ff28 | 4230 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 AC |
4231 | _("allegedly permanent breakpoint is not " |
4232 | "actually inserted")); | |
c2c6d25f | 4233 | |
075f6582 | 4234 | ALL_BP_LOCATIONS (b) |
c2c6d25f JM |
4235 | if (b != perm_bp) |
4236 | { | |
aae64587 PA |
4237 | if (b->owner->enable_state != bp_permanent |
4238 | && b->owner->enable_state != bp_disabled | |
075f6582 | 4239 | && b->owner->enable_state != bp_call_disabled |
8bea4e01 | 4240 | && b->owner->enable_state != bp_startup_disabled |
0d381245 | 4241 | && b->enabled && !b->shlib_disabled |
075f6582 DJ |
4242 | && b->address == address /* address / overlay match */ |
4243 | && (!overlay_debugging || b->section == section) | |
4244 | && breakpoint_address_is_meaningful (b->owner)) | |
4245 | { | |
4246 | if (b->inserted) | |
4247 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 AC |
4248 | _("another breakpoint was inserted on top of " |
4249 | "a permanent breakpoint")); | |
075f6582 DJ |
4250 | |
4251 | b->duplicate = 1; | |
4252 | } | |
c2c6d25f JM |
4253 | } |
4254 | } | |
c906108c SS |
4255 | } |
4256 | ||
0d381245 VP |
4257 | static void |
4258 | check_duplicates (struct breakpoint *bpt) | |
4259 | { | |
4260 | struct bp_location *bl = bpt->loc; | |
4261 | ||
4262 | if (! breakpoint_address_is_meaningful (bpt)) | |
4263 | return; | |
4264 | ||
4265 | for (; bl; bl = bl->next) | |
4266 | check_duplicates_for (bl->address, bl->section); | |
4267 | } | |
4268 | ||
76897487 KB |
4269 | static void |
4270 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
4271 | int bnum, int have_bnum) | |
4272 | { | |
4273 | char astr1[40]; | |
4274 | char astr2[40]; | |
4275 | ||
bb599908 PH |
4276 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
4277 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 4278 | if (have_bnum) |
8a3fe4f8 | 4279 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
4280 | bnum, astr1, astr2); |
4281 | else | |
8a3fe4f8 | 4282 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
4283 | } |
4284 | ||
4285 | /* Adjust a breakpoint's address to account for architectural constraints | |
4286 | on breakpoint placement. Return the adjusted address. Note: Very | |
4287 | few targets require this kind of adjustment. For most targets, | |
4288 | this function is simply the identity function. */ | |
4289 | ||
4290 | static CORE_ADDR | |
a6d9a66e UW |
4291 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
4292 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 4293 | { |
a6d9a66e | 4294 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
4295 | { |
4296 | /* Very few targets need any kind of breakpoint adjustment. */ | |
4297 | return bpaddr; | |
4298 | } | |
88f7da05 KB |
4299 | else if (bptype == bp_watchpoint |
4300 | || bptype == bp_hardware_watchpoint | |
4301 | || bptype == bp_read_watchpoint | |
4302 | || bptype == bp_access_watchpoint | |
fe798b75 | 4303 | || bptype == bp_catchpoint) |
88f7da05 KB |
4304 | { |
4305 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
4306 | have their addresses modified. */ | |
4307 | return bpaddr; | |
4308 | } | |
76897487 KB |
4309 | else |
4310 | { | |
4311 | CORE_ADDR adjusted_bpaddr; | |
4312 | ||
4313 | /* Some targets have architectural constraints on the placement | |
4314 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 4315 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
4316 | |
4317 | /* An adjusted breakpoint address can significantly alter | |
4318 | a user's expectations. Print a warning if an adjustment | |
4319 | is required. */ | |
4320 | if (adjusted_bpaddr != bpaddr) | |
4321 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
4322 | ||
4323 | return adjusted_bpaddr; | |
4324 | } | |
4325 | } | |
4326 | ||
7cc221ef DJ |
4327 | /* Allocate a struct bp_location. */ |
4328 | ||
26bb91f3 | 4329 | static struct bp_location * |
39d61571 | 4330 | allocate_bp_location (struct breakpoint *bpt) |
7cc221ef DJ |
4331 | { |
4332 | struct bp_location *loc, *loc_p; | |
4333 | ||
4334 | loc = xmalloc (sizeof (struct bp_location)); | |
4335 | memset (loc, 0, sizeof (*loc)); | |
4336 | ||
e049a4b5 | 4337 | loc->owner = bpt; |
511a6cd4 | 4338 | loc->cond = NULL; |
0d381245 VP |
4339 | loc->shlib_disabled = 0; |
4340 | loc->enabled = 1; | |
e049a4b5 | 4341 | |
39d61571 | 4342 | switch (bpt->type) |
e049a4b5 DJ |
4343 | { |
4344 | case bp_breakpoint: | |
1042e4c0 | 4345 | case bp_tracepoint: |
e049a4b5 DJ |
4346 | case bp_until: |
4347 | case bp_finish: | |
4348 | case bp_longjmp: | |
4349 | case bp_longjmp_resume: | |
4350 | case bp_step_resume: | |
e049a4b5 DJ |
4351 | case bp_watchpoint_scope: |
4352 | case bp_call_dummy: | |
4353 | case bp_shlib_event: | |
4354 | case bp_thread_event: | |
4355 | case bp_overlay_event: | |
0fd8e87f | 4356 | case bp_longjmp_master: |
e049a4b5 DJ |
4357 | loc->loc_type = bp_loc_software_breakpoint; |
4358 | break; | |
4359 | case bp_hardware_breakpoint: | |
4360 | loc->loc_type = bp_loc_hardware_breakpoint; | |
4361 | break; | |
4362 | case bp_hardware_watchpoint: | |
4363 | case bp_read_watchpoint: | |
4364 | case bp_access_watchpoint: | |
4365 | loc->loc_type = bp_loc_hardware_watchpoint; | |
4366 | break; | |
4367 | case bp_watchpoint: | |
ce78b96d | 4368 | case bp_catchpoint: |
e049a4b5 DJ |
4369 | loc->loc_type = bp_loc_other; |
4370 | break; | |
4371 | default: | |
e2e0b3e5 | 4372 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
4373 | } |
4374 | ||
7cc221ef DJ |
4375 | return loc; |
4376 | } | |
4377 | ||
fe3f5fa8 VP |
4378 | static void free_bp_location (struct bp_location *loc) |
4379 | { | |
4380 | if (loc->cond) | |
4381 | xfree (loc->cond); | |
74960c60 VP |
4382 | |
4383 | if (loc->function_name) | |
4384 | xfree (loc->function_name); | |
4385 | ||
fe3f5fa8 VP |
4386 | xfree (loc); |
4387 | } | |
4388 | ||
0d381245 VP |
4389 | /* Helper to set_raw_breakpoint below. Creates a breakpoint |
4390 | that has type BPTYPE and has no locations as yet. */ | |
63c252f8 | 4391 | /* This function is used in gdbtk sources and thus can not be made static. */ |
c906108c | 4392 | |
c40e75cd | 4393 | static struct breakpoint * |
a6d9a66e UW |
4394 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, |
4395 | enum bptype bptype) | |
c906108c | 4396 | { |
52f0bd74 | 4397 | struct breakpoint *b, *b1; |
c906108c SS |
4398 | |
4399 | b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint)); | |
4400 | memset (b, 0, sizeof (*b)); | |
2219d63c | 4401 | |
4d28f7a8 | 4402 | b->type = bptype; |
a6d9a66e | 4403 | b->gdbarch = gdbarch; |
c906108c SS |
4404 | b->language = current_language->la_language; |
4405 | b->input_radix = input_radix; | |
4406 | b->thread = -1; | |
b5de0fa7 | 4407 | b->enable_state = bp_enabled; |
c906108c SS |
4408 | b->next = 0; |
4409 | b->silent = 0; | |
4410 | b->ignore_count = 0; | |
4411 | b->commands = NULL; | |
818dd999 | 4412 | b->frame_id = null_frame_id; |
3a3e9ee3 | 4413 | b->forked_inferior_pid = null_ptid; |
c906108c | 4414 | b->exec_pathname = NULL; |
3086aeae | 4415 | b->ops = NULL; |
0d381245 | 4416 | b->condition_not_parsed = 0; |
c906108c SS |
4417 | |
4418 | /* Add this breakpoint to the end of the chain | |
4419 | so that a list of breakpoints will come out in order | |
4420 | of increasing numbers. */ | |
4421 | ||
4422 | b1 = breakpoint_chain; | |
4423 | if (b1 == 0) | |
4424 | breakpoint_chain = b; | |
4425 | else | |
4426 | { | |
4427 | while (b1->next) | |
4428 | b1 = b1->next; | |
4429 | b1->next = b; | |
4430 | } | |
0d381245 VP |
4431 | return b; |
4432 | } | |
4433 | ||
4434 | /* Initialize loc->function_name. */ | |
4435 | static void | |
4436 | set_breakpoint_location_function (struct bp_location *loc) | |
4437 | { | |
4438 | if (loc->owner->type == bp_breakpoint | |
1042e4c0 SS |
4439 | || loc->owner->type == bp_hardware_breakpoint |
4440 | || loc->owner->type == bp_tracepoint) | |
0d381245 VP |
4441 | { |
4442 | find_pc_partial_function (loc->address, &(loc->function_name), | |
4443 | NULL, NULL); | |
4444 | if (loc->function_name) | |
4445 | loc->function_name = xstrdup (loc->function_name); | |
4446 | } | |
4447 | } | |
4448 | ||
a6d9a66e UW |
4449 | /* Attempt to determine architecture of location identified by SAL. */ |
4450 | static struct gdbarch * | |
4451 | get_sal_arch (struct symtab_and_line sal) | |
4452 | { | |
4453 | if (sal.section) | |
4454 | return get_objfile_arch (sal.section->objfile); | |
4455 | if (sal.symtab) | |
4456 | return get_objfile_arch (sal.symtab->objfile); | |
4457 | ||
4458 | return NULL; | |
4459 | } | |
4460 | ||
0d381245 VP |
4461 | /* set_raw_breakpoint is a low level routine for allocating and |
4462 | partially initializing a breakpoint of type BPTYPE. The newly | |
4463 | created breakpoint's address, section, source file name, and line | |
4464 | number are provided by SAL. The newly created and partially | |
4465 | initialized breakpoint is added to the breakpoint chain and | |
4466 | is also returned as the value of this function. | |
4467 | ||
4468 | It is expected that the caller will complete the initialization of | |
4469 | the newly created breakpoint struct as well as output any status | |
4470 | information regarding the creation of a new breakpoint. In | |
4471 | particular, set_raw_breakpoint does NOT set the breakpoint | |
4472 | number! Care should be taken to not allow an error to occur | |
4473 | prior to completing the initialization of the breakpoint. If this | |
4474 | should happen, a bogus breakpoint will be left on the chain. */ | |
4475 | ||
63c252f8 | 4476 | struct breakpoint * |
a6d9a66e UW |
4477 | set_raw_breakpoint (struct gdbarch *gdbarch, |
4478 | struct symtab_and_line sal, enum bptype bptype) | |
0d381245 | 4479 | { |
a6d9a66e | 4480 | struct breakpoint *b = set_raw_breakpoint_without_location (gdbarch, bptype); |
0d381245 | 4481 | CORE_ADDR adjusted_address; |
a6d9a66e UW |
4482 | struct gdbarch *loc_gdbarch; |
4483 | ||
4484 | loc_gdbarch = get_sal_arch (sal); | |
4485 | if (!loc_gdbarch) | |
4486 | loc_gdbarch = b->gdbarch; | |
0d381245 VP |
4487 | |
4488 | /* Adjust the breakpoint's address prior to allocating a location. | |
4489 | Once we call allocate_bp_location(), that mostly uninitialized | |
4490 | location will be placed on the location chain. Adjustment of the | |
8defab1a | 4491 | breakpoint may cause target_read_memory() to be called and we do |
0d381245 VP |
4492 | not want its scan of the location chain to find a breakpoint and |
4493 | location that's only been partially initialized. */ | |
a6d9a66e | 4494 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, sal.pc, b->type); |
0d381245 | 4495 | |
39d61571 | 4496 | b->loc = allocate_bp_location (b); |
a6d9a66e | 4497 | b->loc->gdbarch = loc_gdbarch; |
0d381245 VP |
4498 | b->loc->requested_address = sal.pc; |
4499 | b->loc->address = adjusted_address; | |
4500 | ||
4501 | if (sal.symtab == NULL) | |
4502 | b->source_file = NULL; | |
4503 | else | |
1b36a34b | 4504 | b->source_file = xstrdup (sal.symtab->filename); |
0d381245 VP |
4505 | b->loc->section = sal.section; |
4506 | b->line_number = sal.line; | |
4507 | ||
4508 | set_breakpoint_location_function (b->loc); | |
c906108c | 4509 | |
c906108c SS |
4510 | breakpoints_changed (); |
4511 | ||
4512 | return b; | |
4513 | } | |
4514 | ||
c2c6d25f JM |
4515 | |
4516 | /* Note that the breakpoint object B describes a permanent breakpoint | |
4517 | instruction, hard-wired into the inferior's code. */ | |
4518 | void | |
4519 | make_breakpoint_permanent (struct breakpoint *b) | |
4520 | { | |
0d381245 | 4521 | struct bp_location *bl; |
b5de0fa7 | 4522 | b->enable_state = bp_permanent; |
c2c6d25f | 4523 | |
0d381245 VP |
4524 | /* By definition, permanent breakpoints are already present in the code. |
4525 | Mark all locations as inserted. For now, make_breakpoint_permanent | |
4526 | is called in just one place, so it's hard to say if it's reasonable | |
4527 | to have permanent breakpoint with multiple locations or not, | |
4528 | but it's easy to implmement. */ | |
4529 | for (bl = b->loc; bl; bl = bl->next) | |
4530 | bl->inserted = 1; | |
c2c6d25f JM |
4531 | } |
4532 | ||
53a5351d | 4533 | /* Call this routine when stepping and nexting to enable a breakpoint |
0fd8e87f | 4534 | if we do a longjmp() in THREAD. When we hit that breakpoint, call |
c906108c SS |
4535 | set_longjmp_resume_breakpoint() to figure out where we are going. */ |
4536 | ||
4537 | void | |
0fd8e87f | 4538 | set_longjmp_breakpoint (int thread) |
c906108c | 4539 | { |
0fd8e87f UW |
4540 | struct breakpoint *b, *temp; |
4541 | ||
4542 | /* To avoid having to rescan all objfile symbols at every step, | |
4543 | we maintain a list of continually-inserted but always disabled | |
4544 | longjmp "master" breakpoints. Here, we simply create momentary | |
4545 | clones of those and enable them for the requested thread. */ | |
4546 | ALL_BREAKPOINTS_SAFE (b, temp) | |
4547 | if (b->type == bp_longjmp_master) | |
4548 | { | |
4549 | struct breakpoint *clone = clone_momentary_breakpoint (b); | |
4550 | clone->type = bp_longjmp; | |
4551 | clone->thread = thread; | |
4552 | } | |
c906108c SS |
4553 | } |
4554 | ||
611c83ae | 4555 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 4556 | void |
611c83ae | 4557 | delete_longjmp_breakpoint (int thread) |
c906108c | 4558 | { |
611c83ae | 4559 | struct breakpoint *b, *temp; |
c906108c | 4560 | |
611c83ae PA |
4561 | ALL_BREAKPOINTS_SAFE (b, temp) |
4562 | if (b->type == bp_longjmp) | |
4563 | { | |
4564 | if (b->thread == thread) | |
4565 | delete_breakpoint (b); | |
4566 | } | |
c906108c SS |
4567 | } |
4568 | ||
1900040c MS |
4569 | void |
4570 | enable_overlay_breakpoints (void) | |
4571 | { | |
52f0bd74 | 4572 | struct breakpoint *b; |
1900040c MS |
4573 | |
4574 | ALL_BREAKPOINTS (b) | |
4575 | if (b->type == bp_overlay_event) | |
4576 | { | |
4577 | b->enable_state = bp_enabled; | |
b60e7edf | 4578 | update_global_location_list (1); |
c02f5703 | 4579 | overlay_events_enabled = 1; |
1900040c MS |
4580 | } |
4581 | } | |
4582 | ||
4583 | void | |
4584 | disable_overlay_breakpoints (void) | |
4585 | { | |
52f0bd74 | 4586 | struct breakpoint *b; |
1900040c MS |
4587 | |
4588 | ALL_BREAKPOINTS (b) | |
4589 | if (b->type == bp_overlay_event) | |
4590 | { | |
4591 | b->enable_state = bp_disabled; | |
b60e7edf | 4592 | update_global_location_list (0); |
c02f5703 | 4593 | overlay_events_enabled = 0; |
1900040c MS |
4594 | } |
4595 | } | |
4596 | ||
c4093a6a | 4597 | struct breakpoint * |
a6d9a66e | 4598 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
4599 | { |
4600 | struct breakpoint *b; | |
c4093a6a | 4601 | |
a6d9a66e | 4602 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event); |
c4093a6a | 4603 | |
b5de0fa7 | 4604 | b->enable_state = bp_enabled; |
c4093a6a | 4605 | /* addr_string has to be used or breakpoint_re_set will delete me. */ |
5af949e3 UW |
4606 | b->addr_string |
4607 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
c4093a6a | 4608 | |
b60e7edf | 4609 | update_global_location_list_nothrow (1); |
74960c60 | 4610 | |
c4093a6a JM |
4611 | return b; |
4612 | } | |
4613 | ||
4614 | void | |
4615 | remove_thread_event_breakpoints (void) | |
4616 | { | |
4617 | struct breakpoint *b, *temp; | |
4618 | ||
4619 | ALL_BREAKPOINTS_SAFE (b, temp) | |
4620 | if (b->type == bp_thread_event) | |
4621 | delete_breakpoint (b); | |
4622 | } | |
4623 | ||
0101ce28 JJ |
4624 | struct captured_parse_breakpoint_args |
4625 | { | |
4626 | char **arg_p; | |
4627 | struct symtabs_and_lines *sals_p; | |
4628 | char ***addr_string_p; | |
4629 | int *not_found_ptr; | |
4630 | }; | |
4631 | ||
4632 | struct lang_and_radix | |
4633 | { | |
4634 | enum language lang; | |
4635 | int radix; | |
4636 | }; | |
4637 | ||
0101ce28 | 4638 | |
cae688ec JJ |
4639 | void |
4640 | remove_solib_event_breakpoints (void) | |
4641 | { | |
4642 | struct breakpoint *b, *temp; | |
4643 | ||
4644 | ALL_BREAKPOINTS_SAFE (b, temp) | |
4645 | if (b->type == bp_shlib_event) | |
4646 | delete_breakpoint (b); | |
4647 | } | |
4648 | ||
4649 | struct breakpoint * | |
a6d9a66e | 4650 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
cae688ec JJ |
4651 | { |
4652 | struct breakpoint *b; | |
4653 | ||
a6d9a66e | 4654 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event); |
b60e7edf | 4655 | update_global_location_list_nothrow (1); |
cae688ec JJ |
4656 | return b; |
4657 | } | |
4658 | ||
4659 | /* Disable any breakpoints that are on code in shared libraries. Only | |
4660 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
4661 | ||
4662 | void | |
cb851954 | 4663 | disable_breakpoints_in_shlibs (void) |
cae688ec | 4664 | { |
0d381245 | 4665 | struct bp_location *loc; |
cae688ec | 4666 | |
0d381245 | 4667 | ALL_BP_LOCATIONS (loc) |
cae688ec | 4668 | { |
0d381245 VP |
4669 | struct breakpoint *b = loc->owner; |
4670 | /* We apply the check to all breakpoints, including disabled | |
4671 | for those with loc->duplicate set. This is so that when breakpoint | |
4672 | becomes enabled, or the duplicate is removed, gdb will try to insert | |
4673 | all breakpoints. If we don't set shlib_disabled here, we'll try | |
4674 | to insert those breakpoints and fail. */ | |
1042e4c0 SS |
4675 | if (((b->type == bp_breakpoint) |
4676 | || (b->type == bp_hardware_breakpoint) | |
4677 | || (b->type == bp_tracepoint)) | |
0d381245 | 4678 | && !loc->shlib_disabled |
a77053c2 | 4679 | #ifdef PC_SOLIB |
0d381245 | 4680 | && PC_SOLIB (loc->address) |
a77053c2 | 4681 | #else |
f5c9a895 | 4682 | && solib_name_from_address (loc->address) |
a77053c2 MK |
4683 | #endif |
4684 | ) | |
0d381245 VP |
4685 | { |
4686 | loc->shlib_disabled = 1; | |
4687 | } | |
cae688ec JJ |
4688 | } |
4689 | } | |
4690 | ||
84acb35a JJ |
4691 | /* Disable any breakpoints that are in in an unloaded shared library. Only |
4692 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
4693 | ||
75149521 | 4694 | static void |
84acb35a JJ |
4695 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
4696 | { | |
0d381245 | 4697 | struct bp_location *loc; |
84acb35a JJ |
4698 | int disabled_shlib_breaks = 0; |
4699 | ||
c86cf029 VP |
4700 | /* SunOS a.out shared libraries are always mapped, so do not |
4701 | disable breakpoints; they will only be reported as unloaded | |
4702 | through clear_solib when GDB discards its shared library | |
4703 | list. See clear_solib for more information. */ | |
4704 | if (exec_bfd != NULL | |
4705 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) | |
4706 | return; | |
4707 | ||
0d381245 | 4708 | ALL_BP_LOCATIONS (loc) |
84acb35a | 4709 | { |
0d381245 VP |
4710 | struct breakpoint *b = loc->owner; |
4711 | if ((loc->loc_type == bp_loc_hardware_breakpoint | |
4712 | || loc->loc_type == bp_loc_software_breakpoint) | |
e2dd7057 PP |
4713 | && !loc->shlib_disabled |
4714 | && (b->type == bp_breakpoint || b->type == bp_hardware_breakpoint) | |
4715 | && solib_contains_address_p (solib, loc->address)) | |
84acb35a | 4716 | { |
e2dd7057 PP |
4717 | loc->shlib_disabled = 1; |
4718 | /* At this point, we cannot rely on remove_breakpoint | |
4719 | succeeding so we must mark the breakpoint as not inserted | |
4720 | to prevent future errors occurring in remove_breakpoints. */ | |
4721 | loc->inserted = 0; | |
4722 | if (!disabled_shlib_breaks) | |
4723 | { | |
4724 | target_terminal_ours_for_output (); | |
4725 | warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""), | |
4726 | solib->so_name); | |
84acb35a | 4727 | } |
e2dd7057 | 4728 | disabled_shlib_breaks = 1; |
84acb35a JJ |
4729 | } |
4730 | } | |
84acb35a JJ |
4731 | } |
4732 | ||
ce78b96d JB |
4733 | /* FORK & VFORK catchpoints. */ |
4734 | ||
4735 | /* Implement the "insert" breakpoint_ops method for fork catchpoints. */ | |
4736 | ||
c906108c | 4737 | static void |
ce78b96d JB |
4738 | insert_catch_fork (struct breakpoint *b) |
4739 | { | |
4740 | target_insert_fork_catchpoint (PIDGET (inferior_ptid)); | |
4741 | } | |
4742 | ||
4743 | /* Implement the "remove" breakpoint_ops method for fork catchpoints. */ | |
4744 | ||
4745 | static int | |
4746 | remove_catch_fork (struct breakpoint *b) | |
4747 | { | |
4748 | return target_remove_fork_catchpoint (PIDGET (inferior_ptid)); | |
4749 | } | |
4750 | ||
4751 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
4752 | catchpoints. */ | |
4753 | ||
4754 | static int | |
4755 | breakpoint_hit_catch_fork (struct breakpoint *b) | |
4756 | { | |
4757 | return inferior_has_forked (inferior_ptid, &b->forked_inferior_pid); | |
4758 | } | |
4759 | ||
4760 | /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */ | |
4761 | ||
4762 | static enum print_stop_action | |
4763 | print_it_catch_fork (struct breakpoint *b) | |
4764 | { | |
4765 | annotate_catchpoint (b->number); | |
4766 | printf_filtered (_("\nCatchpoint %d (forked process %d), "), | |
4767 | b->number, ptid_get_pid (b->forked_inferior_pid)); | |
4768 | return PRINT_SRC_AND_LOC; | |
4769 | } | |
4770 | ||
4771 | /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */ | |
4772 | ||
4773 | static void | |
a6d9a66e | 4774 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 4775 | { |
79a45b7d TT |
4776 | struct value_print_options opts; |
4777 | ||
4778 | get_user_print_options (&opts); | |
4779 | ||
ce78b96d JB |
4780 | /* Field 4, the address, is omitted (which makes the columns |
4781 | not line up too nicely with the headers, but the effect | |
4782 | is relatively readable). */ | |
79a45b7d | 4783 | if (opts.addressprint) |
ce78b96d JB |
4784 | ui_out_field_skip (uiout, "addr"); |
4785 | annotate_field (5); | |
4786 | ui_out_text (uiout, "fork"); | |
4787 | if (!ptid_equal (b->forked_inferior_pid, null_ptid)) | |
4788 | { | |
4789 | ui_out_text (uiout, ", process "); | |
4790 | ui_out_field_int (uiout, "what", | |
4791 | ptid_get_pid (b->forked_inferior_pid)); | |
4792 | ui_out_spaces (uiout, 1); | |
4793 | } | |
4794 | } | |
4795 | ||
4796 | /* Implement the "print_mention" breakpoint_ops method for fork | |
4797 | catchpoints. */ | |
4798 | ||
4799 | static void | |
4800 | print_mention_catch_fork (struct breakpoint *b) | |
4801 | { | |
4802 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
4803 | } | |
4804 | ||
4805 | /* The breakpoint_ops structure to be used in fork catchpoints. */ | |
4806 | ||
4807 | static struct breakpoint_ops catch_fork_breakpoint_ops = | |
4808 | { | |
4809 | insert_catch_fork, | |
4810 | remove_catch_fork, | |
4811 | breakpoint_hit_catch_fork, | |
4812 | print_it_catch_fork, | |
4813 | print_one_catch_fork, | |
4814 | print_mention_catch_fork | |
4815 | }; | |
4816 | ||
4817 | /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */ | |
4818 | ||
4819 | static void | |
4820 | insert_catch_vfork (struct breakpoint *b) | |
4821 | { | |
4822 | target_insert_vfork_catchpoint (PIDGET (inferior_ptid)); | |
4823 | } | |
4824 | ||
4825 | /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */ | |
4826 | ||
4827 | static int | |
4828 | remove_catch_vfork (struct breakpoint *b) | |
4829 | { | |
4830 | return target_remove_vfork_catchpoint (PIDGET (inferior_ptid)); | |
4831 | } | |
4832 | ||
4833 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
4834 | catchpoints. */ | |
4835 | ||
4836 | static int | |
4837 | breakpoint_hit_catch_vfork (struct breakpoint *b) | |
4838 | { | |
4839 | return inferior_has_vforked (inferior_ptid, &b->forked_inferior_pid); | |
4840 | } | |
4841 | ||
4842 | /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */ | |
4843 | ||
4844 | static enum print_stop_action | |
4845 | print_it_catch_vfork (struct breakpoint *b) | |
4846 | { | |
4847 | annotate_catchpoint (b->number); | |
4848 | printf_filtered (_("\nCatchpoint %d (vforked process %d), "), | |
4849 | b->number, ptid_get_pid (b->forked_inferior_pid)); | |
4850 | return PRINT_SRC_AND_LOC; | |
4851 | } | |
4852 | ||
4853 | /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */ | |
4854 | ||
4855 | static void | |
a6d9a66e | 4856 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 4857 | { |
79a45b7d TT |
4858 | struct value_print_options opts; |
4859 | ||
4860 | get_user_print_options (&opts); | |
ce78b96d JB |
4861 | /* Field 4, the address, is omitted (which makes the columns |
4862 | not line up too nicely with the headers, but the effect | |
4863 | is relatively readable). */ | |
79a45b7d | 4864 | if (opts.addressprint) |
ce78b96d JB |
4865 | ui_out_field_skip (uiout, "addr"); |
4866 | annotate_field (5); | |
4867 | ui_out_text (uiout, "vfork"); | |
4868 | if (!ptid_equal (b->forked_inferior_pid, null_ptid)) | |
4869 | { | |
4870 | ui_out_text (uiout, ", process "); | |
4871 | ui_out_field_int (uiout, "what", | |
4872 | ptid_get_pid (b->forked_inferior_pid)); | |
4873 | ui_out_spaces (uiout, 1); | |
4874 | } | |
4875 | } | |
4876 | ||
4877 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
4878 | catchpoints. */ | |
4879 | ||
4880 | static void | |
4881 | print_mention_catch_vfork (struct breakpoint *b) | |
4882 | { | |
4883 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
4884 | } | |
4885 | ||
4886 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ | |
4887 | ||
4888 | static struct breakpoint_ops catch_vfork_breakpoint_ops = | |
4889 | { | |
4890 | insert_catch_vfork, | |
4891 | remove_catch_vfork, | |
4892 | breakpoint_hit_catch_vfork, | |
4893 | print_it_catch_vfork, | |
4894 | print_one_catch_vfork, | |
4895 | print_mention_catch_vfork | |
4896 | }; | |
4897 | ||
4898 | /* Create a new breakpoint of the bp_catchpoint kind and return it. | |
4899 | ||
4900 | If TEMPFLAG is non-zero, then make the breakpoint temporary. | |
4901 | If COND_STRING is not NULL, then store it in the breakpoint. | |
4902 | OPS, if not NULL, is the breakpoint_ops structure associated | |
4903 | to the catchpoint. */ | |
4904 | ||
4905 | static struct breakpoint * | |
a6d9a66e UW |
4906 | create_catchpoint (struct gdbarch *gdbarch, int tempflag, |
4907 | char *cond_string, struct breakpoint_ops *ops) | |
c906108c | 4908 | { |
c5aa993b JM |
4909 | struct symtab_and_line sal; |
4910 | struct breakpoint *b; | |
c5aa993b | 4911 | |
fe39c653 | 4912 | init_sal (&sal); |
c906108c SS |
4913 | sal.pc = 0; |
4914 | sal.symtab = NULL; | |
4915 | sal.line = 0; | |
c5aa993b | 4916 | |
a6d9a66e | 4917 | b = set_raw_breakpoint (gdbarch, sal, bp_catchpoint); |
c906108c SS |
4918 | set_breakpoint_count (breakpoint_count + 1); |
4919 | b->number = breakpoint_count; | |
ce78b96d | 4920 | |
1b36a34b | 4921 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
ce78b96d | 4922 | b->thread = -1; |
c906108c | 4923 | b->addr_string = NULL; |
b5de0fa7 EZ |
4924 | b->enable_state = bp_enabled; |
4925 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
ce78b96d | 4926 | b->ops = ops; |
c5aa993b | 4927 | |
c906108c | 4928 | mention (b); |
ce78b96d | 4929 | update_global_location_list (1); |
c906108c | 4930 | |
ce78b96d | 4931 | return b; |
c906108c | 4932 | } |
c5aa993b | 4933 | |
9b70b993 | 4934 | static void |
a6d9a66e UW |
4935 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
4936 | int tempflag, char *cond_string, | |
ce78b96d | 4937 | struct breakpoint_ops *ops) |
c906108c | 4938 | { |
a6d9a66e UW |
4939 | struct breakpoint *b |
4940 | = create_catchpoint (gdbarch, tempflag, cond_string, ops); | |
ce78b96d JB |
4941 | |
4942 | /* FIXME: We should put this information in a breakpoint private data | |
4943 | area. */ | |
4944 | b->forked_inferior_pid = null_ptid; | |
c906108c SS |
4945 | } |
4946 | ||
fe798b75 JB |
4947 | /* Exec catchpoints. */ |
4948 | ||
9b70b993 | 4949 | static void |
fe798b75 | 4950 | insert_catch_exec (struct breakpoint *b) |
c906108c | 4951 | { |
fe798b75 JB |
4952 | target_insert_exec_catchpoint (PIDGET (inferior_ptid)); |
4953 | } | |
c906108c | 4954 | |
fe798b75 JB |
4955 | static int |
4956 | remove_catch_exec (struct breakpoint *b) | |
4957 | { | |
4958 | return target_remove_exec_catchpoint (PIDGET (inferior_ptid)); | |
4959 | } | |
c906108c | 4960 | |
fe798b75 JB |
4961 | static int |
4962 | breakpoint_hit_catch_exec (struct breakpoint *b) | |
4963 | { | |
4964 | return inferior_has_execd (inferior_ptid, &b->exec_pathname); | |
4965 | } | |
c906108c | 4966 | |
fe798b75 JB |
4967 | static enum print_stop_action |
4968 | print_it_catch_exec (struct breakpoint *b) | |
4969 | { | |
4970 | annotate_catchpoint (b->number); | |
4971 | printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b->number, | |
4972 | b->exec_pathname); | |
4973 | return PRINT_SRC_AND_LOC; | |
c906108c SS |
4974 | } |
4975 | ||
fe798b75 | 4976 | static void |
a6d9a66e | 4977 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 JB |
4978 | { |
4979 | struct value_print_options opts; | |
4980 | ||
4981 | get_user_print_options (&opts); | |
4982 | ||
4983 | /* Field 4, the address, is omitted (which makes the columns | |
4984 | not line up too nicely with the headers, but the effect | |
4985 | is relatively readable). */ | |
4986 | if (opts.addressprint) | |
4987 | ui_out_field_skip (uiout, "addr"); | |
4988 | annotate_field (5); | |
4989 | ui_out_text (uiout, "exec"); | |
4990 | if (b->exec_pathname != NULL) | |
4991 | { | |
4992 | ui_out_text (uiout, ", program \""); | |
4993 | ui_out_field_string (uiout, "what", b->exec_pathname); | |
4994 | ui_out_text (uiout, "\" "); | |
4995 | } | |
4996 | } | |
4997 | ||
4998 | static void | |
4999 | print_mention_catch_exec (struct breakpoint *b) | |
5000 | { | |
5001 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
5002 | } | |
5003 | ||
5004 | static struct breakpoint_ops catch_exec_breakpoint_ops = | |
5005 | { | |
5006 | insert_catch_exec, | |
5007 | remove_catch_exec, | |
5008 | breakpoint_hit_catch_exec, | |
5009 | print_it_catch_exec, | |
5010 | print_one_catch_exec, | |
5011 | print_mention_catch_exec | |
5012 | }; | |
5013 | ||
c906108c | 5014 | static int |
fba45db2 | 5015 | hw_breakpoint_used_count (void) |
c906108c | 5016 | { |
52f0bd74 | 5017 | struct breakpoint *b; |
c906108c SS |
5018 | int i = 0; |
5019 | ||
5020 | ALL_BREAKPOINTS (b) | |
c5aa993b | 5021 | { |
d6b74ac4 | 5022 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
c5aa993b JM |
5023 | i++; |
5024 | } | |
c906108c SS |
5025 | |
5026 | return i; | |
5027 | } | |
5028 | ||
5029 | static int | |
fba45db2 | 5030 | hw_watchpoint_used_count (enum bptype type, int *other_type_used) |
c906108c | 5031 | { |
52f0bd74 | 5032 | struct breakpoint *b; |
c906108c SS |
5033 | int i = 0; |
5034 | ||
5035 | *other_type_used = 0; | |
5036 | ALL_BREAKPOINTS (b) | |
c5aa993b | 5037 | { |
468d015d | 5038 | if (breakpoint_enabled (b)) |
c5aa993b JM |
5039 | { |
5040 | if (b->type == type) | |
5041 | i++; | |
059fb39f PM |
5042 | else if ((b->type == bp_hardware_watchpoint |
5043 | || b->type == bp_read_watchpoint | |
5044 | || b->type == bp_access_watchpoint)) | |
c5aa993b JM |
5045 | *other_type_used = 1; |
5046 | } | |
5047 | } | |
c906108c SS |
5048 | return i; |
5049 | } | |
5050 | ||
c906108c | 5051 | void |
fba45db2 | 5052 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 5053 | { |
c5aa993b | 5054 | struct breakpoint *b; |
c906108c SS |
5055 | |
5056 | ALL_BREAKPOINTS (b) | |
c5aa993b JM |
5057 | { |
5058 | if (((b->type == bp_watchpoint) | |
5059 | || (b->type == bp_hardware_watchpoint) | |
5060 | || (b->type == bp_read_watchpoint) | |
dfdfb3ca | 5061 | || (b->type == bp_access_watchpoint)) |
468d015d | 5062 | && breakpoint_enabled (b)) |
c5aa993b | 5063 | { |
b5de0fa7 | 5064 | b->enable_state = bp_call_disabled; |
b60e7edf | 5065 | update_global_location_list (0); |
c5aa993b JM |
5066 | } |
5067 | } | |
c906108c SS |
5068 | } |
5069 | ||
5070 | void | |
fba45db2 | 5071 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 5072 | { |
c5aa993b | 5073 | struct breakpoint *b; |
c906108c SS |
5074 | |
5075 | ALL_BREAKPOINTS (b) | |
c5aa993b JM |
5076 | { |
5077 | if (((b->type == bp_watchpoint) | |
5078 | || (b->type == bp_hardware_watchpoint) | |
5079 | || (b->type == bp_read_watchpoint) | |
dfdfb3ca | 5080 | || (b->type == bp_access_watchpoint)) |
b5de0fa7 | 5081 | && (b->enable_state == bp_call_disabled)) |
c5aa993b | 5082 | { |
b5de0fa7 | 5083 | b->enable_state = bp_enabled; |
b60e7edf | 5084 | update_global_location_list (1); |
c5aa993b JM |
5085 | } |
5086 | } | |
c906108c SS |
5087 | } |
5088 | ||
8bea4e01 UW |
5089 | void |
5090 | disable_breakpoints_before_startup (void) | |
5091 | { | |
5092 | struct breakpoint *b; | |
5093 | int found = 0; | |
5094 | ||
5095 | ALL_BREAKPOINTS (b) | |
5096 | { | |
5097 | if ((b->type == bp_breakpoint | |
5098 | || b->type == bp_hardware_breakpoint) | |
5099 | && breakpoint_enabled (b)) | |
5100 | { | |
5101 | b->enable_state = bp_startup_disabled; | |
5102 | found = 1; | |
5103 | } | |
5104 | } | |
5105 | ||
5106 | if (found) | |
5107 | update_global_location_list (0); | |
5108 | ||
5109 | executing_startup = 1; | |
5110 | } | |
5111 | ||
5112 | void | |
5113 | enable_breakpoints_after_startup (void) | |
5114 | { | |
5115 | struct breakpoint *b; | |
5116 | int found = 0; | |
5117 | ||
5118 | executing_startup = 0; | |
5119 | ||
5120 | ALL_BREAKPOINTS (b) | |
5121 | { | |
5122 | if ((b->type == bp_breakpoint | |
5123 | || b->type == bp_hardware_breakpoint) | |
5124 | && b->enable_state == bp_startup_disabled) | |
5125 | { | |
5126 | b->enable_state = bp_enabled; | |
5127 | found = 1; | |
5128 | } | |
5129 | } | |
5130 | ||
5131 | if (found) | |
5132 | breakpoint_re_set (); | |
5133 | } | |
5134 | ||
c906108c SS |
5135 | |
5136 | /* Set a breakpoint that will evaporate an end of command | |
5137 | at address specified by SAL. | |
5138 | Restrict it to frame FRAME if FRAME is nonzero. */ | |
5139 | ||
5140 | struct breakpoint * | |
a6d9a66e UW |
5141 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
5142 | struct frame_id frame_id, enum bptype type) | |
c906108c | 5143 | { |
52f0bd74 | 5144 | struct breakpoint *b; |
edb3359d DJ |
5145 | |
5146 | /* If FRAME_ID is valid, it should be a real frame, not an inlined | |
5147 | one. */ | |
5148 | gdb_assert (!frame_id_inlined_p (frame_id)); | |
5149 | ||
a6d9a66e | 5150 | b = set_raw_breakpoint (gdbarch, sal, type); |
b5de0fa7 EZ |
5151 | b->enable_state = bp_enabled; |
5152 | b->disposition = disp_donttouch; | |
818dd999 | 5153 | b->frame_id = frame_id; |
c906108c SS |
5154 | |
5155 | /* If we're debugging a multi-threaded program, then we | |
5156 | want momentary breakpoints to be active in only a | |
5157 | single thread of control. */ | |
39f77062 KB |
5158 | if (in_thread_list (inferior_ptid)) |
5159 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c | 5160 | |
b60e7edf | 5161 | update_global_location_list_nothrow (1); |
74960c60 | 5162 | |
c906108c SS |
5163 | return b; |
5164 | } | |
611c83ae | 5165 | |
e58b0e63 PA |
5166 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
5167 | ORIG is NULL. */ | |
5168 | ||
5169 | struct breakpoint * | |
5170 | clone_momentary_breakpoint (struct breakpoint *orig) | |
5171 | { | |
5172 | struct breakpoint *copy; | |
5173 | ||
5174 | /* If there's nothing to clone, then return nothing. */ | |
5175 | if (orig == NULL) | |
5176 | return NULL; | |
5177 | ||
a6d9a66e | 5178 | copy = set_raw_breakpoint_without_location (orig->gdbarch, orig->type); |
e58b0e63 PA |
5179 | copy->loc = allocate_bp_location (copy); |
5180 | set_breakpoint_location_function (copy->loc); | |
5181 | ||
a6d9a66e | 5182 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
5183 | copy->loc->requested_address = orig->loc->requested_address; |
5184 | copy->loc->address = orig->loc->address; | |
5185 | copy->loc->section = orig->loc->section; | |
5186 | ||
5187 | if (orig->source_file == NULL) | |
5188 | copy->source_file = NULL; | |
5189 | else | |
5190 | copy->source_file = xstrdup (orig->source_file); | |
5191 | ||
5192 | copy->line_number = orig->line_number; | |
5193 | copy->frame_id = orig->frame_id; | |
5194 | copy->thread = orig->thread; | |
5195 | ||
5196 | copy->enable_state = bp_enabled; | |
5197 | copy->disposition = disp_donttouch; | |
5198 | copy->number = internal_breakpoint_number--; | |
5199 | ||
5200 | update_global_location_list_nothrow (0); | |
5201 | return copy; | |
5202 | } | |
5203 | ||
611c83ae | 5204 | struct breakpoint * |
a6d9a66e UW |
5205 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
5206 | enum bptype type) | |
611c83ae PA |
5207 | { |
5208 | struct symtab_and_line sal; | |
5209 | ||
5210 | sal = find_pc_line (pc, 0); | |
5211 | sal.pc = pc; | |
5212 | sal.section = find_pc_overlay (pc); | |
5213 | sal.explicit_pc = 1; | |
5214 | ||
a6d9a66e | 5215 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 5216 | } |
c906108c | 5217 | \f |
c5aa993b | 5218 | |
c906108c SS |
5219 | /* Tell the user we have just set a breakpoint B. */ |
5220 | ||
5221 | static void | |
fba45db2 | 5222 | mention (struct breakpoint *b) |
c906108c SS |
5223 | { |
5224 | int say_where = 0; | |
fa8a61dc | 5225 | struct cleanup *ui_out_chain; |
79a45b7d TT |
5226 | struct value_print_options opts; |
5227 | ||
5228 | get_user_print_options (&opts); | |
8b93c638 | 5229 | |
9a4105ab AC |
5230 | /* FIXME: This is misplaced; mention() is called by things (like |
5231 | hitting a watchpoint) other than breakpoint creation. It should | |
5232 | be possible to clean this up and at the same time replace the | |
7f4b89d1 | 5233 | random calls to breakpoint_changed with this hook. */ |
383f836e | 5234 | observer_notify_breakpoint_created (b->number); |
c906108c | 5235 | |
3086aeae DJ |
5236 | if (b->ops != NULL && b->ops->print_mention != NULL) |
5237 | b->ops->print_mention (b); | |
5238 | else | |
5239 | switch (b->type) | |
5240 | { | |
5241 | case bp_none: | |
a3f17187 | 5242 | printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b->number); |
3086aeae DJ |
5243 | break; |
5244 | case bp_watchpoint: | |
5245 | ui_out_text (uiout, "Watchpoint "); | |
5246 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
5247 | ui_out_field_int (uiout, "number", b->number); | |
5248 | ui_out_text (uiout, ": "); | |
fa8a61dc | 5249 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
5250 | do_cleanups (ui_out_chain); |
5251 | break; | |
5252 | case bp_hardware_watchpoint: | |
5253 | ui_out_text (uiout, "Hardware watchpoint "); | |
5254 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
5255 | ui_out_field_int (uiout, "number", b->number); | |
5256 | ui_out_text (uiout, ": "); | |
fa8a61dc | 5257 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
5258 | do_cleanups (ui_out_chain); |
5259 | break; | |
5260 | case bp_read_watchpoint: | |
5261 | ui_out_text (uiout, "Hardware read watchpoint "); | |
5262 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
5263 | ui_out_field_int (uiout, "number", b->number); | |
5264 | ui_out_text (uiout, ": "); | |
fa8a61dc | 5265 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
5266 | do_cleanups (ui_out_chain); |
5267 | break; | |
5268 | case bp_access_watchpoint: | |
5269 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
5270 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
5271 | ui_out_field_int (uiout, "number", b->number); | |
5272 | ui_out_text (uiout, ": "); | |
fa8a61dc | 5273 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
5274 | do_cleanups (ui_out_chain); |
5275 | break; | |
5276 | case bp_breakpoint: | |
5277 | if (ui_out_is_mi_like_p (uiout)) | |
5278 | { | |
5279 | say_where = 0; | |
5280 | break; | |
5281 | } | |
2cec12e5 AR |
5282 | if (b->disposition == disp_del) |
5283 | printf_filtered (_("Temporary breakpoint")); | |
5284 | else | |
5285 | printf_filtered (_("Breakpoint")); | |
5286 | printf_filtered (_(" %d"), b->number); | |
3086aeae DJ |
5287 | say_where = 1; |
5288 | break; | |
5289 | case bp_hardware_breakpoint: | |
5290 | if (ui_out_is_mi_like_p (uiout)) | |
5291 | { | |
5292 | say_where = 0; | |
5293 | break; | |
5294 | } | |
a3f17187 | 5295 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); |
3086aeae DJ |
5296 | say_where = 1; |
5297 | break; | |
1042e4c0 SS |
5298 | case bp_tracepoint: |
5299 | if (ui_out_is_mi_like_p (uiout)) | |
5300 | { | |
5301 | say_where = 0; | |
5302 | break; | |
5303 | } | |
5304 | printf_filtered (_("Tracepoint")); | |
5305 | printf_filtered (_(" %d"), b->number); | |
5306 | say_where = 1; | |
5307 | break; | |
3086aeae DJ |
5308 | |
5309 | case bp_until: | |
5310 | case bp_finish: | |
5311 | case bp_longjmp: | |
5312 | case bp_longjmp_resume: | |
5313 | case bp_step_resume: | |
3086aeae DJ |
5314 | case bp_call_dummy: |
5315 | case bp_watchpoint_scope: | |
5316 | case bp_shlib_event: | |
5317 | case bp_thread_event: | |
5318 | case bp_overlay_event: | |
0fd8e87f | 5319 | case bp_longjmp_master: |
3086aeae DJ |
5320 | break; |
5321 | } | |
c906108c | 5322 | |
c906108c SS |
5323 | if (say_where) |
5324 | { | |
a3f17187 AC |
5325 | /* i18n: cagney/2005-02-11: Below needs to be merged into a |
5326 | single string. */ | |
0d381245 | 5327 | if (b->loc == NULL) |
c906108c | 5328 | { |
a3f17187 | 5329 | printf_filtered (_(" (%s) pending."), b->addr_string); |
0101ce28 JJ |
5330 | } |
5331 | else | |
5332 | { | |
79a45b7d | 5333 | if (opts.addressprint || b->source_file == NULL) |
0101ce28 JJ |
5334 | { |
5335 | printf_filtered (" at "); | |
5af949e3 UW |
5336 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), |
5337 | gdb_stdout); | |
0101ce28 JJ |
5338 | } |
5339 | if (b->source_file) | |
5340 | printf_filtered (": file %s, line %d.", | |
5341 | b->source_file, b->line_number); | |
0d381245 VP |
5342 | |
5343 | if (b->loc->next) | |
5344 | { | |
5345 | struct bp_location *loc = b->loc; | |
5346 | int n = 0; | |
5347 | for (; loc; loc = loc->next) | |
5348 | ++n; | |
5349 | printf_filtered (" (%d locations)", n); | |
5350 | } | |
5351 | ||
c906108c | 5352 | } |
c906108c | 5353 | } |
9dc5e2a9 | 5354 | if (ui_out_is_mi_like_p (uiout)) |
fb40c209 | 5355 | return; |
c906108c SS |
5356 | printf_filtered ("\n"); |
5357 | } | |
c906108c | 5358 | \f |
c5aa993b | 5359 | |
0d381245 | 5360 | static struct bp_location * |
39d61571 | 5361 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
5362 | const struct symtab_and_line *sal) |
5363 | { | |
5364 | struct bp_location *loc, **tmp; | |
5365 | ||
39d61571 | 5366 | loc = allocate_bp_location (b); |
0d381245 VP |
5367 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
5368 | ; | |
5369 | *tmp = loc; | |
a6d9a66e UW |
5370 | loc->gdbarch = get_sal_arch (*sal); |
5371 | if (!loc->gdbarch) | |
5372 | loc->gdbarch = b->gdbarch; | |
0d381245 | 5373 | loc->requested_address = sal->pc; |
a6d9a66e UW |
5374 | loc->address = adjust_breakpoint_address (loc->gdbarch, |
5375 | loc->requested_address, b->type); | |
0d381245 VP |
5376 | loc->section = sal->section; |
5377 | ||
5378 | set_breakpoint_location_function (loc); | |
5379 | return loc; | |
5380 | } | |
514f746b AR |
5381 | \f |
5382 | ||
5383 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
5384 | return 0 otherwise. */ | |
5385 | ||
5386 | static int | |
5387 | bp_loc_is_permanent (struct bp_location *loc) | |
5388 | { | |
5389 | int len; | |
5390 | CORE_ADDR addr; | |
5391 | const gdb_byte *brk; | |
5392 | gdb_byte *target_mem; | |
939c61fa JK |
5393 | struct cleanup *cleanup; |
5394 | int retval = 0; | |
514f746b AR |
5395 | |
5396 | gdb_assert (loc != NULL); | |
5397 | ||
5398 | addr = loc->address; | |
a6d9a66e | 5399 | brk = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len); |
514f746b | 5400 | |
939c61fa JK |
5401 | /* Software breakpoints unsupported? */ |
5402 | if (brk == NULL) | |
5403 | return 0; | |
5404 | ||
514f746b AR |
5405 | target_mem = alloca (len); |
5406 | ||
939c61fa JK |
5407 | /* Enable the automatic memory restoration from breakpoints while |
5408 | we read the memory. Otherwise we could say about our temporary | |
5409 | breakpoints they are permanent. */ | |
5410 | cleanup = make_show_memory_breakpoints_cleanup (0); | |
5411 | ||
514f746b AR |
5412 | if (target_read_memory (loc->address, target_mem, len) == 0 |
5413 | && memcmp (target_mem, brk, len) == 0) | |
939c61fa | 5414 | retval = 1; |
514f746b | 5415 | |
939c61fa JK |
5416 | do_cleanups (cleanup); |
5417 | ||
5418 | return retval; | |
514f746b AR |
5419 | } |
5420 | ||
5421 | ||
c3f6f71d | 5422 | |
018d34a4 VP |
5423 | /* Create a breakpoint with SAL as location. Use ADDR_STRING |
5424 | as textual description of the location, and COND_STRING | |
db107f19 | 5425 | as condition expression. */ |
018d34a4 VP |
5426 | |
5427 | static void | |
a6d9a66e UW |
5428 | create_breakpoint (struct gdbarch *gdbarch, |
5429 | struct symtabs_and_lines sals, char *addr_string, | |
018d34a4 VP |
5430 | char *cond_string, |
5431 | enum bptype type, enum bpdisp disposition, | |
4a306c9a | 5432 | int thread, int task, int ignore_count, |
41447f92 | 5433 | struct breakpoint_ops *ops, int from_tty, int enabled) |
018d34a4 | 5434 | { |
0d381245 VP |
5435 | struct breakpoint *b = NULL; |
5436 | int i; | |
018d34a4 VP |
5437 | |
5438 | if (type == bp_hardware_breakpoint) | |
5439 | { | |
5440 | int i = hw_breakpoint_used_count (); | |
5441 | int target_resources_ok = | |
d92524f1 | 5442 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
018d34a4 VP |
5443 | i + 1, 0); |
5444 | if (target_resources_ok == 0) | |
5445 | error (_("No hardware breakpoint support in the target.")); | |
5446 | else if (target_resources_ok < 0) | |
5447 | error (_("Hardware breakpoints used exceeds limit.")); | |
5448 | } | |
5449 | ||
0d381245 VP |
5450 | for (i = 0; i < sals.nelts; ++i) |
5451 | { | |
5452 | struct symtab_and_line sal = sals.sals[i]; | |
5453 | struct bp_location *loc; | |
5454 | ||
5455 | if (from_tty) | |
5af949e3 UW |
5456 | { |
5457 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
5458 | if (!loc_gdbarch) | |
5459 | loc_gdbarch = gdbarch; | |
5460 | ||
5461 | describe_other_breakpoints (loc_gdbarch, | |
5462 | sal.pc, sal.section, thread); | |
5463 | } | |
0d381245 VP |
5464 | |
5465 | if (i == 0) | |
5466 | { | |
a6d9a66e | 5467 | b = set_raw_breakpoint (gdbarch, sal, type); |
0d381245 VP |
5468 | set_breakpoint_count (breakpoint_count + 1); |
5469 | b->number = breakpoint_count; | |
5470 | b->thread = thread; | |
4a306c9a | 5471 | b->task = task; |
018d34a4 | 5472 | |
0d381245 VP |
5473 | b->cond_string = cond_string; |
5474 | b->ignore_count = ignore_count; | |
41447f92 | 5475 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 5476 | b->disposition = disposition; |
018d34a4 | 5477 | |
8bea4e01 UW |
5478 | if (enabled && executing_startup |
5479 | && (b->type == bp_breakpoint | |
5480 | || b->type == bp_hardware_breakpoint)) | |
5481 | b->enable_state = bp_startup_disabled; | |
5482 | ||
0d381245 VP |
5483 | loc = b->loc; |
5484 | } | |
5485 | else | |
018d34a4 | 5486 | { |
39d61571 | 5487 | loc = add_location_to_breakpoint (b, &sal); |
0d381245 VP |
5488 | } |
5489 | ||
514f746b AR |
5490 | if (bp_loc_is_permanent (loc)) |
5491 | make_breakpoint_permanent (b); | |
5492 | ||
0d381245 VP |
5493 | if (b->cond_string) |
5494 | { | |
5495 | char *arg = b->cond_string; | |
d32a6982 | 5496 | loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0); |
0d381245 | 5497 | if (*arg) |
db107f19 | 5498 | error (_("Garbage %s follows condition"), arg); |
018d34a4 | 5499 | } |
0d381245 | 5500 | } |
018d34a4 VP |
5501 | |
5502 | if (addr_string) | |
5503 | b->addr_string = addr_string; | |
5504 | else | |
5505 | /* addr_string has to be used or breakpoint_re_set will delete | |
5506 | me. */ | |
5af949e3 UW |
5507 | b->addr_string |
5508 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
018d34a4 | 5509 | |
604133b5 | 5510 | b->ops = ops; |
018d34a4 VP |
5511 | mention (b); |
5512 | } | |
5513 | ||
ed0616c6 VP |
5514 | /* Remove element at INDEX_TO_REMOVE from SAL, shifting other |
5515 | elements to fill the void space. */ | |
2c0b251b PA |
5516 | static void |
5517 | remove_sal (struct symtabs_and_lines *sal, int index_to_remove) | |
ed0616c6 VP |
5518 | { |
5519 | int i = index_to_remove+1; | |
5520 | int last_index = sal->nelts-1; | |
5521 | ||
5522 | for (;i <= last_index; ++i) | |
5523 | sal->sals[i-1] = sal->sals[i]; | |
5524 | ||
5525 | --(sal->nelts); | |
5526 | } | |
5527 | ||
5528 | /* If appropriate, obtains all sals that correspond | |
5529 | to the same file and line as SAL. This is done | |
5530 | only if SAL does not have explicit PC and has | |
5531 | line and file information. If we got just a single | |
5532 | expanded sal, return the original. | |
5533 | ||
5534 | Otherwise, if SAL.explicit_line is not set, filter out | |
5535 | all sals for which the name of enclosing function | |
5536 | is different from SAL. This makes sure that if we have | |
5537 | breakpoint originally set in template instantiation, say | |
5538 | foo<int>(), we won't expand SAL to locations at the same | |
5539 | line in all existing instantiations of 'foo'. | |
5540 | ||
5541 | */ | |
2c0b251b | 5542 | static struct symtabs_and_lines |
ed0616c6 VP |
5543 | expand_line_sal_maybe (struct symtab_and_line sal) |
5544 | { | |
5545 | struct symtabs_and_lines expanded; | |
5546 | CORE_ADDR original_pc = sal.pc; | |
5547 | char *original_function = NULL; | |
5548 | int found; | |
5549 | int i; | |
5550 | ||
5551 | /* If we have explicit pc, don't expand. | |
5552 | If we have no line number, we can't expand. */ | |
5553 | if (sal.explicit_pc || sal.line == 0 || sal.symtab == NULL) | |
5554 | { | |
5555 | expanded.nelts = 1; | |
5556 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
5557 | expanded.sals[0] = sal; | |
5558 | return expanded; | |
5559 | } | |
5560 | ||
5561 | sal.pc = 0; | |
5562 | find_pc_partial_function (original_pc, &original_function, NULL, NULL); | |
5563 | ||
5564 | expanded = expand_line_sal (sal); | |
5565 | if (expanded.nelts == 1) | |
5566 | { | |
5567 | /* We had one sal, we got one sal. Without futher | |
5568 | processing, just return the original sal. */ | |
5569 | xfree (expanded.sals); | |
5570 | expanded.nelts = 1; | |
5571 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
5572 | sal.pc = original_pc; | |
5573 | expanded.sals[0] = sal; | |
5574 | return expanded; | |
5575 | } | |
5576 | ||
5577 | if (!sal.explicit_line) | |
5578 | { | |
5579 | CORE_ADDR func_addr, func_end; | |
5580 | for (i = 0; i < expanded.nelts; ++i) | |
5581 | { | |
5582 | CORE_ADDR pc = expanded.sals[i].pc; | |
5583 | char *this_function; | |
5584 | if (find_pc_partial_function (pc, &this_function, | |
5585 | &func_addr, &func_end)) | |
5586 | { | |
059fb39f PM |
5587 | if (this_function |
5588 | && strcmp (this_function, original_function) != 0) | |
ed0616c6 VP |
5589 | { |
5590 | remove_sal (&expanded, i); | |
5591 | --i; | |
5592 | } | |
5593 | else if (func_addr == pc) | |
5594 | { | |
5595 | /* We're at beginning of a function, and should | |
5596 | skip prologue. */ | |
5597 | struct symbol *sym = find_pc_function (pc); | |
5598 | if (sym) | |
5599 | expanded.sals[i] = find_function_start_sal (sym, 1); | |
5600 | else | |
d80b854b UW |
5601 | { |
5602 | /* Since find_pc_partial_function returned true, | |
5603 | we should really always find the section here. */ | |
5604 | struct obj_section *section = find_pc_section (pc); | |
5605 | if (section) | |
5606 | { | |
5607 | struct gdbarch *gdbarch | |
5608 | = get_objfile_arch (section->objfile); | |
5609 | expanded.sals[i].pc | |
5610 | = gdbarch_skip_prologue (gdbarch, pc); | |
5611 | } | |
5612 | } | |
ed0616c6 VP |
5613 | } |
5614 | } | |
5615 | } | |
5616 | } | |
3daf8fe5 JG |
5617 | else |
5618 | { | |
5619 | for (i = 0; i < expanded.nelts; ++i) | |
5620 | { | |
5621 | /* If this SAL corresponds to a breakpoint inserted using a | |
5622 | line number, then skip the function prologue if necessary. */ | |
5623 | skip_prologue_sal (&expanded.sals[i]); | |
5624 | } | |
5625 | } | |
ed0616c6 VP |
5626 | |
5627 | ||
5628 | if (expanded.nelts <= 1) | |
5629 | { | |
5630 | /* This is un ugly workaround. If we get zero | |
5631 | expanded sals then something is really wrong. | |
5632 | Fix that by returnign the original sal. */ | |
5633 | xfree (expanded.sals); | |
5634 | expanded.nelts = 1; | |
5635 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
5636 | sal.pc = original_pc; | |
5637 | expanded.sals[0] = sal; | |
5638 | return expanded; | |
5639 | } | |
5640 | ||
5641 | if (original_pc) | |
5642 | { | |
5643 | found = 0; | |
5644 | for (i = 0; i < expanded.nelts; ++i) | |
5645 | if (expanded.sals[i].pc == original_pc) | |
5646 | { | |
5647 | found = 1; | |
5648 | break; | |
5649 | } | |
5650 | gdb_assert (found); | |
5651 | } | |
5652 | ||
5653 | return expanded; | |
5654 | } | |
5655 | ||
018d34a4 VP |
5656 | /* Add SALS.nelts breakpoints to the breakpoint table. For each |
5657 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
5658 | value. COND_STRING, if not NULL, specified the condition to be | |
5659 | used for all breakpoints. Essentially the only case where | |
5660 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
5661 | function. In that case, it's still not possible to specify | |
5662 | separate conditions for different overloaded functions, so | |
5663 | we take just a single condition string. | |
5664 | ||
c3f6f71d | 5665 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 5666 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
5667 | array contents). If the function fails (error() is called), the |
5668 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
5669 | COND and SALS arrays and each of those arrays contents. */ | |
c906108c SS |
5670 | |
5671 | static void | |
a6d9a66e UW |
5672 | create_breakpoints (struct gdbarch *gdbarch, |
5673 | struct symtabs_and_lines sals, char **addr_string, | |
018d34a4 | 5674 | char *cond_string, |
c3f6f71d | 5675 | enum bptype type, enum bpdisp disposition, |
4a306c9a | 5676 | int thread, int task, int ignore_count, |
41447f92 VP |
5677 | struct breakpoint_ops *ops, int from_tty, |
5678 | int enabled) | |
c906108c | 5679 | { |
018d34a4 VP |
5680 | int i; |
5681 | for (i = 0; i < sals.nelts; ++i) | |
c3f6f71d | 5682 | { |
ed0616c6 VP |
5683 | struct symtabs_and_lines expanded = |
5684 | expand_line_sal_maybe (sals.sals[i]); | |
0d381245 | 5685 | |
a6d9a66e | 5686 | create_breakpoint (gdbarch, expanded, addr_string[i], |
018d34a4 | 5687 | cond_string, type, disposition, |
4a306c9a | 5688 | thread, task, ignore_count, ops, from_tty, enabled); |
c3f6f71d | 5689 | } |
c3f6f71d | 5690 | } |
c906108c | 5691 | |
c3f6f71d JM |
5692 | /* Parse ARG which is assumed to be a SAL specification possibly |
5693 | followed by conditionals. On return, SALS contains an array of SAL | |
5694 | addresses found. ADDR_STRING contains a vector of (canonical) | |
5695 | address strings. ARG points to the end of the SAL. */ | |
c906108c | 5696 | |
b9362cc7 | 5697 | static void |
c3f6f71d JM |
5698 | parse_breakpoint_sals (char **address, |
5699 | struct symtabs_and_lines *sals, | |
0101ce28 JJ |
5700 | char ***addr_string, |
5701 | int *not_found_ptr) | |
c3f6f71d JM |
5702 | { |
5703 | char *addr_start = *address; | |
5704 | *addr_string = NULL; | |
5705 | /* If no arg given, or if first arg is 'if ', use the default | |
5706 | breakpoint. */ | |
5707 | if ((*address) == NULL | |
5708 | || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2]))) | |
c906108c SS |
5709 | { |
5710 | if (default_breakpoint_valid) | |
5711 | { | |
c3f6f71d | 5712 | struct symtab_and_line sal; |
fe39c653 | 5713 | init_sal (&sal); /* initialize to zeroes */ |
c3f6f71d | 5714 | sals->sals = (struct symtab_and_line *) |
c906108c SS |
5715 | xmalloc (sizeof (struct symtab_and_line)); |
5716 | sal.pc = default_breakpoint_address; | |
5717 | sal.line = default_breakpoint_line; | |
5718 | sal.symtab = default_breakpoint_symtab; | |
c5aa993b | 5719 | sal.section = find_pc_overlay (sal.pc); |
00903456 JK |
5720 | |
5721 | /* "break" without arguments is equivalent to "break *PC" where PC is | |
5722 | the default_breakpoint_address. So make sure to set | |
5723 | sal.explicit_pc to prevent GDB from trying to expand the list of | |
5724 | sals to include all other instances with the same symtab and line. | |
5725 | */ | |
5726 | sal.explicit_pc = 1; | |
5727 | ||
c3f6f71d JM |
5728 | sals->sals[0] = sal; |
5729 | sals->nelts = 1; | |
c906108c SS |
5730 | } |
5731 | else | |
8a3fe4f8 | 5732 | error (_("No default breakpoint address now.")); |
c906108c SS |
5733 | } |
5734 | else | |
5735 | { | |
c906108c | 5736 | /* Force almost all breakpoints to be in terms of the |
c5aa993b JM |
5737 | current_source_symtab (which is decode_line_1's default). This |
5738 | should produce the results we want almost all of the time while | |
1aeae86e AF |
5739 | leaving default_breakpoint_* alone. |
5740 | ObjC: However, don't match an Objective-C method name which | |
5741 | may have a '+' or '-' succeeded by a '[' */ | |
0378c332 | 5742 | |
c214a6fd | 5743 | struct symtab_and_line cursal = get_current_source_symtab_and_line (); |
0378c332 | 5744 | |
c906108c | 5745 | if (default_breakpoint_valid |
0378c332 | 5746 | && (!cursal.symtab |
1aeae86e AF |
5747 | || ((strchr ("+-", (*address)[0]) != NULL) |
5748 | && ((*address)[1] != '[')))) | |
c3f6f71d | 5749 | *sals = decode_line_1 (address, 1, default_breakpoint_symtab, |
0101ce28 JJ |
5750 | default_breakpoint_line, addr_string, |
5751 | not_found_ptr); | |
c906108c | 5752 | else |
0101ce28 JJ |
5753 | *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0, |
5754 | addr_string, not_found_ptr); | |
c906108c | 5755 | } |
c3f6f71d JM |
5756 | /* For any SAL that didn't have a canonical string, fill one in. */ |
5757 | if (sals->nelts > 0 && *addr_string == NULL) | |
5758 | *addr_string = xcalloc (sals->nelts, sizeof (char **)); | |
5759 | if (addr_start != (*address)) | |
c906108c | 5760 | { |
c3f6f71d JM |
5761 | int i; |
5762 | for (i = 0; i < sals->nelts; i++) | |
c906108c | 5763 | { |
c3f6f71d JM |
5764 | /* Add the string if not present. */ |
5765 | if ((*addr_string)[i] == NULL) | |
5766 | (*addr_string)[i] = savestring (addr_start, (*address) - addr_start); | |
c906108c SS |
5767 | } |
5768 | } | |
c3f6f71d | 5769 | } |
c906108c | 5770 | |
c906108c | 5771 | |
c3f6f71d JM |
5772 | /* Convert each SAL into a real PC. Verify that the PC can be |
5773 | inserted as a breakpoint. If it can't throw an error. */ | |
c906108c | 5774 | |
b9362cc7 | 5775 | static void |
c3f6f71d JM |
5776 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals, |
5777 | char *address) | |
5778 | { | |
5779 | int i; | |
5780 | for (i = 0; i < sals->nelts; i++) | |
ee53e872 | 5781 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
5782 | } |
5783 | ||
05ff989b | 5784 | static void |
0101ce28 JJ |
5785 | do_captured_parse_breakpoint (struct ui_out *ui, void *data) |
5786 | { | |
5787 | struct captured_parse_breakpoint_args *args = data; | |
5788 | ||
5789 | parse_breakpoint_sals (args->arg_p, args->sals_p, args->addr_string_p, | |
5790 | args->not_found_ptr); | |
0101ce28 JJ |
5791 | } |
5792 | ||
018d34a4 VP |
5793 | /* Given TOK, a string specification of condition and thread, as |
5794 | accepted by the 'break' command, extract the condition | |
5795 | string and thread number and set *COND_STRING and *THREAD. | |
5796 | PC identifies the context at which the condition should be parsed. | |
5797 | If no condition is found, *COND_STRING is set to NULL. | |
5798 | If no thread is found, *THREAD is set to -1. */ | |
5799 | static void | |
5800 | find_condition_and_thread (char *tok, CORE_ADDR pc, | |
4a306c9a | 5801 | char **cond_string, int *thread, int *task) |
018d34a4 VP |
5802 | { |
5803 | *cond_string = NULL; | |
5804 | *thread = -1; | |
5805 | while (tok && *tok) | |
5806 | { | |
5807 | char *end_tok; | |
5808 | int toklen; | |
5809 | char *cond_start = NULL; | |
5810 | char *cond_end = NULL; | |
5811 | while (*tok == ' ' || *tok == '\t') | |
5812 | tok++; | |
5813 | ||
5814 | end_tok = tok; | |
5815 | ||
5816 | while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') | |
5817 | end_tok++; | |
5818 | ||
5819 | toklen = end_tok - tok; | |
5820 | ||
5821 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
5822 | { | |
f7545552 TT |
5823 | struct expression *expr; |
5824 | ||
018d34a4 | 5825 | tok = cond_start = end_tok + 1; |
f7545552 TT |
5826 | expr = parse_exp_1 (&tok, block_for_pc (pc), 0); |
5827 | xfree (expr); | |
018d34a4 VP |
5828 | cond_end = tok; |
5829 | *cond_string = savestring (cond_start, | |
5830 | cond_end - cond_start); | |
5831 | } | |
5832 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
5833 | { | |
5834 | char *tmptok; | |
5835 | ||
5836 | tok = end_tok + 1; | |
5837 | tmptok = tok; | |
5838 | *thread = strtol (tok, &tok, 0); | |
5839 | if (tok == tmptok) | |
5840 | error (_("Junk after thread keyword.")); | |
5841 | if (!valid_thread_id (*thread)) | |
5842 | error (_("Unknown thread %d."), *thread); | |
5843 | } | |
4a306c9a JB |
5844 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
5845 | { | |
5846 | char *tmptok; | |
5847 | ||
5848 | tok = end_tok + 1; | |
5849 | tmptok = tok; | |
5850 | *task = strtol (tok, &tok, 0); | |
5851 | if (tok == tmptok) | |
5852 | error (_("Junk after task keyword.")); | |
5853 | if (!valid_task_id (*task)) | |
5854 | error (_("Unknown task %d\n"), *task); | |
5855 | } | |
018d34a4 VP |
5856 | else |
5857 | error (_("Junk at end of arguments.")); | |
5858 | } | |
5859 | } | |
5860 | ||
72b2ff0e VP |
5861 | /* Set a breakpoint. This function is shared between |
5862 | CLI and MI functions for setting a breakpoint. | |
5863 | This function has two major modes of operations, | |
5864 | selected by the PARSE_CONDITION_AND_THREAD parameter. | |
5865 | If non-zero, the function will parse arg, extracting | |
5866 | breakpoint location, address and thread. Otherwise, | |
5867 | ARG is just the location of breakpoint, with condition | |
5868 | and thread specified by the COND_STRING and THREAD | |
5869 | parameters. */ | |
0101ce28 | 5870 | |
98deb0da | 5871 | static void |
a6d9a66e UW |
5872 | break_command_really (struct gdbarch *gdbarch, |
5873 | char *arg, char *cond_string, int thread, | |
60c46647 | 5874 | int parse_condition_and_thread, |
1042e4c0 | 5875 | int tempflag, int hardwareflag, int traceflag, |
60c46647 VP |
5876 | int ignore_count, |
5877 | enum auto_boolean pending_break_support, | |
604133b5 | 5878 | struct breakpoint_ops *ops, |
41447f92 VP |
5879 | int from_tty, |
5880 | int enabled) | |
c3f6f71d | 5881 | { |
71fff37b | 5882 | struct gdb_exception e; |
c3f6f71d | 5883 | struct symtabs_and_lines sals; |
0101ce28 | 5884 | struct symtab_and_line pending_sal; |
0101ce28 JJ |
5885 | char *copy_arg; |
5886 | char *err_msg; | |
c3f6f71d JM |
5887 | char *addr_start = arg; |
5888 | char **addr_string; | |
5889 | struct cleanup *old_chain; | |
80c99de1 | 5890 | struct cleanup *bkpt_chain = NULL; |
0101ce28 | 5891 | struct captured_parse_breakpoint_args parse_args; |
05ff989b | 5892 | int i; |
0101ce28 | 5893 | int pending = 0; |
0101ce28 | 5894 | int not_found = 0; |
1042e4c0 | 5895 | enum bptype type_wanted; |
4a306c9a | 5896 | int task = 0; |
c3f6f71d | 5897 | |
c3f6f71d JM |
5898 | sals.sals = NULL; |
5899 | sals.nelts = 0; | |
5900 | addr_string = NULL; | |
c3f6f71d | 5901 | |
0101ce28 JJ |
5902 | parse_args.arg_p = &arg; |
5903 | parse_args.sals_p = &sals; | |
5904 | parse_args.addr_string_p = &addr_string; | |
5905 | parse_args.not_found_ptr = ¬_found; | |
5906 | ||
05ff989b AC |
5907 | e = catch_exception (uiout, do_captured_parse_breakpoint, |
5908 | &parse_args, RETURN_MASK_ALL); | |
0101ce28 JJ |
5909 | |
5910 | /* If caller is interested in rc value from parse, set value. */ | |
05ff989b | 5911 | switch (e.reason) |
0101ce28 | 5912 | { |
05ff989b | 5913 | case RETURN_QUIT: |
98deb0da | 5914 | throw_exception (e); |
05ff989b AC |
5915 | case RETURN_ERROR: |
5916 | switch (e.error) | |
0101ce28 | 5917 | { |
05ff989b | 5918 | case NOT_FOUND_ERROR: |
0101ce28 | 5919 | |
05ff989b AC |
5920 | /* If pending breakpoint support is turned off, throw |
5921 | error. */ | |
fa8d40ab JJ |
5922 | |
5923 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
5924 | throw_exception (e); |
5925 | ||
5926 | exception_print (gdb_stderr, e); | |
fa8d40ab | 5927 | |
05ff989b AC |
5928 | /* If pending breakpoint support is auto query and the user |
5929 | selects no, then simply return the error code. */ | |
059fb39f PM |
5930 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
5931 | && !nquery ("Make breakpoint pending on future shared library load? ")) | |
98deb0da | 5932 | return; |
fa8d40ab | 5933 | |
05ff989b AC |
5934 | /* At this point, either the user was queried about setting |
5935 | a pending breakpoint and selected yes, or pending | |
5936 | breakpoint behavior is on and thus a pending breakpoint | |
5937 | is defaulted on behalf of the user. */ | |
0101ce28 JJ |
5938 | copy_arg = xstrdup (addr_start); |
5939 | addr_string = ©_arg; | |
5940 | sals.nelts = 1; | |
5941 | sals.sals = &pending_sal; | |
5942 | pending_sal.pc = 0; | |
5943 | pending = 1; | |
05ff989b AC |
5944 | break; |
5945 | default: | |
98deb0da | 5946 | throw_exception (e); |
0101ce28 | 5947 | } |
05ff989b AC |
5948 | default: |
5949 | if (!sals.nelts) | |
98deb0da | 5950 | return; |
0101ce28 | 5951 | } |
c3f6f71d JM |
5952 | |
5953 | /* Create a chain of things that always need to be cleaned up. */ | |
5954 | old_chain = make_cleanup (null_cleanup, 0); | |
5955 | ||
0101ce28 JJ |
5956 | if (!pending) |
5957 | { | |
5958 | /* Make sure that all storage allocated to SALS gets freed. */ | |
5959 | make_cleanup (xfree, sals.sals); | |
5960 | ||
5961 | /* Cleanup the addr_string array but not its contents. */ | |
5962 | make_cleanup (xfree, addr_string); | |
5963 | } | |
c3f6f71d | 5964 | |
c3f6f71d JM |
5965 | /* ----------------------------- SNIP ----------------------------- |
5966 | Anything added to the cleanup chain beyond this point is assumed | |
5967 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
5968 | then the memory is not reclaimed. */ |
5969 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d JM |
5970 | |
5971 | /* Mark the contents of the addr_string for cleanup. These go on | |
80c99de1 | 5972 | the bkpt_chain and only occur if the breakpoint create fails. */ |
c3f6f71d JM |
5973 | for (i = 0; i < sals.nelts; i++) |
5974 | { | |
5975 | if (addr_string[i] != NULL) | |
b8c9b27d | 5976 | make_cleanup (xfree, addr_string[i]); |
c3f6f71d JM |
5977 | } |
5978 | ||
5979 | /* Resolve all line numbers to PC's and verify that the addresses | |
5980 | are ok for the target. */ | |
0101ce28 JJ |
5981 | if (!pending) |
5982 | breakpoint_sals_to_pc (&sals, addr_start); | |
c3f6f71d | 5983 | |
1042e4c0 SS |
5984 | type_wanted = (traceflag |
5985 | ? bp_tracepoint | |
5986 | : (hardwareflag ? bp_hardware_breakpoint : bp_breakpoint)); | |
5987 | ||
c3f6f71d JM |
5988 | /* Verify that condition can be parsed, before setting any |
5989 | breakpoints. Allocate a separate condition expression for each | |
5990 | breakpoint. */ | |
0101ce28 | 5991 | if (!pending) |
c3f6f71d | 5992 | { |
2f069f6f | 5993 | if (parse_condition_and_thread) |
72b2ff0e VP |
5994 | { |
5995 | /* Here we only parse 'arg' to separate condition | |
5996 | from thread number, so parsing in context of first | |
5997 | sal is OK. When setting the breakpoint we'll | |
5998 | re-parse it in context of each sal. */ | |
5999 | cond_string = NULL; | |
6000 | thread = -1; | |
4a306c9a JB |
6001 | find_condition_and_thread (arg, sals.sals[0].pc, &cond_string, |
6002 | &thread, &task); | |
72b2ff0e VP |
6003 | if (cond_string) |
6004 | make_cleanup (xfree, cond_string); | |
6005 | } | |
2f069f6f | 6006 | else |
72b2ff0e VP |
6007 | { |
6008 | /* Create a private copy of condition string. */ | |
6009 | if (cond_string) | |
6010 | { | |
6011 | cond_string = xstrdup (cond_string); | |
6012 | make_cleanup (xfree, cond_string); | |
6013 | } | |
6014 | } | |
a6d9a66e | 6015 | create_breakpoints (gdbarch, sals, addr_string, cond_string, type_wanted, |
0101ce28 | 6016 | tempflag ? disp_del : disp_donttouch, |
4a306c9a | 6017 | thread, task, ignore_count, ops, from_tty, enabled); |
c906108c | 6018 | } |
0101ce28 JJ |
6019 | else |
6020 | { | |
fe3f5fa8 | 6021 | struct symtab_and_line sal = {0}; |
0101ce28 JJ |
6022 | struct breakpoint *b; |
6023 | ||
0101ce28 JJ |
6024 | make_cleanup (xfree, copy_arg); |
6025 | ||
a6d9a66e | 6026 | b = set_raw_breakpoint_without_location (gdbarch, type_wanted); |
0101ce28 JJ |
6027 | set_breakpoint_count (breakpoint_count + 1); |
6028 | b->number = breakpoint_count; | |
72b2ff0e | 6029 | b->thread = -1; |
018d34a4 | 6030 | b->addr_string = addr_string[0]; |
72b2ff0e | 6031 | b->cond_string = NULL; |
0101ce28 | 6032 | b->ignore_count = ignore_count; |
0101ce28 | 6033 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 6034 | b->condition_not_parsed = 1; |
604133b5 | 6035 | b->ops = ops; |
41447f92 | 6036 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
74960c60 | 6037 | |
8bea4e01 UW |
6038 | if (enabled && executing_startup |
6039 | && (b->type == bp_breakpoint | |
6040 | || b->type == bp_hardware_breakpoint)) | |
6041 | b->enable_state = bp_startup_disabled; | |
6042 | ||
0101ce28 JJ |
6043 | mention (b); |
6044 | } | |
6045 | ||
c3f6f71d | 6046 | if (sals.nelts > 1) |
8a3fe4f8 AC |
6047 | warning (_("Multiple breakpoints were set.\n" |
6048 | "Use the \"delete\" command to delete unwanted breakpoints.")); | |
80c99de1 PA |
6049 | /* That's it. Discard the cleanups for data inserted into the |
6050 | breakpoint. */ | |
6051 | discard_cleanups (bkpt_chain); | |
6052 | /* But cleanup everything else. */ | |
c3f6f71d | 6053 | do_cleanups (old_chain); |
217dc9e2 | 6054 | |
80c99de1 | 6055 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
217dc9e2 | 6056 | update_global_location_list (1); |
c3f6f71d | 6057 | } |
c906108c | 6058 | |
72b2ff0e VP |
6059 | /* Set a breakpoint. |
6060 | ARG is a string describing breakpoint address, | |
6061 | condition, and thread. | |
6062 | FLAG specifies if a breakpoint is hardware on, | |
6063 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
6064 | and BP_TEMPFLAG. */ | |
6065 | ||
98deb0da | 6066 | static void |
72b2ff0e | 6067 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 6068 | { |
72b2ff0e VP |
6069 | int hardwareflag = flag & BP_HARDWAREFLAG; |
6070 | int tempflag = flag & BP_TEMPFLAG; | |
c3f6f71d | 6071 | |
a6d9a66e UW |
6072 | break_command_really (get_current_arch (), |
6073 | arg, | |
98deb0da | 6074 | NULL, 0, 1 /* parse arg */, |
1042e4c0 | 6075 | tempflag, hardwareflag, 0 /* traceflag */, |
98deb0da | 6076 | 0 /* Ignore count */, |
604133b5 AR |
6077 | pending_break_support, |
6078 | NULL /* breakpoint_ops */, | |
41447f92 VP |
6079 | from_tty, |
6080 | 1 /* enabled */); | |
c906108c SS |
6081 | } |
6082 | ||
72b2ff0e | 6083 | |
98deb0da | 6084 | void |
a6d9a66e UW |
6085 | set_breakpoint (struct gdbarch *gdbarch, |
6086 | char *address, char *condition, | |
c3f6f71d | 6087 | int hardwareflag, int tempflag, |
ce43223b | 6088 | int thread, int ignore_count, |
41447f92 | 6089 | int pending, int enabled) |
c3f6f71d | 6090 | { |
a6d9a66e UW |
6091 | break_command_really (gdbarch, |
6092 | address, condition, thread, | |
98deb0da | 6093 | 0 /* condition and thread are valid. */, |
1042e4c0 | 6094 | tempflag, hardwareflag, 0 /* traceflag */, |
98deb0da VP |
6095 | ignore_count, |
6096 | pending | |
6097 | ? AUTO_BOOLEAN_TRUE : AUTO_BOOLEAN_FALSE, | |
41447f92 | 6098 | NULL, 0, enabled); |
c3f6f71d JM |
6099 | } |
6100 | ||
6a048695 JB |
6101 | /* Adjust SAL to the first instruction past the function prologue. |
6102 | The end of the prologue is determined using the line table from | |
3daf8fe5 JG |
6103 | the debugging information. explicit_pc and explicit_line are |
6104 | not modified. | |
6a048695 JB |
6105 | |
6106 | If SAL is already past the prologue, then do nothing. */ | |
6107 | ||
6108 | static void | |
6109 | skip_prologue_sal (struct symtab_and_line *sal) | |
6110 | { | |
6111 | struct symbol *sym = find_pc_function (sal->pc); | |
6112 | struct symtab_and_line start_sal; | |
6113 | ||
6114 | if (sym == NULL) | |
6115 | return; | |
6116 | ||
6117 | start_sal = find_function_start_sal (sym, 1); | |
6118 | if (sal->pc < start_sal.pc) | |
3daf8fe5 JG |
6119 | { |
6120 | start_sal.explicit_line = sal->explicit_line; | |
6121 | start_sal.explicit_pc = sal->explicit_pc; | |
6122 | *sal = start_sal; | |
6123 | } | |
6a048695 | 6124 | } |
c3f6f71d | 6125 | |
c906108c SS |
6126 | /* Helper function for break_command_1 and disassemble_command. */ |
6127 | ||
6128 | void | |
fba45db2 | 6129 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
6130 | { |
6131 | CORE_ADDR pc; | |
6132 | ||
6133 | if (sal->pc == 0 && sal->symtab != NULL) | |
6134 | { | |
6135 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 6136 | error (_("No line %d in file \"%s\"."), |
c906108c SS |
6137 | sal->line, sal->symtab->filename); |
6138 | sal->pc = pc; | |
6a048695 JB |
6139 | |
6140 | /* If this SAL corresponds to a breakpoint inserted using | |
6141 | a line number, then skip the function prologue if necessary. */ | |
6142 | if (sal->explicit_line) | |
56ef84b1 TT |
6143 | { |
6144 | /* Preserve the original line number. */ | |
6145 | int saved_line = sal->line; | |
6146 | skip_prologue_sal (sal); | |
6147 | sal->line = saved_line; | |
6148 | } | |
c906108c SS |
6149 | } |
6150 | ||
6151 | if (sal->section == 0 && sal->symtab != NULL) | |
6152 | { | |
6153 | struct blockvector *bv; | |
c5aa993b JM |
6154 | struct block *b; |
6155 | struct symbol *sym; | |
c906108c | 6156 | |
801e3a5b | 6157 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab); |
c906108c SS |
6158 | if (bv != NULL) |
6159 | { | |
7f0df278 | 6160 | sym = block_linkage_function (b); |
c906108c SS |
6161 | if (sym != NULL) |
6162 | { | |
6163 | fixup_symbol_section (sym, sal->symtab->objfile); | |
714835d5 | 6164 | sal->section = SYMBOL_OBJ_SECTION (sym); |
c906108c SS |
6165 | } |
6166 | else | |
6167 | { | |
6168 | /* It really is worthwhile to have the section, so we'll just | |
c5aa993b JM |
6169 | have to look harder. This case can be executed if we have |
6170 | line numbers but no functions (as can happen in assembly | |
6171 | source). */ | |
c906108c | 6172 | |
c5aa993b | 6173 | struct minimal_symbol *msym; |
c906108c SS |
6174 | |
6175 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
6176 | if (msym) | |
714835d5 | 6177 | sal->section = SYMBOL_OBJ_SECTION (msym); |
c906108c SS |
6178 | } |
6179 | } | |
6180 | } | |
6181 | } | |
6182 | ||
6183 | void | |
fba45db2 | 6184 | break_command (char *arg, int from_tty) |
c906108c | 6185 | { |
db107f19 | 6186 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
6187 | } |
6188 | ||
c906108c | 6189 | void |
fba45db2 | 6190 | tbreak_command (char *arg, int from_tty) |
c906108c | 6191 | { |
db107f19 | 6192 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
6193 | } |
6194 | ||
c906108c | 6195 | static void |
fba45db2 | 6196 | hbreak_command (char *arg, int from_tty) |
c906108c | 6197 | { |
db107f19 | 6198 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
6199 | } |
6200 | ||
6201 | static void | |
fba45db2 | 6202 | thbreak_command (char *arg, int from_tty) |
c906108c | 6203 | { |
db107f19 | 6204 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
6205 | } |
6206 | ||
6207 | static void | |
fba45db2 | 6208 | stop_command (char *arg, int from_tty) |
c906108c | 6209 | { |
a3f17187 | 6210 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 6211 | Usage: stop in <function | address>\n\ |
a3f17187 | 6212 | stop at <line>\n")); |
c906108c SS |
6213 | } |
6214 | ||
6215 | static void | |
fba45db2 | 6216 | stopin_command (char *arg, int from_tty) |
c906108c SS |
6217 | { |
6218 | int badInput = 0; | |
6219 | ||
c5aa993b | 6220 | if (arg == (char *) NULL) |
c906108c SS |
6221 | badInput = 1; |
6222 | else if (*arg != '*') | |
6223 | { | |
6224 | char *argptr = arg; | |
6225 | int hasColon = 0; | |
6226 | ||
53a5351d JM |
6227 | /* look for a ':'. If this is a line number specification, then |
6228 | say it is bad, otherwise, it should be an address or | |
6229 | function/method name */ | |
c906108c | 6230 | while (*argptr && !hasColon) |
c5aa993b JM |
6231 | { |
6232 | hasColon = (*argptr == ':'); | |
6233 | argptr++; | |
6234 | } | |
c906108c SS |
6235 | |
6236 | if (hasColon) | |
c5aa993b | 6237 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 6238 | else |
c5aa993b | 6239 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
6240 | } |
6241 | ||
6242 | if (badInput) | |
a3f17187 | 6243 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 6244 | else |
db107f19 | 6245 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
6246 | } |
6247 | ||
6248 | static void | |
fba45db2 | 6249 | stopat_command (char *arg, int from_tty) |
c906108c SS |
6250 | { |
6251 | int badInput = 0; | |
6252 | ||
c5aa993b | 6253 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
6254 | badInput = 1; |
6255 | else | |
6256 | { | |
6257 | char *argptr = arg; | |
6258 | int hasColon = 0; | |
6259 | ||
6260 | /* look for a ':'. If there is a '::' then get out, otherwise | |
c5aa993b | 6261 | it is probably a line number. */ |
c906108c | 6262 | while (*argptr && !hasColon) |
c5aa993b JM |
6263 | { |
6264 | hasColon = (*argptr == ':'); | |
6265 | argptr++; | |
6266 | } | |
c906108c SS |
6267 | |
6268 | if (hasColon) | |
c5aa993b | 6269 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 6270 | else |
c5aa993b | 6271 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
6272 | } |
6273 | ||
6274 | if (badInput) | |
a3f17187 | 6275 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 6276 | else |
db107f19 | 6277 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
6278 | } |
6279 | ||
53a5351d JM |
6280 | /* accessflag: hw_write: watch write, |
6281 | hw_read: watch read, | |
6282 | hw_access: watch access (read or write) */ | |
c906108c | 6283 | static void |
fba45db2 | 6284 | watch_command_1 (char *arg, int accessflag, int from_tty) |
c906108c | 6285 | { |
a6d9a66e | 6286 | struct gdbarch *gdbarch = get_current_arch (); |
d983da9c | 6287 | struct breakpoint *b, *scope_breakpoint = NULL; |
c906108c SS |
6288 | struct symtab_and_line sal; |
6289 | struct expression *exp; | |
6290 | struct block *exp_valid_block; | |
6291 | struct value *val, *mark; | |
6292 | struct frame_info *frame; | |
c906108c SS |
6293 | char *exp_start = NULL; |
6294 | char *exp_end = NULL; | |
37e4754d | 6295 | char *tok, *id_tok_start, *end_tok; |
c906108c SS |
6296 | int toklen; |
6297 | char *cond_start = NULL; | |
6298 | char *cond_end = NULL; | |
6299 | struct expression *cond = NULL; | |
6300 | int i, other_type_used, target_resources_ok = 0; | |
6301 | enum bptype bp_type; | |
6302 | int mem_cnt = 0; | |
37e4754d | 6303 | int thread = -1; |
c906108c | 6304 | |
fe39c653 | 6305 | init_sal (&sal); /* initialize to zeroes */ |
c5aa993b | 6306 | |
37e4754d LM |
6307 | /* Make sure that we actually have parameters to parse. */ |
6308 | if (arg != NULL && arg[0] != '\0') | |
6309 | { | |
6310 | toklen = strlen (arg); /* Size of argument list. */ | |
6311 | ||
6312 | /* Points tok to the end of the argument list. */ | |
6313 | tok = arg + toklen - 1; | |
6314 | ||
6315 | /* Go backwards in the parameters list. Skip the last parameter. | |
6316 | If we're expecting a 'thread <thread_num>' parameter, this should | |
6317 | be the thread identifier. */ | |
6318 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
6319 | tok--; | |
6320 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
6321 | tok--; | |
6322 | ||
6323 | /* Points end_tok to the beginning of the last token. */ | |
6324 | id_tok_start = tok + 1; | |
6325 | ||
6326 | /* Go backwards in the parameters list. Skip one more parameter. | |
6327 | If we're expecting a 'thread <thread_num>' parameter, we should | |
6328 | reach a "thread" token. */ | |
6329 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
6330 | tok--; | |
6331 | ||
6332 | end_tok = tok; | |
6333 | ||
6334 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
6335 | tok--; | |
6336 | ||
6337 | /* Move the pointer forward to skip the whitespace and | |
6338 | calculate the length of the token. */ | |
6339 | tok++; | |
6340 | toklen = end_tok - tok; | |
6341 | ||
6342 | if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
6343 | { | |
6344 | /* At this point we've found a "thread" token, which means | |
6345 | the user is trying to set a watchpoint that triggers | |
6346 | only in a specific thread. */ | |
6347 | char *endp; | |
6348 | ||
6349 | /* Extract the thread ID from the next token. */ | |
6350 | thread = strtol (id_tok_start, &endp, 0); | |
6351 | ||
6352 | /* Check if the user provided a valid numeric value for the | |
6353 | thread ID. */ | |
6354 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
6355 | error (_("Invalid thread ID specification %s."), id_tok_start); | |
6356 | ||
6357 | /* Check if the thread actually exists. */ | |
6358 | if (!valid_thread_id (thread)) | |
6359 | error (_("Unknown thread %d."), thread); | |
6360 | ||
6361 | /* Truncate the string and get rid of the thread <thread_num> | |
6362 | parameter before the parameter list is parsed by the | |
6363 | evaluate_expression() function. */ | |
6364 | *tok = '\0'; | |
6365 | } | |
6366 | } | |
6367 | ||
6368 | /* Parse the rest of the arguments. */ | |
c906108c SS |
6369 | innermost_block = NULL; |
6370 | exp_start = arg; | |
6371 | exp = parse_exp_1 (&arg, 0, 0); | |
6372 | exp_end = arg; | |
fa8a61dc TT |
6373 | /* Remove trailing whitespace from the expression before saving it. |
6374 | This makes the eventual display of the expression string a bit | |
6375 | prettier. */ | |
6376 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
6377 | --exp_end; | |
6378 | ||
c906108c SS |
6379 | exp_valid_block = innermost_block; |
6380 | mark = value_mark (); | |
fa4727a6 DJ |
6381 | fetch_watchpoint_value (exp, &val, NULL, NULL); |
6382 | if (val != NULL) | |
6383 | release_value (val); | |
c906108c SS |
6384 | |
6385 | tok = arg; | |
6386 | while (*tok == ' ' || *tok == '\t') | |
6387 | tok++; | |
6388 | end_tok = tok; | |
6389 | ||
6390 | while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') | |
6391 | end_tok++; | |
6392 | ||
6393 | toklen = end_tok - tok; | |
6394 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
6395 | { | |
6396 | tok = cond_start = end_tok + 1; | |
6397 | cond = parse_exp_1 (&tok, 0, 0); | |
6398 | cond_end = tok; | |
6399 | } | |
6400 | if (*tok) | |
8a3fe4f8 | 6401 | error (_("Junk at end of command.")); |
c906108c | 6402 | |
53a5351d | 6403 | if (accessflag == hw_read) |
c5aa993b | 6404 | bp_type = bp_read_watchpoint; |
53a5351d | 6405 | else if (accessflag == hw_access) |
c5aa993b JM |
6406 | bp_type = bp_access_watchpoint; |
6407 | else | |
6408 | bp_type = bp_hardware_watchpoint; | |
c906108c SS |
6409 | |
6410 | mem_cnt = can_use_hardware_watchpoint (val); | |
6411 | if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint) | |
8a3fe4f8 | 6412 | error (_("Expression cannot be implemented with read/access watchpoint.")); |
c5aa993b JM |
6413 | if (mem_cnt != 0) |
6414 | { | |
6415 | i = hw_watchpoint_used_count (bp_type, &other_type_used); | |
53a5351d | 6416 | target_resources_ok = |
d92524f1 | 6417 | target_can_use_hardware_watchpoint (bp_type, i + mem_cnt, |
53a5351d | 6418 | other_type_used); |
c5aa993b | 6419 | if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint) |
8a3fe4f8 | 6420 | error (_("Target does not support this type of hardware watchpoint.")); |
53a5351d | 6421 | |
c5aa993b | 6422 | if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint) |
8a3fe4f8 | 6423 | error (_("Target can only support one kind of HW watchpoint at a time.")); |
c5aa993b | 6424 | } |
c906108c | 6425 | |
4d28f7a8 KB |
6426 | /* Change the type of breakpoint to an ordinary watchpoint if a hardware |
6427 | watchpoint could not be set. */ | |
6428 | if (!mem_cnt || target_resources_ok <= 0) | |
6429 | bp_type = bp_watchpoint; | |
6430 | ||
d983da9c | 6431 | frame = block_innermost_frame (exp_valid_block); |
d983da9c DJ |
6432 | |
6433 | /* If the expression is "local", then set up a "watchpoint scope" | |
6434 | breakpoint at the point where we've left the scope of the watchpoint | |
6435 | expression. Create the scope breakpoint before the watchpoint, so | |
6436 | that we will encounter it first in bpstat_stop_status. */ | |
edb3359d | 6437 | if (innermost_block && frame) |
d983da9c | 6438 | { |
edb3359d DJ |
6439 | if (frame_id_p (frame_unwind_caller_id (frame))) |
6440 | { | |
6441 | scope_breakpoint | |
a6d9a66e UW |
6442 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
6443 | frame_unwind_caller_pc (frame), | |
edb3359d | 6444 | bp_watchpoint_scope); |
d983da9c | 6445 | |
edb3359d | 6446 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 6447 | |
edb3359d DJ |
6448 | /* Automatically delete the breakpoint when it hits. */ |
6449 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 6450 | |
edb3359d DJ |
6451 | /* Only break in the proper frame (help with recursion). */ |
6452 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); | |
d983da9c | 6453 | |
edb3359d | 6454 | /* Set the address at which we will stop. */ |
a6d9a66e UW |
6455 | scope_breakpoint->loc->gdbarch |
6456 | = frame_unwind_caller_arch (frame); | |
edb3359d DJ |
6457 | scope_breakpoint->loc->requested_address |
6458 | = frame_unwind_caller_pc (frame); | |
6459 | scope_breakpoint->loc->address | |
a6d9a66e UW |
6460 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
6461 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
6462 | scope_breakpoint->type); |
6463 | } | |
d983da9c DJ |
6464 | } |
6465 | ||
c906108c | 6466 | /* Now set up the breakpoint. */ |
a6d9a66e | 6467 | b = set_raw_breakpoint (gdbarch, sal, bp_type); |
c906108c SS |
6468 | set_breakpoint_count (breakpoint_count + 1); |
6469 | b->number = breakpoint_count; | |
37e4754d | 6470 | b->thread = thread; |
b5de0fa7 | 6471 | b->disposition = disp_donttouch; |
c906108c SS |
6472 | b->exp = exp; |
6473 | b->exp_valid_block = exp_valid_block; | |
6474 | b->exp_string = savestring (exp_start, exp_end - exp_start); | |
6475 | b->val = val; | |
fa4727a6 | 6476 | b->val_valid = 1; |
511a6cd4 | 6477 | b->loc->cond = cond; |
c906108c SS |
6478 | if (cond_start) |
6479 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
6480 | else | |
6481 | b->cond_string = 0; | |
c5aa993b | 6482 | |
c906108c | 6483 | if (frame) |
d983da9c | 6484 | b->watchpoint_frame = get_frame_id (frame); |
c906108c | 6485 | else |
35a487f1 | 6486 | b->watchpoint_frame = null_frame_id; |
c906108c | 6487 | |
d983da9c | 6488 | if (scope_breakpoint != NULL) |
c906108c | 6489 | { |
d983da9c DJ |
6490 | /* The scope breakpoint is related to the watchpoint. We will |
6491 | need to act on them together. */ | |
6492 | b->related_breakpoint = scope_breakpoint; | |
6493 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 6494 | } |
d983da9c | 6495 | |
c906108c SS |
6496 | value_free_to_mark (mark); |
6497 | mention (b); | |
b60e7edf | 6498 | update_global_location_list (1); |
c906108c SS |
6499 | } |
6500 | ||
6501 | /* Return count of locations need to be watched and can be handled | |
6502 | in hardware. If the watchpoint can not be handled | |
6503 | in hardware return zero. */ | |
6504 | ||
c906108c | 6505 | static int |
fba45db2 | 6506 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
6507 | { |
6508 | int found_memory_cnt = 0; | |
2e70b7b9 | 6509 | struct value *head = v; |
c906108c SS |
6510 | |
6511 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 6512 | if (!can_use_hw_watchpoints) |
c906108c | 6513 | return 0; |
c5aa993b | 6514 | |
5c44784c JM |
6515 | /* Make sure that the value of the expression depends only upon |
6516 | memory contents, and values computed from them within GDB. If we | |
6517 | find any register references or function calls, we can't use a | |
6518 | hardware watchpoint. | |
6519 | ||
6520 | The idea here is that evaluating an expression generates a series | |
6521 | of values, one holding the value of every subexpression. (The | |
6522 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
6523 | a*b+c.) GDB's values hold almost enough information to establish | |
6524 | the criteria given above --- they identify memory lvalues, | |
6525 | register lvalues, computed values, etcetera. So we can evaluate | |
6526 | the expression, and then scan the chain of values that leaves | |
6527 | behind to decide whether we can detect any possible change to the | |
6528 | expression's final value using only hardware watchpoints. | |
6529 | ||
6530 | However, I don't think that the values returned by inferior | |
6531 | function calls are special in any way. So this function may not | |
6532 | notice that an expression involving an inferior function call | |
6533 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 6534 | for (; v; v = value_next (v)) |
c906108c | 6535 | { |
5c44784c | 6536 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 6537 | { |
d69fe07e | 6538 | if (value_lazy (v)) |
5c44784c JM |
6539 | /* A lazy memory lvalue is one that GDB never needed to fetch; |
6540 | we either just used its address (e.g., `a' in `a.b') or | |
6541 | we never needed it at all (e.g., `a' in `a,b'). */ | |
6542 | ; | |
53a5351d | 6543 | else |
5c44784c JM |
6544 | { |
6545 | /* Ahh, memory we actually used! Check if we can cover | |
6546 | it with hardware watchpoints. */ | |
df407dfe | 6547 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
6548 | |
6549 | /* We only watch structs and arrays if user asked for it | |
6550 | explicitly, never if they just happen to appear in a | |
6551 | middle of some value chain. */ | |
6552 | if (v == head | |
6553 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
6554 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
6555 | { | |
42ae5230 | 6556 | CORE_ADDR vaddr = value_address (v); |
df407dfe | 6557 | int len = TYPE_LENGTH (value_type (v)); |
2e70b7b9 | 6558 | |
d92524f1 | 6559 | if (!target_region_ok_for_hw_watchpoint (vaddr, len)) |
2e70b7b9 MS |
6560 | return 0; |
6561 | else | |
6562 | found_memory_cnt++; | |
6563 | } | |
5c44784c | 6564 | } |
c5aa993b | 6565 | } |
5086187c AC |
6566 | else if (VALUE_LVAL (v) != not_lval |
6567 | && deprecated_value_modifiable (v) == 0) | |
53a5351d | 6568 | return 0; /* ??? What does this represent? */ |
5086187c | 6569 | else if (VALUE_LVAL (v) == lval_register) |
53a5351d | 6570 | return 0; /* cannot watch a register with a HW watchpoint */ |
c906108c SS |
6571 | } |
6572 | ||
6573 | /* The expression itself looks suitable for using a hardware | |
6574 | watchpoint, but give the target machine a chance to reject it. */ | |
6575 | return found_memory_cnt; | |
6576 | } | |
6577 | ||
8b93c638 | 6578 | void |
fba45db2 | 6579 | watch_command_wrapper (char *arg, int from_tty) |
8b93c638 JM |
6580 | { |
6581 | watch_command (arg, from_tty); | |
6582 | } | |
8926118c | 6583 | |
c5aa993b | 6584 | static void |
fba45db2 | 6585 | watch_command (char *arg, int from_tty) |
c906108c | 6586 | { |
53a5351d | 6587 | watch_command_1 (arg, hw_write, from_tty); |
c906108c SS |
6588 | } |
6589 | ||
8b93c638 | 6590 | void |
fba45db2 | 6591 | rwatch_command_wrapper (char *arg, int from_tty) |
8b93c638 JM |
6592 | { |
6593 | rwatch_command (arg, from_tty); | |
6594 | } | |
8926118c | 6595 | |
c5aa993b | 6596 | static void |
fba45db2 | 6597 | rwatch_command (char *arg, int from_tty) |
c906108c | 6598 | { |
53a5351d | 6599 | watch_command_1 (arg, hw_read, from_tty); |
c906108c SS |
6600 | } |
6601 | ||
8b93c638 | 6602 | void |
fba45db2 | 6603 | awatch_command_wrapper (char *arg, int from_tty) |
8b93c638 JM |
6604 | { |
6605 | awatch_command (arg, from_tty); | |
6606 | } | |
8926118c | 6607 | |
c5aa993b | 6608 | static void |
fba45db2 | 6609 | awatch_command (char *arg, int from_tty) |
c906108c | 6610 | { |
53a5351d | 6611 | watch_command_1 (arg, hw_access, from_tty); |
c906108c | 6612 | } |
c906108c | 6613 | \f |
c5aa993b | 6614 | |
43ff13b4 | 6615 | /* Helper routines for the until_command routine in infcmd.c. Here |
c906108c SS |
6616 | because it uses the mechanisms of breakpoints. */ |
6617 | ||
bfec99b2 PA |
6618 | struct until_break_command_continuation_args |
6619 | { | |
6620 | struct breakpoint *breakpoint; | |
6621 | struct breakpoint *breakpoint2; | |
6622 | }; | |
6623 | ||
43ff13b4 JM |
6624 | /* This function is called by fetch_inferior_event via the |
6625 | cmd_continuation pointer, to complete the until command. It takes | |
6626 | care of cleaning up the temporary breakpoints set up by the until | |
6627 | command. */ | |
c2c6d25f | 6628 | static void |
604ead4a | 6629 | until_break_command_continuation (void *arg) |
43ff13b4 | 6630 | { |
bfec99b2 PA |
6631 | struct until_break_command_continuation_args *a = arg; |
6632 | ||
6633 | delete_breakpoint (a->breakpoint); | |
6634 | if (a->breakpoint2) | |
6635 | delete_breakpoint (a->breakpoint2); | |
43ff13b4 JM |
6636 | } |
6637 | ||
c906108c | 6638 | void |
ae66c1fc | 6639 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
6640 | { |
6641 | struct symtabs_and_lines sals; | |
6642 | struct symtab_and_line sal; | |
206415a3 | 6643 | struct frame_info *frame = get_selected_frame (NULL); |
c906108c | 6644 | struct breakpoint *breakpoint; |
f107f563 | 6645 | struct breakpoint *breakpoint2 = NULL; |
c906108c SS |
6646 | struct cleanup *old_chain; |
6647 | ||
6648 | clear_proceed_status (); | |
6649 | ||
6650 | /* Set a breakpoint where the user wants it and at return from | |
6651 | this function */ | |
c5aa993b | 6652 | |
c906108c SS |
6653 | if (default_breakpoint_valid) |
6654 | sals = decode_line_1 (&arg, 1, default_breakpoint_symtab, | |
68219205 | 6655 | default_breakpoint_line, (char ***) NULL, NULL); |
c906108c | 6656 | else |
53a5351d | 6657 | sals = decode_line_1 (&arg, 1, (struct symtab *) NULL, |
68219205 | 6658 | 0, (char ***) NULL, NULL); |
c5aa993b | 6659 | |
c906108c | 6660 | if (sals.nelts != 1) |
8a3fe4f8 | 6661 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 6662 | |
c906108c | 6663 | sal = sals.sals[0]; |
b8c9b27d | 6664 | xfree (sals.sals); /* malloc'd, so freed */ |
c5aa993b | 6665 | |
c906108c | 6666 | if (*arg) |
8a3fe4f8 | 6667 | error (_("Junk at end of arguments.")); |
c5aa993b | 6668 | |
c906108c | 6669 | resolve_sal_pc (&sal); |
c5aa993b | 6670 | |
ae66c1fc EZ |
6671 | if (anywhere) |
6672 | /* If the user told us to continue until a specified location, | |
6673 | we don't specify a frame at which we need to stop. */ | |
a6d9a66e UW |
6674 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
6675 | null_frame_id, bp_until); | |
ae66c1fc | 6676 | else |
edb3359d | 6677 | /* Otherwise, specify the selected frame, because we want to stop only |
ae66c1fc | 6678 | at the very same frame. */ |
a6d9a66e UW |
6679 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
6680 | get_stack_frame_id (frame), | |
ae66c1fc | 6681 | bp_until); |
c5aa993b | 6682 | |
f107f563 | 6683 | old_chain = make_cleanup_delete_breakpoint (breakpoint); |
c906108c | 6684 | |
ae66c1fc EZ |
6685 | /* Keep within the current frame, or in frames called by the current |
6686 | one. */ | |
edb3359d DJ |
6687 | |
6688 | if (frame_id_p (frame_unwind_caller_id (frame))) | |
c906108c | 6689 | { |
edb3359d DJ |
6690 | sal = find_pc_line (frame_unwind_caller_pc (frame), 0); |
6691 | sal.pc = frame_unwind_caller_pc (frame); | |
a6d9a66e UW |
6692 | breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame), |
6693 | sal, | |
edb3359d | 6694 | frame_unwind_caller_id (frame), |
f107f563 VP |
6695 | bp_until); |
6696 | make_cleanup_delete_breakpoint (breakpoint2); | |
c906108c | 6697 | } |
c5aa993b | 6698 | |
c906108c | 6699 | proceed (-1, TARGET_SIGNAL_DEFAULT, 0); |
f107f563 VP |
6700 | |
6701 | /* If we are running asynchronously, and proceed call above has actually | |
6702 | managed to start the target, arrange for breakpoints to be | |
6703 | deleted when the target stops. Otherwise, we're already stopped and | |
6704 | delete breakpoints via cleanup chain. */ | |
6705 | ||
8ea051c5 | 6706 | if (target_can_async_p () && is_running (inferior_ptid)) |
f107f563 | 6707 | { |
bfec99b2 PA |
6708 | struct until_break_command_continuation_args *args; |
6709 | args = xmalloc (sizeof (*args)); | |
f107f563 | 6710 | |
bfec99b2 PA |
6711 | args->breakpoint = breakpoint; |
6712 | args->breakpoint2 = breakpoint2; | |
f107f563 VP |
6713 | |
6714 | discard_cleanups (old_chain); | |
95e54da7 PA |
6715 | add_continuation (inferior_thread (), |
6716 | until_break_command_continuation, args, | |
604ead4a | 6717 | xfree); |
f107f563 VP |
6718 | } |
6719 | else | |
c5aa993b | 6720 | do_cleanups (old_chain); |
c906108c | 6721 | } |
ae66c1fc | 6722 | |
c906108c | 6723 | static void |
fba45db2 | 6724 | ep_skip_leading_whitespace (char **s) |
c906108c | 6725 | { |
c5aa993b JM |
6726 | if ((s == NULL) || (*s == NULL)) |
6727 | return; | |
6728 | while (isspace (**s)) | |
6729 | *s += 1; | |
c906108c | 6730 | } |
c5aa993b | 6731 | |
c906108c SS |
6732 | /* This function attempts to parse an optional "if <cond>" clause |
6733 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 6734 | |
c906108c SS |
6735 | Else, it returns a pointer to the condition string. (It does not |
6736 | attempt to evaluate the string against a particular block.) And, | |
6737 | it updates arg to point to the first character following the parsed | |
6738 | if clause in the arg string. */ | |
53a5351d | 6739 | |
c906108c | 6740 | static char * |
fba45db2 | 6741 | ep_parse_optional_if_clause (char **arg) |
c906108c | 6742 | { |
c5aa993b JM |
6743 | char *cond_string; |
6744 | ||
6745 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 6746 | return NULL; |
c5aa993b | 6747 | |
c906108c SS |
6748 | /* Skip the "if" keyword. */ |
6749 | (*arg) += 2; | |
c5aa993b | 6750 | |
c906108c SS |
6751 | /* Skip any extra leading whitespace, and record the start of the |
6752 | condition string. */ | |
6753 | ep_skip_leading_whitespace (arg); | |
6754 | cond_string = *arg; | |
c5aa993b | 6755 | |
c906108c SS |
6756 | /* Assume that the condition occupies the remainder of the arg string. */ |
6757 | (*arg) += strlen (cond_string); | |
c5aa993b | 6758 | |
c906108c SS |
6759 | return cond_string; |
6760 | } | |
c5aa993b | 6761 | |
c906108c SS |
6762 | /* This function attempts to parse an optional filename from the arg |
6763 | string. If one is not found, it returns NULL. | |
c5aa993b | 6764 | |
c906108c SS |
6765 | Else, it returns a pointer to the parsed filename. (This function |
6766 | makes no attempt to verify that a file of that name exists, or is | |
6767 | accessible.) And, it updates arg to point to the first character | |
6768 | following the parsed filename in the arg string. | |
c5aa993b | 6769 | |
c906108c SS |
6770 | Note that clients needing to preserve the returned filename for |
6771 | future access should copy it to their own buffers. */ | |
6772 | static char * | |
fba45db2 | 6773 | ep_parse_optional_filename (char **arg) |
c906108c | 6774 | { |
c5aa993b JM |
6775 | static char filename[1024]; |
6776 | char *arg_p = *arg; | |
6777 | int i; | |
6778 | char c; | |
6779 | ||
c906108c SS |
6780 | if ((*arg_p == '\0') || isspace (*arg_p)) |
6781 | return NULL; | |
c5aa993b JM |
6782 | |
6783 | for (i = 0;; i++) | |
c906108c SS |
6784 | { |
6785 | c = *arg_p; | |
6786 | if (isspace (c)) | |
c5aa993b | 6787 | c = '\0'; |
c906108c SS |
6788 | filename[i] = c; |
6789 | if (c == '\0') | |
c5aa993b | 6790 | break; |
c906108c SS |
6791 | arg_p++; |
6792 | } | |
6793 | *arg = arg_p; | |
c5aa993b | 6794 | |
c906108c SS |
6795 | return filename; |
6796 | } | |
c5aa993b | 6797 | |
c906108c SS |
6798 | /* Commands to deal with catching events, such as signals, exceptions, |
6799 | process start/exit, etc. */ | |
c5aa993b JM |
6800 | |
6801 | typedef enum | |
6802 | { | |
44feb3ce TT |
6803 | catch_fork_temporary, catch_vfork_temporary, |
6804 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
6805 | } |
6806 | catch_fork_kind; | |
6807 | ||
c906108c | 6808 | static void |
44feb3ce | 6809 | catch_fork_command_1 (char *arg, int from_tty, struct cmd_list_element *command) |
c906108c | 6810 | { |
a6d9a66e | 6811 | struct gdbarch *gdbarch = get_current_arch (); |
c5aa993b | 6812 | char *cond_string = NULL; |
44feb3ce TT |
6813 | catch_fork_kind fork_kind; |
6814 | int tempflag; | |
6815 | ||
6816 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
6817 | tempflag = (fork_kind == catch_fork_temporary | |
6818 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 6819 | |
44feb3ce TT |
6820 | if (!arg) |
6821 | arg = ""; | |
c906108c | 6822 | ep_skip_leading_whitespace (&arg); |
c5aa993b | 6823 | |
c906108c | 6824 | /* The allowed syntax is: |
c5aa993b JM |
6825 | catch [v]fork |
6826 | catch [v]fork if <cond> | |
6827 | ||
c906108c SS |
6828 | First, check if there's an if clause. */ |
6829 | cond_string = ep_parse_optional_if_clause (&arg); | |
c5aa993b | 6830 | |
c906108c | 6831 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 6832 | error (_("Junk at end of arguments.")); |
c5aa993b | 6833 | |
c906108c SS |
6834 | /* If this target supports it, create a fork or vfork catchpoint |
6835 | and enable reporting of such events. */ | |
c5aa993b JM |
6836 | switch (fork_kind) |
6837 | { | |
44feb3ce TT |
6838 | case catch_fork_temporary: |
6839 | case catch_fork_permanent: | |
a6d9a66e | 6840 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 6841 | &catch_fork_breakpoint_ops); |
c906108c | 6842 | break; |
44feb3ce TT |
6843 | case catch_vfork_temporary: |
6844 | case catch_vfork_permanent: | |
a6d9a66e | 6845 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 6846 | &catch_vfork_breakpoint_ops); |
c906108c | 6847 | break; |
c5aa993b | 6848 | default: |
8a3fe4f8 | 6849 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 6850 | break; |
c5aa993b | 6851 | } |
c906108c SS |
6852 | } |
6853 | ||
6854 | static void | |
44feb3ce | 6855 | catch_exec_command_1 (char *arg, int from_tty, struct cmd_list_element *command) |
c906108c | 6856 | { |
a6d9a66e | 6857 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 6858 | int tempflag; |
c5aa993b | 6859 | char *cond_string = NULL; |
c906108c | 6860 | |
44feb3ce TT |
6861 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
6862 | ||
6863 | if (!arg) | |
6864 | arg = ""; | |
c906108c SS |
6865 | ep_skip_leading_whitespace (&arg); |
6866 | ||
6867 | /* The allowed syntax is: | |
c5aa993b JM |
6868 | catch exec |
6869 | catch exec if <cond> | |
c906108c SS |
6870 | |
6871 | First, check if there's an if clause. */ | |
6872 | cond_string = ep_parse_optional_if_clause (&arg); | |
6873 | ||
6874 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 6875 | error (_("Junk at end of arguments.")); |
c906108c SS |
6876 | |
6877 | /* If this target supports it, create an exec catchpoint | |
6878 | and enable reporting of such events. */ | |
a6d9a66e UW |
6879 | create_catchpoint (gdbarch, tempflag, cond_string, |
6880 | &catch_exec_breakpoint_ops); | |
c906108c | 6881 | } |
c5aa993b | 6882 | |
3086aeae DJ |
6883 | static enum print_stop_action |
6884 | print_exception_catchpoint (struct breakpoint *b) | |
6885 | { | |
ade92717 | 6886 | int bp_temp, bp_throw; |
3086aeae | 6887 | |
ade92717 | 6888 | annotate_catchpoint (b->number); |
3086aeae | 6889 | |
ade92717 AR |
6890 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
6891 | if (b->loc->address != b->loc->requested_address) | |
6892 | breakpoint_adjustment_warning (b->loc->requested_address, | |
6893 | b->loc->address, | |
6894 | b->number, 1); | |
df2b6d2d | 6895 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
6896 | ui_out_text (uiout, |
6897 | bp_temp ? "Temporary catchpoint " | |
6898 | : "Catchpoint "); | |
6899 | if (!ui_out_is_mi_like_p (uiout)) | |
6900 | ui_out_field_int (uiout, "bkptno", b->number); | |
6901 | ui_out_text (uiout, | |
c0b37c48 AR |
6902 | bp_throw ? " (exception thrown), " |
6903 | : " (exception caught), "); | |
ade92717 AR |
6904 | if (ui_out_is_mi_like_p (uiout)) |
6905 | { | |
6906 | ui_out_field_string (uiout, "reason", | |
6907 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
6908 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
6909 | ui_out_field_int (uiout, "bkptno", b->number); | |
6910 | } | |
3086aeae DJ |
6911 | return PRINT_SRC_AND_LOC; |
6912 | } | |
6913 | ||
6914 | static void | |
a6d9a66e | 6915 | print_one_exception_catchpoint (struct breakpoint *b, struct bp_location **last_loc) |
3086aeae | 6916 | { |
79a45b7d TT |
6917 | struct value_print_options opts; |
6918 | get_user_print_options (&opts); | |
6919 | if (opts.addressprint) | |
3086aeae DJ |
6920 | { |
6921 | annotate_field (4); | |
604133b5 AR |
6922 | if (b->loc == NULL || b->loc->shlib_disabled) |
6923 | ui_out_field_string (uiout, "addr", "<PENDING>"); | |
6924 | else | |
5af949e3 UW |
6925 | ui_out_field_core_addr (uiout, "addr", |
6926 | b->loc->gdbarch, b->loc->address); | |
3086aeae DJ |
6927 | } |
6928 | annotate_field (5); | |
604133b5 | 6929 | if (b->loc) |
a6d9a66e | 6930 | *last_loc = b->loc; |
3086aeae DJ |
6931 | if (strstr (b->addr_string, "throw") != NULL) |
6932 | ui_out_field_string (uiout, "what", "exception throw"); | |
6933 | else | |
6934 | ui_out_field_string (uiout, "what", "exception catch"); | |
6935 | } | |
6936 | ||
6937 | static void | |
6938 | print_mention_exception_catchpoint (struct breakpoint *b) | |
6939 | { | |
ade92717 AR |
6940 | int bp_temp; |
6941 | int bp_throw; | |
6942 | ||
df2b6d2d | 6943 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
6944 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
6945 | ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ") | |
6946 | : _("Catchpoint ")); | |
6947 | ui_out_field_int (uiout, "bkptno", b->number); | |
6948 | ui_out_text (uiout, bp_throw ? _(" (throw)") | |
6949 | : _(" (catch)")); | |
3086aeae DJ |
6950 | } |
6951 | ||
6952 | static struct breakpoint_ops gnu_v3_exception_catchpoint_ops = { | |
ce78b96d JB |
6953 | NULL, /* insert */ |
6954 | NULL, /* remove */ | |
6955 | NULL, /* breakpoint_hit */ | |
3086aeae DJ |
6956 | print_exception_catchpoint, |
6957 | print_one_exception_catchpoint, | |
6958 | print_mention_exception_catchpoint | |
6959 | }; | |
6960 | ||
6961 | static int | |
6962 | handle_gnu_v3_exceptions (int tempflag, char *cond_string, | |
6963 | enum exception_event_kind ex_event, int from_tty) | |
6964 | { | |
604133b5 AR |
6965 | char *trigger_func_name; |
6966 | ||
3086aeae | 6967 | if (ex_event == EX_EVENT_CATCH) |
604133b5 | 6968 | trigger_func_name = "__cxa_begin_catch"; |
3086aeae | 6969 | else |
604133b5 | 6970 | trigger_func_name = "__cxa_throw"; |
3086aeae | 6971 | |
a6d9a66e UW |
6972 | break_command_really (get_current_arch (), |
6973 | trigger_func_name, cond_string, -1, | |
604133b5 | 6974 | 0 /* condition and thread are valid. */, |
1042e4c0 | 6975 | tempflag, 0, 0, |
604133b5 AR |
6976 | 0, |
6977 | AUTO_BOOLEAN_TRUE /* pending */, | |
41447f92 VP |
6978 | &gnu_v3_exception_catchpoint_ops, from_tty, |
6979 | 1 /* enabled */); | |
3086aeae | 6980 | |
3086aeae DJ |
6981 | return 1; |
6982 | } | |
6983 | ||
c5aa993b | 6984 | /* Deal with "catch catch" and "catch throw" commands */ |
c906108c SS |
6985 | |
6986 | static void | |
fba45db2 KB |
6987 | catch_exception_command_1 (enum exception_event_kind ex_event, char *arg, |
6988 | int tempflag, int from_tty) | |
c906108c | 6989 | { |
c5aa993b JM |
6990 | char *cond_string = NULL; |
6991 | struct symtab_and_line *sal = NULL; | |
6992 | ||
44feb3ce TT |
6993 | if (!arg) |
6994 | arg = ""; | |
c906108c | 6995 | ep_skip_leading_whitespace (&arg); |
c5aa993b | 6996 | |
c906108c SS |
6997 | cond_string = ep_parse_optional_if_clause (&arg); |
6998 | ||
6999 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 7000 | error (_("Junk at end of arguments.")); |
c906108c | 7001 | |
059fb39f PM |
7002 | if (ex_event != EX_EVENT_THROW |
7003 | && ex_event != EX_EVENT_CATCH) | |
8a3fe4f8 | 7004 | error (_("Unsupported or unknown exception event; cannot catch it")); |
c906108c | 7005 | |
3086aeae DJ |
7006 | if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty)) |
7007 | return; | |
7008 | ||
8a3fe4f8 | 7009 | warning (_("Unsupported with this platform/compiler combination.")); |
c906108c SS |
7010 | } |
7011 | ||
44feb3ce TT |
7012 | /* Implementation of "catch catch" command. */ |
7013 | ||
7014 | static void | |
7015 | catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command) | |
7016 | { | |
7017 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
7018 | catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty); | |
7019 | } | |
7020 | ||
7021 | /* Implementation of "catch throw" command. */ | |
7022 | ||
7023 | static void | |
7024 | catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command) | |
7025 | { | |
7026 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
7027 | catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty); | |
7028 | } | |
7029 | ||
f7f9143b JB |
7030 | /* Create a breakpoint struct for Ada exception catchpoints. */ |
7031 | ||
7032 | static void | |
a6d9a66e UW |
7033 | create_ada_exception_breakpoint (struct gdbarch *gdbarch, |
7034 | struct symtab_and_line sal, | |
f7f9143b JB |
7035 | char *addr_string, |
7036 | char *exp_string, | |
7037 | char *cond_string, | |
7038 | struct expression *cond, | |
7039 | struct breakpoint_ops *ops, | |
7040 | int tempflag, | |
7041 | int from_tty) | |
7042 | { | |
7043 | struct breakpoint *b; | |
7044 | ||
7045 | if (from_tty) | |
7046 | { | |
5af949e3 UW |
7047 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
7048 | if (!loc_gdbarch) | |
7049 | loc_gdbarch = gdbarch; | |
7050 | ||
7051 | describe_other_breakpoints (loc_gdbarch, sal.pc, sal.section, -1); | |
f7f9143b JB |
7052 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
7053 | version for exception catchpoints, because two catchpoints | |
7054 | used for different exception names will use the same address. | |
7055 | In this case, a "breakpoint ... also set at..." warning is | |
7056 | unproductive. Besides. the warning phrasing is also a bit | |
7057 | inapropriate, we should use the word catchpoint, and tell | |
7058 | the user what type of catchpoint it is. The above is good | |
7059 | enough for now, though. */ | |
7060 | } | |
7061 | ||
a6d9a66e | 7062 | b = set_raw_breakpoint (gdbarch, sal, bp_breakpoint); |
f7f9143b JB |
7063 | set_breakpoint_count (breakpoint_count + 1); |
7064 | ||
7065 | b->enable_state = bp_enabled; | |
7066 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
7067 | b->number = breakpoint_count; | |
7068 | b->ignore_count = 0; | |
511a6cd4 | 7069 | b->loc->cond = cond; |
f7f9143b JB |
7070 | b->addr_string = addr_string; |
7071 | b->language = language_ada; | |
7072 | b->cond_string = cond_string; | |
7073 | b->exp_string = exp_string; | |
7074 | b->thread = -1; | |
7075 | b->ops = ops; | |
f7f9143b JB |
7076 | |
7077 | mention (b); | |
b60e7edf | 7078 | update_global_location_list (1); |
f7f9143b JB |
7079 | } |
7080 | ||
7081 | /* Implement the "catch exception" command. */ | |
7082 | ||
7083 | static void | |
44feb3ce TT |
7084 | catch_ada_exception_command (char *arg, int from_tty, |
7085 | struct cmd_list_element *command) | |
f7f9143b | 7086 | { |
a6d9a66e | 7087 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 7088 | int tempflag; |
f7f9143b JB |
7089 | struct symtab_and_line sal; |
7090 | enum bptype type; | |
7091 | char *addr_string = NULL; | |
7092 | char *exp_string = NULL; | |
7093 | char *cond_string = NULL; | |
7094 | struct expression *cond = NULL; | |
7095 | struct breakpoint_ops *ops = NULL; | |
7096 | ||
44feb3ce TT |
7097 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
7098 | ||
7099 | if (!arg) | |
7100 | arg = ""; | |
f7f9143b JB |
7101 | sal = ada_decode_exception_location (arg, &addr_string, &exp_string, |
7102 | &cond_string, &cond, &ops); | |
a6d9a66e | 7103 | create_ada_exception_breakpoint (gdbarch, sal, addr_string, exp_string, |
f7f9143b JB |
7104 | cond_string, cond, ops, tempflag, |
7105 | from_tty); | |
7106 | } | |
7107 | ||
7108 | /* Implement the "catch assert" command. */ | |
7109 | ||
7110 | static void | |
44feb3ce | 7111 | catch_assert_command (char *arg, int from_tty, struct cmd_list_element *command) |
f7f9143b | 7112 | { |
a6d9a66e | 7113 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 7114 | int tempflag; |
f7f9143b JB |
7115 | struct symtab_and_line sal; |
7116 | char *addr_string = NULL; | |
7117 | struct breakpoint_ops *ops = NULL; | |
7118 | ||
44feb3ce TT |
7119 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
7120 | ||
7121 | if (!arg) | |
7122 | arg = ""; | |
f7f9143b | 7123 | sal = ada_decode_assert_location (arg, &addr_string, &ops); |
a6d9a66e UW |
7124 | create_ada_exception_breakpoint (gdbarch, sal, addr_string, NULL, NULL, NULL, |
7125 | ops, tempflag, from_tty); | |
f7f9143b JB |
7126 | } |
7127 | ||
c906108c | 7128 | static void |
fba45db2 | 7129 | catch_command (char *arg, int from_tty) |
c906108c | 7130 | { |
44feb3ce | 7131 | error (_("Catch requires an event name.")); |
c906108c SS |
7132 | } |
7133 | \f | |
7134 | ||
7135 | static void | |
fba45db2 | 7136 | tcatch_command (char *arg, int from_tty) |
c906108c | 7137 | { |
44feb3ce | 7138 | error (_("Catch requires an event name.")); |
c906108c SS |
7139 | } |
7140 | ||
80f8a6eb | 7141 | /* Delete breakpoints by address or line. */ |
c906108c SS |
7142 | |
7143 | static void | |
fba45db2 | 7144 | clear_command (char *arg, int from_tty) |
c906108c | 7145 | { |
d6e956e5 VP |
7146 | struct breakpoint *b; |
7147 | VEC(breakpoint_p) *found = 0; | |
7148 | int ix; | |
c906108c SS |
7149 | int default_match; |
7150 | struct symtabs_and_lines sals; | |
7151 | struct symtab_and_line sal; | |
c906108c SS |
7152 | int i; |
7153 | ||
7154 | if (arg) | |
7155 | { | |
7156 | sals = decode_line_spec (arg, 1); | |
7157 | default_match = 0; | |
7158 | } | |
7159 | else | |
7160 | { | |
c5aa993b | 7161 | sals.sals = (struct symtab_and_line *) |
c906108c | 7162 | xmalloc (sizeof (struct symtab_and_line)); |
80f8a6eb | 7163 | make_cleanup (xfree, sals.sals); |
fe39c653 | 7164 | init_sal (&sal); /* initialize to zeroes */ |
c906108c SS |
7165 | sal.line = default_breakpoint_line; |
7166 | sal.symtab = default_breakpoint_symtab; | |
7167 | sal.pc = default_breakpoint_address; | |
7168 | if (sal.symtab == 0) | |
8a3fe4f8 | 7169 | error (_("No source file specified.")); |
c906108c SS |
7170 | |
7171 | sals.sals[0] = sal; | |
7172 | sals.nelts = 1; | |
7173 | ||
7174 | default_match = 1; | |
7175 | } | |
7176 | ||
ed0616c6 VP |
7177 | /* We don't call resolve_sal_pc here. That's not |
7178 | as bad as it seems, because all existing breakpoints | |
7179 | typically have both file/line and pc set. So, if | |
7180 | clear is given file/line, we can match this to existing | |
7181 | breakpoint without obtaining pc at all. | |
7182 | ||
7183 | We only support clearing given the address explicitly | |
7184 | present in breakpoint table. Say, we've set breakpoint | |
7185 | at file:line. There were several PC values for that file:line, | |
7186 | due to optimization, all in one block. | |
7187 | We've picked one PC value. If "clear" is issued with another | |
7188 | PC corresponding to the same file:line, the breakpoint won't | |
7189 | be cleared. We probably can still clear the breakpoint, but | |
7190 | since the other PC value is never presented to user, user | |
7191 | can only find it by guessing, and it does not seem important | |
7192 | to support that. */ | |
7193 | ||
c906108c | 7194 | /* For each line spec given, delete bps which correspond |
80f8a6eb MS |
7195 | to it. Do it in two passes, solely to preserve the current |
7196 | behavior that from_tty is forced true if we delete more than | |
7197 | one breakpoint. */ | |
c906108c | 7198 | |
80f8a6eb | 7199 | found = NULL; |
c906108c SS |
7200 | for (i = 0; i < sals.nelts; i++) |
7201 | { | |
7202 | /* If exact pc given, clear bpts at that pc. | |
c5aa993b JM |
7203 | If line given (pc == 0), clear all bpts on specified line. |
7204 | If defaulting, clear all bpts on default line | |
c906108c | 7205 | or at default pc. |
c5aa993b JM |
7206 | |
7207 | defaulting sal.pc != 0 tests to do | |
7208 | ||
7209 | 0 1 pc | |
7210 | 1 1 pc _and_ line | |
7211 | 0 0 line | |
7212 | 1 0 <can't happen> */ | |
c906108c SS |
7213 | |
7214 | sal = sals.sals[i]; | |
c906108c | 7215 | |
d6e956e5 VP |
7216 | /* Find all matching breakpoints and add them to |
7217 | 'found'. */ | |
7218 | ALL_BREAKPOINTS (b) | |
c5aa993b | 7219 | { |
0d381245 | 7220 | int match = 0; |
80f8a6eb MS |
7221 | /* Are we going to delete b? */ |
7222 | if (b->type != bp_none | |
7223 | && b->type != bp_watchpoint | |
7224 | && b->type != bp_hardware_watchpoint | |
7225 | && b->type != bp_read_watchpoint | |
0d381245 VP |
7226 | && b->type != bp_access_watchpoint) |
7227 | { | |
7228 | struct bp_location *loc = b->loc; | |
7229 | for (; loc; loc = loc->next) | |
7230 | { | |
7231 | int pc_match = sal.pc | |
7232 | && (loc->address == sal.pc) | |
7233 | && (!section_is_overlay (loc->section) | |
7234 | || loc->section == sal.section); | |
7235 | int line_match = ((default_match || (0 == sal.pc)) | |
7236 | && b->source_file != NULL | |
7237 | && sal.symtab != NULL | |
7238 | && strcmp (b->source_file, sal.symtab->filename) == 0 | |
7239 | && b->line_number == sal.line); | |
7240 | if (pc_match || line_match) | |
7241 | { | |
7242 | match = 1; | |
7243 | break; | |
7244 | } | |
7245 | } | |
7246 | } | |
7247 | ||
7248 | if (match) | |
d6e956e5 | 7249 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 7250 | } |
80f8a6eb MS |
7251 | } |
7252 | /* Now go thru the 'found' chain and delete them. */ | |
d6e956e5 | 7253 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
7254 | { |
7255 | if (arg) | |
8a3fe4f8 | 7256 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 7257 | else |
8a3fe4f8 | 7258 | error (_("No breakpoint at this line.")); |
80f8a6eb | 7259 | } |
c906108c | 7260 | |
d6e956e5 | 7261 | if (VEC_length(breakpoint_p, found) > 1) |
80f8a6eb MS |
7262 | from_tty = 1; /* Always report if deleted more than one */ |
7263 | if (from_tty) | |
a3f17187 | 7264 | { |
d6e956e5 | 7265 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
7266 | printf_unfiltered (_("Deleted breakpoint ")); |
7267 | else | |
7268 | printf_unfiltered (_("Deleted breakpoints ")); | |
7269 | } | |
80f8a6eb | 7270 | breakpoints_changed (); |
d6e956e5 VP |
7271 | |
7272 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 7273 | { |
c5aa993b | 7274 | if (from_tty) |
d6e956e5 VP |
7275 | printf_unfiltered ("%d ", b->number); |
7276 | delete_breakpoint (b); | |
c906108c | 7277 | } |
80f8a6eb MS |
7278 | if (from_tty) |
7279 | putchar_unfiltered ('\n'); | |
c906108c SS |
7280 | } |
7281 | \f | |
7282 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
7283 | all breakpoints that are marked for deletion, whether hit or not. | |
7284 | This is called after any breakpoint is hit, or after errors. */ | |
7285 | ||
7286 | void | |
fba45db2 | 7287 | breakpoint_auto_delete (bpstat bs) |
c906108c SS |
7288 | { |
7289 | struct breakpoint *b, *temp; | |
7290 | ||
7291 | for (; bs; bs = bs->next) | |
20874c92 VP |
7292 | if (bs->breakpoint_at |
7293 | && bs->breakpoint_at->owner | |
7294 | && bs->breakpoint_at->owner->disposition == disp_del | |
c906108c | 7295 | && bs->stop) |
4f8d1dc6 | 7296 | delete_breakpoint (bs->breakpoint_at->owner); |
c906108c SS |
7297 | |
7298 | ALL_BREAKPOINTS_SAFE (b, temp) | |
c5aa993b | 7299 | { |
b5de0fa7 | 7300 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
7301 | delete_breakpoint (b); |
7302 | } | |
c906108c SS |
7303 | } |
7304 | ||
f7545552 TT |
7305 | /* A cleanup function which destroys a vector. */ |
7306 | ||
7307 | static void | |
7308 | do_vec_free (void *p) | |
7309 | { | |
7310 | VEC(bp_location_p) **vec = p; | |
7311 | if (*vec) | |
7312 | VEC_free (bp_location_p, *vec); | |
7313 | } | |
7314 | ||
4cd9bd08 | 7315 | /* If SHOULD_INSERT is false, do not insert any breakpoint locations |
b60e7edf PA |
7316 | into the inferior, only remove already-inserted locations that no |
7317 | longer should be inserted. Functions that delete a breakpoint or | |
7318 | breakpoints should pass false, so that deleting a breakpoint | |
7319 | doesn't have the side effect of inserting the locations of other | |
7320 | breakpoints that are marked not-inserted, but should_be_inserted | |
7321 | returns true on them. | |
7322 | ||
7323 | This behaviour is useful is situations close to tear-down -- e.g., | |
7324 | after an exec, while the target still has execution, but breakpoint | |
7325 | shadows of the previous executable image should *NOT* be restored | |
7326 | to the new image; or before detaching, where the target still has | |
7327 | execution and wants to delete breakpoints from GDB's lists, and all | |
7328 | breakpoints had already been removed from the inferior. */ | |
7329 | ||
0d381245 | 7330 | static void |
b60e7edf | 7331 | update_global_location_list (int should_insert) |
0d381245 | 7332 | { |
74960c60 VP |
7333 | struct breakpoint *b; |
7334 | struct bp_location **next = &bp_location_chain; | |
7335 | struct bp_location *loc; | |
7336 | struct bp_location *loc2; | |
74960c60 VP |
7337 | VEC(bp_location_p) *old_locations = NULL; |
7338 | int ret; | |
7339 | int ix; | |
f7545552 TT |
7340 | struct cleanup *cleanups; |
7341 | ||
7342 | cleanups = make_cleanup (do_vec_free, &old_locations); | |
74960c60 VP |
7343 | /* Store old locations for future reference. */ |
7344 | for (loc = bp_location_chain; loc; loc = loc->global_next) | |
7345 | VEC_safe_push (bp_location_p, old_locations, loc); | |
0d381245 | 7346 | |
74960c60 VP |
7347 | bp_location_chain = NULL; |
7348 | ALL_BREAKPOINTS (b) | |
0d381245 | 7349 | { |
74960c60 | 7350 | for (loc = b->loc; loc; loc = loc->next) |
0d381245 | 7351 | { |
74960c60 VP |
7352 | *next = loc; |
7353 | next = &(loc->global_next); | |
7354 | *next = NULL; | |
0d381245 | 7355 | } |
74960c60 VP |
7356 | } |
7357 | ||
7358 | /* Identify bp_location instances that are no longer present in the new | |
7359 | list, and therefore should be freed. Note that it's not necessary that | |
7360 | those locations should be removed from inferior -- if there's another | |
7361 | location at the same address (previously marked as duplicate), | |
7362 | we don't need to remove/insert the location. */ | |
7363 | for (ix = 0; VEC_iterate(bp_location_p, old_locations, ix, loc); ++ix) | |
7364 | { | |
7365 | /* Tells if 'loc' is found amoung the new locations. If not, we | |
7366 | have to free it. */ | |
7367 | int found_object = 0; | |
20874c92 VP |
7368 | /* Tells if the location should remain inserted in the target. */ |
7369 | int keep_in_target = 0; | |
7370 | int removed = 0; | |
74960c60 VP |
7371 | for (loc2 = bp_location_chain; loc2; loc2 = loc2->global_next) |
7372 | if (loc2 == loc) | |
7373 | { | |
7374 | found_object = 1; | |
7375 | break; | |
7376 | } | |
7377 | ||
7378 | /* If this location is no longer present, and inserted, look if there's | |
7379 | maybe a new location at the same address. If so, mark that one | |
7380 | inserted, and don't remove this one. This is needed so that we | |
7381 | don't have a time window where a breakpoint at certain location is not | |
7382 | inserted. */ | |
7383 | ||
7384 | if (loc->inserted) | |
0d381245 | 7385 | { |
74960c60 | 7386 | /* If the location is inserted now, we might have to remove it. */ |
74960c60 VP |
7387 | |
7388 | if (found_object && should_be_inserted (loc)) | |
7389 | { | |
7390 | /* The location is still present in the location list, and still | |
7391 | should be inserted. Don't do anything. */ | |
20874c92 | 7392 | keep_in_target = 1; |
74960c60 VP |
7393 | } |
7394 | else | |
7395 | { | |
7396 | /* The location is either no longer present, or got disabled. | |
7397 | See if there's another location at the same address, in which | |
7398 | case we don't need to remove this one from the target. */ | |
7399 | if (breakpoint_address_is_meaningful (loc->owner)) | |
7400 | for (loc2 = bp_location_chain; loc2; loc2 = loc2->global_next) | |
7401 | { | |
7402 | /* For the sake of should_insert_location. The | |
7403 | call to check_duplicates will fix up this later. */ | |
7404 | loc2->duplicate = 0; | |
7405 | if (should_be_inserted (loc2) | |
7406 | && loc2 != loc && loc2->address == loc->address) | |
7407 | { | |
7408 | loc2->inserted = 1; | |
7409 | loc2->target_info = loc->target_info; | |
20874c92 | 7410 | keep_in_target = 1; |
74960c60 VP |
7411 | break; |
7412 | } | |
7413 | } | |
7414 | } | |
7415 | ||
20874c92 VP |
7416 | if (!keep_in_target) |
7417 | { | |
7418 | if (remove_breakpoint (loc, mark_uninserted)) | |
7419 | { | |
7420 | /* This is just about all we can do. We could keep this | |
7421 | location on the global list, and try to remove it next | |
7422 | time, but there's no particular reason why we will | |
7423 | succeed next time. | |
7424 | ||
7425 | Note that at this point, loc->owner is still valid, | |
7426 | as delete_breakpoint frees the breakpoint only | |
7427 | after calling us. */ | |
7428 | printf_filtered (_("warning: Error removing breakpoint %d\n"), | |
7429 | loc->owner->number); | |
7430 | } | |
7431 | removed = 1; | |
7432 | } | |
0d381245 | 7433 | } |
74960c60 VP |
7434 | |
7435 | if (!found_object) | |
1c5cfe86 PA |
7436 | { |
7437 | if (removed && non_stop) | |
20874c92 VP |
7438 | { |
7439 | /* This location was removed from the targets. In non-stop mode, | |
7440 | a race condition is possible where we've removed a breakpoint, | |
7441 | but stop events for that breakpoint are already queued and will | |
7442 | arrive later. To suppress spurious SIGTRAPs reported to user, | |
7443 | we keep this breakpoint location for a bit, and will retire it | |
7444 | after we see 3 * thread_count events. | |
1c5cfe86 | 7445 | The theory here is that reporting of events should, |
20874c92 VP |
7446 | "on the average", be fair, so after that many event we'll see |
7447 | events from all threads that have anything of interest, and no | |
1c5cfe86 | 7448 | longer need to keep this breakpoint. This is just a |
20874c92 | 7449 | heuristic, but if it's wrong, we'll report unexpected SIGTRAP, |
1c5cfe86 | 7450 | which is usability issue, but not a correctness problem. */ |
20874c92 VP |
7451 | loc->events_till_retirement = 3 * (thread_count () + 1); |
7452 | loc->owner = NULL; | |
20874c92 | 7453 | |
1c5cfe86 PA |
7454 | VEC_safe_push (bp_location_p, moribund_locations, loc); |
7455 | } | |
7456 | else | |
7457 | free_bp_location (loc); | |
20874c92 | 7458 | } |
74960c60 | 7459 | } |
1c5cfe86 | 7460 | |
74960c60 VP |
7461 | ALL_BREAKPOINTS (b) |
7462 | { | |
7463 | check_duplicates (b); | |
0d381245 | 7464 | } |
74960c60 | 7465 | |
50c71eaf | 7466 | if (breakpoints_always_inserted_mode () && should_insert |
c35b1492 | 7467 | && (have_live_inferiors () |
2567c7d9 | 7468 | || (gdbarch_has_global_breakpoints (target_gdbarch)))) |
74960c60 | 7469 | insert_breakpoint_locations (); |
f7545552 TT |
7470 | |
7471 | do_cleanups (cleanups); | |
74960c60 VP |
7472 | } |
7473 | ||
20874c92 VP |
7474 | void |
7475 | breakpoint_retire_moribund (void) | |
7476 | { | |
7477 | struct bp_location *loc; | |
7478 | int ix; | |
7479 | ||
7480 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
7481 | if (--(loc->events_till_retirement) == 0) | |
7482 | { | |
7483 | free_bp_location (loc); | |
7484 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); | |
7485 | --ix; | |
7486 | } | |
7487 | } | |
7488 | ||
74960c60 | 7489 | static void |
b60e7edf | 7490 | update_global_location_list_nothrow (int inserting) |
74960c60 VP |
7491 | { |
7492 | struct gdb_exception e; | |
7493 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
b60e7edf | 7494 | update_global_location_list (inserting); |
0d381245 VP |
7495 | } |
7496 | ||
a474d7c2 PA |
7497 | /* Clear BPT from a BPS. */ |
7498 | static void | |
7499 | bpstat_remove_breakpoint (bpstat bps, struct breakpoint *bpt) | |
7500 | { | |
7501 | bpstat bs; | |
7502 | for (bs = bps; bs; bs = bs->next) | |
7503 | if (bs->breakpoint_at && bs->breakpoint_at->owner == bpt) | |
7504 | { | |
7505 | bs->breakpoint_at = NULL; | |
7506 | bs->old_val = NULL; | |
7507 | /* bs->commands will be freed later. */ | |
7508 | } | |
7509 | } | |
7510 | ||
7511 | /* Callback for iterate_over_threads. */ | |
7512 | static int | |
7513 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
7514 | { | |
7515 | struct breakpoint *bpt = data; | |
7516 | bpstat_remove_breakpoint (th->stop_bpstat, bpt); | |
7517 | return 0; | |
7518 | } | |
7519 | ||
53a5351d JM |
7520 | /* Delete a breakpoint and clean up all traces of it in the data |
7521 | structures. */ | |
c906108c SS |
7522 | |
7523 | void | |
fba45db2 | 7524 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 7525 | { |
52f0bd74 | 7526 | struct breakpoint *b; |
74960c60 | 7527 | struct bp_location *loc, *next; |
c906108c | 7528 | |
8a3fe4f8 | 7529 | gdb_assert (bpt != NULL); |
c906108c SS |
7530 | |
7531 | /* Has this bp already been deleted? This can happen because multiple | |
7532 | lists can hold pointers to bp's. bpstat lists are especial culprits. | |
7533 | ||
7534 | One example of this happening is a watchpoint's scope bp. When the | |
7535 | scope bp triggers, we notice that the watchpoint is out of scope, and | |
7536 | delete it. We also delete its scope bp. But the scope bp is marked | |
7537 | "auto-deleting", and is already on a bpstat. That bpstat is then | |
7538 | checked for auto-deleting bp's, which are deleted. | |
7539 | ||
7540 | A real solution to this problem might involve reference counts in bp's, | |
7541 | and/or giving them pointers back to their referencing bpstat's, and | |
7542 | teaching delete_breakpoint to only free a bp's storage when no more | |
1272ad14 | 7543 | references were extent. A cheaper bandaid was chosen. */ |
c906108c SS |
7544 | if (bpt->type == bp_none) |
7545 | return; | |
7546 | ||
383f836e | 7547 | observer_notify_breakpoint_deleted (bpt->number); |
c906108c | 7548 | |
c906108c SS |
7549 | if (breakpoint_chain == bpt) |
7550 | breakpoint_chain = bpt->next; | |
7551 | ||
c906108c SS |
7552 | ALL_BREAKPOINTS (b) |
7553 | if (b->next == bpt) | |
c5aa993b JM |
7554 | { |
7555 | b->next = bpt->next; | |
7556 | break; | |
7557 | } | |
c906108c | 7558 | |
c906108c | 7559 | free_command_lines (&bpt->commands); |
c906108c | 7560 | if (bpt->cond_string != NULL) |
b8c9b27d | 7561 | xfree (bpt->cond_string); |
c906108c | 7562 | if (bpt->addr_string != NULL) |
b8c9b27d | 7563 | xfree (bpt->addr_string); |
c906108c | 7564 | if (bpt->exp != NULL) |
b8c9b27d | 7565 | xfree (bpt->exp); |
c906108c | 7566 | if (bpt->exp_string != NULL) |
b8c9b27d | 7567 | xfree (bpt->exp_string); |
c906108c SS |
7568 | if (bpt->val != NULL) |
7569 | value_free (bpt->val); | |
7570 | if (bpt->source_file != NULL) | |
b8c9b27d | 7571 | xfree (bpt->source_file); |
c906108c | 7572 | if (bpt->exec_pathname != NULL) |
b8c9b27d | 7573 | xfree (bpt->exec_pathname); |
c906108c SS |
7574 | |
7575 | /* Be sure no bpstat's are pointing at it after it's been freed. */ | |
7576 | /* FIXME, how can we find all bpstat's? | |
198757a8 VP |
7577 | We just check stop_bpstat for now. Note that we cannot just |
7578 | remove bpstats pointing at bpt from the stop_bpstat list | |
7579 | entirely, as breakpoint commands are associated with the bpstat; | |
7580 | if we remove it here, then the later call to | |
7581 | bpstat_do_actions (&stop_bpstat); | |
7582 | in event-top.c won't do anything, and temporary breakpoints | |
7583 | with commands won't work. */ | |
a474d7c2 | 7584 | |
a474d7c2 | 7585 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); |
74960c60 VP |
7586 | |
7587 | /* Now that breakpoint is removed from breakpoint | |
7588 | list, update the global location list. This | |
7589 | will remove locations that used to belong to | |
7590 | this breakpoint. Do this before freeing | |
7591 | the breakpoint itself, since remove_breakpoint | |
7592 | looks at location's owner. It might be better | |
7593 | design to have location completely self-contained, | |
7594 | but it's not the case now. */ | |
b60e7edf | 7595 | update_global_location_list (0); |
74960c60 VP |
7596 | |
7597 | ||
c906108c SS |
7598 | /* On the chance that someone will soon try again to delete this same |
7599 | bp, we mark it as deleted before freeing its storage. */ | |
7600 | bpt->type = bp_none; | |
7601 | ||
b8c9b27d | 7602 | xfree (bpt); |
c906108c SS |
7603 | } |
7604 | ||
4d6140d9 AC |
7605 | static void |
7606 | do_delete_breakpoint_cleanup (void *b) | |
7607 | { | |
7608 | delete_breakpoint (b); | |
7609 | } | |
7610 | ||
7611 | struct cleanup * | |
7612 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
7613 | { | |
7614 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
7615 | } | |
7616 | ||
c906108c | 7617 | void |
fba45db2 | 7618 | delete_command (char *arg, int from_tty) |
c906108c SS |
7619 | { |
7620 | struct breakpoint *b, *temp; | |
7621 | ||
ea9365bb TT |
7622 | dont_repeat (); |
7623 | ||
c906108c SS |
7624 | if (arg == 0) |
7625 | { | |
7626 | int breaks_to_delete = 0; | |
7627 | ||
7628 | /* Delete all breakpoints if no argument. | |
c5aa993b JM |
7629 | Do not delete internal or call-dummy breakpoints, these |
7630 | have to be deleted with an explicit breakpoint number argument. */ | |
7631 | ALL_BREAKPOINTS (b) | |
7632 | { | |
059fb39f PM |
7633 | if (b->type != bp_call_dummy |
7634 | && b->type != bp_shlib_event | |
7635 | && b->type != bp_thread_event | |
7636 | && b->type != bp_overlay_event | |
0fd8e87f | 7637 | && b->type != bp_longjmp_master |
059fb39f | 7638 | && b->number >= 0) |
973d738b DJ |
7639 | { |
7640 | breaks_to_delete = 1; | |
7641 | break; | |
7642 | } | |
c5aa993b | 7643 | } |
c906108c SS |
7644 | |
7645 | /* Ask user only if there are some breakpoints to delete. */ | |
7646 | if (!from_tty | |
e2e0b3e5 | 7647 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 7648 | { |
c5aa993b JM |
7649 | ALL_BREAKPOINTS_SAFE (b, temp) |
7650 | { | |
059fb39f PM |
7651 | if (b->type != bp_call_dummy |
7652 | && b->type != bp_shlib_event | |
7653 | && b->type != bp_thread_event | |
7654 | && b->type != bp_overlay_event | |
0fd8e87f | 7655 | && b->type != bp_longjmp_master |
059fb39f | 7656 | && b->number >= 0) |
c5aa993b JM |
7657 | delete_breakpoint (b); |
7658 | } | |
c906108c SS |
7659 | } |
7660 | } | |
7661 | else | |
7662 | map_breakpoint_numbers (arg, delete_breakpoint); | |
7663 | } | |
7664 | ||
0d381245 VP |
7665 | static int |
7666 | all_locations_are_pending (struct bp_location *loc) | |
fe3f5fa8 | 7667 | { |
0d381245 VP |
7668 | for (; loc; loc = loc->next) |
7669 | if (!loc->shlib_disabled) | |
7670 | return 0; | |
7671 | return 1; | |
fe3f5fa8 VP |
7672 | } |
7673 | ||
776592bf DE |
7674 | /* Subroutine of update_breakpoint_locations to simplify it. |
7675 | Return non-zero if multiple fns in list LOC have the same name. | |
7676 | Null names are ignored. */ | |
7677 | ||
7678 | static int | |
7679 | ambiguous_names_p (struct bp_location *loc) | |
7680 | { | |
7681 | struct bp_location *l; | |
7682 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
7683 | (int (*) (const void *, const void *)) streq, | |
7684 | NULL, xcalloc, xfree); | |
7685 | ||
7686 | for (l = loc; l != NULL; l = l->next) | |
7687 | { | |
7688 | const char **slot; | |
7689 | const char *name = l->function_name; | |
7690 | ||
7691 | /* Allow for some names to be NULL, ignore them. */ | |
7692 | if (name == NULL) | |
7693 | continue; | |
7694 | ||
7695 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
7696 | INSERT); | |
7697 | /* NOTE: We can assume slot != NULL here because xcalloc never returns | |
7698 | NULL. */ | |
7699 | if (*slot != NULL) | |
7700 | { | |
7701 | htab_delete (htab); | |
7702 | return 1; | |
7703 | } | |
7704 | *slot = name; | |
7705 | } | |
7706 | ||
7707 | htab_delete (htab); | |
7708 | return 0; | |
7709 | } | |
7710 | ||
fe3f5fa8 | 7711 | static void |
0d381245 VP |
7712 | update_breakpoint_locations (struct breakpoint *b, |
7713 | struct symtabs_and_lines sals) | |
fe3f5fa8 VP |
7714 | { |
7715 | int i; | |
7716 | char *s; | |
0d381245 VP |
7717 | struct bp_location *existing_locations = b->loc; |
7718 | ||
7719 | /* If there's no new locations, and all existing locations | |
7720 | are pending, don't do anything. This optimizes | |
7721 | the common case where all locations are in the same | |
7722 | shared library, that was unloaded. We'd like to | |
7723 | retain the location, so that when the library | |
7724 | is loaded again, we don't loose the enabled/disabled | |
7725 | status of the individual locations. */ | |
7726 | if (all_locations_are_pending (existing_locations) && sals.nelts == 0) | |
fe3f5fa8 VP |
7727 | return; |
7728 | ||
fe3f5fa8 VP |
7729 | b->loc = NULL; |
7730 | ||
0d381245 | 7731 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 7732 | { |
0d381245 | 7733 | struct bp_location *new_loc = |
39d61571 | 7734 | add_location_to_breakpoint (b, &(sals.sals[i])); |
fe3f5fa8 | 7735 | |
0d381245 VP |
7736 | /* Reparse conditions, they might contain references to the |
7737 | old symtab. */ | |
7738 | if (b->cond_string != NULL) | |
7739 | { | |
7740 | struct gdb_exception e; | |
fe3f5fa8 | 7741 | |
0d381245 VP |
7742 | s = b->cond_string; |
7743 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
7744 | { | |
7745 | new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), | |
7746 | 0); | |
7747 | } | |
7748 | if (e.reason < 0) | |
7749 | { | |
7750 | warning (_("failed to reevaluate condition for breakpoint %d: %s"), | |
7751 | b->number, e.message); | |
7752 | new_loc->enabled = 0; | |
7753 | } | |
7754 | } | |
fe3f5fa8 | 7755 | |
0d381245 VP |
7756 | if (b->source_file != NULL) |
7757 | xfree (b->source_file); | |
7758 | if (sals.sals[i].symtab == NULL) | |
7759 | b->source_file = NULL; | |
7760 | else | |
1b36a34b | 7761 | b->source_file = xstrdup (sals.sals[i].symtab->filename); |
fe3f5fa8 | 7762 | |
0d381245 VP |
7763 | if (b->line_number == 0) |
7764 | b->line_number = sals.sals[i].line; | |
7765 | } | |
fe3f5fa8 | 7766 | |
514f746b AR |
7767 | /* Update locations of permanent breakpoints. */ |
7768 | if (b->enable_state == bp_permanent) | |
7769 | make_breakpoint_permanent (b); | |
7770 | ||
0d381245 VP |
7771 | /* If possible, carry over 'disable' status from existing breakpoints. */ |
7772 | { | |
7773 | struct bp_location *e = existing_locations; | |
776592bf DE |
7774 | /* If there are multiple breakpoints with the same function name, |
7775 | e.g. for inline functions, comparing function names won't work. | |
7776 | Instead compare pc addresses; this is just a heuristic as things | |
7777 | may have moved, but in practice it gives the correct answer | |
7778 | often enough until a better solution is found. */ | |
7779 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
7780 | ||
0d381245 VP |
7781 | for (; e; e = e->next) |
7782 | { | |
7783 | if (!e->enabled && e->function_name) | |
7784 | { | |
7785 | struct bp_location *l = b->loc; | |
776592bf DE |
7786 | if (have_ambiguous_names) |
7787 | { | |
7788 | for (; l; l = l->next) | |
7789 | if (e->address == l->address) | |
7790 | { | |
7791 | l->enabled = 0; | |
7792 | break; | |
7793 | } | |
7794 | } | |
7795 | else | |
7796 | { | |
7797 | for (; l; l = l->next) | |
7798 | if (l->function_name | |
7799 | && strcmp (e->function_name, l->function_name) == 0) | |
7800 | { | |
7801 | l->enabled = 0; | |
7802 | break; | |
7803 | } | |
7804 | } | |
0d381245 VP |
7805 | } |
7806 | } | |
7807 | } | |
fe3f5fa8 | 7808 | |
b60e7edf | 7809 | update_global_location_list (1); |
fe3f5fa8 VP |
7810 | } |
7811 | ||
7812 | ||
c906108c SS |
7813 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
7814 | The value we return ends up being the return value from catch_errors. | |
7815 | Unused in this case. */ | |
7816 | ||
7817 | static int | |
4efb68b1 | 7818 | breakpoint_re_set_one (void *bint) |
c906108c | 7819 | { |
53a5351d JM |
7820 | /* get past catch_errs */ |
7821 | struct breakpoint *b = (struct breakpoint *) bint; | |
c906108c SS |
7822 | struct value *mark; |
7823 | int i; | |
fe3f5fa8 VP |
7824 | int not_found = 0; |
7825 | int *not_found_ptr = ¬_found; | |
7826 | struct symtabs_and_lines sals = {}; | |
ed0616c6 | 7827 | struct symtabs_and_lines expanded; |
c906108c | 7828 | char *s; |
b5de0fa7 | 7829 | enum enable_state save_enable; |
fe3f5fa8 | 7830 | struct gdb_exception e; |
f7545552 | 7831 | struct cleanup *cleanups; |
c906108c SS |
7832 | |
7833 | switch (b->type) | |
7834 | { | |
7835 | case bp_none: | |
8a3fe4f8 | 7836 | warning (_("attempted to reset apparently deleted breakpoint #%d?"), |
53a5351d | 7837 | b->number); |
c906108c SS |
7838 | return 0; |
7839 | case bp_breakpoint: | |
7840 | case bp_hardware_breakpoint: | |
1042e4c0 | 7841 | case bp_tracepoint: |
8bea4e01 UW |
7842 | /* Do not attempt to re-set breakpoints disabled during startup. */ |
7843 | if (b->enable_state == bp_startup_disabled) | |
7844 | return 0; | |
7845 | ||
c906108c SS |
7846 | if (b->addr_string == NULL) |
7847 | { | |
7848 | /* Anything without a string can't be re-set. */ | |
7849 | delete_breakpoint (b); | |
7850 | return 0; | |
7851 | } | |
c906108c SS |
7852 | |
7853 | set_language (b->language); | |
7854 | input_radix = b->input_radix; | |
7855 | s = b->addr_string; | |
fe3f5fa8 | 7856 | TRY_CATCH (e, RETURN_MASK_ERROR) |
c906108c | 7857 | { |
fe3f5fa8 VP |
7858 | sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL, |
7859 | not_found_ptr); | |
7860 | } | |
7861 | if (e.reason < 0) | |
7862 | { | |
7863 | int not_found_and_ok = 0; | |
7864 | /* For pending breakpoints, it's expected that parsing | |
7865 | will fail until the right shared library is loaded. | |
7866 | User has already told to create pending breakpoints and | |
7867 | don't need extra messages. If breakpoint is in bp_shlib_disabled | |
7868 | state, then user already saw the message about that breakpoint | |
7869 | being disabled, and don't want to see more errors. */ | |
0d381245 VP |
7870 | if (not_found |
7871 | && (b->condition_not_parsed | |
7872 | || (b->loc && b->loc->shlib_disabled) | |
7873 | || b->enable_state == bp_disabled)) | |
fe3f5fa8 VP |
7874 | not_found_and_ok = 1; |
7875 | ||
7876 | if (!not_found_and_ok) | |
c906108c | 7877 | { |
fe3f5fa8 VP |
7878 | /* We surely don't want to warn about the same breakpoint |
7879 | 10 times. One solution, implemented here, is disable | |
7880 | the breakpoint on error. Another solution would be to | |
7881 | have separate 'warning emitted' flag. Since this | |
7882 | happens only when a binary has changed, I don't know | |
7883 | which approach is better. */ | |
7884 | b->enable_state = bp_disabled; | |
7885 | throw_exception (e); | |
c906108c | 7886 | } |
fe3f5fa8 | 7887 | } |
c906108c | 7888 | |
fe3f5fa8 VP |
7889 | if (not_found) |
7890 | break; | |
7891 | ||
7892 | gdb_assert (sals.nelts == 1); | |
7893 | resolve_sal_pc (&sals.sals[0]); | |
0d381245 | 7894 | if (b->condition_not_parsed && s && s[0]) |
fe3f5fa8 VP |
7895 | { |
7896 | char *cond_string = 0; | |
7897 | int thread = -1; | |
4a306c9a JB |
7898 | int task = 0; |
7899 | ||
fe3f5fa8 | 7900 | find_condition_and_thread (s, sals.sals[0].pc, |
4a306c9a | 7901 | &cond_string, &thread, &task); |
fe3f5fa8 VP |
7902 | if (cond_string) |
7903 | b->cond_string = cond_string; | |
7904 | b->thread = thread; | |
4a306c9a | 7905 | b->task = task; |
0d381245 | 7906 | b->condition_not_parsed = 0; |
fe3f5fa8 | 7907 | } |
ed0616c6 | 7908 | expanded = expand_line_sal_maybe (sals.sals[0]); |
f7545552 | 7909 | cleanups = make_cleanup (xfree, sals.sals); |
ed0616c6 | 7910 | update_breakpoint_locations (b, expanded); |
f7545552 | 7911 | do_cleanups (cleanups); |
c906108c SS |
7912 | break; |
7913 | ||
7914 | case bp_watchpoint: | |
7915 | case bp_hardware_watchpoint: | |
7916 | case bp_read_watchpoint: | |
7917 | case bp_access_watchpoint: | |
0b3de036 VP |
7918 | /* Watchpoint can be either on expression using entirely global variables, |
7919 | or it can be on local variables. | |
7920 | ||
7921 | Watchpoints of the first kind are never auto-deleted, and even persist | |
7922 | across program restarts. Since they can use variables from shared | |
7923 | libraries, we need to reparse expression as libraries are loaded | |
7924 | and unloaded. | |
7925 | ||
7926 | Watchpoints on local variables can also change meaning as result | |
7927 | of solib event. For example, if a watchpoint uses both a local and | |
7928 | a global variables in expression, it's a local watchpoint, but | |
7929 | unloading of a shared library will make the expression invalid. | |
7930 | This is not a very common use case, but we still re-evaluate | |
7931 | expression, to avoid surprises to the user. | |
7932 | ||
7933 | Note that for local watchpoints, we re-evaluate it only if | |
7934 | watchpoints frame id is still valid. If it's not, it means | |
7935 | the watchpoint is out of scope and will be deleted soon. In fact, | |
7936 | I'm not sure we'll ever be called in this case. | |
7937 | ||
7938 | If a local watchpoint's frame id is still valid, then | |
7939 | b->exp_valid_block is likewise valid, and we can safely use it. | |
7940 | ||
7941 | Don't do anything about disabled watchpoints, since they will | |
7942 | be reevaluated again when enabled. */ | |
a5606eee | 7943 | update_watchpoint (b, 1 /* reparse */); |
c906108c | 7944 | break; |
c5aa993b JM |
7945 | /* We needn't really do anything to reset these, since the mask |
7946 | that requests them is unaffected by e.g., new libraries being | |
7947 | loaded. */ | |
ce78b96d | 7948 | case bp_catchpoint: |
c906108c | 7949 | break; |
c5aa993b | 7950 | |
c906108c | 7951 | default: |
a3f17187 | 7952 | printf_filtered (_("Deleting unknown breakpoint type %d\n"), b->type); |
c906108c | 7953 | /* fall through */ |
0fd8e87f UW |
7954 | /* Delete overlay event and longjmp master breakpoints; they will be |
7955 | reset later by breakpoint_re_set. */ | |
1900040c | 7956 | case bp_overlay_event: |
0fd8e87f | 7957 | case bp_longjmp_master: |
c906108c SS |
7958 | delete_breakpoint (b); |
7959 | break; | |
7960 | ||
c5aa993b JM |
7961 | /* This breakpoint is special, it's set up when the inferior |
7962 | starts and we really don't want to touch it. */ | |
c906108c SS |
7963 | case bp_shlib_event: |
7964 | ||
c4093a6a JM |
7965 | /* Like bp_shlib_event, this breakpoint type is special. |
7966 | Once it is set up, we do not want to touch it. */ | |
7967 | case bp_thread_event: | |
7968 | ||
c5aa993b JM |
7969 | /* Keep temporary breakpoints, which can be encountered when we step |
7970 | over a dlopen call and SOLIB_ADD is resetting the breakpoints. | |
7971 | Otherwise these should have been blown away via the cleanup chain | |
7972 | or by breakpoint_init_inferior when we rerun the executable. */ | |
c906108c SS |
7973 | case bp_until: |
7974 | case bp_finish: | |
7975 | case bp_watchpoint_scope: | |
7976 | case bp_call_dummy: | |
7977 | case bp_step_resume: | |
611c83ae PA |
7978 | case bp_longjmp: |
7979 | case bp_longjmp_resume: | |
c906108c SS |
7980 | break; |
7981 | } | |
7982 | ||
7983 | return 0; | |
7984 | } | |
7985 | ||
69de3c6a | 7986 | /* Re-set all breakpoints after symbols have been re-loaded. */ |
c906108c | 7987 | void |
69de3c6a | 7988 | breakpoint_re_set (void) |
c906108c SS |
7989 | { |
7990 | struct breakpoint *b, *temp; | |
7991 | enum language save_language; | |
7992 | int save_input_radix; | |
c5aa993b | 7993 | |
c906108c SS |
7994 | save_language = current_language->la_language; |
7995 | save_input_radix = input_radix; | |
7996 | ALL_BREAKPOINTS_SAFE (b, temp) | |
c5aa993b | 7997 | { |
53a5351d | 7998 | /* Format possible error msg */ |
fe3f5fa8 | 7999 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
8000 | b->number); |
8001 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 8002 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 8003 | do_cleanups (cleanups); |
c5aa993b | 8004 | } |
c906108c SS |
8005 | set_language (save_language); |
8006 | input_radix = save_input_radix; | |
e62c965a | 8007 | |
69de3c6a | 8008 | create_overlay_event_breakpoint ("_ovly_debug_event"); |
0fd8e87f UW |
8009 | create_longjmp_master_breakpoint ("longjmp"); |
8010 | create_longjmp_master_breakpoint ("_longjmp"); | |
8011 | create_longjmp_master_breakpoint ("siglongjmp"); | |
8012 | create_longjmp_master_breakpoint ("_siglongjmp"); | |
c906108c SS |
8013 | } |
8014 | \f | |
c906108c SS |
8015 | /* Reset the thread number of this breakpoint: |
8016 | ||
8017 | - If the breakpoint is for all threads, leave it as-is. | |
39f77062 | 8018 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 8019 | void |
fba45db2 | 8020 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
8021 | { |
8022 | if (b->thread != -1) | |
8023 | { | |
39f77062 KB |
8024 | if (in_thread_list (inferior_ptid)) |
8025 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c SS |
8026 | } |
8027 | } | |
8028 | ||
03ac34d5 MS |
8029 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
8030 | If from_tty is nonzero, it prints a message to that effect, | |
8031 | which ends with a period (no newline). */ | |
8032 | ||
c906108c | 8033 | void |
fba45db2 | 8034 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 8035 | { |
52f0bd74 | 8036 | struct breakpoint *b; |
c906108c SS |
8037 | |
8038 | if (count < 0) | |
8039 | count = 0; | |
8040 | ||
8041 | ALL_BREAKPOINTS (b) | |
8042 | if (b->number == bptnum) | |
c5aa993b JM |
8043 | { |
8044 | b->ignore_count = count; | |
221ea385 KS |
8045 | if (from_tty) |
8046 | { | |
8047 | if (count == 0) | |
a3f17187 | 8048 | printf_filtered (_("Will stop next time breakpoint %d is reached."), |
221ea385 KS |
8049 | bptnum); |
8050 | else if (count == 1) | |
a3f17187 | 8051 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
8052 | bptnum); |
8053 | else | |
a3f17187 | 8054 | printf_filtered (_("Will ignore next %d crossings of breakpoint %d."), |
221ea385 KS |
8055 | count, bptnum); |
8056 | } | |
c5aa993b | 8057 | breakpoints_changed (); |
383f836e | 8058 | observer_notify_breakpoint_modified (b->number); |
c5aa993b JM |
8059 | return; |
8060 | } | |
c906108c | 8061 | |
8a3fe4f8 | 8062 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
8063 | } |
8064 | ||
b2175913 MS |
8065 | void |
8066 | make_breakpoint_silent (struct breakpoint *b) | |
8067 | { | |
8068 | /* Silence the breakpoint. */ | |
8069 | b->silent = 1; | |
8070 | } | |
8071 | ||
c906108c SS |
8072 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
8073 | ||
8074 | static void | |
fba45db2 | 8075 | ignore_command (char *args, int from_tty) |
c906108c SS |
8076 | { |
8077 | char *p = args; | |
52f0bd74 | 8078 | int num; |
c906108c SS |
8079 | |
8080 | if (p == 0) | |
e2e0b3e5 | 8081 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 8082 | |
c906108c | 8083 | num = get_number (&p); |
5c44784c | 8084 | if (num == 0) |
8a3fe4f8 | 8085 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 8086 | if (*p == 0) |
8a3fe4f8 | 8087 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
8088 | |
8089 | set_ignore_count (num, | |
8090 | longest_to_int (value_as_long (parse_and_eval (p))), | |
8091 | from_tty); | |
221ea385 KS |
8092 | if (from_tty) |
8093 | printf_filtered ("\n"); | |
c906108c SS |
8094 | } |
8095 | \f | |
8096 | /* Call FUNCTION on each of the breakpoints | |
8097 | whose numbers are given in ARGS. */ | |
8098 | ||
8099 | static void | |
831662b3 | 8100 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *)) |
c906108c | 8101 | { |
52f0bd74 | 8102 | char *p = args; |
c906108c | 8103 | char *p1; |
52f0bd74 AC |
8104 | int num; |
8105 | struct breakpoint *b, *tmp; | |
11cf8741 | 8106 | int match; |
c906108c SS |
8107 | |
8108 | if (p == 0) | |
e2e0b3e5 | 8109 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c SS |
8110 | |
8111 | while (*p) | |
8112 | { | |
11cf8741 | 8113 | match = 0; |
c906108c | 8114 | p1 = p; |
c5aa993b | 8115 | |
5c44784c JM |
8116 | num = get_number_or_range (&p1); |
8117 | if (num == 0) | |
c5aa993b | 8118 | { |
8a3fe4f8 | 8119 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
8120 | } |
8121 | else | |
8122 | { | |
8123 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
8124 | if (b->number == num) | |
8125 | { | |
8126 | struct breakpoint *related_breakpoint = b->related_breakpoint; | |
11cf8741 | 8127 | match = 1; |
5c44784c JM |
8128 | function (b); |
8129 | if (related_breakpoint) | |
8130 | function (related_breakpoint); | |
11cf8741 | 8131 | break; |
5c44784c | 8132 | } |
11cf8741 | 8133 | if (match == 0) |
a3f17187 | 8134 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 8135 | } |
c906108c SS |
8136 | p = p1; |
8137 | } | |
8138 | } | |
8139 | ||
0d381245 VP |
8140 | static struct bp_location * |
8141 | find_location_by_number (char *number) | |
8142 | { | |
8143 | char *dot = strchr (number, '.'); | |
8144 | char *p1; | |
8145 | int bp_num; | |
8146 | int loc_num; | |
8147 | struct breakpoint *b; | |
8148 | struct bp_location *loc; | |
8149 | ||
8150 | *dot = '\0'; | |
8151 | ||
8152 | p1 = number; | |
8153 | bp_num = get_number_or_range (&p1); | |
8154 | if (bp_num == 0) | |
8155 | error (_("Bad breakpoint number '%s'"), number); | |
8156 | ||
8157 | ALL_BREAKPOINTS (b) | |
8158 | if (b->number == bp_num) | |
8159 | { | |
8160 | break; | |
8161 | } | |
8162 | ||
8163 | if (!b || b->number != bp_num) | |
8164 | error (_("Bad breakpoint number '%s'"), number); | |
8165 | ||
8166 | p1 = dot+1; | |
8167 | loc_num = get_number_or_range (&p1); | |
8168 | if (loc_num == 0) | |
8169 | error (_("Bad breakpoint location number '%s'"), number); | |
8170 | ||
8171 | --loc_num; | |
8172 | loc = b->loc; | |
8173 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
8174 | ; | |
8175 | if (!loc) | |
8176 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
8177 | ||
8178 | return loc; | |
8179 | } | |
8180 | ||
8181 | ||
1900040c MS |
8182 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
8183 | If from_tty is nonzero, it prints a message to that effect, | |
8184 | which ends with a period (no newline). */ | |
8185 | ||
c906108c | 8186 | void |
fba45db2 | 8187 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
8188 | { |
8189 | /* Never disable a watchpoint scope breakpoint; we want to | |
8190 | hit them when we leave scope so we can delete both the | |
8191 | watchpoint and its scope breakpoint at that time. */ | |
8192 | if (bpt->type == bp_watchpoint_scope) | |
8193 | return; | |
8194 | ||
c2c6d25f | 8195 | /* You can't disable permanent breakpoints. */ |
b5de0fa7 | 8196 | if (bpt->enable_state == bp_permanent) |
c2c6d25f JM |
8197 | return; |
8198 | ||
b5de0fa7 | 8199 | bpt->enable_state = bp_disabled; |
c906108c | 8200 | |
b60e7edf | 8201 | update_global_location_list (0); |
c906108c | 8202 | |
383f836e | 8203 | observer_notify_breakpoint_modified (bpt->number); |
c906108c SS |
8204 | } |
8205 | ||
c906108c | 8206 | static void |
fba45db2 | 8207 | disable_command (char *args, int from_tty) |
c906108c | 8208 | { |
52f0bd74 | 8209 | struct breakpoint *bpt; |
c906108c SS |
8210 | if (args == 0) |
8211 | ALL_BREAKPOINTS (bpt) | |
8212 | switch (bpt->type) | |
c5aa993b JM |
8213 | { |
8214 | case bp_none: | |
8a3fe4f8 | 8215 | warning (_("attempted to disable apparently deleted breakpoint #%d?"), |
53a5351d | 8216 | bpt->number); |
c5aa993b JM |
8217 | continue; |
8218 | case bp_breakpoint: | |
1042e4c0 | 8219 | case bp_tracepoint: |
ce78b96d | 8220 | case bp_catchpoint: |
c5aa993b JM |
8221 | case bp_hardware_breakpoint: |
8222 | case bp_watchpoint: | |
8223 | case bp_hardware_watchpoint: | |
8224 | case bp_read_watchpoint: | |
8225 | case bp_access_watchpoint: | |
8226 | disable_breakpoint (bpt); | |
8227 | default: | |
8228 | continue; | |
8229 | } | |
0d381245 VP |
8230 | else if (strchr (args, '.')) |
8231 | { | |
8232 | struct bp_location *loc = find_location_by_number (args); | |
8233 | if (loc) | |
8234 | loc->enabled = 0; | |
b60e7edf | 8235 | update_global_location_list (0); |
0d381245 | 8236 | } |
c906108c SS |
8237 | else |
8238 | map_breakpoint_numbers (args, disable_breakpoint); | |
8239 | } | |
8240 | ||
8241 | static void | |
fba45db2 | 8242 | do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition) |
c906108c | 8243 | { |
c906108c SS |
8244 | int target_resources_ok, other_type_used; |
8245 | struct value *mark; | |
8246 | ||
8247 | if (bpt->type == bp_hardware_breakpoint) | |
8248 | { | |
8249 | int i; | |
c5aa993b | 8250 | i = hw_breakpoint_used_count (); |
53a5351d | 8251 | target_resources_ok = |
d92524f1 | 8252 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 8253 | i + 1, 0); |
c906108c | 8254 | if (target_resources_ok == 0) |
8a3fe4f8 | 8255 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 8256 | else if (target_resources_ok < 0) |
8a3fe4f8 | 8257 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
8258 | } |
8259 | ||
059fb39f PM |
8260 | if (bpt->type == bp_watchpoint |
8261 | || bpt->type == bp_hardware_watchpoint | |
8262 | || bpt->type == bp_read_watchpoint | |
8263 | || bpt->type == bp_access_watchpoint) | |
c906108c | 8264 | { |
dde02812 ES |
8265 | struct gdb_exception e; |
8266 | ||
8267 | TRY_CATCH (e, RETURN_MASK_ALL) | |
c906108c | 8268 | { |
dde02812 | 8269 | update_watchpoint (bpt, 1 /* reparse */); |
c906108c | 8270 | } |
dde02812 | 8271 | if (e.reason < 0) |
c5aa993b | 8272 | { |
dde02812 ES |
8273 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
8274 | bpt->number); | |
8275 | return; | |
c5aa993b | 8276 | } |
c906108c | 8277 | } |
0101ce28 | 8278 | |
b4c291bb KH |
8279 | if (bpt->enable_state != bp_permanent) |
8280 | bpt->enable_state = bp_enabled; | |
8281 | bpt->disposition = disposition; | |
b60e7edf | 8282 | update_global_location_list (1); |
b4c291bb KH |
8283 | breakpoints_changed (); |
8284 | ||
383f836e | 8285 | observer_notify_breakpoint_modified (bpt->number); |
c906108c SS |
8286 | } |
8287 | ||
fe3f5fa8 | 8288 | |
c906108c | 8289 | void |
fba45db2 | 8290 | enable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
8291 | { |
8292 | do_enable_breakpoint (bpt, bpt->disposition); | |
8293 | } | |
8294 | ||
8295 | /* The enable command enables the specified breakpoints (or all defined | |
8296 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 8297 | in stopping the inferior. */ |
c906108c | 8298 | |
c906108c | 8299 | static void |
fba45db2 | 8300 | enable_command (char *args, int from_tty) |
c906108c | 8301 | { |
52f0bd74 | 8302 | struct breakpoint *bpt; |
c906108c SS |
8303 | if (args == 0) |
8304 | ALL_BREAKPOINTS (bpt) | |
8305 | switch (bpt->type) | |
c5aa993b JM |
8306 | { |
8307 | case bp_none: | |
8a3fe4f8 | 8308 | warning (_("attempted to enable apparently deleted breakpoint #%d?"), |
53a5351d | 8309 | bpt->number); |
c5aa993b JM |
8310 | continue; |
8311 | case bp_breakpoint: | |
1042e4c0 | 8312 | case bp_tracepoint: |
ce78b96d | 8313 | case bp_catchpoint: |
c5aa993b JM |
8314 | case bp_hardware_breakpoint: |
8315 | case bp_watchpoint: | |
8316 | case bp_hardware_watchpoint: | |
8317 | case bp_read_watchpoint: | |
8318 | case bp_access_watchpoint: | |
8319 | enable_breakpoint (bpt); | |
8320 | default: | |
8321 | continue; | |
8322 | } | |
0d381245 VP |
8323 | else if (strchr (args, '.')) |
8324 | { | |
8325 | struct bp_location *loc = find_location_by_number (args); | |
8326 | if (loc) | |
8327 | loc->enabled = 1; | |
b60e7edf | 8328 | update_global_location_list (1); |
0d381245 | 8329 | } |
c906108c SS |
8330 | else |
8331 | map_breakpoint_numbers (args, enable_breakpoint); | |
8332 | } | |
8333 | ||
8334 | static void | |
fba45db2 | 8335 | enable_once_breakpoint (struct breakpoint *bpt) |
c906108c | 8336 | { |
b5de0fa7 | 8337 | do_enable_breakpoint (bpt, disp_disable); |
c906108c SS |
8338 | } |
8339 | ||
c906108c | 8340 | static void |
fba45db2 | 8341 | enable_once_command (char *args, int from_tty) |
c906108c SS |
8342 | { |
8343 | map_breakpoint_numbers (args, enable_once_breakpoint); | |
8344 | } | |
8345 | ||
8346 | static void | |
fba45db2 | 8347 | enable_delete_breakpoint (struct breakpoint *bpt) |
c906108c | 8348 | { |
b5de0fa7 | 8349 | do_enable_breakpoint (bpt, disp_del); |
c906108c SS |
8350 | } |
8351 | ||
c906108c | 8352 | static void |
fba45db2 | 8353 | enable_delete_command (char *args, int from_tty) |
c906108c SS |
8354 | { |
8355 | map_breakpoint_numbers (args, enable_delete_breakpoint); | |
8356 | } | |
8357 | \f | |
fa8d40ab JJ |
8358 | static void |
8359 | set_breakpoint_cmd (char *args, int from_tty) | |
8360 | { | |
8361 | } | |
8362 | ||
8363 | static void | |
8364 | show_breakpoint_cmd (char *args, int from_tty) | |
8365 | { | |
8366 | } | |
8367 | ||
c906108c SS |
8368 | /* Use default_breakpoint_'s, or nothing if they aren't valid. */ |
8369 | ||
8370 | struct symtabs_and_lines | |
fba45db2 | 8371 | decode_line_spec_1 (char *string, int funfirstline) |
c906108c SS |
8372 | { |
8373 | struct symtabs_and_lines sals; | |
8374 | if (string == 0) | |
8a3fe4f8 | 8375 | error (_("Empty line specification.")); |
c906108c SS |
8376 | if (default_breakpoint_valid) |
8377 | sals = decode_line_1 (&string, funfirstline, | |
53a5351d JM |
8378 | default_breakpoint_symtab, |
8379 | default_breakpoint_line, | |
68219205 | 8380 | (char ***) NULL, NULL); |
c906108c SS |
8381 | else |
8382 | sals = decode_line_1 (&string, funfirstline, | |
68219205 | 8383 | (struct symtab *) NULL, 0, (char ***) NULL, NULL); |
c906108c | 8384 | if (*string) |
8a3fe4f8 | 8385 | error (_("Junk at end of line specification: %s"), string); |
c906108c SS |
8386 | return sals; |
8387 | } | |
8181d85f DJ |
8388 | |
8389 | /* Create and insert a raw software breakpoint at PC. Return an | |
8390 | identifier, which should be used to remove the breakpoint later. | |
8391 | In general, places which call this should be using something on the | |
8392 | breakpoint chain instead; this function should be eliminated | |
8393 | someday. */ | |
8394 | ||
8395 | void * | |
a6d9a66e | 8396 | deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch, CORE_ADDR pc) |
8181d85f DJ |
8397 | { |
8398 | struct bp_target_info *bp_tgt; | |
8399 | ||
8400 | bp_tgt = xmalloc (sizeof (struct bp_target_info)); | |
8401 | memset (bp_tgt, 0, sizeof (struct bp_target_info)); | |
8402 | ||
8403 | bp_tgt->placed_address = pc; | |
a6d9a66e | 8404 | if (target_insert_breakpoint (gdbarch, bp_tgt) != 0) |
8181d85f DJ |
8405 | { |
8406 | /* Could not insert the breakpoint. */ | |
8407 | xfree (bp_tgt); | |
8408 | return NULL; | |
8409 | } | |
8410 | ||
8411 | return bp_tgt; | |
8412 | } | |
8413 | ||
8414 | /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */ | |
8415 | ||
8416 | int | |
a6d9a66e | 8417 | deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp) |
8181d85f DJ |
8418 | { |
8419 | struct bp_target_info *bp_tgt = bp; | |
8420 | int ret; | |
8421 | ||
a6d9a66e | 8422 | ret = target_remove_breakpoint (gdbarch, bp_tgt); |
8181d85f DJ |
8423 | xfree (bp_tgt); |
8424 | ||
8425 | return ret; | |
8426 | } | |
8427 | ||
8428 | /* One (or perhaps two) breakpoints used for software single stepping. */ | |
8429 | ||
8430 | static void *single_step_breakpoints[2]; | |
a6d9a66e | 8431 | static struct gdbarch *single_step_gdbarch[2]; |
8181d85f DJ |
8432 | |
8433 | /* Create and insert a breakpoint for software single step. */ | |
8434 | ||
8435 | void | |
a6d9a66e | 8436 | insert_single_step_breakpoint (struct gdbarch *gdbarch, CORE_ADDR next_pc) |
8181d85f DJ |
8437 | { |
8438 | void **bpt_p; | |
8439 | ||
8440 | if (single_step_breakpoints[0] == NULL) | |
a6d9a66e UW |
8441 | { |
8442 | bpt_p = &single_step_breakpoints[0]; | |
8443 | single_step_gdbarch[0] = gdbarch; | |
8444 | } | |
8181d85f DJ |
8445 | else |
8446 | { | |
8447 | gdb_assert (single_step_breakpoints[1] == NULL); | |
8448 | bpt_p = &single_step_breakpoints[1]; | |
a6d9a66e | 8449 | single_step_gdbarch[1] = gdbarch; |
8181d85f DJ |
8450 | } |
8451 | ||
8452 | /* NOTE drow/2006-04-11: A future improvement to this function would be | |
8453 | to only create the breakpoints once, and actually put them on the | |
8454 | breakpoint chain. That would let us use set_raw_breakpoint. We could | |
8455 | adjust the addresses each time they were needed. Doing this requires | |
8456 | corresponding changes elsewhere where single step breakpoints are | |
8457 | handled, however. So, for now, we use this. */ | |
8458 | ||
a6d9a66e | 8459 | *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, next_pc); |
8181d85f | 8460 | if (*bpt_p == NULL) |
5af949e3 UW |
8461 | error (_("Could not insert single-step breakpoint at %s"), |
8462 | paddress (gdbarch, next_pc)); | |
8181d85f DJ |
8463 | } |
8464 | ||
8465 | /* Remove and delete any breakpoints used for software single step. */ | |
8466 | ||
8467 | void | |
8468 | remove_single_step_breakpoints (void) | |
8469 | { | |
8470 | gdb_assert (single_step_breakpoints[0] != NULL); | |
8471 | ||
8472 | /* See insert_single_step_breakpoint for more about this deprecated | |
8473 | call. */ | |
a6d9a66e UW |
8474 | deprecated_remove_raw_breakpoint (single_step_gdbarch[0], |
8475 | single_step_breakpoints[0]); | |
8476 | single_step_gdbarch[0] = NULL; | |
8181d85f DJ |
8477 | single_step_breakpoints[0] = NULL; |
8478 | ||
8479 | if (single_step_breakpoints[1] != NULL) | |
8480 | { | |
a6d9a66e UW |
8481 | deprecated_remove_raw_breakpoint (single_step_gdbarch[1], |
8482 | single_step_breakpoints[1]); | |
8483 | single_step_gdbarch[1] = NULL; | |
8181d85f DJ |
8484 | single_step_breakpoints[1] = NULL; |
8485 | } | |
8486 | } | |
8487 | ||
1aafd4da UW |
8488 | /* Check whether a software single-step breakpoint is inserted at PC. */ |
8489 | ||
8490 | static int | |
8491 | single_step_breakpoint_inserted_here_p (CORE_ADDR pc) | |
8492 | { | |
8493 | int i; | |
8494 | ||
8495 | for (i = 0; i < 2; i++) | |
8496 | { | |
8497 | struct bp_target_info *bp_tgt = single_step_breakpoints[i]; | |
8498 | if (bp_tgt && bp_tgt->placed_address == pc) | |
8499 | return 1; | |
8500 | } | |
8501 | ||
8502 | return 0; | |
8503 | } | |
8504 | ||
1042e4c0 SS |
8505 | /* Tracepoint-specific operations. */ |
8506 | ||
8507 | /* Set tracepoint count to NUM. */ | |
8508 | static void | |
8509 | set_tracepoint_count (int num) | |
8510 | { | |
8511 | tracepoint_count = num; | |
4fa62494 | 8512 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
8513 | } |
8514 | ||
8515 | void | |
8516 | trace_command (char *arg, int from_tty) | |
8517 | { | |
a6d9a66e UW |
8518 | break_command_really (get_current_arch (), |
8519 | arg, | |
1042e4c0 SS |
8520 | NULL, 0, 1 /* parse arg */, |
8521 | 0 /* tempflag */, 0 /* hardwareflag */, | |
8522 | 1 /* traceflag */, | |
8523 | 0 /* Ignore count */, | |
8524 | pending_break_support, | |
8525 | NULL, | |
8526 | from_tty, | |
8527 | 1 /* enabled */); | |
8528 | set_tracepoint_count (breakpoint_count); | |
8529 | } | |
8530 | ||
8531 | /* Print information on tracepoint number TPNUM_EXP, or all if | |
8532 | omitted. */ | |
8533 | ||
8534 | static void | |
8535 | tracepoints_info (char *tpnum_exp, int from_tty) | |
8536 | { | |
8537 | struct breakpoint *b; | |
8538 | int tps_to_list = 0; | |
8539 | ||
8540 | /* In the no-arguments case, say "No tracepoints" if none found. */ | |
8541 | if (tpnum_exp == 0) | |
8542 | { | |
8543 | ALL_TRACEPOINTS (b) | |
8544 | { | |
8545 | if (b->number >= 0) | |
8546 | { | |
8547 | tps_to_list = 1; | |
8548 | break; | |
8549 | } | |
8550 | } | |
8551 | if (!tps_to_list) | |
8552 | { | |
8553 | ui_out_message (uiout, 0, "No tracepoints.\n"); | |
8554 | return; | |
8555 | } | |
8556 | } | |
8557 | ||
8558 | /* Otherwise be the same as "info break". */ | |
8559 | breakpoints_info (tpnum_exp, from_tty); | |
8560 | } | |
8561 | ||
8562 | /* The 'enable trace' command enables tracepoints. | |
8563 | Not supported by all targets. */ | |
8564 | static void | |
8565 | enable_trace_command (char *args, int from_tty) | |
8566 | { | |
8567 | enable_command (args, from_tty); | |
8568 | } | |
8569 | ||
8570 | /* The 'disable trace' command disables tracepoints. | |
8571 | Not supported by all targets. */ | |
8572 | static void | |
8573 | disable_trace_command (char *args, int from_tty) | |
8574 | { | |
8575 | disable_command (args, from_tty); | |
8576 | } | |
8577 | ||
8578 | /* Remove a tracepoint (or all if no argument) */ | |
8579 | static void | |
8580 | delete_trace_command (char *arg, int from_tty) | |
8581 | { | |
8582 | struct breakpoint *b, *temp; | |
8583 | ||
8584 | dont_repeat (); | |
8585 | ||
8586 | if (arg == 0) | |
8587 | { | |
8588 | int breaks_to_delete = 0; | |
8589 | ||
8590 | /* Delete all breakpoints if no argument. | |
8591 | Do not delete internal or call-dummy breakpoints, these | |
8592 | have to be deleted with an explicit breakpoint number argument. */ | |
8593 | ALL_TRACEPOINTS (b) | |
8594 | { | |
8595 | if (b->number >= 0) | |
8596 | { | |
8597 | breaks_to_delete = 1; | |
8598 | break; | |
8599 | } | |
8600 | } | |
8601 | ||
8602 | /* Ask user only if there are some breakpoints to delete. */ | |
8603 | if (!from_tty | |
8604 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
8605 | { | |
8606 | ALL_BREAKPOINTS_SAFE (b, temp) | |
8607 | { | |
059fb39f PM |
8608 | if (b->type == bp_tracepoint |
8609 | && b->number >= 0) | |
1042e4c0 SS |
8610 | delete_breakpoint (b); |
8611 | } | |
8612 | } | |
8613 | } | |
8614 | else | |
8615 | map_breakpoint_numbers (arg, delete_breakpoint); | |
8616 | } | |
8617 | ||
8618 | /* Set passcount for tracepoint. | |
8619 | ||
8620 | First command argument is passcount, second is tracepoint number. | |
8621 | If tracepoint number omitted, apply to most recently defined. | |
8622 | Also accepts special argument "all". */ | |
8623 | ||
8624 | static void | |
8625 | trace_pass_command (char *args, int from_tty) | |
8626 | { | |
8627 | struct breakpoint *t1 = (struct breakpoint *) -1, *t2; | |
8628 | unsigned int count; | |
8629 | int all = 0; | |
8630 | ||
8631 | if (args == 0 || *args == 0) | |
8632 | error (_("passcount command requires an argument (count + optional TP num)")); | |
8633 | ||
8634 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ | |
8635 | ||
8636 | while (*args && isspace ((int) *args)) | |
8637 | args++; | |
8638 | ||
8639 | if (*args && strncasecmp (args, "all", 3) == 0) | |
8640 | { | |
8641 | args += 3; /* Skip special argument "all". */ | |
8642 | all = 1; | |
8643 | if (*args) | |
8644 | error (_("Junk at end of arguments.")); | |
8645 | } | |
8646 | else | |
8647 | t1 = get_tracepoint_by_number (&args, 1, 1); | |
8648 | ||
8649 | do | |
8650 | { | |
8651 | if (t1) | |
8652 | { | |
8653 | ALL_TRACEPOINTS (t2) | |
8654 | if (t1 == (struct breakpoint *) -1 || t1 == t2) | |
8655 | { | |
8656 | t2->pass_count = count; | |
8657 | observer_notify_tracepoint_modified (t2->number); | |
8658 | if (from_tty) | |
8659 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
8660 | t2->number, count); | |
8661 | } | |
8662 | if (! all && *args) | |
8663 | t1 = get_tracepoint_by_number (&args, 1, 0); | |
8664 | } | |
8665 | } | |
8666 | while (*args); | |
8667 | } | |
8668 | ||
8669 | struct breakpoint * | |
8670 | get_tracepoint (int num) | |
8671 | { | |
8672 | struct breakpoint *t; | |
8673 | ||
8674 | ALL_TRACEPOINTS (t) | |
8675 | if (t->number == num) | |
8676 | return t; | |
8677 | ||
8678 | return NULL; | |
8679 | } | |
8680 | ||
8681 | /* Utility: parse a tracepoint number and look it up in the list. | |
8682 | If MULTI_P is true, there might be a range of tracepoints in ARG. | |
8683 | if OPTIONAL_P is true, then if the argument is missing, the most | |
8684 | recent tracepoint (tracepoint_count) is returned. */ | |
8685 | struct breakpoint * | |
8686 | get_tracepoint_by_number (char **arg, int multi_p, int optional_p) | |
8687 | { | |
8688 | extern int tracepoint_count; | |
8689 | struct breakpoint *t; | |
8690 | int tpnum; | |
8691 | char *instring = arg == NULL ? NULL : *arg; | |
8692 | ||
8693 | if (arg == NULL || *arg == NULL || ! **arg) | |
8694 | { | |
8695 | if (optional_p) | |
8696 | tpnum = tracepoint_count; | |
8697 | else | |
8698 | error_no_arg (_("tracepoint number")); | |
8699 | } | |
8700 | else | |
8701 | tpnum = multi_p ? get_number_or_range (arg) : get_number (arg); | |
8702 | ||
8703 | if (tpnum <= 0) | |
8704 | { | |
8705 | if (instring && *instring) | |
8706 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
8707 | instring); | |
8708 | else | |
8709 | printf_filtered (_("Tracepoint argument missing and no previous tracepoint\n")); | |
8710 | return NULL; | |
8711 | } | |
8712 | ||
8713 | ALL_TRACEPOINTS (t) | |
8714 | if (t->number == tpnum) | |
8715 | { | |
8716 | return t; | |
8717 | } | |
8718 | ||
8719 | /* FIXME: if we are in the middle of a range we don't want to give | |
8720 | a message. The current interface to get_number_or_range doesn't | |
8721 | allow us to discover this. */ | |
8722 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); | |
8723 | return NULL; | |
8724 | } | |
8725 | ||
8726 | /* save-tracepoints command */ | |
8727 | static void | |
8728 | tracepoint_save_command (char *args, int from_tty) | |
8729 | { | |
8730 | struct breakpoint *tp; | |
8731 | int any_tp = 0; | |
8732 | struct action_line *line; | |
8733 | FILE *fp; | |
8734 | char *i1 = " ", *i2 = " "; | |
8735 | char *indent, *actionline, *pathname; | |
8736 | char tmp[40]; | |
8737 | struct cleanup *cleanup; | |
8738 | ||
8739 | if (args == 0 || *args == 0) | |
8740 | error (_("Argument required (file name in which to save tracepoints)")); | |
8741 | ||
8742 | /* See if we have anything to save. */ | |
8743 | ALL_TRACEPOINTS (tp) | |
8744 | { | |
8745 | any_tp = 1; | |
8746 | break; | |
8747 | } | |
8748 | if (!any_tp) | |
8749 | { | |
8750 | warning (_("save-tracepoints: no tracepoints to save.")); | |
8751 | return; | |
8752 | } | |
8753 | ||
8754 | pathname = tilde_expand (args); | |
8755 | cleanup = make_cleanup (xfree, pathname); | |
059fb39f PM |
8756 | fp = fopen (pathname, "w"); |
8757 | if (!fp) | |
1042e4c0 SS |
8758 | error (_("Unable to open file '%s' for saving tracepoints (%s)"), |
8759 | args, safe_strerror (errno)); | |
8760 | make_cleanup_fclose (fp); | |
8761 | ||
8762 | ALL_TRACEPOINTS (tp) | |
8763 | { | |
8764 | if (tp->addr_string) | |
8765 | fprintf (fp, "trace %s\n", tp->addr_string); | |
8766 | else | |
8767 | { | |
8768 | sprintf_vma (tmp, tp->loc->address); | |
8769 | fprintf (fp, "trace *0x%s\n", tmp); | |
8770 | } | |
8771 | ||
8772 | if (tp->pass_count) | |
8773 | fprintf (fp, " passcount %d\n", tp->pass_count); | |
8774 | ||
8775 | if (tp->actions) | |
8776 | { | |
8777 | fprintf (fp, " actions\n"); | |
8778 | indent = i1; | |
8779 | for (line = tp->actions; line; line = line->next) | |
8780 | { | |
8781 | struct cmd_list_element *cmd; | |
8782 | ||
8783 | QUIT; /* allow user to bail out with ^C */ | |
8784 | actionline = line->action; | |
8785 | while (isspace ((int) *actionline)) | |
8786 | actionline++; | |
8787 | ||
8788 | fprintf (fp, "%s%s\n", indent, actionline); | |
8789 | if (*actionline != '#') /* skip for comment lines */ | |
8790 | { | |
8791 | cmd = lookup_cmd (&actionline, cmdlist, "", -1, 1); | |
8792 | if (cmd == 0) | |
8793 | error (_("Bad action list item: %s"), actionline); | |
8794 | if (cmd_cfunc_eq (cmd, while_stepping_pseudocommand)) | |
8795 | indent = i2; | |
8796 | else if (cmd_cfunc_eq (cmd, end_actions_pseudocommand)) | |
8797 | indent = i1; | |
8798 | } | |
8799 | } | |
8800 | } | |
8801 | } | |
8802 | do_cleanups (cleanup); | |
8803 | if (from_tty) | |
8804 | printf_filtered (_("Tracepoints saved to file '%s'.\n"), args); | |
8805 | return; | |
8806 | } | |
8807 | ||
8808 | /* Create a vector of all tracepoints. */ | |
8809 | ||
8810 | VEC(breakpoint_p) * | |
8811 | all_tracepoints () | |
8812 | { | |
8813 | VEC(breakpoint_p) *tp_vec = 0; | |
8814 | struct breakpoint *tp; | |
8815 | ||
8816 | ALL_TRACEPOINTS (tp) | |
8817 | { | |
8818 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
8819 | } | |
8820 | ||
8821 | return tp_vec; | |
8822 | } | |
8823 | ||
c906108c | 8824 | \f |
31e2b00f AS |
8825 | /* This help string is used for the break, hbreak, tbreak and thbreak commands. |
8826 | It is defined as a macro to prevent duplication. | |
8827 | COMMAND should be a string constant containing the name of the command. */ | |
8828 | #define BREAK_ARGS_HELP(command) \ | |
8829 | command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\ | |
8830 | LOCATION may be a line number, function name, or \"*\" and an address.\n\ | |
8831 | If a line number is specified, break at start of code for that line.\n\ | |
8832 | If a function is specified, break at start of code for that function.\n\ | |
8833 | If an address is specified, break at that exact address.\n\ | |
8834 | With no LOCATION, uses current execution address of selected stack frame.\n\ | |
8835 | This is useful for breaking on return to a stack frame.\n\ | |
8836 | \n\ | |
8837 | THREADNUM is the number from \"info threads\".\n\ | |
8838 | CONDITION is a boolean expression.\n\ | |
8839 | \n\ | |
8840 | Multiple breakpoints at one place are permitted, and useful if conditional.\n\ | |
8841 | \n\ | |
8842 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
8843 | ||
44feb3ce TT |
8844 | /* List of subcommands for "catch". */ |
8845 | static struct cmd_list_element *catch_cmdlist; | |
8846 | ||
8847 | /* List of subcommands for "tcatch". */ | |
8848 | static struct cmd_list_element *tcatch_cmdlist; | |
8849 | ||
8850 | /* Like add_cmd, but add the command to both the "catch" and "tcatch" | |
8851 | lists, and pass some additional user data to the command function. */ | |
8852 | static void | |
8853 | add_catch_command (char *name, char *docstring, | |
8854 | void (*sfunc) (char *args, int from_tty, | |
8855 | struct cmd_list_element *command), | |
8856 | void *user_data_catch, | |
8857 | void *user_data_tcatch) | |
8858 | { | |
8859 | struct cmd_list_element *command; | |
8860 | ||
8861 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
8862 | &catch_cmdlist); | |
8863 | set_cmd_sfunc (command, sfunc); | |
8864 | set_cmd_context (command, user_data_catch); | |
8865 | ||
8866 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
8867 | &tcatch_cmdlist); | |
8868 | set_cmd_sfunc (command, sfunc); | |
8869 | set_cmd_context (command, user_data_tcatch); | |
8870 | } | |
8871 | ||
c906108c | 8872 | void |
fba45db2 | 8873 | _initialize_breakpoint (void) |
c906108c | 8874 | { |
fa8d40ab JJ |
8875 | static struct cmd_list_element *breakpoint_set_cmdlist; |
8876 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
c906108c SS |
8877 | struct cmd_list_element *c; |
8878 | ||
84acb35a | 8879 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
84acb35a | 8880 | |
c906108c SS |
8881 | breakpoint_chain = 0; |
8882 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
8883 | before a breakpoint is set. */ | |
8884 | breakpoint_count = 0; | |
8885 | ||
1042e4c0 SS |
8886 | tracepoint_count = 0; |
8887 | ||
1bedd215 AC |
8888 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
8889 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
8890 | Usage is `ignore N COUNT'.")); | |
c906108c | 8891 | if (xdb_commands) |
c5aa993b | 8892 | add_com_alias ("bc", "ignore", class_breakpoint, 1); |
c906108c | 8893 | |
1bedd215 AC |
8894 | add_com ("commands", class_breakpoint, commands_command, _("\ |
8895 | Set commands to be executed when a breakpoint is hit.\n\ | |
c906108c SS |
8896 | Give breakpoint number as argument after \"commands\".\n\ |
8897 | With no argument, the targeted breakpoint is the last one set.\n\ | |
8898 | The commands themselves follow starting on the next line.\n\ | |
8899 | Type a line containing \"end\" to indicate the end of them.\n\ | |
8900 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 8901 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 8902 | |
1bedd215 AC |
8903 | add_com ("condition", class_breakpoint, condition_command, _("\ |
8904 | Specify breakpoint number N to break only if COND is true.\n\ | |
c906108c | 8905 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 8906 | expression to be evaluated whenever breakpoint N is reached.")); |
c906108c | 8907 | |
1bedd215 | 8908 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 8909 | Set a temporary breakpoint.\n\ |
c906108c SS |
8910 | Like \"break\" except the breakpoint is only temporary,\n\ |
8911 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
8912 | by using \"enable delete\" on the breakpoint number.\n\ |
8913 | \n" | |
8914 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 8915 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 8916 | |
1bedd215 | 8917 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
31e2b00f | 8918 | Set a hardware assisted breakpoint.\n\ |
c906108c | 8919 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
8920 | some target hardware may not have this support.\n\ |
8921 | \n" | |
8922 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 8923 | set_cmd_completer (c, location_completer); |
c906108c | 8924 | |
1bedd215 | 8925 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 8926 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 8927 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
8928 | so it will be deleted when hit.\n\ |
8929 | \n" | |
8930 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 8931 | set_cmd_completer (c, location_completer); |
c906108c | 8932 | |
1bedd215 AC |
8933 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
8934 | Enable some breakpoints.\n\ | |
c906108c SS |
8935 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
8936 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
8937 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 8938 | With a subcommand you can enable temporarily."), |
c906108c SS |
8939 | &enablelist, "enable ", 1, &cmdlist); |
8940 | if (xdb_commands) | |
1bedd215 AC |
8941 | add_com ("ab", class_breakpoint, enable_command, _("\ |
8942 | Enable some breakpoints.\n\ | |
c906108c SS |
8943 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
8944 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
8945 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 8946 | With a subcommand you can enable temporarily.")); |
c906108c SS |
8947 | |
8948 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
8949 | ||
1bedd215 AC |
8950 | add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
8951 | Enable some breakpoints.\n\ | |
c906108c SS |
8952 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
8953 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 8954 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 8955 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 8956 | |
1a966eab AC |
8957 | add_cmd ("once", no_class, enable_once_command, _("\ |
8958 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
8959 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
8960 | &enablebreaklist); |
8961 | ||
1a966eab AC |
8962 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
8963 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
8964 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
8965 | &enablebreaklist); |
8966 | ||
1a966eab AC |
8967 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
8968 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
8969 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
8970 | &enablelist); |
8971 | ||
1a966eab AC |
8972 | add_cmd ("once", no_class, enable_once_command, _("\ |
8973 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
8974 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
8975 | &enablelist); |
8976 | ||
1bedd215 AC |
8977 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
8978 | Disable some breakpoints.\n\ | |
c906108c SS |
8979 | Arguments are breakpoint numbers with spaces in between.\n\ |
8980 | To disable all breakpoints, give no argument.\n\ | |
1bedd215 | 8981 | A disabled breakpoint is not forgotten, but has no effect until reenabled."), |
c906108c SS |
8982 | &disablelist, "disable ", 1, &cmdlist); |
8983 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
8984 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
8985 | if (xdb_commands) | |
1bedd215 AC |
8986 | add_com ("sb", class_breakpoint, disable_command, _("\ |
8987 | Disable some breakpoints.\n\ | |
c906108c SS |
8988 | Arguments are breakpoint numbers with spaces in between.\n\ |
8989 | To disable all breakpoints, give no argument.\n\ | |
1bedd215 | 8990 | A disabled breakpoint is not forgotten, but has no effect until reenabled.")); |
c906108c | 8991 | |
1a966eab AC |
8992 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
8993 | Disable some breakpoints.\n\ | |
c906108c SS |
8994 | Arguments are breakpoint numbers with spaces in between.\n\ |
8995 | To disable all breakpoints, give no argument.\n\ | |
8996 | A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\ | |
1a966eab | 8997 | This command may be abbreviated \"disable\"."), |
c906108c SS |
8998 | &disablelist); |
8999 | ||
1bedd215 AC |
9000 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
9001 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
9002 | Arguments are breakpoint numbers with spaces in between.\n\ |
9003 | To delete all breakpoints, give no argument.\n\ | |
9004 | \n\ | |
9005 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 9006 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
9007 | &deletelist, "delete ", 1, &cmdlist); |
9008 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 9009 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 9010 | if (xdb_commands) |
1bedd215 AC |
9011 | add_com ("db", class_breakpoint, delete_command, _("\ |
9012 | Delete some breakpoints.\n\ | |
c906108c | 9013 | Arguments are breakpoint numbers with spaces in between.\n\ |
1bedd215 | 9014 | To delete all breakpoints, give no argument.\n")); |
c906108c | 9015 | |
1a966eab AC |
9016 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
9017 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
9018 | Arguments are breakpoint numbers with spaces in between.\n\ |
9019 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 9020 | This command may be abbreviated \"delete\"."), |
c906108c SS |
9021 | &deletelist); |
9022 | ||
1bedd215 AC |
9023 | add_com ("clear", class_breakpoint, clear_command, _("\ |
9024 | Clear breakpoint at specified line or function.\n\ | |
c906108c SS |
9025 | Argument may be line number, function name, or \"*\" and an address.\n\ |
9026 | If line number is specified, all breakpoints in that line are cleared.\n\ | |
9027 | If function is specified, breakpoints at beginning of function are cleared.\n\ | |
1bedd215 AC |
9028 | If an address is specified, breakpoints at that address are cleared.\n\ |
9029 | \n\ | |
9030 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
c906108c SS |
9031 | is executing in.\n\ |
9032 | \n\ | |
1bedd215 | 9033 | See also the \"delete\" command which clears breakpoints by number.")); |
c906108c | 9034 | |
1bedd215 | 9035 | c = add_com ("break", class_breakpoint, break_command, _("\ |
31e2b00f AS |
9036 | Set breakpoint at specified line or function.\n" |
9037 | BREAK_ARGS_HELP ("break"))); | |
5ba2abeb | 9038 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 9039 | |
c906108c SS |
9040 | add_com_alias ("b", "break", class_run, 1); |
9041 | add_com_alias ("br", "break", class_run, 1); | |
9042 | add_com_alias ("bre", "break", class_run, 1); | |
9043 | add_com_alias ("brea", "break", class_run, 1); | |
9044 | ||
7681d515 PM |
9045 | if (xdb_commands) |
9046 | add_com_alias ("ba", "break", class_breakpoint, 1); | |
c906108c SS |
9047 | |
9048 | if (dbx_commands) | |
9049 | { | |
1bedd215 AC |
9050 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
9051 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
9052 | &stoplist, "stop ", 1, &cmdlist); |
9053 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 9054 | _("Break in function or address."), &stoplist); |
c5aa993b | 9055 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 9056 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
9057 | add_com ("status", class_info, breakpoints_info, _("\ |
9058 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
9059 | The \"Type\" column indicates one of:\n\ |
9060 | \tbreakpoint - normal breakpoint\n\ | |
9061 | \twatchpoint - watchpoint\n\ | |
9062 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
9063 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
9064 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
9065 | address and file/line number respectively.\n\ |
9066 | \n\ | |
9067 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
9068 | are set to the address of the last breakpoint listed unless the command\n\ |
9069 | is prefixed with \"server \".\n\n\ | |
c906108c | 9070 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 9071 | breakpoint set.")); |
c906108c SS |
9072 | } |
9073 | ||
1bedd215 AC |
9074 | add_info ("breakpoints", breakpoints_info, _("\ |
9075 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
9076 | The \"Type\" column indicates one of:\n\ |
9077 | \tbreakpoint - normal breakpoint\n\ | |
9078 | \twatchpoint - watchpoint\n\ | |
9079 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
9080 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
9081 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
9082 | address and file/line number respectively.\n\ |
9083 | \n\ | |
9084 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
9085 | are set to the address of the last breakpoint listed unless the command\n\ |
9086 | is prefixed with \"server \".\n\n\ | |
c906108c | 9087 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 9088 | breakpoint set.")); |
c906108c SS |
9089 | |
9090 | if (xdb_commands) | |
1bedd215 AC |
9091 | add_com ("lb", class_breakpoint, breakpoints_info, _("\ |
9092 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
9093 | The \"Type\" column indicates one of:\n\ |
9094 | \tbreakpoint - normal breakpoint\n\ | |
9095 | \twatchpoint - watchpoint\n\ | |
9096 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
9097 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
9098 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
9099 | address and file/line number respectively.\n\ |
9100 | \n\ | |
9101 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
9102 | are set to the address of the last breakpoint listed unless the command\n\ |
9103 | is prefixed with \"server \".\n\n\ | |
c906108c | 9104 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 9105 | breakpoint set.")); |
c906108c | 9106 | |
1a966eab AC |
9107 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
9108 | Status of all 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 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
9113 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
9114 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
9115 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
9116 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
9117 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
9118 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
9119 | address and file/line number respectively.\n\ |
9120 | \n\ | |
9121 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
9122 | are set to the address of the last breakpoint listed unless the command\n\ |
9123 | is prefixed with \"server \".\n\n\ | |
c906108c | 9124 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 9125 | breakpoint set."), |
c906108c SS |
9126 | &maintenanceinfolist); |
9127 | ||
44feb3ce TT |
9128 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
9129 | Set catchpoints to catch events."), | |
9130 | &catch_cmdlist, "catch ", | |
9131 | 0/*allow-unknown*/, &cmdlist); | |
9132 | ||
9133 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
9134 | Set temporary catchpoints to catch events."), | |
9135 | &tcatch_cmdlist, "tcatch ", | |
9136 | 0/*allow-unknown*/, &cmdlist); | |
9137 | ||
9138 | /* Add catch and tcatch sub-commands. */ | |
9139 | add_catch_command ("catch", _("\ | |
9140 | Catch an exception, when caught.\n\ | |
9141 | With an argument, catch only exceptions with the given name."), | |
9142 | catch_catch_command, | |
9143 | CATCH_PERMANENT, | |
9144 | CATCH_TEMPORARY); | |
9145 | add_catch_command ("throw", _("\ | |
9146 | Catch an exception, when thrown.\n\ | |
9147 | With an argument, catch only exceptions with the given name."), | |
9148 | catch_throw_command, | |
9149 | CATCH_PERMANENT, | |
9150 | CATCH_TEMPORARY); | |
9151 | add_catch_command ("fork", _("Catch calls to fork."), | |
9152 | catch_fork_command_1, | |
9153 | (void *) (uintptr_t) catch_fork_permanent, | |
9154 | (void *) (uintptr_t) catch_fork_temporary); | |
9155 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
9156 | catch_fork_command_1, | |
9157 | (void *) (uintptr_t) catch_vfork_permanent, | |
9158 | (void *) (uintptr_t) catch_vfork_temporary); | |
9159 | add_catch_command ("exec", _("Catch calls to exec."), | |
9160 | catch_exec_command_1, | |
9161 | CATCH_PERMANENT, | |
9162 | CATCH_TEMPORARY); | |
44feb3ce TT |
9163 | add_catch_command ("exception", _("\ |
9164 | Catch Ada exceptions, when raised.\n\ | |
9165 | With an argument, catch only exceptions with the given name."), | |
9166 | catch_ada_exception_command, | |
9167 | CATCH_PERMANENT, | |
9168 | CATCH_TEMPORARY); | |
9169 | add_catch_command ("assert", _("\ | |
9170 | Catch failed Ada assertions, when raised.\n\ | |
9171 | With an argument, catch only exceptions with the given name."), | |
9172 | catch_assert_command, | |
9173 | CATCH_PERMANENT, | |
9174 | CATCH_TEMPORARY); | |
c5aa993b | 9175 | |
1bedd215 AC |
9176 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
9177 | Set a watchpoint for an expression.\n\ | |
c906108c | 9178 | A watchpoint stops execution of your program whenever the value of\n\ |
1bedd215 | 9179 | an expression changes.")); |
65d12d83 | 9180 | set_cmd_completer (c, expression_completer); |
c906108c | 9181 | |
1bedd215 AC |
9182 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
9183 | Set a read watchpoint for an expression.\n\ | |
c906108c | 9184 | A watchpoint stops execution of your program whenever the value of\n\ |
1bedd215 | 9185 | an expression is read.")); |
65d12d83 | 9186 | set_cmd_completer (c, expression_completer); |
c906108c | 9187 | |
1bedd215 AC |
9188 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
9189 | Set a watchpoint for an expression.\n\ | |
c906108c | 9190 | A watchpoint stops execution of your program whenever the value of\n\ |
1bedd215 | 9191 | an expression is either read or written.")); |
65d12d83 | 9192 | set_cmd_completer (c, expression_completer); |
c906108c SS |
9193 | |
9194 | add_info ("watchpoints", breakpoints_info, | |
1bedd215 | 9195 | _("Synonym for ``info breakpoints''.")); |
c906108c SS |
9196 | |
9197 | ||
920d2a44 AC |
9198 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
9199 | respond to changes - contrary to the description. */ | |
85c07804 AC |
9200 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
9201 | &can_use_hw_watchpoints, _("\ | |
9202 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
9203 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
9204 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
9205 | such is available. (However, any hardware watchpoints that were\n\ | |
9206 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
9207 | hardware.)"), |
9208 | NULL, | |
920d2a44 | 9209 | show_can_use_hw_watchpoints, |
85c07804 | 9210 | &setlist, &showlist); |
c906108c SS |
9211 | |
9212 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 9213 | |
1042e4c0 SS |
9214 | /* Tracepoint manipulation commands. */ |
9215 | ||
9216 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
9217 | Set a tracepoint at specified line or function.\n\ | |
9218 | \n" | |
9219 | BREAK_ARGS_HELP ("trace") "\n\ | |
9220 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
9221 | set_cmd_completer (c, location_completer); | |
9222 | ||
9223 | add_com_alias ("tp", "trace", class_alias, 0); | |
9224 | add_com_alias ("tr", "trace", class_alias, 1); | |
9225 | add_com_alias ("tra", "trace", class_alias, 1); | |
9226 | add_com_alias ("trac", "trace", class_alias, 1); | |
9227 | ||
9228 | add_info ("tracepoints", tracepoints_info, _("\ | |
9229 | Status of tracepoints, or tracepoint number NUMBER.\n\ | |
9230 | Convenience variable \"$tpnum\" contains the number of the\n\ | |
9231 | last tracepoint set.")); | |
9232 | ||
9233 | add_info_alias ("tp", "tracepoints", 1); | |
9234 | ||
9235 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
9236 | Delete specified tracepoints.\n\ | |
9237 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
9238 | No argument means delete all tracepoints."), | |
9239 | &deletelist); | |
9240 | ||
9241 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
9242 | Disable specified tracepoints.\n\ | |
9243 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
9244 | No argument means disable all tracepoints."), | |
9245 | &disablelist); | |
9246 | deprecate_cmd (c, "disable"); | |
9247 | ||
9248 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
9249 | Enable specified tracepoints.\n\ | |
9250 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
9251 | No argument means enable all tracepoints."), | |
9252 | &enablelist); | |
9253 | deprecate_cmd (c, "enable"); | |
9254 | ||
9255 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
9256 | Set the passcount for a tracepoint.\n\ | |
9257 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
9258 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
9259 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
9260 | ||
9261 | c = add_com ("save-tracepoints", class_trace, tracepoint_save_command, _("\ | |
9262 | Save current tracepoint definitions as a script.\n\ | |
9263 | Use the 'source' command in another debug session to restore them.")); | |
9264 | set_cmd_completer (c, filename_completer); | |
9265 | ||
1bedd215 | 9266 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
9267 | Breakpoint specific settings\n\ |
9268 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 9269 | pending breakpoint behavior"), |
fa8d40ab JJ |
9270 | &breakpoint_set_cmdlist, "set breakpoint ", |
9271 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 9272 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
9273 | Breakpoint specific settings\n\ |
9274 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 9275 | pending breakpoint behavior"), |
fa8d40ab JJ |
9276 | &breakpoint_show_cmdlist, "show breakpoint ", |
9277 | 0/*allow-unknown*/, &showlist); | |
9278 | ||
7915a72c AC |
9279 | add_setshow_auto_boolean_cmd ("pending", no_class, |
9280 | &pending_break_support, _("\ | |
9281 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
9282 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
9283 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
9284 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
9285 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 9286 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 9287 | NULL, |
920d2a44 | 9288 | show_pending_break_support, |
6e1d7d6c AC |
9289 | &breakpoint_set_cmdlist, |
9290 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
9291 | |
9292 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
9293 | |
9294 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
9295 | &automatic_hardware_breakpoints, _("\ | |
9296 | Set automatic usage of hardware breakpoints."), _("\ | |
9297 | Show automatic usage of hardware breakpoints."), _("\ | |
9298 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
9299 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
9300 | a warning will be emitted for such breakpoints."), | |
9301 | NULL, | |
9302 | show_automatic_hardware_breakpoints, | |
9303 | &breakpoint_set_cmdlist, | |
9304 | &breakpoint_show_cmdlist); | |
74960c60 | 9305 | |
33e5cbd6 PA |
9306 | add_setshow_enum_cmd ("always-inserted", class_support, |
9307 | always_inserted_enums, &always_inserted_mode, _("\ | |
74960c60 VP |
9308 | Set mode for inserting breakpoints."), _("\ |
9309 | Show mode for inserting breakpoints."), _("\ | |
33e5cbd6 PA |
9310 | When this mode is off, breakpoints are inserted in inferior when it is\n\ |
9311 | resumed, and removed when execution stops. When this mode is on,\n\ | |
9312 | breakpoints are inserted immediately and removed only when the user\n\ | |
9313 | deletes the breakpoint. When this mode is auto (which is the default),\n\ | |
9314 | the behaviour depends on the non-stop setting (see help set non-stop).\n\ | |
9315 | In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\ | |
9316 | behaves as if always-inserted mode is on; if gdb is controlling the\n\ | |
9317 | inferior in all-stop mode, gdb behaves as if always-inserted mode is off."), | |
74960c60 VP |
9318 | NULL, |
9319 | &show_always_inserted_mode, | |
9320 | &breakpoint_set_cmdlist, | |
9321 | &breakpoint_show_cmdlist); | |
765dc015 VP |
9322 | |
9323 | automatic_hardware_breakpoints = 1; | |
f3b1572e PA |
9324 | |
9325 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
c906108c | 9326 | } |