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 | ||
48cb2d85 VP |
565 | /* Return the breakpoint with the specified number, or NULL |
566 | if the number does not refer to an existing breakpoint. */ | |
567 | ||
568 | struct breakpoint * | |
569 | get_breakpoint (int num) | |
570 | { | |
571 | struct breakpoint *b; | |
572 | ||
573 | ALL_BREAKPOINTS (b) | |
574 | if (b->number == num) | |
575 | return b; | |
576 | ||
577 | return NULL; | |
578 | } | |
5c44784c | 579 | |
c906108c SS |
580 | \f |
581 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ | |
582 | ||
583 | static void | |
fba45db2 | 584 | condition_command (char *arg, int from_tty) |
c906108c | 585 | { |
52f0bd74 | 586 | struct breakpoint *b; |
c906108c | 587 | char *p; |
52f0bd74 | 588 | int bnum; |
c906108c SS |
589 | |
590 | if (arg == 0) | |
e2e0b3e5 | 591 | error_no_arg (_("breakpoint number")); |
c906108c SS |
592 | |
593 | p = arg; | |
594 | bnum = get_number (&p); | |
5c44784c | 595 | if (bnum == 0) |
8a3fe4f8 | 596 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
597 | |
598 | ALL_BREAKPOINTS (b) | |
599 | if (b->number == bnum) | |
2f069f6f JB |
600 | { |
601 | struct bp_location *loc = b->loc; | |
602 | for (; loc; loc = loc->next) | |
603 | { | |
604 | if (loc->cond) | |
605 | { | |
606 | xfree (loc->cond); | |
607 | loc->cond = 0; | |
608 | } | |
609 | } | |
610 | if (b->cond_string != NULL) | |
611 | xfree (b->cond_string); | |
c906108c | 612 | |
2f069f6f JB |
613 | if (*p == 0) |
614 | { | |
615 | b->cond_string = NULL; | |
616 | if (from_tty) | |
617 | printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum); | |
618 | } | |
619 | else | |
620 | { | |
621 | arg = p; | |
622 | /* I don't know if it matters whether this is the string the user | |
623 | typed in or the decompiled expression. */ | |
1b36a34b | 624 | b->cond_string = xstrdup (arg); |
2f069f6f JB |
625 | b->condition_not_parsed = 0; |
626 | for (loc = b->loc; loc; loc = loc->next) | |
627 | { | |
628 | arg = p; | |
629 | loc->cond = | |
630 | parse_exp_1 (&arg, block_for_pc (loc->address), 0); | |
631 | if (*arg) | |
632 | error (_("Junk at end of expression")); | |
633 | } | |
634 | } | |
635 | breakpoints_changed (); | |
383f836e | 636 | observer_notify_breakpoint_modified (b->number); |
2f069f6f JB |
637 | return; |
638 | } | |
c906108c | 639 | |
8a3fe4f8 | 640 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
641 | } |
642 | ||
48cb2d85 VP |
643 | /* Set the command list of B to COMMANDS. */ |
644 | ||
645 | void | |
646 | breakpoint_set_commands (struct breakpoint *b, struct command_line *commands) | |
647 | { | |
648 | free_command_lines (&b->commands); | |
649 | b->commands = commands; | |
650 | breakpoints_changed (); | |
651 | observer_notify_breakpoint_modified (b->number); | |
652 | } | |
653 | ||
c906108c | 654 | static void |
fba45db2 | 655 | commands_command (char *arg, int from_tty) |
c906108c | 656 | { |
52f0bd74 | 657 | struct breakpoint *b; |
c906108c | 658 | char *p; |
52f0bd74 | 659 | int bnum; |
c906108c SS |
660 | struct command_line *l; |
661 | ||
662 | /* If we allowed this, we would have problems with when to | |
663 | free the storage, if we change the commands currently | |
664 | being read from. */ | |
665 | ||
666 | if (executing_breakpoint_commands) | |
8a3fe4f8 | 667 | error (_("Can't use the \"commands\" command among a breakpoint's commands.")); |
c906108c SS |
668 | |
669 | p = arg; | |
670 | bnum = get_number (&p); | |
5c44784c | 671 | |
c906108c | 672 | if (p && *p) |
8a3fe4f8 | 673 | error (_("Unexpected extra arguments following breakpoint number.")); |
c5aa993b | 674 | |
c906108c SS |
675 | ALL_BREAKPOINTS (b) |
676 | if (b->number == bnum) | |
9ebf4acf AC |
677 | { |
678 | char *tmpbuf = xstrprintf ("Type commands for when breakpoint %d is hit, one per line.", | |
679 | bnum); | |
680 | struct cleanup *cleanups = make_cleanup (xfree, tmpbuf); | |
311a4e6b | 681 | l = read_command_lines (tmpbuf, from_tty, 1); |
9ebf4acf | 682 | do_cleanups (cleanups); |
48cb2d85 | 683 | breakpoint_set_commands (b, l); |
9ebf4acf | 684 | return; |
c5aa993b | 685 | } |
8a3fe4f8 | 686 | error (_("No breakpoint number %d."), bnum); |
c906108c | 687 | } |
40c03ae8 EZ |
688 | |
689 | /* Like commands_command, but instead of reading the commands from | |
690 | input stream, takes them from an already parsed command structure. | |
691 | ||
692 | This is used by cli-script.c to DTRT with breakpoint commands | |
693 | that are part of if and while bodies. */ | |
694 | enum command_control_type | |
695 | commands_from_control_command (char *arg, struct command_line *cmd) | |
696 | { | |
697 | struct breakpoint *b; | |
698 | char *p; | |
699 | int bnum; | |
700 | ||
701 | /* If we allowed this, we would have problems with when to | |
702 | free the storage, if we change the commands currently | |
703 | being read from. */ | |
704 | ||
705 | if (executing_breakpoint_commands) | |
706 | error (_("Can't use the \"commands\" command among a breakpoint's commands.")); | |
707 | ||
708 | /* An empty string for the breakpoint number means the last | |
709 | breakpoint, but get_number expects a NULL pointer. */ | |
710 | if (arg && !*arg) | |
711 | p = NULL; | |
712 | else | |
713 | p = arg; | |
714 | bnum = get_number (&p); | |
715 | ||
716 | if (p && *p) | |
717 | error (_("Unexpected extra arguments following breakpoint number.")); | |
718 | ||
719 | ALL_BREAKPOINTS (b) | |
720 | if (b->number == bnum) | |
721 | { | |
722 | free_command_lines (&b->commands); | |
723 | if (cmd->body_count != 1) | |
724 | error (_("Invalid \"commands\" block structure.")); | |
725 | /* We need to copy the commands because if/while will free the | |
726 | list after it finishes execution. */ | |
727 | b->commands = copy_command_lines (cmd->body_list[0]); | |
728 | breakpoints_changed (); | |
383f836e | 729 | observer_notify_breakpoint_modified (b->number); |
40c03ae8 | 730 | return simple_control; |
2f069f6f | 731 | } |
40c03ae8 EZ |
732 | error (_("No breakpoint number %d."), bnum); |
733 | } | |
c906108c | 734 | \f |
8defab1a DJ |
735 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
736 | by replacing any memory breakpoints with their shadowed contents. */ | |
c906108c | 737 | |
8defab1a DJ |
738 | void |
739 | breakpoint_restore_shadows (gdb_byte *buf, ULONGEST memaddr, LONGEST len) | |
c906108c | 740 | { |
8defab1a | 741 | struct bp_location *b; |
c906108c SS |
742 | CORE_ADDR bp_addr = 0; |
743 | int bp_size = 0; | |
8defab1a | 744 | int bptoffset = 0; |
c5aa993b | 745 | |
ffce0d52 | 746 | ALL_BP_LOCATIONS (b) |
c5aa993b | 747 | { |
ffce0d52 | 748 | if (b->owner->type == bp_none) |
8a3fe4f8 | 749 | warning (_("reading through apparently deleted breakpoint #%d?"), |
ffce0d52 DJ |
750 | b->owner->number); |
751 | ||
752 | if (b->loc_type != bp_loc_software_breakpoint) | |
c5aa993b | 753 | continue; |
ffce0d52 | 754 | if (!b->inserted) |
c5aa993b JM |
755 | continue; |
756 | /* Addresses and length of the part of the breakpoint that | |
757 | we need to copy. */ | |
8181d85f DJ |
758 | bp_addr = b->target_info.placed_address; |
759 | bp_size = b->target_info.shadow_len; | |
c5aa993b | 760 | if (bp_size == 0) |
8181d85f | 761 | /* bp isn't valid, or doesn't shadow memory. */ |
c5aa993b | 762 | continue; |
8defab1a | 763 | |
c5aa993b JM |
764 | if (bp_addr + bp_size <= memaddr) |
765 | /* The breakpoint is entirely before the chunk of memory we | |
766 | are reading. */ | |
767 | continue; | |
8defab1a | 768 | |
c5aa993b JM |
769 | if (bp_addr >= memaddr + len) |
770 | /* The breakpoint is entirely after the chunk of memory we are | |
771 | reading. */ | |
772 | continue; | |
c5aa993b | 773 | |
8defab1a DJ |
774 | /* Offset within shadow_contents. */ |
775 | if (bp_addr < memaddr) | |
776 | { | |
777 | /* Only copy the second part of the breakpoint. */ | |
778 | bp_size -= memaddr - bp_addr; | |
779 | bptoffset = memaddr - bp_addr; | |
780 | bp_addr = memaddr; | |
781 | } | |
c5aa993b | 782 | |
8defab1a DJ |
783 | if (bp_addr + bp_size > memaddr + len) |
784 | { | |
785 | /* Only copy the first part of the breakpoint. */ | |
786 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
787 | } | |
c5aa993b | 788 | |
8defab1a DJ |
789 | memcpy (buf + bp_addr - memaddr, |
790 | b->target_info.shadow_contents + bptoffset, bp_size); | |
c5aa993b | 791 | } |
c906108c | 792 | } |
c906108c | 793 | \f |
c5aa993b | 794 | |
687595f9 | 795 | /* A wrapper function for inserting catchpoints. */ |
9cbc821d | 796 | static void |
687595f9 DJ |
797 | insert_catchpoint (struct ui_out *uo, void *args) |
798 | { | |
799 | struct breakpoint *b = (struct breakpoint *) args; | |
800 | int val = -1; | |
801 | ||
fe798b75 JB |
802 | gdb_assert (b->type == bp_catchpoint); |
803 | gdb_assert (b->ops != NULL && b->ops->insert != NULL); | |
804 | ||
805 | b->ops->insert (b); | |
687595f9 DJ |
806 | } |
807 | ||
a5606eee VP |
808 | static int |
809 | is_hardware_watchpoint (struct breakpoint *bpt) | |
810 | { | |
811 | return (bpt->type == bp_hardware_watchpoint | |
812 | || bpt->type == bp_read_watchpoint | |
813 | || bpt->type == bp_access_watchpoint); | |
814 | } | |
7270d8f2 | 815 | |
fa4727a6 DJ |
816 | /* Find the current value of a watchpoint on EXP. Return the value in |
817 | *VALP and *RESULTP and the chain of intermediate and final values | |
818 | in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does | |
819 | not need them. | |
820 | ||
ccc57cf9 | 821 | If a memory error occurs while evaluating the expression, *RESULTP will |
fa4727a6 DJ |
822 | be set to NULL. *RESULTP may be a lazy value, if the result could |
823 | not be read from memory. It is used to determine whether a value | |
824 | is user-specified (we should watch the whole value) or intermediate | |
825 | (we should watch only the bit used to locate the final value). | |
826 | ||
827 | If the final value, or any intermediate value, could not be read | |
828 | from memory, *VALP will be set to NULL. *VAL_CHAIN will still be | |
829 | set to any referenced values. *VALP will never be a lazy value. | |
830 | This is the value which we store in struct breakpoint. | |
831 | ||
832 | If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the | |
833 | value chain. The caller must free the values individually. If | |
834 | VAL_CHAIN is NULL, all generated values will be left on the value | |
835 | chain. */ | |
836 | ||
837 | static void | |
838 | fetch_watchpoint_value (struct expression *exp, struct value **valp, | |
839 | struct value **resultp, struct value **val_chain) | |
840 | { | |
841 | struct value *mark, *new_mark, *result; | |
ccc57cf9 | 842 | volatile struct gdb_exception ex; |
fa4727a6 DJ |
843 | |
844 | *valp = NULL; | |
845 | if (resultp) | |
846 | *resultp = NULL; | |
847 | if (val_chain) | |
848 | *val_chain = NULL; | |
849 | ||
850 | /* Evaluate the expression. */ | |
851 | mark = value_mark (); | |
852 | result = NULL; | |
ccc57cf9 PA |
853 | |
854 | TRY_CATCH (ex, RETURN_MASK_ALL) | |
855 | { | |
856 | result = evaluate_expression (exp); | |
857 | } | |
858 | if (ex.reason < 0) | |
859 | { | |
860 | /* Ignore memory errors, we want watchpoints pointing at | |
861 | inaccessible memory to still be created; otherwise, throw the | |
862 | error to some higher catcher. */ | |
863 | switch (ex.error) | |
864 | { | |
865 | case MEMORY_ERROR: | |
866 | break; | |
867 | default: | |
868 | throw_exception (ex); | |
869 | break; | |
870 | } | |
871 | } | |
872 | ||
fa4727a6 DJ |
873 | new_mark = value_mark (); |
874 | if (mark == new_mark) | |
875 | return; | |
876 | if (resultp) | |
877 | *resultp = result; | |
878 | ||
879 | /* Make sure it's not lazy, so that after the target stops again we | |
880 | have a non-lazy previous value to compare with. */ | |
881 | if (result != NULL | |
882 | && (!value_lazy (result) || gdb_value_fetch_lazy (result))) | |
883 | *valp = result; | |
884 | ||
885 | if (val_chain) | |
886 | { | |
887 | /* Return the chain of intermediate values. We use this to | |
888 | decide which addresses to watch. */ | |
889 | *val_chain = new_mark; | |
890 | value_release_to_mark (mark); | |
891 | } | |
892 | } | |
893 | ||
567e1b4e JB |
894 | /* Assuming that B is a watchpoint: |
895 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 896 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
897 | - Evaluate the condition if there is one, and store the result |
898 | in b->loc->cond. | |
a5606eee VP |
899 | - Update the list of values that must be watched in B->loc. |
900 | ||
bfa149ac JB |
901 | If the watchpoint disposition is disp_del_at_next_stop, then do nothing. |
902 | If this is local watchpoint that is out of scope, delete it. */ | |
b40ce68a | 903 | static void |
a5606eee | 904 | update_watchpoint (struct breakpoint *b, int reparse) |
7270d8f2 | 905 | { |
a5606eee | 906 | int within_current_scope; |
a5606eee VP |
907 | struct frame_id saved_frame_id; |
908 | struct bp_location *loc; | |
909 | bpstat bs; | |
910 | ||
567e1b4e JB |
911 | /* We don't free locations. They are stored in bp_location_chain and |
912 | update_global_locations will eventually delete them and remove | |
913 | breakpoints if needed. */ | |
a5606eee VP |
914 | b->loc = NULL; |
915 | ||
916 | if (b->disposition == disp_del_at_next_stop) | |
917 | return; | |
918 | ||
919 | /* Save the current frame's ID so we can restore it after | |
920 | evaluating the watchpoint expression on its own frame. */ | |
921 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
922 | took a frame parameter, so that we didn't have to change the | |
923 | selected frame. */ | |
924 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
925 | ||
926 | /* Determine if the watchpoint is within scope. */ | |
927 | if (b->exp_valid_block == NULL) | |
928 | within_current_scope = 1; | |
929 | else | |
930 | { | |
931 | struct frame_info *fi; | |
932 | fi = frame_find_by_id (b->watchpoint_frame); | |
933 | within_current_scope = (fi != NULL); | |
934 | if (within_current_scope) | |
935 | select_frame (fi); | |
936 | } | |
937 | ||
938 | if (within_current_scope && reparse) | |
939 | { | |
940 | char *s; | |
941 | if (b->exp) | |
942 | { | |
943 | xfree (b->exp); | |
944 | b->exp = NULL; | |
945 | } | |
946 | s = b->exp_string; | |
947 | b->exp = parse_exp_1 (&s, b->exp_valid_block, 0); | |
948 | /* If the meaning of expression itself changed, the old value is | |
949 | no longer relevant. We don't want to report a watchpoint hit | |
950 | to the user when the old value and the new value may actually | |
951 | be completely different objects. */ | |
952 | value_free (b->val); | |
fa4727a6 DJ |
953 | b->val = NULL; |
954 | b->val_valid = 0; | |
a5606eee | 955 | } |
a5606eee VP |
956 | |
957 | /* If we failed to parse the expression, for example because | |
958 | it refers to a global variable in a not-yet-loaded shared library, | |
959 | don't try to insert watchpoint. We don't automatically delete | |
960 | such watchpoint, though, since failure to parse expression | |
961 | is different from out-of-scope watchpoint. */ | |
962 | if (within_current_scope && b->exp) | |
963 | { | |
fa4727a6 | 964 | struct value *val_chain, *v, *result, *next; |
a5606eee | 965 | |
fa4727a6 | 966 | fetch_watchpoint_value (b->exp, &v, &result, &val_chain); |
a5606eee | 967 | |
a5606eee VP |
968 | /* Avoid setting b->val if it's already set. The meaning of |
969 | b->val is 'the last value' user saw, and we should update | |
970 | it only if we reported that last value to user. As it | |
971 | happens, the code that reports it updates b->val directly. */ | |
fa4727a6 DJ |
972 | if (!b->val_valid) |
973 | { | |
974 | b->val = v; | |
975 | b->val_valid = 1; | |
976 | } | |
a5606eee | 977 | |
db2ad4c3 JK |
978 | /* Change the type of breakpoint between hardware assisted or an |
979 | ordinary watchpoint depending on the hardware support and free | |
980 | hardware slots. REPARSE is set when the inferior is started. */ | |
981 | if ((b->type == bp_watchpoint || b->type == bp_hardware_watchpoint) | |
982 | && reparse) | |
983 | { | |
ca2d49e8 | 984 | int i, mem_cnt, other_type_used; |
db2ad4c3 JK |
985 | |
986 | i = hw_watchpoint_used_count (bp_hardware_watchpoint, | |
987 | &other_type_used); | |
988 | mem_cnt = can_use_hardware_watchpoint (val_chain); | |
989 | ||
ca2d49e8 | 990 | if (!mem_cnt) |
db2ad4c3 JK |
991 | b->type = bp_watchpoint; |
992 | else | |
ca2d49e8 | 993 | { |
d92524f1 | 994 | int target_resources_ok = target_can_use_hardware_watchpoint |
ca2d49e8 SL |
995 | (bp_hardware_watchpoint, i + mem_cnt, other_type_used); |
996 | if (target_resources_ok <= 0) | |
997 | b->type = bp_watchpoint; | |
998 | else | |
999 | b->type = bp_hardware_watchpoint; | |
1000 | } | |
db2ad4c3 JK |
1001 | } |
1002 | ||
a5606eee | 1003 | /* Look at each value on the value chain. */ |
fa4727a6 | 1004 | for (v = val_chain; v; v = next) |
a5606eee VP |
1005 | { |
1006 | /* If it's a memory location, and GDB actually needed | |
1007 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1008 | must watch it. If the first value returned is |
1009 | still lazy, that means an error occurred reading it; | |
1010 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1011 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 1012 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
1013 | { |
1014 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1015 | |
a5606eee VP |
1016 | /* We only watch structs and arrays if user asked |
1017 | for it explicitly, never if they just happen to | |
1018 | appear in the middle of some value chain. */ | |
fa4727a6 | 1019 | if (v == result |
a5606eee VP |
1020 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
1021 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
1022 | { | |
1023 | CORE_ADDR addr; | |
1024 | int len, type; | |
1025 | struct bp_location *loc, **tmp; | |
1026 | ||
42ae5230 | 1027 | addr = value_address (v); |
a5606eee VP |
1028 | len = TYPE_LENGTH (value_type (v)); |
1029 | type = hw_write; | |
1030 | if (b->type == bp_read_watchpoint) | |
1031 | type = hw_read; | |
1032 | else if (b->type == bp_access_watchpoint) | |
1033 | type = hw_access; | |
1034 | ||
39d61571 | 1035 | loc = allocate_bp_location (b); |
a5606eee VP |
1036 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
1037 | ; | |
1038 | *tmp = loc; | |
a6d9a66e | 1039 | loc->gdbarch = get_type_arch (value_type (v)); |
a5606eee VP |
1040 | loc->address = addr; |
1041 | loc->length = len; | |
1042 | loc->watchpoint_type = type; | |
1043 | } | |
1044 | } | |
1045 | ||
1046 | next = value_next (v); | |
1047 | if (v != b->val) | |
1048 | value_free (v); | |
1049 | } | |
1050 | ||
2ec93238 MK |
1051 | /* We just regenerated the list of breakpoint locations. |
1052 | The new location does not have its condition field set to anything | |
1053 | and therefore, we must always reparse the cond_string, independently | |
1054 | of the value of the reparse flag. */ | |
1055 | if (b->cond_string != NULL) | |
a5606eee VP |
1056 | { |
1057 | char *s = b->cond_string; | |
a5606eee VP |
1058 | b->loc->cond = parse_exp_1 (&s, b->exp_valid_block, 0); |
1059 | } | |
1060 | } | |
1061 | else if (!within_current_scope) | |
7270d8f2 | 1062 | { |
a5606eee | 1063 | printf_filtered (_("\ |
567e1b4e | 1064 | Watchpoint %d deleted because the program has left the block \n\ |
a5606eee VP |
1065 | in which its expression is valid.\n"), |
1066 | b->number); | |
1067 | if (b->related_breakpoint) | |
1068 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
1069 | b->disposition = disp_del_at_next_stop; | |
7270d8f2 | 1070 | } |
a5606eee VP |
1071 | |
1072 | /* Restore the selected frame. */ | |
1073 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
1074 | } |
1075 | ||
a5606eee | 1076 | |
74960c60 VP |
1077 | /* Returns 1 iff breakpoint location should be |
1078 | inserted in the inferior. */ | |
1079 | static int | |
1080 | should_be_inserted (struct bp_location *bpt) | |
1081 | { | |
1082 | if (!breakpoint_enabled (bpt->owner)) | |
1083 | return 0; | |
1084 | ||
1085 | if (bpt->owner->disposition == disp_del_at_next_stop) | |
1086 | return 0; | |
1087 | ||
1088 | if (!bpt->enabled || bpt->shlib_disabled || bpt->duplicate) | |
1089 | return 0; | |
1090 | ||
1042e4c0 SS |
1091 | /* Tracepoints are inserted by the target at a time of its choosing, |
1092 | not by us. */ | |
1093 | if (bpt->owner->type == bp_tracepoint) | |
1094 | return 0; | |
1095 | ||
74960c60 VP |
1096 | return 1; |
1097 | } | |
1098 | ||
879bfdc2 DJ |
1099 | /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint. |
1100 | Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS, | |
fa3a767f | 1101 | and HW_BREAKPOINT_ERROR are used to report problems. |
879bfdc2 DJ |
1102 | |
1103 | NOTE drow/2003-09-09: This routine could be broken down to an object-style | |
1104 | method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 1105 | static int |
879bfdc2 | 1106 | insert_bp_location (struct bp_location *bpt, |
26bb91f3 | 1107 | struct ui_file *tmp_error_stream, |
fa3a767f | 1108 | int *disabled_breaks, |
26bb91f3 | 1109 | int *hw_breakpoint_error) |
879bfdc2 DJ |
1110 | { |
1111 | int val = 0; | |
1112 | ||
74960c60 | 1113 | if (!should_be_inserted (bpt) || bpt->inserted) |
879bfdc2 DJ |
1114 | return 0; |
1115 | ||
8181d85f DJ |
1116 | /* Initialize the target-specific information. */ |
1117 | memset (&bpt->target_info, 0, sizeof (bpt->target_info)); | |
1118 | bpt->target_info.placed_address = bpt->address; | |
1119 | ||
879bfdc2 DJ |
1120 | if (bpt->loc_type == bp_loc_software_breakpoint |
1121 | || bpt->loc_type == bp_loc_hardware_breakpoint) | |
1122 | { | |
765dc015 VP |
1123 | if (bpt->owner->type != bp_hardware_breakpoint) |
1124 | { | |
1125 | /* If the explicitly specified breakpoint type | |
1126 | is not hardware breakpoint, check the memory map to see | |
1127 | if the breakpoint address is in read only memory or not. | |
1128 | Two important cases are: | |
1129 | - location type is not hardware breakpoint, memory | |
1130 | is readonly. We change the type of the location to | |
1131 | hardware breakpoint. | |
1132 | - location type is hardware breakpoint, memory is read-write. | |
1133 | This means we've previously made the location hardware one, but | |
1134 | then the memory map changed, so we undo. | |
1135 | ||
1136 | When breakpoints are removed, remove_breakpoints will | |
1137 | use location types we've just set here, the only possible | |
1138 | problem is that memory map has changed during running program, | |
1139 | but it's not going to work anyway with current gdb. */ | |
1140 | struct mem_region *mr | |
1141 | = lookup_mem_region (bpt->target_info.placed_address); | |
1142 | ||
1143 | if (mr) | |
1144 | { | |
1145 | if (automatic_hardware_breakpoints) | |
1146 | { | |
1147 | int changed = 0; | |
1148 | enum bp_loc_type new_type; | |
1149 | ||
1150 | if (mr->attrib.mode != MEM_RW) | |
1151 | new_type = bp_loc_hardware_breakpoint; | |
1152 | else | |
1153 | new_type = bp_loc_software_breakpoint; | |
1154 | ||
1155 | if (new_type != bpt->loc_type) | |
1156 | { | |
1157 | static int said = 0; | |
1158 | bpt->loc_type = new_type; | |
1159 | if (!said) | |
1160 | { | |
1161 | fprintf_filtered (gdb_stdout, _("\ | |
0767c96d | 1162 | Note: automatically using hardware breakpoints for read-only addresses.\n")); |
765dc015 VP |
1163 | said = 1; |
1164 | } | |
1165 | } | |
1166 | } | |
1167 | else if (bpt->loc_type == bp_loc_software_breakpoint | |
1168 | && mr->attrib.mode != MEM_RW) | |
1169 | warning (_("cannot set software breakpoint at readonly address %s"), | |
5af949e3 | 1170 | paddress (bpt->gdbarch, bpt->address)); |
765dc015 VP |
1171 | } |
1172 | } | |
1173 | ||
879bfdc2 DJ |
1174 | /* First check to see if we have to handle an overlay. */ |
1175 | if (overlay_debugging == ovly_off | |
1176 | || bpt->section == NULL | |
1177 | || !(section_is_overlay (bpt->section))) | |
1178 | { | |
1179 | /* No overlay handling: just set the breakpoint. */ | |
1180 | ||
1181 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
a6d9a66e UW |
1182 | val = target_insert_hw_breakpoint (bpt->gdbarch, |
1183 | &bpt->target_info); | |
879bfdc2 | 1184 | else |
a6d9a66e UW |
1185 | val = target_insert_breakpoint (bpt->gdbarch, |
1186 | &bpt->target_info); | |
879bfdc2 DJ |
1187 | } |
1188 | else | |
1189 | { | |
1190 | /* This breakpoint is in an overlay section. | |
1191 | Shall we set a breakpoint at the LMA? */ | |
1192 | if (!overlay_events_enabled) | |
1193 | { | |
1194 | /* Yes -- overlay event support is not active, | |
1195 | so we must try to set a breakpoint at the LMA. | |
1196 | This will not work for a hardware breakpoint. */ | |
1197 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
8a3fe4f8 | 1198 | warning (_("hardware breakpoint %d not supported in overlay!"), |
879bfdc2 DJ |
1199 | bpt->owner->number); |
1200 | else | |
1201 | { | |
1202 | CORE_ADDR addr = overlay_unmapped_address (bpt->address, | |
1203 | bpt->section); | |
1204 | /* Set a software (trap) breakpoint at the LMA. */ | |
8181d85f DJ |
1205 | bpt->overlay_target_info = bpt->target_info; |
1206 | bpt->overlay_target_info.placed_address = addr; | |
a6d9a66e UW |
1207 | val = target_insert_breakpoint (bpt->gdbarch, |
1208 | &bpt->overlay_target_info); | |
879bfdc2 | 1209 | if (val != 0) |
99361f52 DE |
1210 | fprintf_unfiltered (tmp_error_stream, |
1211 | "Overlay breakpoint %d failed: in ROM?\n", | |
879bfdc2 DJ |
1212 | bpt->owner->number); |
1213 | } | |
1214 | } | |
1215 | /* Shall we set a breakpoint at the VMA? */ | |
1216 | if (section_is_mapped (bpt->section)) | |
1217 | { | |
1218 | /* Yes. This overlay section is mapped into memory. */ | |
1219 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
a6d9a66e UW |
1220 | val = target_insert_hw_breakpoint (bpt->gdbarch, |
1221 | &bpt->target_info); | |
879bfdc2 | 1222 | else |
a6d9a66e UW |
1223 | val = target_insert_breakpoint (bpt->gdbarch, |
1224 | &bpt->target_info); | |
879bfdc2 DJ |
1225 | } |
1226 | else | |
1227 | { | |
1228 | /* No. This breakpoint will not be inserted. | |
1229 | No error, but do not mark the bp as 'inserted'. */ | |
1230 | return 0; | |
1231 | } | |
1232 | } | |
1233 | ||
1234 | if (val) | |
1235 | { | |
1236 | /* Can't set the breakpoint. */ | |
f5c9a895 | 1237 | if (solib_name_from_address (bpt->address)) |
879bfdc2 DJ |
1238 | { |
1239 | /* See also: disable_breakpoints_in_shlibs. */ | |
1240 | val = 0; | |
0d381245 | 1241 | bpt->shlib_disabled = 1; |
879bfdc2 DJ |
1242 | if (!*disabled_breaks) |
1243 | { | |
1244 | fprintf_unfiltered (tmp_error_stream, | |
1245 | "Cannot insert breakpoint %d.\n", | |
1246 | bpt->owner->number); | |
1247 | fprintf_unfiltered (tmp_error_stream, | |
1248 | "Temporarily disabling shared library breakpoints:\n"); | |
1249 | } | |
1250 | *disabled_breaks = 1; | |
1251 | fprintf_unfiltered (tmp_error_stream, | |
1252 | "breakpoint #%d\n", bpt->owner->number); | |
1253 | } | |
1254 | else | |
879bfdc2 | 1255 | { |
879bfdc2 DJ |
1256 | if (bpt->loc_type == bp_loc_hardware_breakpoint) |
1257 | { | |
1258 | *hw_breakpoint_error = 1; | |
1259 | fprintf_unfiltered (tmp_error_stream, | |
1260 | "Cannot insert hardware breakpoint %d.\n", | |
1261 | bpt->owner->number); | |
1262 | } | |
1263 | else | |
1264 | { | |
1265 | fprintf_unfiltered (tmp_error_stream, | |
1266 | "Cannot insert breakpoint %d.\n", | |
1267 | bpt->owner->number); | |
1268 | fprintf_filtered (tmp_error_stream, | |
1269 | "Error accessing memory address "); | |
5af949e3 UW |
1270 | fputs_filtered (paddress (bpt->gdbarch, bpt->address), |
1271 | tmp_error_stream); | |
879bfdc2 DJ |
1272 | fprintf_filtered (tmp_error_stream, ": %s.\n", |
1273 | safe_strerror (val)); | |
1274 | } | |
1275 | ||
1276 | } | |
1277 | } | |
1278 | else | |
1279 | bpt->inserted = 1; | |
1280 | ||
1281 | return val; | |
1282 | } | |
1283 | ||
1284 | else if (bpt->loc_type == bp_loc_hardware_watchpoint | |
1285 | /* NOTE drow/2003-09-08: This state only exists for removing | |
1286 | watchpoints. It's not clear that it's necessary... */ | |
1287 | && bpt->owner->disposition != disp_del_at_next_stop) | |
1288 | { | |
a5606eee VP |
1289 | val = target_insert_watchpoint (bpt->address, |
1290 | bpt->length, | |
1291 | bpt->watchpoint_type); | |
1292 | bpt->inserted = (val != -1); | |
879bfdc2 DJ |
1293 | } |
1294 | ||
fe798b75 | 1295 | else if (bpt->owner->type == bp_catchpoint) |
879bfdc2 | 1296 | { |
71fff37b AC |
1297 | struct gdb_exception e = catch_exception (uiout, insert_catchpoint, |
1298 | bpt->owner, RETURN_MASK_ERROR); | |
9cbc821d AC |
1299 | exception_fprintf (gdb_stderr, e, "warning: inserting catchpoint %d: ", |
1300 | bpt->owner->number); | |
1301 | if (e.reason < 0) | |
879bfdc2 DJ |
1302 | bpt->owner->enable_state = bp_disabled; |
1303 | else | |
1304 | bpt->inserted = 1; | |
1640b821 DJ |
1305 | |
1306 | /* We've already printed an error message if there was a problem | |
1307 | inserting this catchpoint, and we've disabled the catchpoint, | |
1308 | so just return success. */ | |
1309 | return 0; | |
879bfdc2 DJ |
1310 | } |
1311 | ||
1312 | return 0; | |
1313 | } | |
1314 | ||
74960c60 VP |
1315 | /* Make sure all breakpoints are inserted in inferior. |
1316 | Throws exception on any error. | |
1317 | A breakpoint that is already inserted won't be inserted | |
1318 | again, so calling this function twice is safe. */ | |
1319 | void | |
1320 | insert_breakpoints (void) | |
1321 | { | |
1322 | struct breakpoint *bpt; | |
1323 | ||
1324 | ALL_BREAKPOINTS (bpt) | |
1325 | if (is_hardware_watchpoint (bpt)) | |
1326 | update_watchpoint (bpt, 0 /* don't reparse. */); | |
1327 | ||
b60e7edf | 1328 | update_global_location_list (1); |
74960c60 | 1329 | |
c35b1492 PA |
1330 | /* update_global_location_list does not insert breakpoints when |
1331 | always_inserted_mode is not enabled. Explicitly insert them | |
1332 | now. */ | |
1333 | if (!breakpoints_always_inserted_mode ()) | |
74960c60 VP |
1334 | insert_breakpoint_locations (); |
1335 | } | |
1336 | ||
c906108c SS |
1337 | /* insert_breakpoints is used when starting or continuing the program. |
1338 | remove_breakpoints is used when the program stops. | |
1339 | Both return zero if successful, | |
1340 | or an `errno' value if could not write the inferior. */ | |
1341 | ||
74960c60 VP |
1342 | static void |
1343 | insert_breakpoint_locations (void) | |
c906108c | 1344 | { |
a5606eee | 1345 | struct breakpoint *bpt; |
879bfdc2 | 1346 | struct bp_location *b, *temp; |
e236ba44 | 1347 | int error = 0; |
c906108c SS |
1348 | int val = 0; |
1349 | int disabled_breaks = 0; | |
81d0cc19 | 1350 | int hw_breakpoint_error = 0; |
c906108c | 1351 | |
81d0cc19 | 1352 | struct ui_file *tmp_error_stream = mem_fileopen (); |
f7545552 | 1353 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
74960c60 | 1354 | |
81d0cc19 GS |
1355 | /* Explicitly mark the warning -- this will only be printed if |
1356 | there was an error. */ | |
1357 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
a5606eee | 1358 | |
879bfdc2 DJ |
1359 | ALL_BP_LOCATIONS_SAFE (b, temp) |
1360 | { | |
74960c60 | 1361 | if (!should_be_inserted (b) || b->inserted) |
879bfdc2 DJ |
1362 | continue; |
1363 | ||
f365de73 AS |
1364 | /* There is no point inserting thread-specific breakpoints if the |
1365 | thread no longer exists. */ | |
1366 | if (b->owner->thread != -1 | |
1367 | && !valid_thread_id (b->owner->thread)) | |
1368 | continue; | |
1369 | ||
879bfdc2 | 1370 | val = insert_bp_location (b, tmp_error_stream, |
fa3a767f | 1371 | &disabled_breaks, |
879bfdc2 DJ |
1372 | &hw_breakpoint_error); |
1373 | if (val) | |
e236ba44 | 1374 | error = val; |
879bfdc2 | 1375 | } |
c906108c | 1376 | |
a5606eee VP |
1377 | /* If we failed to insert all locations of a watchpoint, |
1378 | remove them, as half-inserted watchpoint is of limited use. */ | |
1379 | ALL_BREAKPOINTS (bpt) | |
1380 | { | |
1381 | int some_failed = 0; | |
1382 | struct bp_location *loc; | |
1383 | ||
1384 | if (!is_hardware_watchpoint (bpt)) | |
1385 | continue; | |
1386 | ||
d6b74ac4 | 1387 | if (!breakpoint_enabled (bpt)) |
a5606eee | 1388 | continue; |
74960c60 VP |
1389 | |
1390 | if (bpt->disposition == disp_del_at_next_stop) | |
1391 | continue; | |
a5606eee VP |
1392 | |
1393 | for (loc = bpt->loc; loc; loc = loc->next) | |
1394 | if (!loc->inserted) | |
1395 | { | |
1396 | some_failed = 1; | |
1397 | break; | |
1398 | } | |
1399 | if (some_failed) | |
1400 | { | |
1401 | for (loc = bpt->loc; loc; loc = loc->next) | |
1402 | if (loc->inserted) | |
1403 | remove_breakpoint (loc, mark_uninserted); | |
1404 | ||
1405 | hw_breakpoint_error = 1; | |
1406 | fprintf_unfiltered (tmp_error_stream, | |
1407 | "Could not insert hardware watchpoint %d.\n", | |
1408 | bpt->number); | |
1409 | error = -1; | |
1410 | } | |
1411 | } | |
1412 | ||
e236ba44 | 1413 | if (error) |
81d0cc19 GS |
1414 | { |
1415 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
1416 | message about possibly exhausted resources. */ | |
879bfdc2 | 1417 | if (hw_breakpoint_error) |
81d0cc19 | 1418 | { |
c6510018 MS |
1419 | fprintf_unfiltered (tmp_error_stream, |
1420 | "Could not insert hardware breakpoints:\n\ | |
1421 | You may have requested too many hardware breakpoints/watchpoints.\n"); | |
81d0cc19 | 1422 | } |
81d0cc19 GS |
1423 | target_terminal_ours_for_output (); |
1424 | error_stream (tmp_error_stream); | |
1425 | } | |
f7545552 TT |
1426 | |
1427 | do_cleanups (cleanups); | |
c906108c SS |
1428 | } |
1429 | ||
c906108c | 1430 | int |
fba45db2 | 1431 | remove_breakpoints (void) |
c906108c | 1432 | { |
0bde7532 | 1433 | struct bp_location *b; |
3a1bae8e | 1434 | int val = 0; |
c906108c | 1435 | |
0bde7532 | 1436 | ALL_BP_LOCATIONS (b) |
c5aa993b | 1437 | { |
0bde7532 | 1438 | if (b->inserted) |
3a1bae8e | 1439 | val |= remove_breakpoint (b, mark_uninserted); |
c5aa993b | 1440 | } |
3a1bae8e | 1441 | return val; |
c906108c SS |
1442 | } |
1443 | ||
692590c1 | 1444 | int |
80ce1ecb | 1445 | remove_hw_watchpoints (void) |
692590c1 | 1446 | { |
0bde7532 | 1447 | struct bp_location *b; |
3a1bae8e | 1448 | int val = 0; |
692590c1 | 1449 | |
0bde7532 | 1450 | ALL_BP_LOCATIONS (b) |
692590c1 | 1451 | { |
0bde7532 | 1452 | if (b->inserted && b->loc_type == bp_loc_hardware_watchpoint) |
3a1bae8e | 1453 | val |= remove_breakpoint (b, mark_uninserted); |
692590c1 | 1454 | } |
3a1bae8e | 1455 | return val; |
692590c1 MS |
1456 | } |
1457 | ||
c906108c | 1458 | int |
fba45db2 | 1459 | reattach_breakpoints (int pid) |
c906108c | 1460 | { |
0bde7532 | 1461 | struct bp_location *b; |
c906108c | 1462 | int val; |
ce696e05 | 1463 | struct cleanup *old_chain = save_inferior_ptid (); |
a4954f26 | 1464 | struct ui_file *tmp_error_stream = mem_fileopen (); |
fa3a767f | 1465 | int dummy1 = 0, dummy2 = 0; |
a4954f26 DJ |
1466 | |
1467 | make_cleanup_ui_file_delete (tmp_error_stream); | |
c906108c | 1468 | |
ce696e05 | 1469 | inferior_ptid = pid_to_ptid (pid); |
0bde7532 | 1470 | ALL_BP_LOCATIONS (b) |
c5aa993b | 1471 | { |
0bde7532 | 1472 | if (b->inserted) |
c5aa993b | 1473 | { |
a4954f26 DJ |
1474 | b->inserted = 0; |
1475 | val = insert_bp_location (b, tmp_error_stream, | |
fa3a767f | 1476 | &dummy1, &dummy2); |
c5aa993b JM |
1477 | if (val != 0) |
1478 | { | |
ce696e05 | 1479 | do_cleanups (old_chain); |
c5aa993b JM |
1480 | return val; |
1481 | } | |
1482 | } | |
1483 | } | |
ce696e05 | 1484 | do_cleanups (old_chain); |
c906108c SS |
1485 | return 0; |
1486 | } | |
1487 | ||
e58b0e63 PA |
1488 | static int internal_breakpoint_number = -1; |
1489 | ||
e62c965a | 1490 | static struct breakpoint * |
a6d9a66e UW |
1491 | create_internal_breakpoint (struct gdbarch *gdbarch, |
1492 | CORE_ADDR address, enum bptype type) | |
e62c965a | 1493 | { |
e62c965a PP |
1494 | struct symtab_and_line sal; |
1495 | struct breakpoint *b; | |
1496 | ||
1497 | init_sal (&sal); /* initialize to zeroes */ | |
1498 | ||
1499 | sal.pc = address; | |
1500 | sal.section = find_pc_overlay (sal.pc); | |
1501 | ||
a6d9a66e | 1502 | b = set_raw_breakpoint (gdbarch, sal, type); |
e62c965a PP |
1503 | b->number = internal_breakpoint_number--; |
1504 | b->disposition = disp_donttouch; | |
1505 | ||
1506 | return b; | |
1507 | } | |
1508 | ||
1509 | static void | |
69de3c6a | 1510 | create_overlay_event_breakpoint (char *func_name) |
e62c965a | 1511 | { |
69de3c6a | 1512 | struct objfile *objfile; |
e62c965a | 1513 | |
69de3c6a PP |
1514 | ALL_OBJFILES (objfile) |
1515 | { | |
1516 | struct breakpoint *b; | |
1517 | struct minimal_symbol *m; | |
1518 | ||
1519 | m = lookup_minimal_symbol_text (func_name, objfile); | |
1520 | if (m == NULL) | |
1521 | continue; | |
e62c965a | 1522 | |
a6d9a66e UW |
1523 | b = create_internal_breakpoint (get_objfile_arch (objfile), |
1524 | SYMBOL_VALUE_ADDRESS (m), | |
69de3c6a PP |
1525 | bp_overlay_event); |
1526 | b->addr_string = xstrdup (func_name); | |
e62c965a | 1527 | |
69de3c6a PP |
1528 | if (overlay_debugging == ovly_auto) |
1529 | { | |
1530 | b->enable_state = bp_enabled; | |
1531 | overlay_events_enabled = 1; | |
1532 | } | |
1533 | else | |
1534 | { | |
1535 | b->enable_state = bp_disabled; | |
1536 | overlay_events_enabled = 0; | |
1537 | } | |
e62c965a PP |
1538 | } |
1539 | update_global_location_list (1); | |
1540 | } | |
1541 | ||
0fd8e87f UW |
1542 | static void |
1543 | create_longjmp_master_breakpoint (char *func_name) | |
1544 | { | |
1545 | struct objfile *objfile; | |
1546 | ||
1547 | ALL_OBJFILES (objfile) | |
1548 | { | |
1549 | struct breakpoint *b; | |
1550 | struct minimal_symbol *m; | |
1551 | ||
1552 | if (!gdbarch_get_longjmp_target_p (get_objfile_arch (objfile))) | |
1553 | continue; | |
1554 | ||
1555 | m = lookup_minimal_symbol_text (func_name, objfile); | |
1556 | if (m == NULL) | |
1557 | continue; | |
1558 | ||
a6d9a66e UW |
1559 | b = create_internal_breakpoint (get_objfile_arch (objfile), |
1560 | SYMBOL_VALUE_ADDRESS (m), | |
0fd8e87f UW |
1561 | bp_longjmp_master); |
1562 | b->addr_string = xstrdup (func_name); | |
1563 | b->enable_state = bp_disabled; | |
1564 | } | |
1565 | update_global_location_list (1); | |
1566 | } | |
1567 | ||
c906108c | 1568 | void |
fba45db2 | 1569 | update_breakpoints_after_exec (void) |
c906108c | 1570 | { |
c5aa993b JM |
1571 | struct breakpoint *b; |
1572 | struct breakpoint *temp; | |
25b22b0a | 1573 | struct bp_location *bploc; |
c906108c | 1574 | |
25b22b0a PA |
1575 | /* We're about to delete breakpoints from GDB's lists. If the |
1576 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
1577 | writing the breakpoints' "shadow contents" back into memory. The | |
1578 | "shadow contents" are NOT valid after an exec, so GDB should not | |
1579 | do that. Instead, the target is responsible from marking | |
1580 | breakpoints out as soon as it detects an exec. We don't do that | |
1581 | here instead, because there may be other attempts to delete | |
1582 | breakpoints after detecting an exec and before reaching here. */ | |
1583 | ALL_BP_LOCATIONS (bploc) | |
1584 | gdb_assert (!bploc->inserted); | |
c906108c SS |
1585 | |
1586 | ALL_BREAKPOINTS_SAFE (b, temp) | |
c5aa993b JM |
1587 | { |
1588 | /* Solib breakpoints must be explicitly reset after an exec(). */ | |
1589 | if (b->type == bp_shlib_event) | |
1590 | { | |
1591 | delete_breakpoint (b); | |
1592 | continue; | |
1593 | } | |
c906108c | 1594 | |
1900040c | 1595 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
1596 | as must overlay event and longjmp master breakpoints. */ |
1597 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
1598 | || b->type == bp_longjmp_master) | |
c4093a6a JM |
1599 | { |
1600 | delete_breakpoint (b); | |
1601 | continue; | |
1602 | } | |
1603 | ||
c5aa993b JM |
1604 | /* Step-resume breakpoints are meaningless after an exec(). */ |
1605 | if (b->type == bp_step_resume) | |
1606 | { | |
1607 | delete_breakpoint (b); | |
1608 | continue; | |
1609 | } | |
1610 | ||
611c83ae PA |
1611 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
1612 | after an exec. */ | |
1613 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume) | |
1614 | { | |
1615 | delete_breakpoint (b); | |
1616 | continue; | |
1617 | } | |
1618 | ||
ce78b96d JB |
1619 | if (b->type == bp_catchpoint) |
1620 | { | |
1621 | /* For now, none of the bp_catchpoint breakpoints need to | |
1622 | do anything at this point. In the future, if some of | |
1623 | the catchpoints need to something, we will need to add | |
1624 | a new method, and call this method from here. */ | |
1625 | continue; | |
1626 | } | |
1627 | ||
c5aa993b JM |
1628 | /* bp_finish is a special case. The only way we ought to be able |
1629 | to see one of these when an exec() has happened, is if the user | |
1630 | caught a vfork, and then said "finish". Ordinarily a finish just | |
1631 | carries them to the call-site of the current callee, by setting | |
1632 | a temporary bp there and resuming. But in this case, the finish | |
1633 | will carry them entirely through the vfork & exec. | |
1634 | ||
1635 | We don't want to allow a bp_finish to remain inserted now. But | |
1636 | we can't safely delete it, 'cause finish_command has a handle to | |
1637 | the bp on a bpstat, and will later want to delete it. There's a | |
1638 | chance (and I've seen it happen) that if we delete the bp_finish | |
1639 | here, that its storage will get reused by the time finish_command | |
1640 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
1641 | We really must allow finish_command to delete a bp_finish. | |
1642 | ||
53a5351d JM |
1643 | In the absense of a general solution for the "how do we know |
1644 | it's safe to delete something others may have handles to?" | |
1645 | problem, what we'll do here is just uninsert the bp_finish, and | |
1646 | let finish_command delete it. | |
1647 | ||
1648 | (We know the bp_finish is "doomed" in the sense that it's | |
1649 | momentary, and will be deleted as soon as finish_command sees | |
1650 | the inferior stopped. So it doesn't matter that the bp's | |
1651 | address is probably bogus in the new a.out, unlike e.g., the | |
1652 | solib breakpoints.) */ | |
c5aa993b | 1653 | |
c5aa993b JM |
1654 | if (b->type == bp_finish) |
1655 | { | |
1656 | continue; | |
1657 | } | |
1658 | ||
1659 | /* Without a symbolic address, we have little hope of the | |
1660 | pre-exec() address meaning the same thing in the post-exec() | |
1661 | a.out. */ | |
1662 | if (b->addr_string == NULL) | |
1663 | { | |
1664 | delete_breakpoint (b); | |
1665 | continue; | |
1666 | } | |
c5aa993b | 1667 | } |
1900040c | 1668 | /* FIXME what about longjmp breakpoints? Re-create them here? */ |
69de3c6a | 1669 | create_overlay_event_breakpoint ("_ovly_debug_event"); |
0fd8e87f UW |
1670 | create_longjmp_master_breakpoint ("longjmp"); |
1671 | create_longjmp_master_breakpoint ("_longjmp"); | |
1672 | create_longjmp_master_breakpoint ("siglongjmp"); | |
1673 | create_longjmp_master_breakpoint ("_siglongjmp"); | |
c906108c SS |
1674 | } |
1675 | ||
1676 | int | |
fba45db2 | 1677 | detach_breakpoints (int pid) |
c906108c | 1678 | { |
0bde7532 | 1679 | struct bp_location *b; |
3a1bae8e | 1680 | int val = 0; |
ce696e05 | 1681 | struct cleanup *old_chain = save_inferior_ptid (); |
c5aa993b | 1682 | |
39f77062 | 1683 | if (pid == PIDGET (inferior_ptid)) |
8a3fe4f8 | 1684 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 1685 | |
ce696e05 KB |
1686 | /* Set inferior_ptid; remove_breakpoint uses this global. */ |
1687 | inferior_ptid = pid_to_ptid (pid); | |
0bde7532 | 1688 | ALL_BP_LOCATIONS (b) |
c5aa993b | 1689 | { |
0bde7532 | 1690 | if (b->inserted) |
3a1bae8e | 1691 | val |= remove_breakpoint (b, mark_inserted); |
c5aa993b | 1692 | } |
ce696e05 | 1693 | do_cleanups (old_chain); |
3a1bae8e | 1694 | return val; |
c906108c SS |
1695 | } |
1696 | ||
1697 | static int | |
0bde7532 | 1698 | remove_breakpoint (struct bp_location *b, insertion_state_t is) |
c906108c SS |
1699 | { |
1700 | int val; | |
c5aa993b | 1701 | |
0bde7532 | 1702 | if (b->owner->enable_state == bp_permanent) |
c2c6d25f JM |
1703 | /* Permanent breakpoints cannot be inserted or removed. */ |
1704 | return 0; | |
1705 | ||
74960c60 VP |
1706 | /* The type of none suggests that owner is actually deleted. |
1707 | This should not ever happen. */ | |
1708 | gdb_assert (b->owner->type != bp_none); | |
0bde7532 DJ |
1709 | |
1710 | if (b->loc_type == bp_loc_software_breakpoint | |
1711 | || b->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 1712 | { |
c02f5703 MS |
1713 | /* "Normal" instruction breakpoint: either the standard |
1714 | trap-instruction bp (bp_breakpoint), or a | |
1715 | bp_hardware_breakpoint. */ | |
1716 | ||
1717 | /* First check to see if we have to handle an overlay. */ | |
1718 | if (overlay_debugging == ovly_off | |
0bde7532 DJ |
1719 | || b->section == NULL |
1720 | || !(section_is_overlay (b->section))) | |
c02f5703 MS |
1721 | { |
1722 | /* No overlay handling: just remove the breakpoint. */ | |
1723 | ||
0bde7532 | 1724 | if (b->loc_type == bp_loc_hardware_breakpoint) |
a6d9a66e | 1725 | val = target_remove_hw_breakpoint (b->gdbarch, &b->target_info); |
c02f5703 | 1726 | else |
a6d9a66e | 1727 | val = target_remove_breakpoint (b->gdbarch, &b->target_info); |
c02f5703 | 1728 | } |
c906108c SS |
1729 | else |
1730 | { | |
c02f5703 MS |
1731 | /* This breakpoint is in an overlay section. |
1732 | Did we set a breakpoint at the LMA? */ | |
1733 | if (!overlay_events_enabled) | |
1734 | { | |
1735 | /* Yes -- overlay event support is not active, so we | |
1736 | should have set a breakpoint at the LMA. Remove it. | |
1737 | */ | |
c02f5703 MS |
1738 | /* Ignore any failures: if the LMA is in ROM, we will |
1739 | have already warned when we failed to insert it. */ | |
0bde7532 | 1740 | if (b->loc_type == bp_loc_hardware_breakpoint) |
a6d9a66e UW |
1741 | target_remove_hw_breakpoint (b->gdbarch, |
1742 | &b->overlay_target_info); | |
c02f5703 | 1743 | else |
a6d9a66e UW |
1744 | target_remove_breakpoint (b->gdbarch, |
1745 | &b->overlay_target_info); | |
c02f5703 MS |
1746 | } |
1747 | /* Did we set a breakpoint at the VMA? | |
1748 | If so, we will have marked the breakpoint 'inserted'. */ | |
0bde7532 | 1749 | if (b->inserted) |
c906108c | 1750 | { |
c02f5703 MS |
1751 | /* Yes -- remove it. Previously we did not bother to |
1752 | remove the breakpoint if the section had been | |
1753 | unmapped, but let's not rely on that being safe. We | |
1754 | don't know what the overlay manager might do. */ | |
0bde7532 | 1755 | if (b->loc_type == bp_loc_hardware_breakpoint) |
a6d9a66e UW |
1756 | val = target_remove_hw_breakpoint (b->gdbarch, |
1757 | &b->target_info); | |
aa67235e UW |
1758 | |
1759 | /* However, we should remove *software* breakpoints only | |
1760 | if the section is still mapped, or else we overwrite | |
1761 | wrong code with the saved shadow contents. */ | |
1762 | else if (section_is_mapped (b->section)) | |
a6d9a66e UW |
1763 | val = target_remove_breakpoint (b->gdbarch, |
1764 | &b->target_info); | |
aa67235e UW |
1765 | else |
1766 | val = 0; | |
c906108c | 1767 | } |
c02f5703 MS |
1768 | else |
1769 | { | |
1770 | /* No -- not inserted, so no need to remove. No error. */ | |
1771 | val = 0; | |
1772 | } | |
c906108c | 1773 | } |
879d1e6b UW |
1774 | |
1775 | /* In some cases, we might not be able to remove a breakpoint | |
1776 | in a shared library that has already been removed, but we | |
1777 | have not yet processed the shlib unload event. */ | |
f5c9a895 | 1778 | if (val && solib_name_from_address (b->address)) |
879d1e6b UW |
1779 | val = 0; |
1780 | ||
c906108c SS |
1781 | if (val) |
1782 | return val; | |
0bde7532 | 1783 | b->inserted = (is == mark_inserted); |
c906108c | 1784 | } |
a5606eee | 1785 | else if (b->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 1786 | { |
278cd55f AC |
1787 | struct value *v; |
1788 | struct value *n; | |
c5aa993b | 1789 | |
0bde7532 | 1790 | b->inserted = (is == mark_inserted); |
a5606eee VP |
1791 | val = target_remove_watchpoint (b->address, b->length, |
1792 | b->watchpoint_type); | |
2e70b7b9 | 1793 | |
c906108c | 1794 | /* Failure to remove any of the hardware watchpoints comes here. */ |
0bde7532 | 1795 | if ((is == mark_uninserted) && (b->inserted)) |
8a3fe4f8 | 1796 | warning (_("Could not remove hardware watchpoint %d."), |
0bde7532 | 1797 | b->owner->number); |
c906108c | 1798 | } |
ce78b96d JB |
1799 | else if (b->owner->type == bp_catchpoint |
1800 | && breakpoint_enabled (b->owner) | |
1801 | && !b->duplicate) | |
1802 | { | |
1803 | gdb_assert (b->owner->ops != NULL && b->owner->ops->remove != NULL); | |
1804 | ||
1805 | val = b->owner->ops->remove (b->owner); | |
1806 | if (val) | |
1807 | return val; | |
1808 | b->inserted = (is == mark_inserted); | |
1809 | } | |
c906108c SS |
1810 | |
1811 | return 0; | |
1812 | } | |
1813 | ||
1814 | /* Clear the "inserted" flag in all breakpoints. */ | |
1815 | ||
25b22b0a | 1816 | void |
fba45db2 | 1817 | mark_breakpoints_out (void) |
c906108c | 1818 | { |
075f6582 | 1819 | struct bp_location *bpt; |
c906108c | 1820 | |
075f6582 DJ |
1821 | ALL_BP_LOCATIONS (bpt) |
1822 | bpt->inserted = 0; | |
c906108c SS |
1823 | } |
1824 | ||
53a5351d JM |
1825 | /* Clear the "inserted" flag in all breakpoints and delete any |
1826 | breakpoints which should go away between runs of the program. | |
c906108c SS |
1827 | |
1828 | Plus other such housekeeping that has to be done for breakpoints | |
1829 | between runs. | |
1830 | ||
53a5351d JM |
1831 | Note: this function gets called at the end of a run (by |
1832 | generic_mourn_inferior) and when a run begins (by | |
1833 | init_wait_for_inferior). */ | |
c906108c SS |
1834 | |
1835 | ||
1836 | ||
1837 | void | |
fba45db2 | 1838 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 1839 | { |
52f0bd74 | 1840 | struct breakpoint *b, *temp; |
075f6582 | 1841 | struct bp_location *bpt; |
1c5cfe86 | 1842 | int ix; |
c906108c | 1843 | |
50c71eaf PA |
1844 | /* If breakpoint locations are shared across processes, then there's |
1845 | nothing to do. */ | |
2567c7d9 | 1846 | if (gdbarch_has_global_breakpoints (target_gdbarch)) |
50c71eaf PA |
1847 | return; |
1848 | ||
075f6582 | 1849 | ALL_BP_LOCATIONS (bpt) |
514f746b AR |
1850 | if (bpt->owner->enable_state != bp_permanent) |
1851 | bpt->inserted = 0; | |
075f6582 | 1852 | |
c906108c | 1853 | ALL_BREAKPOINTS_SAFE (b, temp) |
c5aa993b | 1854 | { |
c5aa993b JM |
1855 | switch (b->type) |
1856 | { | |
1857 | case bp_call_dummy: | |
1858 | case bp_watchpoint_scope: | |
c906108c | 1859 | |
c5aa993b JM |
1860 | /* If the call dummy breakpoint is at the entry point it will |
1861 | cause problems when the inferior is rerun, so we better | |
1862 | get rid of it. | |
c906108c | 1863 | |
c5aa993b JM |
1864 | Also get rid of scope breakpoints. */ |
1865 | delete_breakpoint (b); | |
1866 | break; | |
c906108c | 1867 | |
c5aa993b JM |
1868 | case bp_watchpoint: |
1869 | case bp_hardware_watchpoint: | |
1870 | case bp_read_watchpoint: | |
1871 | case bp_access_watchpoint: | |
c906108c | 1872 | |
c5aa993b JM |
1873 | /* Likewise for watchpoints on local expressions. */ |
1874 | if (b->exp_valid_block != NULL) | |
1875 | delete_breakpoint (b); | |
967af18d | 1876 | else if (context == inf_starting) |
c860120c PM |
1877 | { |
1878 | /* Reset val field to force reread of starting value | |
1879 | in insert_breakpoints. */ | |
1880 | if (b->val) | |
1881 | value_free (b->val); | |
1882 | b->val = NULL; | |
fa4727a6 | 1883 | b->val_valid = 0; |
c860120c | 1884 | } |
c5aa993b JM |
1885 | break; |
1886 | default: | |
c5aa993b JM |
1887 | break; |
1888 | } | |
1889 | } | |
1c5cfe86 PA |
1890 | |
1891 | /* Get rid of the moribund locations. */ | |
1892 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bpt); ++ix) | |
1893 | free_bp_location (bpt); | |
1894 | VEC_free (bp_location_p, moribund_locations); | |
c906108c SS |
1895 | } |
1896 | ||
c2c6d25f JM |
1897 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
1898 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
1899 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
1900 | permanent breakpoint. | |
1901 | - When continuing from a location with an ordinary breakpoint, we | |
1902 | actually single step once before calling insert_breakpoints. | |
1903 | - When continuing from a localion with a permanent breakpoint, we | |
1904 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by | |
1905 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 1906 | |
c2c6d25f | 1907 | enum breakpoint_here |
fba45db2 | 1908 | breakpoint_here_p (CORE_ADDR pc) |
c906108c | 1909 | { |
89f9893c | 1910 | const struct bp_location *bpt; |
c2c6d25f | 1911 | int any_breakpoint_here = 0; |
c906108c | 1912 | |
075f6582 DJ |
1913 | ALL_BP_LOCATIONS (bpt) |
1914 | { | |
1915 | if (bpt->loc_type != bp_loc_software_breakpoint | |
1916 | && bpt->loc_type != bp_loc_hardware_breakpoint) | |
1917 | continue; | |
1918 | ||
468d015d | 1919 | if ((breakpoint_enabled (bpt->owner) |
075f6582 DJ |
1920 | || bpt->owner->enable_state == bp_permanent) |
1921 | && bpt->address == pc) /* bp is enabled and matches pc */ | |
1922 | { | |
1923 | if (overlay_debugging | |
1924 | && section_is_overlay (bpt->section) | |
1925 | && !section_is_mapped (bpt->section)) | |
1926 | continue; /* unmapped overlay -- can't be a match */ | |
1927 | else if (bpt->owner->enable_state == bp_permanent) | |
1928 | return permanent_breakpoint_here; | |
1929 | else | |
1930 | any_breakpoint_here = 1; | |
1931 | } | |
1932 | } | |
c906108c | 1933 | |
c2c6d25f | 1934 | return any_breakpoint_here ? ordinary_breakpoint_here : 0; |
c906108c SS |
1935 | } |
1936 | ||
1c5cfe86 PA |
1937 | /* Return true if there's a moribund breakpoint at PC. */ |
1938 | ||
1939 | int | |
1940 | moribund_breakpoint_here_p (CORE_ADDR pc) | |
1941 | { | |
1942 | struct bp_location *loc; | |
1943 | int ix; | |
1944 | ||
1945 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
1946 | if (loc->address == pc) | |
1947 | return 1; | |
1948 | ||
1949 | return 0; | |
1950 | } | |
c2c6d25f | 1951 | |
c36b740a VP |
1952 | /* Returns non-zero if there's a breakpoint inserted at PC, which is |
1953 | inserted using regular breakpoint_chain/bp_location_chain mechanism. | |
1954 | This does not check for single-step breakpoints, which are | |
1955 | inserted and removed using direct target manipulation. */ | |
c906108c SS |
1956 | |
1957 | int | |
c36b740a | 1958 | regular_breakpoint_inserted_here_p (CORE_ADDR pc) |
c906108c | 1959 | { |
89f9893c | 1960 | const struct bp_location *bpt; |
c906108c | 1961 | |
075f6582 | 1962 | ALL_BP_LOCATIONS (bpt) |
c5aa993b | 1963 | { |
075f6582 DJ |
1964 | if (bpt->loc_type != bp_loc_software_breakpoint |
1965 | && bpt->loc_type != bp_loc_hardware_breakpoint) | |
1966 | continue; | |
1967 | ||
1968 | if (bpt->inserted | |
1969 | && bpt->address == pc) /* bp is inserted and matches pc */ | |
1970 | { | |
1971 | if (overlay_debugging | |
1972 | && section_is_overlay (bpt->section) | |
1973 | && !section_is_mapped (bpt->section)) | |
1974 | continue; /* unmapped overlay -- can't be a match */ | |
1975 | else | |
1976 | return 1; | |
1977 | } | |
c5aa993b | 1978 | } |
c36b740a VP |
1979 | return 0; |
1980 | } | |
1981 | ||
1982 | /* Returns non-zero iff there's either regular breakpoint | |
1983 | or a single step breakpoint inserted at PC. */ | |
1984 | ||
1985 | int | |
1986 | breakpoint_inserted_here_p (CORE_ADDR pc) | |
1987 | { | |
1988 | if (regular_breakpoint_inserted_here_p (pc)) | |
1989 | return 1; | |
c906108c | 1990 | |
1aafd4da UW |
1991 | if (single_step_breakpoint_inserted_here_p (pc)) |
1992 | return 1; | |
1993 | ||
c906108c SS |
1994 | return 0; |
1995 | } | |
1996 | ||
4fa8626c DJ |
1997 | /* This function returns non-zero iff there is a software breakpoint |
1998 | inserted at PC. */ | |
1999 | ||
2000 | int | |
2001 | software_breakpoint_inserted_here_p (CORE_ADDR pc) | |
2002 | { | |
89f9893c | 2003 | const struct bp_location *bpt; |
4fa8626c DJ |
2004 | int any_breakpoint_here = 0; |
2005 | ||
2006 | ALL_BP_LOCATIONS (bpt) | |
2007 | { | |
2008 | if (bpt->loc_type != bp_loc_software_breakpoint) | |
2009 | continue; | |
2010 | ||
0d381245 | 2011 | if (bpt->inserted |
4fa8626c DJ |
2012 | && bpt->address == pc) /* bp is enabled and matches pc */ |
2013 | { | |
2014 | if (overlay_debugging | |
2015 | && section_is_overlay (bpt->section) | |
2016 | && !section_is_mapped (bpt->section)) | |
2017 | continue; /* unmapped overlay -- can't be a match */ | |
2018 | else | |
2019 | return 1; | |
2020 | } | |
2021 | } | |
2022 | ||
1aafd4da UW |
2023 | /* Also check for software single-step breakpoints. */ |
2024 | if (single_step_breakpoint_inserted_here_p (pc)) | |
2025 | return 1; | |
2026 | ||
4fa8626c DJ |
2027 | return 0; |
2028 | } | |
2029 | ||
075f6582 DJ |
2030 | /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at |
2031 | PC is valid for process/thread PTID. */ | |
c906108c SS |
2032 | |
2033 | int | |
39f77062 | 2034 | breakpoint_thread_match (CORE_ADDR pc, ptid_t ptid) |
c906108c | 2035 | { |
89f9893c | 2036 | const struct bp_location *bpt; |
4a306c9a | 2037 | /* The thread and task IDs associated to PTID, computed lazily. */ |
a6f1cd96 | 2038 | int thread = -1; |
4a306c9a | 2039 | int task = 0; |
a6f1cd96 | 2040 | |
075f6582 | 2041 | ALL_BP_LOCATIONS (bpt) |
c5aa993b | 2042 | { |
075f6582 DJ |
2043 | if (bpt->loc_type != bp_loc_software_breakpoint |
2044 | && bpt->loc_type != bp_loc_hardware_breakpoint) | |
2045 | continue; | |
2046 | ||
a6f1cd96 JB |
2047 | if (!breakpoint_enabled (bpt->owner) |
2048 | && bpt->owner->enable_state != bp_permanent) | |
2049 | continue; | |
2050 | ||
2051 | if (bpt->address != pc) | |
2052 | continue; | |
2053 | ||
2054 | if (bpt->owner->thread != -1) | |
075f6582 | 2055 | { |
a6f1cd96 JB |
2056 | /* This is a thread-specific breakpoint. Check that ptid |
2057 | matches that thread. If thread hasn't been computed yet, | |
2058 | it is now time to do so. */ | |
2059 | if (thread == -1) | |
2060 | thread = pid_to_thread_id (ptid); | |
2061 | if (bpt->owner->thread != thread) | |
2062 | continue; | |
075f6582 | 2063 | } |
a6f1cd96 | 2064 | |
4a306c9a JB |
2065 | if (bpt->owner->task != 0) |
2066 | { | |
2067 | /* This is a task-specific breakpoint. Check that ptid | |
2068 | matches that task. If task hasn't been computed yet, | |
2069 | it is now time to do so. */ | |
2070 | if (task == 0) | |
2071 | task = ada_get_task_number (ptid); | |
2072 | if (bpt->owner->task != task) | |
2073 | continue; | |
2074 | } | |
2075 | ||
a6f1cd96 JB |
2076 | if (overlay_debugging |
2077 | && section_is_overlay (bpt->section) | |
2078 | && !section_is_mapped (bpt->section)) | |
2079 | continue; /* unmapped overlay -- can't be a match */ | |
2080 | ||
2081 | return 1; | |
c5aa993b | 2082 | } |
c906108c SS |
2083 | |
2084 | return 0; | |
2085 | } | |
c906108c | 2086 | \f |
c5aa993b | 2087 | |
c906108c SS |
2088 | /* bpstat stuff. External routines' interfaces are documented |
2089 | in breakpoint.h. */ | |
2090 | ||
2091 | int | |
fba45db2 | 2092 | ep_is_catchpoint (struct breakpoint *ep) |
c906108c | 2093 | { |
533be4dd | 2094 | return (ep->type == bp_catchpoint); |
c906108c SS |
2095 | } |
2096 | ||
198757a8 VP |
2097 | void |
2098 | bpstat_free (bpstat bs) | |
2099 | { | |
2100 | if (bs->old_val != NULL) | |
2101 | value_free (bs->old_val); | |
2102 | free_command_lines (&bs->commands); | |
2103 | xfree (bs); | |
2104 | } | |
2105 | ||
c906108c SS |
2106 | /* Clear a bpstat so that it says we are not at any breakpoint. |
2107 | Also free any storage that is part of a bpstat. */ | |
2108 | ||
2109 | void | |
fba45db2 | 2110 | bpstat_clear (bpstat *bsp) |
c906108c SS |
2111 | { |
2112 | bpstat p; | |
2113 | bpstat q; | |
2114 | ||
2115 | if (bsp == 0) | |
2116 | return; | |
2117 | p = *bsp; | |
2118 | while (p != NULL) | |
2119 | { | |
2120 | q = p->next; | |
198757a8 | 2121 | bpstat_free (p); |
c906108c SS |
2122 | p = q; |
2123 | } | |
2124 | *bsp = NULL; | |
2125 | } | |
2126 | ||
2127 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
2128 | is part of the bpstat is copied as well. */ | |
2129 | ||
2130 | bpstat | |
fba45db2 | 2131 | bpstat_copy (bpstat bs) |
c906108c SS |
2132 | { |
2133 | bpstat p = NULL; | |
2134 | bpstat tmp; | |
2135 | bpstat retval = NULL; | |
2136 | ||
2137 | if (bs == NULL) | |
2138 | return bs; | |
2139 | ||
2140 | for (; bs != NULL; bs = bs->next) | |
2141 | { | |
2142 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
2143 | memcpy (tmp, bs, sizeof (*tmp)); | |
31cc81e9 DJ |
2144 | if (bs->commands != NULL) |
2145 | tmp->commands = copy_command_lines (bs->commands); | |
2146 | if (bs->old_val != NULL) | |
3c3185ac JK |
2147 | { |
2148 | tmp->old_val = value_copy (bs->old_val); | |
2149 | release_value (tmp->old_val); | |
2150 | } | |
31cc81e9 | 2151 | |
c906108c SS |
2152 | if (p == NULL) |
2153 | /* This is the first thing in the chain. */ | |
2154 | retval = tmp; | |
2155 | else | |
2156 | p->next = tmp; | |
2157 | p = tmp; | |
2158 | } | |
2159 | p->next = NULL; | |
2160 | return retval; | |
2161 | } | |
2162 | ||
2163 | /* Find the bpstat associated with this breakpoint */ | |
2164 | ||
2165 | bpstat | |
fba45db2 | 2166 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 2167 | { |
c5aa993b JM |
2168 | if (bsp == NULL) |
2169 | return NULL; | |
c906108c | 2170 | |
c5aa993b JM |
2171 | for (; bsp != NULL; bsp = bsp->next) |
2172 | { | |
4f8d1dc6 | 2173 | if (bsp->breakpoint_at && bsp->breakpoint_at->owner == breakpoint) |
c5aa993b JM |
2174 | return bsp; |
2175 | } | |
c906108c SS |
2176 | return NULL; |
2177 | } | |
2178 | ||
2179 | /* Find a step_resume breakpoint associated with this bpstat. | |
2180 | (If there are multiple step_resume bp's on the list, this function | |
2181 | will arbitrarily pick one.) | |
2182 | ||
2183 | It is an error to use this function if BPSTAT doesn't contain a | |
2184 | step_resume breakpoint. | |
2185 | ||
2186 | See wait_for_inferior's use of this function. */ | |
2187 | struct breakpoint * | |
fba45db2 | 2188 | bpstat_find_step_resume_breakpoint (bpstat bsp) |
c906108c | 2189 | { |
8601f500 MS |
2190 | int current_thread; |
2191 | ||
8a3fe4f8 | 2192 | gdb_assert (bsp != NULL); |
c906108c | 2193 | |
8601f500 MS |
2194 | current_thread = pid_to_thread_id (inferior_ptid); |
2195 | ||
c906108c SS |
2196 | for (; bsp != NULL; bsp = bsp->next) |
2197 | { | |
059fb39f PM |
2198 | if ((bsp->breakpoint_at != NULL) |
2199 | && (bsp->breakpoint_at->owner->type == bp_step_resume) | |
2200 | && (bsp->breakpoint_at->owner->thread == current_thread | |
2201 | || bsp->breakpoint_at->owner->thread == -1)) | |
4f8d1dc6 | 2202 | return bsp->breakpoint_at->owner; |
c906108c SS |
2203 | } |
2204 | ||
8a3fe4f8 | 2205 | internal_error (__FILE__, __LINE__, _("No step_resume breakpoint found.")); |
c906108c SS |
2206 | } |
2207 | ||
2208 | ||
8671a17b | 2209 | /* Put in *NUM the breakpoint number of the first breakpoint we are stopped |
c906108c SS |
2210 | at. *BSP upon return is a bpstat which points to the remaining |
2211 | breakpoints stopped at (but which is not guaranteed to be good for | |
2212 | anything but further calls to bpstat_num). | |
8671a17b PA |
2213 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
2214 | Return -1 if stopped at a breakpoint that has been deleted since | |
2215 | we set it. | |
2216 | Return 1 otherwise. */ | |
c906108c SS |
2217 | |
2218 | int | |
8671a17b | 2219 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
2220 | { |
2221 | struct breakpoint *b; | |
2222 | ||
2223 | if ((*bsp) == NULL) | |
2224 | return 0; /* No more breakpoint values */ | |
8671a17b | 2225 | |
4f8d1dc6 VP |
2226 | /* We assume we'll never have several bpstats that |
2227 | correspond to a single breakpoint -- otherwise, | |
2228 | this function might return the same number more | |
2229 | than once and this will look ugly. */ | |
2230 | b = (*bsp)->breakpoint_at ? (*bsp)->breakpoint_at->owner : NULL; | |
8671a17b PA |
2231 | *bsp = (*bsp)->next; |
2232 | if (b == NULL) | |
2233 | return -1; /* breakpoint that's been deleted since */ | |
2234 | ||
2235 | *num = b->number; /* We have its number */ | |
2236 | return 1; | |
c906108c SS |
2237 | } |
2238 | ||
2239 | /* Modify BS so that the actions will not be performed. */ | |
2240 | ||
2241 | void | |
fba45db2 | 2242 | bpstat_clear_actions (bpstat bs) |
c906108c SS |
2243 | { |
2244 | for (; bs != NULL; bs = bs->next) | |
2245 | { | |
c2b8ed2c | 2246 | free_command_lines (&bs->commands); |
c906108c SS |
2247 | if (bs->old_val != NULL) |
2248 | { | |
2249 | value_free (bs->old_val); | |
2250 | bs->old_val = NULL; | |
2251 | } | |
2252 | } | |
2253 | } | |
2254 | ||
f3b1572e PA |
2255 | /* Called when a command is about to proceed the inferior. */ |
2256 | ||
2257 | static void | |
2258 | breakpoint_about_to_proceed (void) | |
2259 | { | |
2260 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
2261 | { | |
2262 | struct thread_info *tp = inferior_thread (); | |
2263 | ||
2264 | /* Allow inferior function calls in breakpoint commands to not | |
2265 | interrupt the command list. When the call finishes | |
2266 | successfully, the inferior will be standing at the same | |
2267 | breakpoint as if nothing happened. */ | |
2268 | if (tp->in_infcall) | |
2269 | return; | |
2270 | } | |
2271 | ||
2272 | breakpoint_proceeded = 1; | |
2273 | } | |
2274 | ||
c906108c | 2275 | /* Stub for cleaning up our state if we error-out of a breakpoint command */ |
c906108c | 2276 | static void |
4efb68b1 | 2277 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
2278 | { |
2279 | executing_breakpoint_commands = 0; | |
2280 | } | |
2281 | ||
2282 | /* Execute all the commands associated with all the breakpoints at this | |
2283 | location. Any of these commands could cause the process to proceed | |
2284 | beyond this point, etc. We look out for such changes by checking | |
347bddb7 | 2285 | the global "breakpoint_proceeded" after each command. |
c906108c | 2286 | |
347bddb7 PA |
2287 | Returns true if a breakpoint command resumed the inferior. In that |
2288 | case, it is the caller's responsibility to recall it again with the | |
2289 | bpstat of the current thread. */ | |
2290 | ||
2291 | static int | |
2292 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
2293 | { |
2294 | bpstat bs; | |
2295 | struct cleanup *old_chain; | |
347bddb7 | 2296 | int again = 0; |
c906108c SS |
2297 | |
2298 | /* Avoid endless recursion if a `source' command is contained | |
2299 | in bs->commands. */ | |
2300 | if (executing_breakpoint_commands) | |
347bddb7 | 2301 | return 0; |
c906108c SS |
2302 | |
2303 | executing_breakpoint_commands = 1; | |
2304 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
2305 | ||
c906108c SS |
2306 | /* This pointer will iterate over the list of bpstat's. */ |
2307 | bs = *bsp; | |
2308 | ||
2309 | breakpoint_proceeded = 0; | |
2310 | for (; bs != NULL; bs = bs->next) | |
2311 | { | |
6c50ab1c JB |
2312 | struct command_line *cmd; |
2313 | struct cleanup *this_cmd_tree_chain; | |
2314 | ||
2315 | /* Take ownership of the BSP's command tree, if it has one. | |
2316 | ||
2317 | The command tree could legitimately contain commands like | |
2318 | 'step' and 'next', which call clear_proceed_status, which | |
2319 | frees stop_bpstat's command tree. To make sure this doesn't | |
2320 | free the tree we're executing out from under us, we need to | |
2321 | take ownership of the tree ourselves. Since a given bpstat's | |
2322 | commands are only executed once, we don't need to copy it; we | |
2323 | can clear the pointer in the bpstat, and make sure we free | |
2324 | the tree when we're done. */ | |
c906108c | 2325 | cmd = bs->commands; |
6c50ab1c JB |
2326 | bs->commands = 0; |
2327 | this_cmd_tree_chain = make_cleanup_free_command_lines (&cmd); | |
2328 | ||
c906108c SS |
2329 | while (cmd != NULL) |
2330 | { | |
2331 | execute_control_command (cmd); | |
2332 | ||
2333 | if (breakpoint_proceeded) | |
2334 | break; | |
2335 | else | |
2336 | cmd = cmd->next; | |
2337 | } | |
6c50ab1c JB |
2338 | |
2339 | /* We can free this command tree now. */ | |
2340 | do_cleanups (this_cmd_tree_chain); | |
2341 | ||
c906108c | 2342 | if (breakpoint_proceeded) |
32c1e744 VP |
2343 | { |
2344 | if (target_can_async_p ()) | |
347bddb7 PA |
2345 | /* If we are in async mode, then the target might be still |
2346 | running, not stopped at any breakpoint, so nothing for | |
2347 | us to do here -- just return to the event loop. */ | |
2348 | ; | |
32c1e744 VP |
2349 | else |
2350 | /* In sync mode, when execute_control_command returns | |
2351 | we're already standing on the next breakpoint. | |
347bddb7 PA |
2352 | Breakpoint commands for that stop were not run, since |
2353 | execute_command does not run breakpoint commands -- | |
2354 | only command_line_handler does, but that one is not | |
2355 | involved in execution of breakpoint commands. So, we | |
2356 | can now execute breakpoint commands. It should be | |
2357 | noted that making execute_command do bpstat actions is | |
2358 | not an option -- in this case we'll have recursive | |
2359 | invocation of bpstat for each breakpoint with a | |
2360 | command, and can easily blow up GDB stack. Instead, we | |
2361 | return true, which will trigger the caller to recall us | |
2362 | with the new stop_bpstat. */ | |
2363 | again = 1; | |
2364 | break; | |
32c1e744 | 2365 | } |
c906108c | 2366 | } |
c2b8ed2c | 2367 | do_cleanups (old_chain); |
347bddb7 PA |
2368 | return again; |
2369 | } | |
2370 | ||
2371 | void | |
2372 | bpstat_do_actions (void) | |
2373 | { | |
2374 | /* Do any commands attached to breakpoint we are stopped at. */ | |
2375 | while (!ptid_equal (inferior_ptid, null_ptid) | |
2376 | && target_has_execution | |
2377 | && !is_exited (inferior_ptid) | |
2378 | && !is_executing (inferior_ptid)) | |
2379 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
2380 | and only return when it is stopped at the next breakpoint, we | |
2381 | keep doing breakpoint actions until it returns false to | |
2382 | indicate the inferior was not resumed. */ | |
2383 | if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat)) | |
2384 | break; | |
c906108c SS |
2385 | } |
2386 | ||
fa4727a6 DJ |
2387 | /* Print out the (old or new) value associated with a watchpoint. */ |
2388 | ||
2389 | static void | |
2390 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
2391 | { | |
2392 | if (val == NULL) | |
2393 | fprintf_unfiltered (stream, _("<unreadable>")); | |
2394 | else | |
79a45b7d TT |
2395 | { |
2396 | struct value_print_options opts; | |
2397 | get_user_print_options (&opts); | |
2398 | value_print (val, stream, &opts); | |
2399 | } | |
fa4727a6 DJ |
2400 | } |
2401 | ||
e514a9d6 | 2402 | /* This is the normal print function for a bpstat. In the future, |
c906108c | 2403 | much of this logic could (should?) be moved to bpstat_stop_status, |
e514a9d6 JM |
2404 | by having it set different print_it values. |
2405 | ||
2406 | Current scheme: When we stop, bpstat_print() is called. It loops | |
2407 | through the bpstat list of things causing this stop, calling the | |
2408 | print_bp_stop_message function on each one. The behavior of the | |
2409 | print_bp_stop_message function depends on the print_it field of | |
2410 | bpstat. If such field so indicates, call this function here. | |
2411 | ||
2412 | Return values from this routine (ultimately used by bpstat_print() | |
2413 | and normal_stop() to decide what to do): | |
2414 | PRINT_NOTHING: Means we already printed all we needed to print, | |
2415 | don't print anything else. | |
2416 | PRINT_SRC_ONLY: Means we printed something, and we do *not* desire | |
2417 | that something to be followed by a location. | |
2418 | PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire | |
2419 | that something to be followed by a location. | |
2420 | PRINT_UNKNOWN: Means we printed nothing or we need to do some more | |
2421 | analysis. */ | |
c906108c | 2422 | |
917317f4 | 2423 | static enum print_stop_action |
fba45db2 | 2424 | print_it_typical (bpstat bs) |
c906108c | 2425 | { |
f7545552 | 2426 | struct cleanup *old_chain; |
4f8d1dc6 | 2427 | struct breakpoint *b; |
89f9893c | 2428 | const struct bp_location *bl; |
8b93c638 | 2429 | struct ui_stream *stb; |
f7545552 TT |
2430 | int bp_temp = 0; |
2431 | enum print_stop_action result; | |
2432 | ||
c906108c SS |
2433 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
2434 | which has since been deleted. */ | |
e514a9d6 | 2435 | if (bs->breakpoint_at == NULL) |
917317f4 | 2436 | return PRINT_UNKNOWN; |
0d381245 VP |
2437 | bl = bs->breakpoint_at; |
2438 | b = bl->owner; | |
c906108c | 2439 | |
f7545552 TT |
2440 | stb = ui_out_stream_new (uiout); |
2441 | old_chain = make_cleanup_ui_out_stream_delete (stb); | |
2442 | ||
4f8d1dc6 | 2443 | switch (b->type) |
c906108c | 2444 | { |
e514a9d6 JM |
2445 | case bp_breakpoint: |
2446 | case bp_hardware_breakpoint: | |
2cec12e5 | 2447 | bp_temp = bs->breakpoint_at->owner->disposition == disp_del; |
0d381245 VP |
2448 | if (bl->address != bl->requested_address) |
2449 | breakpoint_adjustment_warning (bl->requested_address, | |
2450 | bl->address, | |
4f8d1dc6 VP |
2451 | b->number, 1); |
2452 | annotate_breakpoint (b->number); | |
2cec12e5 AR |
2453 | if (bp_temp) |
2454 | ui_out_text (uiout, "\nTemporary breakpoint "); | |
2455 | else | |
2456 | ui_out_text (uiout, "\nBreakpoint "); | |
9dc5e2a9 | 2457 | if (ui_out_is_mi_like_p (uiout)) |
2cec12e5 AR |
2458 | { |
2459 | ui_out_field_string (uiout, "reason", | |
2460 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
2461 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
2462 | } | |
4f8d1dc6 | 2463 | ui_out_field_int (uiout, "bkptno", b->number); |
8b93c638 | 2464 | ui_out_text (uiout, ", "); |
f7545552 | 2465 | result = PRINT_SRC_AND_LOC; |
e514a9d6 JM |
2466 | break; |
2467 | ||
2468 | case bp_shlib_event: | |
917317f4 JM |
2469 | /* Did we stop because the user set the stop_on_solib_events |
2470 | variable? (If so, we report this as a generic, "Stopped due | |
2471 | to shlib event" message.) */ | |
a3f17187 | 2472 | printf_filtered (_("Stopped due to shared library event\n")); |
f7545552 | 2473 | result = PRINT_NOTHING; |
e514a9d6 JM |
2474 | break; |
2475 | ||
c4093a6a JM |
2476 | case bp_thread_event: |
2477 | /* Not sure how we will get here. | |
2478 | GDB should not stop for these breakpoints. */ | |
a3f17187 | 2479 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); |
f7545552 | 2480 | result = PRINT_NOTHING; |
c4093a6a JM |
2481 | break; |
2482 | ||
1900040c MS |
2483 | case bp_overlay_event: |
2484 | /* By analogy with the thread event, GDB should not stop for these. */ | |
a3f17187 | 2485 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); |
f7545552 | 2486 | result = PRINT_NOTHING; |
1900040c MS |
2487 | break; |
2488 | ||
0fd8e87f UW |
2489 | case bp_longjmp_master: |
2490 | /* These should never be enabled. */ | |
2491 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
2492 | result = PRINT_NOTHING; | |
2493 | break; | |
2494 | ||
e514a9d6 JM |
2495 | case bp_watchpoint: |
2496 | case bp_hardware_watchpoint: | |
fa4727a6 DJ |
2497 | annotate_watchpoint (b->number); |
2498 | if (ui_out_is_mi_like_p (uiout)) | |
2499 | ui_out_field_string | |
2500 | (uiout, "reason", | |
2501 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
2502 | mention (b); | |
f7545552 | 2503 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
fa4727a6 DJ |
2504 | ui_out_text (uiout, "\nOld value = "); |
2505 | watchpoint_value_print (bs->old_val, stb->stream); | |
2506 | ui_out_field_stream (uiout, "old", stb); | |
2507 | ui_out_text (uiout, "\nNew value = "); | |
2508 | watchpoint_value_print (b->val, stb->stream); | |
2509 | ui_out_field_stream (uiout, "new", stb); | |
fa4727a6 | 2510 | ui_out_text (uiout, "\n"); |
e514a9d6 | 2511 | /* More than one watchpoint may have been triggered. */ |
f7545552 | 2512 | result = PRINT_UNKNOWN; |
e514a9d6 JM |
2513 | break; |
2514 | ||
2515 | case bp_read_watchpoint: | |
9dc5e2a9 | 2516 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
2517 | ui_out_field_string |
2518 | (uiout, "reason", | |
2519 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
4f8d1dc6 | 2520 | mention (b); |
f7545552 | 2521 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 | 2522 | ui_out_text (uiout, "\nValue = "); |
fa4727a6 | 2523 | watchpoint_value_print (b->val, stb->stream); |
8b93c638 | 2524 | ui_out_field_stream (uiout, "value", stb); |
8b93c638 | 2525 | ui_out_text (uiout, "\n"); |
f7545552 | 2526 | result = PRINT_UNKNOWN; |
e514a9d6 JM |
2527 | break; |
2528 | ||
2529 | case bp_access_watchpoint: | |
fa4727a6 | 2530 | if (bs->old_val != NULL) |
8b93c638 | 2531 | { |
4f8d1dc6 | 2532 | annotate_watchpoint (b->number); |
9dc5e2a9 | 2533 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
2534 | ui_out_field_string |
2535 | (uiout, "reason", | |
2536 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
4f8d1dc6 | 2537 | mention (b); |
f7545552 | 2538 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 | 2539 | ui_out_text (uiout, "\nOld value = "); |
fa4727a6 | 2540 | watchpoint_value_print (bs->old_val, stb->stream); |
8b93c638 | 2541 | ui_out_field_stream (uiout, "old", stb); |
8b93c638 JM |
2542 | ui_out_text (uiout, "\nNew value = "); |
2543 | } | |
2544 | else | |
2545 | { | |
4f8d1dc6 | 2546 | mention (b); |
9dc5e2a9 | 2547 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
2548 | ui_out_field_string |
2549 | (uiout, "reason", | |
2550 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
f7545552 | 2551 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 JM |
2552 | ui_out_text (uiout, "\nValue = "); |
2553 | } | |
fa4727a6 | 2554 | watchpoint_value_print (b->val, stb->stream); |
8b93c638 | 2555 | ui_out_field_stream (uiout, "new", stb); |
8b93c638 | 2556 | ui_out_text (uiout, "\n"); |
f7545552 | 2557 | result = PRINT_UNKNOWN; |
e514a9d6 | 2558 | break; |
4ce44c66 | 2559 | |
e514a9d6 JM |
2560 | /* Fall through, we don't deal with these types of breakpoints |
2561 | here. */ | |
2562 | ||
11cf8741 | 2563 | case bp_finish: |
9dc5e2a9 | 2564 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
2565 | ui_out_field_string |
2566 | (uiout, "reason", | |
2567 | async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED)); | |
f7545552 | 2568 | result = PRINT_UNKNOWN; |
8b93c638 JM |
2569 | break; |
2570 | ||
e514a9d6 | 2571 | case bp_until: |
9dc5e2a9 | 2572 | if (ui_out_is_mi_like_p (uiout)) |
1fbc2a49 NR |
2573 | ui_out_field_string |
2574 | (uiout, "reason", | |
2575 | async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED)); | |
f7545552 | 2576 | result = PRINT_UNKNOWN; |
8b93c638 JM |
2577 | break; |
2578 | ||
c2d11a7d | 2579 | case bp_none: |
e514a9d6 JM |
2580 | case bp_longjmp: |
2581 | case bp_longjmp_resume: | |
2582 | case bp_step_resume: | |
e514a9d6 JM |
2583 | case bp_watchpoint_scope: |
2584 | case bp_call_dummy: | |
1042e4c0 | 2585 | case bp_tracepoint: |
e514a9d6 | 2586 | default: |
f7545552 TT |
2587 | result = PRINT_UNKNOWN; |
2588 | break; | |
e514a9d6 | 2589 | } |
f7545552 TT |
2590 | |
2591 | do_cleanups (old_chain); | |
2592 | return result; | |
e514a9d6 JM |
2593 | } |
2594 | ||
2595 | /* Generic routine for printing messages indicating why we | |
2596 | stopped. The behavior of this function depends on the value | |
2597 | 'print_it' in the bpstat structure. Under some circumstances we | |
2598 | may decide not to print anything here and delegate the task to | |
2599 | normal_stop(). */ | |
2600 | ||
2601 | static enum print_stop_action | |
2602 | print_bp_stop_message (bpstat bs) | |
2603 | { | |
2604 | switch (bs->print_it) | |
2605 | { | |
2606 | case print_it_noop: | |
2607 | /* Nothing should be printed for this bpstat entry. */ | |
2608 | return PRINT_UNKNOWN; | |
2609 | break; | |
2610 | ||
2611 | case print_it_done: | |
2612 | /* We still want to print the frame, but we already printed the | |
2613 | relevant messages. */ | |
2614 | return PRINT_SRC_AND_LOC; | |
2615 | break; | |
2616 | ||
2617 | case print_it_normal: | |
4f8d1dc6 | 2618 | { |
89f9893c | 2619 | const struct bp_location *bl = bs->breakpoint_at; |
4f8d1dc6 VP |
2620 | struct breakpoint *b = bl ? bl->owner : NULL; |
2621 | ||
2622 | /* Normal case. Call the breakpoint's print_it method, or | |
2623 | print_it_typical. */ | |
2624 | /* FIXME: how breakpoint can ever be NULL here? */ | |
2625 | if (b != NULL && b->ops != NULL && b->ops->print_it != NULL) | |
2626 | return b->ops->print_it (b); | |
2627 | else | |
2628 | return print_it_typical (bs); | |
2629 | } | |
2630 | break; | |
3086aeae | 2631 | |
e514a9d6 | 2632 | default: |
8e65ff28 | 2633 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 2634 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 2635 | break; |
c906108c | 2636 | } |
c906108c SS |
2637 | } |
2638 | ||
e514a9d6 JM |
2639 | /* Print a message indicating what happened. This is called from |
2640 | normal_stop(). The input to this routine is the head of the bpstat | |
2641 | list - a list of the eventpoints that caused this stop. This | |
2642 | routine calls the generic print routine for printing a message | |
2643 | about reasons for stopping. This will print (for example) the | |
2644 | "Breakpoint n," part of the output. The return value of this | |
2645 | routine is one of: | |
c906108c | 2646 | |
917317f4 JM |
2647 | PRINT_UNKNOWN: Means we printed nothing |
2648 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent | |
c5aa993b JM |
2649 | code to print the location. An example is |
2650 | "Breakpoint 1, " which should be followed by | |
2651 | the location. | |
917317f4 | 2652 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
2653 | to also print the location part of the message. |
2654 | An example is the catch/throw messages, which | |
917317f4 JM |
2655 | don't require a location appended to the end. |
2656 | PRINT_NOTHING: We have done some printing and we don't need any | |
2657 | further info to be printed.*/ | |
c906108c | 2658 | |
917317f4 | 2659 | enum print_stop_action |
fba45db2 | 2660 | bpstat_print (bpstat bs) |
c906108c SS |
2661 | { |
2662 | int val; | |
c5aa993b | 2663 | |
c906108c | 2664 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
2665 | (Currently all watchpoints go on the bpstat whether hit or not. |
2666 | That probably could (should) be changed, provided care is taken | |
c906108c | 2667 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
2668 | for (; bs; bs = bs->next) |
2669 | { | |
2670 | val = print_bp_stop_message (bs); | |
2671 | if (val == PRINT_SRC_ONLY | |
2672 | || val == PRINT_SRC_AND_LOC | |
2673 | || val == PRINT_NOTHING) | |
2674 | return val; | |
2675 | } | |
c906108c | 2676 | |
e514a9d6 JM |
2677 | /* We reached the end of the chain, or we got a null BS to start |
2678 | with and nothing was printed. */ | |
917317f4 | 2679 | return PRINT_UNKNOWN; |
c906108c SS |
2680 | } |
2681 | ||
2682 | /* Evaluate the expression EXP and return 1 if value is zero. | |
2683 | This is used inside a catch_errors to evaluate the breakpoint condition. | |
2684 | The argument is a "struct expression *" that has been cast to char * to | |
2685 | make it pass through catch_errors. */ | |
2686 | ||
2687 | static int | |
4efb68b1 | 2688 | breakpoint_cond_eval (void *exp) |
c906108c | 2689 | { |
278cd55f | 2690 | struct value *mark = value_mark (); |
c5aa993b | 2691 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
c906108c SS |
2692 | value_free_to_mark (mark); |
2693 | return i; | |
2694 | } | |
2695 | ||
2696 | /* Allocate a new bpstat and chain it to the current one. */ | |
2697 | ||
2698 | static bpstat | |
89f9893c | 2699 | bpstat_alloc (const struct bp_location *bl, bpstat cbs /* Current "bs" value */ ) |
c906108c SS |
2700 | { |
2701 | bpstat bs; | |
2702 | ||
2703 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
2704 | cbs->next = bs; | |
4f8d1dc6 | 2705 | bs->breakpoint_at = bl; |
c906108c SS |
2706 | /* If the condition is false, etc., don't do the commands. */ |
2707 | bs->commands = NULL; | |
2708 | bs->old_val = NULL; | |
2709 | bs->print_it = print_it_normal; | |
2710 | return bs; | |
2711 | } | |
2712 | \f | |
d983da9c DJ |
2713 | /* The target has stopped with waitstatus WS. Check if any hardware |
2714 | watchpoints have triggered, according to the target. */ | |
2715 | ||
2716 | int | |
2717 | watchpoints_triggered (struct target_waitstatus *ws) | |
2718 | { | |
d92524f1 | 2719 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
2720 | CORE_ADDR addr; |
2721 | struct breakpoint *b; | |
2722 | ||
2723 | if (!stopped_by_watchpoint) | |
2724 | { | |
2725 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
2726 | as not triggered. */ | |
2727 | ALL_BREAKPOINTS (b) | |
2728 | if (b->type == bp_hardware_watchpoint | |
2729 | || b->type == bp_read_watchpoint | |
2730 | || b->type == bp_access_watchpoint) | |
2731 | b->watchpoint_triggered = watch_triggered_no; | |
2732 | ||
2733 | return 0; | |
2734 | } | |
2735 | ||
2736 | if (!target_stopped_data_address (¤t_target, &addr)) | |
2737 | { | |
2738 | /* We were stopped by a watchpoint, but we don't know where. | |
2739 | Mark all watchpoints as unknown. */ | |
2740 | ALL_BREAKPOINTS (b) | |
2741 | if (b->type == bp_hardware_watchpoint | |
2742 | || b->type == bp_read_watchpoint | |
2743 | || b->type == bp_access_watchpoint) | |
2744 | b->watchpoint_triggered = watch_triggered_unknown; | |
2745 | ||
2746 | return stopped_by_watchpoint; | |
2747 | } | |
2748 | ||
2749 | /* The target could report the data address. Mark watchpoints | |
2750 | affected by this data address as triggered, and all others as not | |
2751 | triggered. */ | |
2752 | ||
2753 | ALL_BREAKPOINTS (b) | |
2754 | if (b->type == bp_hardware_watchpoint | |
2755 | || b->type == bp_read_watchpoint | |
2756 | || b->type == bp_access_watchpoint) | |
2757 | { | |
a5606eee | 2758 | struct bp_location *loc; |
d983da9c DJ |
2759 | struct value *v; |
2760 | ||
2761 | b->watchpoint_triggered = watch_triggered_no; | |
a5606eee VP |
2762 | for (loc = b->loc; loc; loc = loc->next) |
2763 | /* Exact match not required. Within range is | |
2764 | sufficient. */ | |
5009afc5 AS |
2765 | if (target_watchpoint_addr_within_range (¤t_target, |
2766 | addr, loc->address, | |
2767 | loc->length)) | |
a5606eee VP |
2768 | { |
2769 | b->watchpoint_triggered = watch_triggered_yes; | |
2770 | break; | |
2771 | } | |
d983da9c DJ |
2772 | } |
2773 | ||
2774 | return 1; | |
2775 | } | |
2776 | ||
c906108c SS |
2777 | /* Possible return values for watchpoint_check (this can't be an enum |
2778 | because of check_errors). */ | |
2779 | /* The watchpoint has been deleted. */ | |
2780 | #define WP_DELETED 1 | |
2781 | /* The value has changed. */ | |
2782 | #define WP_VALUE_CHANGED 2 | |
2783 | /* The value has not changed. */ | |
2784 | #define WP_VALUE_NOT_CHANGED 3 | |
2785 | ||
2786 | #define BP_TEMPFLAG 1 | |
2787 | #define BP_HARDWAREFLAG 2 | |
2788 | ||
2789 | /* Check watchpoint condition. */ | |
2790 | ||
2791 | static int | |
4efb68b1 | 2792 | watchpoint_check (void *p) |
c906108c SS |
2793 | { |
2794 | bpstat bs = (bpstat) p; | |
2795 | struct breakpoint *b; | |
2796 | struct frame_info *fr; | |
2797 | int within_current_scope; | |
2798 | ||
4f8d1dc6 | 2799 | b = bs->breakpoint_at->owner; |
c906108c SS |
2800 | |
2801 | if (b->exp_valid_block == NULL) | |
2802 | within_current_scope = 1; | |
2803 | else | |
2804 | { | |
edb3359d DJ |
2805 | struct frame_info *frame = get_current_frame (); |
2806 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
2807 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
2808 | ||
101dcfbe | 2809 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 2810 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
2811 | |
2812 | /* If we've gotten confused in the unwinder, we might have | |
2813 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
2814 | if (within_current_scope) |
2815 | { | |
2816 | struct symbol *function; | |
2817 | ||
2818 | function = get_frame_function (fr); | |
2819 | if (function == NULL | |
2820 | || !contained_in (b->exp_valid_block, | |
2821 | SYMBOL_BLOCK_VALUE (function))) | |
2822 | within_current_scope = 0; | |
2823 | } | |
69fbadd5 | 2824 | |
c12260ac CV |
2825 | /* in_function_epilogue_p() returns a non-zero value if we're still |
2826 | in the function but the stack frame has already been invalidated. | |
2827 | Since we can't rely on the values of local variables after the | |
2828 | stack has been destroyed, we are treating the watchpoint in that | |
edb3359d DJ |
2829 | state as `not changed' without further checking. Don't mark |
2830 | watchpoints as changed if the current frame is in an epilogue - | |
2831 | even if they are in some other frame, our view of the stack | |
2832 | is likely to be wrong. */ | |
2833 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) | |
2834 | return WP_VALUE_NOT_CHANGED; | |
fb14de7b | 2835 | |
edb3359d | 2836 | if (within_current_scope) |
c906108c SS |
2837 | /* If we end up stopping, the current frame will get selected |
2838 | in normal_stop. So this call to select_frame won't affect | |
2839 | the user. */ | |
0f7d239c | 2840 | select_frame (fr); |
c906108c | 2841 | } |
c5aa993b | 2842 | |
c906108c SS |
2843 | if (within_current_scope) |
2844 | { | |
2845 | /* We use value_{,free_to_}mark because it could be a | |
2846 | *long* time before we return to the command level and | |
c5aa993b JM |
2847 | call free_all_values. We can't call free_all_values because |
2848 | we might be in the middle of evaluating a function call. */ | |
c906108c | 2849 | |
278cd55f | 2850 | struct value *mark = value_mark (); |
fa4727a6 DJ |
2851 | struct value *new_val; |
2852 | ||
2853 | fetch_watchpoint_value (b->exp, &new_val, NULL, NULL); | |
2854 | if ((b->val != NULL) != (new_val != NULL) | |
2855 | || (b->val != NULL && !value_equal (b->val, new_val))) | |
c906108c | 2856 | { |
fa4727a6 DJ |
2857 | if (new_val != NULL) |
2858 | { | |
2859 | release_value (new_val); | |
2860 | value_free_to_mark (mark); | |
2861 | } | |
c906108c SS |
2862 | bs->old_val = b->val; |
2863 | b->val = new_val; | |
fa4727a6 | 2864 | b->val_valid = 1; |
c906108c SS |
2865 | /* We will stop here */ |
2866 | return WP_VALUE_CHANGED; | |
2867 | } | |
2868 | else | |
2869 | { | |
2870 | /* Nothing changed, don't do anything. */ | |
2871 | value_free_to_mark (mark); | |
2872 | /* We won't stop here */ | |
2873 | return WP_VALUE_NOT_CHANGED; | |
2874 | } | |
2875 | } | |
2876 | else | |
2877 | { | |
2878 | /* This seems like the only logical thing to do because | |
c5aa993b JM |
2879 | if we temporarily ignored the watchpoint, then when |
2880 | we reenter the block in which it is valid it contains | |
2881 | garbage (in the case of a function, it may have two | |
2882 | garbage values, one before and one after the prologue). | |
2883 | So we can't even detect the first assignment to it and | |
2884 | watch after that (since the garbage may or may not equal | |
2885 | the first value assigned). */ | |
4ce44c66 JM |
2886 | /* We print all the stop information in print_it_typical(), but |
2887 | in this case, by the time we call print_it_typical() this bp | |
2888 | will be deleted already. So we have no choice but print the | |
2889 | information here. */ | |
9dc5e2a9 | 2890 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
2891 | ui_out_field_string |
2892 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
8b93c638 | 2893 | ui_out_text (uiout, "\nWatchpoint "); |
4f8d1dc6 | 2894 | ui_out_field_int (uiout, "wpnum", b->number); |
8b93c638 JM |
2895 | ui_out_text (uiout, " deleted because the program has left the block in\n\ |
2896 | which its expression is valid.\n"); | |
4ce44c66 | 2897 | |
c906108c | 2898 | if (b->related_breakpoint) |
b5de0fa7 EZ |
2899 | b->related_breakpoint->disposition = disp_del_at_next_stop; |
2900 | b->disposition = disp_del_at_next_stop; | |
c906108c SS |
2901 | |
2902 | return WP_DELETED; | |
2903 | } | |
2904 | } | |
2905 | ||
18a18393 VP |
2906 | /* Return true if it looks like target has stopped due to hitting |
2907 | breakpoint location BL. This function does not check if we | |
2908 | should stop, only if BL explains the stop. */ | |
2909 | static int | |
2910 | bpstat_check_location (const struct bp_location *bl, CORE_ADDR bp_addr) | |
2911 | { | |
2912 | struct breakpoint *b = bl->owner; | |
2913 | ||
2914 | if (b->type != bp_watchpoint | |
2915 | && b->type != bp_hardware_watchpoint | |
2916 | && b->type != bp_read_watchpoint | |
2917 | && b->type != bp_access_watchpoint | |
2918 | && b->type != bp_hardware_breakpoint | |
fe798b75 | 2919 | && b->type != bp_catchpoint) /* a non-watchpoint bp */ |
18a18393 VP |
2920 | { |
2921 | if (bl->address != bp_addr) /* address doesn't match */ | |
2922 | return 0; | |
2923 | if (overlay_debugging /* unmapped overlay section */ | |
2924 | && section_is_overlay (bl->section) | |
2925 | && !section_is_mapped (bl->section)) | |
2926 | return 0; | |
2927 | } | |
2928 | ||
2929 | /* Continuable hardware watchpoints are treated as non-existent if the | |
2930 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
2931 | some data address). Otherwise gdb won't stop on a break instruction | |
2932 | in the code (not from a breakpoint) when a hardware watchpoint has | |
2933 | been defined. Also skip watchpoints which we know did not trigger | |
2934 | (did not match the data address). */ | |
2935 | ||
2936 | if ((b->type == bp_hardware_watchpoint | |
2937 | || b->type == bp_read_watchpoint | |
2938 | || b->type == bp_access_watchpoint) | |
2939 | && b->watchpoint_triggered == watch_triggered_no) | |
2940 | return 0; | |
2941 | ||
2942 | if (b->type == bp_hardware_breakpoint) | |
2943 | { | |
2944 | if (bl->address != bp_addr) | |
2945 | return 0; | |
2946 | if (overlay_debugging /* unmapped overlay section */ | |
2947 | && section_is_overlay (bl->section) | |
2948 | && !section_is_mapped (bl->section)) | |
2949 | return 0; | |
2950 | } | |
ce78b96d | 2951 | |
ce78b96d JB |
2952 | if (b->type == bp_catchpoint) |
2953 | { | |
2954 | gdb_assert (b->ops != NULL && b->ops->breakpoint_hit != NULL); | |
2955 | if (!b->ops->breakpoint_hit (b)) | |
2956 | return 0; | |
2957 | } | |
2958 | ||
18a18393 VP |
2959 | return 1; |
2960 | } | |
2961 | ||
2962 | /* If BS refers to a watchpoint, determine if the watched values | |
2963 | has actually changed, and we should stop. If not, set BS->stop | |
2964 | to 0. */ | |
2965 | static void | |
2966 | bpstat_check_watchpoint (bpstat bs) | |
2967 | { | |
2968 | const struct bp_location *bl = bs->breakpoint_at; | |
2969 | struct breakpoint *b = bl->owner; | |
2970 | ||
2971 | if (b->type == bp_watchpoint | |
2972 | || b->type == bp_read_watchpoint | |
2973 | || b->type == bp_access_watchpoint | |
2974 | || b->type == bp_hardware_watchpoint) | |
2975 | { | |
2976 | CORE_ADDR addr; | |
2977 | struct value *v; | |
2978 | int must_check_value = 0; | |
2979 | ||
2980 | if (b->type == bp_watchpoint) | |
2981 | /* For a software watchpoint, we must always check the | |
2982 | watched value. */ | |
2983 | must_check_value = 1; | |
2984 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
2985 | /* We have a hardware watchpoint (read, write, or access) | |
2986 | and the target earlier reported an address watched by | |
2987 | this watchpoint. */ | |
2988 | must_check_value = 1; | |
2989 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
2990 | && b->type == bp_hardware_watchpoint) | |
2991 | /* We were stopped by a hardware watchpoint, but the target could | |
2992 | not report the data address. We must check the watchpoint's | |
2993 | value. Access and read watchpoints are out of luck; without | |
2994 | a data address, we can't figure it out. */ | |
2995 | must_check_value = 1; | |
2996 | ||
2997 | if (must_check_value) | |
2998 | { | |
2999 | char *message = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
3000 | b->number); | |
3001 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
3002 | int e = catch_errors (watchpoint_check, bs, message, | |
3003 | RETURN_MASK_ALL); | |
3004 | do_cleanups (cleanups); | |
3005 | switch (e) | |
3006 | { | |
3007 | case WP_DELETED: | |
3008 | /* We've already printed what needs to be printed. */ | |
3009 | bs->print_it = print_it_done; | |
3010 | /* Stop. */ | |
3011 | break; | |
3012 | case WP_VALUE_CHANGED: | |
3013 | if (b->type == bp_read_watchpoint) | |
3014 | { | |
3015 | /* Don't stop: read watchpoints shouldn't fire if | |
3016 | the value has changed. This is for targets | |
3017 | which cannot set read-only watchpoints. */ | |
3018 | bs->print_it = print_it_noop; | |
3019 | bs->stop = 0; | |
3020 | } | |
3021 | break; | |
3022 | case WP_VALUE_NOT_CHANGED: | |
3023 | if (b->type == bp_hardware_watchpoint | |
3024 | || b->type == bp_watchpoint) | |
3025 | { | |
3026 | /* Don't stop: write watchpoints shouldn't fire if | |
3027 | the value hasn't changed. */ | |
3028 | bs->print_it = print_it_noop; | |
3029 | bs->stop = 0; | |
3030 | } | |
3031 | /* Stop. */ | |
3032 | break; | |
3033 | default: | |
3034 | /* Can't happen. */ | |
3035 | case 0: | |
3036 | /* Error from catch_errors. */ | |
3037 | printf_filtered (_("Watchpoint %d deleted.\n"), b->number); | |
3038 | if (b->related_breakpoint) | |
3039 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
3040 | b->disposition = disp_del_at_next_stop; | |
3041 | /* We've already printed what needs to be printed. */ | |
3042 | bs->print_it = print_it_done; | |
3043 | break; | |
3044 | } | |
3045 | } | |
3046 | else /* must_check_value == 0 */ | |
3047 | { | |
3048 | /* This is a case where some watchpoint(s) triggered, but | |
3049 | not at the address of this watchpoint, or else no | |
3050 | watchpoint triggered after all. So don't print | |
3051 | anything for this watchpoint. */ | |
3052 | bs->print_it = print_it_noop; | |
3053 | bs->stop = 0; | |
3054 | } | |
3055 | } | |
3056 | } | |
3057 | ||
3058 | ||
3059 | /* Check conditions (condition proper, frame, thread and ignore count) | |
3060 | of breakpoint referred to by BS. If we should not stop for this | |
3061 | breakpoint, set BS->stop to 0. */ | |
3062 | static void | |
3063 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
3064 | { | |
3065 | int thread_id = pid_to_thread_id (ptid); | |
3066 | const struct bp_location *bl = bs->breakpoint_at; | |
3067 | struct breakpoint *b = bl->owner; | |
3068 | ||
3069 | if (frame_id_p (b->frame_id) | |
edb3359d | 3070 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 VP |
3071 | bs->stop = 0; |
3072 | else if (bs->stop) | |
3073 | { | |
3074 | int value_is_zero = 0; | |
3075 | ||
3076 | /* If this is a scope breakpoint, mark the associated | |
3077 | watchpoint as triggered so that we will handle the | |
3078 | out-of-scope event. We'll get to the watchpoint next | |
3079 | iteration. */ | |
3080 | if (b->type == bp_watchpoint_scope) | |
3081 | b->related_breakpoint->watchpoint_triggered = watch_triggered_yes; | |
3082 | ||
3083 | if (bl->cond && bl->owner->disposition != disp_del_at_next_stop) | |
3084 | { | |
c5bc3a77 DJ |
3085 | /* We use value_mark and value_free_to_mark because it could |
3086 | be a long time before we return to the command level and | |
3087 | call free_all_values. We can't call free_all_values | |
3088 | because we might be in the middle of evaluating a | |
3089 | function call. */ | |
3090 | struct value *mark = value_mark (); | |
3091 | ||
edb3359d DJ |
3092 | /* Need to select the frame, with all that implies so that |
3093 | the conditions will have the right context. Because we | |
3094 | use the frame, we will not see an inlined function's | |
3095 | variables when we arrive at a breakpoint at the start | |
3096 | of the inlined function; the current frame will be the | |
3097 | call site. */ | |
18a18393 VP |
3098 | select_frame (get_current_frame ()); |
3099 | value_is_zero | |
3100 | = catch_errors (breakpoint_cond_eval, (bl->cond), | |
3101 | "Error in testing breakpoint condition:\n", | |
3102 | RETURN_MASK_ALL); | |
3103 | /* FIXME-someday, should give breakpoint # */ | |
c5bc3a77 | 3104 | value_free_to_mark (mark); |
18a18393 VP |
3105 | } |
3106 | if (bl->cond && value_is_zero) | |
3107 | { | |
3108 | bs->stop = 0; | |
3109 | } | |
3110 | else if (b->thread != -1 && b->thread != thread_id) | |
3111 | { | |
3112 | bs->stop = 0; | |
3113 | } | |
3114 | else if (b->ignore_count > 0) | |
3115 | { | |
3116 | b->ignore_count--; | |
3117 | annotate_ignore_count_change (); | |
3118 | bs->stop = 0; | |
3119 | /* Increase the hit count even though we don't | |
3120 | stop. */ | |
3121 | ++(b->hit_count); | |
3122 | } | |
3123 | } | |
3124 | } | |
3125 | ||
3126 | ||
9709f61c | 3127 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 3128 | BP_ADDR in thread PTID. |
c906108c | 3129 | |
d983da9c | 3130 | Determine whether we stopped at a breakpoint, etc, or whether we |
c906108c SS |
3131 | don't understand this stop. Result is a chain of bpstat's such that: |
3132 | ||
c5aa993b | 3133 | if we don't understand the stop, the result is a null pointer. |
c906108c | 3134 | |
c5aa993b | 3135 | if we understand why we stopped, the result is not null. |
c906108c | 3136 | |
c5aa993b JM |
3137 | Each element of the chain refers to a particular breakpoint or |
3138 | watchpoint at which we have stopped. (We may have stopped for | |
3139 | several reasons concurrently.) | |
c906108c | 3140 | |
c5aa993b JM |
3141 | Each element of the chain has valid next, breakpoint_at, |
3142 | commands, FIXME??? fields. */ | |
c906108c SS |
3143 | |
3144 | bpstat | |
d983da9c | 3145 | bpstat_stop_status (CORE_ADDR bp_addr, ptid_t ptid) |
c906108c | 3146 | { |
0d381245 | 3147 | struct breakpoint *b = NULL; |
89f9893c | 3148 | const struct bp_location *bl; |
20874c92 | 3149 | struct bp_location *loc; |
c906108c SS |
3150 | /* Root of the chain of bpstat's */ |
3151 | struct bpstats root_bs[1]; | |
3152 | /* Pointer to the last thing in the chain currently. */ | |
3153 | bpstat bs = root_bs; | |
20874c92 | 3154 | int ix; |
d832cb68 | 3155 | int need_remove_insert; |
c906108c | 3156 | |
0d381245 | 3157 | ALL_BP_LOCATIONS (bl) |
c5aa993b | 3158 | { |
0d381245 VP |
3159 | b = bl->owner; |
3160 | gdb_assert (b); | |
468d015d | 3161 | if (!breakpoint_enabled (b) && b->enable_state != bp_permanent) |
c5aa993b JM |
3162 | continue; |
3163 | ||
a5606eee VP |
3164 | /* For hardware watchpoints, we look only at the first location. |
3165 | The watchpoint_check function will work on entire expression, | |
3166 | not the individual locations. For read watchopints, the | |
3167 | watchpoints_triggered function have checked all locations | |
3168 | alrea | |
3169 | */ | |
3170 | if (b->type == bp_hardware_watchpoint && bl != b->loc) | |
3171 | continue; | |
3172 | ||
18a18393 VP |
3173 | if (!bpstat_check_location (bl, bp_addr)) |
3174 | continue; | |
3175 | ||
c5aa993b JM |
3176 | /* Come here if it's a watchpoint, or if the break address matches */ |
3177 | ||
0d381245 | 3178 | bs = bpstat_alloc (bl, bs); /* Alloc a bpstat to explain stop */ |
c5aa993b | 3179 | |
18a18393 VP |
3180 | /* Assume we stop. Should we find watchpoint that is not actually |
3181 | triggered, or if condition of breakpoint is false, we'll reset | |
3182 | 'stop' to 0. */ | |
c5aa993b JM |
3183 | bs->stop = 1; |
3184 | bs->print = 1; | |
3185 | ||
18a18393 VP |
3186 | bpstat_check_watchpoint (bs); |
3187 | if (!bs->stop) | |
3188 | continue; | |
c5aa993b | 3189 | |
0fd8e87f UW |
3190 | if (b->type == bp_thread_event || b->type == bp_overlay_event |
3191 | || b->type == bp_longjmp_master) | |
18a18393 | 3192 | /* We do not stop for these. */ |
c5aa993b JM |
3193 | bs->stop = 0; |
3194 | else | |
18a18393 VP |
3195 | bpstat_check_breakpoint_conditions (bs, ptid); |
3196 | ||
3197 | if (bs->stop) | |
c5aa993b | 3198 | { |
18a18393 | 3199 | ++(b->hit_count); |
d983da9c | 3200 | |
18a18393 VP |
3201 | /* We will stop here */ |
3202 | if (b->disposition == disp_disable) | |
c5aa993b | 3203 | { |
514f746b AR |
3204 | if (b->enable_state != bp_permanent) |
3205 | b->enable_state = bp_disabled; | |
b60e7edf | 3206 | update_global_location_list (0); |
c5aa993b | 3207 | } |
18a18393 VP |
3208 | if (b->silent) |
3209 | bs->print = 0; | |
3210 | bs->commands = b->commands; | |
059fb39f PM |
3211 | if (bs->commands |
3212 | && (strcmp ("silent", bs->commands->line) == 0 | |
3213 | || (xdb_commands && strcmp ("Q", bs->commands->line) == 0))) | |
c5aa993b | 3214 | { |
18a18393 VP |
3215 | bs->commands = bs->commands->next; |
3216 | bs->print = 0; | |
c5aa993b | 3217 | } |
18a18393 | 3218 | bs->commands = copy_command_lines (bs->commands); |
c5aa993b | 3219 | } |
18a18393 | 3220 | |
c5aa993b JM |
3221 | /* Print nothing for this entry if we dont stop or if we dont print. */ |
3222 | if (bs->stop == 0 || bs->print == 0) | |
3223 | bs->print_it = print_it_noop; | |
3224 | } | |
c906108c | 3225 | |
20874c92 VP |
3226 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) |
3227 | { | |
3228 | if (loc->address == bp_addr) | |
3229 | { | |
3230 | bs = bpstat_alloc (loc, bs); | |
3231 | /* For hits of moribund locations, we should just proceed. */ | |
3232 | bs->stop = 0; | |
3233 | bs->print = 0; | |
3234 | bs->print_it = print_it_noop; | |
3235 | } | |
3236 | } | |
3237 | ||
c906108c SS |
3238 | bs->next = NULL; /* Terminate the chain */ |
3239 | bs = root_bs->next; /* Re-grab the head of the chain */ | |
3240 | ||
d983da9c DJ |
3241 | /* If we aren't stopping, the value of some hardware watchpoint may |
3242 | not have changed, but the intermediate memory locations we are | |
3243 | watching may have. Don't bother if we're stopping; this will get | |
3244 | done later. */ | |
3245 | for (bs = root_bs->next; bs != NULL; bs = bs->next) | |
3246 | if (bs->stop) | |
3247 | break; | |
3248 | ||
d832cb68 | 3249 | need_remove_insert = 0; |
d983da9c DJ |
3250 | if (bs == NULL) |
3251 | for (bs = root_bs->next; bs != NULL; bs = bs->next) | |
3252 | if (!bs->stop | |
20874c92 | 3253 | && bs->breakpoint_at->owner |
d983da9c DJ |
3254 | && (bs->breakpoint_at->owner->type == bp_hardware_watchpoint |
3255 | || bs->breakpoint_at->owner->type == bp_read_watchpoint | |
3256 | || bs->breakpoint_at->owner->type == bp_access_watchpoint)) | |
3257 | { | |
a5606eee VP |
3258 | /* remove/insert can invalidate bs->breakpoint_at, if this |
3259 | location is no longer used by the watchpoint. Prevent | |
3260 | further code from trying to use it. */ | |
3261 | bs->breakpoint_at = NULL; | |
d832cb68 | 3262 | need_remove_insert = 1; |
d983da9c DJ |
3263 | } |
3264 | ||
d832cb68 DD |
3265 | if (need_remove_insert) |
3266 | { | |
3267 | remove_breakpoints (); | |
3268 | insert_breakpoints (); | |
3269 | } | |
3270 | ||
d983da9c | 3271 | return root_bs->next; |
c906108c SS |
3272 | } |
3273 | \f | |
3274 | /* Tell what to do about this bpstat. */ | |
3275 | struct bpstat_what | |
fba45db2 | 3276 | bpstat_what (bpstat bs) |
c906108c SS |
3277 | { |
3278 | /* Classify each bpstat as one of the following. */ | |
c5aa993b JM |
3279 | enum class |
3280 | { | |
3281 | /* This bpstat element has no effect on the main_action. */ | |
3282 | no_effect = 0, | |
3283 | ||
3284 | /* There was a watchpoint, stop but don't print. */ | |
3285 | wp_silent, | |
c906108c | 3286 | |
c5aa993b JM |
3287 | /* There was a watchpoint, stop and print. */ |
3288 | wp_noisy, | |
c906108c | 3289 | |
c5aa993b JM |
3290 | /* There was a breakpoint but we're not stopping. */ |
3291 | bp_nostop, | |
c906108c | 3292 | |
c5aa993b JM |
3293 | /* There was a breakpoint, stop but don't print. */ |
3294 | bp_silent, | |
c906108c | 3295 | |
c5aa993b JM |
3296 | /* There was a breakpoint, stop and print. */ |
3297 | bp_noisy, | |
c906108c | 3298 | |
c5aa993b JM |
3299 | /* We hit the longjmp breakpoint. */ |
3300 | long_jump, | |
c906108c | 3301 | |
c5aa993b JM |
3302 | /* We hit the longjmp_resume breakpoint. */ |
3303 | long_resume, | |
c906108c | 3304 | |
c5aa993b JM |
3305 | /* We hit the step_resume breakpoint. */ |
3306 | step_resume, | |
c906108c | 3307 | |
c5aa993b JM |
3308 | /* We hit the shared library event breakpoint. */ |
3309 | shlib_event, | |
c906108c | 3310 | |
c5aa993b JM |
3311 | /* This is just used to count how many enums there are. */ |
3312 | class_last | |
c906108c SS |
3313 | }; |
3314 | ||
3315 | /* Here is the table which drives this routine. So that we can | |
3316 | format it pretty, we define some abbreviations for the | |
3317 | enum bpstat_what codes. */ | |
3318 | #define kc BPSTAT_WHAT_KEEP_CHECKING | |
3319 | #define ss BPSTAT_WHAT_STOP_SILENT | |
3320 | #define sn BPSTAT_WHAT_STOP_NOISY | |
3321 | #define sgl BPSTAT_WHAT_SINGLE | |
3322 | #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME | |
3323 | #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME | |
c906108c | 3324 | #define sr BPSTAT_WHAT_STEP_RESUME |
c906108c | 3325 | #define shl BPSTAT_WHAT_CHECK_SHLIBS |
c906108c SS |
3326 | |
3327 | /* "Can't happen." Might want to print an error message. | |
3328 | abort() is not out of the question, but chances are GDB is just | |
3329 | a bit confused, not unusable. */ | |
3330 | #define err BPSTAT_WHAT_STOP_NOISY | |
3331 | ||
3332 | /* Given an old action and a class, come up with a new action. */ | |
3333 | /* One interesting property of this table is that wp_silent is the same | |
3334 | as bp_silent and wp_noisy is the same as bp_noisy. That is because | |
3335 | after stopping, the check for whether to step over a breakpoint | |
3336 | (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without | |
53a5351d JM |
3337 | reference to how we stopped. We retain separate wp_silent and |
3338 | bp_silent codes in case we want to change that someday. | |
43ff13b4 JM |
3339 | |
3340 | Another possibly interesting property of this table is that | |
3341 | there's a partial ordering, priority-like, of the actions. Once | |
3342 | you've decided that some action is appropriate, you'll never go | |
3343 | back and decide something of a lower priority is better. The | |
3344 | ordering is: | |
3345 | ||
d81191fc JB |
3346 | kc < clr sgl shl slr sn sr ss |
3347 | sgl < shl slr sn sr ss | |
3348 | slr < err shl sn sr ss | |
3349 | clr < err shl sn sr ss | |
3350 | ss < shl sn sr | |
3351 | sn < shl sr | |
3352 | shl < sr | |
4d5b2cd7 | 3353 | sr < |
c5aa993b | 3354 | |
43ff13b4 JM |
3355 | What I think this means is that we don't need a damned table |
3356 | here. If you just put the rows and columns in the right order, | |
3357 | it'd look awfully regular. We could simply walk the bpstat list | |
3358 | and choose the highest priority action we find, with a little | |
78b6a731 | 3359 | logic to handle the 'err' cases. */ |
c906108c SS |
3360 | |
3361 | /* step_resume entries: a step resume breakpoint overrides another | |
3362 | breakpoint of signal handling (see comment in wait_for_inferior | |
fcf70625 | 3363 | at where we set the step_resume breakpoint). */ |
c906108c SS |
3364 | |
3365 | static const enum bpstat_what_main_action | |
c5aa993b JM |
3366 | table[(int) class_last][(int) BPSTAT_WHAT_LAST] = |
3367 | { | |
3368 | /* old action */ | |
d81191fc | 3369 | /* kc ss sn sgl slr clr sr shl |
c5aa993b JM |
3370 | */ |
3371 | /*no_effect */ | |
d81191fc | 3372 | {kc, ss, sn, sgl, slr, clr, sr, shl}, |
c5aa993b | 3373 | /*wp_silent */ |
d81191fc | 3374 | {ss, ss, sn, ss, ss, ss, sr, shl}, |
c5aa993b | 3375 | /*wp_noisy */ |
d81191fc | 3376 | {sn, sn, sn, sn, sn, sn, sr, shl}, |
c5aa993b | 3377 | /*bp_nostop */ |
d81191fc | 3378 | {sgl, ss, sn, sgl, slr, slr, sr, shl}, |
c5aa993b | 3379 | /*bp_silent */ |
d81191fc | 3380 | {ss, ss, sn, ss, ss, ss, sr, shl}, |
c5aa993b | 3381 | /*bp_noisy */ |
d81191fc | 3382 | {sn, sn, sn, sn, sn, sn, sr, shl}, |
c5aa993b | 3383 | /*long_jump */ |
d81191fc | 3384 | {slr, ss, sn, slr, slr, err, sr, shl}, |
c5aa993b | 3385 | /*long_resume */ |
d81191fc | 3386 | {clr, ss, sn, err, err, err, sr, shl}, |
c5aa993b | 3387 | /*step_resume */ |
d81191fc | 3388 | {sr, sr, sr, sr, sr, sr, sr, sr}, |
c5aa993b | 3389 | /*shlib */ |
d81191fc | 3390 | {shl, shl, shl, shl, shl, shl, sr, shl} |
c5aa993b | 3391 | }; |
c906108c SS |
3392 | |
3393 | #undef kc | |
3394 | #undef ss | |
3395 | #undef sn | |
3396 | #undef sgl | |
3397 | #undef slr | |
3398 | #undef clr | |
c906108c SS |
3399 | #undef err |
3400 | #undef sr | |
3401 | #undef ts | |
3402 | #undef shl | |
c906108c SS |
3403 | enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING; |
3404 | struct bpstat_what retval; | |
3405 | ||
3406 | retval.call_dummy = 0; | |
3407 | for (; bs != NULL; bs = bs->next) | |
3408 | { | |
3409 | enum class bs_class = no_effect; | |
3410 | if (bs->breakpoint_at == NULL) | |
3411 | /* I suspect this can happen if it was a momentary breakpoint | |
3412 | which has since been deleted. */ | |
3413 | continue; | |
20874c92 VP |
3414 | if (bs->breakpoint_at->owner == NULL) |
3415 | bs_class = bp_nostop; | |
3416 | else | |
4f8d1dc6 | 3417 | switch (bs->breakpoint_at->owner->type) |
c906108c SS |
3418 | { |
3419 | case bp_none: | |
3420 | continue; | |
3421 | ||
3422 | case bp_breakpoint: | |
3423 | case bp_hardware_breakpoint: | |
3424 | case bp_until: | |
3425 | case bp_finish: | |
3426 | if (bs->stop) | |
3427 | { | |
3428 | if (bs->print) | |
3429 | bs_class = bp_noisy; | |
3430 | else | |
3431 | bs_class = bp_silent; | |
3432 | } | |
3433 | else | |
3434 | bs_class = bp_nostop; | |
3435 | break; | |
3436 | case bp_watchpoint: | |
3437 | case bp_hardware_watchpoint: | |
3438 | case bp_read_watchpoint: | |
3439 | case bp_access_watchpoint: | |
3440 | if (bs->stop) | |
3441 | { | |
3442 | if (bs->print) | |
3443 | bs_class = wp_noisy; | |
3444 | else | |
3445 | bs_class = wp_silent; | |
3446 | } | |
3447 | else | |
53a5351d JM |
3448 | /* There was a watchpoint, but we're not stopping. |
3449 | This requires no further action. */ | |
c906108c SS |
3450 | bs_class = no_effect; |
3451 | break; | |
3452 | case bp_longjmp: | |
3453 | bs_class = long_jump; | |
3454 | break; | |
3455 | case bp_longjmp_resume: | |
3456 | bs_class = long_resume; | |
3457 | break; | |
3458 | case bp_step_resume: | |
3459 | if (bs->stop) | |
3460 | { | |
3461 | bs_class = step_resume; | |
3462 | } | |
3463 | else | |
3464 | /* It is for the wrong frame. */ | |
3465 | bs_class = bp_nostop; | |
3466 | break; | |
c906108c SS |
3467 | case bp_watchpoint_scope: |
3468 | bs_class = bp_nostop; | |
3469 | break; | |
c5aa993b JM |
3470 | case bp_shlib_event: |
3471 | bs_class = shlib_event; | |
3472 | break; | |
c4093a6a | 3473 | case bp_thread_event: |
1900040c | 3474 | case bp_overlay_event: |
0fd8e87f | 3475 | case bp_longjmp_master: |
c4093a6a JM |
3476 | bs_class = bp_nostop; |
3477 | break; | |
ce78b96d | 3478 | case bp_catchpoint: |
c5aa993b JM |
3479 | if (bs->stop) |
3480 | { | |
3481 | if (bs->print) | |
3482 | bs_class = bp_noisy; | |
3483 | else | |
3484 | bs_class = bp_silent; | |
3485 | } | |
3486 | else | |
53a5351d JM |
3487 | /* There was a catchpoint, but we're not stopping. |
3488 | This requires no further action. */ | |
c5aa993b JM |
3489 | bs_class = no_effect; |
3490 | break; | |
c906108c | 3491 | case bp_call_dummy: |
53a5351d JM |
3492 | /* Make sure the action is stop (silent or noisy), |
3493 | so infrun.c pops the dummy frame. */ | |
c906108c SS |
3494 | bs_class = bp_silent; |
3495 | retval.call_dummy = 1; | |
3496 | break; | |
1042e4c0 SS |
3497 | case bp_tracepoint: |
3498 | /* Tracepoint hits should not be reported back to GDB, and | |
3499 | if one got through somehow, it should have been filtered | |
3500 | out already. */ | |
3501 | internal_error (__FILE__, __LINE__, | |
3502 | _("bpstat_what: bp_tracepoint encountered")); | |
3503 | break; | |
c906108c | 3504 | } |
c5aa993b | 3505 | current_action = table[(int) bs_class][(int) current_action]; |
c906108c SS |
3506 | } |
3507 | retval.main_action = current_action; | |
3508 | return retval; | |
3509 | } | |
3510 | ||
3511 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
3512 | without hardware support). This isn't related to a specific bpstat, | |
3513 | just to things like whether watchpoints are set. */ | |
3514 | ||
c5aa993b | 3515 | int |
fba45db2 | 3516 | bpstat_should_step (void) |
c906108c SS |
3517 | { |
3518 | struct breakpoint *b; | |
3519 | ALL_BREAKPOINTS (b) | |
717a8278 | 3520 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 3521 | return 1; |
c906108c SS |
3522 | return 0; |
3523 | } | |
3524 | ||
c906108c | 3525 | \f |
c5aa993b | 3526 | |
0d381245 VP |
3527 | static void print_breakpoint_location (struct breakpoint *b, |
3528 | struct bp_location *loc, | |
3529 | char *wrap_indent, | |
3530 | struct ui_stream *stb) | |
3531 | { | |
3532 | if (b->source_file) | |
3533 | { | |
3534 | struct symbol *sym | |
3535 | = find_pc_sect_function (loc->address, loc->section); | |
3536 | if (sym) | |
3537 | { | |
3538 | ui_out_text (uiout, "in "); | |
3539 | ui_out_field_string (uiout, "func", | |
3540 | SYMBOL_PRINT_NAME (sym)); | |
3541 | ui_out_wrap_hint (uiout, wrap_indent); | |
3542 | ui_out_text (uiout, " at "); | |
3543 | } | |
3544 | ui_out_field_string (uiout, "file", b->source_file); | |
3545 | ui_out_text (uiout, ":"); | |
3546 | ||
3547 | if (ui_out_is_mi_like_p (uiout)) | |
3548 | { | |
3549 | struct symtab_and_line sal = find_pc_line (loc->address, 0); | |
3550 | char *fullname = symtab_to_fullname (sal.symtab); | |
3551 | ||
3552 | if (fullname) | |
3553 | ui_out_field_string (uiout, "fullname", fullname); | |
3554 | } | |
3555 | ||
3556 | ui_out_field_int (uiout, "line", b->line_number); | |
3557 | } | |
3558 | else if (!b->loc) | |
3559 | { | |
3560 | ui_out_field_string (uiout, "pending", b->addr_string); | |
3561 | } | |
3562 | else | |
3563 | { | |
3564 | print_address_symbolic (loc->address, stb->stream, demangle, ""); | |
3565 | ui_out_field_stream (uiout, "at", stb); | |
3566 | } | |
3567 | } | |
3568 | ||
c4093a6a | 3569 | /* Print B to gdb_stdout. */ |
c906108c | 3570 | static void |
0d381245 VP |
3571 | print_one_breakpoint_location (struct breakpoint *b, |
3572 | struct bp_location *loc, | |
3573 | int loc_number, | |
a6d9a66e UW |
3574 | struct bp_location **last_loc, |
3575 | int print_address_bits) | |
c906108c | 3576 | { |
52f0bd74 AC |
3577 | struct command_line *l; |
3578 | struct symbol *sym; | |
c4093a6a JM |
3579 | struct ep_type_description |
3580 | { | |
3581 | enum bptype type; | |
3582 | char *description; | |
3583 | }; | |
3584 | static struct ep_type_description bptypes[] = | |
c906108c | 3585 | { |
c5aa993b JM |
3586 | {bp_none, "?deleted?"}, |
3587 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 3588 | {bp_hardware_breakpoint, "hw breakpoint"}, |
c5aa993b JM |
3589 | {bp_until, "until"}, |
3590 | {bp_finish, "finish"}, | |
3591 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 3592 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
3593 | {bp_read_watchpoint, "read watchpoint"}, |
3594 | {bp_access_watchpoint, "acc watchpoint"}, | |
3595 | {bp_longjmp, "longjmp"}, | |
3596 | {bp_longjmp_resume, "longjmp resume"}, | |
3597 | {bp_step_resume, "step resume"}, | |
c5aa993b JM |
3598 | {bp_watchpoint_scope, "watchpoint scope"}, |
3599 | {bp_call_dummy, "call dummy"}, | |
3600 | {bp_shlib_event, "shlib events"}, | |
c4093a6a | 3601 | {bp_thread_event, "thread events"}, |
1900040c | 3602 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 3603 | {bp_longjmp_master, "longjmp master"}, |
ce78b96d | 3604 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 3605 | {bp_tracepoint, "tracepoint"}, |
c5aa993b | 3606 | }; |
c4093a6a | 3607 | |
c2c6d25f | 3608 | static char bpenables[] = "nynny"; |
c906108c | 3609 | char wrap_indent[80]; |
8b93c638 JM |
3610 | struct ui_stream *stb = ui_out_stream_new (uiout); |
3611 | struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb); | |
3b31d625 | 3612 | struct cleanup *bkpt_chain; |
c906108c | 3613 | |
0d381245 VP |
3614 | int header_of_multiple = 0; |
3615 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
3616 | struct value_print_options opts; |
3617 | ||
3618 | get_user_print_options (&opts); | |
0d381245 VP |
3619 | |
3620 | gdb_assert (!loc || loc_number != 0); | |
3621 | /* See comment in print_one_breakpoint concerning | |
3622 | treatment of breakpoints with single disabled | |
3623 | location. */ | |
3624 | if (loc == NULL | |
3625 | && (b->loc != NULL | |
3626 | && (b->loc->next != NULL || !b->loc->enabled))) | |
3627 | header_of_multiple = 1; | |
3628 | if (loc == NULL) | |
3629 | loc = b->loc; | |
3630 | ||
c4093a6a | 3631 | annotate_record (); |
3b31d625 | 3632 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); |
c4093a6a JM |
3633 | |
3634 | /* 1 */ | |
3635 | annotate_field (0); | |
0d381245 VP |
3636 | if (part_of_multiple) |
3637 | { | |
3638 | char *formatted; | |
0c6773c1 | 3639 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
0d381245 VP |
3640 | ui_out_field_string (uiout, "number", formatted); |
3641 | xfree (formatted); | |
3642 | } | |
3643 | else | |
3644 | { | |
3645 | ui_out_field_int (uiout, "number", b->number); | |
3646 | } | |
c4093a6a JM |
3647 | |
3648 | /* 2 */ | |
3649 | annotate_field (1); | |
0d381245 VP |
3650 | if (part_of_multiple) |
3651 | ui_out_field_skip (uiout, "type"); | |
3652 | else | |
3653 | { | |
3654 | if (((int) b->type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
3655 | || ((int) b->type != bptypes[(int) b->type].type)) | |
3656 | internal_error (__FILE__, __LINE__, | |
3657 | _("bptypes table does not describe type #%d."), | |
3658 | (int) b->type); | |
3659 | ui_out_field_string (uiout, "type", bptypes[(int) b->type].description); | |
3660 | } | |
c4093a6a JM |
3661 | |
3662 | /* 3 */ | |
3663 | annotate_field (2); | |
0d381245 VP |
3664 | if (part_of_multiple) |
3665 | ui_out_field_skip (uiout, "disp"); | |
3666 | else | |
2cec12e5 | 3667 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
0d381245 | 3668 | |
c4093a6a JM |
3669 | |
3670 | /* 4 */ | |
3671 | annotate_field (3); | |
0d381245 | 3672 | if (part_of_multiple) |
54e52265 | 3673 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
0d381245 | 3674 | else |
54e52265 VP |
3675 | ui_out_field_fmt (uiout, "enabled", "%c", |
3676 | bpenables[(int) b->enable_state]); | |
3677 | ui_out_spaces (uiout, 2); | |
0d381245 | 3678 | |
c4093a6a JM |
3679 | |
3680 | /* 5 and 6 */ | |
3681 | strcpy (wrap_indent, " "); | |
79a45b7d | 3682 | if (opts.addressprint) |
75ac9d7b | 3683 | { |
a6d9a66e | 3684 | if (print_address_bits <= 32) |
75ac9d7b MS |
3685 | strcat (wrap_indent, " "); |
3686 | else | |
3687 | strcat (wrap_indent, " "); | |
3688 | } | |
c906108c | 3689 | |
3086aeae | 3690 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 VP |
3691 | { |
3692 | /* Although the print_one can possibly print | |
3693 | all locations, calling it here is not likely | |
3694 | to get any nice result. So, make sure there's | |
3695 | just one location. */ | |
3696 | gdb_assert (b->loc == NULL || b->loc->next == NULL); | |
a6d9a66e | 3697 | b->ops->print_one (b, last_loc); |
0d381245 | 3698 | } |
3086aeae DJ |
3699 | else |
3700 | switch (b->type) | |
3701 | { | |
3702 | case bp_none: | |
3703 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 3704 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 3705 | break; |
c906108c | 3706 | |
3086aeae DJ |
3707 | case bp_watchpoint: |
3708 | case bp_hardware_watchpoint: | |
3709 | case bp_read_watchpoint: | |
3710 | case bp_access_watchpoint: | |
3711 | /* Field 4, the address, is omitted (which makes the columns | |
3712 | not line up too nicely with the headers, but the effect | |
3713 | is relatively readable). */ | |
79a45b7d | 3714 | if (opts.addressprint) |
3086aeae DJ |
3715 | ui_out_field_skip (uiout, "addr"); |
3716 | annotate_field (5); | |
fa8a61dc | 3717 | ui_out_field_string (uiout, "what", b->exp_string); |
3086aeae DJ |
3718 | break; |
3719 | ||
3086aeae DJ |
3720 | case bp_breakpoint: |
3721 | case bp_hardware_breakpoint: | |
3722 | case bp_until: | |
3723 | case bp_finish: | |
3724 | case bp_longjmp: | |
3725 | case bp_longjmp_resume: | |
3726 | case bp_step_resume: | |
3086aeae DJ |
3727 | case bp_watchpoint_scope: |
3728 | case bp_call_dummy: | |
3729 | case bp_shlib_event: | |
3730 | case bp_thread_event: | |
3731 | case bp_overlay_event: | |
0fd8e87f | 3732 | case bp_longjmp_master: |
1042e4c0 | 3733 | case bp_tracepoint: |
79a45b7d | 3734 | if (opts.addressprint) |
3086aeae DJ |
3735 | { |
3736 | annotate_field (4); | |
54e52265 | 3737 | if (header_of_multiple) |
0d381245 | 3738 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
e9bbd7c5 | 3739 | else if (b->loc == NULL || loc->shlib_disabled) |
54e52265 | 3740 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
0101ce28 | 3741 | else |
5af949e3 UW |
3742 | ui_out_field_core_addr (uiout, "addr", |
3743 | loc->gdbarch, loc->address); | |
3086aeae DJ |
3744 | } |
3745 | annotate_field (5); | |
0d381245 VP |
3746 | if (!header_of_multiple) |
3747 | print_breakpoint_location (b, loc, wrap_indent, stb); | |
3748 | if (b->loc) | |
a6d9a66e | 3749 | *last_loc = b->loc; |
3086aeae DJ |
3750 | break; |
3751 | } | |
c906108c | 3752 | |
4a306c9a | 3753 | if (!part_of_multiple) |
c4093a6a | 3754 | { |
4a306c9a JB |
3755 | if (b->thread != -1) |
3756 | { | |
3757 | /* FIXME: This seems to be redundant and lost here; see the | |
3758 | "stop only in" line a little further down. */ | |
3759 | ui_out_text (uiout, " thread "); | |
3760 | ui_out_field_int (uiout, "thread", b->thread); | |
3761 | } | |
3762 | else if (b->task != 0) | |
3763 | { | |
3764 | ui_out_text (uiout, " task "); | |
3765 | ui_out_field_int (uiout, "task", b->task); | |
3766 | } | |
c4093a6a JM |
3767 | } |
3768 | ||
8b93c638 | 3769 | ui_out_text (uiout, "\n"); |
c4093a6a | 3770 | |
0d381245 | 3771 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
3772 | { |
3773 | annotate_field (6); | |
8b93c638 | 3774 | ui_out_text (uiout, "\tstop only in stack frame at "); |
818dd999 AC |
3775 | /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside |
3776 | the frame ID. */ | |
5af949e3 UW |
3777 | ui_out_field_core_addr (uiout, "frame", |
3778 | b->gdbarch, b->frame_id.stack_addr); | |
8b93c638 | 3779 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
3780 | } |
3781 | ||
0d381245 | 3782 | if (!part_of_multiple && b->cond_string && !ada_exception_catchpoint_p (b)) |
c4093a6a | 3783 | { |
f7f9143b JB |
3784 | /* We do not print the condition for Ada exception catchpoints |
3785 | because the condition is an internal implementation detail | |
3786 | that we do not want to expose to the user. */ | |
c4093a6a | 3787 | annotate_field (7); |
1042e4c0 SS |
3788 | if (b->type == bp_tracepoint) |
3789 | ui_out_text (uiout, "\ttrace only if "); | |
3790 | else | |
3791 | ui_out_text (uiout, "\tstop only if "); | |
0101ce28 JJ |
3792 | ui_out_field_string (uiout, "cond", b->cond_string); |
3793 | ui_out_text (uiout, "\n"); | |
3794 | } | |
3795 | ||
0d381245 | 3796 | if (!part_of_multiple && b->thread != -1) |
c4093a6a JM |
3797 | { |
3798 | /* FIXME should make an annotation for this */ | |
8b93c638 JM |
3799 | ui_out_text (uiout, "\tstop only in thread "); |
3800 | ui_out_field_int (uiout, "thread", b->thread); | |
3801 | ui_out_text (uiout, "\n"); | |
c4093a6a JM |
3802 | } |
3803 | ||
63c715c6 | 3804 | if (!part_of_multiple && b->hit_count) |
c4093a6a JM |
3805 | { |
3806 | /* FIXME should make an annotation for this */ | |
8b93c638 JM |
3807 | if (ep_is_catchpoint (b)) |
3808 | ui_out_text (uiout, "\tcatchpoint"); | |
3809 | else | |
3810 | ui_out_text (uiout, "\tbreakpoint"); | |
3811 | ui_out_text (uiout, " already hit "); | |
3812 | ui_out_field_int (uiout, "times", b->hit_count); | |
3813 | if (b->hit_count == 1) | |
3814 | ui_out_text (uiout, " time\n"); | |
3815 | else | |
3816 | ui_out_text (uiout, " times\n"); | |
c4093a6a JM |
3817 | } |
3818 | ||
fb40c209 AC |
3819 | /* Output the count also if it is zero, but only if this is |
3820 | mi. FIXME: Should have a better test for this. */ | |
9dc5e2a9 | 3821 | if (ui_out_is_mi_like_p (uiout)) |
63c715c6 | 3822 | if (!part_of_multiple && b->hit_count == 0) |
fb40c209 | 3823 | ui_out_field_int (uiout, "times", b->hit_count); |
8b93c638 | 3824 | |
0d381245 | 3825 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
3826 | { |
3827 | annotate_field (8); | |
8b93c638 JM |
3828 | ui_out_text (uiout, "\tignore next "); |
3829 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
3830 | ui_out_text (uiout, " hits\n"); | |
c4093a6a | 3831 | } |
059fb39f PM |
3832 | |
3833 | l = b->commands; | |
3834 | if (!part_of_multiple && l) | |
c4093a6a | 3835 | { |
3b31d625 EZ |
3836 | struct cleanup *script_chain; |
3837 | ||
c4093a6a | 3838 | annotate_field (9); |
3b31d625 | 3839 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 3840 | print_command_lines (uiout, l, 4); |
3b31d625 | 3841 | do_cleanups (script_chain); |
c4093a6a | 3842 | } |
d24317b4 | 3843 | |
1042e4c0 SS |
3844 | if (!part_of_multiple && b->pass_count) |
3845 | { | |
3846 | annotate_field (10); | |
3847 | ui_out_text (uiout, "\tpass count "); | |
3848 | ui_out_field_int (uiout, "pass", b->pass_count); | |
3849 | ui_out_text (uiout, " \n"); | |
3850 | } | |
3851 | ||
3852 | if (!part_of_multiple && b->step_count) | |
3853 | { | |
3854 | annotate_field (11); | |
3855 | ui_out_text (uiout, "\tstep count "); | |
3856 | ui_out_field_int (uiout, "step", b->step_count); | |
3857 | ui_out_text (uiout, " \n"); | |
3858 | } | |
3859 | ||
3860 | if (!part_of_multiple && b->actions) | |
3861 | { | |
3862 | struct action_line *action; | |
3863 | annotate_field (12); | |
3864 | for (action = b->actions; action; action = action->next) | |
3865 | { | |
3866 | ui_out_text (uiout, " A\t"); | |
3867 | ui_out_text (uiout, action->action); | |
3868 | ui_out_text (uiout, "\n"); | |
3869 | } | |
3870 | } | |
3871 | ||
d24317b4 VP |
3872 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
3873 | { | |
3874 | if (b->addr_string) | |
3875 | ui_out_field_string (uiout, "original-location", b->addr_string); | |
3876 | else if (b->exp_string) | |
3877 | ui_out_field_string (uiout, "original-location", b->exp_string); | |
3878 | } | |
3879 | ||
3b31d625 | 3880 | do_cleanups (bkpt_chain); |
8b93c638 | 3881 | do_cleanups (old_chain); |
c4093a6a | 3882 | } |
c5aa993b | 3883 | |
0d381245 VP |
3884 | static void |
3885 | print_one_breakpoint (struct breakpoint *b, | |
a6d9a66e | 3886 | struct bp_location **last_loc, int print_address_bits) |
0d381245 | 3887 | { |
a6d9a66e | 3888 | print_one_breakpoint_location (b, NULL, 0, last_loc, print_address_bits); |
0d381245 VP |
3889 | |
3890 | /* If this breakpoint has custom print function, | |
3891 | it's already printed. Otherwise, print individual | |
3892 | locations, if any. */ | |
3893 | if (b->ops == NULL || b->ops->print_one == NULL) | |
3894 | { | |
3895 | /* If breakpoint has a single location that is | |
3896 | disabled, we print it as if it had | |
3897 | several locations, since otherwise it's hard to | |
3898 | represent "breakpoint enabled, location disabled" | |
a5606eee VP |
3899 | situation. |
3900 | Note that while hardware watchpoints have | |
3901 | several locations internally, that's no a property | |
3902 | exposed to user. */ | |
0d381245 | 3903 | if (b->loc |
a5606eee | 3904 | && !is_hardware_watchpoint (b) |
0d381245 | 3905 | && (b->loc->next || !b->loc->enabled) |
a5606eee | 3906 | && !ui_out_is_mi_like_p (uiout)) |
0d381245 VP |
3907 | { |
3908 | struct bp_location *loc; | |
3909 | int n = 1; | |
3910 | for (loc = b->loc; loc; loc = loc->next, ++n) | |
a6d9a66e UW |
3911 | print_one_breakpoint_location (b, loc, n, last_loc, |
3912 | print_address_bits); | |
0d381245 VP |
3913 | } |
3914 | } | |
3915 | } | |
3916 | ||
a6d9a66e UW |
3917 | static int |
3918 | breakpoint_address_bits (struct breakpoint *b) | |
3919 | { | |
3920 | int print_address_bits = 0; | |
3921 | struct bp_location *loc; | |
3922 | ||
3923 | for (loc = b->loc; loc; loc = loc->next) | |
3924 | { | |
3925 | int addr_bit = gdbarch_addr_bit (b->gdbarch); | |
3926 | if (addr_bit > print_address_bits) | |
3927 | print_address_bits = addr_bit; | |
3928 | } | |
3929 | ||
3930 | return print_address_bits; | |
3931 | } | |
0d381245 | 3932 | |
c4093a6a JM |
3933 | struct captured_breakpoint_query_args |
3934 | { | |
3935 | int bnum; | |
3936 | }; | |
c5aa993b | 3937 | |
c4093a6a | 3938 | static int |
2b65245e | 3939 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a JM |
3940 | { |
3941 | struct captured_breakpoint_query_args *args = data; | |
52f0bd74 | 3942 | struct breakpoint *b; |
a6d9a66e | 3943 | struct bp_location *dummy_loc = NULL; |
c4093a6a JM |
3944 | ALL_BREAKPOINTS (b) |
3945 | { | |
3946 | if (args->bnum == b->number) | |
c5aa993b | 3947 | { |
a6d9a66e UW |
3948 | int print_address_bits = breakpoint_address_bits (b); |
3949 | print_one_breakpoint (b, &dummy_loc, print_address_bits); | |
c4093a6a | 3950 | return GDB_RC_OK; |
c5aa993b | 3951 | } |
c4093a6a JM |
3952 | } |
3953 | return GDB_RC_NONE; | |
3954 | } | |
c5aa993b | 3955 | |
c4093a6a | 3956 | enum gdb_rc |
ce43223b | 3957 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, char **error_message) |
c4093a6a JM |
3958 | { |
3959 | struct captured_breakpoint_query_args args; | |
3960 | args.bnum = bnum; | |
3961 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
3962 | an error. */ | |
b0b13bb4 DJ |
3963 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
3964 | error_message, RETURN_MASK_ALL) < 0) | |
3965 | return GDB_RC_FAIL; | |
3966 | else | |
3967 | return GDB_RC_OK; | |
c4093a6a | 3968 | } |
c5aa993b | 3969 | |
7f3b0473 AC |
3970 | /* Return non-zero if B is user settable (breakpoints, watchpoints, |
3971 | catchpoints, et.al.). */ | |
3972 | ||
3973 | static int | |
3974 | user_settable_breakpoint (const struct breakpoint *b) | |
3975 | { | |
3976 | return (b->type == bp_breakpoint | |
ce78b96d | 3977 | || b->type == bp_catchpoint |
7f3b0473 | 3978 | || b->type == bp_hardware_breakpoint |
1042e4c0 | 3979 | || b->type == bp_tracepoint |
7f3b0473 AC |
3980 | || b->type == bp_watchpoint |
3981 | || b->type == bp_read_watchpoint | |
3982 | || b->type == bp_access_watchpoint | |
3983 | || b->type == bp_hardware_watchpoint); | |
3984 | } | |
3985 | ||
3986 | /* Print information on user settable breakpoint (watchpoint, etc) | |
3987 | number BNUM. If BNUM is -1 print all user settable breakpoints. | |
3988 | If ALLFLAG is non-zero, include non- user settable breakpoints. */ | |
c906108c | 3989 | |
c4093a6a | 3990 | static void |
fba45db2 | 3991 | breakpoint_1 (int bnum, int allflag) |
c4093a6a | 3992 | { |
52f0bd74 | 3993 | struct breakpoint *b; |
a6d9a66e | 3994 | struct bp_location *last_loc = NULL; |
7f3b0473 | 3995 | int nr_printable_breakpoints; |
3b31d625 | 3996 | struct cleanup *bkpttbl_chain; |
79a45b7d | 3997 | struct value_print_options opts; |
a6d9a66e | 3998 | int print_address_bits = 0; |
c4093a6a | 3999 | |
79a45b7d TT |
4000 | get_user_print_options (&opts); |
4001 | ||
a6d9a66e UW |
4002 | /* Compute the number of rows in the table, as well as the |
4003 | size required for address fields. */ | |
7f3b0473 AC |
4004 | nr_printable_breakpoints = 0; |
4005 | ALL_BREAKPOINTS (b) | |
4006 | if (bnum == -1 | |
4007 | || bnum == b->number) | |
4008 | { | |
4009 | if (allflag || user_settable_breakpoint (b)) | |
a6d9a66e UW |
4010 | { |
4011 | int addr_bit = breakpoint_address_bits (b); | |
4012 | if (addr_bit > print_address_bits) | |
4013 | print_address_bits = addr_bit; | |
4014 | ||
4015 | nr_printable_breakpoints++; | |
4016 | } | |
7f3b0473 AC |
4017 | } |
4018 | ||
79a45b7d | 4019 | if (opts.addressprint) |
3b31d625 EZ |
4020 | bkpttbl_chain |
4021 | = make_cleanup_ui_out_table_begin_end (uiout, 6, nr_printable_breakpoints, | |
4022 | "BreakpointTable"); | |
8b93c638 | 4023 | else |
3b31d625 EZ |
4024 | bkpttbl_chain |
4025 | = make_cleanup_ui_out_table_begin_end (uiout, 5, nr_printable_breakpoints, | |
4026 | "BreakpointTable"); | |
8b93c638 | 4027 | |
7f3b0473 | 4028 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
4029 | annotate_breakpoints_headers (); |
4030 | if (nr_printable_breakpoints > 0) | |
4031 | annotate_field (0); | |
0d381245 | 4032 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
4033 | if (nr_printable_breakpoints > 0) |
4034 | annotate_field (1); | |
4035 | ui_out_table_header (uiout, 14, ui_left, "type", "Type"); /* 2 */ | |
4036 | if (nr_printable_breakpoints > 0) | |
4037 | annotate_field (2); | |
4038 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ | |
4039 | if (nr_printable_breakpoints > 0) | |
4040 | annotate_field (3); | |
54e52265 | 4041 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 4042 | if (opts.addressprint) |
7f3b0473 | 4043 | { |
d7faa9e7 AC |
4044 | if (nr_printable_breakpoints > 0) |
4045 | annotate_field (4); | |
a6d9a66e | 4046 | if (print_address_bits <= 32) |
b25959ec | 4047 | ui_out_table_header (uiout, 10, ui_left, "addr", "Address");/* 5 */ |
7f3b0473 | 4048 | else |
b25959ec | 4049 | ui_out_table_header (uiout, 18, ui_left, "addr", "Address");/* 5 */ |
7f3b0473 | 4050 | } |
d7faa9e7 AC |
4051 | if (nr_printable_breakpoints > 0) |
4052 | annotate_field (5); | |
4053 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
4054 | ui_out_table_body (uiout); | |
4055 | if (nr_printable_breakpoints > 0) | |
4056 | annotate_breakpoints_table (); | |
7f3b0473 | 4057 | |
c4093a6a JM |
4058 | ALL_BREAKPOINTS (b) |
4059 | if (bnum == -1 | |
4060 | || bnum == b->number) | |
4061 | { | |
4062 | /* We only print out user settable breakpoints unless the | |
4063 | allflag is set. */ | |
7f3b0473 | 4064 | if (allflag || user_settable_breakpoint (b)) |
a6d9a66e | 4065 | print_one_breakpoint (b, &last_loc, print_address_bits); |
c4093a6a JM |
4066 | } |
4067 | ||
3b31d625 | 4068 | do_cleanups (bkpttbl_chain); |
698384cd | 4069 | |
7f3b0473 | 4070 | if (nr_printable_breakpoints == 0) |
c906108c | 4071 | { |
8b93c638 JM |
4072 | if (bnum == -1) |
4073 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); | |
4074 | else | |
4075 | ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n", | |
4076 | bnum); | |
c906108c SS |
4077 | } |
4078 | else | |
c4093a6a | 4079 | { |
a6d9a66e UW |
4080 | if (last_loc && !server_command) |
4081 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 4082 | } |
c906108c | 4083 | |
c4093a6a JM |
4084 | /* FIXME? Should this be moved up so that it is only called when |
4085 | there have been breakpoints? */ | |
c906108c SS |
4086 | annotate_breakpoints_table_end (); |
4087 | } | |
4088 | ||
c906108c | 4089 | static void |
fba45db2 | 4090 | breakpoints_info (char *bnum_exp, int from_tty) |
c906108c SS |
4091 | { |
4092 | int bnum = -1; | |
4093 | ||
4094 | if (bnum_exp) | |
bb518678 | 4095 | bnum = parse_and_eval_long (bnum_exp); |
c906108c SS |
4096 | |
4097 | breakpoint_1 (bnum, 0); | |
4098 | } | |
4099 | ||
7a292a7a | 4100 | static void |
fba45db2 | 4101 | maintenance_info_breakpoints (char *bnum_exp, int from_tty) |
c906108c SS |
4102 | { |
4103 | int bnum = -1; | |
4104 | ||
4105 | if (bnum_exp) | |
bb518678 | 4106 | bnum = parse_and_eval_long (bnum_exp); |
c906108c SS |
4107 | |
4108 | breakpoint_1 (bnum, 1); | |
4109 | } | |
4110 | ||
0d381245 | 4111 | static int |
714835d5 UW |
4112 | breakpoint_has_pc (struct breakpoint *b, |
4113 | CORE_ADDR pc, struct obj_section *section) | |
0d381245 VP |
4114 | { |
4115 | struct bp_location *bl = b->loc; | |
4116 | for (; bl; bl = bl->next) | |
4117 | { | |
4118 | if (bl->address == pc | |
4119 | && (!overlay_debugging || bl->section == section)) | |
4120 | return 1; | |
4121 | } | |
4122 | return 0; | |
4123 | } | |
4124 | ||
c906108c SS |
4125 | /* Print a message describing any breakpoints set at PC. */ |
4126 | ||
4127 | static void | |
5af949e3 UW |
4128 | describe_other_breakpoints (struct gdbarch *gdbarch, CORE_ADDR pc, |
4129 | struct obj_section *section, int thread) | |
c906108c | 4130 | { |
52f0bd74 AC |
4131 | int others = 0; |
4132 | struct breakpoint *b; | |
c906108c SS |
4133 | |
4134 | ALL_BREAKPOINTS (b) | |
0d381245 | 4135 | others += breakpoint_has_pc (b, pc, section); |
c906108c SS |
4136 | if (others > 0) |
4137 | { | |
a3f17187 AC |
4138 | if (others == 1) |
4139 | printf_filtered (_("Note: breakpoint ")); | |
4140 | else /* if (others == ???) */ | |
4141 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 4142 | ALL_BREAKPOINTS (b) |
0d381245 VP |
4143 | if (breakpoint_has_pc (b, pc, section)) |
4144 | { | |
4145 | others--; | |
4146 | printf_filtered ("%d", b->number); | |
4147 | if (b->thread == -1 && thread != -1) | |
4148 | printf_filtered (" (all threads)"); | |
4149 | else if (b->thread != -1) | |
4150 | printf_filtered (" (thread %d)", b->thread); | |
4151 | printf_filtered ("%s%s ", | |
059fb39f | 4152 | ((b->enable_state == bp_disabled |
8bea4e01 UW |
4153 | || b->enable_state == bp_call_disabled |
4154 | || b->enable_state == bp_startup_disabled) | |
0d381245 VP |
4155 | ? " (disabled)" |
4156 | : b->enable_state == bp_permanent | |
4157 | ? " (permanent)" | |
4158 | : ""), | |
4159 | (others > 1) ? "," | |
4160 | : ((others == 1) ? " and" : "")); | |
4161 | } | |
a3f17187 | 4162 | printf_filtered (_("also set at pc ")); |
5af949e3 | 4163 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
4164 | printf_filtered (".\n"); |
4165 | } | |
4166 | } | |
4167 | \f | |
4168 | /* Set the default place to put a breakpoint | |
4169 | for the `break' command with no arguments. */ | |
4170 | ||
4171 | void | |
fba45db2 KB |
4172 | set_default_breakpoint (int valid, CORE_ADDR addr, struct symtab *symtab, |
4173 | int line) | |
c906108c SS |
4174 | { |
4175 | default_breakpoint_valid = valid; | |
4176 | default_breakpoint_address = addr; | |
4177 | default_breakpoint_symtab = symtab; | |
4178 | default_breakpoint_line = line; | |
4179 | } | |
4180 | ||
e4f237da KB |
4181 | /* Return true iff it is meaningful to use the address member of |
4182 | BPT. For some breakpoint types, the address member is irrelevant | |
4183 | and it makes no sense to attempt to compare it to other addresses | |
4184 | (or use it for any other purpose either). | |
4185 | ||
4186 | More specifically, each of the following breakpoint types will always | |
4187 | have a zero valued address and we don't want check_duplicates() to mark | |
4188 | breakpoints of any of these types to be a duplicate of an actual | |
4189 | breakpoint at address zero: | |
4190 | ||
4191 | bp_watchpoint | |
4192 | bp_hardware_watchpoint | |
4193 | bp_read_watchpoint | |
4194 | bp_access_watchpoint | |
fe798b75 | 4195 | bp_catchpoint */ |
e4f237da KB |
4196 | |
4197 | static int | |
4198 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
4199 | { | |
4200 | enum bptype type = bpt->type; | |
4201 | ||
4202 | return (type != bp_watchpoint | |
4203 | && type != bp_hardware_watchpoint | |
4204 | && type != bp_read_watchpoint | |
4205 | && type != bp_access_watchpoint | |
fe798b75 | 4206 | && type != bp_catchpoint); |
e4f237da KB |
4207 | } |
4208 | ||
9f60f21b | 4209 | /* Rescan breakpoints at the same address and section as BPT, |
c906108c | 4210 | marking the first one as "first" and any others as "duplicates". |
c2c6d25f | 4211 | This is so that the bpt instruction is only inserted once. |
9f60f21b JB |
4212 | If we have a permanent breakpoint at the same place as BPT, make |
4213 | that one the official one, and the rest as duplicates. */ | |
c906108c SS |
4214 | |
4215 | static void | |
714835d5 | 4216 | check_duplicates_for (CORE_ADDR address, struct obj_section *section) |
c906108c | 4217 | { |
075f6582 | 4218 | struct bp_location *b; |
52f0bd74 | 4219 | int count = 0; |
075f6582 | 4220 | struct bp_location *perm_bp = 0; |
c906108c | 4221 | |
075f6582 DJ |
4222 | ALL_BP_LOCATIONS (b) |
4223 | if (b->owner->enable_state != bp_disabled | |
075f6582 | 4224 | && b->owner->enable_state != bp_call_disabled |
8bea4e01 | 4225 | && b->owner->enable_state != bp_startup_disabled |
0d381245 VP |
4226 | && b->enabled |
4227 | && !b->shlib_disabled | |
075f6582 DJ |
4228 | && b->address == address /* address / overlay match */ |
4229 | && (!overlay_debugging || b->section == section) | |
4230 | && breakpoint_address_is_meaningful (b->owner)) | |
c5aa993b | 4231 | { |
c2c6d25f | 4232 | /* Have we found a permanent breakpoint? */ |
075f6582 | 4233 | if (b->owner->enable_state == bp_permanent) |
c2c6d25f JM |
4234 | { |
4235 | perm_bp = b; | |
4236 | break; | |
4237 | } | |
4238 | ||
c5aa993b | 4239 | count++; |
075f6582 | 4240 | b->duplicate = count > 1; |
c5aa993b | 4241 | } |
c2c6d25f JM |
4242 | |
4243 | /* If we found a permanent breakpoint at this address, go over the | |
aae64587 PA |
4244 | list again and declare all the other breakpoints there (except |
4245 | other permanent breakpoints) to be the duplicates. */ | |
c2c6d25f JM |
4246 | if (perm_bp) |
4247 | { | |
075f6582 | 4248 | perm_bp->duplicate = 0; |
c2c6d25f JM |
4249 | |
4250 | /* Permanent breakpoint should always be inserted. */ | |
075f6582 | 4251 | if (! perm_bp->inserted) |
8e65ff28 | 4252 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 AC |
4253 | _("allegedly permanent breakpoint is not " |
4254 | "actually inserted")); | |
c2c6d25f | 4255 | |
075f6582 | 4256 | ALL_BP_LOCATIONS (b) |
c2c6d25f JM |
4257 | if (b != perm_bp) |
4258 | { | |
aae64587 PA |
4259 | if (b->owner->enable_state != bp_permanent |
4260 | && b->owner->enable_state != bp_disabled | |
075f6582 | 4261 | && b->owner->enable_state != bp_call_disabled |
8bea4e01 | 4262 | && b->owner->enable_state != bp_startup_disabled |
0d381245 | 4263 | && b->enabled && !b->shlib_disabled |
075f6582 DJ |
4264 | && b->address == address /* address / overlay match */ |
4265 | && (!overlay_debugging || b->section == section) | |
4266 | && breakpoint_address_is_meaningful (b->owner)) | |
4267 | { | |
4268 | if (b->inserted) | |
4269 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 AC |
4270 | _("another breakpoint was inserted on top of " |
4271 | "a permanent breakpoint")); | |
075f6582 DJ |
4272 | |
4273 | b->duplicate = 1; | |
4274 | } | |
c2c6d25f JM |
4275 | } |
4276 | } | |
c906108c SS |
4277 | } |
4278 | ||
0d381245 VP |
4279 | static void |
4280 | check_duplicates (struct breakpoint *bpt) | |
4281 | { | |
4282 | struct bp_location *bl = bpt->loc; | |
4283 | ||
4284 | if (! breakpoint_address_is_meaningful (bpt)) | |
4285 | return; | |
4286 | ||
4287 | for (; bl; bl = bl->next) | |
4288 | check_duplicates_for (bl->address, bl->section); | |
4289 | } | |
4290 | ||
76897487 KB |
4291 | static void |
4292 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
4293 | int bnum, int have_bnum) | |
4294 | { | |
4295 | char astr1[40]; | |
4296 | char astr2[40]; | |
4297 | ||
bb599908 PH |
4298 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
4299 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 4300 | if (have_bnum) |
8a3fe4f8 | 4301 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
4302 | bnum, astr1, astr2); |
4303 | else | |
8a3fe4f8 | 4304 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
4305 | } |
4306 | ||
4307 | /* Adjust a breakpoint's address to account for architectural constraints | |
4308 | on breakpoint placement. Return the adjusted address. Note: Very | |
4309 | few targets require this kind of adjustment. For most targets, | |
4310 | this function is simply the identity function. */ | |
4311 | ||
4312 | static CORE_ADDR | |
a6d9a66e UW |
4313 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
4314 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 4315 | { |
a6d9a66e | 4316 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
4317 | { |
4318 | /* Very few targets need any kind of breakpoint adjustment. */ | |
4319 | return bpaddr; | |
4320 | } | |
88f7da05 KB |
4321 | else if (bptype == bp_watchpoint |
4322 | || bptype == bp_hardware_watchpoint | |
4323 | || bptype == bp_read_watchpoint | |
4324 | || bptype == bp_access_watchpoint | |
fe798b75 | 4325 | || bptype == bp_catchpoint) |
88f7da05 KB |
4326 | { |
4327 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
4328 | have their addresses modified. */ | |
4329 | return bpaddr; | |
4330 | } | |
76897487 KB |
4331 | else |
4332 | { | |
4333 | CORE_ADDR adjusted_bpaddr; | |
4334 | ||
4335 | /* Some targets have architectural constraints on the placement | |
4336 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 4337 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
4338 | |
4339 | /* An adjusted breakpoint address can significantly alter | |
4340 | a user's expectations. Print a warning if an adjustment | |
4341 | is required. */ | |
4342 | if (adjusted_bpaddr != bpaddr) | |
4343 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
4344 | ||
4345 | return adjusted_bpaddr; | |
4346 | } | |
4347 | } | |
4348 | ||
7cc221ef DJ |
4349 | /* Allocate a struct bp_location. */ |
4350 | ||
26bb91f3 | 4351 | static struct bp_location * |
39d61571 | 4352 | allocate_bp_location (struct breakpoint *bpt) |
7cc221ef DJ |
4353 | { |
4354 | struct bp_location *loc, *loc_p; | |
4355 | ||
4356 | loc = xmalloc (sizeof (struct bp_location)); | |
4357 | memset (loc, 0, sizeof (*loc)); | |
4358 | ||
e049a4b5 | 4359 | loc->owner = bpt; |
511a6cd4 | 4360 | loc->cond = NULL; |
0d381245 VP |
4361 | loc->shlib_disabled = 0; |
4362 | loc->enabled = 1; | |
e049a4b5 | 4363 | |
39d61571 | 4364 | switch (bpt->type) |
e049a4b5 DJ |
4365 | { |
4366 | case bp_breakpoint: | |
1042e4c0 | 4367 | case bp_tracepoint: |
e049a4b5 DJ |
4368 | case bp_until: |
4369 | case bp_finish: | |
4370 | case bp_longjmp: | |
4371 | case bp_longjmp_resume: | |
4372 | case bp_step_resume: | |
e049a4b5 DJ |
4373 | case bp_watchpoint_scope: |
4374 | case bp_call_dummy: | |
4375 | case bp_shlib_event: | |
4376 | case bp_thread_event: | |
4377 | case bp_overlay_event: | |
0fd8e87f | 4378 | case bp_longjmp_master: |
e049a4b5 DJ |
4379 | loc->loc_type = bp_loc_software_breakpoint; |
4380 | break; | |
4381 | case bp_hardware_breakpoint: | |
4382 | loc->loc_type = bp_loc_hardware_breakpoint; | |
4383 | break; | |
4384 | case bp_hardware_watchpoint: | |
4385 | case bp_read_watchpoint: | |
4386 | case bp_access_watchpoint: | |
4387 | loc->loc_type = bp_loc_hardware_watchpoint; | |
4388 | break; | |
4389 | case bp_watchpoint: | |
ce78b96d | 4390 | case bp_catchpoint: |
e049a4b5 DJ |
4391 | loc->loc_type = bp_loc_other; |
4392 | break; | |
4393 | default: | |
e2e0b3e5 | 4394 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
4395 | } |
4396 | ||
7cc221ef DJ |
4397 | return loc; |
4398 | } | |
4399 | ||
fe3f5fa8 VP |
4400 | static void free_bp_location (struct bp_location *loc) |
4401 | { | |
4402 | if (loc->cond) | |
4403 | xfree (loc->cond); | |
74960c60 VP |
4404 | |
4405 | if (loc->function_name) | |
4406 | xfree (loc->function_name); | |
4407 | ||
fe3f5fa8 VP |
4408 | xfree (loc); |
4409 | } | |
4410 | ||
0d381245 VP |
4411 | /* Helper to set_raw_breakpoint below. Creates a breakpoint |
4412 | that has type BPTYPE and has no locations as yet. */ | |
63c252f8 | 4413 | /* This function is used in gdbtk sources and thus can not be made static. */ |
c906108c | 4414 | |
c40e75cd | 4415 | static struct breakpoint * |
a6d9a66e UW |
4416 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, |
4417 | enum bptype bptype) | |
c906108c | 4418 | { |
52f0bd74 | 4419 | struct breakpoint *b, *b1; |
c906108c SS |
4420 | |
4421 | b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint)); | |
4422 | memset (b, 0, sizeof (*b)); | |
2219d63c | 4423 | |
4d28f7a8 | 4424 | b->type = bptype; |
a6d9a66e | 4425 | b->gdbarch = gdbarch; |
c906108c SS |
4426 | b->language = current_language->la_language; |
4427 | b->input_radix = input_radix; | |
4428 | b->thread = -1; | |
b5de0fa7 | 4429 | b->enable_state = bp_enabled; |
c906108c SS |
4430 | b->next = 0; |
4431 | b->silent = 0; | |
4432 | b->ignore_count = 0; | |
4433 | b->commands = NULL; | |
818dd999 | 4434 | b->frame_id = null_frame_id; |
3a3e9ee3 | 4435 | b->forked_inferior_pid = null_ptid; |
c906108c | 4436 | b->exec_pathname = NULL; |
3086aeae | 4437 | b->ops = NULL; |
0d381245 | 4438 | b->condition_not_parsed = 0; |
c906108c SS |
4439 | |
4440 | /* Add this breakpoint to the end of the chain | |
4441 | so that a list of breakpoints will come out in order | |
4442 | of increasing numbers. */ | |
4443 | ||
4444 | b1 = breakpoint_chain; | |
4445 | if (b1 == 0) | |
4446 | breakpoint_chain = b; | |
4447 | else | |
4448 | { | |
4449 | while (b1->next) | |
4450 | b1 = b1->next; | |
4451 | b1->next = b; | |
4452 | } | |
0d381245 VP |
4453 | return b; |
4454 | } | |
4455 | ||
4456 | /* Initialize loc->function_name. */ | |
4457 | static void | |
4458 | set_breakpoint_location_function (struct bp_location *loc) | |
4459 | { | |
4460 | if (loc->owner->type == bp_breakpoint | |
1042e4c0 SS |
4461 | || loc->owner->type == bp_hardware_breakpoint |
4462 | || loc->owner->type == bp_tracepoint) | |
0d381245 VP |
4463 | { |
4464 | find_pc_partial_function (loc->address, &(loc->function_name), | |
4465 | NULL, NULL); | |
4466 | if (loc->function_name) | |
4467 | loc->function_name = xstrdup (loc->function_name); | |
4468 | } | |
4469 | } | |
4470 | ||
a6d9a66e UW |
4471 | /* Attempt to determine architecture of location identified by SAL. */ |
4472 | static struct gdbarch * | |
4473 | get_sal_arch (struct symtab_and_line sal) | |
4474 | { | |
4475 | if (sal.section) | |
4476 | return get_objfile_arch (sal.section->objfile); | |
4477 | if (sal.symtab) | |
4478 | return get_objfile_arch (sal.symtab->objfile); | |
4479 | ||
4480 | return NULL; | |
4481 | } | |
4482 | ||
0d381245 VP |
4483 | /* set_raw_breakpoint is a low level routine for allocating and |
4484 | partially initializing a breakpoint of type BPTYPE. The newly | |
4485 | created breakpoint's address, section, source file name, and line | |
4486 | number are provided by SAL. The newly created and partially | |
4487 | initialized breakpoint is added to the breakpoint chain and | |
4488 | is also returned as the value of this function. | |
4489 | ||
4490 | It is expected that the caller will complete the initialization of | |
4491 | the newly created breakpoint struct as well as output any status | |
4492 | information regarding the creation of a new breakpoint. In | |
4493 | particular, set_raw_breakpoint does NOT set the breakpoint | |
4494 | number! Care should be taken to not allow an error to occur | |
4495 | prior to completing the initialization of the breakpoint. If this | |
4496 | should happen, a bogus breakpoint will be left on the chain. */ | |
4497 | ||
63c252f8 | 4498 | struct breakpoint * |
a6d9a66e UW |
4499 | set_raw_breakpoint (struct gdbarch *gdbarch, |
4500 | struct symtab_and_line sal, enum bptype bptype) | |
0d381245 | 4501 | { |
a6d9a66e | 4502 | struct breakpoint *b = set_raw_breakpoint_without_location (gdbarch, bptype); |
0d381245 | 4503 | CORE_ADDR adjusted_address; |
a6d9a66e UW |
4504 | struct gdbarch *loc_gdbarch; |
4505 | ||
4506 | loc_gdbarch = get_sal_arch (sal); | |
4507 | if (!loc_gdbarch) | |
4508 | loc_gdbarch = b->gdbarch; | |
0d381245 VP |
4509 | |
4510 | /* Adjust the breakpoint's address prior to allocating a location. | |
4511 | Once we call allocate_bp_location(), that mostly uninitialized | |
4512 | location will be placed on the location chain. Adjustment of the | |
8defab1a | 4513 | breakpoint may cause target_read_memory() to be called and we do |
0d381245 VP |
4514 | not want its scan of the location chain to find a breakpoint and |
4515 | location that's only been partially initialized. */ | |
a6d9a66e | 4516 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, sal.pc, b->type); |
0d381245 | 4517 | |
39d61571 | 4518 | b->loc = allocate_bp_location (b); |
a6d9a66e | 4519 | b->loc->gdbarch = loc_gdbarch; |
0d381245 VP |
4520 | b->loc->requested_address = sal.pc; |
4521 | b->loc->address = adjusted_address; | |
4522 | ||
4523 | if (sal.symtab == NULL) | |
4524 | b->source_file = NULL; | |
4525 | else | |
1b36a34b | 4526 | b->source_file = xstrdup (sal.symtab->filename); |
0d381245 VP |
4527 | b->loc->section = sal.section; |
4528 | b->line_number = sal.line; | |
4529 | ||
4530 | set_breakpoint_location_function (b->loc); | |
c906108c | 4531 | |
c906108c SS |
4532 | breakpoints_changed (); |
4533 | ||
4534 | return b; | |
4535 | } | |
4536 | ||
c2c6d25f JM |
4537 | |
4538 | /* Note that the breakpoint object B describes a permanent breakpoint | |
4539 | instruction, hard-wired into the inferior's code. */ | |
4540 | void | |
4541 | make_breakpoint_permanent (struct breakpoint *b) | |
4542 | { | |
0d381245 | 4543 | struct bp_location *bl; |
b5de0fa7 | 4544 | b->enable_state = bp_permanent; |
c2c6d25f | 4545 | |
0d381245 VP |
4546 | /* By definition, permanent breakpoints are already present in the code. |
4547 | Mark all locations as inserted. For now, make_breakpoint_permanent | |
4548 | is called in just one place, so it's hard to say if it's reasonable | |
4549 | to have permanent breakpoint with multiple locations or not, | |
4550 | but it's easy to implmement. */ | |
4551 | for (bl = b->loc; bl; bl = bl->next) | |
4552 | bl->inserted = 1; | |
c2c6d25f JM |
4553 | } |
4554 | ||
53a5351d | 4555 | /* Call this routine when stepping and nexting to enable a breakpoint |
0fd8e87f | 4556 | if we do a longjmp() in THREAD. When we hit that breakpoint, call |
c906108c SS |
4557 | set_longjmp_resume_breakpoint() to figure out where we are going. */ |
4558 | ||
4559 | void | |
0fd8e87f | 4560 | set_longjmp_breakpoint (int thread) |
c906108c | 4561 | { |
0fd8e87f UW |
4562 | struct breakpoint *b, *temp; |
4563 | ||
4564 | /* To avoid having to rescan all objfile symbols at every step, | |
4565 | we maintain a list of continually-inserted but always disabled | |
4566 | longjmp "master" breakpoints. Here, we simply create momentary | |
4567 | clones of those and enable them for the requested thread. */ | |
4568 | ALL_BREAKPOINTS_SAFE (b, temp) | |
4569 | if (b->type == bp_longjmp_master) | |
4570 | { | |
4571 | struct breakpoint *clone = clone_momentary_breakpoint (b); | |
4572 | clone->type = bp_longjmp; | |
4573 | clone->thread = thread; | |
4574 | } | |
c906108c SS |
4575 | } |
4576 | ||
611c83ae | 4577 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 4578 | void |
611c83ae | 4579 | delete_longjmp_breakpoint (int thread) |
c906108c | 4580 | { |
611c83ae | 4581 | struct breakpoint *b, *temp; |
c906108c | 4582 | |
611c83ae PA |
4583 | ALL_BREAKPOINTS_SAFE (b, temp) |
4584 | if (b->type == bp_longjmp) | |
4585 | { | |
4586 | if (b->thread == thread) | |
4587 | delete_breakpoint (b); | |
4588 | } | |
c906108c SS |
4589 | } |
4590 | ||
1900040c MS |
4591 | void |
4592 | enable_overlay_breakpoints (void) | |
4593 | { | |
52f0bd74 | 4594 | struct breakpoint *b; |
1900040c MS |
4595 | |
4596 | ALL_BREAKPOINTS (b) | |
4597 | if (b->type == bp_overlay_event) | |
4598 | { | |
4599 | b->enable_state = bp_enabled; | |
b60e7edf | 4600 | update_global_location_list (1); |
c02f5703 | 4601 | overlay_events_enabled = 1; |
1900040c MS |
4602 | } |
4603 | } | |
4604 | ||
4605 | void | |
4606 | disable_overlay_breakpoints (void) | |
4607 | { | |
52f0bd74 | 4608 | struct breakpoint *b; |
1900040c MS |
4609 | |
4610 | ALL_BREAKPOINTS (b) | |
4611 | if (b->type == bp_overlay_event) | |
4612 | { | |
4613 | b->enable_state = bp_disabled; | |
b60e7edf | 4614 | update_global_location_list (0); |
c02f5703 | 4615 | overlay_events_enabled = 0; |
1900040c MS |
4616 | } |
4617 | } | |
4618 | ||
c4093a6a | 4619 | struct breakpoint * |
a6d9a66e | 4620 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
4621 | { |
4622 | struct breakpoint *b; | |
c4093a6a | 4623 | |
a6d9a66e | 4624 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event); |
c4093a6a | 4625 | |
b5de0fa7 | 4626 | b->enable_state = bp_enabled; |
c4093a6a | 4627 | /* addr_string has to be used or breakpoint_re_set will delete me. */ |
5af949e3 UW |
4628 | b->addr_string |
4629 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
c4093a6a | 4630 | |
b60e7edf | 4631 | update_global_location_list_nothrow (1); |
74960c60 | 4632 | |
c4093a6a JM |
4633 | return b; |
4634 | } | |
4635 | ||
4636 | void | |
4637 | remove_thread_event_breakpoints (void) | |
4638 | { | |
4639 | struct breakpoint *b, *temp; | |
4640 | ||
4641 | ALL_BREAKPOINTS_SAFE (b, temp) | |
4642 | if (b->type == bp_thread_event) | |
4643 | delete_breakpoint (b); | |
4644 | } | |
4645 | ||
0101ce28 JJ |
4646 | struct captured_parse_breakpoint_args |
4647 | { | |
4648 | char **arg_p; | |
4649 | struct symtabs_and_lines *sals_p; | |
4650 | char ***addr_string_p; | |
4651 | int *not_found_ptr; | |
4652 | }; | |
4653 | ||
4654 | struct lang_and_radix | |
4655 | { | |
4656 | enum language lang; | |
4657 | int radix; | |
4658 | }; | |
4659 | ||
0101ce28 | 4660 | |
cae688ec JJ |
4661 | void |
4662 | remove_solib_event_breakpoints (void) | |
4663 | { | |
4664 | struct breakpoint *b, *temp; | |
4665 | ||
4666 | ALL_BREAKPOINTS_SAFE (b, temp) | |
4667 | if (b->type == bp_shlib_event) | |
4668 | delete_breakpoint (b); | |
4669 | } | |
4670 | ||
4671 | struct breakpoint * | |
a6d9a66e | 4672 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
cae688ec JJ |
4673 | { |
4674 | struct breakpoint *b; | |
4675 | ||
a6d9a66e | 4676 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event); |
b60e7edf | 4677 | update_global_location_list_nothrow (1); |
cae688ec JJ |
4678 | return b; |
4679 | } | |
4680 | ||
4681 | /* Disable any breakpoints that are on code in shared libraries. Only | |
4682 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
4683 | ||
4684 | void | |
cb851954 | 4685 | disable_breakpoints_in_shlibs (void) |
cae688ec | 4686 | { |
0d381245 | 4687 | struct bp_location *loc; |
cae688ec | 4688 | |
0d381245 | 4689 | ALL_BP_LOCATIONS (loc) |
cae688ec | 4690 | { |
0d381245 VP |
4691 | struct breakpoint *b = loc->owner; |
4692 | /* We apply the check to all breakpoints, including disabled | |
4693 | for those with loc->duplicate set. This is so that when breakpoint | |
4694 | becomes enabled, or the duplicate is removed, gdb will try to insert | |
4695 | all breakpoints. If we don't set shlib_disabled here, we'll try | |
4696 | to insert those breakpoints and fail. */ | |
1042e4c0 SS |
4697 | if (((b->type == bp_breakpoint) |
4698 | || (b->type == bp_hardware_breakpoint) | |
4699 | || (b->type == bp_tracepoint)) | |
0d381245 | 4700 | && !loc->shlib_disabled |
a77053c2 | 4701 | #ifdef PC_SOLIB |
0d381245 | 4702 | && PC_SOLIB (loc->address) |
a77053c2 | 4703 | #else |
f5c9a895 | 4704 | && solib_name_from_address (loc->address) |
a77053c2 MK |
4705 | #endif |
4706 | ) | |
0d381245 VP |
4707 | { |
4708 | loc->shlib_disabled = 1; | |
4709 | } | |
cae688ec JJ |
4710 | } |
4711 | } | |
4712 | ||
84acb35a JJ |
4713 | /* Disable any breakpoints that are in in an unloaded shared library. Only |
4714 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
4715 | ||
75149521 | 4716 | static void |
84acb35a JJ |
4717 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
4718 | { | |
0d381245 | 4719 | struct bp_location *loc; |
84acb35a JJ |
4720 | int disabled_shlib_breaks = 0; |
4721 | ||
c86cf029 VP |
4722 | /* SunOS a.out shared libraries are always mapped, so do not |
4723 | disable breakpoints; they will only be reported as unloaded | |
4724 | through clear_solib when GDB discards its shared library | |
4725 | list. See clear_solib for more information. */ | |
4726 | if (exec_bfd != NULL | |
4727 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) | |
4728 | return; | |
4729 | ||
0d381245 | 4730 | ALL_BP_LOCATIONS (loc) |
84acb35a | 4731 | { |
0d381245 VP |
4732 | struct breakpoint *b = loc->owner; |
4733 | if ((loc->loc_type == bp_loc_hardware_breakpoint | |
4734 | || loc->loc_type == bp_loc_software_breakpoint) | |
e2dd7057 PP |
4735 | && !loc->shlib_disabled |
4736 | && (b->type == bp_breakpoint || b->type == bp_hardware_breakpoint) | |
4737 | && solib_contains_address_p (solib, loc->address)) | |
84acb35a | 4738 | { |
e2dd7057 PP |
4739 | loc->shlib_disabled = 1; |
4740 | /* At this point, we cannot rely on remove_breakpoint | |
4741 | succeeding so we must mark the breakpoint as not inserted | |
4742 | to prevent future errors occurring in remove_breakpoints. */ | |
4743 | loc->inserted = 0; | |
4744 | if (!disabled_shlib_breaks) | |
4745 | { | |
4746 | target_terminal_ours_for_output (); | |
4747 | warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""), | |
4748 | solib->so_name); | |
84acb35a | 4749 | } |
e2dd7057 | 4750 | disabled_shlib_breaks = 1; |
84acb35a JJ |
4751 | } |
4752 | } | |
84acb35a JJ |
4753 | } |
4754 | ||
ce78b96d JB |
4755 | /* FORK & VFORK catchpoints. */ |
4756 | ||
4757 | /* Implement the "insert" breakpoint_ops method for fork catchpoints. */ | |
4758 | ||
c906108c | 4759 | static void |
ce78b96d JB |
4760 | insert_catch_fork (struct breakpoint *b) |
4761 | { | |
4762 | target_insert_fork_catchpoint (PIDGET (inferior_ptid)); | |
4763 | } | |
4764 | ||
4765 | /* Implement the "remove" breakpoint_ops method for fork catchpoints. */ | |
4766 | ||
4767 | static int | |
4768 | remove_catch_fork (struct breakpoint *b) | |
4769 | { | |
4770 | return target_remove_fork_catchpoint (PIDGET (inferior_ptid)); | |
4771 | } | |
4772 | ||
4773 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
4774 | catchpoints. */ | |
4775 | ||
4776 | static int | |
4777 | breakpoint_hit_catch_fork (struct breakpoint *b) | |
4778 | { | |
4779 | return inferior_has_forked (inferior_ptid, &b->forked_inferior_pid); | |
4780 | } | |
4781 | ||
4782 | /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */ | |
4783 | ||
4784 | static enum print_stop_action | |
4785 | print_it_catch_fork (struct breakpoint *b) | |
4786 | { | |
4787 | annotate_catchpoint (b->number); | |
4788 | printf_filtered (_("\nCatchpoint %d (forked process %d), "), | |
4789 | b->number, ptid_get_pid (b->forked_inferior_pid)); | |
4790 | return PRINT_SRC_AND_LOC; | |
4791 | } | |
4792 | ||
4793 | /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */ | |
4794 | ||
4795 | static void | |
a6d9a66e | 4796 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 4797 | { |
79a45b7d TT |
4798 | struct value_print_options opts; |
4799 | ||
4800 | get_user_print_options (&opts); | |
4801 | ||
ce78b96d JB |
4802 | /* Field 4, the address, is omitted (which makes the columns |
4803 | not line up too nicely with the headers, but the effect | |
4804 | is relatively readable). */ | |
79a45b7d | 4805 | if (opts.addressprint) |
ce78b96d JB |
4806 | ui_out_field_skip (uiout, "addr"); |
4807 | annotate_field (5); | |
4808 | ui_out_text (uiout, "fork"); | |
4809 | if (!ptid_equal (b->forked_inferior_pid, null_ptid)) | |
4810 | { | |
4811 | ui_out_text (uiout, ", process "); | |
4812 | ui_out_field_int (uiout, "what", | |
4813 | ptid_get_pid (b->forked_inferior_pid)); | |
4814 | ui_out_spaces (uiout, 1); | |
4815 | } | |
4816 | } | |
4817 | ||
4818 | /* Implement the "print_mention" breakpoint_ops method for fork | |
4819 | catchpoints. */ | |
4820 | ||
4821 | static void | |
4822 | print_mention_catch_fork (struct breakpoint *b) | |
4823 | { | |
4824 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
4825 | } | |
4826 | ||
4827 | /* The breakpoint_ops structure to be used in fork catchpoints. */ | |
4828 | ||
4829 | static struct breakpoint_ops catch_fork_breakpoint_ops = | |
4830 | { | |
4831 | insert_catch_fork, | |
4832 | remove_catch_fork, | |
4833 | breakpoint_hit_catch_fork, | |
4834 | print_it_catch_fork, | |
4835 | print_one_catch_fork, | |
4836 | print_mention_catch_fork | |
4837 | }; | |
4838 | ||
4839 | /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */ | |
4840 | ||
4841 | static void | |
4842 | insert_catch_vfork (struct breakpoint *b) | |
4843 | { | |
4844 | target_insert_vfork_catchpoint (PIDGET (inferior_ptid)); | |
4845 | } | |
4846 | ||
4847 | /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */ | |
4848 | ||
4849 | static int | |
4850 | remove_catch_vfork (struct breakpoint *b) | |
4851 | { | |
4852 | return target_remove_vfork_catchpoint (PIDGET (inferior_ptid)); | |
4853 | } | |
4854 | ||
4855 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
4856 | catchpoints. */ | |
4857 | ||
4858 | static int | |
4859 | breakpoint_hit_catch_vfork (struct breakpoint *b) | |
4860 | { | |
4861 | return inferior_has_vforked (inferior_ptid, &b->forked_inferior_pid); | |
4862 | } | |
4863 | ||
4864 | /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */ | |
4865 | ||
4866 | static enum print_stop_action | |
4867 | print_it_catch_vfork (struct breakpoint *b) | |
4868 | { | |
4869 | annotate_catchpoint (b->number); | |
4870 | printf_filtered (_("\nCatchpoint %d (vforked process %d), "), | |
4871 | b->number, ptid_get_pid (b->forked_inferior_pid)); | |
4872 | return PRINT_SRC_AND_LOC; | |
4873 | } | |
4874 | ||
4875 | /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */ | |
4876 | ||
4877 | static void | |
a6d9a66e | 4878 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 4879 | { |
79a45b7d TT |
4880 | struct value_print_options opts; |
4881 | ||
4882 | get_user_print_options (&opts); | |
ce78b96d JB |
4883 | /* Field 4, the address, is omitted (which makes the columns |
4884 | not line up too nicely with the headers, but the effect | |
4885 | is relatively readable). */ | |
79a45b7d | 4886 | if (opts.addressprint) |
ce78b96d JB |
4887 | ui_out_field_skip (uiout, "addr"); |
4888 | annotate_field (5); | |
4889 | ui_out_text (uiout, "vfork"); | |
4890 | if (!ptid_equal (b->forked_inferior_pid, null_ptid)) | |
4891 | { | |
4892 | ui_out_text (uiout, ", process "); | |
4893 | ui_out_field_int (uiout, "what", | |
4894 | ptid_get_pid (b->forked_inferior_pid)); | |
4895 | ui_out_spaces (uiout, 1); | |
4896 | } | |
4897 | } | |
4898 | ||
4899 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
4900 | catchpoints. */ | |
4901 | ||
4902 | static void | |
4903 | print_mention_catch_vfork (struct breakpoint *b) | |
4904 | { | |
4905 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
4906 | } | |
4907 | ||
4908 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ | |
4909 | ||
4910 | static struct breakpoint_ops catch_vfork_breakpoint_ops = | |
4911 | { | |
4912 | insert_catch_vfork, | |
4913 | remove_catch_vfork, | |
4914 | breakpoint_hit_catch_vfork, | |
4915 | print_it_catch_vfork, | |
4916 | print_one_catch_vfork, | |
4917 | print_mention_catch_vfork | |
4918 | }; | |
4919 | ||
4920 | /* Create a new breakpoint of the bp_catchpoint kind and return it. | |
4921 | ||
4922 | If TEMPFLAG is non-zero, then make the breakpoint temporary. | |
4923 | If COND_STRING is not NULL, then store it in the breakpoint. | |
4924 | OPS, if not NULL, is the breakpoint_ops structure associated | |
4925 | to the catchpoint. */ | |
4926 | ||
4927 | static struct breakpoint * | |
a6d9a66e UW |
4928 | create_catchpoint (struct gdbarch *gdbarch, int tempflag, |
4929 | char *cond_string, struct breakpoint_ops *ops) | |
c906108c | 4930 | { |
c5aa993b JM |
4931 | struct symtab_and_line sal; |
4932 | struct breakpoint *b; | |
c5aa993b | 4933 | |
fe39c653 | 4934 | init_sal (&sal); |
c906108c SS |
4935 | sal.pc = 0; |
4936 | sal.symtab = NULL; | |
4937 | sal.line = 0; | |
c5aa993b | 4938 | |
a6d9a66e | 4939 | b = set_raw_breakpoint (gdbarch, sal, bp_catchpoint); |
c906108c SS |
4940 | set_breakpoint_count (breakpoint_count + 1); |
4941 | b->number = breakpoint_count; | |
ce78b96d | 4942 | |
1b36a34b | 4943 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
ce78b96d | 4944 | b->thread = -1; |
c906108c | 4945 | b->addr_string = NULL; |
b5de0fa7 EZ |
4946 | b->enable_state = bp_enabled; |
4947 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
ce78b96d | 4948 | b->ops = ops; |
c5aa993b | 4949 | |
c906108c | 4950 | mention (b); |
ce78b96d | 4951 | update_global_location_list (1); |
c906108c | 4952 | |
ce78b96d | 4953 | return b; |
c906108c | 4954 | } |
c5aa993b | 4955 | |
9b70b993 | 4956 | static void |
a6d9a66e UW |
4957 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
4958 | int tempflag, char *cond_string, | |
ce78b96d | 4959 | struct breakpoint_ops *ops) |
c906108c | 4960 | { |
a6d9a66e UW |
4961 | struct breakpoint *b |
4962 | = create_catchpoint (gdbarch, tempflag, cond_string, ops); | |
ce78b96d JB |
4963 | |
4964 | /* FIXME: We should put this information in a breakpoint private data | |
4965 | area. */ | |
4966 | b->forked_inferior_pid = null_ptid; | |
c906108c SS |
4967 | } |
4968 | ||
fe798b75 JB |
4969 | /* Exec catchpoints. */ |
4970 | ||
9b70b993 | 4971 | static void |
fe798b75 | 4972 | insert_catch_exec (struct breakpoint *b) |
c906108c | 4973 | { |
fe798b75 JB |
4974 | target_insert_exec_catchpoint (PIDGET (inferior_ptid)); |
4975 | } | |
c906108c | 4976 | |
fe798b75 JB |
4977 | static int |
4978 | remove_catch_exec (struct breakpoint *b) | |
4979 | { | |
4980 | return target_remove_exec_catchpoint (PIDGET (inferior_ptid)); | |
4981 | } | |
c906108c | 4982 | |
fe798b75 JB |
4983 | static int |
4984 | breakpoint_hit_catch_exec (struct breakpoint *b) | |
4985 | { | |
4986 | return inferior_has_execd (inferior_ptid, &b->exec_pathname); | |
4987 | } | |
c906108c | 4988 | |
fe798b75 JB |
4989 | static enum print_stop_action |
4990 | print_it_catch_exec (struct breakpoint *b) | |
4991 | { | |
4992 | annotate_catchpoint (b->number); | |
4993 | printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b->number, | |
4994 | b->exec_pathname); | |
4995 | return PRINT_SRC_AND_LOC; | |
c906108c SS |
4996 | } |
4997 | ||
fe798b75 | 4998 | static void |
a6d9a66e | 4999 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 JB |
5000 | { |
5001 | struct value_print_options opts; | |
5002 | ||
5003 | get_user_print_options (&opts); | |
5004 | ||
5005 | /* Field 4, the address, is omitted (which makes the columns | |
5006 | not line up too nicely with the headers, but the effect | |
5007 | is relatively readable). */ | |
5008 | if (opts.addressprint) | |
5009 | ui_out_field_skip (uiout, "addr"); | |
5010 | annotate_field (5); | |
5011 | ui_out_text (uiout, "exec"); | |
5012 | if (b->exec_pathname != NULL) | |
5013 | { | |
5014 | ui_out_text (uiout, ", program \""); | |
5015 | ui_out_field_string (uiout, "what", b->exec_pathname); | |
5016 | ui_out_text (uiout, "\" "); | |
5017 | } | |
5018 | } | |
5019 | ||
5020 | static void | |
5021 | print_mention_catch_exec (struct breakpoint *b) | |
5022 | { | |
5023 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
5024 | } | |
5025 | ||
5026 | static struct breakpoint_ops catch_exec_breakpoint_ops = | |
5027 | { | |
5028 | insert_catch_exec, | |
5029 | remove_catch_exec, | |
5030 | breakpoint_hit_catch_exec, | |
5031 | print_it_catch_exec, | |
5032 | print_one_catch_exec, | |
5033 | print_mention_catch_exec | |
5034 | }; | |
5035 | ||
c906108c | 5036 | static int |
fba45db2 | 5037 | hw_breakpoint_used_count (void) |
c906108c | 5038 | { |
52f0bd74 | 5039 | struct breakpoint *b; |
c906108c SS |
5040 | int i = 0; |
5041 | ||
5042 | ALL_BREAKPOINTS (b) | |
c5aa993b | 5043 | { |
d6b74ac4 | 5044 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
c5aa993b JM |
5045 | i++; |
5046 | } | |
c906108c SS |
5047 | |
5048 | return i; | |
5049 | } | |
5050 | ||
5051 | static int | |
fba45db2 | 5052 | hw_watchpoint_used_count (enum bptype type, int *other_type_used) |
c906108c | 5053 | { |
52f0bd74 | 5054 | struct breakpoint *b; |
c906108c SS |
5055 | int i = 0; |
5056 | ||
5057 | *other_type_used = 0; | |
5058 | ALL_BREAKPOINTS (b) | |
c5aa993b | 5059 | { |
468d015d | 5060 | if (breakpoint_enabled (b)) |
c5aa993b JM |
5061 | { |
5062 | if (b->type == type) | |
5063 | i++; | |
059fb39f PM |
5064 | else if ((b->type == bp_hardware_watchpoint |
5065 | || b->type == bp_read_watchpoint | |
5066 | || b->type == bp_access_watchpoint)) | |
c5aa993b JM |
5067 | *other_type_used = 1; |
5068 | } | |
5069 | } | |
c906108c SS |
5070 | return i; |
5071 | } | |
5072 | ||
c906108c | 5073 | void |
fba45db2 | 5074 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 5075 | { |
c5aa993b | 5076 | struct breakpoint *b; |
c906108c SS |
5077 | |
5078 | ALL_BREAKPOINTS (b) | |
c5aa993b JM |
5079 | { |
5080 | if (((b->type == bp_watchpoint) | |
5081 | || (b->type == bp_hardware_watchpoint) | |
5082 | || (b->type == bp_read_watchpoint) | |
dfdfb3ca | 5083 | || (b->type == bp_access_watchpoint)) |
468d015d | 5084 | && breakpoint_enabled (b)) |
c5aa993b | 5085 | { |
b5de0fa7 | 5086 | b->enable_state = bp_call_disabled; |
b60e7edf | 5087 | update_global_location_list (0); |
c5aa993b JM |
5088 | } |
5089 | } | |
c906108c SS |
5090 | } |
5091 | ||
5092 | void | |
fba45db2 | 5093 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 5094 | { |
c5aa993b | 5095 | struct breakpoint *b; |
c906108c SS |
5096 | |
5097 | ALL_BREAKPOINTS (b) | |
c5aa993b JM |
5098 | { |
5099 | if (((b->type == bp_watchpoint) | |
5100 | || (b->type == bp_hardware_watchpoint) | |
5101 | || (b->type == bp_read_watchpoint) | |
dfdfb3ca | 5102 | || (b->type == bp_access_watchpoint)) |
b5de0fa7 | 5103 | && (b->enable_state == bp_call_disabled)) |
c5aa993b | 5104 | { |
b5de0fa7 | 5105 | b->enable_state = bp_enabled; |
b60e7edf | 5106 | update_global_location_list (1); |
c5aa993b JM |
5107 | } |
5108 | } | |
c906108c SS |
5109 | } |
5110 | ||
8bea4e01 UW |
5111 | void |
5112 | disable_breakpoints_before_startup (void) | |
5113 | { | |
5114 | struct breakpoint *b; | |
5115 | int found = 0; | |
5116 | ||
5117 | ALL_BREAKPOINTS (b) | |
5118 | { | |
5119 | if ((b->type == bp_breakpoint | |
5120 | || b->type == bp_hardware_breakpoint) | |
5121 | && breakpoint_enabled (b)) | |
5122 | { | |
5123 | b->enable_state = bp_startup_disabled; | |
5124 | found = 1; | |
5125 | } | |
5126 | } | |
5127 | ||
5128 | if (found) | |
5129 | update_global_location_list (0); | |
5130 | ||
5131 | executing_startup = 1; | |
5132 | } | |
5133 | ||
5134 | void | |
5135 | enable_breakpoints_after_startup (void) | |
5136 | { | |
5137 | struct breakpoint *b; | |
5138 | int found = 0; | |
5139 | ||
5140 | executing_startup = 0; | |
5141 | ||
5142 | ALL_BREAKPOINTS (b) | |
5143 | { | |
5144 | if ((b->type == bp_breakpoint | |
5145 | || b->type == bp_hardware_breakpoint) | |
5146 | && b->enable_state == bp_startup_disabled) | |
5147 | { | |
5148 | b->enable_state = bp_enabled; | |
5149 | found = 1; | |
5150 | } | |
5151 | } | |
5152 | ||
5153 | if (found) | |
5154 | breakpoint_re_set (); | |
5155 | } | |
5156 | ||
c906108c SS |
5157 | |
5158 | /* Set a breakpoint that will evaporate an end of command | |
5159 | at address specified by SAL. | |
5160 | Restrict it to frame FRAME if FRAME is nonzero. */ | |
5161 | ||
5162 | struct breakpoint * | |
a6d9a66e UW |
5163 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
5164 | struct frame_id frame_id, enum bptype type) | |
c906108c | 5165 | { |
52f0bd74 | 5166 | struct breakpoint *b; |
edb3359d DJ |
5167 | |
5168 | /* If FRAME_ID is valid, it should be a real frame, not an inlined | |
5169 | one. */ | |
5170 | gdb_assert (!frame_id_inlined_p (frame_id)); | |
5171 | ||
a6d9a66e | 5172 | b = set_raw_breakpoint (gdbarch, sal, type); |
b5de0fa7 EZ |
5173 | b->enable_state = bp_enabled; |
5174 | b->disposition = disp_donttouch; | |
818dd999 | 5175 | b->frame_id = frame_id; |
c906108c SS |
5176 | |
5177 | /* If we're debugging a multi-threaded program, then we | |
5178 | want momentary breakpoints to be active in only a | |
5179 | single thread of control. */ | |
39f77062 KB |
5180 | if (in_thread_list (inferior_ptid)) |
5181 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c | 5182 | |
b60e7edf | 5183 | update_global_location_list_nothrow (1); |
74960c60 | 5184 | |
c906108c SS |
5185 | return b; |
5186 | } | |
611c83ae | 5187 | |
e58b0e63 PA |
5188 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
5189 | ORIG is NULL. */ | |
5190 | ||
5191 | struct breakpoint * | |
5192 | clone_momentary_breakpoint (struct breakpoint *orig) | |
5193 | { | |
5194 | struct breakpoint *copy; | |
5195 | ||
5196 | /* If there's nothing to clone, then return nothing. */ | |
5197 | if (orig == NULL) | |
5198 | return NULL; | |
5199 | ||
a6d9a66e | 5200 | copy = set_raw_breakpoint_without_location (orig->gdbarch, orig->type); |
e58b0e63 PA |
5201 | copy->loc = allocate_bp_location (copy); |
5202 | set_breakpoint_location_function (copy->loc); | |
5203 | ||
a6d9a66e | 5204 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
5205 | copy->loc->requested_address = orig->loc->requested_address; |
5206 | copy->loc->address = orig->loc->address; | |
5207 | copy->loc->section = orig->loc->section; | |
5208 | ||
5209 | if (orig->source_file == NULL) | |
5210 | copy->source_file = NULL; | |
5211 | else | |
5212 | copy->source_file = xstrdup (orig->source_file); | |
5213 | ||
5214 | copy->line_number = orig->line_number; | |
5215 | copy->frame_id = orig->frame_id; | |
5216 | copy->thread = orig->thread; | |
5217 | ||
5218 | copy->enable_state = bp_enabled; | |
5219 | copy->disposition = disp_donttouch; | |
5220 | copy->number = internal_breakpoint_number--; | |
5221 | ||
5222 | update_global_location_list_nothrow (0); | |
5223 | return copy; | |
5224 | } | |
5225 | ||
611c83ae | 5226 | struct breakpoint * |
a6d9a66e UW |
5227 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
5228 | enum bptype type) | |
611c83ae PA |
5229 | { |
5230 | struct symtab_and_line sal; | |
5231 | ||
5232 | sal = find_pc_line (pc, 0); | |
5233 | sal.pc = pc; | |
5234 | sal.section = find_pc_overlay (pc); | |
5235 | sal.explicit_pc = 1; | |
5236 | ||
a6d9a66e | 5237 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 5238 | } |
c906108c | 5239 | \f |
c5aa993b | 5240 | |
c906108c SS |
5241 | /* Tell the user we have just set a breakpoint B. */ |
5242 | ||
5243 | static void | |
fba45db2 | 5244 | mention (struct breakpoint *b) |
c906108c SS |
5245 | { |
5246 | int say_where = 0; | |
fa8a61dc | 5247 | struct cleanup *ui_out_chain; |
79a45b7d TT |
5248 | struct value_print_options opts; |
5249 | ||
5250 | get_user_print_options (&opts); | |
8b93c638 | 5251 | |
9a4105ab AC |
5252 | /* FIXME: This is misplaced; mention() is called by things (like |
5253 | hitting a watchpoint) other than breakpoint creation. It should | |
5254 | be possible to clean this up and at the same time replace the | |
7f4b89d1 | 5255 | random calls to breakpoint_changed with this hook. */ |
383f836e | 5256 | observer_notify_breakpoint_created (b->number); |
c906108c | 5257 | |
3086aeae DJ |
5258 | if (b->ops != NULL && b->ops->print_mention != NULL) |
5259 | b->ops->print_mention (b); | |
5260 | else | |
5261 | switch (b->type) | |
5262 | { | |
5263 | case bp_none: | |
a3f17187 | 5264 | printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b->number); |
3086aeae DJ |
5265 | break; |
5266 | case bp_watchpoint: | |
5267 | ui_out_text (uiout, "Watchpoint "); | |
5268 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
5269 | ui_out_field_int (uiout, "number", b->number); | |
5270 | ui_out_text (uiout, ": "); | |
fa8a61dc | 5271 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
5272 | do_cleanups (ui_out_chain); |
5273 | break; | |
5274 | case bp_hardware_watchpoint: | |
5275 | ui_out_text (uiout, "Hardware watchpoint "); | |
5276 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
5277 | ui_out_field_int (uiout, "number", b->number); | |
5278 | ui_out_text (uiout, ": "); | |
fa8a61dc | 5279 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
5280 | do_cleanups (ui_out_chain); |
5281 | break; | |
5282 | case bp_read_watchpoint: | |
5283 | ui_out_text (uiout, "Hardware read watchpoint "); | |
5284 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
5285 | ui_out_field_int (uiout, "number", b->number); | |
5286 | ui_out_text (uiout, ": "); | |
fa8a61dc | 5287 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
5288 | do_cleanups (ui_out_chain); |
5289 | break; | |
5290 | case bp_access_watchpoint: | |
5291 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
5292 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
5293 | ui_out_field_int (uiout, "number", b->number); | |
5294 | ui_out_text (uiout, ": "); | |
fa8a61dc | 5295 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
5296 | do_cleanups (ui_out_chain); |
5297 | break; | |
5298 | case bp_breakpoint: | |
5299 | if (ui_out_is_mi_like_p (uiout)) | |
5300 | { | |
5301 | say_where = 0; | |
5302 | break; | |
5303 | } | |
2cec12e5 AR |
5304 | if (b->disposition == disp_del) |
5305 | printf_filtered (_("Temporary breakpoint")); | |
5306 | else | |
5307 | printf_filtered (_("Breakpoint")); | |
5308 | printf_filtered (_(" %d"), b->number); | |
3086aeae DJ |
5309 | say_where = 1; |
5310 | break; | |
5311 | case bp_hardware_breakpoint: | |
5312 | if (ui_out_is_mi_like_p (uiout)) | |
5313 | { | |
5314 | say_where = 0; | |
5315 | break; | |
5316 | } | |
a3f17187 | 5317 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); |
3086aeae DJ |
5318 | say_where = 1; |
5319 | break; | |
1042e4c0 SS |
5320 | case bp_tracepoint: |
5321 | if (ui_out_is_mi_like_p (uiout)) | |
5322 | { | |
5323 | say_where = 0; | |
5324 | break; | |
5325 | } | |
5326 | printf_filtered (_("Tracepoint")); | |
5327 | printf_filtered (_(" %d"), b->number); | |
5328 | say_where = 1; | |
5329 | break; | |
3086aeae DJ |
5330 | |
5331 | case bp_until: | |
5332 | case bp_finish: | |
5333 | case bp_longjmp: | |
5334 | case bp_longjmp_resume: | |
5335 | case bp_step_resume: | |
3086aeae DJ |
5336 | case bp_call_dummy: |
5337 | case bp_watchpoint_scope: | |
5338 | case bp_shlib_event: | |
5339 | case bp_thread_event: | |
5340 | case bp_overlay_event: | |
0fd8e87f | 5341 | case bp_longjmp_master: |
3086aeae DJ |
5342 | break; |
5343 | } | |
c906108c | 5344 | |
c906108c SS |
5345 | if (say_where) |
5346 | { | |
a3f17187 AC |
5347 | /* i18n: cagney/2005-02-11: Below needs to be merged into a |
5348 | single string. */ | |
0d381245 | 5349 | if (b->loc == NULL) |
c906108c | 5350 | { |
a3f17187 | 5351 | printf_filtered (_(" (%s) pending."), b->addr_string); |
0101ce28 JJ |
5352 | } |
5353 | else | |
5354 | { | |
79a45b7d | 5355 | if (opts.addressprint || b->source_file == NULL) |
0101ce28 JJ |
5356 | { |
5357 | printf_filtered (" at "); | |
5af949e3 UW |
5358 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), |
5359 | gdb_stdout); | |
0101ce28 JJ |
5360 | } |
5361 | if (b->source_file) | |
5362 | printf_filtered (": file %s, line %d.", | |
5363 | b->source_file, b->line_number); | |
0d381245 VP |
5364 | |
5365 | if (b->loc->next) | |
5366 | { | |
5367 | struct bp_location *loc = b->loc; | |
5368 | int n = 0; | |
5369 | for (; loc; loc = loc->next) | |
5370 | ++n; | |
5371 | printf_filtered (" (%d locations)", n); | |
5372 | } | |
5373 | ||
c906108c | 5374 | } |
c906108c | 5375 | } |
9dc5e2a9 | 5376 | if (ui_out_is_mi_like_p (uiout)) |
fb40c209 | 5377 | return; |
c906108c SS |
5378 | printf_filtered ("\n"); |
5379 | } | |
c906108c | 5380 | \f |
c5aa993b | 5381 | |
0d381245 | 5382 | static struct bp_location * |
39d61571 | 5383 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
5384 | const struct symtab_and_line *sal) |
5385 | { | |
5386 | struct bp_location *loc, **tmp; | |
5387 | ||
39d61571 | 5388 | loc = allocate_bp_location (b); |
0d381245 VP |
5389 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
5390 | ; | |
5391 | *tmp = loc; | |
a6d9a66e UW |
5392 | loc->gdbarch = get_sal_arch (*sal); |
5393 | if (!loc->gdbarch) | |
5394 | loc->gdbarch = b->gdbarch; | |
0d381245 | 5395 | loc->requested_address = sal->pc; |
a6d9a66e UW |
5396 | loc->address = adjust_breakpoint_address (loc->gdbarch, |
5397 | loc->requested_address, b->type); | |
0d381245 VP |
5398 | loc->section = sal->section; |
5399 | ||
5400 | set_breakpoint_location_function (loc); | |
5401 | return loc; | |
5402 | } | |
514f746b AR |
5403 | \f |
5404 | ||
5405 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
5406 | return 0 otherwise. */ | |
5407 | ||
5408 | static int | |
5409 | bp_loc_is_permanent (struct bp_location *loc) | |
5410 | { | |
5411 | int len; | |
5412 | CORE_ADDR addr; | |
5413 | const gdb_byte *brk; | |
5414 | gdb_byte *target_mem; | |
939c61fa JK |
5415 | struct cleanup *cleanup; |
5416 | int retval = 0; | |
514f746b AR |
5417 | |
5418 | gdb_assert (loc != NULL); | |
5419 | ||
5420 | addr = loc->address; | |
a6d9a66e | 5421 | brk = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len); |
514f746b | 5422 | |
939c61fa JK |
5423 | /* Software breakpoints unsupported? */ |
5424 | if (brk == NULL) | |
5425 | return 0; | |
5426 | ||
514f746b AR |
5427 | target_mem = alloca (len); |
5428 | ||
939c61fa JK |
5429 | /* Enable the automatic memory restoration from breakpoints while |
5430 | we read the memory. Otherwise we could say about our temporary | |
5431 | breakpoints they are permanent. */ | |
5432 | cleanup = make_show_memory_breakpoints_cleanup (0); | |
5433 | ||
514f746b AR |
5434 | if (target_read_memory (loc->address, target_mem, len) == 0 |
5435 | && memcmp (target_mem, brk, len) == 0) | |
939c61fa | 5436 | retval = 1; |
514f746b | 5437 | |
939c61fa JK |
5438 | do_cleanups (cleanup); |
5439 | ||
5440 | return retval; | |
514f746b AR |
5441 | } |
5442 | ||
5443 | ||
c3f6f71d | 5444 | |
018d34a4 VP |
5445 | /* Create a breakpoint with SAL as location. Use ADDR_STRING |
5446 | as textual description of the location, and COND_STRING | |
db107f19 | 5447 | as condition expression. */ |
018d34a4 VP |
5448 | |
5449 | static void | |
a6d9a66e UW |
5450 | create_breakpoint (struct gdbarch *gdbarch, |
5451 | struct symtabs_and_lines sals, char *addr_string, | |
018d34a4 VP |
5452 | char *cond_string, |
5453 | enum bptype type, enum bpdisp disposition, | |
4a306c9a | 5454 | int thread, int task, int ignore_count, |
41447f92 | 5455 | struct breakpoint_ops *ops, int from_tty, int enabled) |
018d34a4 | 5456 | { |
0d381245 VP |
5457 | struct breakpoint *b = NULL; |
5458 | int i; | |
018d34a4 VP |
5459 | |
5460 | if (type == bp_hardware_breakpoint) | |
5461 | { | |
5462 | int i = hw_breakpoint_used_count (); | |
5463 | int target_resources_ok = | |
d92524f1 | 5464 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
018d34a4 VP |
5465 | i + 1, 0); |
5466 | if (target_resources_ok == 0) | |
5467 | error (_("No hardware breakpoint support in the target.")); | |
5468 | else if (target_resources_ok < 0) | |
5469 | error (_("Hardware breakpoints used exceeds limit.")); | |
5470 | } | |
5471 | ||
0d381245 VP |
5472 | for (i = 0; i < sals.nelts; ++i) |
5473 | { | |
5474 | struct symtab_and_line sal = sals.sals[i]; | |
5475 | struct bp_location *loc; | |
5476 | ||
5477 | if (from_tty) | |
5af949e3 UW |
5478 | { |
5479 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
5480 | if (!loc_gdbarch) | |
5481 | loc_gdbarch = gdbarch; | |
5482 | ||
5483 | describe_other_breakpoints (loc_gdbarch, | |
5484 | sal.pc, sal.section, thread); | |
5485 | } | |
0d381245 VP |
5486 | |
5487 | if (i == 0) | |
5488 | { | |
a6d9a66e | 5489 | b = set_raw_breakpoint (gdbarch, sal, type); |
0d381245 VP |
5490 | set_breakpoint_count (breakpoint_count + 1); |
5491 | b->number = breakpoint_count; | |
5492 | b->thread = thread; | |
4a306c9a | 5493 | b->task = task; |
018d34a4 | 5494 | |
0d381245 VP |
5495 | b->cond_string = cond_string; |
5496 | b->ignore_count = ignore_count; | |
41447f92 | 5497 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 5498 | b->disposition = disposition; |
018d34a4 | 5499 | |
8bea4e01 UW |
5500 | if (enabled && executing_startup |
5501 | && (b->type == bp_breakpoint | |
5502 | || b->type == bp_hardware_breakpoint)) | |
5503 | b->enable_state = bp_startup_disabled; | |
5504 | ||
0d381245 VP |
5505 | loc = b->loc; |
5506 | } | |
5507 | else | |
018d34a4 | 5508 | { |
39d61571 | 5509 | loc = add_location_to_breakpoint (b, &sal); |
0d381245 VP |
5510 | } |
5511 | ||
514f746b AR |
5512 | if (bp_loc_is_permanent (loc)) |
5513 | make_breakpoint_permanent (b); | |
5514 | ||
0d381245 VP |
5515 | if (b->cond_string) |
5516 | { | |
5517 | char *arg = b->cond_string; | |
d32a6982 | 5518 | loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0); |
0d381245 | 5519 | if (*arg) |
db107f19 | 5520 | error (_("Garbage %s follows condition"), arg); |
018d34a4 | 5521 | } |
0d381245 | 5522 | } |
018d34a4 VP |
5523 | |
5524 | if (addr_string) | |
5525 | b->addr_string = addr_string; | |
5526 | else | |
5527 | /* addr_string has to be used or breakpoint_re_set will delete | |
5528 | me. */ | |
5af949e3 UW |
5529 | b->addr_string |
5530 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
018d34a4 | 5531 | |
604133b5 | 5532 | b->ops = ops; |
018d34a4 VP |
5533 | mention (b); |
5534 | } | |
5535 | ||
ed0616c6 VP |
5536 | /* Remove element at INDEX_TO_REMOVE from SAL, shifting other |
5537 | elements to fill the void space. */ | |
2c0b251b PA |
5538 | static void |
5539 | remove_sal (struct symtabs_and_lines *sal, int index_to_remove) | |
ed0616c6 VP |
5540 | { |
5541 | int i = index_to_remove+1; | |
5542 | int last_index = sal->nelts-1; | |
5543 | ||
5544 | for (;i <= last_index; ++i) | |
5545 | sal->sals[i-1] = sal->sals[i]; | |
5546 | ||
5547 | --(sal->nelts); | |
5548 | } | |
5549 | ||
5550 | /* If appropriate, obtains all sals that correspond | |
5551 | to the same file and line as SAL. This is done | |
5552 | only if SAL does not have explicit PC and has | |
5553 | line and file information. If we got just a single | |
5554 | expanded sal, return the original. | |
5555 | ||
5556 | Otherwise, if SAL.explicit_line is not set, filter out | |
5557 | all sals for which the name of enclosing function | |
5558 | is different from SAL. This makes sure that if we have | |
5559 | breakpoint originally set in template instantiation, say | |
5560 | foo<int>(), we won't expand SAL to locations at the same | |
5561 | line in all existing instantiations of 'foo'. | |
5562 | ||
5563 | */ | |
2c0b251b | 5564 | static struct symtabs_and_lines |
ed0616c6 VP |
5565 | expand_line_sal_maybe (struct symtab_and_line sal) |
5566 | { | |
5567 | struct symtabs_and_lines expanded; | |
5568 | CORE_ADDR original_pc = sal.pc; | |
5569 | char *original_function = NULL; | |
5570 | int found; | |
5571 | int i; | |
5572 | ||
5573 | /* If we have explicit pc, don't expand. | |
5574 | If we have no line number, we can't expand. */ | |
5575 | if (sal.explicit_pc || sal.line == 0 || sal.symtab == NULL) | |
5576 | { | |
5577 | expanded.nelts = 1; | |
5578 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
5579 | expanded.sals[0] = sal; | |
5580 | return expanded; | |
5581 | } | |
5582 | ||
5583 | sal.pc = 0; | |
5584 | find_pc_partial_function (original_pc, &original_function, NULL, NULL); | |
5585 | ||
5586 | expanded = expand_line_sal (sal); | |
5587 | if (expanded.nelts == 1) | |
5588 | { | |
5589 | /* We had one sal, we got one sal. Without futher | |
5590 | processing, just return the original sal. */ | |
5591 | xfree (expanded.sals); | |
5592 | expanded.nelts = 1; | |
5593 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
5594 | sal.pc = original_pc; | |
5595 | expanded.sals[0] = sal; | |
5596 | return expanded; | |
5597 | } | |
5598 | ||
5599 | if (!sal.explicit_line) | |
5600 | { | |
5601 | CORE_ADDR func_addr, func_end; | |
5602 | for (i = 0; i < expanded.nelts; ++i) | |
5603 | { | |
5604 | CORE_ADDR pc = expanded.sals[i].pc; | |
5605 | char *this_function; | |
5606 | if (find_pc_partial_function (pc, &this_function, | |
5607 | &func_addr, &func_end)) | |
5608 | { | |
059fb39f PM |
5609 | if (this_function |
5610 | && strcmp (this_function, original_function) != 0) | |
ed0616c6 VP |
5611 | { |
5612 | remove_sal (&expanded, i); | |
5613 | --i; | |
5614 | } | |
5615 | else if (func_addr == pc) | |
5616 | { | |
5617 | /* We're at beginning of a function, and should | |
5618 | skip prologue. */ | |
5619 | struct symbol *sym = find_pc_function (pc); | |
5620 | if (sym) | |
5621 | expanded.sals[i] = find_function_start_sal (sym, 1); | |
5622 | else | |
d80b854b UW |
5623 | { |
5624 | /* Since find_pc_partial_function returned true, | |
5625 | we should really always find the section here. */ | |
5626 | struct obj_section *section = find_pc_section (pc); | |
5627 | if (section) | |
5628 | { | |
5629 | struct gdbarch *gdbarch | |
5630 | = get_objfile_arch (section->objfile); | |
5631 | expanded.sals[i].pc | |
5632 | = gdbarch_skip_prologue (gdbarch, pc); | |
5633 | } | |
5634 | } | |
ed0616c6 VP |
5635 | } |
5636 | } | |
5637 | } | |
5638 | } | |
3daf8fe5 JG |
5639 | else |
5640 | { | |
5641 | for (i = 0; i < expanded.nelts; ++i) | |
5642 | { | |
5643 | /* If this SAL corresponds to a breakpoint inserted using a | |
5644 | line number, then skip the function prologue if necessary. */ | |
5645 | skip_prologue_sal (&expanded.sals[i]); | |
5646 | } | |
5647 | } | |
ed0616c6 VP |
5648 | |
5649 | ||
5650 | if (expanded.nelts <= 1) | |
5651 | { | |
5652 | /* This is un ugly workaround. If we get zero | |
5653 | expanded sals then something is really wrong. | |
5654 | Fix that by returnign the original sal. */ | |
5655 | xfree (expanded.sals); | |
5656 | expanded.nelts = 1; | |
5657 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
5658 | sal.pc = original_pc; | |
5659 | expanded.sals[0] = sal; | |
5660 | return expanded; | |
5661 | } | |
5662 | ||
5663 | if (original_pc) | |
5664 | { | |
5665 | found = 0; | |
5666 | for (i = 0; i < expanded.nelts; ++i) | |
5667 | if (expanded.sals[i].pc == original_pc) | |
5668 | { | |
5669 | found = 1; | |
5670 | break; | |
5671 | } | |
5672 | gdb_assert (found); | |
5673 | } | |
5674 | ||
5675 | return expanded; | |
5676 | } | |
5677 | ||
018d34a4 VP |
5678 | /* Add SALS.nelts breakpoints to the breakpoint table. For each |
5679 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
5680 | value. COND_STRING, if not NULL, specified the condition to be | |
5681 | used for all breakpoints. Essentially the only case where | |
5682 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
5683 | function. In that case, it's still not possible to specify | |
5684 | separate conditions for different overloaded functions, so | |
5685 | we take just a single condition string. | |
5686 | ||
c3f6f71d | 5687 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 5688 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
5689 | array contents). If the function fails (error() is called), the |
5690 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
5691 | COND and SALS arrays and each of those arrays contents. */ | |
c906108c SS |
5692 | |
5693 | static void | |
a6d9a66e UW |
5694 | create_breakpoints (struct gdbarch *gdbarch, |
5695 | struct symtabs_and_lines sals, char **addr_string, | |
018d34a4 | 5696 | char *cond_string, |
c3f6f71d | 5697 | enum bptype type, enum bpdisp disposition, |
4a306c9a | 5698 | int thread, int task, int ignore_count, |
41447f92 VP |
5699 | struct breakpoint_ops *ops, int from_tty, |
5700 | int enabled) | |
c906108c | 5701 | { |
018d34a4 VP |
5702 | int i; |
5703 | for (i = 0; i < sals.nelts; ++i) | |
c3f6f71d | 5704 | { |
ed0616c6 VP |
5705 | struct symtabs_and_lines expanded = |
5706 | expand_line_sal_maybe (sals.sals[i]); | |
0d381245 | 5707 | |
a6d9a66e | 5708 | create_breakpoint (gdbarch, expanded, addr_string[i], |
018d34a4 | 5709 | cond_string, type, disposition, |
4a306c9a | 5710 | thread, task, ignore_count, ops, from_tty, enabled); |
c3f6f71d | 5711 | } |
c3f6f71d | 5712 | } |
c906108c | 5713 | |
c3f6f71d JM |
5714 | /* Parse ARG which is assumed to be a SAL specification possibly |
5715 | followed by conditionals. On return, SALS contains an array of SAL | |
5716 | addresses found. ADDR_STRING contains a vector of (canonical) | |
5717 | address strings. ARG points to the end of the SAL. */ | |
c906108c | 5718 | |
b9362cc7 | 5719 | static void |
c3f6f71d JM |
5720 | parse_breakpoint_sals (char **address, |
5721 | struct symtabs_and_lines *sals, | |
0101ce28 JJ |
5722 | char ***addr_string, |
5723 | int *not_found_ptr) | |
c3f6f71d JM |
5724 | { |
5725 | char *addr_start = *address; | |
5726 | *addr_string = NULL; | |
5727 | /* If no arg given, or if first arg is 'if ', use the default | |
5728 | breakpoint. */ | |
5729 | if ((*address) == NULL | |
5730 | || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2]))) | |
c906108c SS |
5731 | { |
5732 | if (default_breakpoint_valid) | |
5733 | { | |
c3f6f71d | 5734 | struct symtab_and_line sal; |
fe39c653 | 5735 | init_sal (&sal); /* initialize to zeroes */ |
c3f6f71d | 5736 | sals->sals = (struct symtab_and_line *) |
c906108c SS |
5737 | xmalloc (sizeof (struct symtab_and_line)); |
5738 | sal.pc = default_breakpoint_address; | |
5739 | sal.line = default_breakpoint_line; | |
5740 | sal.symtab = default_breakpoint_symtab; | |
c5aa993b | 5741 | sal.section = find_pc_overlay (sal.pc); |
00903456 JK |
5742 | |
5743 | /* "break" without arguments is equivalent to "break *PC" where PC is | |
5744 | the default_breakpoint_address. So make sure to set | |
5745 | sal.explicit_pc to prevent GDB from trying to expand the list of | |
5746 | sals to include all other instances with the same symtab and line. | |
5747 | */ | |
5748 | sal.explicit_pc = 1; | |
5749 | ||
c3f6f71d JM |
5750 | sals->sals[0] = sal; |
5751 | sals->nelts = 1; | |
c906108c SS |
5752 | } |
5753 | else | |
8a3fe4f8 | 5754 | error (_("No default breakpoint address now.")); |
c906108c SS |
5755 | } |
5756 | else | |
5757 | { | |
c906108c | 5758 | /* Force almost all breakpoints to be in terms of the |
c5aa993b JM |
5759 | current_source_symtab (which is decode_line_1's default). This |
5760 | should produce the results we want almost all of the time while | |
1aeae86e AF |
5761 | leaving default_breakpoint_* alone. |
5762 | ObjC: However, don't match an Objective-C method name which | |
5763 | may have a '+' or '-' succeeded by a '[' */ | |
0378c332 | 5764 | |
c214a6fd | 5765 | struct symtab_and_line cursal = get_current_source_symtab_and_line (); |
0378c332 | 5766 | |
c906108c | 5767 | if (default_breakpoint_valid |
0378c332 | 5768 | && (!cursal.symtab |
1aeae86e AF |
5769 | || ((strchr ("+-", (*address)[0]) != NULL) |
5770 | && ((*address)[1] != '[')))) | |
c3f6f71d | 5771 | *sals = decode_line_1 (address, 1, default_breakpoint_symtab, |
0101ce28 JJ |
5772 | default_breakpoint_line, addr_string, |
5773 | not_found_ptr); | |
c906108c | 5774 | else |
0101ce28 JJ |
5775 | *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0, |
5776 | addr_string, not_found_ptr); | |
c906108c | 5777 | } |
c3f6f71d JM |
5778 | /* For any SAL that didn't have a canonical string, fill one in. */ |
5779 | if (sals->nelts > 0 && *addr_string == NULL) | |
5780 | *addr_string = xcalloc (sals->nelts, sizeof (char **)); | |
5781 | if (addr_start != (*address)) | |
c906108c | 5782 | { |
c3f6f71d JM |
5783 | int i; |
5784 | for (i = 0; i < sals->nelts; i++) | |
c906108c | 5785 | { |
c3f6f71d JM |
5786 | /* Add the string if not present. */ |
5787 | if ((*addr_string)[i] == NULL) | |
5788 | (*addr_string)[i] = savestring (addr_start, (*address) - addr_start); | |
c906108c SS |
5789 | } |
5790 | } | |
c3f6f71d | 5791 | } |
c906108c | 5792 | |
c906108c | 5793 | |
c3f6f71d JM |
5794 | /* Convert each SAL into a real PC. Verify that the PC can be |
5795 | inserted as a breakpoint. If it can't throw an error. */ | |
c906108c | 5796 | |
b9362cc7 | 5797 | static void |
c3f6f71d JM |
5798 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals, |
5799 | char *address) | |
5800 | { | |
5801 | int i; | |
5802 | for (i = 0; i < sals->nelts; i++) | |
ee53e872 | 5803 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
5804 | } |
5805 | ||
05ff989b | 5806 | static void |
0101ce28 JJ |
5807 | do_captured_parse_breakpoint (struct ui_out *ui, void *data) |
5808 | { | |
5809 | struct captured_parse_breakpoint_args *args = data; | |
5810 | ||
5811 | parse_breakpoint_sals (args->arg_p, args->sals_p, args->addr_string_p, | |
5812 | args->not_found_ptr); | |
0101ce28 JJ |
5813 | } |
5814 | ||
018d34a4 VP |
5815 | /* Given TOK, a string specification of condition and thread, as |
5816 | accepted by the 'break' command, extract the condition | |
5817 | string and thread number and set *COND_STRING and *THREAD. | |
5818 | PC identifies the context at which the condition should be parsed. | |
5819 | If no condition is found, *COND_STRING is set to NULL. | |
5820 | If no thread is found, *THREAD is set to -1. */ | |
5821 | static void | |
5822 | find_condition_and_thread (char *tok, CORE_ADDR pc, | |
4a306c9a | 5823 | char **cond_string, int *thread, int *task) |
018d34a4 VP |
5824 | { |
5825 | *cond_string = NULL; | |
5826 | *thread = -1; | |
5827 | while (tok && *tok) | |
5828 | { | |
5829 | char *end_tok; | |
5830 | int toklen; | |
5831 | char *cond_start = NULL; | |
5832 | char *cond_end = NULL; | |
5833 | while (*tok == ' ' || *tok == '\t') | |
5834 | tok++; | |
5835 | ||
5836 | end_tok = tok; | |
5837 | ||
5838 | while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') | |
5839 | end_tok++; | |
5840 | ||
5841 | toklen = end_tok - tok; | |
5842 | ||
5843 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
5844 | { | |
f7545552 TT |
5845 | struct expression *expr; |
5846 | ||
018d34a4 | 5847 | tok = cond_start = end_tok + 1; |
f7545552 TT |
5848 | expr = parse_exp_1 (&tok, block_for_pc (pc), 0); |
5849 | xfree (expr); | |
018d34a4 VP |
5850 | cond_end = tok; |
5851 | *cond_string = savestring (cond_start, | |
5852 | cond_end - cond_start); | |
5853 | } | |
5854 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
5855 | { | |
5856 | char *tmptok; | |
5857 | ||
5858 | tok = end_tok + 1; | |
5859 | tmptok = tok; | |
5860 | *thread = strtol (tok, &tok, 0); | |
5861 | if (tok == tmptok) | |
5862 | error (_("Junk after thread keyword.")); | |
5863 | if (!valid_thread_id (*thread)) | |
5864 | error (_("Unknown thread %d."), *thread); | |
5865 | } | |
4a306c9a JB |
5866 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
5867 | { | |
5868 | char *tmptok; | |
5869 | ||
5870 | tok = end_tok + 1; | |
5871 | tmptok = tok; | |
5872 | *task = strtol (tok, &tok, 0); | |
5873 | if (tok == tmptok) | |
5874 | error (_("Junk after task keyword.")); | |
5875 | if (!valid_task_id (*task)) | |
5876 | error (_("Unknown task %d\n"), *task); | |
5877 | } | |
018d34a4 VP |
5878 | else |
5879 | error (_("Junk at end of arguments.")); | |
5880 | } | |
5881 | } | |
5882 | ||
72b2ff0e VP |
5883 | /* Set a breakpoint. This function is shared between |
5884 | CLI and MI functions for setting a breakpoint. | |
5885 | This function has two major modes of operations, | |
5886 | selected by the PARSE_CONDITION_AND_THREAD parameter. | |
5887 | If non-zero, the function will parse arg, extracting | |
5888 | breakpoint location, address and thread. Otherwise, | |
5889 | ARG is just the location of breakpoint, with condition | |
5890 | and thread specified by the COND_STRING and THREAD | |
5891 | parameters. */ | |
0101ce28 | 5892 | |
98deb0da | 5893 | static void |
a6d9a66e UW |
5894 | break_command_really (struct gdbarch *gdbarch, |
5895 | char *arg, char *cond_string, int thread, | |
60c46647 | 5896 | int parse_condition_and_thread, |
1042e4c0 | 5897 | int tempflag, int hardwareflag, int traceflag, |
60c46647 VP |
5898 | int ignore_count, |
5899 | enum auto_boolean pending_break_support, | |
604133b5 | 5900 | struct breakpoint_ops *ops, |
41447f92 VP |
5901 | int from_tty, |
5902 | int enabled) | |
c3f6f71d | 5903 | { |
71fff37b | 5904 | struct gdb_exception e; |
c3f6f71d | 5905 | struct symtabs_and_lines sals; |
0101ce28 | 5906 | struct symtab_and_line pending_sal; |
0101ce28 JJ |
5907 | char *copy_arg; |
5908 | char *err_msg; | |
c3f6f71d JM |
5909 | char *addr_start = arg; |
5910 | char **addr_string; | |
5911 | struct cleanup *old_chain; | |
80c99de1 | 5912 | struct cleanup *bkpt_chain = NULL; |
0101ce28 | 5913 | struct captured_parse_breakpoint_args parse_args; |
05ff989b | 5914 | int i; |
0101ce28 | 5915 | int pending = 0; |
0101ce28 | 5916 | int not_found = 0; |
1042e4c0 | 5917 | enum bptype type_wanted; |
4a306c9a | 5918 | int task = 0; |
c3f6f71d | 5919 | |
c3f6f71d JM |
5920 | sals.sals = NULL; |
5921 | sals.nelts = 0; | |
5922 | addr_string = NULL; | |
c3f6f71d | 5923 | |
0101ce28 JJ |
5924 | parse_args.arg_p = &arg; |
5925 | parse_args.sals_p = &sals; | |
5926 | parse_args.addr_string_p = &addr_string; | |
5927 | parse_args.not_found_ptr = ¬_found; | |
5928 | ||
05ff989b AC |
5929 | e = catch_exception (uiout, do_captured_parse_breakpoint, |
5930 | &parse_args, RETURN_MASK_ALL); | |
0101ce28 JJ |
5931 | |
5932 | /* If caller is interested in rc value from parse, set value. */ | |
05ff989b | 5933 | switch (e.reason) |
0101ce28 | 5934 | { |
05ff989b | 5935 | case RETURN_QUIT: |
98deb0da | 5936 | throw_exception (e); |
05ff989b AC |
5937 | case RETURN_ERROR: |
5938 | switch (e.error) | |
0101ce28 | 5939 | { |
05ff989b | 5940 | case NOT_FOUND_ERROR: |
0101ce28 | 5941 | |
05ff989b AC |
5942 | /* If pending breakpoint support is turned off, throw |
5943 | error. */ | |
fa8d40ab JJ |
5944 | |
5945 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
5946 | throw_exception (e); |
5947 | ||
5948 | exception_print (gdb_stderr, e); | |
fa8d40ab | 5949 | |
05ff989b AC |
5950 | /* If pending breakpoint support is auto query and the user |
5951 | selects no, then simply return the error code. */ | |
059fb39f PM |
5952 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
5953 | && !nquery ("Make breakpoint pending on future shared library load? ")) | |
98deb0da | 5954 | return; |
fa8d40ab | 5955 | |
05ff989b AC |
5956 | /* At this point, either the user was queried about setting |
5957 | a pending breakpoint and selected yes, or pending | |
5958 | breakpoint behavior is on and thus a pending breakpoint | |
5959 | is defaulted on behalf of the user. */ | |
0101ce28 JJ |
5960 | copy_arg = xstrdup (addr_start); |
5961 | addr_string = ©_arg; | |
5962 | sals.nelts = 1; | |
5963 | sals.sals = &pending_sal; | |
5964 | pending_sal.pc = 0; | |
5965 | pending = 1; | |
05ff989b AC |
5966 | break; |
5967 | default: | |
98deb0da | 5968 | throw_exception (e); |
0101ce28 | 5969 | } |
05ff989b AC |
5970 | default: |
5971 | if (!sals.nelts) | |
98deb0da | 5972 | return; |
0101ce28 | 5973 | } |
c3f6f71d JM |
5974 | |
5975 | /* Create a chain of things that always need to be cleaned up. */ | |
5976 | old_chain = make_cleanup (null_cleanup, 0); | |
5977 | ||
0101ce28 JJ |
5978 | if (!pending) |
5979 | { | |
5980 | /* Make sure that all storage allocated to SALS gets freed. */ | |
5981 | make_cleanup (xfree, sals.sals); | |
5982 | ||
5983 | /* Cleanup the addr_string array but not its contents. */ | |
5984 | make_cleanup (xfree, addr_string); | |
5985 | } | |
c3f6f71d | 5986 | |
c3f6f71d JM |
5987 | /* ----------------------------- SNIP ----------------------------- |
5988 | Anything added to the cleanup chain beyond this point is assumed | |
5989 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
5990 | then the memory is not reclaimed. */ |
5991 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d JM |
5992 | |
5993 | /* Mark the contents of the addr_string for cleanup. These go on | |
80c99de1 | 5994 | the bkpt_chain and only occur if the breakpoint create fails. */ |
c3f6f71d JM |
5995 | for (i = 0; i < sals.nelts; i++) |
5996 | { | |
5997 | if (addr_string[i] != NULL) | |
b8c9b27d | 5998 | make_cleanup (xfree, addr_string[i]); |
c3f6f71d JM |
5999 | } |
6000 | ||
6001 | /* Resolve all line numbers to PC's and verify that the addresses | |
6002 | are ok for the target. */ | |
0101ce28 JJ |
6003 | if (!pending) |
6004 | breakpoint_sals_to_pc (&sals, addr_start); | |
c3f6f71d | 6005 | |
1042e4c0 SS |
6006 | type_wanted = (traceflag |
6007 | ? bp_tracepoint | |
6008 | : (hardwareflag ? bp_hardware_breakpoint : bp_breakpoint)); | |
6009 | ||
c3f6f71d JM |
6010 | /* Verify that condition can be parsed, before setting any |
6011 | breakpoints. Allocate a separate condition expression for each | |
6012 | breakpoint. */ | |
0101ce28 | 6013 | if (!pending) |
c3f6f71d | 6014 | { |
2f069f6f | 6015 | if (parse_condition_and_thread) |
72b2ff0e VP |
6016 | { |
6017 | /* Here we only parse 'arg' to separate condition | |
6018 | from thread number, so parsing in context of first | |
6019 | sal is OK. When setting the breakpoint we'll | |
6020 | re-parse it in context of each sal. */ | |
6021 | cond_string = NULL; | |
6022 | thread = -1; | |
4a306c9a JB |
6023 | find_condition_and_thread (arg, sals.sals[0].pc, &cond_string, |
6024 | &thread, &task); | |
72b2ff0e VP |
6025 | if (cond_string) |
6026 | make_cleanup (xfree, cond_string); | |
6027 | } | |
2f069f6f | 6028 | else |
72b2ff0e VP |
6029 | { |
6030 | /* Create a private copy of condition string. */ | |
6031 | if (cond_string) | |
6032 | { | |
6033 | cond_string = xstrdup (cond_string); | |
6034 | make_cleanup (xfree, cond_string); | |
6035 | } | |
6036 | } | |
a6d9a66e | 6037 | create_breakpoints (gdbarch, sals, addr_string, cond_string, type_wanted, |
0101ce28 | 6038 | tempflag ? disp_del : disp_donttouch, |
4a306c9a | 6039 | thread, task, ignore_count, ops, from_tty, enabled); |
c906108c | 6040 | } |
0101ce28 JJ |
6041 | else |
6042 | { | |
fe3f5fa8 | 6043 | struct symtab_and_line sal = {0}; |
0101ce28 JJ |
6044 | struct breakpoint *b; |
6045 | ||
0101ce28 JJ |
6046 | make_cleanup (xfree, copy_arg); |
6047 | ||
a6d9a66e | 6048 | b = set_raw_breakpoint_without_location (gdbarch, type_wanted); |
0101ce28 JJ |
6049 | set_breakpoint_count (breakpoint_count + 1); |
6050 | b->number = breakpoint_count; | |
72b2ff0e | 6051 | b->thread = -1; |
018d34a4 | 6052 | b->addr_string = addr_string[0]; |
72b2ff0e | 6053 | b->cond_string = NULL; |
0101ce28 | 6054 | b->ignore_count = ignore_count; |
0101ce28 | 6055 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 6056 | b->condition_not_parsed = 1; |
604133b5 | 6057 | b->ops = ops; |
41447f92 | 6058 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
74960c60 | 6059 | |
8bea4e01 UW |
6060 | if (enabled && executing_startup |
6061 | && (b->type == bp_breakpoint | |
6062 | || b->type == bp_hardware_breakpoint)) | |
6063 | b->enable_state = bp_startup_disabled; | |
6064 | ||
0101ce28 JJ |
6065 | mention (b); |
6066 | } | |
6067 | ||
c3f6f71d | 6068 | if (sals.nelts > 1) |
8a3fe4f8 AC |
6069 | warning (_("Multiple breakpoints were set.\n" |
6070 | "Use the \"delete\" command to delete unwanted breakpoints.")); | |
80c99de1 PA |
6071 | /* That's it. Discard the cleanups for data inserted into the |
6072 | breakpoint. */ | |
6073 | discard_cleanups (bkpt_chain); | |
6074 | /* But cleanup everything else. */ | |
c3f6f71d | 6075 | do_cleanups (old_chain); |
217dc9e2 | 6076 | |
80c99de1 | 6077 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
217dc9e2 | 6078 | update_global_location_list (1); |
c3f6f71d | 6079 | } |
c906108c | 6080 | |
72b2ff0e VP |
6081 | /* Set a breakpoint. |
6082 | ARG is a string describing breakpoint address, | |
6083 | condition, and thread. | |
6084 | FLAG specifies if a breakpoint is hardware on, | |
6085 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
6086 | and BP_TEMPFLAG. */ | |
6087 | ||
98deb0da | 6088 | static void |
72b2ff0e | 6089 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 6090 | { |
72b2ff0e VP |
6091 | int hardwareflag = flag & BP_HARDWAREFLAG; |
6092 | int tempflag = flag & BP_TEMPFLAG; | |
c3f6f71d | 6093 | |
a6d9a66e UW |
6094 | break_command_really (get_current_arch (), |
6095 | arg, | |
98deb0da | 6096 | NULL, 0, 1 /* parse arg */, |
1042e4c0 | 6097 | tempflag, hardwareflag, 0 /* traceflag */, |
98deb0da | 6098 | 0 /* Ignore count */, |
604133b5 AR |
6099 | pending_break_support, |
6100 | NULL /* breakpoint_ops */, | |
41447f92 VP |
6101 | from_tty, |
6102 | 1 /* enabled */); | |
c906108c SS |
6103 | } |
6104 | ||
72b2ff0e | 6105 | |
98deb0da | 6106 | void |
a6d9a66e UW |
6107 | set_breakpoint (struct gdbarch *gdbarch, |
6108 | char *address, char *condition, | |
c3f6f71d | 6109 | int hardwareflag, int tempflag, |
ce43223b | 6110 | int thread, int ignore_count, |
41447f92 | 6111 | int pending, int enabled) |
c3f6f71d | 6112 | { |
a6d9a66e UW |
6113 | break_command_really (gdbarch, |
6114 | address, condition, thread, | |
98deb0da | 6115 | 0 /* condition and thread are valid. */, |
1042e4c0 | 6116 | tempflag, hardwareflag, 0 /* traceflag */, |
98deb0da VP |
6117 | ignore_count, |
6118 | pending | |
6119 | ? AUTO_BOOLEAN_TRUE : AUTO_BOOLEAN_FALSE, | |
41447f92 | 6120 | NULL, 0, enabled); |
c3f6f71d JM |
6121 | } |
6122 | ||
6a048695 JB |
6123 | /* Adjust SAL to the first instruction past the function prologue. |
6124 | The end of the prologue is determined using the line table from | |
3daf8fe5 JG |
6125 | the debugging information. explicit_pc and explicit_line are |
6126 | not modified. | |
6a048695 JB |
6127 | |
6128 | If SAL is already past the prologue, then do nothing. */ | |
6129 | ||
6130 | static void | |
6131 | skip_prologue_sal (struct symtab_and_line *sal) | |
6132 | { | |
6133 | struct symbol *sym = find_pc_function (sal->pc); | |
6134 | struct symtab_and_line start_sal; | |
6135 | ||
6136 | if (sym == NULL) | |
6137 | return; | |
6138 | ||
6139 | start_sal = find_function_start_sal (sym, 1); | |
6140 | if (sal->pc < start_sal.pc) | |
3daf8fe5 JG |
6141 | { |
6142 | start_sal.explicit_line = sal->explicit_line; | |
6143 | start_sal.explicit_pc = sal->explicit_pc; | |
6144 | *sal = start_sal; | |
6145 | } | |
6a048695 | 6146 | } |
c3f6f71d | 6147 | |
c906108c SS |
6148 | /* Helper function for break_command_1 and disassemble_command. */ |
6149 | ||
6150 | void | |
fba45db2 | 6151 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
6152 | { |
6153 | CORE_ADDR pc; | |
6154 | ||
6155 | if (sal->pc == 0 && sal->symtab != NULL) | |
6156 | { | |
6157 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 6158 | error (_("No line %d in file \"%s\"."), |
c906108c SS |
6159 | sal->line, sal->symtab->filename); |
6160 | sal->pc = pc; | |
6a048695 JB |
6161 | |
6162 | /* If this SAL corresponds to a breakpoint inserted using | |
6163 | a line number, then skip the function prologue if necessary. */ | |
6164 | if (sal->explicit_line) | |
56ef84b1 TT |
6165 | { |
6166 | /* Preserve the original line number. */ | |
6167 | int saved_line = sal->line; | |
6168 | skip_prologue_sal (sal); | |
6169 | sal->line = saved_line; | |
6170 | } | |
c906108c SS |
6171 | } |
6172 | ||
6173 | if (sal->section == 0 && sal->symtab != NULL) | |
6174 | { | |
6175 | struct blockvector *bv; | |
c5aa993b JM |
6176 | struct block *b; |
6177 | struct symbol *sym; | |
c906108c | 6178 | |
801e3a5b | 6179 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab); |
c906108c SS |
6180 | if (bv != NULL) |
6181 | { | |
7f0df278 | 6182 | sym = block_linkage_function (b); |
c906108c SS |
6183 | if (sym != NULL) |
6184 | { | |
6185 | fixup_symbol_section (sym, sal->symtab->objfile); | |
714835d5 | 6186 | sal->section = SYMBOL_OBJ_SECTION (sym); |
c906108c SS |
6187 | } |
6188 | else | |
6189 | { | |
6190 | /* It really is worthwhile to have the section, so we'll just | |
c5aa993b JM |
6191 | have to look harder. This case can be executed if we have |
6192 | line numbers but no functions (as can happen in assembly | |
6193 | source). */ | |
c906108c | 6194 | |
c5aa993b | 6195 | struct minimal_symbol *msym; |
c906108c SS |
6196 | |
6197 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
6198 | if (msym) | |
714835d5 | 6199 | sal->section = SYMBOL_OBJ_SECTION (msym); |
c906108c SS |
6200 | } |
6201 | } | |
6202 | } | |
6203 | } | |
6204 | ||
6205 | void | |
fba45db2 | 6206 | break_command (char *arg, int from_tty) |
c906108c | 6207 | { |
db107f19 | 6208 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
6209 | } |
6210 | ||
c906108c | 6211 | void |
fba45db2 | 6212 | tbreak_command (char *arg, int from_tty) |
c906108c | 6213 | { |
db107f19 | 6214 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
6215 | } |
6216 | ||
c906108c | 6217 | static void |
fba45db2 | 6218 | hbreak_command (char *arg, int from_tty) |
c906108c | 6219 | { |
db107f19 | 6220 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
6221 | } |
6222 | ||
6223 | static void | |
fba45db2 | 6224 | thbreak_command (char *arg, int from_tty) |
c906108c | 6225 | { |
db107f19 | 6226 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
6227 | } |
6228 | ||
6229 | static void | |
fba45db2 | 6230 | stop_command (char *arg, int from_tty) |
c906108c | 6231 | { |
a3f17187 | 6232 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 6233 | Usage: stop in <function | address>\n\ |
a3f17187 | 6234 | stop at <line>\n")); |
c906108c SS |
6235 | } |
6236 | ||
6237 | static void | |
fba45db2 | 6238 | stopin_command (char *arg, int from_tty) |
c906108c SS |
6239 | { |
6240 | int badInput = 0; | |
6241 | ||
c5aa993b | 6242 | if (arg == (char *) NULL) |
c906108c SS |
6243 | badInput = 1; |
6244 | else if (*arg != '*') | |
6245 | { | |
6246 | char *argptr = arg; | |
6247 | int hasColon = 0; | |
6248 | ||
53a5351d JM |
6249 | /* look for a ':'. If this is a line number specification, then |
6250 | say it is bad, otherwise, it should be an address or | |
6251 | function/method name */ | |
c906108c | 6252 | while (*argptr && !hasColon) |
c5aa993b JM |
6253 | { |
6254 | hasColon = (*argptr == ':'); | |
6255 | argptr++; | |
6256 | } | |
c906108c SS |
6257 | |
6258 | if (hasColon) | |
c5aa993b | 6259 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 6260 | else |
c5aa993b | 6261 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
6262 | } |
6263 | ||
6264 | if (badInput) | |
a3f17187 | 6265 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 6266 | else |
db107f19 | 6267 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
6268 | } |
6269 | ||
6270 | static void | |
fba45db2 | 6271 | stopat_command (char *arg, int from_tty) |
c906108c SS |
6272 | { |
6273 | int badInput = 0; | |
6274 | ||
c5aa993b | 6275 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
6276 | badInput = 1; |
6277 | else | |
6278 | { | |
6279 | char *argptr = arg; | |
6280 | int hasColon = 0; | |
6281 | ||
6282 | /* look for a ':'. If there is a '::' then get out, otherwise | |
c5aa993b | 6283 | it is probably a line number. */ |
c906108c | 6284 | while (*argptr && !hasColon) |
c5aa993b JM |
6285 | { |
6286 | hasColon = (*argptr == ':'); | |
6287 | argptr++; | |
6288 | } | |
c906108c SS |
6289 | |
6290 | if (hasColon) | |
c5aa993b | 6291 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 6292 | else |
c5aa993b | 6293 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
6294 | } |
6295 | ||
6296 | if (badInput) | |
a3f17187 | 6297 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 6298 | else |
db107f19 | 6299 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
6300 | } |
6301 | ||
53a5351d JM |
6302 | /* accessflag: hw_write: watch write, |
6303 | hw_read: watch read, | |
6304 | hw_access: watch access (read or write) */ | |
c906108c | 6305 | static void |
fba45db2 | 6306 | watch_command_1 (char *arg, int accessflag, int from_tty) |
c906108c | 6307 | { |
a6d9a66e | 6308 | struct gdbarch *gdbarch = get_current_arch (); |
d983da9c | 6309 | struct breakpoint *b, *scope_breakpoint = NULL; |
c906108c SS |
6310 | struct symtab_and_line sal; |
6311 | struct expression *exp; | |
6312 | struct block *exp_valid_block; | |
6313 | struct value *val, *mark; | |
6314 | struct frame_info *frame; | |
c906108c SS |
6315 | char *exp_start = NULL; |
6316 | char *exp_end = NULL; | |
37e4754d | 6317 | char *tok, *id_tok_start, *end_tok; |
c906108c SS |
6318 | int toklen; |
6319 | char *cond_start = NULL; | |
6320 | char *cond_end = NULL; | |
6321 | struct expression *cond = NULL; | |
6322 | int i, other_type_used, target_resources_ok = 0; | |
6323 | enum bptype bp_type; | |
6324 | int mem_cnt = 0; | |
37e4754d | 6325 | int thread = -1; |
c906108c | 6326 | |
fe39c653 | 6327 | init_sal (&sal); /* initialize to zeroes */ |
c5aa993b | 6328 | |
37e4754d LM |
6329 | /* Make sure that we actually have parameters to parse. */ |
6330 | if (arg != NULL && arg[0] != '\0') | |
6331 | { | |
6332 | toklen = strlen (arg); /* Size of argument list. */ | |
6333 | ||
6334 | /* Points tok to the end of the argument list. */ | |
6335 | tok = arg + toklen - 1; | |
6336 | ||
6337 | /* Go backwards in the parameters list. Skip the last parameter. | |
6338 | If we're expecting a 'thread <thread_num>' parameter, this should | |
6339 | be the thread identifier. */ | |
6340 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
6341 | tok--; | |
6342 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
6343 | tok--; | |
6344 | ||
6345 | /* Points end_tok to the beginning of the last token. */ | |
6346 | id_tok_start = tok + 1; | |
6347 | ||
6348 | /* Go backwards in the parameters list. Skip one more parameter. | |
6349 | If we're expecting a 'thread <thread_num>' parameter, we should | |
6350 | reach a "thread" token. */ | |
6351 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
6352 | tok--; | |
6353 | ||
6354 | end_tok = tok; | |
6355 | ||
6356 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
6357 | tok--; | |
6358 | ||
6359 | /* Move the pointer forward to skip the whitespace and | |
6360 | calculate the length of the token. */ | |
6361 | tok++; | |
6362 | toklen = end_tok - tok; | |
6363 | ||
6364 | if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
6365 | { | |
6366 | /* At this point we've found a "thread" token, which means | |
6367 | the user is trying to set a watchpoint that triggers | |
6368 | only in a specific thread. */ | |
6369 | char *endp; | |
6370 | ||
6371 | /* Extract the thread ID from the next token. */ | |
6372 | thread = strtol (id_tok_start, &endp, 0); | |
6373 | ||
6374 | /* Check if the user provided a valid numeric value for the | |
6375 | thread ID. */ | |
6376 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
6377 | error (_("Invalid thread ID specification %s."), id_tok_start); | |
6378 | ||
6379 | /* Check if the thread actually exists. */ | |
6380 | if (!valid_thread_id (thread)) | |
6381 | error (_("Unknown thread %d."), thread); | |
6382 | ||
6383 | /* Truncate the string and get rid of the thread <thread_num> | |
6384 | parameter before the parameter list is parsed by the | |
6385 | evaluate_expression() function. */ | |
6386 | *tok = '\0'; | |
6387 | } | |
6388 | } | |
6389 | ||
6390 | /* Parse the rest of the arguments. */ | |
c906108c SS |
6391 | innermost_block = NULL; |
6392 | exp_start = arg; | |
6393 | exp = parse_exp_1 (&arg, 0, 0); | |
6394 | exp_end = arg; | |
fa8a61dc TT |
6395 | /* Remove trailing whitespace from the expression before saving it. |
6396 | This makes the eventual display of the expression string a bit | |
6397 | prettier. */ | |
6398 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
6399 | --exp_end; | |
6400 | ||
c906108c SS |
6401 | exp_valid_block = innermost_block; |
6402 | mark = value_mark (); | |
fa4727a6 DJ |
6403 | fetch_watchpoint_value (exp, &val, NULL, NULL); |
6404 | if (val != NULL) | |
6405 | release_value (val); | |
c906108c SS |
6406 | |
6407 | tok = arg; | |
6408 | while (*tok == ' ' || *tok == '\t') | |
6409 | tok++; | |
6410 | end_tok = tok; | |
6411 | ||
6412 | while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') | |
6413 | end_tok++; | |
6414 | ||
6415 | toklen = end_tok - tok; | |
6416 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
6417 | { | |
6418 | tok = cond_start = end_tok + 1; | |
6419 | cond = parse_exp_1 (&tok, 0, 0); | |
6420 | cond_end = tok; | |
6421 | } | |
6422 | if (*tok) | |
8a3fe4f8 | 6423 | error (_("Junk at end of command.")); |
c906108c | 6424 | |
53a5351d | 6425 | if (accessflag == hw_read) |
c5aa993b | 6426 | bp_type = bp_read_watchpoint; |
53a5351d | 6427 | else if (accessflag == hw_access) |
c5aa993b JM |
6428 | bp_type = bp_access_watchpoint; |
6429 | else | |
6430 | bp_type = bp_hardware_watchpoint; | |
c906108c SS |
6431 | |
6432 | mem_cnt = can_use_hardware_watchpoint (val); | |
6433 | if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint) | |
8a3fe4f8 | 6434 | error (_("Expression cannot be implemented with read/access watchpoint.")); |
c5aa993b JM |
6435 | if (mem_cnt != 0) |
6436 | { | |
6437 | i = hw_watchpoint_used_count (bp_type, &other_type_used); | |
53a5351d | 6438 | target_resources_ok = |
d92524f1 | 6439 | target_can_use_hardware_watchpoint (bp_type, i + mem_cnt, |
53a5351d | 6440 | other_type_used); |
c5aa993b | 6441 | if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint) |
8a3fe4f8 | 6442 | error (_("Target does not support this type of hardware watchpoint.")); |
53a5351d | 6443 | |
c5aa993b | 6444 | if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint) |
8a3fe4f8 | 6445 | error (_("Target can only support one kind of HW watchpoint at a time.")); |
c5aa993b | 6446 | } |
c906108c | 6447 | |
4d28f7a8 KB |
6448 | /* Change the type of breakpoint to an ordinary watchpoint if a hardware |
6449 | watchpoint could not be set. */ | |
6450 | if (!mem_cnt || target_resources_ok <= 0) | |
6451 | bp_type = bp_watchpoint; | |
6452 | ||
d983da9c | 6453 | frame = block_innermost_frame (exp_valid_block); |
d983da9c DJ |
6454 | |
6455 | /* If the expression is "local", then set up a "watchpoint scope" | |
6456 | breakpoint at the point where we've left the scope of the watchpoint | |
6457 | expression. Create the scope breakpoint before the watchpoint, so | |
6458 | that we will encounter it first in bpstat_stop_status. */ | |
edb3359d | 6459 | if (innermost_block && frame) |
d983da9c | 6460 | { |
edb3359d DJ |
6461 | if (frame_id_p (frame_unwind_caller_id (frame))) |
6462 | { | |
6463 | scope_breakpoint | |
a6d9a66e UW |
6464 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
6465 | frame_unwind_caller_pc (frame), | |
edb3359d | 6466 | bp_watchpoint_scope); |
d983da9c | 6467 | |
edb3359d | 6468 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 6469 | |
edb3359d DJ |
6470 | /* Automatically delete the breakpoint when it hits. */ |
6471 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 6472 | |
edb3359d DJ |
6473 | /* Only break in the proper frame (help with recursion). */ |
6474 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); | |
d983da9c | 6475 | |
edb3359d | 6476 | /* Set the address at which we will stop. */ |
a6d9a66e UW |
6477 | scope_breakpoint->loc->gdbarch |
6478 | = frame_unwind_caller_arch (frame); | |
edb3359d DJ |
6479 | scope_breakpoint->loc->requested_address |
6480 | = frame_unwind_caller_pc (frame); | |
6481 | scope_breakpoint->loc->address | |
a6d9a66e UW |
6482 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
6483 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
6484 | scope_breakpoint->type); |
6485 | } | |
d983da9c DJ |
6486 | } |
6487 | ||
c906108c | 6488 | /* Now set up the breakpoint. */ |
a6d9a66e | 6489 | b = set_raw_breakpoint (gdbarch, sal, bp_type); |
c906108c SS |
6490 | set_breakpoint_count (breakpoint_count + 1); |
6491 | b->number = breakpoint_count; | |
37e4754d | 6492 | b->thread = thread; |
b5de0fa7 | 6493 | b->disposition = disp_donttouch; |
c906108c SS |
6494 | b->exp = exp; |
6495 | b->exp_valid_block = exp_valid_block; | |
6496 | b->exp_string = savestring (exp_start, exp_end - exp_start); | |
6497 | b->val = val; | |
fa4727a6 | 6498 | b->val_valid = 1; |
511a6cd4 | 6499 | b->loc->cond = cond; |
c906108c SS |
6500 | if (cond_start) |
6501 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
6502 | else | |
6503 | b->cond_string = 0; | |
c5aa993b | 6504 | |
c906108c | 6505 | if (frame) |
d983da9c | 6506 | b->watchpoint_frame = get_frame_id (frame); |
c906108c | 6507 | else |
35a487f1 | 6508 | b->watchpoint_frame = null_frame_id; |
c906108c | 6509 | |
d983da9c | 6510 | if (scope_breakpoint != NULL) |
c906108c | 6511 | { |
d983da9c DJ |
6512 | /* The scope breakpoint is related to the watchpoint. We will |
6513 | need to act on them together. */ | |
6514 | b->related_breakpoint = scope_breakpoint; | |
6515 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 6516 | } |
d983da9c | 6517 | |
c906108c SS |
6518 | value_free_to_mark (mark); |
6519 | mention (b); | |
b60e7edf | 6520 | update_global_location_list (1); |
c906108c SS |
6521 | } |
6522 | ||
6523 | /* Return count of locations need to be watched and can be handled | |
6524 | in hardware. If the watchpoint can not be handled | |
6525 | in hardware return zero. */ | |
6526 | ||
c906108c | 6527 | static int |
fba45db2 | 6528 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
6529 | { |
6530 | int found_memory_cnt = 0; | |
2e70b7b9 | 6531 | struct value *head = v; |
c906108c SS |
6532 | |
6533 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 6534 | if (!can_use_hw_watchpoints) |
c906108c | 6535 | return 0; |
c5aa993b | 6536 | |
5c44784c JM |
6537 | /* Make sure that the value of the expression depends only upon |
6538 | memory contents, and values computed from them within GDB. If we | |
6539 | find any register references or function calls, we can't use a | |
6540 | hardware watchpoint. | |
6541 | ||
6542 | The idea here is that evaluating an expression generates a series | |
6543 | of values, one holding the value of every subexpression. (The | |
6544 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
6545 | a*b+c.) GDB's values hold almost enough information to establish | |
6546 | the criteria given above --- they identify memory lvalues, | |
6547 | register lvalues, computed values, etcetera. So we can evaluate | |
6548 | the expression, and then scan the chain of values that leaves | |
6549 | behind to decide whether we can detect any possible change to the | |
6550 | expression's final value using only hardware watchpoints. | |
6551 | ||
6552 | However, I don't think that the values returned by inferior | |
6553 | function calls are special in any way. So this function may not | |
6554 | notice that an expression involving an inferior function call | |
6555 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 6556 | for (; v; v = value_next (v)) |
c906108c | 6557 | { |
5c44784c | 6558 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 6559 | { |
d69fe07e | 6560 | if (value_lazy (v)) |
5c44784c JM |
6561 | /* A lazy memory lvalue is one that GDB never needed to fetch; |
6562 | we either just used its address (e.g., `a' in `a.b') or | |
6563 | we never needed it at all (e.g., `a' in `a,b'). */ | |
6564 | ; | |
53a5351d | 6565 | else |
5c44784c JM |
6566 | { |
6567 | /* Ahh, memory we actually used! Check if we can cover | |
6568 | it with hardware watchpoints. */ | |
df407dfe | 6569 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
6570 | |
6571 | /* We only watch structs and arrays if user asked for it | |
6572 | explicitly, never if they just happen to appear in a | |
6573 | middle of some value chain. */ | |
6574 | if (v == head | |
6575 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
6576 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
6577 | { | |
42ae5230 | 6578 | CORE_ADDR vaddr = value_address (v); |
df407dfe | 6579 | int len = TYPE_LENGTH (value_type (v)); |
2e70b7b9 | 6580 | |
d92524f1 | 6581 | if (!target_region_ok_for_hw_watchpoint (vaddr, len)) |
2e70b7b9 MS |
6582 | return 0; |
6583 | else | |
6584 | found_memory_cnt++; | |
6585 | } | |
5c44784c | 6586 | } |
c5aa993b | 6587 | } |
5086187c AC |
6588 | else if (VALUE_LVAL (v) != not_lval |
6589 | && deprecated_value_modifiable (v) == 0) | |
53a5351d | 6590 | return 0; /* ??? What does this represent? */ |
5086187c | 6591 | else if (VALUE_LVAL (v) == lval_register) |
53a5351d | 6592 | return 0; /* cannot watch a register with a HW watchpoint */ |
c906108c SS |
6593 | } |
6594 | ||
6595 | /* The expression itself looks suitable for using a hardware | |
6596 | watchpoint, but give the target machine a chance to reject it. */ | |
6597 | return found_memory_cnt; | |
6598 | } | |
6599 | ||
8b93c638 | 6600 | void |
fba45db2 | 6601 | watch_command_wrapper (char *arg, int from_tty) |
8b93c638 JM |
6602 | { |
6603 | watch_command (arg, from_tty); | |
6604 | } | |
8926118c | 6605 | |
c5aa993b | 6606 | static void |
fba45db2 | 6607 | watch_command (char *arg, int from_tty) |
c906108c | 6608 | { |
53a5351d | 6609 | watch_command_1 (arg, hw_write, from_tty); |
c906108c SS |
6610 | } |
6611 | ||
8b93c638 | 6612 | void |
fba45db2 | 6613 | rwatch_command_wrapper (char *arg, int from_tty) |
8b93c638 JM |
6614 | { |
6615 | rwatch_command (arg, from_tty); | |
6616 | } | |
8926118c | 6617 | |
c5aa993b | 6618 | static void |
fba45db2 | 6619 | rwatch_command (char *arg, int from_tty) |
c906108c | 6620 | { |
53a5351d | 6621 | watch_command_1 (arg, hw_read, from_tty); |
c906108c SS |
6622 | } |
6623 | ||
8b93c638 | 6624 | void |
fba45db2 | 6625 | awatch_command_wrapper (char *arg, int from_tty) |
8b93c638 JM |
6626 | { |
6627 | awatch_command (arg, from_tty); | |
6628 | } | |
8926118c | 6629 | |
c5aa993b | 6630 | static void |
fba45db2 | 6631 | awatch_command (char *arg, int from_tty) |
c906108c | 6632 | { |
53a5351d | 6633 | watch_command_1 (arg, hw_access, from_tty); |
c906108c | 6634 | } |
c906108c | 6635 | \f |
c5aa993b | 6636 | |
43ff13b4 | 6637 | /* Helper routines for the until_command routine in infcmd.c. Here |
c906108c SS |
6638 | because it uses the mechanisms of breakpoints. */ |
6639 | ||
bfec99b2 PA |
6640 | struct until_break_command_continuation_args |
6641 | { | |
6642 | struct breakpoint *breakpoint; | |
6643 | struct breakpoint *breakpoint2; | |
6644 | }; | |
6645 | ||
43ff13b4 JM |
6646 | /* This function is called by fetch_inferior_event via the |
6647 | cmd_continuation pointer, to complete the until command. It takes | |
6648 | care of cleaning up the temporary breakpoints set up by the until | |
6649 | command. */ | |
c2c6d25f | 6650 | static void |
604ead4a | 6651 | until_break_command_continuation (void *arg) |
43ff13b4 | 6652 | { |
bfec99b2 PA |
6653 | struct until_break_command_continuation_args *a = arg; |
6654 | ||
6655 | delete_breakpoint (a->breakpoint); | |
6656 | if (a->breakpoint2) | |
6657 | delete_breakpoint (a->breakpoint2); | |
43ff13b4 JM |
6658 | } |
6659 | ||
c906108c | 6660 | void |
ae66c1fc | 6661 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
6662 | { |
6663 | struct symtabs_and_lines sals; | |
6664 | struct symtab_and_line sal; | |
206415a3 | 6665 | struct frame_info *frame = get_selected_frame (NULL); |
c906108c | 6666 | struct breakpoint *breakpoint; |
f107f563 | 6667 | struct breakpoint *breakpoint2 = NULL; |
c906108c SS |
6668 | struct cleanup *old_chain; |
6669 | ||
6670 | clear_proceed_status (); | |
6671 | ||
6672 | /* Set a breakpoint where the user wants it and at return from | |
6673 | this function */ | |
c5aa993b | 6674 | |
c906108c SS |
6675 | if (default_breakpoint_valid) |
6676 | sals = decode_line_1 (&arg, 1, default_breakpoint_symtab, | |
68219205 | 6677 | default_breakpoint_line, (char ***) NULL, NULL); |
c906108c | 6678 | else |
53a5351d | 6679 | sals = decode_line_1 (&arg, 1, (struct symtab *) NULL, |
68219205 | 6680 | 0, (char ***) NULL, NULL); |
c5aa993b | 6681 | |
c906108c | 6682 | if (sals.nelts != 1) |
8a3fe4f8 | 6683 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 6684 | |
c906108c | 6685 | sal = sals.sals[0]; |
b8c9b27d | 6686 | xfree (sals.sals); /* malloc'd, so freed */ |
c5aa993b | 6687 | |
c906108c | 6688 | if (*arg) |
8a3fe4f8 | 6689 | error (_("Junk at end of arguments.")); |
c5aa993b | 6690 | |
c906108c | 6691 | resolve_sal_pc (&sal); |
c5aa993b | 6692 | |
ae66c1fc EZ |
6693 | if (anywhere) |
6694 | /* If the user told us to continue until a specified location, | |
6695 | we don't specify a frame at which we need to stop. */ | |
a6d9a66e UW |
6696 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
6697 | null_frame_id, bp_until); | |
ae66c1fc | 6698 | else |
edb3359d | 6699 | /* Otherwise, specify the selected frame, because we want to stop only |
ae66c1fc | 6700 | at the very same frame. */ |
a6d9a66e UW |
6701 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
6702 | get_stack_frame_id (frame), | |
ae66c1fc | 6703 | bp_until); |
c5aa993b | 6704 | |
f107f563 | 6705 | old_chain = make_cleanup_delete_breakpoint (breakpoint); |
c906108c | 6706 | |
ae66c1fc EZ |
6707 | /* Keep within the current frame, or in frames called by the current |
6708 | one. */ | |
edb3359d DJ |
6709 | |
6710 | if (frame_id_p (frame_unwind_caller_id (frame))) | |
c906108c | 6711 | { |
edb3359d DJ |
6712 | sal = find_pc_line (frame_unwind_caller_pc (frame), 0); |
6713 | sal.pc = frame_unwind_caller_pc (frame); | |
a6d9a66e UW |
6714 | breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame), |
6715 | sal, | |
edb3359d | 6716 | frame_unwind_caller_id (frame), |
f107f563 VP |
6717 | bp_until); |
6718 | make_cleanup_delete_breakpoint (breakpoint2); | |
c906108c | 6719 | } |
c5aa993b | 6720 | |
c906108c | 6721 | proceed (-1, TARGET_SIGNAL_DEFAULT, 0); |
f107f563 VP |
6722 | |
6723 | /* If we are running asynchronously, and proceed call above has actually | |
6724 | managed to start the target, arrange for breakpoints to be | |
6725 | deleted when the target stops. Otherwise, we're already stopped and | |
6726 | delete breakpoints via cleanup chain. */ | |
6727 | ||
8ea051c5 | 6728 | if (target_can_async_p () && is_running (inferior_ptid)) |
f107f563 | 6729 | { |
bfec99b2 PA |
6730 | struct until_break_command_continuation_args *args; |
6731 | args = xmalloc (sizeof (*args)); | |
f107f563 | 6732 | |
bfec99b2 PA |
6733 | args->breakpoint = breakpoint; |
6734 | args->breakpoint2 = breakpoint2; | |
f107f563 VP |
6735 | |
6736 | discard_cleanups (old_chain); | |
95e54da7 PA |
6737 | add_continuation (inferior_thread (), |
6738 | until_break_command_continuation, args, | |
604ead4a | 6739 | xfree); |
f107f563 VP |
6740 | } |
6741 | else | |
c5aa993b | 6742 | do_cleanups (old_chain); |
c906108c | 6743 | } |
ae66c1fc | 6744 | |
c906108c | 6745 | static void |
fba45db2 | 6746 | ep_skip_leading_whitespace (char **s) |
c906108c | 6747 | { |
c5aa993b JM |
6748 | if ((s == NULL) || (*s == NULL)) |
6749 | return; | |
6750 | while (isspace (**s)) | |
6751 | *s += 1; | |
c906108c | 6752 | } |
c5aa993b | 6753 | |
c906108c SS |
6754 | /* This function attempts to parse an optional "if <cond>" clause |
6755 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 6756 | |
c906108c SS |
6757 | Else, it returns a pointer to the condition string. (It does not |
6758 | attempt to evaluate the string against a particular block.) And, | |
6759 | it updates arg to point to the first character following the parsed | |
6760 | if clause in the arg string. */ | |
53a5351d | 6761 | |
c906108c | 6762 | static char * |
fba45db2 | 6763 | ep_parse_optional_if_clause (char **arg) |
c906108c | 6764 | { |
c5aa993b JM |
6765 | char *cond_string; |
6766 | ||
6767 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 6768 | return NULL; |
c5aa993b | 6769 | |
c906108c SS |
6770 | /* Skip the "if" keyword. */ |
6771 | (*arg) += 2; | |
c5aa993b | 6772 | |
c906108c SS |
6773 | /* Skip any extra leading whitespace, and record the start of the |
6774 | condition string. */ | |
6775 | ep_skip_leading_whitespace (arg); | |
6776 | cond_string = *arg; | |
c5aa993b | 6777 | |
c906108c SS |
6778 | /* Assume that the condition occupies the remainder of the arg string. */ |
6779 | (*arg) += strlen (cond_string); | |
c5aa993b | 6780 | |
c906108c SS |
6781 | return cond_string; |
6782 | } | |
c5aa993b | 6783 | |
c906108c SS |
6784 | /* This function attempts to parse an optional filename from the arg |
6785 | string. If one is not found, it returns NULL. | |
c5aa993b | 6786 | |
c906108c SS |
6787 | Else, it returns a pointer to the parsed filename. (This function |
6788 | makes no attempt to verify that a file of that name exists, or is | |
6789 | accessible.) And, it updates arg to point to the first character | |
6790 | following the parsed filename in the arg string. | |
c5aa993b | 6791 | |
c906108c SS |
6792 | Note that clients needing to preserve the returned filename for |
6793 | future access should copy it to their own buffers. */ | |
6794 | static char * | |
fba45db2 | 6795 | ep_parse_optional_filename (char **arg) |
c906108c | 6796 | { |
c5aa993b JM |
6797 | static char filename[1024]; |
6798 | char *arg_p = *arg; | |
6799 | int i; | |
6800 | char c; | |
6801 | ||
c906108c SS |
6802 | if ((*arg_p == '\0') || isspace (*arg_p)) |
6803 | return NULL; | |
c5aa993b JM |
6804 | |
6805 | for (i = 0;; i++) | |
c906108c SS |
6806 | { |
6807 | c = *arg_p; | |
6808 | if (isspace (c)) | |
c5aa993b | 6809 | c = '\0'; |
c906108c SS |
6810 | filename[i] = c; |
6811 | if (c == '\0') | |
c5aa993b | 6812 | break; |
c906108c SS |
6813 | arg_p++; |
6814 | } | |
6815 | *arg = arg_p; | |
c5aa993b | 6816 | |
c906108c SS |
6817 | return filename; |
6818 | } | |
c5aa993b | 6819 | |
c906108c SS |
6820 | /* Commands to deal with catching events, such as signals, exceptions, |
6821 | process start/exit, etc. */ | |
c5aa993b JM |
6822 | |
6823 | typedef enum | |
6824 | { | |
44feb3ce TT |
6825 | catch_fork_temporary, catch_vfork_temporary, |
6826 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
6827 | } |
6828 | catch_fork_kind; | |
6829 | ||
c906108c | 6830 | static void |
44feb3ce | 6831 | catch_fork_command_1 (char *arg, int from_tty, struct cmd_list_element *command) |
c906108c | 6832 | { |
a6d9a66e | 6833 | struct gdbarch *gdbarch = get_current_arch (); |
c5aa993b | 6834 | char *cond_string = NULL; |
44feb3ce TT |
6835 | catch_fork_kind fork_kind; |
6836 | int tempflag; | |
6837 | ||
6838 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
6839 | tempflag = (fork_kind == catch_fork_temporary | |
6840 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 6841 | |
44feb3ce TT |
6842 | if (!arg) |
6843 | arg = ""; | |
c906108c | 6844 | ep_skip_leading_whitespace (&arg); |
c5aa993b | 6845 | |
c906108c | 6846 | /* The allowed syntax is: |
c5aa993b JM |
6847 | catch [v]fork |
6848 | catch [v]fork if <cond> | |
6849 | ||
c906108c SS |
6850 | First, check if there's an if clause. */ |
6851 | cond_string = ep_parse_optional_if_clause (&arg); | |
c5aa993b | 6852 | |
c906108c | 6853 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 6854 | error (_("Junk at end of arguments.")); |
c5aa993b | 6855 | |
c906108c SS |
6856 | /* If this target supports it, create a fork or vfork catchpoint |
6857 | and enable reporting of such events. */ | |
c5aa993b JM |
6858 | switch (fork_kind) |
6859 | { | |
44feb3ce TT |
6860 | case catch_fork_temporary: |
6861 | case catch_fork_permanent: | |
a6d9a66e | 6862 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 6863 | &catch_fork_breakpoint_ops); |
c906108c | 6864 | break; |
44feb3ce TT |
6865 | case catch_vfork_temporary: |
6866 | case catch_vfork_permanent: | |
a6d9a66e | 6867 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 6868 | &catch_vfork_breakpoint_ops); |
c906108c | 6869 | break; |
c5aa993b | 6870 | default: |
8a3fe4f8 | 6871 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 6872 | break; |
c5aa993b | 6873 | } |
c906108c SS |
6874 | } |
6875 | ||
6876 | static void | |
44feb3ce | 6877 | catch_exec_command_1 (char *arg, int from_tty, struct cmd_list_element *command) |
c906108c | 6878 | { |
a6d9a66e | 6879 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 6880 | int tempflag; |
c5aa993b | 6881 | char *cond_string = NULL; |
c906108c | 6882 | |
44feb3ce TT |
6883 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
6884 | ||
6885 | if (!arg) | |
6886 | arg = ""; | |
c906108c SS |
6887 | ep_skip_leading_whitespace (&arg); |
6888 | ||
6889 | /* The allowed syntax is: | |
c5aa993b JM |
6890 | catch exec |
6891 | catch exec if <cond> | |
c906108c SS |
6892 | |
6893 | First, check if there's an if clause. */ | |
6894 | cond_string = ep_parse_optional_if_clause (&arg); | |
6895 | ||
6896 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 6897 | error (_("Junk at end of arguments.")); |
c906108c SS |
6898 | |
6899 | /* If this target supports it, create an exec catchpoint | |
6900 | and enable reporting of such events. */ | |
a6d9a66e UW |
6901 | create_catchpoint (gdbarch, tempflag, cond_string, |
6902 | &catch_exec_breakpoint_ops); | |
c906108c | 6903 | } |
c5aa993b | 6904 | |
3086aeae DJ |
6905 | static enum print_stop_action |
6906 | print_exception_catchpoint (struct breakpoint *b) | |
6907 | { | |
ade92717 | 6908 | int bp_temp, bp_throw; |
3086aeae | 6909 | |
ade92717 | 6910 | annotate_catchpoint (b->number); |
3086aeae | 6911 | |
ade92717 AR |
6912 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
6913 | if (b->loc->address != b->loc->requested_address) | |
6914 | breakpoint_adjustment_warning (b->loc->requested_address, | |
6915 | b->loc->address, | |
6916 | b->number, 1); | |
df2b6d2d | 6917 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
6918 | ui_out_text (uiout, |
6919 | bp_temp ? "Temporary catchpoint " | |
6920 | : "Catchpoint "); | |
6921 | if (!ui_out_is_mi_like_p (uiout)) | |
6922 | ui_out_field_int (uiout, "bkptno", b->number); | |
6923 | ui_out_text (uiout, | |
c0b37c48 AR |
6924 | bp_throw ? " (exception thrown), " |
6925 | : " (exception caught), "); | |
ade92717 AR |
6926 | if (ui_out_is_mi_like_p (uiout)) |
6927 | { | |
6928 | ui_out_field_string (uiout, "reason", | |
6929 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
6930 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
6931 | ui_out_field_int (uiout, "bkptno", b->number); | |
6932 | } | |
3086aeae DJ |
6933 | return PRINT_SRC_AND_LOC; |
6934 | } | |
6935 | ||
6936 | static void | |
a6d9a66e | 6937 | print_one_exception_catchpoint (struct breakpoint *b, struct bp_location **last_loc) |
3086aeae | 6938 | { |
79a45b7d TT |
6939 | struct value_print_options opts; |
6940 | get_user_print_options (&opts); | |
6941 | if (opts.addressprint) | |
3086aeae DJ |
6942 | { |
6943 | annotate_field (4); | |
604133b5 AR |
6944 | if (b->loc == NULL || b->loc->shlib_disabled) |
6945 | ui_out_field_string (uiout, "addr", "<PENDING>"); | |
6946 | else | |
5af949e3 UW |
6947 | ui_out_field_core_addr (uiout, "addr", |
6948 | b->loc->gdbarch, b->loc->address); | |
3086aeae DJ |
6949 | } |
6950 | annotate_field (5); | |
604133b5 | 6951 | if (b->loc) |
a6d9a66e | 6952 | *last_loc = b->loc; |
3086aeae DJ |
6953 | if (strstr (b->addr_string, "throw") != NULL) |
6954 | ui_out_field_string (uiout, "what", "exception throw"); | |
6955 | else | |
6956 | ui_out_field_string (uiout, "what", "exception catch"); | |
6957 | } | |
6958 | ||
6959 | static void | |
6960 | print_mention_exception_catchpoint (struct breakpoint *b) | |
6961 | { | |
ade92717 AR |
6962 | int bp_temp; |
6963 | int bp_throw; | |
6964 | ||
df2b6d2d | 6965 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
6966 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
6967 | ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ") | |
6968 | : _("Catchpoint ")); | |
6969 | ui_out_field_int (uiout, "bkptno", b->number); | |
6970 | ui_out_text (uiout, bp_throw ? _(" (throw)") | |
6971 | : _(" (catch)")); | |
3086aeae DJ |
6972 | } |
6973 | ||
6974 | static struct breakpoint_ops gnu_v3_exception_catchpoint_ops = { | |
ce78b96d JB |
6975 | NULL, /* insert */ |
6976 | NULL, /* remove */ | |
6977 | NULL, /* breakpoint_hit */ | |
3086aeae DJ |
6978 | print_exception_catchpoint, |
6979 | print_one_exception_catchpoint, | |
6980 | print_mention_exception_catchpoint | |
6981 | }; | |
6982 | ||
6983 | static int | |
6984 | handle_gnu_v3_exceptions (int tempflag, char *cond_string, | |
6985 | enum exception_event_kind ex_event, int from_tty) | |
6986 | { | |
604133b5 AR |
6987 | char *trigger_func_name; |
6988 | ||
3086aeae | 6989 | if (ex_event == EX_EVENT_CATCH) |
604133b5 | 6990 | trigger_func_name = "__cxa_begin_catch"; |
3086aeae | 6991 | else |
604133b5 | 6992 | trigger_func_name = "__cxa_throw"; |
3086aeae | 6993 | |
a6d9a66e UW |
6994 | break_command_really (get_current_arch (), |
6995 | trigger_func_name, cond_string, -1, | |
604133b5 | 6996 | 0 /* condition and thread are valid. */, |
1042e4c0 | 6997 | tempflag, 0, 0, |
604133b5 AR |
6998 | 0, |
6999 | AUTO_BOOLEAN_TRUE /* pending */, | |
41447f92 VP |
7000 | &gnu_v3_exception_catchpoint_ops, from_tty, |
7001 | 1 /* enabled */); | |
3086aeae | 7002 | |
3086aeae DJ |
7003 | return 1; |
7004 | } | |
7005 | ||
c5aa993b | 7006 | /* Deal with "catch catch" and "catch throw" commands */ |
c906108c SS |
7007 | |
7008 | static void | |
fba45db2 KB |
7009 | catch_exception_command_1 (enum exception_event_kind ex_event, char *arg, |
7010 | int tempflag, int from_tty) | |
c906108c | 7011 | { |
c5aa993b JM |
7012 | char *cond_string = NULL; |
7013 | struct symtab_and_line *sal = NULL; | |
7014 | ||
44feb3ce TT |
7015 | if (!arg) |
7016 | arg = ""; | |
c906108c | 7017 | ep_skip_leading_whitespace (&arg); |
c5aa993b | 7018 | |
c906108c SS |
7019 | cond_string = ep_parse_optional_if_clause (&arg); |
7020 | ||
7021 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 7022 | error (_("Junk at end of arguments.")); |
c906108c | 7023 | |
059fb39f PM |
7024 | if (ex_event != EX_EVENT_THROW |
7025 | && ex_event != EX_EVENT_CATCH) | |
8a3fe4f8 | 7026 | error (_("Unsupported or unknown exception event; cannot catch it")); |
c906108c | 7027 | |
3086aeae DJ |
7028 | if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty)) |
7029 | return; | |
7030 | ||
8a3fe4f8 | 7031 | warning (_("Unsupported with this platform/compiler combination.")); |
c906108c SS |
7032 | } |
7033 | ||
44feb3ce TT |
7034 | /* Implementation of "catch catch" command. */ |
7035 | ||
7036 | static void | |
7037 | catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command) | |
7038 | { | |
7039 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
7040 | catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty); | |
7041 | } | |
7042 | ||
7043 | /* Implementation of "catch throw" command. */ | |
7044 | ||
7045 | static void | |
7046 | catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command) | |
7047 | { | |
7048 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
7049 | catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty); | |
7050 | } | |
7051 | ||
f7f9143b JB |
7052 | /* Create a breakpoint struct for Ada exception catchpoints. */ |
7053 | ||
7054 | static void | |
a6d9a66e UW |
7055 | create_ada_exception_breakpoint (struct gdbarch *gdbarch, |
7056 | struct symtab_and_line sal, | |
f7f9143b JB |
7057 | char *addr_string, |
7058 | char *exp_string, | |
7059 | char *cond_string, | |
7060 | struct expression *cond, | |
7061 | struct breakpoint_ops *ops, | |
7062 | int tempflag, | |
7063 | int from_tty) | |
7064 | { | |
7065 | struct breakpoint *b; | |
7066 | ||
7067 | if (from_tty) | |
7068 | { | |
5af949e3 UW |
7069 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
7070 | if (!loc_gdbarch) | |
7071 | loc_gdbarch = gdbarch; | |
7072 | ||
7073 | describe_other_breakpoints (loc_gdbarch, sal.pc, sal.section, -1); | |
f7f9143b JB |
7074 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
7075 | version for exception catchpoints, because two catchpoints | |
7076 | used for different exception names will use the same address. | |
7077 | In this case, a "breakpoint ... also set at..." warning is | |
7078 | unproductive. Besides. the warning phrasing is also a bit | |
7079 | inapropriate, we should use the word catchpoint, and tell | |
7080 | the user what type of catchpoint it is. The above is good | |
7081 | enough for now, though. */ | |
7082 | } | |
7083 | ||
a6d9a66e | 7084 | b = set_raw_breakpoint (gdbarch, sal, bp_breakpoint); |
f7f9143b JB |
7085 | set_breakpoint_count (breakpoint_count + 1); |
7086 | ||
7087 | b->enable_state = bp_enabled; | |
7088 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
7089 | b->number = breakpoint_count; | |
7090 | b->ignore_count = 0; | |
511a6cd4 | 7091 | b->loc->cond = cond; |
f7f9143b JB |
7092 | b->addr_string = addr_string; |
7093 | b->language = language_ada; | |
7094 | b->cond_string = cond_string; | |
7095 | b->exp_string = exp_string; | |
7096 | b->thread = -1; | |
7097 | b->ops = ops; | |
f7f9143b JB |
7098 | |
7099 | mention (b); | |
b60e7edf | 7100 | update_global_location_list (1); |
f7f9143b JB |
7101 | } |
7102 | ||
7103 | /* Implement the "catch exception" command. */ | |
7104 | ||
7105 | static void | |
44feb3ce TT |
7106 | catch_ada_exception_command (char *arg, int from_tty, |
7107 | struct cmd_list_element *command) | |
f7f9143b | 7108 | { |
a6d9a66e | 7109 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 7110 | int tempflag; |
f7f9143b JB |
7111 | struct symtab_and_line sal; |
7112 | enum bptype type; | |
7113 | char *addr_string = NULL; | |
7114 | char *exp_string = NULL; | |
7115 | char *cond_string = NULL; | |
7116 | struct expression *cond = 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 JB |
7123 | sal = ada_decode_exception_location (arg, &addr_string, &exp_string, |
7124 | &cond_string, &cond, &ops); | |
a6d9a66e | 7125 | create_ada_exception_breakpoint (gdbarch, sal, addr_string, exp_string, |
f7f9143b JB |
7126 | cond_string, cond, ops, tempflag, |
7127 | from_tty); | |
7128 | } | |
7129 | ||
7130 | /* Implement the "catch assert" command. */ | |
7131 | ||
7132 | static void | |
44feb3ce | 7133 | catch_assert_command (char *arg, int from_tty, struct cmd_list_element *command) |
f7f9143b | 7134 | { |
a6d9a66e | 7135 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 7136 | int tempflag; |
f7f9143b JB |
7137 | struct symtab_and_line sal; |
7138 | char *addr_string = NULL; | |
7139 | struct breakpoint_ops *ops = NULL; | |
7140 | ||
44feb3ce TT |
7141 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
7142 | ||
7143 | if (!arg) | |
7144 | arg = ""; | |
f7f9143b | 7145 | sal = ada_decode_assert_location (arg, &addr_string, &ops); |
a6d9a66e UW |
7146 | create_ada_exception_breakpoint (gdbarch, sal, addr_string, NULL, NULL, NULL, |
7147 | ops, tempflag, from_tty); | |
f7f9143b JB |
7148 | } |
7149 | ||
c906108c | 7150 | static void |
fba45db2 | 7151 | catch_command (char *arg, int from_tty) |
c906108c | 7152 | { |
44feb3ce | 7153 | error (_("Catch requires an event name.")); |
c906108c SS |
7154 | } |
7155 | \f | |
7156 | ||
7157 | static void | |
fba45db2 | 7158 | tcatch_command (char *arg, int from_tty) |
c906108c | 7159 | { |
44feb3ce | 7160 | error (_("Catch requires an event name.")); |
c906108c SS |
7161 | } |
7162 | ||
80f8a6eb | 7163 | /* Delete breakpoints by address or line. */ |
c906108c SS |
7164 | |
7165 | static void | |
fba45db2 | 7166 | clear_command (char *arg, int from_tty) |
c906108c | 7167 | { |
d6e956e5 VP |
7168 | struct breakpoint *b; |
7169 | VEC(breakpoint_p) *found = 0; | |
7170 | int ix; | |
c906108c SS |
7171 | int default_match; |
7172 | struct symtabs_and_lines sals; | |
7173 | struct symtab_and_line sal; | |
c906108c SS |
7174 | int i; |
7175 | ||
7176 | if (arg) | |
7177 | { | |
7178 | sals = decode_line_spec (arg, 1); | |
7179 | default_match = 0; | |
7180 | } | |
7181 | else | |
7182 | { | |
c5aa993b | 7183 | sals.sals = (struct symtab_and_line *) |
c906108c | 7184 | xmalloc (sizeof (struct symtab_and_line)); |
80f8a6eb | 7185 | make_cleanup (xfree, sals.sals); |
fe39c653 | 7186 | init_sal (&sal); /* initialize to zeroes */ |
c906108c SS |
7187 | sal.line = default_breakpoint_line; |
7188 | sal.symtab = default_breakpoint_symtab; | |
7189 | sal.pc = default_breakpoint_address; | |
7190 | if (sal.symtab == 0) | |
8a3fe4f8 | 7191 | error (_("No source file specified.")); |
c906108c SS |
7192 | |
7193 | sals.sals[0] = sal; | |
7194 | sals.nelts = 1; | |
7195 | ||
7196 | default_match = 1; | |
7197 | } | |
7198 | ||
ed0616c6 VP |
7199 | /* We don't call resolve_sal_pc here. That's not |
7200 | as bad as it seems, because all existing breakpoints | |
7201 | typically have both file/line and pc set. So, if | |
7202 | clear is given file/line, we can match this to existing | |
7203 | breakpoint without obtaining pc at all. | |
7204 | ||
7205 | We only support clearing given the address explicitly | |
7206 | present in breakpoint table. Say, we've set breakpoint | |
7207 | at file:line. There were several PC values for that file:line, | |
7208 | due to optimization, all in one block. | |
7209 | We've picked one PC value. If "clear" is issued with another | |
7210 | PC corresponding to the same file:line, the breakpoint won't | |
7211 | be cleared. We probably can still clear the breakpoint, but | |
7212 | since the other PC value is never presented to user, user | |
7213 | can only find it by guessing, and it does not seem important | |
7214 | to support that. */ | |
7215 | ||
c906108c | 7216 | /* For each line spec given, delete bps which correspond |
80f8a6eb MS |
7217 | to it. Do it in two passes, solely to preserve the current |
7218 | behavior that from_tty is forced true if we delete more than | |
7219 | one breakpoint. */ | |
c906108c | 7220 | |
80f8a6eb | 7221 | found = NULL; |
c906108c SS |
7222 | for (i = 0; i < sals.nelts; i++) |
7223 | { | |
7224 | /* If exact pc given, clear bpts at that pc. | |
c5aa993b JM |
7225 | If line given (pc == 0), clear all bpts on specified line. |
7226 | If defaulting, clear all bpts on default line | |
c906108c | 7227 | or at default pc. |
c5aa993b JM |
7228 | |
7229 | defaulting sal.pc != 0 tests to do | |
7230 | ||
7231 | 0 1 pc | |
7232 | 1 1 pc _and_ line | |
7233 | 0 0 line | |
7234 | 1 0 <can't happen> */ | |
c906108c SS |
7235 | |
7236 | sal = sals.sals[i]; | |
c906108c | 7237 | |
d6e956e5 VP |
7238 | /* Find all matching breakpoints and add them to |
7239 | 'found'. */ | |
7240 | ALL_BREAKPOINTS (b) | |
c5aa993b | 7241 | { |
0d381245 | 7242 | int match = 0; |
80f8a6eb MS |
7243 | /* Are we going to delete b? */ |
7244 | if (b->type != bp_none | |
7245 | && b->type != bp_watchpoint | |
7246 | && b->type != bp_hardware_watchpoint | |
7247 | && b->type != bp_read_watchpoint | |
0d381245 VP |
7248 | && b->type != bp_access_watchpoint) |
7249 | { | |
7250 | struct bp_location *loc = b->loc; | |
7251 | for (; loc; loc = loc->next) | |
7252 | { | |
7253 | int pc_match = sal.pc | |
7254 | && (loc->address == sal.pc) | |
7255 | && (!section_is_overlay (loc->section) | |
7256 | || loc->section == sal.section); | |
7257 | int line_match = ((default_match || (0 == sal.pc)) | |
7258 | && b->source_file != NULL | |
7259 | && sal.symtab != NULL | |
7260 | && strcmp (b->source_file, sal.symtab->filename) == 0 | |
7261 | && b->line_number == sal.line); | |
7262 | if (pc_match || line_match) | |
7263 | { | |
7264 | match = 1; | |
7265 | break; | |
7266 | } | |
7267 | } | |
7268 | } | |
7269 | ||
7270 | if (match) | |
d6e956e5 | 7271 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 7272 | } |
80f8a6eb MS |
7273 | } |
7274 | /* Now go thru the 'found' chain and delete them. */ | |
d6e956e5 | 7275 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
7276 | { |
7277 | if (arg) | |
8a3fe4f8 | 7278 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 7279 | else |
8a3fe4f8 | 7280 | error (_("No breakpoint at this line.")); |
80f8a6eb | 7281 | } |
c906108c | 7282 | |
d6e956e5 | 7283 | if (VEC_length(breakpoint_p, found) > 1) |
80f8a6eb MS |
7284 | from_tty = 1; /* Always report if deleted more than one */ |
7285 | if (from_tty) | |
a3f17187 | 7286 | { |
d6e956e5 | 7287 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
7288 | printf_unfiltered (_("Deleted breakpoint ")); |
7289 | else | |
7290 | printf_unfiltered (_("Deleted breakpoints ")); | |
7291 | } | |
80f8a6eb | 7292 | breakpoints_changed (); |
d6e956e5 VP |
7293 | |
7294 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 7295 | { |
c5aa993b | 7296 | if (from_tty) |
d6e956e5 VP |
7297 | printf_unfiltered ("%d ", b->number); |
7298 | delete_breakpoint (b); | |
c906108c | 7299 | } |
80f8a6eb MS |
7300 | if (from_tty) |
7301 | putchar_unfiltered ('\n'); | |
c906108c SS |
7302 | } |
7303 | \f | |
7304 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
7305 | all breakpoints that are marked for deletion, whether hit or not. | |
7306 | This is called after any breakpoint is hit, or after errors. */ | |
7307 | ||
7308 | void | |
fba45db2 | 7309 | breakpoint_auto_delete (bpstat bs) |
c906108c SS |
7310 | { |
7311 | struct breakpoint *b, *temp; | |
7312 | ||
7313 | for (; bs; bs = bs->next) | |
20874c92 VP |
7314 | if (bs->breakpoint_at |
7315 | && bs->breakpoint_at->owner | |
7316 | && bs->breakpoint_at->owner->disposition == disp_del | |
c906108c | 7317 | && bs->stop) |
4f8d1dc6 | 7318 | delete_breakpoint (bs->breakpoint_at->owner); |
c906108c SS |
7319 | |
7320 | ALL_BREAKPOINTS_SAFE (b, temp) | |
c5aa993b | 7321 | { |
b5de0fa7 | 7322 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
7323 | delete_breakpoint (b); |
7324 | } | |
c906108c SS |
7325 | } |
7326 | ||
f7545552 TT |
7327 | /* A cleanup function which destroys a vector. */ |
7328 | ||
7329 | static void | |
7330 | do_vec_free (void *p) | |
7331 | { | |
7332 | VEC(bp_location_p) **vec = p; | |
7333 | if (*vec) | |
7334 | VEC_free (bp_location_p, *vec); | |
7335 | } | |
7336 | ||
4cd9bd08 | 7337 | /* If SHOULD_INSERT is false, do not insert any breakpoint locations |
b60e7edf PA |
7338 | into the inferior, only remove already-inserted locations that no |
7339 | longer should be inserted. Functions that delete a breakpoint or | |
7340 | breakpoints should pass false, so that deleting a breakpoint | |
7341 | doesn't have the side effect of inserting the locations of other | |
7342 | breakpoints that are marked not-inserted, but should_be_inserted | |
7343 | returns true on them. | |
7344 | ||
7345 | This behaviour is useful is situations close to tear-down -- e.g., | |
7346 | after an exec, while the target still has execution, but breakpoint | |
7347 | shadows of the previous executable image should *NOT* be restored | |
7348 | to the new image; or before detaching, where the target still has | |
7349 | execution and wants to delete breakpoints from GDB's lists, and all | |
7350 | breakpoints had already been removed from the inferior. */ | |
7351 | ||
0d381245 | 7352 | static void |
b60e7edf | 7353 | update_global_location_list (int should_insert) |
0d381245 | 7354 | { |
74960c60 VP |
7355 | struct breakpoint *b; |
7356 | struct bp_location **next = &bp_location_chain; | |
7357 | struct bp_location *loc; | |
7358 | struct bp_location *loc2; | |
74960c60 VP |
7359 | VEC(bp_location_p) *old_locations = NULL; |
7360 | int ret; | |
7361 | int ix; | |
f7545552 TT |
7362 | struct cleanup *cleanups; |
7363 | ||
7364 | cleanups = make_cleanup (do_vec_free, &old_locations); | |
74960c60 VP |
7365 | /* Store old locations for future reference. */ |
7366 | for (loc = bp_location_chain; loc; loc = loc->global_next) | |
7367 | VEC_safe_push (bp_location_p, old_locations, loc); | |
0d381245 | 7368 | |
74960c60 VP |
7369 | bp_location_chain = NULL; |
7370 | ALL_BREAKPOINTS (b) | |
0d381245 | 7371 | { |
74960c60 | 7372 | for (loc = b->loc; loc; loc = loc->next) |
0d381245 | 7373 | { |
74960c60 VP |
7374 | *next = loc; |
7375 | next = &(loc->global_next); | |
7376 | *next = NULL; | |
0d381245 | 7377 | } |
74960c60 VP |
7378 | } |
7379 | ||
7380 | /* Identify bp_location instances that are no longer present in the new | |
7381 | list, and therefore should be freed. Note that it's not necessary that | |
7382 | those locations should be removed from inferior -- if there's another | |
7383 | location at the same address (previously marked as duplicate), | |
7384 | we don't need to remove/insert the location. */ | |
7385 | for (ix = 0; VEC_iterate(bp_location_p, old_locations, ix, loc); ++ix) | |
7386 | { | |
7387 | /* Tells if 'loc' is found amoung the new locations. If not, we | |
7388 | have to free it. */ | |
7389 | int found_object = 0; | |
20874c92 VP |
7390 | /* Tells if the location should remain inserted in the target. */ |
7391 | int keep_in_target = 0; | |
7392 | int removed = 0; | |
74960c60 VP |
7393 | for (loc2 = bp_location_chain; loc2; loc2 = loc2->global_next) |
7394 | if (loc2 == loc) | |
7395 | { | |
7396 | found_object = 1; | |
7397 | break; | |
7398 | } | |
7399 | ||
7400 | /* If this location is no longer present, and inserted, look if there's | |
7401 | maybe a new location at the same address. If so, mark that one | |
7402 | inserted, and don't remove this one. This is needed so that we | |
7403 | don't have a time window where a breakpoint at certain location is not | |
7404 | inserted. */ | |
7405 | ||
7406 | if (loc->inserted) | |
0d381245 | 7407 | { |
74960c60 | 7408 | /* If the location is inserted now, we might have to remove it. */ |
74960c60 VP |
7409 | |
7410 | if (found_object && should_be_inserted (loc)) | |
7411 | { | |
7412 | /* The location is still present in the location list, and still | |
7413 | should be inserted. Don't do anything. */ | |
20874c92 | 7414 | keep_in_target = 1; |
74960c60 VP |
7415 | } |
7416 | else | |
7417 | { | |
7418 | /* The location is either no longer present, or got disabled. | |
7419 | See if there's another location at the same address, in which | |
7420 | case we don't need to remove this one from the target. */ | |
7421 | if (breakpoint_address_is_meaningful (loc->owner)) | |
7422 | for (loc2 = bp_location_chain; loc2; loc2 = loc2->global_next) | |
7423 | { | |
7424 | /* For the sake of should_insert_location. The | |
7425 | call to check_duplicates will fix up this later. */ | |
7426 | loc2->duplicate = 0; | |
7427 | if (should_be_inserted (loc2) | |
7428 | && loc2 != loc && loc2->address == loc->address) | |
7429 | { | |
7430 | loc2->inserted = 1; | |
7431 | loc2->target_info = loc->target_info; | |
20874c92 | 7432 | keep_in_target = 1; |
74960c60 VP |
7433 | break; |
7434 | } | |
7435 | } | |
7436 | } | |
7437 | ||
20874c92 VP |
7438 | if (!keep_in_target) |
7439 | { | |
7440 | if (remove_breakpoint (loc, mark_uninserted)) | |
7441 | { | |
7442 | /* This is just about all we can do. We could keep this | |
7443 | location on the global list, and try to remove it next | |
7444 | time, but there's no particular reason why we will | |
7445 | succeed next time. | |
7446 | ||
7447 | Note that at this point, loc->owner is still valid, | |
7448 | as delete_breakpoint frees the breakpoint only | |
7449 | after calling us. */ | |
7450 | printf_filtered (_("warning: Error removing breakpoint %d\n"), | |
7451 | loc->owner->number); | |
7452 | } | |
7453 | removed = 1; | |
7454 | } | |
0d381245 | 7455 | } |
74960c60 VP |
7456 | |
7457 | if (!found_object) | |
1c5cfe86 PA |
7458 | { |
7459 | if (removed && non_stop) | |
20874c92 VP |
7460 | { |
7461 | /* This location was removed from the targets. In non-stop mode, | |
7462 | a race condition is possible where we've removed a breakpoint, | |
7463 | but stop events for that breakpoint are already queued and will | |
7464 | arrive later. To suppress spurious SIGTRAPs reported to user, | |
7465 | we keep this breakpoint location for a bit, and will retire it | |
7466 | after we see 3 * thread_count events. | |
1c5cfe86 | 7467 | The theory here is that reporting of events should, |
20874c92 VP |
7468 | "on the average", be fair, so after that many event we'll see |
7469 | events from all threads that have anything of interest, and no | |
1c5cfe86 | 7470 | longer need to keep this breakpoint. This is just a |
20874c92 | 7471 | heuristic, but if it's wrong, we'll report unexpected SIGTRAP, |
1c5cfe86 | 7472 | which is usability issue, but not a correctness problem. */ |
20874c92 VP |
7473 | loc->events_till_retirement = 3 * (thread_count () + 1); |
7474 | loc->owner = NULL; | |
20874c92 | 7475 | |
1c5cfe86 PA |
7476 | VEC_safe_push (bp_location_p, moribund_locations, loc); |
7477 | } | |
7478 | else | |
7479 | free_bp_location (loc); | |
20874c92 | 7480 | } |
74960c60 | 7481 | } |
1c5cfe86 | 7482 | |
74960c60 VP |
7483 | ALL_BREAKPOINTS (b) |
7484 | { | |
7485 | check_duplicates (b); | |
0d381245 | 7486 | } |
74960c60 | 7487 | |
50c71eaf | 7488 | if (breakpoints_always_inserted_mode () && should_insert |
c35b1492 | 7489 | && (have_live_inferiors () |
2567c7d9 | 7490 | || (gdbarch_has_global_breakpoints (target_gdbarch)))) |
74960c60 | 7491 | insert_breakpoint_locations (); |
f7545552 TT |
7492 | |
7493 | do_cleanups (cleanups); | |
74960c60 VP |
7494 | } |
7495 | ||
20874c92 VP |
7496 | void |
7497 | breakpoint_retire_moribund (void) | |
7498 | { | |
7499 | struct bp_location *loc; | |
7500 | int ix; | |
7501 | ||
7502 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
7503 | if (--(loc->events_till_retirement) == 0) | |
7504 | { | |
7505 | free_bp_location (loc); | |
7506 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); | |
7507 | --ix; | |
7508 | } | |
7509 | } | |
7510 | ||
74960c60 | 7511 | static void |
b60e7edf | 7512 | update_global_location_list_nothrow (int inserting) |
74960c60 VP |
7513 | { |
7514 | struct gdb_exception e; | |
7515 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
b60e7edf | 7516 | update_global_location_list (inserting); |
0d381245 VP |
7517 | } |
7518 | ||
a474d7c2 PA |
7519 | /* Clear BPT from a BPS. */ |
7520 | static void | |
7521 | bpstat_remove_breakpoint (bpstat bps, struct breakpoint *bpt) | |
7522 | { | |
7523 | bpstat bs; | |
7524 | for (bs = bps; bs; bs = bs->next) | |
7525 | if (bs->breakpoint_at && bs->breakpoint_at->owner == bpt) | |
7526 | { | |
7527 | bs->breakpoint_at = NULL; | |
7528 | bs->old_val = NULL; | |
7529 | /* bs->commands will be freed later. */ | |
7530 | } | |
7531 | } | |
7532 | ||
7533 | /* Callback for iterate_over_threads. */ | |
7534 | static int | |
7535 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
7536 | { | |
7537 | struct breakpoint *bpt = data; | |
7538 | bpstat_remove_breakpoint (th->stop_bpstat, bpt); | |
7539 | return 0; | |
7540 | } | |
7541 | ||
53a5351d JM |
7542 | /* Delete a breakpoint and clean up all traces of it in the data |
7543 | structures. */ | |
c906108c SS |
7544 | |
7545 | void | |
fba45db2 | 7546 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 7547 | { |
52f0bd74 | 7548 | struct breakpoint *b; |
74960c60 | 7549 | struct bp_location *loc, *next; |
c906108c | 7550 | |
8a3fe4f8 | 7551 | gdb_assert (bpt != NULL); |
c906108c SS |
7552 | |
7553 | /* Has this bp already been deleted? This can happen because multiple | |
7554 | lists can hold pointers to bp's. bpstat lists are especial culprits. | |
7555 | ||
7556 | One example of this happening is a watchpoint's scope bp. When the | |
7557 | scope bp triggers, we notice that the watchpoint is out of scope, and | |
7558 | delete it. We also delete its scope bp. But the scope bp is marked | |
7559 | "auto-deleting", and is already on a bpstat. That bpstat is then | |
7560 | checked for auto-deleting bp's, which are deleted. | |
7561 | ||
7562 | A real solution to this problem might involve reference counts in bp's, | |
7563 | and/or giving them pointers back to their referencing bpstat's, and | |
7564 | teaching delete_breakpoint to only free a bp's storage when no more | |
1272ad14 | 7565 | references were extent. A cheaper bandaid was chosen. */ |
c906108c SS |
7566 | if (bpt->type == bp_none) |
7567 | return; | |
7568 | ||
383f836e | 7569 | observer_notify_breakpoint_deleted (bpt->number); |
c906108c | 7570 | |
c906108c SS |
7571 | if (breakpoint_chain == bpt) |
7572 | breakpoint_chain = bpt->next; | |
7573 | ||
c906108c SS |
7574 | ALL_BREAKPOINTS (b) |
7575 | if (b->next == bpt) | |
c5aa993b JM |
7576 | { |
7577 | b->next = bpt->next; | |
7578 | break; | |
7579 | } | |
c906108c | 7580 | |
c906108c | 7581 | free_command_lines (&bpt->commands); |
c906108c | 7582 | if (bpt->cond_string != NULL) |
b8c9b27d | 7583 | xfree (bpt->cond_string); |
c906108c | 7584 | if (bpt->addr_string != NULL) |
b8c9b27d | 7585 | xfree (bpt->addr_string); |
c906108c | 7586 | if (bpt->exp != NULL) |
b8c9b27d | 7587 | xfree (bpt->exp); |
c906108c | 7588 | if (bpt->exp_string != NULL) |
b8c9b27d | 7589 | xfree (bpt->exp_string); |
c906108c SS |
7590 | if (bpt->val != NULL) |
7591 | value_free (bpt->val); | |
7592 | if (bpt->source_file != NULL) | |
b8c9b27d | 7593 | xfree (bpt->source_file); |
c906108c | 7594 | if (bpt->exec_pathname != NULL) |
b8c9b27d | 7595 | xfree (bpt->exec_pathname); |
c906108c SS |
7596 | |
7597 | /* Be sure no bpstat's are pointing at it after it's been freed. */ | |
7598 | /* FIXME, how can we find all bpstat's? | |
198757a8 VP |
7599 | We just check stop_bpstat for now. Note that we cannot just |
7600 | remove bpstats pointing at bpt from the stop_bpstat list | |
7601 | entirely, as breakpoint commands are associated with the bpstat; | |
7602 | if we remove it here, then the later call to | |
7603 | bpstat_do_actions (&stop_bpstat); | |
7604 | in event-top.c won't do anything, and temporary breakpoints | |
7605 | with commands won't work. */ | |
a474d7c2 | 7606 | |
a474d7c2 | 7607 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); |
74960c60 VP |
7608 | |
7609 | /* Now that breakpoint is removed from breakpoint | |
7610 | list, update the global location list. This | |
7611 | will remove locations that used to belong to | |
7612 | this breakpoint. Do this before freeing | |
7613 | the breakpoint itself, since remove_breakpoint | |
7614 | looks at location's owner. It might be better | |
7615 | design to have location completely self-contained, | |
7616 | but it's not the case now. */ | |
b60e7edf | 7617 | update_global_location_list (0); |
74960c60 VP |
7618 | |
7619 | ||
c906108c SS |
7620 | /* On the chance that someone will soon try again to delete this same |
7621 | bp, we mark it as deleted before freeing its storage. */ | |
7622 | bpt->type = bp_none; | |
7623 | ||
b8c9b27d | 7624 | xfree (bpt); |
c906108c SS |
7625 | } |
7626 | ||
4d6140d9 AC |
7627 | static void |
7628 | do_delete_breakpoint_cleanup (void *b) | |
7629 | { | |
7630 | delete_breakpoint (b); | |
7631 | } | |
7632 | ||
7633 | struct cleanup * | |
7634 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
7635 | { | |
7636 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
7637 | } | |
7638 | ||
c906108c | 7639 | void |
fba45db2 | 7640 | delete_command (char *arg, int from_tty) |
c906108c SS |
7641 | { |
7642 | struct breakpoint *b, *temp; | |
7643 | ||
ea9365bb TT |
7644 | dont_repeat (); |
7645 | ||
c906108c SS |
7646 | if (arg == 0) |
7647 | { | |
7648 | int breaks_to_delete = 0; | |
7649 | ||
7650 | /* Delete all breakpoints if no argument. | |
c5aa993b JM |
7651 | Do not delete internal or call-dummy breakpoints, these |
7652 | have to be deleted with an explicit breakpoint number argument. */ | |
7653 | ALL_BREAKPOINTS (b) | |
7654 | { | |
059fb39f PM |
7655 | if (b->type != bp_call_dummy |
7656 | && b->type != bp_shlib_event | |
7657 | && b->type != bp_thread_event | |
7658 | && b->type != bp_overlay_event | |
0fd8e87f | 7659 | && b->type != bp_longjmp_master |
059fb39f | 7660 | && b->number >= 0) |
973d738b DJ |
7661 | { |
7662 | breaks_to_delete = 1; | |
7663 | break; | |
7664 | } | |
c5aa993b | 7665 | } |
c906108c SS |
7666 | |
7667 | /* Ask user only if there are some breakpoints to delete. */ | |
7668 | if (!from_tty | |
e2e0b3e5 | 7669 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 7670 | { |
c5aa993b JM |
7671 | ALL_BREAKPOINTS_SAFE (b, temp) |
7672 | { | |
059fb39f PM |
7673 | if (b->type != bp_call_dummy |
7674 | && b->type != bp_shlib_event | |
7675 | && b->type != bp_thread_event | |
7676 | && b->type != bp_overlay_event | |
0fd8e87f | 7677 | && b->type != bp_longjmp_master |
059fb39f | 7678 | && b->number >= 0) |
c5aa993b JM |
7679 | delete_breakpoint (b); |
7680 | } | |
c906108c SS |
7681 | } |
7682 | } | |
7683 | else | |
7684 | map_breakpoint_numbers (arg, delete_breakpoint); | |
7685 | } | |
7686 | ||
0d381245 VP |
7687 | static int |
7688 | all_locations_are_pending (struct bp_location *loc) | |
fe3f5fa8 | 7689 | { |
0d381245 VP |
7690 | for (; loc; loc = loc->next) |
7691 | if (!loc->shlib_disabled) | |
7692 | return 0; | |
7693 | return 1; | |
fe3f5fa8 VP |
7694 | } |
7695 | ||
776592bf DE |
7696 | /* Subroutine of update_breakpoint_locations to simplify it. |
7697 | Return non-zero if multiple fns in list LOC have the same name. | |
7698 | Null names are ignored. */ | |
7699 | ||
7700 | static int | |
7701 | ambiguous_names_p (struct bp_location *loc) | |
7702 | { | |
7703 | struct bp_location *l; | |
7704 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
7705 | (int (*) (const void *, const void *)) streq, | |
7706 | NULL, xcalloc, xfree); | |
7707 | ||
7708 | for (l = loc; l != NULL; l = l->next) | |
7709 | { | |
7710 | const char **slot; | |
7711 | const char *name = l->function_name; | |
7712 | ||
7713 | /* Allow for some names to be NULL, ignore them. */ | |
7714 | if (name == NULL) | |
7715 | continue; | |
7716 | ||
7717 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
7718 | INSERT); | |
7719 | /* NOTE: We can assume slot != NULL here because xcalloc never returns | |
7720 | NULL. */ | |
7721 | if (*slot != NULL) | |
7722 | { | |
7723 | htab_delete (htab); | |
7724 | return 1; | |
7725 | } | |
7726 | *slot = name; | |
7727 | } | |
7728 | ||
7729 | htab_delete (htab); | |
7730 | return 0; | |
7731 | } | |
7732 | ||
fe3f5fa8 | 7733 | static void |
0d381245 VP |
7734 | update_breakpoint_locations (struct breakpoint *b, |
7735 | struct symtabs_and_lines sals) | |
fe3f5fa8 VP |
7736 | { |
7737 | int i; | |
7738 | char *s; | |
0d381245 VP |
7739 | struct bp_location *existing_locations = b->loc; |
7740 | ||
7741 | /* If there's no new locations, and all existing locations | |
7742 | are pending, don't do anything. This optimizes | |
7743 | the common case where all locations are in the same | |
7744 | shared library, that was unloaded. We'd like to | |
7745 | retain the location, so that when the library | |
7746 | is loaded again, we don't loose the enabled/disabled | |
7747 | status of the individual locations. */ | |
7748 | if (all_locations_are_pending (existing_locations) && sals.nelts == 0) | |
fe3f5fa8 VP |
7749 | return; |
7750 | ||
fe3f5fa8 VP |
7751 | b->loc = NULL; |
7752 | ||
0d381245 | 7753 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 7754 | { |
0d381245 | 7755 | struct bp_location *new_loc = |
39d61571 | 7756 | add_location_to_breakpoint (b, &(sals.sals[i])); |
fe3f5fa8 | 7757 | |
0d381245 VP |
7758 | /* Reparse conditions, they might contain references to the |
7759 | old symtab. */ | |
7760 | if (b->cond_string != NULL) | |
7761 | { | |
7762 | struct gdb_exception e; | |
fe3f5fa8 | 7763 | |
0d381245 VP |
7764 | s = b->cond_string; |
7765 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
7766 | { | |
7767 | new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), | |
7768 | 0); | |
7769 | } | |
7770 | if (e.reason < 0) | |
7771 | { | |
7772 | warning (_("failed to reevaluate condition for breakpoint %d: %s"), | |
7773 | b->number, e.message); | |
7774 | new_loc->enabled = 0; | |
7775 | } | |
7776 | } | |
fe3f5fa8 | 7777 | |
0d381245 VP |
7778 | if (b->source_file != NULL) |
7779 | xfree (b->source_file); | |
7780 | if (sals.sals[i].symtab == NULL) | |
7781 | b->source_file = NULL; | |
7782 | else | |
1b36a34b | 7783 | b->source_file = xstrdup (sals.sals[i].symtab->filename); |
fe3f5fa8 | 7784 | |
0d381245 VP |
7785 | if (b->line_number == 0) |
7786 | b->line_number = sals.sals[i].line; | |
7787 | } | |
fe3f5fa8 | 7788 | |
514f746b AR |
7789 | /* Update locations of permanent breakpoints. */ |
7790 | if (b->enable_state == bp_permanent) | |
7791 | make_breakpoint_permanent (b); | |
7792 | ||
0d381245 VP |
7793 | /* If possible, carry over 'disable' status from existing breakpoints. */ |
7794 | { | |
7795 | struct bp_location *e = existing_locations; | |
776592bf DE |
7796 | /* If there are multiple breakpoints with the same function name, |
7797 | e.g. for inline functions, comparing function names won't work. | |
7798 | Instead compare pc addresses; this is just a heuristic as things | |
7799 | may have moved, but in practice it gives the correct answer | |
7800 | often enough until a better solution is found. */ | |
7801 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
7802 | ||
0d381245 VP |
7803 | for (; e; e = e->next) |
7804 | { | |
7805 | if (!e->enabled && e->function_name) | |
7806 | { | |
7807 | struct bp_location *l = b->loc; | |
776592bf DE |
7808 | if (have_ambiguous_names) |
7809 | { | |
7810 | for (; l; l = l->next) | |
7811 | if (e->address == l->address) | |
7812 | { | |
7813 | l->enabled = 0; | |
7814 | break; | |
7815 | } | |
7816 | } | |
7817 | else | |
7818 | { | |
7819 | for (; l; l = l->next) | |
7820 | if (l->function_name | |
7821 | && strcmp (e->function_name, l->function_name) == 0) | |
7822 | { | |
7823 | l->enabled = 0; | |
7824 | break; | |
7825 | } | |
7826 | } | |
0d381245 VP |
7827 | } |
7828 | } | |
7829 | } | |
fe3f5fa8 | 7830 | |
b60e7edf | 7831 | update_global_location_list (1); |
fe3f5fa8 VP |
7832 | } |
7833 | ||
7834 | ||
c906108c SS |
7835 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
7836 | The value we return ends up being the return value from catch_errors. | |
7837 | Unused in this case. */ | |
7838 | ||
7839 | static int | |
4efb68b1 | 7840 | breakpoint_re_set_one (void *bint) |
c906108c | 7841 | { |
53a5351d JM |
7842 | /* get past catch_errs */ |
7843 | struct breakpoint *b = (struct breakpoint *) bint; | |
c906108c SS |
7844 | struct value *mark; |
7845 | int i; | |
fe3f5fa8 VP |
7846 | int not_found = 0; |
7847 | int *not_found_ptr = ¬_found; | |
7848 | struct symtabs_and_lines sals = {}; | |
ed0616c6 | 7849 | struct symtabs_and_lines expanded; |
c906108c | 7850 | char *s; |
b5de0fa7 | 7851 | enum enable_state save_enable; |
fe3f5fa8 | 7852 | struct gdb_exception e; |
f7545552 | 7853 | struct cleanup *cleanups; |
c906108c SS |
7854 | |
7855 | switch (b->type) | |
7856 | { | |
7857 | case bp_none: | |
8a3fe4f8 | 7858 | warning (_("attempted to reset apparently deleted breakpoint #%d?"), |
53a5351d | 7859 | b->number); |
c906108c SS |
7860 | return 0; |
7861 | case bp_breakpoint: | |
7862 | case bp_hardware_breakpoint: | |
1042e4c0 | 7863 | case bp_tracepoint: |
8bea4e01 UW |
7864 | /* Do not attempt to re-set breakpoints disabled during startup. */ |
7865 | if (b->enable_state == bp_startup_disabled) | |
7866 | return 0; | |
7867 | ||
c906108c SS |
7868 | if (b->addr_string == NULL) |
7869 | { | |
7870 | /* Anything without a string can't be re-set. */ | |
7871 | delete_breakpoint (b); | |
7872 | return 0; | |
7873 | } | |
c906108c SS |
7874 | |
7875 | set_language (b->language); | |
7876 | input_radix = b->input_radix; | |
7877 | s = b->addr_string; | |
fe3f5fa8 | 7878 | TRY_CATCH (e, RETURN_MASK_ERROR) |
c906108c | 7879 | { |
fe3f5fa8 VP |
7880 | sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL, |
7881 | not_found_ptr); | |
7882 | } | |
7883 | if (e.reason < 0) | |
7884 | { | |
7885 | int not_found_and_ok = 0; | |
7886 | /* For pending breakpoints, it's expected that parsing | |
7887 | will fail until the right shared library is loaded. | |
7888 | User has already told to create pending breakpoints and | |
7889 | don't need extra messages. If breakpoint is in bp_shlib_disabled | |
7890 | state, then user already saw the message about that breakpoint | |
7891 | being disabled, and don't want to see more errors. */ | |
0d381245 VP |
7892 | if (not_found |
7893 | && (b->condition_not_parsed | |
7894 | || (b->loc && b->loc->shlib_disabled) | |
7895 | || b->enable_state == bp_disabled)) | |
fe3f5fa8 VP |
7896 | not_found_and_ok = 1; |
7897 | ||
7898 | if (!not_found_and_ok) | |
c906108c | 7899 | { |
fe3f5fa8 VP |
7900 | /* We surely don't want to warn about the same breakpoint |
7901 | 10 times. One solution, implemented here, is disable | |
7902 | the breakpoint on error. Another solution would be to | |
7903 | have separate 'warning emitted' flag. Since this | |
7904 | happens only when a binary has changed, I don't know | |
7905 | which approach is better. */ | |
7906 | b->enable_state = bp_disabled; | |
7907 | throw_exception (e); | |
c906108c | 7908 | } |
fe3f5fa8 | 7909 | } |
c906108c | 7910 | |
fe3f5fa8 VP |
7911 | if (not_found) |
7912 | break; | |
7913 | ||
7914 | gdb_assert (sals.nelts == 1); | |
7915 | resolve_sal_pc (&sals.sals[0]); | |
0d381245 | 7916 | if (b->condition_not_parsed && s && s[0]) |
fe3f5fa8 VP |
7917 | { |
7918 | char *cond_string = 0; | |
7919 | int thread = -1; | |
4a306c9a JB |
7920 | int task = 0; |
7921 | ||
fe3f5fa8 | 7922 | find_condition_and_thread (s, sals.sals[0].pc, |
4a306c9a | 7923 | &cond_string, &thread, &task); |
fe3f5fa8 VP |
7924 | if (cond_string) |
7925 | b->cond_string = cond_string; | |
7926 | b->thread = thread; | |
4a306c9a | 7927 | b->task = task; |
0d381245 | 7928 | b->condition_not_parsed = 0; |
fe3f5fa8 | 7929 | } |
ed0616c6 | 7930 | expanded = expand_line_sal_maybe (sals.sals[0]); |
f7545552 | 7931 | cleanups = make_cleanup (xfree, sals.sals); |
ed0616c6 | 7932 | update_breakpoint_locations (b, expanded); |
f7545552 | 7933 | do_cleanups (cleanups); |
c906108c SS |
7934 | break; |
7935 | ||
7936 | case bp_watchpoint: | |
7937 | case bp_hardware_watchpoint: | |
7938 | case bp_read_watchpoint: | |
7939 | case bp_access_watchpoint: | |
0b3de036 VP |
7940 | /* Watchpoint can be either on expression using entirely global variables, |
7941 | or it can be on local variables. | |
7942 | ||
7943 | Watchpoints of the first kind are never auto-deleted, and even persist | |
7944 | across program restarts. Since they can use variables from shared | |
7945 | libraries, we need to reparse expression as libraries are loaded | |
7946 | and unloaded. | |
7947 | ||
7948 | Watchpoints on local variables can also change meaning as result | |
7949 | of solib event. For example, if a watchpoint uses both a local and | |
7950 | a global variables in expression, it's a local watchpoint, but | |
7951 | unloading of a shared library will make the expression invalid. | |
7952 | This is not a very common use case, but we still re-evaluate | |
7953 | expression, to avoid surprises to the user. | |
7954 | ||
7955 | Note that for local watchpoints, we re-evaluate it only if | |
7956 | watchpoints frame id is still valid. If it's not, it means | |
7957 | the watchpoint is out of scope and will be deleted soon. In fact, | |
7958 | I'm not sure we'll ever be called in this case. | |
7959 | ||
7960 | If a local watchpoint's frame id is still valid, then | |
7961 | b->exp_valid_block is likewise valid, and we can safely use it. | |
7962 | ||
7963 | Don't do anything about disabled watchpoints, since they will | |
7964 | be reevaluated again when enabled. */ | |
a5606eee | 7965 | update_watchpoint (b, 1 /* reparse */); |
c906108c | 7966 | break; |
c5aa993b JM |
7967 | /* We needn't really do anything to reset these, since the mask |
7968 | that requests them is unaffected by e.g., new libraries being | |
7969 | loaded. */ | |
ce78b96d | 7970 | case bp_catchpoint: |
c906108c | 7971 | break; |
c5aa993b | 7972 | |
c906108c | 7973 | default: |
a3f17187 | 7974 | printf_filtered (_("Deleting unknown breakpoint type %d\n"), b->type); |
c906108c | 7975 | /* fall through */ |
0fd8e87f UW |
7976 | /* Delete overlay event and longjmp master breakpoints; they will be |
7977 | reset later by breakpoint_re_set. */ | |
1900040c | 7978 | case bp_overlay_event: |
0fd8e87f | 7979 | case bp_longjmp_master: |
c906108c SS |
7980 | delete_breakpoint (b); |
7981 | break; | |
7982 | ||
c5aa993b JM |
7983 | /* This breakpoint is special, it's set up when the inferior |
7984 | starts and we really don't want to touch it. */ | |
c906108c SS |
7985 | case bp_shlib_event: |
7986 | ||
c4093a6a JM |
7987 | /* Like bp_shlib_event, this breakpoint type is special. |
7988 | Once it is set up, we do not want to touch it. */ | |
7989 | case bp_thread_event: | |
7990 | ||
c5aa993b JM |
7991 | /* Keep temporary breakpoints, which can be encountered when we step |
7992 | over a dlopen call and SOLIB_ADD is resetting the breakpoints. | |
7993 | Otherwise these should have been blown away via the cleanup chain | |
7994 | or by breakpoint_init_inferior when we rerun the executable. */ | |
c906108c SS |
7995 | case bp_until: |
7996 | case bp_finish: | |
7997 | case bp_watchpoint_scope: | |
7998 | case bp_call_dummy: | |
7999 | case bp_step_resume: | |
611c83ae PA |
8000 | case bp_longjmp: |
8001 | case bp_longjmp_resume: | |
c906108c SS |
8002 | break; |
8003 | } | |
8004 | ||
8005 | return 0; | |
8006 | } | |
8007 | ||
69de3c6a | 8008 | /* Re-set all breakpoints after symbols have been re-loaded. */ |
c906108c | 8009 | void |
69de3c6a | 8010 | breakpoint_re_set (void) |
c906108c SS |
8011 | { |
8012 | struct breakpoint *b, *temp; | |
8013 | enum language save_language; | |
8014 | int save_input_radix; | |
c5aa993b | 8015 | |
c906108c SS |
8016 | save_language = current_language->la_language; |
8017 | save_input_radix = input_radix; | |
8018 | ALL_BREAKPOINTS_SAFE (b, temp) | |
c5aa993b | 8019 | { |
53a5351d | 8020 | /* Format possible error msg */ |
fe3f5fa8 | 8021 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
8022 | b->number); |
8023 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 8024 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 8025 | do_cleanups (cleanups); |
c5aa993b | 8026 | } |
c906108c SS |
8027 | set_language (save_language); |
8028 | input_radix = save_input_radix; | |
e62c965a | 8029 | |
69de3c6a | 8030 | create_overlay_event_breakpoint ("_ovly_debug_event"); |
0fd8e87f UW |
8031 | create_longjmp_master_breakpoint ("longjmp"); |
8032 | create_longjmp_master_breakpoint ("_longjmp"); | |
8033 | create_longjmp_master_breakpoint ("siglongjmp"); | |
8034 | create_longjmp_master_breakpoint ("_siglongjmp"); | |
c906108c SS |
8035 | } |
8036 | \f | |
c906108c SS |
8037 | /* Reset the thread number of this breakpoint: |
8038 | ||
8039 | - If the breakpoint is for all threads, leave it as-is. | |
39f77062 | 8040 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 8041 | void |
fba45db2 | 8042 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
8043 | { |
8044 | if (b->thread != -1) | |
8045 | { | |
39f77062 KB |
8046 | if (in_thread_list (inferior_ptid)) |
8047 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c SS |
8048 | } |
8049 | } | |
8050 | ||
03ac34d5 MS |
8051 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
8052 | If from_tty is nonzero, it prints a message to that effect, | |
8053 | which ends with a period (no newline). */ | |
8054 | ||
c906108c | 8055 | void |
fba45db2 | 8056 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 8057 | { |
52f0bd74 | 8058 | struct breakpoint *b; |
c906108c SS |
8059 | |
8060 | if (count < 0) | |
8061 | count = 0; | |
8062 | ||
8063 | ALL_BREAKPOINTS (b) | |
8064 | if (b->number == bptnum) | |
c5aa993b JM |
8065 | { |
8066 | b->ignore_count = count; | |
221ea385 KS |
8067 | if (from_tty) |
8068 | { | |
8069 | if (count == 0) | |
a3f17187 | 8070 | printf_filtered (_("Will stop next time breakpoint %d is reached."), |
221ea385 KS |
8071 | bptnum); |
8072 | else if (count == 1) | |
a3f17187 | 8073 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
8074 | bptnum); |
8075 | else | |
a3f17187 | 8076 | printf_filtered (_("Will ignore next %d crossings of breakpoint %d."), |
221ea385 KS |
8077 | count, bptnum); |
8078 | } | |
c5aa993b | 8079 | breakpoints_changed (); |
383f836e | 8080 | observer_notify_breakpoint_modified (b->number); |
c5aa993b JM |
8081 | return; |
8082 | } | |
c906108c | 8083 | |
8a3fe4f8 | 8084 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
8085 | } |
8086 | ||
b2175913 MS |
8087 | void |
8088 | make_breakpoint_silent (struct breakpoint *b) | |
8089 | { | |
8090 | /* Silence the breakpoint. */ | |
8091 | b->silent = 1; | |
8092 | } | |
8093 | ||
c906108c SS |
8094 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
8095 | ||
8096 | static void | |
fba45db2 | 8097 | ignore_command (char *args, int from_tty) |
c906108c SS |
8098 | { |
8099 | char *p = args; | |
52f0bd74 | 8100 | int num; |
c906108c SS |
8101 | |
8102 | if (p == 0) | |
e2e0b3e5 | 8103 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 8104 | |
c906108c | 8105 | num = get_number (&p); |
5c44784c | 8106 | if (num == 0) |
8a3fe4f8 | 8107 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 8108 | if (*p == 0) |
8a3fe4f8 | 8109 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
8110 | |
8111 | set_ignore_count (num, | |
8112 | longest_to_int (value_as_long (parse_and_eval (p))), | |
8113 | from_tty); | |
221ea385 KS |
8114 | if (from_tty) |
8115 | printf_filtered ("\n"); | |
c906108c SS |
8116 | } |
8117 | \f | |
8118 | /* Call FUNCTION on each of the breakpoints | |
8119 | whose numbers are given in ARGS. */ | |
8120 | ||
8121 | static void | |
831662b3 | 8122 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *)) |
c906108c | 8123 | { |
52f0bd74 | 8124 | char *p = args; |
c906108c | 8125 | char *p1; |
52f0bd74 AC |
8126 | int num; |
8127 | struct breakpoint *b, *tmp; | |
11cf8741 | 8128 | int match; |
c906108c SS |
8129 | |
8130 | if (p == 0) | |
e2e0b3e5 | 8131 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c SS |
8132 | |
8133 | while (*p) | |
8134 | { | |
11cf8741 | 8135 | match = 0; |
c906108c | 8136 | p1 = p; |
c5aa993b | 8137 | |
5c44784c JM |
8138 | num = get_number_or_range (&p1); |
8139 | if (num == 0) | |
c5aa993b | 8140 | { |
8a3fe4f8 | 8141 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
8142 | } |
8143 | else | |
8144 | { | |
8145 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
8146 | if (b->number == num) | |
8147 | { | |
8148 | struct breakpoint *related_breakpoint = b->related_breakpoint; | |
11cf8741 | 8149 | match = 1; |
5c44784c JM |
8150 | function (b); |
8151 | if (related_breakpoint) | |
8152 | function (related_breakpoint); | |
11cf8741 | 8153 | break; |
5c44784c | 8154 | } |
11cf8741 | 8155 | if (match == 0) |
a3f17187 | 8156 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 8157 | } |
c906108c SS |
8158 | p = p1; |
8159 | } | |
8160 | } | |
8161 | ||
0d381245 VP |
8162 | static struct bp_location * |
8163 | find_location_by_number (char *number) | |
8164 | { | |
8165 | char *dot = strchr (number, '.'); | |
8166 | char *p1; | |
8167 | int bp_num; | |
8168 | int loc_num; | |
8169 | struct breakpoint *b; | |
8170 | struct bp_location *loc; | |
8171 | ||
8172 | *dot = '\0'; | |
8173 | ||
8174 | p1 = number; | |
8175 | bp_num = get_number_or_range (&p1); | |
8176 | if (bp_num == 0) | |
8177 | error (_("Bad breakpoint number '%s'"), number); | |
8178 | ||
8179 | ALL_BREAKPOINTS (b) | |
8180 | if (b->number == bp_num) | |
8181 | { | |
8182 | break; | |
8183 | } | |
8184 | ||
8185 | if (!b || b->number != bp_num) | |
8186 | error (_("Bad breakpoint number '%s'"), number); | |
8187 | ||
8188 | p1 = dot+1; | |
8189 | loc_num = get_number_or_range (&p1); | |
8190 | if (loc_num == 0) | |
8191 | error (_("Bad breakpoint location number '%s'"), number); | |
8192 | ||
8193 | --loc_num; | |
8194 | loc = b->loc; | |
8195 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
8196 | ; | |
8197 | if (!loc) | |
8198 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
8199 | ||
8200 | return loc; | |
8201 | } | |
8202 | ||
8203 | ||
1900040c MS |
8204 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
8205 | If from_tty is nonzero, it prints a message to that effect, | |
8206 | which ends with a period (no newline). */ | |
8207 | ||
c906108c | 8208 | void |
fba45db2 | 8209 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
8210 | { |
8211 | /* Never disable a watchpoint scope breakpoint; we want to | |
8212 | hit them when we leave scope so we can delete both the | |
8213 | watchpoint and its scope breakpoint at that time. */ | |
8214 | if (bpt->type == bp_watchpoint_scope) | |
8215 | return; | |
8216 | ||
c2c6d25f | 8217 | /* You can't disable permanent breakpoints. */ |
b5de0fa7 | 8218 | if (bpt->enable_state == bp_permanent) |
c2c6d25f JM |
8219 | return; |
8220 | ||
b5de0fa7 | 8221 | bpt->enable_state = bp_disabled; |
c906108c | 8222 | |
b60e7edf | 8223 | update_global_location_list (0); |
c906108c | 8224 | |
383f836e | 8225 | observer_notify_breakpoint_modified (bpt->number); |
c906108c SS |
8226 | } |
8227 | ||
c906108c | 8228 | static void |
fba45db2 | 8229 | disable_command (char *args, int from_tty) |
c906108c | 8230 | { |
52f0bd74 | 8231 | struct breakpoint *bpt; |
c906108c SS |
8232 | if (args == 0) |
8233 | ALL_BREAKPOINTS (bpt) | |
8234 | switch (bpt->type) | |
c5aa993b JM |
8235 | { |
8236 | case bp_none: | |
8a3fe4f8 | 8237 | warning (_("attempted to disable apparently deleted breakpoint #%d?"), |
53a5351d | 8238 | bpt->number); |
c5aa993b JM |
8239 | continue; |
8240 | case bp_breakpoint: | |
1042e4c0 | 8241 | case bp_tracepoint: |
ce78b96d | 8242 | case bp_catchpoint: |
c5aa993b JM |
8243 | case bp_hardware_breakpoint: |
8244 | case bp_watchpoint: | |
8245 | case bp_hardware_watchpoint: | |
8246 | case bp_read_watchpoint: | |
8247 | case bp_access_watchpoint: | |
8248 | disable_breakpoint (bpt); | |
8249 | default: | |
8250 | continue; | |
8251 | } | |
0d381245 VP |
8252 | else if (strchr (args, '.')) |
8253 | { | |
8254 | struct bp_location *loc = find_location_by_number (args); | |
8255 | if (loc) | |
8256 | loc->enabled = 0; | |
b60e7edf | 8257 | update_global_location_list (0); |
0d381245 | 8258 | } |
c906108c SS |
8259 | else |
8260 | map_breakpoint_numbers (args, disable_breakpoint); | |
8261 | } | |
8262 | ||
8263 | static void | |
fba45db2 | 8264 | do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition) |
c906108c | 8265 | { |
c906108c SS |
8266 | int target_resources_ok, other_type_used; |
8267 | struct value *mark; | |
8268 | ||
8269 | if (bpt->type == bp_hardware_breakpoint) | |
8270 | { | |
8271 | int i; | |
c5aa993b | 8272 | i = hw_breakpoint_used_count (); |
53a5351d | 8273 | target_resources_ok = |
d92524f1 | 8274 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 8275 | i + 1, 0); |
c906108c | 8276 | if (target_resources_ok == 0) |
8a3fe4f8 | 8277 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 8278 | else if (target_resources_ok < 0) |
8a3fe4f8 | 8279 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
8280 | } |
8281 | ||
059fb39f PM |
8282 | if (bpt->type == bp_watchpoint |
8283 | || bpt->type == bp_hardware_watchpoint | |
8284 | || bpt->type == bp_read_watchpoint | |
8285 | || bpt->type == bp_access_watchpoint) | |
c906108c | 8286 | { |
dde02812 ES |
8287 | struct gdb_exception e; |
8288 | ||
8289 | TRY_CATCH (e, RETURN_MASK_ALL) | |
c906108c | 8290 | { |
dde02812 | 8291 | update_watchpoint (bpt, 1 /* reparse */); |
c906108c | 8292 | } |
dde02812 | 8293 | if (e.reason < 0) |
c5aa993b | 8294 | { |
dde02812 ES |
8295 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
8296 | bpt->number); | |
8297 | return; | |
c5aa993b | 8298 | } |
c906108c | 8299 | } |
0101ce28 | 8300 | |
b4c291bb KH |
8301 | if (bpt->enable_state != bp_permanent) |
8302 | bpt->enable_state = bp_enabled; | |
8303 | bpt->disposition = disposition; | |
b60e7edf | 8304 | update_global_location_list (1); |
b4c291bb KH |
8305 | breakpoints_changed (); |
8306 | ||
383f836e | 8307 | observer_notify_breakpoint_modified (bpt->number); |
c906108c SS |
8308 | } |
8309 | ||
fe3f5fa8 | 8310 | |
c906108c | 8311 | void |
fba45db2 | 8312 | enable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
8313 | { |
8314 | do_enable_breakpoint (bpt, bpt->disposition); | |
8315 | } | |
8316 | ||
8317 | /* The enable command enables the specified breakpoints (or all defined | |
8318 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 8319 | in stopping the inferior. */ |
c906108c | 8320 | |
c906108c | 8321 | static void |
fba45db2 | 8322 | enable_command (char *args, int from_tty) |
c906108c | 8323 | { |
52f0bd74 | 8324 | struct breakpoint *bpt; |
c906108c SS |
8325 | if (args == 0) |
8326 | ALL_BREAKPOINTS (bpt) | |
8327 | switch (bpt->type) | |
c5aa993b JM |
8328 | { |
8329 | case bp_none: | |
8a3fe4f8 | 8330 | warning (_("attempted to enable apparently deleted breakpoint #%d?"), |
53a5351d | 8331 | bpt->number); |
c5aa993b JM |
8332 | continue; |
8333 | case bp_breakpoint: | |
1042e4c0 | 8334 | case bp_tracepoint: |
ce78b96d | 8335 | case bp_catchpoint: |
c5aa993b JM |
8336 | case bp_hardware_breakpoint: |
8337 | case bp_watchpoint: | |
8338 | case bp_hardware_watchpoint: | |
8339 | case bp_read_watchpoint: | |
8340 | case bp_access_watchpoint: | |
8341 | enable_breakpoint (bpt); | |
8342 | default: | |
8343 | continue; | |
8344 | } | |
0d381245 VP |
8345 | else if (strchr (args, '.')) |
8346 | { | |
8347 | struct bp_location *loc = find_location_by_number (args); | |
8348 | if (loc) | |
8349 | loc->enabled = 1; | |
b60e7edf | 8350 | update_global_location_list (1); |
0d381245 | 8351 | } |
c906108c SS |
8352 | else |
8353 | map_breakpoint_numbers (args, enable_breakpoint); | |
8354 | } | |
8355 | ||
8356 | static void | |
fba45db2 | 8357 | enable_once_breakpoint (struct breakpoint *bpt) |
c906108c | 8358 | { |
b5de0fa7 | 8359 | do_enable_breakpoint (bpt, disp_disable); |
c906108c SS |
8360 | } |
8361 | ||
c906108c | 8362 | static void |
fba45db2 | 8363 | enable_once_command (char *args, int from_tty) |
c906108c SS |
8364 | { |
8365 | map_breakpoint_numbers (args, enable_once_breakpoint); | |
8366 | } | |
8367 | ||
8368 | static void | |
fba45db2 | 8369 | enable_delete_breakpoint (struct breakpoint *bpt) |
c906108c | 8370 | { |
b5de0fa7 | 8371 | do_enable_breakpoint (bpt, disp_del); |
c906108c SS |
8372 | } |
8373 | ||
c906108c | 8374 | static void |
fba45db2 | 8375 | enable_delete_command (char *args, int from_tty) |
c906108c SS |
8376 | { |
8377 | map_breakpoint_numbers (args, enable_delete_breakpoint); | |
8378 | } | |
8379 | \f | |
fa8d40ab JJ |
8380 | static void |
8381 | set_breakpoint_cmd (char *args, int from_tty) | |
8382 | { | |
8383 | } | |
8384 | ||
8385 | static void | |
8386 | show_breakpoint_cmd (char *args, int from_tty) | |
8387 | { | |
8388 | } | |
8389 | ||
c906108c SS |
8390 | /* Use default_breakpoint_'s, or nothing if they aren't valid. */ |
8391 | ||
8392 | struct symtabs_and_lines | |
fba45db2 | 8393 | decode_line_spec_1 (char *string, int funfirstline) |
c906108c SS |
8394 | { |
8395 | struct symtabs_and_lines sals; | |
8396 | if (string == 0) | |
8a3fe4f8 | 8397 | error (_("Empty line specification.")); |
c906108c SS |
8398 | if (default_breakpoint_valid) |
8399 | sals = decode_line_1 (&string, funfirstline, | |
53a5351d JM |
8400 | default_breakpoint_symtab, |
8401 | default_breakpoint_line, | |
68219205 | 8402 | (char ***) NULL, NULL); |
c906108c SS |
8403 | else |
8404 | sals = decode_line_1 (&string, funfirstline, | |
68219205 | 8405 | (struct symtab *) NULL, 0, (char ***) NULL, NULL); |
c906108c | 8406 | if (*string) |
8a3fe4f8 | 8407 | error (_("Junk at end of line specification: %s"), string); |
c906108c SS |
8408 | return sals; |
8409 | } | |
8181d85f DJ |
8410 | |
8411 | /* Create and insert a raw software breakpoint at PC. Return an | |
8412 | identifier, which should be used to remove the breakpoint later. | |
8413 | In general, places which call this should be using something on the | |
8414 | breakpoint chain instead; this function should be eliminated | |
8415 | someday. */ | |
8416 | ||
8417 | void * | |
a6d9a66e | 8418 | deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch, CORE_ADDR pc) |
8181d85f DJ |
8419 | { |
8420 | struct bp_target_info *bp_tgt; | |
8421 | ||
8422 | bp_tgt = xmalloc (sizeof (struct bp_target_info)); | |
8423 | memset (bp_tgt, 0, sizeof (struct bp_target_info)); | |
8424 | ||
8425 | bp_tgt->placed_address = pc; | |
a6d9a66e | 8426 | if (target_insert_breakpoint (gdbarch, bp_tgt) != 0) |
8181d85f DJ |
8427 | { |
8428 | /* Could not insert the breakpoint. */ | |
8429 | xfree (bp_tgt); | |
8430 | return NULL; | |
8431 | } | |
8432 | ||
8433 | return bp_tgt; | |
8434 | } | |
8435 | ||
8436 | /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */ | |
8437 | ||
8438 | int | |
a6d9a66e | 8439 | deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp) |
8181d85f DJ |
8440 | { |
8441 | struct bp_target_info *bp_tgt = bp; | |
8442 | int ret; | |
8443 | ||
a6d9a66e | 8444 | ret = target_remove_breakpoint (gdbarch, bp_tgt); |
8181d85f DJ |
8445 | xfree (bp_tgt); |
8446 | ||
8447 | return ret; | |
8448 | } | |
8449 | ||
8450 | /* One (or perhaps two) breakpoints used for software single stepping. */ | |
8451 | ||
8452 | static void *single_step_breakpoints[2]; | |
a6d9a66e | 8453 | static struct gdbarch *single_step_gdbarch[2]; |
8181d85f DJ |
8454 | |
8455 | /* Create and insert a breakpoint for software single step. */ | |
8456 | ||
8457 | void | |
a6d9a66e | 8458 | insert_single_step_breakpoint (struct gdbarch *gdbarch, CORE_ADDR next_pc) |
8181d85f DJ |
8459 | { |
8460 | void **bpt_p; | |
8461 | ||
8462 | if (single_step_breakpoints[0] == NULL) | |
a6d9a66e UW |
8463 | { |
8464 | bpt_p = &single_step_breakpoints[0]; | |
8465 | single_step_gdbarch[0] = gdbarch; | |
8466 | } | |
8181d85f DJ |
8467 | else |
8468 | { | |
8469 | gdb_assert (single_step_breakpoints[1] == NULL); | |
8470 | bpt_p = &single_step_breakpoints[1]; | |
a6d9a66e | 8471 | single_step_gdbarch[1] = gdbarch; |
8181d85f DJ |
8472 | } |
8473 | ||
8474 | /* NOTE drow/2006-04-11: A future improvement to this function would be | |
8475 | to only create the breakpoints once, and actually put them on the | |
8476 | breakpoint chain. That would let us use set_raw_breakpoint. We could | |
8477 | adjust the addresses each time they were needed. Doing this requires | |
8478 | corresponding changes elsewhere where single step breakpoints are | |
8479 | handled, however. So, for now, we use this. */ | |
8480 | ||
a6d9a66e | 8481 | *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, next_pc); |
8181d85f | 8482 | if (*bpt_p == NULL) |
5af949e3 UW |
8483 | error (_("Could not insert single-step breakpoint at %s"), |
8484 | paddress (gdbarch, next_pc)); | |
8181d85f DJ |
8485 | } |
8486 | ||
8487 | /* Remove and delete any breakpoints used for software single step. */ | |
8488 | ||
8489 | void | |
8490 | remove_single_step_breakpoints (void) | |
8491 | { | |
8492 | gdb_assert (single_step_breakpoints[0] != NULL); | |
8493 | ||
8494 | /* See insert_single_step_breakpoint for more about this deprecated | |
8495 | call. */ | |
a6d9a66e UW |
8496 | deprecated_remove_raw_breakpoint (single_step_gdbarch[0], |
8497 | single_step_breakpoints[0]); | |
8498 | single_step_gdbarch[0] = NULL; | |
8181d85f DJ |
8499 | single_step_breakpoints[0] = NULL; |
8500 | ||
8501 | if (single_step_breakpoints[1] != NULL) | |
8502 | { | |
a6d9a66e UW |
8503 | deprecated_remove_raw_breakpoint (single_step_gdbarch[1], |
8504 | single_step_breakpoints[1]); | |
8505 | single_step_gdbarch[1] = NULL; | |
8181d85f DJ |
8506 | single_step_breakpoints[1] = NULL; |
8507 | } | |
8508 | } | |
8509 | ||
1aafd4da UW |
8510 | /* Check whether a software single-step breakpoint is inserted at PC. */ |
8511 | ||
8512 | static int | |
8513 | single_step_breakpoint_inserted_here_p (CORE_ADDR pc) | |
8514 | { | |
8515 | int i; | |
8516 | ||
8517 | for (i = 0; i < 2; i++) | |
8518 | { | |
8519 | struct bp_target_info *bp_tgt = single_step_breakpoints[i]; | |
8520 | if (bp_tgt && bp_tgt->placed_address == pc) | |
8521 | return 1; | |
8522 | } | |
8523 | ||
8524 | return 0; | |
8525 | } | |
8526 | ||
1042e4c0 SS |
8527 | /* Tracepoint-specific operations. */ |
8528 | ||
8529 | /* Set tracepoint count to NUM. */ | |
8530 | static void | |
8531 | set_tracepoint_count (int num) | |
8532 | { | |
8533 | tracepoint_count = num; | |
4fa62494 | 8534 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
8535 | } |
8536 | ||
8537 | void | |
8538 | trace_command (char *arg, int from_tty) | |
8539 | { | |
a6d9a66e UW |
8540 | break_command_really (get_current_arch (), |
8541 | arg, | |
1042e4c0 SS |
8542 | NULL, 0, 1 /* parse arg */, |
8543 | 0 /* tempflag */, 0 /* hardwareflag */, | |
8544 | 1 /* traceflag */, | |
8545 | 0 /* Ignore count */, | |
8546 | pending_break_support, | |
8547 | NULL, | |
8548 | from_tty, | |
8549 | 1 /* enabled */); | |
8550 | set_tracepoint_count (breakpoint_count); | |
8551 | } | |
8552 | ||
8553 | /* Print information on tracepoint number TPNUM_EXP, or all if | |
8554 | omitted. */ | |
8555 | ||
8556 | static void | |
8557 | tracepoints_info (char *tpnum_exp, int from_tty) | |
8558 | { | |
8559 | struct breakpoint *b; | |
8560 | int tps_to_list = 0; | |
8561 | ||
8562 | /* In the no-arguments case, say "No tracepoints" if none found. */ | |
8563 | if (tpnum_exp == 0) | |
8564 | { | |
8565 | ALL_TRACEPOINTS (b) | |
8566 | { | |
8567 | if (b->number >= 0) | |
8568 | { | |
8569 | tps_to_list = 1; | |
8570 | break; | |
8571 | } | |
8572 | } | |
8573 | if (!tps_to_list) | |
8574 | { | |
8575 | ui_out_message (uiout, 0, "No tracepoints.\n"); | |
8576 | return; | |
8577 | } | |
8578 | } | |
8579 | ||
8580 | /* Otherwise be the same as "info break". */ | |
8581 | breakpoints_info (tpnum_exp, from_tty); | |
8582 | } | |
8583 | ||
8584 | /* The 'enable trace' command enables tracepoints. | |
8585 | Not supported by all targets. */ | |
8586 | static void | |
8587 | enable_trace_command (char *args, int from_tty) | |
8588 | { | |
8589 | enable_command (args, from_tty); | |
8590 | } | |
8591 | ||
8592 | /* The 'disable trace' command disables tracepoints. | |
8593 | Not supported by all targets. */ | |
8594 | static void | |
8595 | disable_trace_command (char *args, int from_tty) | |
8596 | { | |
8597 | disable_command (args, from_tty); | |
8598 | } | |
8599 | ||
8600 | /* Remove a tracepoint (or all if no argument) */ | |
8601 | static void | |
8602 | delete_trace_command (char *arg, int from_tty) | |
8603 | { | |
8604 | struct breakpoint *b, *temp; | |
8605 | ||
8606 | dont_repeat (); | |
8607 | ||
8608 | if (arg == 0) | |
8609 | { | |
8610 | int breaks_to_delete = 0; | |
8611 | ||
8612 | /* Delete all breakpoints if no argument. | |
8613 | Do not delete internal or call-dummy breakpoints, these | |
8614 | have to be deleted with an explicit breakpoint number argument. */ | |
8615 | ALL_TRACEPOINTS (b) | |
8616 | { | |
8617 | if (b->number >= 0) | |
8618 | { | |
8619 | breaks_to_delete = 1; | |
8620 | break; | |
8621 | } | |
8622 | } | |
8623 | ||
8624 | /* Ask user only if there are some breakpoints to delete. */ | |
8625 | if (!from_tty | |
8626 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
8627 | { | |
8628 | ALL_BREAKPOINTS_SAFE (b, temp) | |
8629 | { | |
059fb39f PM |
8630 | if (b->type == bp_tracepoint |
8631 | && b->number >= 0) | |
1042e4c0 SS |
8632 | delete_breakpoint (b); |
8633 | } | |
8634 | } | |
8635 | } | |
8636 | else | |
8637 | map_breakpoint_numbers (arg, delete_breakpoint); | |
8638 | } | |
8639 | ||
8640 | /* Set passcount for tracepoint. | |
8641 | ||
8642 | First command argument is passcount, second is tracepoint number. | |
8643 | If tracepoint number omitted, apply to most recently defined. | |
8644 | Also accepts special argument "all". */ | |
8645 | ||
8646 | static void | |
8647 | trace_pass_command (char *args, int from_tty) | |
8648 | { | |
8649 | struct breakpoint *t1 = (struct breakpoint *) -1, *t2; | |
8650 | unsigned int count; | |
8651 | int all = 0; | |
8652 | ||
8653 | if (args == 0 || *args == 0) | |
8654 | error (_("passcount command requires an argument (count + optional TP num)")); | |
8655 | ||
8656 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ | |
8657 | ||
8658 | while (*args && isspace ((int) *args)) | |
8659 | args++; | |
8660 | ||
8661 | if (*args && strncasecmp (args, "all", 3) == 0) | |
8662 | { | |
8663 | args += 3; /* Skip special argument "all". */ | |
8664 | all = 1; | |
8665 | if (*args) | |
8666 | error (_("Junk at end of arguments.")); | |
8667 | } | |
8668 | else | |
8669 | t1 = get_tracepoint_by_number (&args, 1, 1); | |
8670 | ||
8671 | do | |
8672 | { | |
8673 | if (t1) | |
8674 | { | |
8675 | ALL_TRACEPOINTS (t2) | |
8676 | if (t1 == (struct breakpoint *) -1 || t1 == t2) | |
8677 | { | |
8678 | t2->pass_count = count; | |
8679 | observer_notify_tracepoint_modified (t2->number); | |
8680 | if (from_tty) | |
8681 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
8682 | t2->number, count); | |
8683 | } | |
8684 | if (! all && *args) | |
8685 | t1 = get_tracepoint_by_number (&args, 1, 0); | |
8686 | } | |
8687 | } | |
8688 | while (*args); | |
8689 | } | |
8690 | ||
8691 | struct breakpoint * | |
8692 | get_tracepoint (int num) | |
8693 | { | |
8694 | struct breakpoint *t; | |
8695 | ||
8696 | ALL_TRACEPOINTS (t) | |
8697 | if (t->number == num) | |
8698 | return t; | |
8699 | ||
8700 | return NULL; | |
8701 | } | |
8702 | ||
8703 | /* Utility: parse a tracepoint number and look it up in the list. | |
8704 | If MULTI_P is true, there might be a range of tracepoints in ARG. | |
8705 | if OPTIONAL_P is true, then if the argument is missing, the most | |
8706 | recent tracepoint (tracepoint_count) is returned. */ | |
8707 | struct breakpoint * | |
8708 | get_tracepoint_by_number (char **arg, int multi_p, int optional_p) | |
8709 | { | |
8710 | extern int tracepoint_count; | |
8711 | struct breakpoint *t; | |
8712 | int tpnum; | |
8713 | char *instring = arg == NULL ? NULL : *arg; | |
8714 | ||
8715 | if (arg == NULL || *arg == NULL || ! **arg) | |
8716 | { | |
8717 | if (optional_p) | |
8718 | tpnum = tracepoint_count; | |
8719 | else | |
8720 | error_no_arg (_("tracepoint number")); | |
8721 | } | |
8722 | else | |
8723 | tpnum = multi_p ? get_number_or_range (arg) : get_number (arg); | |
8724 | ||
8725 | if (tpnum <= 0) | |
8726 | { | |
8727 | if (instring && *instring) | |
8728 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
8729 | instring); | |
8730 | else | |
8731 | printf_filtered (_("Tracepoint argument missing and no previous tracepoint\n")); | |
8732 | return NULL; | |
8733 | } | |
8734 | ||
8735 | ALL_TRACEPOINTS (t) | |
8736 | if (t->number == tpnum) | |
8737 | { | |
8738 | return t; | |
8739 | } | |
8740 | ||
8741 | /* FIXME: if we are in the middle of a range we don't want to give | |
8742 | a message. The current interface to get_number_or_range doesn't | |
8743 | allow us to discover this. */ | |
8744 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); | |
8745 | return NULL; | |
8746 | } | |
8747 | ||
8748 | /* save-tracepoints command */ | |
8749 | static void | |
8750 | tracepoint_save_command (char *args, int from_tty) | |
8751 | { | |
8752 | struct breakpoint *tp; | |
8753 | int any_tp = 0; | |
8754 | struct action_line *line; | |
8755 | FILE *fp; | |
8756 | char *i1 = " ", *i2 = " "; | |
8757 | char *indent, *actionline, *pathname; | |
8758 | char tmp[40]; | |
8759 | struct cleanup *cleanup; | |
8760 | ||
8761 | if (args == 0 || *args == 0) | |
8762 | error (_("Argument required (file name in which to save tracepoints)")); | |
8763 | ||
8764 | /* See if we have anything to save. */ | |
8765 | ALL_TRACEPOINTS (tp) | |
8766 | { | |
8767 | any_tp = 1; | |
8768 | break; | |
8769 | } | |
8770 | if (!any_tp) | |
8771 | { | |
8772 | warning (_("save-tracepoints: no tracepoints to save.")); | |
8773 | return; | |
8774 | } | |
8775 | ||
8776 | pathname = tilde_expand (args); | |
8777 | cleanup = make_cleanup (xfree, pathname); | |
059fb39f PM |
8778 | fp = fopen (pathname, "w"); |
8779 | if (!fp) | |
1042e4c0 SS |
8780 | error (_("Unable to open file '%s' for saving tracepoints (%s)"), |
8781 | args, safe_strerror (errno)); | |
8782 | make_cleanup_fclose (fp); | |
8783 | ||
8784 | ALL_TRACEPOINTS (tp) | |
8785 | { | |
8786 | if (tp->addr_string) | |
8787 | fprintf (fp, "trace %s\n", tp->addr_string); | |
8788 | else | |
8789 | { | |
8790 | sprintf_vma (tmp, tp->loc->address); | |
8791 | fprintf (fp, "trace *0x%s\n", tmp); | |
8792 | } | |
8793 | ||
8794 | if (tp->pass_count) | |
8795 | fprintf (fp, " passcount %d\n", tp->pass_count); | |
8796 | ||
8797 | if (tp->actions) | |
8798 | { | |
8799 | fprintf (fp, " actions\n"); | |
8800 | indent = i1; | |
8801 | for (line = tp->actions; line; line = line->next) | |
8802 | { | |
8803 | struct cmd_list_element *cmd; | |
8804 | ||
8805 | QUIT; /* allow user to bail out with ^C */ | |
8806 | actionline = line->action; | |
8807 | while (isspace ((int) *actionline)) | |
8808 | actionline++; | |
8809 | ||
8810 | fprintf (fp, "%s%s\n", indent, actionline); | |
8811 | if (*actionline != '#') /* skip for comment lines */ | |
8812 | { | |
8813 | cmd = lookup_cmd (&actionline, cmdlist, "", -1, 1); | |
8814 | if (cmd == 0) | |
8815 | error (_("Bad action list item: %s"), actionline); | |
8816 | if (cmd_cfunc_eq (cmd, while_stepping_pseudocommand)) | |
8817 | indent = i2; | |
8818 | else if (cmd_cfunc_eq (cmd, end_actions_pseudocommand)) | |
8819 | indent = i1; | |
8820 | } | |
8821 | } | |
8822 | } | |
8823 | } | |
8824 | do_cleanups (cleanup); | |
8825 | if (from_tty) | |
8826 | printf_filtered (_("Tracepoints saved to file '%s'.\n"), args); | |
8827 | return; | |
8828 | } | |
8829 | ||
8830 | /* Create a vector of all tracepoints. */ | |
8831 | ||
8832 | VEC(breakpoint_p) * | |
8833 | all_tracepoints () | |
8834 | { | |
8835 | VEC(breakpoint_p) *tp_vec = 0; | |
8836 | struct breakpoint *tp; | |
8837 | ||
8838 | ALL_TRACEPOINTS (tp) | |
8839 | { | |
8840 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
8841 | } | |
8842 | ||
8843 | return tp_vec; | |
8844 | } | |
8845 | ||
c906108c | 8846 | \f |
31e2b00f AS |
8847 | /* This help string is used for the break, hbreak, tbreak and thbreak commands. |
8848 | It is defined as a macro to prevent duplication. | |
8849 | COMMAND should be a string constant containing the name of the command. */ | |
8850 | #define BREAK_ARGS_HELP(command) \ | |
8851 | command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\ | |
8852 | LOCATION may be a line number, function name, or \"*\" and an address.\n\ | |
8853 | If a line number is specified, break at start of code for that line.\n\ | |
8854 | If a function is specified, break at start of code for that function.\n\ | |
8855 | If an address is specified, break at that exact address.\n\ | |
8856 | With no LOCATION, uses current execution address of selected stack frame.\n\ | |
8857 | This is useful for breaking on return to a stack frame.\n\ | |
8858 | \n\ | |
8859 | THREADNUM is the number from \"info threads\".\n\ | |
8860 | CONDITION is a boolean expression.\n\ | |
8861 | \n\ | |
8862 | Multiple breakpoints at one place are permitted, and useful if conditional.\n\ | |
8863 | \n\ | |
8864 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
8865 | ||
44feb3ce TT |
8866 | /* List of subcommands for "catch". */ |
8867 | static struct cmd_list_element *catch_cmdlist; | |
8868 | ||
8869 | /* List of subcommands for "tcatch". */ | |
8870 | static struct cmd_list_element *tcatch_cmdlist; | |
8871 | ||
8872 | /* Like add_cmd, but add the command to both the "catch" and "tcatch" | |
8873 | lists, and pass some additional user data to the command function. */ | |
8874 | static void | |
8875 | add_catch_command (char *name, char *docstring, | |
8876 | void (*sfunc) (char *args, int from_tty, | |
8877 | struct cmd_list_element *command), | |
8878 | void *user_data_catch, | |
8879 | void *user_data_tcatch) | |
8880 | { | |
8881 | struct cmd_list_element *command; | |
8882 | ||
8883 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
8884 | &catch_cmdlist); | |
8885 | set_cmd_sfunc (command, sfunc); | |
8886 | set_cmd_context (command, user_data_catch); | |
8887 | ||
8888 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
8889 | &tcatch_cmdlist); | |
8890 | set_cmd_sfunc (command, sfunc); | |
8891 | set_cmd_context (command, user_data_tcatch); | |
8892 | } | |
8893 | ||
c906108c | 8894 | void |
fba45db2 | 8895 | _initialize_breakpoint (void) |
c906108c | 8896 | { |
fa8d40ab JJ |
8897 | static struct cmd_list_element *breakpoint_set_cmdlist; |
8898 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
c906108c SS |
8899 | struct cmd_list_element *c; |
8900 | ||
84acb35a | 8901 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
84acb35a | 8902 | |
c906108c SS |
8903 | breakpoint_chain = 0; |
8904 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
8905 | before a breakpoint is set. */ | |
8906 | breakpoint_count = 0; | |
8907 | ||
1042e4c0 SS |
8908 | tracepoint_count = 0; |
8909 | ||
1bedd215 AC |
8910 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
8911 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
8912 | Usage is `ignore N COUNT'.")); | |
c906108c | 8913 | if (xdb_commands) |
c5aa993b | 8914 | add_com_alias ("bc", "ignore", class_breakpoint, 1); |
c906108c | 8915 | |
1bedd215 AC |
8916 | add_com ("commands", class_breakpoint, commands_command, _("\ |
8917 | Set commands to be executed when a breakpoint is hit.\n\ | |
c906108c SS |
8918 | Give breakpoint number as argument after \"commands\".\n\ |
8919 | With no argument, the targeted breakpoint is the last one set.\n\ | |
8920 | The commands themselves follow starting on the next line.\n\ | |
8921 | Type a line containing \"end\" to indicate the end of them.\n\ | |
8922 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 8923 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 8924 | |
1bedd215 AC |
8925 | add_com ("condition", class_breakpoint, condition_command, _("\ |
8926 | Specify breakpoint number N to break only if COND is true.\n\ | |
c906108c | 8927 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 8928 | expression to be evaluated whenever breakpoint N is reached.")); |
c906108c | 8929 | |
1bedd215 | 8930 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 8931 | Set a temporary breakpoint.\n\ |
c906108c SS |
8932 | Like \"break\" except the breakpoint is only temporary,\n\ |
8933 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
8934 | by using \"enable delete\" on the breakpoint number.\n\ |
8935 | \n" | |
8936 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 8937 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 8938 | |
1bedd215 | 8939 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
31e2b00f | 8940 | Set a hardware assisted breakpoint.\n\ |
c906108c | 8941 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
8942 | some target hardware may not have this support.\n\ |
8943 | \n" | |
8944 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 8945 | set_cmd_completer (c, location_completer); |
c906108c | 8946 | |
1bedd215 | 8947 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 8948 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 8949 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
8950 | so it will be deleted when hit.\n\ |
8951 | \n" | |
8952 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 8953 | set_cmd_completer (c, location_completer); |
c906108c | 8954 | |
1bedd215 AC |
8955 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
8956 | Enable some breakpoints.\n\ | |
c906108c SS |
8957 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
8958 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
8959 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 8960 | With a subcommand you can enable temporarily."), |
c906108c SS |
8961 | &enablelist, "enable ", 1, &cmdlist); |
8962 | if (xdb_commands) | |
1bedd215 AC |
8963 | add_com ("ab", class_breakpoint, enable_command, _("\ |
8964 | Enable some breakpoints.\n\ | |
c906108c SS |
8965 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
8966 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
8967 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 8968 | With a subcommand you can enable temporarily.")); |
c906108c SS |
8969 | |
8970 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
8971 | ||
1bedd215 AC |
8972 | add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
8973 | Enable some breakpoints.\n\ | |
c906108c SS |
8974 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
8975 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 8976 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 8977 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 8978 | |
1a966eab AC |
8979 | add_cmd ("once", no_class, enable_once_command, _("\ |
8980 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
8981 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
8982 | &enablebreaklist); |
8983 | ||
1a966eab AC |
8984 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
8985 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
8986 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
8987 | &enablebreaklist); |
8988 | ||
1a966eab AC |
8989 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
8990 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
8991 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
8992 | &enablelist); |
8993 | ||
1a966eab AC |
8994 | add_cmd ("once", no_class, enable_once_command, _("\ |
8995 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
8996 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
8997 | &enablelist); |
8998 | ||
1bedd215 AC |
8999 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
9000 | Disable some breakpoints.\n\ | |
c906108c SS |
9001 | Arguments are breakpoint numbers with spaces in between.\n\ |
9002 | To disable all breakpoints, give no argument.\n\ | |
1bedd215 | 9003 | A disabled breakpoint is not forgotten, but has no effect until reenabled."), |
c906108c SS |
9004 | &disablelist, "disable ", 1, &cmdlist); |
9005 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
9006 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
9007 | if (xdb_commands) | |
1bedd215 AC |
9008 | add_com ("sb", class_breakpoint, disable_command, _("\ |
9009 | Disable some breakpoints.\n\ | |
c906108c SS |
9010 | Arguments are breakpoint numbers with spaces in between.\n\ |
9011 | To disable all breakpoints, give no argument.\n\ | |
1bedd215 | 9012 | A disabled breakpoint is not forgotten, but has no effect until reenabled.")); |
c906108c | 9013 | |
1a966eab AC |
9014 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
9015 | Disable some breakpoints.\n\ | |
c906108c SS |
9016 | Arguments are breakpoint numbers with spaces in between.\n\ |
9017 | To disable all breakpoints, give no argument.\n\ | |
9018 | A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\ | |
1a966eab | 9019 | This command may be abbreviated \"disable\"."), |
c906108c SS |
9020 | &disablelist); |
9021 | ||
1bedd215 AC |
9022 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
9023 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
9024 | Arguments are breakpoint numbers with spaces in between.\n\ |
9025 | To delete all breakpoints, give no argument.\n\ | |
9026 | \n\ | |
9027 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 9028 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
9029 | &deletelist, "delete ", 1, &cmdlist); |
9030 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 9031 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 9032 | if (xdb_commands) |
1bedd215 AC |
9033 | add_com ("db", class_breakpoint, delete_command, _("\ |
9034 | Delete some breakpoints.\n\ | |
c906108c | 9035 | Arguments are breakpoint numbers with spaces in between.\n\ |
1bedd215 | 9036 | To delete all breakpoints, give no argument.\n")); |
c906108c | 9037 | |
1a966eab AC |
9038 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
9039 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
9040 | Arguments are breakpoint numbers with spaces in between.\n\ |
9041 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 9042 | This command may be abbreviated \"delete\"."), |
c906108c SS |
9043 | &deletelist); |
9044 | ||
1bedd215 AC |
9045 | add_com ("clear", class_breakpoint, clear_command, _("\ |
9046 | Clear breakpoint at specified line or function.\n\ | |
c906108c SS |
9047 | Argument may be line number, function name, or \"*\" and an address.\n\ |
9048 | If line number is specified, all breakpoints in that line are cleared.\n\ | |
9049 | If function is specified, breakpoints at beginning of function are cleared.\n\ | |
1bedd215 AC |
9050 | If an address is specified, breakpoints at that address are cleared.\n\ |
9051 | \n\ | |
9052 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
c906108c SS |
9053 | is executing in.\n\ |
9054 | \n\ | |
1bedd215 | 9055 | See also the \"delete\" command which clears breakpoints by number.")); |
c906108c | 9056 | |
1bedd215 | 9057 | c = add_com ("break", class_breakpoint, break_command, _("\ |
31e2b00f AS |
9058 | Set breakpoint at specified line or function.\n" |
9059 | BREAK_ARGS_HELP ("break"))); | |
5ba2abeb | 9060 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 9061 | |
c906108c SS |
9062 | add_com_alias ("b", "break", class_run, 1); |
9063 | add_com_alias ("br", "break", class_run, 1); | |
9064 | add_com_alias ("bre", "break", class_run, 1); | |
9065 | add_com_alias ("brea", "break", class_run, 1); | |
9066 | ||
7681d515 PM |
9067 | if (xdb_commands) |
9068 | add_com_alias ("ba", "break", class_breakpoint, 1); | |
c906108c SS |
9069 | |
9070 | if (dbx_commands) | |
9071 | { | |
1bedd215 AC |
9072 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
9073 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
9074 | &stoplist, "stop ", 1, &cmdlist); |
9075 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 9076 | _("Break in function or address."), &stoplist); |
c5aa993b | 9077 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 9078 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
9079 | add_com ("status", class_info, breakpoints_info, _("\ |
9080 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
9081 | The \"Type\" column indicates one of:\n\ |
9082 | \tbreakpoint - normal breakpoint\n\ | |
9083 | \twatchpoint - watchpoint\n\ | |
9084 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
9085 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
9086 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
9087 | address and file/line number respectively.\n\ |
9088 | \n\ | |
9089 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
9090 | are set to the address of the last breakpoint listed unless the command\n\ |
9091 | is prefixed with \"server \".\n\n\ | |
c906108c | 9092 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 9093 | breakpoint set.")); |
c906108c SS |
9094 | } |
9095 | ||
1bedd215 AC |
9096 | add_info ("breakpoints", breakpoints_info, _("\ |
9097 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
9098 | The \"Type\" column indicates one of:\n\ |
9099 | \tbreakpoint - normal breakpoint\n\ | |
9100 | \twatchpoint - watchpoint\n\ | |
9101 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
9102 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
9103 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
9104 | address and file/line number respectively.\n\ |
9105 | \n\ | |
9106 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
9107 | are set to the address of the last breakpoint listed unless the command\n\ |
9108 | is prefixed with \"server \".\n\n\ | |
c906108c | 9109 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 9110 | breakpoint set.")); |
c906108c SS |
9111 | |
9112 | if (xdb_commands) | |
1bedd215 AC |
9113 | add_com ("lb", class_breakpoint, breakpoints_info, _("\ |
9114 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
9115 | The \"Type\" column indicates one of:\n\ |
9116 | \tbreakpoint - normal breakpoint\n\ | |
9117 | \twatchpoint - watchpoint\n\ | |
9118 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
9119 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
9120 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
9121 | address and file/line number respectively.\n\ |
9122 | \n\ | |
9123 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
9124 | are set to the address of the last breakpoint listed unless the command\n\ |
9125 | is prefixed with \"server \".\n\n\ | |
c906108c | 9126 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 9127 | breakpoint set.")); |
c906108c | 9128 | |
1a966eab AC |
9129 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
9130 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
9131 | The \"Type\" column indicates one of:\n\ |
9132 | \tbreakpoint - normal breakpoint\n\ | |
9133 | \twatchpoint - watchpoint\n\ | |
9134 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
9135 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
9136 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
9137 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
9138 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
9139 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
9140 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
9141 | address and file/line number respectively.\n\ |
9142 | \n\ | |
9143 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
9144 | are set to the address of the last breakpoint listed unless the command\n\ |
9145 | is prefixed with \"server \".\n\n\ | |
c906108c | 9146 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 9147 | breakpoint set."), |
c906108c SS |
9148 | &maintenanceinfolist); |
9149 | ||
44feb3ce TT |
9150 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
9151 | Set catchpoints to catch events."), | |
9152 | &catch_cmdlist, "catch ", | |
9153 | 0/*allow-unknown*/, &cmdlist); | |
9154 | ||
9155 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
9156 | Set temporary catchpoints to catch events."), | |
9157 | &tcatch_cmdlist, "tcatch ", | |
9158 | 0/*allow-unknown*/, &cmdlist); | |
9159 | ||
9160 | /* Add catch and tcatch sub-commands. */ | |
9161 | add_catch_command ("catch", _("\ | |
9162 | Catch an exception, when caught.\n\ | |
9163 | With an argument, catch only exceptions with the given name."), | |
9164 | catch_catch_command, | |
9165 | CATCH_PERMANENT, | |
9166 | CATCH_TEMPORARY); | |
9167 | add_catch_command ("throw", _("\ | |
9168 | Catch an exception, when thrown.\n\ | |
9169 | With an argument, catch only exceptions with the given name."), | |
9170 | catch_throw_command, | |
9171 | CATCH_PERMANENT, | |
9172 | CATCH_TEMPORARY); | |
9173 | add_catch_command ("fork", _("Catch calls to fork."), | |
9174 | catch_fork_command_1, | |
9175 | (void *) (uintptr_t) catch_fork_permanent, | |
9176 | (void *) (uintptr_t) catch_fork_temporary); | |
9177 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
9178 | catch_fork_command_1, | |
9179 | (void *) (uintptr_t) catch_vfork_permanent, | |
9180 | (void *) (uintptr_t) catch_vfork_temporary); | |
9181 | add_catch_command ("exec", _("Catch calls to exec."), | |
9182 | catch_exec_command_1, | |
9183 | CATCH_PERMANENT, | |
9184 | CATCH_TEMPORARY); | |
44feb3ce TT |
9185 | add_catch_command ("exception", _("\ |
9186 | Catch Ada exceptions, when raised.\n\ | |
9187 | With an argument, catch only exceptions with the given name."), | |
9188 | catch_ada_exception_command, | |
9189 | CATCH_PERMANENT, | |
9190 | CATCH_TEMPORARY); | |
9191 | add_catch_command ("assert", _("\ | |
9192 | Catch failed Ada assertions, when raised.\n\ | |
9193 | With an argument, catch only exceptions with the given name."), | |
9194 | catch_assert_command, | |
9195 | CATCH_PERMANENT, | |
9196 | CATCH_TEMPORARY); | |
c5aa993b | 9197 | |
1bedd215 AC |
9198 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
9199 | Set a watchpoint for an expression.\n\ | |
c906108c | 9200 | A watchpoint stops execution of your program whenever the value of\n\ |
1bedd215 | 9201 | an expression changes.")); |
65d12d83 | 9202 | set_cmd_completer (c, expression_completer); |
c906108c | 9203 | |
1bedd215 AC |
9204 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
9205 | Set a read watchpoint for an expression.\n\ | |
c906108c | 9206 | A watchpoint stops execution of your program whenever the value of\n\ |
1bedd215 | 9207 | an expression is read.")); |
65d12d83 | 9208 | set_cmd_completer (c, expression_completer); |
c906108c | 9209 | |
1bedd215 AC |
9210 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
9211 | Set a watchpoint for an expression.\n\ | |
c906108c | 9212 | A watchpoint stops execution of your program whenever the value of\n\ |
1bedd215 | 9213 | an expression is either read or written.")); |
65d12d83 | 9214 | set_cmd_completer (c, expression_completer); |
c906108c SS |
9215 | |
9216 | add_info ("watchpoints", breakpoints_info, | |
1bedd215 | 9217 | _("Synonym for ``info breakpoints''.")); |
c906108c SS |
9218 | |
9219 | ||
920d2a44 AC |
9220 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
9221 | respond to changes - contrary to the description. */ | |
85c07804 AC |
9222 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
9223 | &can_use_hw_watchpoints, _("\ | |
9224 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
9225 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
9226 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
9227 | such is available. (However, any hardware watchpoints that were\n\ | |
9228 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
9229 | hardware.)"), |
9230 | NULL, | |
920d2a44 | 9231 | show_can_use_hw_watchpoints, |
85c07804 | 9232 | &setlist, &showlist); |
c906108c SS |
9233 | |
9234 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 9235 | |
1042e4c0 SS |
9236 | /* Tracepoint manipulation commands. */ |
9237 | ||
9238 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
9239 | Set a tracepoint at specified line or function.\n\ | |
9240 | \n" | |
9241 | BREAK_ARGS_HELP ("trace") "\n\ | |
9242 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
9243 | set_cmd_completer (c, location_completer); | |
9244 | ||
9245 | add_com_alias ("tp", "trace", class_alias, 0); | |
9246 | add_com_alias ("tr", "trace", class_alias, 1); | |
9247 | add_com_alias ("tra", "trace", class_alias, 1); | |
9248 | add_com_alias ("trac", "trace", class_alias, 1); | |
9249 | ||
9250 | add_info ("tracepoints", tracepoints_info, _("\ | |
9251 | Status of tracepoints, or tracepoint number NUMBER.\n\ | |
9252 | Convenience variable \"$tpnum\" contains the number of the\n\ | |
9253 | last tracepoint set.")); | |
9254 | ||
9255 | add_info_alias ("tp", "tracepoints", 1); | |
9256 | ||
9257 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
9258 | Delete specified tracepoints.\n\ | |
9259 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
9260 | No argument means delete all tracepoints."), | |
9261 | &deletelist); | |
9262 | ||
9263 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
9264 | Disable specified tracepoints.\n\ | |
9265 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
9266 | No argument means disable all tracepoints."), | |
9267 | &disablelist); | |
9268 | deprecate_cmd (c, "disable"); | |
9269 | ||
9270 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
9271 | Enable specified tracepoints.\n\ | |
9272 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
9273 | No argument means enable all tracepoints."), | |
9274 | &enablelist); | |
9275 | deprecate_cmd (c, "enable"); | |
9276 | ||
9277 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
9278 | Set the passcount for a tracepoint.\n\ | |
9279 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
9280 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
9281 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
9282 | ||
9283 | c = add_com ("save-tracepoints", class_trace, tracepoint_save_command, _("\ | |
9284 | Save current tracepoint definitions as a script.\n\ | |
9285 | Use the 'source' command in another debug session to restore them.")); | |
9286 | set_cmd_completer (c, filename_completer); | |
9287 | ||
1bedd215 | 9288 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
9289 | Breakpoint specific settings\n\ |
9290 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 9291 | pending breakpoint behavior"), |
fa8d40ab JJ |
9292 | &breakpoint_set_cmdlist, "set breakpoint ", |
9293 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 9294 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
9295 | Breakpoint specific settings\n\ |
9296 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 9297 | pending breakpoint behavior"), |
fa8d40ab JJ |
9298 | &breakpoint_show_cmdlist, "show breakpoint ", |
9299 | 0/*allow-unknown*/, &showlist); | |
9300 | ||
7915a72c AC |
9301 | add_setshow_auto_boolean_cmd ("pending", no_class, |
9302 | &pending_break_support, _("\ | |
9303 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
9304 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
9305 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
9306 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
9307 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 9308 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 9309 | NULL, |
920d2a44 | 9310 | show_pending_break_support, |
6e1d7d6c AC |
9311 | &breakpoint_set_cmdlist, |
9312 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
9313 | |
9314 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
9315 | |
9316 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
9317 | &automatic_hardware_breakpoints, _("\ | |
9318 | Set automatic usage of hardware breakpoints."), _("\ | |
9319 | Show automatic usage of hardware breakpoints."), _("\ | |
9320 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
9321 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
9322 | a warning will be emitted for such breakpoints."), | |
9323 | NULL, | |
9324 | show_automatic_hardware_breakpoints, | |
9325 | &breakpoint_set_cmdlist, | |
9326 | &breakpoint_show_cmdlist); | |
74960c60 | 9327 | |
33e5cbd6 PA |
9328 | add_setshow_enum_cmd ("always-inserted", class_support, |
9329 | always_inserted_enums, &always_inserted_mode, _("\ | |
74960c60 VP |
9330 | Set mode for inserting breakpoints."), _("\ |
9331 | Show mode for inserting breakpoints."), _("\ | |
33e5cbd6 PA |
9332 | When this mode is off, breakpoints are inserted in inferior when it is\n\ |
9333 | resumed, and removed when execution stops. When this mode is on,\n\ | |
9334 | breakpoints are inserted immediately and removed only when the user\n\ | |
9335 | deletes the breakpoint. When this mode is auto (which is the default),\n\ | |
9336 | the behaviour depends on the non-stop setting (see help set non-stop).\n\ | |
9337 | In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\ | |
9338 | behaves as if always-inserted mode is on; if gdb is controlling the\n\ | |
9339 | inferior in all-stop mode, gdb behaves as if always-inserted mode is off."), | |
74960c60 VP |
9340 | NULL, |
9341 | &show_always_inserted_mode, | |
9342 | &breakpoint_set_cmdlist, | |
9343 | &breakpoint_show_cmdlist); | |
765dc015 VP |
9344 | |
9345 | automatic_hardware_breakpoints = 1; | |
f3b1572e PA |
9346 | |
9347 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
c906108c | 9348 | } |